for security reasons, clicking the external links in the on the Help screen no longer opens website directly, but instead triggers the share URL dialog
This commit is contained in:
parent
60aba7084d
commit
0ff354a4eb
15 changed files with 73 additions and 6 deletions
|
|
@ -10,7 +10,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.app.ActionBar;
|
||||
|
||||
abstract public class WebViewActivity extends EdgeToEdgeActivity implements View.OnAttachStateChangeListener {
|
||||
private WebView container;
|
||||
private WebView webView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
|
@ -28,7 +28,7 @@ abstract public class WebViewActivity extends EdgeToEdgeActivity implements View
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
container.removeOnAttachStateChangeListener(this);
|
||||
webView.removeOnAttachStateChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -52,8 +52,9 @@ abstract public class WebViewActivity extends EdgeToEdgeActivity implements View
|
|||
}
|
||||
|
||||
private void setContent() {
|
||||
container = new WebView(this);
|
||||
container.addOnAttachStateChangeListener(this);
|
||||
webView = new WebView(this);
|
||||
webView.addOnAttachStateChangeListener(this);
|
||||
webView.setWebViewClient(new WebViewSafeClient(this));
|
||||
|
||||
// On API > 30 the WebView does not load the entire String with .loadData(),
|
||||
// so we need to do this weird shit.
|
||||
|
|
@ -61,9 +62,9 @@ abstract public class WebViewActivity extends EdgeToEdgeActivity implements View
|
|||
// Reference: https://developer.android.com/develop/ui/views/layout/webapps/webview
|
||||
String text = getText();
|
||||
String encodedHtml = "app:" + Base64.encodeToString(text.getBytes(), Base64.NO_PADDING);
|
||||
container.loadDataWithBaseURL(encodedHtml, text, getMimeType(), "UTF-8", null);
|
||||
webView.loadDataWithBaseURL(encodedHtml, text, getMimeType(), "UTF-8", null);
|
||||
|
||||
setContentView(container);
|
||||
setContentView(webView);
|
||||
}
|
||||
|
||||
abstract protected String getText();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
package io.github.sspanak.tt9.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.util.Clipboard;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class WebViewSafeClient extends WebViewClient {
|
||||
private final Activity activity;
|
||||
|
||||
public WebViewSafeClient(@NonNull Activity activity) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (!url.startsWith("http")) {
|
||||
return super.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || !shareLink(url)) {
|
||||
Clipboard.copy(activity, url);
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
UI.toastShortSingle(activity, R.string.help_url_copied);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean shareLink(String url) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
|
||||
try {
|
||||
activity.startActivity(Intent.createChooser(intent, "Share URL"));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Logger.d(getClass().getSimpleName(), "Failed sharing URL: '" + url + "'. " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -169,6 +169,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Импортиране на думи от по-рано експортирано CSV.</string>
|
||||
<string name="dictionary_import_progress">Импортиране на CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Импортиране на CSV…</string>
|
||||
<string name="help_url_copied">Връзката е копирана.</string>
|
||||
<string name="language_selection_language_loaded">(зареден)</string>
|
||||
<string name="language_selection_title">Избор на езици</string>
|
||||
<string name="language_selection_search_placeholder">Търси езици</string>
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Wörter aus einer zuvor exportierten CSV-Datei importieren.</string>
|
||||
<string name="dictionary_import_progress">CSV importieren (%1$s)…</string>
|
||||
<string name="dictionary_import_running">CSV importieren…</string>
|
||||
<string name="help_url_copied">Der Link ist kopiert.</string>
|
||||
<string name="language_selection_language_loaded">(geladen)</string>
|
||||
<string name="language_selection_title">Sprachen aktivieren</string>
|
||||
<string name="language_selection_search_placeholder">Nach Sprachen suchen</string>
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Importar palabras de un CSV previamente exportado.</string>
|
||||
<string name="dictionary_import_progress">Importando CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Importando CSV…</string>
|
||||
<string name="help_url_copied">El enlace ha sido copiado.</string>
|
||||
<string name="language_selection_language_loaded">(cargado)</string>
|
||||
<string name="language_selection_title">Habilitar idiomas</string>
|
||||
<string name="language_selection_search_placeholder">Buscar idiomas</string>
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Importer des mots à partir d\'un fichier CSV précédemment exporté.</string>
|
||||
<string name="dictionary_import_progress">Importation de CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Importation de CSV…</string>
|
||||
<string name="help_url_copied">Le lien est copié.</string>
|
||||
<string name="language_selection_language_loaded">(chargée)</string>
|
||||
<string name="language_selection_title">Activer les langues</string>
|
||||
<string name="language_selection_search_placeholder">Rechercher des langues</string>
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Importare parole da un CSV precedentemente esportato.</string>
|
||||
<string name="dictionary_import_progress">Importazione CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Importazione CSV…</string>
|
||||
<string name="help_url_copied">Il link è copiato.</string>
|
||||
<string name="language_selection_language_loaded">(caricata)</string>
|
||||
<string name="language_selection_title">Abilita lingue</string>
|
||||
<string name="language_selection_search_placeholder">Cerca lingue</string>
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">ייבוא מילים מקובץ CSV שיוצא קודם לכן.</string>
|
||||
<string name="dictionary_import_progress">מייבא CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">מייבא CSV…</string>
|
||||
<string name="help_url_copied">הקישור הועתק.</string>
|
||||
<string name="language_selection_language_loaded">(נטען)</string>
|
||||
<string name="language_selection_title">הפעל שפות</string>
|
||||
<string name="language_selection_search_placeholder">חיפוש שפות</string>
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Importuoti žodžius iš anksčiau eksportuoto CSV.</string>
|
||||
<string name="dictionary_import_progress">Importuojamas CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Importuojamas CSV…</string>
|
||||
<string name="help_url_copied">Nuoroda nukopijuota.</string>
|
||||
<string name="language_selection_language_loaded">(įkelta)</string>
|
||||
<string name="language_selection_title">Įjungti kalbas</string>
|
||||
<string name="language_selection_search_placeholder">Ieškoti kalbų</string>
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Woorden importeren uit een eerder geëxporteerde CSV.</string>
|
||||
<string name="dictionary_import_progress">CSV importeren (%1$s)…</string>
|
||||
<string name="dictionary_import_running">CSV importeren…</string>
|
||||
<string name="help_url_copied">Link is gekopieerd.</string>
|
||||
<string name="language_selection_language_loaded">(geladen)</string>
|
||||
<string name="language_selection_title">Talen inschakelen</string>
|
||||
<string name="language_selection_search_placeholder">Zoeken naar talen</string>
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Importar palavras de um CSV previamente exportado.</string>
|
||||
<string name="dictionary_import_progress">Importando CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Importando CSV…</string>
|
||||
<string name="help_url_copied">O link foi copiado.</string>
|
||||
<string name="language_selection_language_loaded">(carregado)</string>
|
||||
<string name="language_selection_title">Habilitar idiomas</string>
|
||||
<string name="language_selection_search_placeholder">Buscar por idiomas</string>
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Импортировать слова из ранее экспортированного CSV.</string>
|
||||
<string name="dictionary_import_progress">Импортирование CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Импортирование CSV…</string>
|
||||
<string name="help_url_copied">Ссылка скопирована.</string>
|
||||
<string name="language_selection_language_loaded">(загружен)</string>
|
||||
<string name="language_selection_title">Включить языки</string>
|
||||
<string name="language_selection_search_placeholder">Поиск языков</string>
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Daha önce dışa aktarılan bir CSV\'den kelimeleri içe aktar.</string>
|
||||
<string name="dictionary_import_progress">CSV İçe aktarılıyor (%1$s)…</string>
|
||||
<string name="dictionary_import_running">CSV İçe aktarılıyor…</string>
|
||||
<string name="help_url_copied">Bağlantı kopyalandı.</string>
|
||||
<string name="language_selection_language_loaded">(yüklendi)</string>
|
||||
<string name="language_selection_title">Dilleri etkinleştir</string>
|
||||
<string name="language_selection_search_placeholder">Diller için arama</string>
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@
|
|||
<string name="dictionary_import_custom_words_summary">Імпортувати слова з раніше експортованого CSV.</string>
|
||||
<string name="dictionary_import_progress">Імпорт CSV (%1$s)…</string>
|
||||
<string name="dictionary_import_running">Імпорт CSV…</string>
|
||||
<string name="help_url_copied">Посилання скопійовано.</string>
|
||||
<string name="language_selection_language_loaded">(завантажено)</string>
|
||||
<string name="language_selection_title">Увімкнути мови</string>
|
||||
<string name="language_selection_search_placeholder">Пошук мов</string>
|
||||
|
|
|
|||
|
|
@ -160,6 +160,8 @@
|
|||
<string name="function_reset_keys_title">Restore Default Keys</string>
|
||||
<string name="function_reset_keys_done">Default key settings restored.</string>
|
||||
|
||||
<string name="help_url_copied">URL copied.</string>
|
||||
|
||||
<string name="language_selection_language_loaded">(loaded)</string>
|
||||
<string name="language_selection_title">Enable Languages</string>
|
||||
<string name="language_selection_search_placeholder">Search for Languages</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue