diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e765691ad..2a1f35ec4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -277,6 +277,11 @@
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize">
+
+
+
diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c
index 5a2f9beb1..36003db47 100644
--- a/jni/dc_wrapper.c
+++ b/jni/dc_wrapper.c
@@ -506,6 +506,15 @@ JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getMsgInfo(JNIEnv *env, jobj
}
+JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getMsgHtml(JNIEnv *env, jobject obj, jint msg_id)
+{
+ char* temp = dc_get_msg_html(get_dc_context(env, obj), msg_id);
+ jstring ret = JSTRING_NEW(temp);
+ dc_str_unref(temp);
+ return ret;
+}
+
+
JNIEXPORT void Java_com_b44t_messenger_DcContext_deleteMsgs(JNIEnv *env, jobject obj, jintArray msg_ids)
{
int msg_ids_cnt = 0;
@@ -1337,6 +1346,12 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcMsg_isSetupMessage(JNIEnv *env, job
}
+JNIEXPORT jboolean Java_com_b44t_messenger_DcMsg_hasHtml(JNIEnv *env, jobject obj)
+{
+ return dc_msg_has_html(get_dc_msg(env, obj))!=0;
+}
+
+
JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getSetupCodeBegin(JNIEnv *env, jobject obj)
{
char* temp = dc_msg_get_setupcodebegin(get_dc_msg(env, obj));
diff --git a/res/layout/conversation_item_received.xml b/res/layout/conversation_item_received.xml
index 12eb090f8..0c2677295 100644
--- a/res/layout/conversation_item_received.xml
+++ b/res/layout/conversation_item_received.xml
@@ -151,6 +151,23 @@
app:scaleEmojis="true"
tools:text="Mango pickle lorem ipsum"/>
+
+
-
+ android:layout_height="28dp"
+ android:layout_gravity="center_vertical"
+ android:layout_marginLeft="10dp"
+ android:layout_marginRight="10dp"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="10dp"
+ android:paddingLeft="12dp"
+ android:paddingRight="12dp"
+ android:background="@drawable/conversation_item_update_background"
+ android:minWidth="20dp"
+ android:text="@string/show_full_message"
+ android:textAllCaps="false"/>
+
+
diff --git a/res/menu/local_help.xml b/res/menu/local_help.xml
index 66b171b9b..1d2dc82bb 100644
--- a/res/menu/local_help.xml
+++ b/res/menu/local_help.xml
@@ -2,28 +2,6 @@
\ No newline at end of file
+
diff --git a/res/menu/web_view.xml b/res/menu/web_view.xml
new file mode 100644
index 000000000..35a8008b4
--- /dev/null
+++ b/res/menu/web_view.xml
@@ -0,0 +1,27 @@
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cc90b6be7..6b2c62ed8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -39,6 +39,12 @@
Profile
Main menu
Start chat
+ Show full message…
+ Load remote images
+
+ Remote images can be used to track you.\n\nThe setting also allows loading fonts and other content. Even if it is disabled, you may still see embedded or cached images.\n\nLoad remote images?
+ Always
+ Once
Show password
Hide password
Not now
diff --git a/src/com/b44t/messenger/DcContext.java b/src/com/b44t/messenger/DcContext.java
index 7a6998f58..e74c00563 100644
--- a/src/com/b44t/messenger/DcContext.java
+++ b/src/com/b44t/messenger/DcContext.java
@@ -156,6 +156,7 @@ public class DcContext {
public native void deleteChat (int chat_id);
public @NonNull DcMsg getMsg (int msg_id) { return new DcMsg(getMsgCPtr(msg_id)); }
public native String getMsgInfo (int id);
+ public native String getMsgHtml (int msg_id);
public native int getFreshMsgCount (int chat_id);
public native int estimateDeletionCount(boolean from_server, long seconds);
public native void deleteMsgs (int msg_ids[]);
diff --git a/src/com/b44t/messenger/DcMsg.java b/src/com/b44t/messenger/DcMsg.java
index dc4715b42..25c47ee13 100644
--- a/src/com/b44t/messenger/DcMsg.java
+++ b/src/com/b44t/messenger/DcMsg.java
@@ -114,6 +114,7 @@ public class DcMsg {
public native boolean isForwarded ();
public native boolean isInfo ();
public native boolean isSetupMessage ();
+ public native boolean hasHtml ();
public native String getSetupCodeBegin ();
public native String getVideochatUrl ();
public native int getVideochatType ();
diff --git a/src/org/thoughtcrime/securesms/BindableConversationItem.java b/src/org/thoughtcrime/securesms/BindableConversationItem.java
index 11a0ed6b0..ba9de3407 100644
--- a/src/org/thoughtcrime/securesms/BindableConversationItem.java
+++ b/src/org/thoughtcrime/securesms/BindableConversationItem.java
@@ -28,5 +28,6 @@ public interface BindableConversationItem extends Unbindable {
interface EventListener {
void onQuoteClicked(DcMsg messageRecord);
+ void onShowFullClicked(DcMsg messageRecord);
}
}
diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java
index fda9a2b8a..6bf5b7b7d 100644
--- a/src/org/thoughtcrime/securesms/ConversationFragment.java
+++ b/src/org/thoughtcrime/securesms/ConversationFragment.java
@@ -872,6 +872,14 @@ public class ConversationFragment extends Fragment
}
}
}
+
+ @Override
+ public void onShowFullClicked(DcMsg messageRecord) {
+ Intent intent = new Intent(getActivity(), FullMsgActivity.class);
+ intent.putExtra(FullMsgActivity.MSG_ID_EXTRA, messageRecord.getId());
+ startActivity(intent);
+ getActivity().overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
+ }
}
@Override
diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java
index 020fb0545..5051ca971 100644
--- a/src/org/thoughtcrime/securesms/ConversationItem.java
+++ b/src/org/thoughtcrime/securesms/ConversationItem.java
@@ -32,6 +32,7 @@ import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -110,6 +111,7 @@ public class ConversationItem extends LinearLayout
private AvatarImageView contactPhoto;
protected ViewGroup contactPhotoHolder;
private ViewGroup container;
+ private Button showFullMessage;
private @NonNull Set batchSelected = new HashSet<>();
private @NonNull Recipient conversationRecipient;
@@ -162,6 +164,7 @@ public class ConversationItem extends LinearLayout
this.quoteView = findViewById(R.id.quote_view);
this.container = findViewById(R.id.container);
this.replyView = findViewById(R.id.reply_icon);
+ this.showFullMessage = findViewById(R.id.show_full_message);
setOnClickListener(new ClickListener(null));
@@ -361,6 +364,18 @@ public class ConversationItem extends LinearLayout
bodyText.setVisibility(View.VISIBLE);
}
+ if (messageRecord.hasHtml()) {
+ showFullMessage.setVisibility(View.VISIBLE);
+ showFullMessage.setOnClickListener(view -> {
+ if (eventListener != null && batchSelected.isEmpty()) {
+ eventListener.onShowFullClicked(messageRecord);
+ } else {
+ passthroughClickListener.onClick(view);
+ }
+ });
+ } else {
+ showFullMessage.setVisibility(View.GONE);
+ }
}
private void setMediaAttributes(@NonNull DcMsg messageRecord,
diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java
index c9a809580..6020e1050 100644
--- a/src/org/thoughtcrime/securesms/ConversationListActivity.java
+++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java
@@ -282,7 +282,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
final ApplicationDcContext dcContext = DcHelper.getContext(this);
if (isForwarding(this) && dcContext.getChat(chatId).isSelfTalk()) {
SendRelayedMessageUtil.immediatelyRelay(this, chatId);
- Toast.makeText(this, "✔️ " + getString(R.string.saved), Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, DynamicTheme.getCheckmarkEmoji(this) + " " + getString(R.string.saved), Toast.LENGTH_SHORT).show();
handleResetRelaying();
finish();
} else {
diff --git a/src/org/thoughtcrime/securesms/FullMsgActivity.java b/src/org/thoughtcrime/securesms/FullMsgActivity.java
new file mode 100644
index 000000000..762132dab
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/FullMsgActivity.java
@@ -0,0 +1,141 @@
+package org.thoughtcrime.securesms;
+
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import androidx.appcompat.app.AlertDialog;
+
+import org.thoughtcrime.securesms.connect.ApplicationDcContext;
+import org.thoughtcrime.securesms.connect.DcHelper;
+import org.thoughtcrime.securesms.util.DynamicTheme;
+import org.thoughtcrime.securesms.util.Prefs;
+import org.thoughtcrime.securesms.util.Util;
+
+import java.lang.ref.WeakReference;
+
+import static android.util.Base64.DEFAULT;
+import static android.util.Base64.encodeToString;
+
+public class FullMsgActivity extends WebViewActivity
+{
+ public static final String MSG_ID_EXTRA = "msg_id";
+ private int msgId;
+ private ApplicationDcContext dcContext;
+ private boolean loadRemoteContent = false;
+
+ enum LoadRemoteContent {
+ NEVER,
+ ONCE,
+ ALWAYS
+ }
+
+ @Override
+ protected void onCreate(Bundle state, boolean ready) {
+ super.onCreate(state, ready);
+
+ loadRemoteContent = Prefs.getAlwaysLoadRemoteContent(this);
+ webView.getSettings().setBlockNetworkLoads(!loadRemoteContent);
+
+ getSupportActionBar().setTitle(getString(R.string.chat_input_placeholder));
+
+ dcContext = DcHelper.getContext(this);
+ msgId = getIntent().getIntExtra(MSG_ID_EXTRA, 0);
+
+ loadHtmlAsync(new WeakReference<>(this));
+ }
+
+ private static void loadHtmlAsync(final WeakReference activityReference) {
+ Util.runOnBackground(() -> {
+ // android9 seems to make problems for non-base64-encoded html,
+ // see eg. https://stackoverflow.com/questions/54516798/webview-loaddata-not-working-on-android-9-0-api-29
+ String html;
+
+ try {
+ FullMsgActivity activity = activityReference.get();
+ html = activity.dcContext.getMsgHtml(activity.msgId);
+ html = encodeToString(html.getBytes("UTF-8"), DEFAULT);
+ String finalHtml = html;
+
+ activity.runOnUiThread(() -> {
+ try {
+ activityReference.get().webView.loadData(finalHtml, "text/html; charset=utf-8", "base64");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (isFinishing()) {
+ overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
+ }
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ this.getMenuInflater().inflate(R.menu.full_msg, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ super.onOptionsItemSelected(item);
+ switch (item.getItemId()) {
+ case R.id.load_remote_content:
+ AlertDialog.Builder builder = new AlertDialog.Builder(this)
+ .setTitle(R.string.load_remote_content)
+ .setMessage(R.string.load_remote_content_ask);
+
+ // we are using the buttons "[Always] [Never][Once]" in that order.
+ // 1. Checkmarks before [Always] and [Never] show the current state.
+ // 2. [Once] is also shown in always-mode and disables always-mode if selected
+ // (there was the idea to hide [Once] in always mode, but that looks more like a bug in the end)
+ // (maybe a usual Always-Checkbox and "[Cancel][OK]" buttons are an alternative, however, a [Once]
+ // would be required as well - probably as the leftmost button which is not that usable in
+ // not-always-mode where the dialog is used more often. Or [Ok] would mean "Once" as well as "Change checkbox setting",
+ // which is also a bit weird. Anyway, let's give the three buttons a try :)
+ final String checkmarkPrefix = DynamicTheme.getCheckmarkEmoji(this) + " ";
+ if (Prefs.getAlwaysLoadRemoteContent(this)) {
+ builder.setNeutralButton(checkmarkPrefix + getString(R.string.always), (dialog, which) -> onChangeLoadRemoteContent(LoadRemoteContent.ALWAYS));
+ builder.setNegativeButton(R.string.never, (dialog, which) -> onChangeLoadRemoteContent(LoadRemoteContent.NEVER));
+ builder.setPositiveButton(R.string.once, (dialog, which) -> onChangeLoadRemoteContent(LoadRemoteContent.ONCE));
+ } else {
+ builder.setNeutralButton(R.string.always, (dialog, which) -> onChangeLoadRemoteContent(LoadRemoteContent.ALWAYS));
+ builder.setNegativeButton((loadRemoteContent? "" : checkmarkPrefix) + getString(R.string.never), (dialog, which) -> onChangeLoadRemoteContent(LoadRemoteContent.NEVER));
+ builder.setPositiveButton((loadRemoteContent? checkmarkPrefix : "") + getString(R.string.once), (dialog, which) -> onChangeLoadRemoteContent(LoadRemoteContent.ONCE));
+ }
+
+ builder.show();
+ return true;
+ }
+ return false;
+ }
+
+ private void onChangeLoadRemoteContent(LoadRemoteContent loadRemoteContent) {
+ switch (loadRemoteContent) {
+ case NEVER:
+ this.loadRemoteContent = false;
+ Prefs.setBooleanPreference(this, Prefs.ALWAYS_LOAD_REMOTE_CONTENT, false);
+ break;
+ case ONCE:
+ this.loadRemoteContent = true;
+ Prefs.setBooleanPreference(this, Prefs.ALWAYS_LOAD_REMOTE_CONTENT, false);
+ break;
+ case ALWAYS:
+ this.loadRemoteContent = true;
+ Prefs.setBooleanPreference(this, Prefs.ALWAYS_LOAD_REMOTE_CONTENT, true);
+ break;
+ }
+ webView.getSettings().setBlockNetworkLoads(!this.loadRemoteContent);
+ webView.reload();
+ }
+}
diff --git a/src/org/thoughtcrime/securesms/LocalHelpActivity.java b/src/org/thoughtcrime/securesms/LocalHelpActivity.java
index 532bc798f..6a8873ad4 100644
--- a/src/org/thoughtcrime/securesms/LocalHelpActivity.java
+++ b/src/org/thoughtcrime/securesms/LocalHelpActivity.java
@@ -1,269 +1,80 @@
package org.thoughtcrime.securesms;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
import android.content.res.AssetManager;
-import android.net.Uri;
import android.os.Bundle;
-import android.util.Log;
import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-import android.widget.ImageView;
-import android.widget.Toast;
-
-import androidx.appcompat.widget.SearchView;
-
-import org.thoughtcrime.securesms.util.DynamicLanguage;
-import org.thoughtcrime.securesms.util.DynamicTheme;
import java.io.InputStream;
import java.util.Locale;
-public class LocalHelpActivity extends PassphraseRequiredActionBarActivity
- implements SearchView.OnQueryTextListener,
- WebView.FindListener
+public class LocalHelpActivity extends WebViewActivity
{
- private static final String TAG = LocalHelpActivity.class.getSimpleName();
+ @Override
+ protected void onCreate(Bundle state, boolean ready) {
+ super.onCreate(state, ready);
+ getSupportActionBar().setTitle(getString(R.string.menu_help));
- private WebView webView;
- private final DynamicTheme dynamicTheme = new DynamicTheme();
- private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
-
- @Override
- protected void onPreCreate() {
- dynamicTheme.onCreate(this);
- dynamicLanguage.onCreate(this);
- }
-
- private boolean assetExists(String fileName) {
- // test using AssetManager.open();
- // AssetManager.list() is unreliable eg. on my Android 7 Moto G
- // and also reported to be pretty slow.
- boolean exists = false;
- try {
- AssetManager assetManager = getResources().getAssets();
- InputStream is = assetManager.open(fileName);
- exists = true;
- is.close();
- } catch(Exception e) {
- ;
+ String helpPath = "help/LANG/help.html";
+ String helpLang = "en";
+ try {
+ Locale locale = dynamicLanguage.getCurrentLocale();
+ String appLang = locale.getLanguage();
+ if (assetExists(helpPath.replace("LANG", appLang))) {
+ helpLang = appLang;
+ } else {
+ appLang = appLang.substring(0, 2);
+ if (assetExists(helpPath.replace("LANG", appLang))) {
+ helpLang = appLang;
}
- return exists;
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
}
- @Override
- protected void onCreate(Bundle state, boolean ready) {
- setContentView(R.layout.local_help_activity);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setTitle(getString(R.string.menu_help));
+ webView.loadUrl("file:///android_asset/" + helpPath.replace("LANG", helpLang));
+ }
- String helpPath = "help/LANG/help.html";
- String helpLang = "en";
- try {
- Locale locale = dynamicLanguage.getCurrentLocale();
- String appLang = locale.getLanguage();
- if (assetExists(helpPath.replace("LANG", appLang))) {
- helpLang = appLang;
- } else {
- appLang = appLang.substring(0, 2);
- if (assetExists(helpPath.replace("LANG", appLang))) {
- helpLang = appLang;
- }
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ this.getMenuInflater().inflate(R.menu.local_help, menu);
+ return true;
+ }
- webView = findViewById(R.id.webview);
- webView.setWebViewClient(new WebViewClient(){
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
- openOnlineUrl(url);
- return true;
- }
- return false;
- }
- });
- webView.loadUrl("file:///android_asset/" + helpPath.replace("LANG", helpLang));
- webView.setFindListener(this);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- dynamicTheme.onResume(this);
- dynamicLanguage.onResume(this);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- MenuInflater inflater = this.getMenuInflater();
- menu.clear();
-
- inflater.inflate(R.menu.local_help, menu);
-
- try {
- MenuItem searchItem = menu.findItem(R.id.menu_search_localhelp);
- searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
- @Override
- public boolean onMenuItemActionExpand(final MenuItem item) {
- searchMenu = menu;
- LocalHelpActivity.this.lastQuery = "";
- LocalHelpActivity.this.makeSearchMenuVisible(menu, searchItem, true);
- return true;
- }
-
- @Override
- public boolean onMenuItemActionCollapse(final MenuItem item) {
- LocalHelpActivity.this.makeSearchMenuVisible(menu, searchItem, false);
- return true;
- }
- });
- SearchView searchView = (SearchView) searchItem.getActionView();
- searchView.setOnQueryTextListener(this);
- searchView.setQueryHint(getString(R.string.search));
- searchView.setIconifiedByDefault(true);
-
- // hide the [X] beside the search field - this is too much noise, search can be aborted eg. by "back"
- ImageView closeBtn = searchView.findViewById(R.id.search_close_btn);
- if (closeBtn!=null) {
- closeBtn.setEnabled(false);
- closeBtn.setImageDrawable(null);
- }
- } catch (Exception e) {
- Log.e(TAG, "cannot set up help-search: ", e);
- }
-
- super.onPrepareOptionsMenu(menu);
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ super.onOptionsItemSelected(item);
+ switch (item.getItemId()) {
+ case R.id.log_scroll_up:
+ webView.scrollTo(0, 0);
+ return true;
+ case R.id.learn_more:
+ openOnlineUrl("https://delta.chat");
+ return true;
+ case R.id.contribute:
+ openOnlineUrl("https://github.com/deltachat/deltachat-android");
+ return true;
+ case R.id.report_issue:
+ openOnlineUrl("https://github.com/deltachat/deltachat-android/issues");
return true;
}
+ return false;
+ }
-
- // search
-
- private Menu searchMenu = null;
- private String lastQuery = "";
- private Toast lastToast = null;
-
- private void updateResultCounter(int curr, int total) {
- if (searchMenu!=null) {
- MenuItem item = searchMenu.findItem(R.id.menu_search_counter);
- if (curr!=-1) {
- item.setTitle(String.format("%d/%d", total==0? 0 : curr+1, total));
- item.setVisible(true);
- } else {
- item.setVisible(false);
- }
- }
+ private boolean assetExists(String fileName) {
+ // test using AssetManager.open();
+ // AssetManager.list() is unreliable eg. on my Android 7 Moto G
+ // and also reported to be pretty slow.
+ boolean exists = false;
+ try {
+ AssetManager assetManager = getResources().getAssets();
+ InputStream is = assetManager.open(fileName);
+ exists = true;
+ is.close();
+ } catch(Exception e) {
+ ; // a non-existent asset is no error, the function's purpose is to check exactly that.
}
-
- @Override
- public boolean onQueryTextSubmit(String query) {
- return true; // action handled by listener
- }
-
- @Override
- public boolean onQueryTextChange(String query) {
- String normQuery = query.trim();
- lastQuery = normQuery;
- if (lastToast!=null) {
- lastToast.cancel();
- lastToast = null;
- }
- webView.findAllAsync(normQuery);
- return true; // action handled by listener
- }
-
- @Override
- public void onFindResultReceived (int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting)
- {
- if (isDoneCounting) {
- if (numberOfMatches>0) {
- updateResultCounter(activeMatchOrdinal, numberOfMatches);
- } else {
- if (lastQuery.isEmpty()) {
- updateResultCounter(-1, 0); // hide
- } else {
- String msg = getString(R.string.search_no_result_for_x, lastQuery);
- if (lastToast != null) {
- lastToast.cancel();
- }
- lastToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
- lastToast.show();
- updateResultCounter(0, 0); // show as "0/0"
- }
- }
- }
- }
-
-
- // other actions
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- super.onOptionsItemSelected(item);
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.menu_search_up:
- if (lastQuery.isEmpty()) {
- webView.scrollTo(0, 0);
- } else {
- webView.findNext(false);
- }
- return true;
- case R.id.menu_search_down:
- if (lastQuery.isEmpty()) {
- webView.scrollTo(0, 1000000000);
- } else {
- webView.findNext(true);
- }
- return true;
- case R.id.log_scroll_up:
- webView.scrollTo(0, 0);
- return true;
- case R.id.learn_more:
- openOnlineUrl("https://delta.chat");
- return true;
- case R.id.contribute:
- openOnlineUrl("https://github.com/deltachat/deltachat-android");
- return true;
- case R.id.report_issue:
- openOnlineUrl("https://github.com/deltachat/deltachat-android/issues");
- return true;
- }
- return false;
- }
-
- @Override
- public void onBackPressed() {
- if (webView.canGoBack()) {
- webView.goBack();
- } else {
- super.onBackPressed();
- }
- }
-
- private void openOnlineUrl(String url) {
- try {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
- } catch (ActivityNotFoundException e) {
- Toast.makeText(this, R.string.no_browser_installed, Toast.LENGTH_LONG).show();
- }
- }
-
- @Override
- public void onActivityResult(int reqCode, int resultCode, final Intent data) {
- super.onActivityResult(reqCode, resultCode, data);
- }
-
+ return exists;
+ }
}
diff --git a/src/org/thoughtcrime/securesms/WebViewActivity.java b/src/org/thoughtcrime/securesms/WebViewActivity.java
new file mode 100644
index 000000000..7833e8c8f
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/WebViewActivity.java
@@ -0,0 +1,220 @@
+package org.thoughtcrime.securesms;
+
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import androidx.appcompat.widget.SearchView;
+
+import org.thoughtcrime.securesms.util.DynamicLanguage;
+import org.thoughtcrime.securesms.util.DynamicTheme;
+
+public class WebViewActivity extends PassphraseRequiredActionBarActivity
+ implements SearchView.OnQueryTextListener,
+ WebView.FindListener
+{
+ private static final String TAG = WebViewActivity.class.getSimpleName();
+
+ protected WebView webView;
+ private final DynamicTheme dynamicTheme = new DynamicTheme();
+ protected final DynamicLanguage dynamicLanguage = new DynamicLanguage();
+
+ @Override
+ protected void onPreCreate() {
+ dynamicTheme.onCreate(this);
+ dynamicLanguage.onCreate(this);
+ }
+
+ @Override
+ protected void onCreate(Bundle state, boolean ready) {
+ setContentView(R.layout.web_view_activity);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ webView = findViewById(R.id.webview);
+ webView.setWebViewClient(new WebViewClient() {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ if (url != null) {
+ if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:")) {
+ openOnlineUrl(url);
+ return true;
+ }
+ }
+ return false;
+ }
+ });
+ webView.setFindListener(this);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ dynamicTheme.onResume(this);
+ dynamicLanguage.onResume(this);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ MenuInflater inflater = this.getMenuInflater();
+ menu.clear();
+
+ inflater.inflate(R.menu.web_view, menu);
+
+ try {
+ MenuItem searchItem = menu.findItem(R.id.menu_search_web_view);
+ searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
+ @Override
+ public boolean onMenuItemActionExpand(final MenuItem item) {
+ searchMenu = menu;
+ WebViewActivity.this.lastQuery = "";
+ WebViewActivity.this.makeSearchMenuVisible(menu, searchItem, true);
+ return true;
+ }
+
+ @Override
+ public boolean onMenuItemActionCollapse(final MenuItem item) {
+ WebViewActivity.this.makeSearchMenuVisible(menu, searchItem, false);
+ return true;
+ }
+ });
+ SearchView searchView = (SearchView) searchItem.getActionView();
+ searchView.setOnQueryTextListener(this);
+ searchView.setQueryHint(getString(R.string.search));
+ searchView.setIconifiedByDefault(true);
+
+ // hide the [X] beside the search field - this is too much noise, search can be aborted eg. by "back"
+ ImageView closeBtn = searchView.findViewById(R.id.search_close_btn);
+ if (closeBtn!=null) {
+ closeBtn.setEnabled(false);
+ closeBtn.setImageDrawable(null);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "cannot set up web-view-search: ", e);
+ }
+
+ super.onPrepareOptionsMenu(menu);
+ return true;
+ }
+
+
+ // search
+
+ private Menu searchMenu = null;
+ private String lastQuery = "";
+ private Toast lastToast = null;
+
+ private void updateResultCounter(int curr, int total) {
+ if (searchMenu!=null) {
+ MenuItem item = searchMenu.findItem(R.id.menu_search_counter);
+ if (curr!=-1) {
+ item.setTitle(String.format("%d/%d", total==0? 0 : curr+1, total));
+ item.setVisible(true);
+ } else {
+ item.setVisible(false);
+ }
+ }
+ }
+
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ return true; // action handled by listener
+ }
+
+ @Override
+ public boolean onQueryTextChange(String query) {
+ String normQuery = query.trim();
+ lastQuery = normQuery;
+ if (lastToast!=null) {
+ lastToast.cancel();
+ lastToast = null;
+ }
+ webView.findAllAsync(normQuery);
+ return true; // action handled by listener
+ }
+
+ @Override
+ public void onFindResultReceived (int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting)
+ {
+ if (isDoneCounting) {
+ if (numberOfMatches>0) {
+ updateResultCounter(activeMatchOrdinal, numberOfMatches);
+ } else {
+ if (lastQuery.isEmpty()) {
+ updateResultCounter(-1, 0); // hide
+ } else {
+ String msg = getString(R.string.search_no_result_for_x, lastQuery);
+ if (lastToast != null) {
+ lastToast.cancel();
+ }
+ lastToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
+ lastToast.show();
+ updateResultCounter(0, 0); // show as "0/0"
+ }
+ }
+ }
+ }
+
+
+ // other actions
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ super.onOptionsItemSelected(item);
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ case R.id.menu_search_up:
+ if (lastQuery.isEmpty()) {
+ webView.scrollTo(0, 0);
+ } else {
+ webView.findNext(false);
+ }
+ return true;
+ case R.id.menu_search_down:
+ if (lastQuery.isEmpty()) {
+ webView.scrollTo(0, 1000000000);
+ } else {
+ webView.findNext(true);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (webView.canGoBack()) {
+ webView.goBack();
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ protected void openOnlineUrl(String url) {
+ try {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(this, R.string.no_browser_installed, Toast.LENGTH_LONG).show();
+ }
+ }
+
+ @Override
+ public void onActivityResult(int reqCode, int resultCode, final Intent data) {
+ super.onActivityResult(reqCode, resultCode, data);
+ }
+}
diff --git a/src/org/thoughtcrime/securesms/util/DynamicTheme.java b/src/org/thoughtcrime/securesms/util/DynamicTheme.java
index 12836761d..6864f59e3 100644
--- a/src/org/thoughtcrime/securesms/util/DynamicTheme.java
+++ b/src/org/thoughtcrime/securesms/util/DynamicTheme.java
@@ -80,6 +80,11 @@ public class DynamicTheme {
}
}
+ // return a checkmark emoji that fits to the background of the selected theme.
+ public static String getCheckmarkEmoji(@NonNull Context context) {
+ return isDarkTheme(context) ? "✅" /*blue, white or white in a box*/ : "✔️" /*blue or black*/;
+ }
+
private static boolean isSystemInDarkTheme(@NonNull Context context) {
return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
diff --git a/src/org/thoughtcrime/securesms/util/Prefs.java b/src/org/thoughtcrime/securesms/util/Prefs.java
index 00a7dadfd..b70ecaf09 100644
--- a/src/org/thoughtcrime/securesms/util/Prefs.java
+++ b/src/org/thoughtcrime/securesms/util/Prefs.java
@@ -68,6 +68,9 @@ public class Prefs {
private static final String MAP_CENTER_LONGITUDE = "pref_map_center_longitude";
private static final String MAP_ZOOM = "pref_map_zoom";
+ public static final String ALWAYS_LOAD_REMOTE_CONTENT = "pref_always_load_remote_content";
+ public static final boolean ALWAYS_LOAD_REMOTE_CONTENT_DEFAULT = false;
+
public enum VibrateState {
DEFAULT(0), ENABLED(1), DISABLED(2);
private final int id;
@@ -303,6 +306,11 @@ public class Prefs {
return getBooleanPreference(context, SYSTEM_EMOJI_PREF, false);
}
+ public static boolean getAlwaysLoadRemoteContent(Context context) {
+ return getBooleanPreference(context, Prefs.ALWAYS_LOAD_REMOTE_CONTENT,
+ Prefs.ALWAYS_LOAD_REMOTE_CONTENT_DEFAULT);
+ }
+
// generic preference functions
public static void setBooleanPreference(Context context, String key, boolean value) {