diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java index 915d7f787..4e4d4f6b0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java @@ -42,6 +42,7 @@ import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.MastodonToolbarFragment; +import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.PushNotification; import org.joinmastodon.android.model.PushSubscription; import org.joinmastodon.android.ui.OutlineProviders; @@ -65,6 +66,8 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple protected ThemeItem themeItem; protected boolean needAppRestart; + private Instance instance; + private String instanceName; protected NotificationPolicyItem notificationPolicyItem; @@ -85,6 +88,8 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple accountID=getArguments().getString("account"); AccountSession session = AccountSessionManager.getInstance().getAccount(accountID); + instance = AccountSessionManager.getInstance().getInstanceInfo(session.domain); + instanceName = UiUtils.getInstanceName(accountID); DomainManager.getInstance().setCurrentDomain(session.domain + "/settings"); addItems(items); @@ -125,6 +130,14 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple this.view = view; } + protected Instance getInstance() { + return instance; + } + + protected String getInstanceName() { + return instanceName; + } + static abstract class Item{ public abstract int getViewType(); @@ -152,7 +165,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple private int icon; boolean checked; private Consumer onChanged; - private boolean enabled=true; + protected boolean enabled=true; public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer onChanged){ this.text=getString(text); @@ -532,7 +545,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple return pushSubscription; } - private class SwitchViewHolder extends BindableViewHolder implements UsableRecyclerView.DisableableClickable{ + protected class SwitchViewHolder extends BindableViewHolder implements UsableRecyclerView.DisableableClickable{ private final TextView text; private final ImageView icon; private final Switch checkbox; 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 db9398a4f..64141cca3 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 @@ -9,5 +9,6 @@ public class SettingsMainFragment extends SettingsBaseFragment{ public void addItems(ArrayList items) { items.add(new SettingsCategoryItem(R.string.settings_theme, SettingsAppearanceFragment.class, R.drawable.ic_fluent_color_24_regular)); items.add(new SettingsCategoryItem(R.string.settings_behavior, BehaviourFragment.class, R.drawable.ic_fluent_chat_settings_24_regular)); + items.add(new SettingsCategoryItem(R.string.sk_timelines, TimeLineFragment.class, R.drawable.ic_fluent_timeline_24_regular)); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/TimeLineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/TimeLineFragment.java new file mode 100644 index 000000000..528a06fd3 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/TimeLineFragment.java @@ -0,0 +1,123 @@ +package org.joinmastodon.android.fragments.settings; + +import android.view.Gravity; +import android.view.MenuItem; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.PopupMenu; +import android.widget.Toast; + +import org.joinmastodon.android.GlobalUserPreferences; +import org.joinmastodon.android.R; +import org.joinmastodon.android.ui.M3AlertDialogBuilder; + +import java.util.ArrayList; + +import me.grishka.appkit.utils.V; + +public class TimeLineFragment extends SettingsBaseFragment{ + + private SwitchItem showNewPostsButtonItem, compactReblogReplyLineItem; + @Override + public void addItems(ArrayList items) { + items.add(new SwitchItem(R.string.sk_settings_show_replies, R.drawable.ic_fluent_chat_multiple_24_regular, GlobalUserPreferences.showReplies, i->{ + GlobalUserPreferences.showReplies=i.checked; + GlobalUserPreferences.save(); + })); + if (getInstance().pleroma != null) { + items.add(new ButtonItem(R.string.sk_settings_reply_visibility, R.drawable.ic_fluent_chat_24_regular, b->{ + PopupMenu popupMenu=new PopupMenu(getActivity(), b, Gravity.CENTER_HORIZONTAL); + popupMenu.inflate(R.menu.reply_visibility); + popupMenu.setOnMenuItemClickListener(item -> this.onReplyVisibilityChanged(item, b)); + b.setOnTouchListener(popupMenu.getDragToOpenListener()); + b.setOnClickListener(v->popupMenu.show()); + b.setText(GlobalUserPreferences.replyVisibility == null ? + R.string.sk_settings_reply_visibility_all : + switch(GlobalUserPreferences.replyVisibility){ + case "following" -> R.string.sk_settings_reply_visibility_following; + case "self" -> R.string.sk_settings_reply_visibility_self; + default -> R.string.sk_settings_reply_visibility_all; + }); + })); + } + items.add(new SwitchItem(R.string.sk_settings_show_boosts, R.drawable.ic_fluent_arrow_repeat_all_24_regular, GlobalUserPreferences.showBoosts, i->{ + GlobalUserPreferences.showBoosts=i.checked; + GlobalUserPreferences.save(); + })); + items.add(new SwitchItem(R.string.sk_settings_load_new_posts, R.drawable.ic_fluent_arrow_sync_24_regular, GlobalUserPreferences.loadNewPosts, i->{ + GlobalUserPreferences.loadNewPosts=i.checked; + showNewPostsButtonItem.enabled = i.checked; + if (!i.checked) { + GlobalUserPreferences.showNewPostsButton = false; + showNewPostsButtonItem.checked = false; + } + if (list.findViewHolderForAdapterPosition(items.indexOf(showNewPostsButtonItem)) instanceof SwitchViewHolder svh) svh.rebind(); + GlobalUserPreferences.save(); + })); + items.add(showNewPostsButtonItem = new SwitchItem(R.string.sk_settings_show_new_posts_button, R.drawable.ic_fluent_arrow_up_24_regular, GlobalUserPreferences.showNewPostsButton, i->{ + GlobalUserPreferences.showNewPostsButton=i.checked; + GlobalUserPreferences.save(); + })); + + items.add(new SwitchItem(R.string.sk_settings_show_alt_indicator, R.drawable.ic_fluent_scan_text_24_regular, GlobalUserPreferences.showAltIndicator, i->{ + GlobalUserPreferences.showAltIndicator=i.checked; + GlobalUserPreferences.save(); + needAppRestart=true; + })); + items.add(new SwitchItem(R.string.sk_settings_show_no_alt_indicator, R.drawable.ic_fluent_important_24_regular, GlobalUserPreferences.showNoAltIndicator, i->{ + GlobalUserPreferences.showNoAltIndicator=i.checked; + GlobalUserPreferences.save(); + needAppRestart=true; + })); + items.add(new SwitchItem(R.string.sk_settings_collapse_long_posts, R.drawable.ic_fluent_chevron_down_24_regular, GlobalUserPreferences.collapseLongPosts, i->{ + GlobalUserPreferences.collapseLongPosts=i.checked; + GlobalUserPreferences.save(); + })); + items.add(new SwitchItem(R.string.sk_settings_hide_fab, R.drawable.ic_fluent_edit_24_regular, GlobalUserPreferences.autoHideFab, i->{ + GlobalUserPreferences.autoHideFab=i.checked; + GlobalUserPreferences.save(); + needAppRestart=true; + })); + items.add(new SwitchItem(R.string.sk_reply_line_above_avatar, R.drawable.ic_fluent_arrow_reply_24_regular, GlobalUserPreferences.replyLineAboveHeader, i->{ + GlobalUserPreferences.replyLineAboveHeader=i.checked; + GlobalUserPreferences.compactReblogReplyLine=i.checked; + compactReblogReplyLineItem.enabled=i.checked; + compactReblogReplyLineItem.checked= GlobalUserPreferences.replyLineAboveHeader; + if (list.findViewHolderForAdapterPosition(items.indexOf(compactReblogReplyLineItem)) instanceof SwitchViewHolder svh) svh.rebind(); + GlobalUserPreferences.save(); + needAppRestart=true; + })); + items.add(compactReblogReplyLineItem=new SwitchItem(R.string.sk_compact_reblog_reply_line, R.drawable.ic_fluent_re_order_24_regular, GlobalUserPreferences.compactReblogReplyLine, i->{ + GlobalUserPreferences.compactReblogReplyLine=i.checked; + GlobalUserPreferences.save(); + needAppRestart=true; + })); + compactReblogReplyLineItem.enabled=GlobalUserPreferences.replyLineAboveHeader; + items.add(new SwitchItem(R.string.sk_settings_hide_interaction, R.drawable.ic_fluent_eye_24_regular, GlobalUserPreferences.spectatorMode, i->{ + GlobalUserPreferences.spectatorMode=i.checked; + GlobalUserPreferences.save(); + needAppRestart=true; + })); + } + + private boolean onReplyVisibilityChanged(MenuItem item, Button btn){ + String pref = null; + int id = item.getItemId(); + + if (id == R.id.reply_visibility_following) pref = "following"; + else if (id == R.id.reply_visibility_self) pref = "self"; + + GlobalUserPreferences.replyVisibility=pref; + GlobalUserPreferences.save(); + btn.setText(GlobalUserPreferences.replyVisibility == null ? + R.string.sk_settings_reply_visibility_all : + switch(GlobalUserPreferences.replyVisibility){ + case "following" -> R.string.sk_settings_reply_visibility_following; + case "self" -> R.string.sk_settings_reply_visibility_self; + default -> R.string.sk_settings_reply_visibility_all; + }); + return true; + } +}