From 70d0ba88e496b7a075e81601707d2586882d9903 Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Sun, 5 May 2024 16:47:12 -0300 Subject: [PATCH] fix(custom-tabs-setting): use upstream implementation Seriously, why do we do this? --- mastodon/src/main/AndroidManifest.xml | 4 ++ .../settings/SettingsBehaviorFragment.java | 59 +++++++++++++++++-- ...ert_single_choice_2lines_but_different.xml | 51 ++++++++++++++++ 3 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 mastodon/src/main/res/layout/item_alert_single_choice_2lines_but_different.xml diff --git a/mastodon/src/main/AndroidManifest.xml b/mastodon/src/main/AndroidManifest.xml index 422cb8b98a..69a320a390 100644 --- a/mastodon/src/main/AndroidManifest.xml +++ b/mastodon/src/main/AndroidManifest.xml @@ -25,6 +25,10 @@ + + + + implements HasAccountID{ private ListItem languageItem; - private CheckableListItem altTextItem, playGifsItem, customTabsItem, confirmUnfollowItem, confirmBoostItem, confirmDeleteItem; + private CheckableListItem altTextItem, playGifsItem, confirmUnfollowItem, confirmBoostItem, confirmDeleteItem; private MastodonLanguage postLanguage; private ComposeLanguageAlertViewController.SelectedOption newPostLanguage; // MEGALODON private MastodonLanguage.LanguageResolver languageResolver; - private ListItem prefixRepliesItem, replyVisibilityItem; + private ListItem prefixRepliesItem, replyVisibilityItem, customTabsItem; private CheckableListItem forwardReportsItem, remoteLoadingItem, showBoostsItem, showRepliesItem, loadNewPostsItem, seeNewPostsBtnItem, overlayMediaItem; // MOSHIDON @@ -49,11 +59,11 @@ public void onCreate(Bundle savedInstanceState){ List> items = new ArrayList<>(List.of( languageItem=new ListItem<>(getString(R.string.default_post_language), postLanguage!=null ? postLanguage.getDisplayName(getContext()) : null, R.drawable.ic_fluent_local_language_24_regular, this::onDefaultLanguageClick), + customTabsItem=new ListItem<>(getString(R.string.settings_custom_tabs), getString(GlobalUserPreferences.useCustomTabs ? R.string.in_app_browser : R.string.system_browser), R.drawable.ic_fluent_open_24_regular, this::onCustomTabsClick), altTextItem=new CheckableListItem<>(R.string.settings_alt_text_reminders, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.altTextReminders, R.drawable.ic_fluent_image_alt_text_24_regular, i->toggleCheckableItem(altTextItem)), showPostsWithoutAltItem=new CheckableListItem<>(R.string.mo_settings_show_posts_without_alt, R.string.mo_settings_show_posts_without_alt_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showPostsWithoutAlt, R.drawable.ic_fluent_eye_tracking_on_24_regular, i->toggleCheckableItem(showPostsWithoutAltItem)), playGifsItem=new CheckableListItem<>(R.string.settings_gif, R.string.mo_setting_play_gif_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.playGifs, R.drawable.ic_fluent_gif_24_regular, i->toggleCheckableItem(playGifsItem)), overlayMediaItem=new CheckableListItem<>(R.string.sk_settings_continues_playback, R.string.sk_settings_continues_playback_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.overlayMedia, R.drawable.ic_fluent_play_circle_hint_24_regular, i->toggleCheckableItem(overlayMediaItem)), - customTabsItem=new CheckableListItem<>(R.string.settings_custom_tabs, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.useCustomTabs, R.drawable.ic_fluent_link_24_regular, i->toggleCheckableItem(customTabsItem)), confirmUnfollowItem=new CheckableListItem<>(R.string.settings_confirm_unfollow, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmUnfollow, R.drawable.ic_fluent_person_delete_24_regular, i->toggleCheckableItem(confirmUnfollowItem)), confirmBoostItem=new CheckableListItem<>(R.string.settings_confirm_boost, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmBoost, R.drawable.ic_fluent_arrow_repeat_all_24_regular, i->toggleCheckableItem(confirmBoostItem)), confirmDeleteItem=new CheckableListItem<>(R.string.settings_confirm_delete_post, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmDeletePost, R.drawable.ic_fluent_delete_24_regular, i->toggleCheckableItem(confirmDeleteItem)), @@ -166,12 +176,53 @@ private void onLoadNewPostsClick(){ rebindItem(seeNewPostsBtnItem); } + private void onCustomTabsClick(ListItem item){ +// GlobalUserPreferences.useCustomTabs=customTabsItem.checked; + Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")); + ResolveInfo info=getActivity().getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); + final String browserName; + if(info==null){ + browserName="??"; + }else{ + browserName=info.loadLabel(getActivity().getPackageManager()).toString(); + } + ArrayAdapter adapter=new ArrayAdapter<>(getActivity(), R.layout.item_alert_single_choice_2lines_but_different, R.id.text, + new String[]{getString(R.string.in_app_browser), getString(R.string.system_browser)}){ + @Override + public boolean hasStableIds(){ + return true; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent){ + View view=super.getView(position, convertView, parent); + TextView subtitle=view.findViewById(R.id.subtitle); + if(position==0){ + subtitle.setVisibility(View.GONE); + }else{ + subtitle.setVisibility(View.VISIBLE); + subtitle.setText(browserName); + } + return view; + } + }; + new M3AlertDialogBuilder(getActivity()) + .setTitle(R.string.settings_custom_tabs) + .setSingleChoiceItems(adapter, GlobalUserPreferences.useCustomTabs ? 0 : 1, (dlg, which)->{ + GlobalUserPreferences.useCustomTabs=which==0; + customTabsItem.subtitleRes=GlobalUserPreferences.useCustomTabs ? R.string.in_app_browser : R.string.system_browser; + rebindItem(customTabsItem); + dlg.dismiss(); + }) + .show(); + } + @Override protected void onHidden(){ super.onHidden(); GlobalUserPreferences.playGifs=playGifsItem.checked; GlobalUserPreferences.overlayMedia=overlayMediaItem.checked; - GlobalUserPreferences.useCustomTabs=customTabsItem.checked; GlobalUserPreferences.altTextReminders=altTextItem.checked; GlobalUserPreferences.confirmUnfollow=confirmUnfollowItem.checked; GlobalUserPreferences.confirmBoost=confirmBoostItem.checked; diff --git a/mastodon/src/main/res/layout/item_alert_single_choice_2lines_but_different.xml b/mastodon/src/main/res/layout/item_alert_single_choice_2lines_but_different.xml new file mode 100644 index 0000000000..185b343fb2 --- /dev/null +++ b/mastodon/src/main/res/layout/item_alert_single_choice_2lines_but_different.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + \ No newline at end of file