External links popup (#294)

* Add settings switch for external links popup

* Add warning popup when entering external links

* Fix typo

This reverts commit 9da984c72e3867dd63e2d8e9e38cd9020e633844.
This commit is contained in:
Albert 2017-11-28 21:33:35 +01:00 committed by Isaac Hutt
parent 9f61c49c29
commit 0e0c90080e
5 changed files with 58 additions and 2 deletions

View File

@ -163,6 +163,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
public static final String PREF_STORAGE_TITLE = "pref_selected_title";
public static final String PREF_EXTERNAL_LINK_POPUP = "pref_external_link_popup";
public static final String contactEmailAddress = "android@kiwix.org";
public static boolean isFullscreenOpened;
@ -181,6 +183,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
private boolean isOpenNewTabInBackground;
private boolean isExternalLinkPopup;
public static boolean refresh;
public static boolean wifiOnly;
@ -920,13 +924,53 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
@Override
public void openExternalUrl(Intent intent) {
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
// Show popup with warning that this url is external and could lead to additional costs
// or may event not work when the user is offline.
if (intent.hasExtra("external_link")
&& intent.getBooleanExtra("external_link", false)
&& isExternalLinkPopup) {
externalLinkPopup(intent);
} else {
startActivity(intent);
}
} else {
String error = getString(R.string.no_reader_application_installed);
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
}
private void externalLinkPopup(Intent intent) {
new AlertDialog.Builder(this, dialogStyle())
.setTitle(R.string.external_link_popup_dialog_title)
.setMessage(R.string.external_link_popup_dialog_message)
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// do nothing
}
})
.setNeutralButton(R.string.do_not_ask_anymore, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
PreferenceManager
.getDefaultSharedPreferences(KiwixMobileActivity.this)
.edit()
.putBoolean(PREF_EXTERNAL_LINK_POPUP, false)
.apply();
isExternalLinkPopup = false;
startActivity(intent);
}
})
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startActivity(intent);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
public boolean openZimFile(File file, boolean clearHistory) {
if (file.canRead() || Build.VERSION.SDK_INT < 19 || (BuildConfig.IS_CUSTOM_APP
@ -1568,6 +1612,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
isFullscreenOpened = sharedPreferences.getBoolean(PREF_FULLSCREEN, false);
boolean isZoomEnabled = sharedPreferences.getBoolean(PREF_ZOOM_ENABLED, false);
isOpenNewTabInBackground = sharedPreferences.getBoolean(PREF_NEW_TAB_BACKGROUND, false);
isExternalLinkPopup = sharedPreferences.getBoolean(PREF_EXTERNAL_LINK_POPUP, true);
if (isZoomEnabled) {
int zoomScale = (int) sharedPreferences.getFloat(PREF_ZOOM, 100.0f);

View File

@ -56,6 +56,7 @@ public class KiwixWebViewClient extends WebViewClient {
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra("external_link", true);
callback.openExternalUrl(intent);
return true;
}

View File

@ -87,7 +87,6 @@ public class KiwixSettingsActivity extends AppCompatActivity {
public static final String PREF_WIFI_ONLY = "pref_wifi_only";
public static final String PREF_BOTTOM_TOOLBAR = "pref_bottomtoolbar";
public static String zimFile;

View File

@ -182,4 +182,9 @@
<string name="language_count">(%1$d)</string>
<string name="pref_multi_search_title">MultiZim Search</string>
<string name="pref_multi_search_summary">Allow app to search the across ZIM files (Warning Very Experimental).</string>
<string name="pref_external_link_popup_title">Warn when entering external links</string>
<string name="pref_external_link_popup_summary">Display popup to warn about additional costs or not working in offline links.</string>
<string name="external_link_popup_dialog_title">Entering External Link</string>
<string name="external_link_popup_dialog_message">You are entering an external link. This could lead to additional costs for data transfer or will just not work when you are offline. Do you want to continue?</string>
<string name="do_not_ask_anymore">Do not ask anymore</string>
</resources>

View File

@ -46,6 +46,12 @@
android:title="@string/pref_newtab_background_title"
android:summary="@string/pref_newtab_background_summary"/>
<org.kiwix.kiwixmobile.settings.CustomSwitchPreference
android:defaultValue="true"
android:key="pref_external_link_popup"
android:title="@string/pref_external_link_popup_title"
android:summary="@string/pref_external_link_popup_summary"/>
<org.kiwix.kiwixmobile.settings.CustomSwitchPreference
android:defaultValue="false"
android:key="pref_full_text_search"