mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add option to view full (html) message (#1763)
* add get-mime-original apis * remove unused control * add 'Show full message' buttons * split reusable WebViewActivity from LocalHelpActivity * add FullMsgActivity * load html via AsyncTask * adapt to changed api * handle mailto:-links in WebView * block loading remote images by default, add user setting always/once/never * do not hide 'Once' button in always-mode, playing around a day with hidden 'Once' that looks more like a bug :) * wording: as 'Always' affects all messages, it is better to speak of multiple senders * wording: use 'Load remote images' this makes it easier for the user to find the option if one sees, images are missing in the document. * wording: shorten text. * wording: change 'may' to 'can'. 'may' sounds a bit as if someone allows this. * Don't use AsyncTask * check 'once' if appropriate * use lite-colored checkbox-emoji in dark-theme * add comment about missing error logging Co-authored-by: Hocuri <hocuri@gmx.de>
This commit is contained in:
@@ -277,6 +277,11 @@
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".FullMsgActivity"
|
||||
android:theme="@style/TextSecure.LightTheme"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".map.MapActivity" />
|
||||
|
||||
<service android:name=".connect.KeepAliveService" android:enabled="true" />
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -151,6 +151,23 @@
|
||||
app:scaleEmojis="true"
|
||||
tools:text="Mango pickle lorem ipsum"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/show_full_message"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
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"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.ConversationItemFooter
|
||||
android:id="@+id/conversation_item_footer"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -129,10 +129,22 @@
|
||||
app:scaleEmojis="true"
|
||||
tools:text="Mango pickle lorem ipsum"/>
|
||||
|
||||
<TextView
|
||||
<Button
|
||||
android:id="@+id/show_full_message"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone" />
|
||||
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"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.ConversationItemFooter
|
||||
android:id="@+id/conversation_item_footer"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/load_remote_content"
|
||||
android:id="@+id/load_remote_content" />
|
||||
|
||||
</menu>
|
||||
+1
-23
@@ -2,28 +2,6 @@
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/search"
|
||||
android:id="@+id/menu_search_localhelp"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|never" />
|
||||
|
||||
<item android:title="0/0"
|
||||
android:id="@+id/menu_search_counter"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/back"
|
||||
android:id="@+id/menu_search_up"
|
||||
android:icon="@drawable/ic_search_up"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/next"
|
||||
android:id="@+id/menu_search_down"
|
||||
android:icon="@drawable/ic_search_down"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/menu_scroll_to_top"
|
||||
android:id="@+id/log_scroll_up" />
|
||||
|
||||
@@ -39,4 +17,4 @@
|
||||
android:id="@+id/report_issue"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
</menu>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/search"
|
||||
android:id="@+id/menu_search_web_view"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|never" />
|
||||
|
||||
<item android:title="0/0"
|
||||
android:id="@+id/menu_search_counter"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/back"
|
||||
android:id="@+id/menu_search_up"
|
||||
android:icon="@drawable/ic_search_up"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/next"
|
||||
android:id="@+id/menu_search_down"
|
||||
android:icon="@drawable/ic_search_down"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
</menu>
|
||||
@@ -39,6 +39,12 @@
|
||||
<string name="profile">Profile</string>
|
||||
<string name="main_menu">Main menu</string>
|
||||
<string name="start_chat">Start chat</string>
|
||||
<string name="show_full_message">Show full message…</string>
|
||||
<string name="load_remote_content">Load remote images</string>
|
||||
<!-- possible answers to the question are: Never, Always, Once -->
|
||||
<string name="load_remote_content_ask">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?</string>
|
||||
<string name="always">Always</string>
|
||||
<string name="once">Once</string>
|
||||
<string name="show_password">Show password</string>
|
||||
<string name="hide_password">Hide password</string>
|
||||
<string name="not_now">Not now</string>
|
||||
|
||||
@@ -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[]);
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -28,5 +28,6 @@ public interface BindableConversationItem extends Unbindable {
|
||||
|
||||
interface EventListener {
|
||||
void onQuoteClicked(DcMsg messageRecord);
|
||||
void onShowFullClicked(DcMsg messageRecord);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<DcMsg> 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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<FullMsgActivity> 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user