Persist view state open link

This commit is contained in:
M66B 2023-03-30 09:50:16 +02:00
parent bc7ebeb79b
commit 1076a99c53
3 changed files with 38 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.RemoteAction;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentResolver;
@ -6125,15 +6126,30 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
fragment.setArguments(args);
fragment.show(parentFragment.getParentFragmentManager(), "open:link");
} else {
boolean sanitize = prefs.getBoolean(chost + ".sanitize", false);
if (sanitize && UriHelper.isHyperLink(uri)) {
boolean link_view = prefs.getBoolean(chost + ".link_view", false);
boolean link_sanitize = prefs.getBoolean(chost + ".link_sanitize", false);
if (link_sanitize && UriHelper.isHyperLink(uri)) {
Uri sanitized = UriHelper.sanitize(uri);
if (sanitized != null)
uri = sanitized;
Log.i("Open sanitized=" + uri);
}
boolean tabs = prefs.getBoolean("open_with_tabs", true);
Helper.view(context, UriHelper.guessScheme(uri), !tabs, !tabs);
if (link_view) {
Log.i("Open view=" + uri);
Intent view = new Intent(Intent.ACTION_VIEW, UriHelper.fix(uri));
Intent chooser = Intent.createChooser(view, context.getString(R.string.title_select_app));
try {
context.startActivity(chooser);
} catch (ActivityNotFoundException ex) {
Log.w(ex);
Helper.view(context, uri, true, true);
}
} else {
boolean tabs = prefs.getBoolean("open_with_tabs", true);
Helper.view(context, UriHelper.guessScheme(uri), !tabs, !tabs);
}
}
}

View File

@ -753,8 +753,13 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (UriHelper.isHyperLink(uri))
prefs.edit().putBoolean(chost + ".sanitize", cbNotAgain.isChecked()).apply();
if (chost != null &&
cbNotAgain.getVisibility() == View.VISIBLE && cbNotAgain.isChecked())
prefs.edit()
.putBoolean(chost + ".link_view", false)
.putBoolean(chost + ".link_sanitize",
cbSanitize.getVisibility() == View.VISIBLE && cbSanitize.isChecked())
.apply();
Uri theUri = Uri.parse(etLink.getText().toString());
Package pkg = (Package) spOpenWith.getSelectedItem();
@ -772,6 +777,14 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
.setNeutralButton(R.string.title_browse, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (chost != null &&
cbNotAgain.getVisibility() == View.VISIBLE && cbNotAgain.isChecked())
prefs.edit()
.putBoolean(chost + ".link_view", true)
.putBoolean(chost + ".link_sanitize",
cbSanitize.getVisibility() == View.VISIBLE && cbSanitize.isChecked())
.apply();
// https://developer.android.com/training/basics/intents/sending#AppChooser
Uri theUri = Uri.parse(etLink.getText().toString());
Log.i("Open link with uri=" + theUri);

View File

@ -2256,7 +2256,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
(key.startsWith("announcement.") && cbGeneral.isChecked()) ||
(key.endsWith(".show_full") && cbFull.isChecked()) ||
(key.endsWith(".show_images") && cbImages.isChecked()) ||
(key.endsWith(".confirm_link") && cbLinks.isChecked())) {
(key.endsWith(".confirm_link") && cbLinks.isChecked())||
(key.endsWith(".link_view") && cbLinks.isChecked())||
(key.endsWith(".link_sanitize") && cbLinks.isChecked())) {
Log.i("Removing option=" + key);
editor.remove(key);
}