diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java index b304c6e82e..84bceb46fc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java @@ -115,7 +115,7 @@ protected void doLoadData(int offset, int count){ onDataLoaded(results.stream().map(sr->{ SearchResultViewModel vm=new SearchResultViewModel(sr, accountID, true); if(sr.type==SearchResult.Type.HASHTAG){ - vm.hashtagItem.onClick=()->openHashtag(sr); + vm.hashtagItem.setOnClick(i->openHashtag(sr)); } return vm; }).collect(Collectors.toList()), false); @@ -132,7 +132,7 @@ public void onSuccess(SearchResults result){ .map(sr->{ SearchResultViewModel vm=new SearchResultViewModel(sr, accountID, false); if(sr.type==SearchResult.Type.HASHTAG){ - vm.hashtagItem.onClick=()->openHashtag(sr); + vm.hashtagItem.setOnClick(i->openHashtag(sr)); } return vm; }) @@ -429,11 +429,11 @@ private void onSearchViewEnter(){ wrapSuicideDialog(()->deliverResult(currentQuery, null)); } - private void onOpenURLClick(){ + private void onOpenURLClick(ListItem item_){ UiUtils.openURL(getContext(), accountID, searchViewHelper.getQuery(), false); } - private void onGoToHashtagClick(){ + private void onGoToHashtagClick(ListItem item_){ wrapSuicideDialog(()->{ String q=searchViewHelper.getQuery(); if(q.startsWith("#")) @@ -442,7 +442,7 @@ private void onGoToHashtagClick(){ }); } - private void onGoToAccountClick(){ + private void onGoToAccountClick(ListItem item_){ String q=searchViewHelper.getQuery(); if(!q.startsWith("@")){ q="@"+q; @@ -459,11 +459,11 @@ private void onGoToAccountClick(){ }).ifPresent(progress -> progress.wrapProgress((Activity) getContext(), R.string.loading, true)); } - private void onGoToStatusSearchClick(){ + private void onGoToStatusSearchClick(ListItem item_){ wrapSuicideDialog(()->deliverResult(searchViewHelper.getQuery(), SearchResult.Type.STATUS)); } - private void onGoToAccountSearchClick(){ + private void onGoToAccountSearchClick(ListItem item_){ wrapSuicideDialog(()->deliverResult(searchViewHelper.getQuery(), SearchResult.Type.ACCOUNT)); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/EditFilterFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/EditFilterFragment.java index 4655c4169d..bee767c193 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/EditFilterFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/EditFilterFragment.java @@ -73,7 +73,7 @@ public void onCreate(Bundle savedInstanceState){ durationItem=new ListItem<>(R.string.settings_filter_duration, 0, this::onDurationClick), wordsItem=new ListItem<>(R.string.settings_filter_muted_words, 0, this::onWordsClick), contextItem=new ListItem<>(R.string.settings_filter_context, 0, this::onContextClick), - cwItem=new CheckableListItem<>(R.string.settings_filter_show_cw, R.string.settings_filter_show_cw_explanation, CheckableListItem.Style.SWITCH, filter==null || filter.filterAction==FilterAction.WARN, ()->toggleCheckableItem(cwItem)) + cwItem=new CheckableListItem<>(R.string.settings_filter_show_cw, R.string.settings_filter_show_cw_explanation, CheckableListItem.Style.SWITCH, filter==null || filter.filterAction==FilterAction.WARN, this::toggleCheckableItem) )); if(filter!=null){ @@ -113,7 +113,7 @@ protected int indexOfItemsAdapter(){ return 1; } - private void onDurationClick(){ + private void onDurationClick(ListItem item_){ int[] durationOptions={ 1800, 3600, @@ -182,21 +182,21 @@ private void showCustomDurationAlert(Instant currentValue, Consumer cal alert.setOnDismissListener(dialog->callback.accept(null)); } - private void onWordsClick(){ + private void onWordsClick(ListItem item){ Bundle args=new Bundle(); args.putString("account", accountID); args.putParcelableArrayList("words", (ArrayList) keywords.stream().map(Parcels::wrap).collect(Collectors.toCollection(ArrayList::new))); Nav.goForResult(getActivity(), FilterWordsFragment.class, args, WORDS_RESULT, this); } - private void onContextClick(){ + private void onContextClick(ListItem item){ Bundle args=new Bundle(); args.putString("account", accountID); args.putSerializable("context", context); Nav.goForResult(getActivity(), FilterContextFragment.class, args, CONTEXT_RESULT, this); } - private void onDeleteClick(){ + private void onDeleteClick(ListItem item_){ AlertDialog alert=new M3AlertDialogBuilder(getActivity()) .setTitle(getString(R.string.settings_delete_filter_title, filter.title)) .setMessage(R.string.settings_delete_filter_confirmation) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterContextFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterContextFragment.java index 233c00cb59..37d9110726 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterContextFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterContextFragment.java @@ -22,10 +22,9 @@ public void onCreate(Bundle savedInstanceState){ setTitle(R.string.settings_filter_context); context=(EnumSet) getArguments().getSerializable("context"); onDataLoaded(Arrays.stream(FilterContext.values()).map(c->{ - CheckableListItem item=new CheckableListItem<>(c.getDisplayNameRes(), 0, CheckableListItem.Style.CHECKBOX, context.contains(c), null); + CheckableListItem item=new CheckableListItem<>(c.getDisplayNameRes(), 0, CheckableListItem.Style.CHECKBOX, context.contains(c), this::toggleCheckableItem); item.parentObject=c; item.isEnabled=true; - item.onClick=()->toggleCheckableItem(item); return item; }).collect(Collectors.toList())); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterWordsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterWordsFragment.java index 8ce67f89f2..d6e854242e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterWordsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/FilterWordsFragment.java @@ -1,11 +1,6 @@ package org.joinmastodon.android.fragments.settings; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.IntEvaluator; -import android.animation.ObjectAnimator; import android.app.AlertDialog; -import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; @@ -27,6 +22,7 @@ import org.joinmastodon.android.model.viewmodel.CheckableListItem; import org.joinmastodon.android.model.viewmodel.ListItem; import org.joinmastodon.android.ui.M3AlertDialogBuilder; +import org.joinmastodon.android.ui.utils.ActionModeHelper; import org.joinmastodon.android.ui.utils.SimpleTextWatcher; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.FloatingHintEditTextLayout; @@ -37,7 +33,6 @@ import java.util.List; import java.util.stream.Collectors; -import me.grishka.appkit.FragmentStackActivity; import me.grishka.appkit.fragments.OnBackPressedListener; import me.grishka.appkit.utils.V; @@ -60,7 +55,7 @@ public void onCreate(Bundle savedInstanceState){ FilterKeyword word=Parcels.unwrap(p); ListItem item=new ListItem<>(word.keyword, null, null, word); item.isEnabled=true; - item.onClick=()->onWordClick(item); + item.setOnClick(this::onWordClick); return item; }).collect(Collectors.toList())); setHasOptionsMenu(true); @@ -114,7 +109,7 @@ public void onApplyWindowInsets(WindowInsets insets){ @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){ - inflater.inflate(R.menu.settings_filter_words, menu); + inflater.inflate(R.menu.selectable_list, menu); } @Override @@ -174,7 +169,7 @@ private void showAlertForWord(FilterKeyword word){ w.keyword=input; ListItem item=new ListItem<>(w.keyword, null, null, w); item.isEnabled=true; - item.onClick=()->onWordClick(item); + item.setOnClick(this::onWordClick); data.add(item); itemsAdapter.notifyItemInserted(data.size()-1); }else{ @@ -228,29 +223,15 @@ private void enterSelectionMode(boolean selectAll){ return; V.setVisibilityAnimated(fab, View.GONE); - actionMode=getActivity().startActionMode(new ActionMode.Callback(){ + actionMode=ActionModeHelper.startActionMode(this, ()->elevationOnScrollListener.getCurrentStatusBarColor(), new ActionMode.Callback(){ @Override public boolean onCreateActionMode(ActionMode mode, Menu menu){ - ObjectAnimator anim=ObjectAnimator.ofInt(getActivity().getWindow(), "statusBarColor", elevationOnScrollListener.getCurrentStatusBarColor(), UiUtils.getThemeColor(getActivity(), R.attr.colorM3Primary)); - anim.setEvaluator(new IntEvaluator(){ - @Override - public Integer evaluate(float fraction, Integer startValue, Integer endValue){ - return UiUtils.alphaBlendColors(startValue, endValue, fraction); - } - }); - anim.start(); - ((FragmentStackActivity) getActivity()).invalidateSystemBarColors(FilterWordsFragment.this); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu){ mode.getMenuInflater().inflate(R.menu.settings_filter_words_action_mode, menu); - for(int i=0;i item=data.get(i); CheckableListItem newItem=new CheckableListItem<>(item.title, null, CheckableListItem.Style.CHECKBOX, selectAll, null); newItem.isEnabled=true; - newItem.onClick=()->onSelectionModeWordClick(newItem); + newItem.setOnClick(this::onSelectionModeWordClick); newItem.parentObject=item.parentObject; if(selectAll) selectedItems.add(newItem); @@ -313,7 +279,7 @@ private void leaveSelectionMode(boolean fromActionMode){ ListItem item=data.get(i); ListItem newItem=new ListItem<>(item.title, null, null); newItem.isEnabled=true; - newItem.onClick=()->onWordClick(newItem); + newItem.setOnClick(this::onWordClick); newItem.parentObject=item.parentObject; data.set(i, newItem); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsAboutAppFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsAboutAppFragment.java index 1bfb5c5db8..0ec9c7177a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsAboutAppFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsAboutAppFragment.java @@ -33,10 +33,10 @@ public void onCreate(Bundle savedInstanceState){ setTitle(getString(R.string.about_app, getString(R.string.sk_app_name))); AccountSession s=AccountSessionManager.get(accountID); onDataLoaded(List.of( - new ListItem<>(R.string.sk_settings_donate, 0, R.drawable.ic_fluent_heart_24_regular, ()->UiUtils.openHashtagTimeline(getActivity(), accountID, getString(R.string.donate_hashtag))), - new ListItem<>(R.string.sk_settings_contribute, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), getString(R.string.repo_url))), - new ListItem<>(R.string.settings_tos, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/terms")), - new ListItem<>(R.string.settings_privacy_policy, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), getString(R.string.privacy_policy_url)), 0, true), + new ListItem<>(R.string.sk_settings_donate, 0, R.drawable.ic_fluent_heart_24_regular, i->UiUtils.openHashtagTimeline(getActivity(), accountID, getString(R.string.donate_hashtag))), + new ListItem<>(R.string.sk_settings_contribute, 0, R.drawable.ic_fluent_open_24_regular, i->UiUtils.launchWebBrowser(getActivity(), getString(R.string.repo_url))), + new ListItem<>(R.string.settings_tos, 0, R.drawable.ic_fluent_open_24_regular, i->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/terms")), + new ListItem<>(R.string.settings_privacy_policy, 0, R.drawable.ic_fluent_open_24_regular, i->UiUtils.launchWebBrowser(getActivity(), getString(R.string.privacy_policy_url)), 0, true), mediaCacheItem=new ListItem<>(R.string.settings_clear_cache, 0, this::onClearMediaCacheClick) )); @@ -63,7 +63,7 @@ protected RecyclerView.Adapter getAdapter(){ return adapter; } - private void onClearMediaCacheClick(){ + private void onClearMediaCacheClick(ListItem item){ MastodonAPIController.runInBackground(()->{ Activity activity=getActivity(); ImageCache.getInstance(getActivity()).clear(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java index ff080775a8..93ccd17faa 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBehaviorFragment.java @@ -46,20 +46,20 @@ 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), - altTextItem=new CheckableListItem<>(R.string.settings_alt_text_reminders, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.altTextReminders, R.drawable.ic_fluent_image_alt_text_24_regular, ()->toggleCheckableItem(altTextItem)), - playGifsItem=new CheckableListItem<>(R.string.settings_gif, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.playGifs, R.drawable.ic_fluent_gif_24_regular, ()->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, ()->toggleCheckableItem(overlayMediaItem)), - customTabsItem=new CheckableListItem<>(R.string.settings_custom_tabs, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.useCustomTabs, R.drawable.ic_fluent_link_24_regular, ()->toggleCheckableItem(customTabsItem)), - confirmUnfollowItem=new CheckableListItem<>(R.string.settings_confirm_unfollow, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmUnfollow, R.drawable.ic_fluent_person_delete_24_regular, ()->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, ()->toggleCheckableItem(confirmBoostItem)), - confirmDeleteItem=new CheckableListItem<>(R.string.settings_confirm_delete_post, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmDeletePost, R.drawable.ic_fluent_delete_24_regular, ()->toggleCheckableItem(confirmDeleteItem)), + 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)), + playGifsItem=new CheckableListItem<>(R.string.settings_gif, 0, 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)), prefixRepliesItem=new ListItem<>(R.string.sk_settings_prefix_reply_cw_with_re, getPrefixWithRepliesString(), R.drawable.ic_fluent_arrow_reply_24_regular, this::onPrefixRepliesClick), - forwardReportsItem=new CheckableListItem<>(R.string.sk_settings_forward_report_default, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.forwardReportDefault, R.drawable.ic_fluent_arrow_forward_24_regular, ()->toggleCheckableItem(forwardReportsItem)), - loadNewPostsItem=new CheckableListItem<>(R.string.sk_settings_load_new_posts, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.loadNewPosts, R.drawable.ic_fluent_arrow_sync_24_regular, this::onLoadNewPostsClick), - seeNewPostsBtnItem=new CheckableListItem<>(R.string.sk_settings_see_new_posts_button, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNewPostsButton, R.drawable.ic_fluent_arrow_up_24_regular, ()->toggleCheckableItem(seeNewPostsBtnItem)), - remoteLoadingItem=new CheckableListItem<>(R.string.sk_settings_allow_remote_loading, R.string.sk_settings_allow_remote_loading_explanation, CheckableListItem.Style.SWITCH, GlobalUserPreferences.allowRemoteLoading, R.drawable.ic_fluent_communication_24_regular, ()->toggleCheckableItem(remoteLoadingItem), true), - showBoostsItem=new CheckableListItem<>(R.string.sk_settings_show_boosts, 0, CheckableListItem.Style.SWITCH, lp.showBoosts, R.drawable.ic_fluent_arrow_repeat_all_24_regular, ()->toggleCheckableItem(showBoostsItem)), - showRepliesItem=new CheckableListItem<>(R.string.sk_settings_show_replies, 0, CheckableListItem.Style.SWITCH, lp.showReplies, R.drawable.ic_fluent_arrow_reply_24_regular, ()->toggleCheckableItem(showRepliesItem)) + forwardReportsItem=new CheckableListItem<>(R.string.sk_settings_forward_report_default, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.forwardReportDefault, R.drawable.ic_fluent_arrow_forward_24_regular, i->toggleCheckableItem(forwardReportsItem)), + loadNewPostsItem=new CheckableListItem<>(R.string.sk_settings_load_new_posts, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.loadNewPosts, R.drawable.ic_fluent_arrow_sync_24_regular, i->onLoadNewPostsClick()), + seeNewPostsBtnItem=new CheckableListItem<>(R.string.sk_settings_see_new_posts_button, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNewPostsButton, R.drawable.ic_fluent_arrow_up_24_regular, i->toggleCheckableItem(seeNewPostsBtnItem)), + remoteLoadingItem=new CheckableListItem<>(R.string.sk_settings_allow_remote_loading, R.string.sk_settings_allow_remote_loading_explanation, CheckableListItem.Style.SWITCH, GlobalUserPreferences.allowRemoteLoading, R.drawable.ic_fluent_communication_24_regular, i->toggleCheckableItem(remoteLoadingItem), true), + showBoostsItem=new CheckableListItem<>(R.string.sk_settings_show_boosts, 0, CheckableListItem.Style.SWITCH, lp.showBoosts, R.drawable.ic_fluent_arrow_repeat_all_24_regular, i->toggleCheckableItem(showBoostsItem)), + showRepliesItem=new CheckableListItem<>(R.string.sk_settings_show_replies, 0, CheckableListItem.Style.SWITCH, lp.showReplies, R.drawable.ic_fluent_arrow_reply_24_regular, i->toggleCheckableItem(showRepliesItem)) )); if(isInstanceAkkoma()) items.add( @@ -93,7 +93,7 @@ public void onCreate(Bundle savedInstanceState){ @Override protected void doLoadData(int offset, int count){} - private void onDefaultLanguageClick(){ + private void onDefaultLanguageClick(ListItem item){ if (languageResolver == null) return; ComposeLanguageAlertViewController vc=new ComposeLanguageAlertViewController(getActivity(), null, new ComposeLanguageAlertViewController.SelectedOption(postLanguage), null, languageResolver); new M3AlertDialogBuilder(getActivity()) @@ -112,14 +112,14 @@ private void onDefaultLanguageClick(){ .show(); } - private void onPrefixRepliesClick(){ + private void onPrefixRepliesClick(ListItem item){ int selected=GlobalUserPreferences.prefixReplies.ordinal(); int[] newSelected={selected}; new M3AlertDialogBuilder(getActivity()) .setTitle(R.string.sk_settings_prefix_reply_cw_with_re) .setSingleChoiceItems((String[]) IntStream.of(R.string.sk_settings_prefix_replies_never, R.string.sk_settings_prefix_replies_always, R.string.sk_settings_prefix_replies_to_others).mapToObj(this::getString).toArray(String[]::new), - selected, (dlg, item)->newSelected[0]=item) - .setPositiveButton(R.string.ok, (dlg, item)->{ + selected, (dlg, which)->newSelected[0]=which) + .setPositiveButton(R.string.ok, (dlg, which)->{ GlobalUserPreferences.prefixReplies=GlobalUserPreferences.PrefixRepliesMode.values()[newSelected[0]]; prefixRepliesItem.subtitleRes=getPrefixWithRepliesString(); rebindItem(prefixRepliesItem); @@ -128,7 +128,7 @@ private void onPrefixRepliesClick(){ .show(); } - private void onReplyVisibilityClick(){ + private void onReplyVisibilityClick(ListItem item){ AccountLocalPreferences lp=getLocalPrefs(); int selected=lp.timelineReplyVisibility==null ? 2 : switch(lp.timelineReplyVisibility){ case "following" -> 0; @@ -139,8 +139,8 @@ private void onReplyVisibilityClick(){ new M3AlertDialogBuilder(getActivity()) .setTitle(R.string.sk_settings_prefix_reply_cw_with_re) .setSingleChoiceItems((String[]) IntStream.of(R.string.sk_settings_reply_visibility_following, R.string.sk_settings_reply_visibility_self, R.string.sk_settings_reply_visibility_all).mapToObj(this::getString).toArray(String[]::new), - selected, (dlg, item)->newSelected[0]=item) - .setPositiveButton(R.string.ok, (dlg, item)->{ + selected, (dlg, which)->newSelected[0]=which) + .setPositiveButton(R.string.ok, (dlg, which)->{ lp.timelineReplyVisibility=switch(newSelected[0]){ case 0 -> "following"; case 1 -> "self"; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDebugFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDebugFragment.java index 0b666705e7..bc3b594968 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDebugFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDebugFragment.java @@ -39,7 +39,7 @@ public void onCreate(Bundle savedInstanceState){ @Override protected void doLoadData(int offset, int count){} - private void onTestEmailConfirmClick(){ + private void onTestEmailConfirmClick(ListItem item){ AccountSession sess=AccountSessionManager.getInstance().getAccount(accountID); sess.activated=false; sess.activationInfo=new AccountActivationInfo("test@email", System.currentTimeMillis()); @@ -49,18 +49,18 @@ private void onTestEmailConfirmClick(){ Nav.goClearingStack(getActivity(), AccountActivationFragment.class, args); } - private void onForceSelfUpdateClick(){ + private void onForceSelfUpdateClick(ListItem item){ GithubSelfUpdater.forceUpdate=true; GithubSelfUpdater.getInstance().maybeCheckForUpdates(); restartUI(); } - private void onResetUpdaterClick(){ + private void onResetUpdaterClick(ListItem item){ GithubSelfUpdater.getInstance().reset(); restartUI(); } - private void onResetDiscoverBannersClick(){ + private void onResetDiscoverBannersClick(ListItem item){ DiscoverInfoBannerHelper.reset(); restartUI(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java index 4fa108fa6e..b5bb429fc9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsDisplayFragment.java @@ -56,29 +56,29 @@ public void onCreate(Bundle savedInstanceState){ onDataLoaded(List.of( themeItem=new ListItem<>(R.string.settings_theme, getAppearanceValue(), R.drawable.ic_fluent_weather_moon_24_regular, this::onAppearanceClick), colorItem=new ListItem<>(getString(R.string.sk_settings_color_palette), getColorPaletteValue(), R.drawable.ic_fluent_color_24_regular, this::onColorClick), - trueBlackModeItem=new CheckableListItem<>(R.string.sk_settings_true_black, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.trueBlackTheme, R.drawable.ic_fluent_dark_theme_24_regular, this::onTrueBlackModeClick, true), + trueBlackModeItem=new CheckableListItem<>(R.string.sk_settings_true_black, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.trueBlackTheme, R.drawable.ic_fluent_dark_theme_24_regular, i->onTrueBlackModeClick(), true), publishTextItem=new ListItem<>(getString(R.string.sk_settings_publish_button_text), getPublishButtonText(), R.drawable.ic_fluent_send_24_regular, this::onPublishTextClick), autoRevealCWsItem=new ListItem<>(R.string.sk_settings_auto_reveal_equal_spoilers, getAutoRevealSpoilersText(), R.drawable.ic_fluent_eye_24_regular, this::onAutoRevealSpoilersClick), - revealCWsItem=new CheckableListItem<>(R.string.sk_settings_always_reveal_content_warnings, 0, CheckableListItem.Style.SWITCH, lp.revealCWs, R.drawable.ic_fluent_chat_warning_24_regular, ()->toggleCheckableItem(revealCWsItem)), - hideSensitiveMediaItem=new CheckableListItem<>(R.string.settings_hide_sensitive_media, 0, CheckableListItem.Style.SWITCH, lp.hideSensitiveMedia, R.drawable.ic_fluent_flag_24_regular, ()->toggleCheckableItem(hideSensitiveMediaItem)), - interactionCountsItem=new CheckableListItem<>(R.string.settings_show_interaction_counts, 0, CheckableListItem.Style.SWITCH, lp.showInteractionCounts, R.drawable.ic_fluent_number_row_24_regular, ()->toggleCheckableItem(interactionCountsItem)), - emojiInNamesItem=new CheckableListItem<>(R.string.settings_show_emoji_in_names, 0, CheckableListItem.Style.SWITCH, lp.customEmojiInNames, R.drawable.ic_fluent_emoji_24_regular, ()->toggleCheckableItem(emojiInNamesItem)), - marqueeItem=new CheckableListItem<>(R.string.sk_settings_enable_marquee, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.toolbarMarquee, R.drawable.ic_fluent_text_more_24_regular, ()->toggleCheckableItem(marqueeItem)), - reduceMotionItem=new CheckableListItem<>(R.string.sk_settings_reduce_motion, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.reduceMotion, R.drawable.ic_fluent_star_emphasis_24_regular, ()->toggleCheckableItem(reduceMotionItem)), - disableSwipeItem=new CheckableListItem<>(R.string.sk_settings_tabs_disable_swipe, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.disableSwipe, R.drawable.ic_fluent_swipe_right_24_regular, ()->toggleCheckableItem(disableSwipeItem)), - altIndicatorItem=new CheckableListItem<>(R.string.sk_settings_show_alt_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showAltIndicator, R.drawable.ic_fluent_scan_text_24_regular, ()->toggleCheckableItem(altIndicatorItem)), - noAltIndicatorItem=new CheckableListItem<>(R.string.sk_settings_show_no_alt_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNoAltIndicator, R.drawable.ic_fluent_important_24_regular, ()->toggleCheckableItem(noAltIndicatorItem)), - collapsePostsItem=new CheckableListItem<>(R.string.sk_settings_collapse_long_posts, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.collapseLongPosts, R.drawable.ic_fluent_chevron_down_24_regular, ()->toggleCheckableItem(collapsePostsItem)), - spectatorModeItem=new CheckableListItem<>(R.string.sk_settings_hide_interaction, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.spectatorMode, R.drawable.ic_fluent_star_off_24_regular, ()->toggleCheckableItem(spectatorModeItem)), - hideFabItem=new CheckableListItem<>(R.string.sk_settings_hide_fab, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.autoHideFab, R.drawable.ic_fluent_edit_24_regular, ()->toggleCheckableItem(hideFabItem)), - translateOpenedItem=new CheckableListItem<>(R.string.sk_settings_translate_only_opened, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.translateButtonOpenedOnly, R.drawable.ic_fluent_translate_24_regular, ()->toggleCheckableItem(translateOpenedItem)), - likeIconItem=new CheckableListItem<>(R.string.sk_settings_like_icon, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.likeIcon, R.drawable.ic_fluent_heart_24_regular, ()->toggleCheckableItem(likeIconItem)), - underlinedLinksItem=new CheckableListItem<>(R.string.sk_settings_underlined_links, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.underlinedLinks, R.drawable.ic_fluent_text_underline_24_regular, ()->toggleCheckableItem(underlinedLinksItem)), - disablePillItem=new CheckableListItem<>(R.string.sk_disable_pill_shaped_active_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.disableM3PillActiveIndicator, R.drawable.ic_fluent_pill_24_regular, ()->toggleCheckableItem(disablePillItem)), - showNavigationLabelsItem=new CheckableListItem<>(R.string.sk_settings_show_labels_in_navigation_bar, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNavigationLabels, R.drawable.ic_fluent_tag_24_regular, ()->toggleCheckableItem(showNavigationLabelsItem), true), - pronounsInTimelinesItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_timelines, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInTimelines, 0, ()->toggleCheckableItem(pronounsInTimelinesItem)), - pronounsInThreadsItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_threads, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInThreads, 0, ()->toggleCheckableItem(pronounsInThreadsItem)), - pronounsInUserListingsItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_user_listings, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInUserListings, 0, ()->toggleCheckableItem(pronounsInUserListingsItem)) + revealCWsItem=new CheckableListItem<>(R.string.sk_settings_always_reveal_content_warnings, 0, CheckableListItem.Style.SWITCH, lp.revealCWs, R.drawable.ic_fluent_chat_warning_24_regular, i->toggleCheckableItem(revealCWsItem)), + hideSensitiveMediaItem=new CheckableListItem<>(R.string.settings_hide_sensitive_media, 0, CheckableListItem.Style.SWITCH, lp.hideSensitiveMedia, R.drawable.ic_fluent_flag_24_regular, i->toggleCheckableItem(hideSensitiveMediaItem)), + interactionCountsItem=new CheckableListItem<>(R.string.settings_show_interaction_counts, 0, CheckableListItem.Style.SWITCH, lp.showInteractionCounts, R.drawable.ic_fluent_number_row_24_regular, i->toggleCheckableItem(interactionCountsItem)), + emojiInNamesItem=new CheckableListItem<>(R.string.settings_show_emoji_in_names, 0, CheckableListItem.Style.SWITCH, lp.customEmojiInNames, R.drawable.ic_fluent_emoji_24_regular, i->toggleCheckableItem(emojiInNamesItem)), + marqueeItem=new CheckableListItem<>(R.string.sk_settings_enable_marquee, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.toolbarMarquee, R.drawable.ic_fluent_text_more_24_regular, i->toggleCheckableItem(marqueeItem)), + reduceMotionItem=new CheckableListItem<>(R.string.sk_settings_reduce_motion, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.reduceMotion, R.drawable.ic_fluent_star_emphasis_24_regular, i->toggleCheckableItem(reduceMotionItem)), + disableSwipeItem=new CheckableListItem<>(R.string.sk_settings_tabs_disable_swipe, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.disableSwipe, R.drawable.ic_fluent_swipe_right_24_regular, i->toggleCheckableItem(disableSwipeItem)), + altIndicatorItem=new CheckableListItem<>(R.string.sk_settings_show_alt_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showAltIndicator, R.drawable.ic_fluent_scan_text_24_regular, i->toggleCheckableItem(altIndicatorItem)), + noAltIndicatorItem=new CheckableListItem<>(R.string.sk_settings_show_no_alt_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNoAltIndicator, R.drawable.ic_fluent_important_24_regular, i->toggleCheckableItem(noAltIndicatorItem)), + collapsePostsItem=new CheckableListItem<>(R.string.sk_settings_collapse_long_posts, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.collapseLongPosts, R.drawable.ic_fluent_chevron_down_24_regular, i->toggleCheckableItem(collapsePostsItem)), + spectatorModeItem=new CheckableListItem<>(R.string.sk_settings_hide_interaction, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.spectatorMode, R.drawable.ic_fluent_star_off_24_regular, i->toggleCheckableItem(spectatorModeItem)), + hideFabItem=new CheckableListItem<>(R.string.sk_settings_hide_fab, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.autoHideFab, R.drawable.ic_fluent_edit_24_regular, i->toggleCheckableItem(hideFabItem)), + translateOpenedItem=new CheckableListItem<>(R.string.sk_settings_translate_only_opened, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.translateButtonOpenedOnly, R.drawable.ic_fluent_translate_24_regular, i->toggleCheckableItem(translateOpenedItem)), + likeIconItem=new CheckableListItem<>(R.string.sk_settings_like_icon, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.likeIcon, R.drawable.ic_fluent_heart_24_regular, i->toggleCheckableItem(likeIconItem)), + underlinedLinksItem=new CheckableListItem<>(R.string.sk_settings_underlined_links, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.underlinedLinks, R.drawable.ic_fluent_text_underline_24_regular, i->toggleCheckableItem(underlinedLinksItem)), + disablePillItem=new CheckableListItem<>(R.string.sk_disable_pill_shaped_active_indicator, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.disableM3PillActiveIndicator, R.drawable.ic_fluent_pill_24_regular, i->toggleCheckableItem(disablePillItem)), + showNavigationLabelsItem=new CheckableListItem<>(R.string.sk_settings_show_labels_in_navigation_bar, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.showNavigationLabels, R.drawable.ic_fluent_tag_24_regular, i->toggleCheckableItem(showNavigationLabelsItem), true), + pronounsInTimelinesItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_timelines, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInTimelines, 0, i->toggleCheckableItem(pronounsInTimelinesItem)), + pronounsInThreadsItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_threads, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInThreads, 0, i->toggleCheckableItem(pronounsInThreadsItem)), + pronounsInUserListingsItem=new CheckableListItem<>(R.string.sk_settings_display_pronouns_in_user_listings, 0, CheckableListItem.Style.CHECKBOX, GlobalUserPreferences.displayPronounsInUserListings, 0, i->toggleCheckableItem(pronounsInUserListingsItem)) )); trueBlackModeItem.checkedChangeListener=checked->onTrueBlackModeClick(); } @@ -166,7 +166,7 @@ private void onTrueBlackModeClick(){ maybeApplyNewThemeRightNow(null, null, prev); } - private void onAppearanceClick(){ + private void onAppearanceClick(ListItem item_){ int selected=switch(GlobalUserPreferences.theme){ case LIGHT -> 0; case DARK -> 1; @@ -197,7 +197,7 @@ private void onAppearanceClick(){ .show(); } - private void onColorClick(){ + private void onColorClick(ListItem item_){ boolean multiple=AccountSessionManager.getInstance().getLoggedInAccounts().size() > 1; int indexOffset=multiple ? 1 : 0; int selected=lp.color==null ? 0 : lp.color.ordinal() + indexOffset; @@ -234,7 +234,7 @@ private void onColorClick(){ alert.show(); } - private void onPublishTextClick(){ + private void onPublishTextClick(ListItem item_){ TextInputFrameLayout input = new TextInputFrameLayout( getContext(), getString(R.string.publish), @@ -257,7 +257,7 @@ private void onPublishTextClick(){ .show(); } - private void onAutoRevealSpoilersClick(){ + private void onAutoRevealSpoilersClick(ListItem item_){ int selected=GlobalUserPreferences.autoRevealEqualSpoilers.ordinal(); int[] newSelected={selected}; new M3AlertDialogBuilder(getActivity()) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsFiltersFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsFiltersFragment.java index 2a6399e986..b2a40c9532 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsFiltersFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsFiltersFragment.java @@ -67,16 +67,14 @@ private void onFilterClick(ListItem filter){ Nav.go(getActivity(), EditFilterFragment.class, args); } - private void onAddFilterClick(){ + private void onAddFilterClick(ListItem item){ Bundle args=new Bundle(); args.putString("account", accountID); Nav.go(getActivity(), EditFilterFragment.class, args); } private ListItem makeListItem(Filter f){ - ListItem item=new ListItem<>(f.title, getString(f.isActive() ? R.string.filter_active : R.string.filter_inactive), null, f); - item.onClick=()->onFilterClick(item); - item.isEnabled=true; + ListItem item=new ListItem<>(f.title, getString(f.isActive() ? R.string.filter_active : R.string.filter_inactive), this::onFilterClick, f); return item; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsInstanceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsInstanceFragment.java index 93542823ec..e86df44f41 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsInstanceFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsInstanceFragment.java @@ -36,15 +36,15 @@ public void onCreate(Bundle savedInstanceState){ lp=s.getLocalPreferences(); onDataLoaded(List.of( new ListItem<>(AccountSessionManager.get(accountID).domain, getString(R.string.settings_server_explanation), R.drawable.ic_fluent_server_24_regular, this::onServerClick), - new ListItem<>(R.string.sk_settings_profile, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/settings/profile")), - new ListItem<>(R.string.sk_settings_posting, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/settings/preferences/other")), - new ListItem<>(R.string.sk_settings_auth, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/auth/edit"), 0, true), - contentTypesItem=new CheckableListItem<>(R.string.sk_settings_content_types, R.string.sk_settings_content_types_explanation, CheckableListItem.Style.SWITCH, lp.contentTypesEnabled, R.drawable.ic_fluent_text_edit_style_24_regular, this::onContentTypeClick), + new ListItem<>(R.string.sk_settings_profile, 0, R.drawable.ic_fluent_open_24_regular, i->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/settings/profile")), + new ListItem<>(R.string.sk_settings_posting, 0, R.drawable.ic_fluent_open_24_regular, i->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/settings/preferences/other")), + new ListItem<>(R.string.sk_settings_auth, 0, R.drawable.ic_fluent_open_24_regular, i->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/auth/edit"), 0, true), + contentTypesItem=new CheckableListItem<>(R.string.sk_settings_content_types, R.string.sk_settings_content_types_explanation, CheckableListItem.Style.SWITCH, lp.contentTypesEnabled, R.drawable.ic_fluent_text_edit_style_24_regular, i->onContentTypeClick()), defaultContentTypeItem=new ListItem<>(R.string.sk_settings_default_content_type, lp.defaultContentType.getName(), R.drawable.ic_fluent_text_bold_24_regular, this::onDefaultContentTypeClick, 0, true), - emojiReactionsItem=new CheckableListItem<>(R.string.sk_settings_emoji_reactions, R.string.sk_settings_emoji_reactions_explanation, CheckableListItem.Style.SWITCH, lp.emojiReactionsEnabled, R.drawable.ic_fluent_emoji_laugh_24_regular, this::onEmojiReactionsClick), + emojiReactionsItem=new CheckableListItem<>(R.string.sk_settings_emoji_reactions, R.string.sk_settings_emoji_reactions_explanation, CheckableListItem.Style.SWITCH, lp.emojiReactionsEnabled, R.drawable.ic_fluent_emoji_laugh_24_regular, i->onEmojiReactionsClick()), showEmojiReactionsItem=new ListItem<>(R.string.sk_settings_show_emoji_reactions, getShowEmojiReactionsString(), R.drawable.ic_fluent_emoji_24_regular, this::onShowEmojiReactionsClick, 0, true), - localOnlyItem=new CheckableListItem<>(R.string.sk_settings_support_local_only, R.string.sk_settings_local_only_explanation, CheckableListItem.Style.SWITCH, lp.localOnlySupported, R.drawable.ic_fluent_eye_24_regular, this::onLocalOnlyClick), - glitchModeItem=new CheckableListItem<>(R.string.sk_settings_glitch_instance, R.string.sk_settings_glitch_mode_explanation, CheckableListItem.Style.SWITCH, lp.glitchInstance, R.drawable.ic_fluent_eye_24_filled, ()->toggleCheckableItem(glitchModeItem)) + localOnlyItem=new CheckableListItem<>(R.string.sk_settings_support_local_only, R.string.sk_settings_local_only_explanation, CheckableListItem.Style.SWITCH, lp.localOnlySupported, R.drawable.ic_fluent_eye_24_regular, i->onLocalOnlyClick()), + glitchModeItem=new CheckableListItem<>(R.string.sk_settings_glitch_instance, R.string.sk_settings_glitch_mode_explanation, CheckableListItem.Style.SWITCH, lp.glitchInstance, R.drawable.ic_fluent_eye_24_filled, i->toggleCheckableItem(glitchModeItem)) )); contentTypesItem.checkedChangeListener=checked->onContentTypeClick(); defaultContentTypeItem.isEnabled=contentTypesItem.checked; @@ -68,7 +68,7 @@ protected void onHidden(){ E.post(new StatusDisplaySettingsChangedEvent(accountID)); } - private void onServerClick(){ + private void onServerClick(ListItem item){ Bundle args=new Bundle(); args.putString("account", accountID); Nav.go(getActivity(), SettingsServerFragment.class, args); @@ -87,7 +87,7 @@ private void resetDefaultContentType(){ defaultContentTypeItem.subtitleRes=lp.defaultContentType.getName(); } - private void onDefaultContentTypeClick(){ + private void onDefaultContentTypeClick(ListItem item_){ int selected=lp.defaultContentType.ordinal(); int[] newSelected={selected}; ContentType[] supportedContentTypes=Arrays.stream(ContentType.values()) @@ -112,7 +112,7 @@ private void onDefaultContentTypeClick(){ .show(); } - private void onShowEmojiReactionsClick(){ + private void onShowEmojiReactionsClick(ListItem item_){ int selected=lp.showEmojiReactions.ordinal(); int[] newSelected={selected}; new M3AlertDialogBuilder(getActivity()) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java index 673df63403..a83a566729 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java @@ -18,6 +18,7 @@ import org.joinmastodon.android.events.SelfUpdateStateChangedEvent; import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.viewmodel.ListItem; +import org.joinmastodon.android.ui.AccountSwitcherSheet; import org.joinmastodon.android.ui.M3AlertDialogBuilder; import org.joinmastodon.android.ui.utils.HideableSingleViewRecyclerAdapter; import org.joinmastodon.android.ui.utils.UiUtils; @@ -59,6 +60,7 @@ public void onCreate(Bundle savedInstanceState){ new ListItem<>(R.string.settings_notifications, 0, R.drawable.ic_fluent_alert_24_regular, this::onNotificationsClick), new ListItem<>(R.string.sk_settings_instance, 0, R.drawable.ic_fluent_server_24_regular, this::onInstanceClick), new ListItem<>(getString(R.string.about_app, getString(R.string.sk_app_name)), null, R.drawable.ic_fluent_info_24_regular, this::onAboutClick, null, 0, true), + new ListItem<>(R.string.manage_accounts, 0, R.drawable.ic_fluent_person_swap_24_regular, this::onManageAccountsClick), new ListItem<>(R.string.log_out, 0, R.drawable.ic_fluent_sign_out_24_regular, this::onLogOutClick, R.attr.colorM3Error, false) )); @@ -67,7 +69,7 @@ public void onCreate(Bundle savedInstanceState){ data.add(3, new ListItem<>(R.string.settings_filters, 0, R.drawable.ic_fluent_filter_24_regular, this::onFiltersClick)); if(BuildConfig.DEBUG || BuildConfig.BUILD_TYPE.equals("appcenterPrivateBeta")){ - data.add(0, new ListItem<>("Debug settings", null, R.drawable.ic_fluent_wrench_screwdriver_24_regular, ()->Nav.go(getActivity(), SettingsDebugFragment.class, makeFragmentArgs()), null, 0, true)); + data.add(0, new ListItem<>("Debug settings", null, R.drawable.ic_fluent_wrench_screwdriver_24_regular, i->Nav.go(getActivity(), SettingsDebugFragment.class, makeFragmentArgs()), null, 0, true)); } AccountSession session=AccountSessionManager.get(accountID); @@ -128,35 +130,39 @@ private Bundle makeFragmentArgs(){ return args; } - private void onBehaviorClick(){ + private void onBehaviorClick(ListItem item_){ Nav.go(getActivity(), SettingsBehaviorFragment.class, makeFragmentArgs()); } - private void onDisplayClick(){ + private void onDisplayClick(ListItem item_){ Nav.go(getActivity(), SettingsDisplayFragment.class, makeFragmentArgs()); } - private void onPrivacyClick(){ + private void onPrivacyClick(ListItem item_){ Nav.go(getActivity(), SettingsPrivacyFragment.class, makeFragmentArgs()); } - private void onFiltersClick(){ + private void onFiltersClick(ListItem item_){ Nav.go(getActivity(), SettingsFiltersFragment.class, makeFragmentArgs()); } - private void onNotificationsClick(){ + private void onNotificationsClick(ListItem item_){ Nav.go(getActivity(), SettingsNotificationsFragment.class, makeFragmentArgs()); } - private void onInstanceClick(){ + private void onInstanceClick(ListItem item_){ Nav.go(getActivity(), SettingsInstanceFragment.class, makeFragmentArgs()); } - private void onAboutClick(){ + private void onAboutClick(ListItem item_){ Nav.go(getActivity(), SettingsAboutAppFragment.class, makeFragmentArgs()); } - private void onLogOutClick(){ + private void onManageAccountsClick(ListItem item){ + new AccountSwitcherSheet(getActivity(), null).show(); + } + + private void onLogOutClick(ListItem item_){ AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); new M3AlertDialogBuilder(getActivity()) .setMessage(getString(R.string.confirm_log_out, session.getFullUsername())) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsNotificationsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsNotificationsFragment.java index 5192b9fc15..2b240629b7 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsNotificationsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsNotificationsFragment.java @@ -27,7 +27,6 @@ import org.joinmastodon.android.ui.M3AlertDialogBuilder; import org.joinmastodon.android.ui.utils.HideableSingleViewRecyclerAdapter; import org.joinmastodon.android.ui.utils.UiUtils; -import org.unifiedpush.android.connector.RegistrationDialogContent; import org.unifiedpush.android.connector.UnifiedPush; import java.time.Instant; @@ -73,21 +72,21 @@ public void onCreate(Bundle savedInstanceState){ useUnifiedPush=!getDistributor(getContext()).isEmpty(); onDataLoaded(List.of( - pauseItem=new CheckableListItem<>(getString(R.string.pause_all_notifications), getPauseItemSubtitle(), CheckableListItem.Style.SWITCH, false, R.drawable.ic_fluent_alert_snooze_24_regular, ()->onPauseNotificationsClick(false)), + pauseItem=new CheckableListItem<>(getString(R.string.pause_all_notifications), getPauseItemSubtitle(), CheckableListItem.Style.SWITCH, false, R.drawable.ic_fluent_alert_snooze_24_regular, i->onPauseNotificationsClick(false)), policyItem=new ListItem<>(R.string.settings_notifications_policy, 0, R.drawable.ic_fluent_people_24_regular, this::onNotificationsPolicyClick, 0, true), - mentionsItem=new CheckableListItem<>(R.string.notification_type_mentions_and_replies, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.mention, R.drawable.ic_fluent_mention_24_regular, ()->toggleCheckableItem(mentionsItem)), - boostsItem=new CheckableListItem<>(R.string.notification_type_reblog, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.reblog, R.drawable.ic_fluent_arrow_repeat_all_24_regular, ()->toggleCheckableItem(boostsItem)), - favoritesItem=new CheckableListItem<>(R.string.notification_type_favorite, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.favourite, R.drawable.ic_fluent_star_24_regular, ()->toggleCheckableItem(favoritesItem)), - followersItem=new CheckableListItem<>(R.string.notification_type_follow, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.follow, R.drawable.ic_fluent_person_add_24_regular, ()->toggleCheckableItem(followersItem)), - pollsItem=new CheckableListItem<>(R.string.notification_type_poll, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.poll, R.drawable.ic_fluent_poll_24_regular, ()->toggleCheckableItem(pollsItem)), - updateItem=new CheckableListItem<>(R.string.sk_notification_type_update, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.update, R.drawable.ic_fluent_history_24_regular, ()->toggleCheckableItem(updateItem)), - postsItem=new CheckableListItem<>(R.string.sk_notification_type_posts, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.status, R.drawable.ic_fluent_chat_24_regular, ()->toggleCheckableItem(postsItem), true), - - uniformIconItem=new CheckableListItem<>(R.string.sk_settings_uniform_icon_for_notifications, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.uniformNotificationIcon, R.drawable.ic_ntf_logo, ()->toggleCheckableItem(uniformIconItem)), - deleteItem=new CheckableListItem<>(R.string.sk_settings_enable_delete_notifications, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.enableDeleteNotifications, R.drawable.ic_fluent_mail_inbox_dismiss_24_regular, ()->toggleCheckableItem(deleteItem)), - onlyLatestItem=new CheckableListItem<>(R.string.sk_settings_single_notification, 0, CheckableListItem.Style.SWITCH, lp.keepOnlyLatestNotification, R.drawable.ic_fluent_convert_range_24_regular, ()->toggleCheckableItem(onlyLatestItem), true), - unifiedPushItem=new CheckableListItem<>(R.string.sk_settings_unifiedpush, 0, CheckableListItem.Style.SWITCH, useUnifiedPush, R.drawable.ic_fluent_alert_arrow_up_24_regular, this::onUnifiedPush, true) + mentionsItem=new CheckableListItem<>(R.string.notification_type_mentions_and_replies, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.mention, R.drawable.ic_fluent_mention_24_regular, i->toggleCheckableItem(mentionsItem)), + boostsItem=new CheckableListItem<>(R.string.notification_type_reblog, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.reblog, R.drawable.ic_fluent_arrow_repeat_all_24_regular, i->toggleCheckableItem(boostsItem)), + favoritesItem=new CheckableListItem<>(R.string.notification_type_favorite, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.favourite, R.drawable.ic_fluent_star_24_regular, i->toggleCheckableItem(favoritesItem)), + followersItem=new CheckableListItem<>(R.string.notification_type_follow, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.follow, R.drawable.ic_fluent_person_add_24_regular, i->toggleCheckableItem(followersItem)), + pollsItem=new CheckableListItem<>(R.string.notification_type_poll, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.poll, R.drawable.ic_fluent_poll_24_regular, i->toggleCheckableItem(pollsItem)), + updateItem=new CheckableListItem<>(R.string.sk_notification_type_update, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.update, R.drawable.ic_fluent_history_24_regular, i->toggleCheckableItem(updateItem)), + postsItem=new CheckableListItem<>(R.string.sk_notification_type_posts, 0, CheckableListItem.Style.CHECKBOX, pushSubscription.alerts.status, R.drawable.ic_fluent_chat_24_regular, i->toggleCheckableItem(postsItem), true), + + uniformIconItem=new CheckableListItem<>(R.string.sk_settings_uniform_icon_for_notifications, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.uniformNotificationIcon, R.drawable.ic_ntf_logo, i->toggleCheckableItem(uniformIconItem)), + deleteItem=new CheckableListItem<>(R.string.sk_settings_enable_delete_notifications, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.enableDeleteNotifications, R.drawable.ic_fluent_mail_inbox_dismiss_24_regular, i->toggleCheckableItem(deleteItem)), + onlyLatestItem=new CheckableListItem<>(R.string.sk_settings_single_notification, 0, CheckableListItem.Style.SWITCH, lp.keepOnlyLatestNotification, R.drawable.ic_fluent_convert_range_24_regular, i->toggleCheckableItem(onlyLatestItem), true), + unifiedPushItem=new CheckableListItem<>(R.string.sk_settings_unifiedpush, 0, CheckableListItem.Style.SWITCH, useUnifiedPush, R.drawable.ic_fluent_alert_arrow_up_24_regular, i->onUnifiedPushClick(), true) )); //only enable when distributors, who can receive notifications, are available @@ -98,7 +97,7 @@ public void onCreate(Bundle savedInstanceState){ typeItems=List.of(mentionsItem, boostsItem, favoritesItem, followersItem, pollsItem, updateItem, postsItem); pauseItem.checkedChangeListener=checked->onPauseNotificationsClick(true); - unifiedPushItem.checkedChangeListener=checked->onUnifiedPush(); + unifiedPushItem.checkedChangeListener=checked->onUnifiedPushClick(); updatePolicyItem(null); updatePauseItem(); } @@ -254,7 +253,7 @@ private void onPauseNotificationsClick(boolean fromSwitch){ alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } - private void onNotificationsPolicyClick(){ + private void onNotificationsPolicyClick(ListItem item_){ String[] items=Stream.of( R.string.notifications_policy_anyone, R.string.notifications_policy_followed, @@ -328,7 +327,7 @@ private void updateBanner(){ } } - private void onUnifiedPush(){ + private void onUnifiedPushClick(){ if(getDistributor(getContext()).isEmpty()){ List distributors = UnifiedPush.getDistributors(getContext(), new ArrayList<>()); showUnifiedPushRegisterDialog(distributors); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsPrivacyFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsPrivacyFragment.java index 2a54013d04..a1df2984f3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsPrivacyFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsPrivacyFragment.java @@ -18,8 +18,8 @@ public void onCreate(Bundle savedInstanceState){ setTitle(R.string.settings_privacy); Account self=AccountSessionManager.get(accountID).self; onDataLoaded(List.of( - discoverableItem=new CheckableListItem<>(R.string.settings_discoverable, 0, CheckableListItem.Style.SWITCH, self.discoverable, R.drawable.ic_fluent_thumb_like_dislike_24_regular, ()->toggleCheckableItem(discoverableItem)), - indexableItem=new CheckableListItem<>(R.string.settings_indexable, 0, CheckableListItem.Style.SWITCH, self.source.indexable!=null ? self.source.indexable : true, R.drawable.ic_fluent_search_24_regular, ()->toggleCheckableItem(indexableItem)) + discoverableItem=new CheckableListItem<>(R.string.settings_discoverable, 0, CheckableListItem.Style.SWITCH, self.discoverable, R.drawable.ic_fluent_thumb_like_dislike_24_regular, i->toggleCheckableItem(discoverableItem)), + indexableItem=new CheckableListItem<>(R.string.settings_indexable, 0, CheckableListItem.Style.SWITCH, self.source.indexable!=null ? self.source.indexable : true, R.drawable.ic_fluent_search_24_regular, i->toggleCheckableItem(indexableItem)) )); if(self.source.indexable==null) indexableItem.isEnabled=false; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java index 7f588b9911..a655368e1e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java @@ -145,7 +145,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url){ if(!TextUtils.isEmpty(instance.email)){ needDivider=true; SimpleListItemViewHolder holder=new SimpleListItemViewHolder(getActivity(), scrollingLayout); - ListItem item=new ListItem<>(R.string.send_email_to_server_admin, 0, R.drawable.ic_fluent_mail_24_regular, ()->{}); + ListItem item=new ListItem<>(R.string.send_email_to_server_admin, 0, R.drawable.ic_fluent_mail_24_regular, i->{}); holder.bind(item); holder.itemView.setBackground(UiUtils.getThemeDrawable(getActivity(), android.R.attr.selectableItemBackground)); holder.itemView.setOnClickListener(v->openAdminEmail()); diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/CheckableListItem.java b/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/CheckableListItem.java index cff521a9b9..0363f81f5a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/CheckableListItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/CheckableListItem.java @@ -9,42 +9,42 @@ public class CheckableListItem extends ListItem{ public boolean checked; public Consumer checkedChangeListener; - public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Runnable onClick, T parentObject, boolean dividerAfter){ - super(title, subtitle, iconRes, onClick, parentObject, 0, dividerAfter); + public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Consumer> onClick, T parentObject, boolean dividerAfter){ + super(title, subtitle, iconRes, (Consumer>)(Object)onClick, parentObject, 0, dividerAfter); this.style=style; this.checked=checked; } - public CheckableListItem(String title, String subtitle, Style style, boolean checked, Runnable onClick){ + public CheckableListItem(String title, String subtitle, Style style, boolean checked, Consumer> onClick){ this(title, subtitle, style, checked, 0, onClick, null, false); } - public CheckableListItem(String title, String subtitle, Style style, boolean checked, Runnable onClick, T parentObject){ + public CheckableListItem(String title, String subtitle, Style style, boolean checked, Consumer> onClick, T parentObject){ this(title, subtitle, style, checked, 0, onClick, parentObject, false); } - public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Runnable onClick){ + public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Consumer> onClick){ this(title, subtitle, style, checked, iconRes, onClick, null, false); } - public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Runnable onClick, T parentObject){ + public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Consumer> onClick, T parentObject){ this(title, subtitle, style, checked, iconRes, onClick, parentObject, false); } - public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, Runnable onClick){ + public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, Consumer> onClick){ this(titleRes, subtitleRes, style, checked, 0, onClick, false); } - public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, Runnable onClick, boolean dividerAfter){ + public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, Consumer> onClick, boolean dividerAfter){ this(titleRes, subtitleRes, style, checked, 0, onClick, dividerAfter); } - public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, int iconRes, Runnable onClick){ + public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, int iconRes, Consumer> onClick){ this(titleRes, subtitleRes, style, checked, iconRes, onClick, false); } - public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, int iconRes, Runnable onClick, boolean dividerAfter){ - super(titleRes, subtitleRes, iconRes, onClick, 0, dividerAfter); + public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, int iconRes, Consumer> onClick, boolean dividerAfter){ + super(titleRes, subtitleRes, iconRes, (Consumer>)(Object)onClick, 0, dividerAfter); this.style=style; this.checked=checked; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/ListItem.java b/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/ListItem.java index e00ae06368..9785431458 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/ListItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/viewmodel/ListItem.java @@ -2,6 +2,8 @@ import org.joinmastodon.android.R; +import java.util.function.Consumer; + import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; @@ -16,11 +18,11 @@ public class ListItem{ public int iconRes; public int colorOverrideAttr; public boolean dividerAfter; - public Runnable onClick; + private Consumer> onClick; public boolean isEnabled=true; public T parentObject; - public ListItem(String title, String subtitle, int iconRes, Runnable onClick, T parentObject, int colorOverrideAttr, boolean dividerAfter){ + public ListItem(String title, String subtitle, int iconRes, Consumer> onClick, T parentObject, int colorOverrideAttr, boolean dividerAfter){ this.title=title; this.subtitle=subtitle; this.iconRes=iconRes; @@ -32,45 +34,41 @@ public ListItem(String title, String subtitle, int iconRes, Runnable onClick, T isEnabled=false; } - public ListItem(String title, String subtitle, Runnable onClick){ + public ListItem(String title, String subtitle, Consumer> onClick){ this(title, subtitle, 0, onClick, null, 0, false); } - public ListItem(String title, String subtitle, Runnable onClick, T parentObject){ + public ListItem(String title, String subtitle, Consumer> onClick, T parentObject){ this(title, subtitle, 0, onClick, parentObject, 0, false); } - public ListItem(String title, String subtitle, @DrawableRes int iconRes, Runnable onClick){ + public ListItem(String title, String subtitle, @DrawableRes int iconRes, Consumer> onClick){ this(title, subtitle, iconRes, onClick, null, 0, false); } - public ListItem(String title, String subtitle, @DrawableRes int iconRes, Runnable onClick, boolean dividerAfter){ - this(title, subtitle, iconRes, onClick, null, 0, dividerAfter); - } - - public ListItem(String title, String subtitle, @DrawableRes int iconRes, Runnable onClick, T parentObject){ + public ListItem(String title, String subtitle, @DrawableRes int iconRes, Consumer> onClick, T parentObject){ this(title, subtitle, iconRes, onClick, parentObject, 0, false); } - public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, Runnable onClick){ + public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, Consumer> onClick){ this(null, null, 0, onClick, null, 0, false); this.titleRes=titleRes; this.subtitleRes=subtitleRes; } - public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, Runnable onClick, int colorOverrideAttr, boolean dividerAfter){ + public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, Consumer> onClick, int colorOverrideAttr, boolean dividerAfter){ this(null, null, 0, onClick, null, colorOverrideAttr, dividerAfter); this.titleRes=titleRes; this.subtitleRes=subtitleRes; } - public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Runnable onClick){ + public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Consumer> onClick){ this(null, null, iconRes, onClick, null, 0, false); this.titleRes=titleRes; this.subtitleRes=subtitleRes; } - public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Runnable onClick, int colorOverrideAttr, boolean dividerAfter){ + public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Consumer> onClick, int colorOverrideAttr, boolean dividerAfter){ this(null, null, iconRes, onClick, null, colorOverrideAttr, dividerAfter); this.titleRes=titleRes; this.subtitleRes=subtitleRes; @@ -79,4 +77,13 @@ public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRe public int getItemViewType(){ return colorOverrideAttr==0 ? R.id.list_item_simple : R.id.list_item_simple_tinted; } + + public void performClick(){ + if(onClick!=null) + onClick.accept(this); + } + + public > void setOnClick(Consumer onClick){ + this.onClick=(Consumer>) onClick; + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/ActionModeHelper.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/ActionModeHelper.java new file mode 100644 index 0000000000..23f7fbf453 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/ActionModeHelper.java @@ -0,0 +1,88 @@ +package org.joinmastodon.android.ui.utils; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.IntEvaluator; +import android.animation.ObjectAnimator; +import android.graphics.drawable.Drawable; +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import org.joinmastodon.android.R; + +import java.util.function.IntSupplier; + +import me.grishka.appkit.FragmentStackActivity; +import me.grishka.appkit.fragments.AppKitFragment; + +public class ActionModeHelper{ + public static ActionMode startActionMode(AppKitFragment fragment, IntSupplier statusBarColorSupplier, ActionMode.Callback callback){ + FragmentStackActivity activity=(FragmentStackActivity) fragment.getActivity(); + return activity.startActionMode(new ActionMode.Callback(){ + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu){ + if(!callback.onCreateActionMode(mode, menu)) + return false; + ObjectAnimator anim=ObjectAnimator.ofInt(activity.getWindow(), "statusBarColor", statusBarColorSupplier.getAsInt(), UiUtils.getThemeColor(activity, R.attr.colorM3Primary)); + anim.setEvaluator(new IntEvaluator(){ + @Override + public Integer evaluate(float fraction, Integer startValue, Integer endValue){ + return UiUtils.alphaBlendColors(startValue, endValue, fraction); + } + }); + anim.start(); + activity.invalidateSystemBarColors(fragment); + View fakeView=new View(activity); +// mode.setCustomView(fakeView); +// int buttonID=activity.getResources().getIdentifier("action_mode_close_button", "id", "android"); +// View btn=activity.getWindow().getDecorView().findViewById(buttonID); +// if(btn!=null){ +// ((ViewGroup.MarginLayoutParams)btn.getLayoutParams()).setMarginEnd(0); +// } + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu){ + if(!callback.onPrepareActionMode(mode, menu)) + return false; + for(int i=0;i Error playing video + Following + Lists + Followed hashtags + You don\'t have any lists yet. + You don\'t follow any hashtags. + Manage lists + Manage hashtags + + Dropdown menu + Edit list + List members + Delete list + + Delete “%s”? + Hide members in Following + If someone is on this list, hide them in your Following timeline to avoid seeing their posts twice. + List name + Show replies to + No one + Members of the list + Anyone I follow + Remove members? + Remove + Add member + Search among people you follow + Add to list… + Add to list + + Manage the lists %s appears on + Remove from list + Remove member? + Keep up with interests by following hashtags + Follows will appear here + Organize your home feed with Lists + Yours will appear here + Manage accounts + + %,d post recently + %,d posts recently + \ No newline at end of file