fix: move method to fix compiler error
This commit is contained in:
parent
ea152234a9
commit
78a0c60600
|
@ -1,32 +1,26 @@
|
|||
package org.joinmastodon.android.fragments.settings;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Build;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.joinmastodon.android.GlobalUserPreferences;
|
||||
import org.joinmastodon.android.MastodonApp;
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SettingsAppearanceFragment extends SettingsBaseFragment {
|
||||
|
||||
@Override
|
||||
public void addItems(ArrayList<Item> items) {
|
||||
items.add(themeItem SettingsBaseFragment.ThemeItem());
|
||||
items.add(new SettingsFragment.ButtonItem(R.string.sk_settings_color_palette, R.drawable.ic_fluent_color_24_regular, b -> {
|
||||
themeItem = new ThemeItem();
|
||||
items.add(themeItem);
|
||||
items.add(new ButtonItem(R.string.sk_settings_color_palette, R.drawable.ic_fluent_color_24_regular, b -> {
|
||||
PopupMenu popupMenu = new PopupMenu(getActivity(), b, Gravity.CENTER_HORIZONTAL);
|
||||
popupMenu.inflate(R.menu.color_palettes);
|
||||
popupMenu.getMenu().findItem(R.id.m3_color).setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
|
||||
popupMenu.setOnMenuItemClickListener(SettingsBaseFragment.this::onColorPreferenceClick);
|
||||
popupMenu.setOnMenuItemClickListener(this::onColorPreferenceClick);
|
||||
b.setOnTouchListener(popupMenu.getDragToOpenListener());
|
||||
b.setOnClickListener(v -> popupMenu.show());
|
||||
b.setText(switch (GlobalUserPreferences.color) {
|
||||
|
@ -41,21 +35,43 @@ public class SettingsAppearanceFragment extends SettingsBaseFragment {
|
|||
case NORD -> R.string.mo_color_palette_nord;
|
||||
});
|
||||
}));
|
||||
items.add(new SettingsBaseFragment.SwitchItem(R.string.theme_true_black, R.drawable.ic_fluent_dark_theme_24_regular, GlobalUserPreferences.trueBlackTheme, this::onTrueBlackThemeChanged));
|
||||
items.add(new SettingsBaseFragment.SwitchItem(R.string.sk_disable_marquee, R.drawable.ic_fluent_text_more_24_regular, GlobalUserPreferences.disableMarquee, i -> {
|
||||
items.add(new SwitchItem(R.string.theme_true_black, R.drawable.ic_fluent_dark_theme_24_regular, GlobalUserPreferences.trueBlackTheme, this::onTrueBlackThemeChanged));
|
||||
items.add(new SwitchItem(R.string.sk_disable_marquee, R.drawable.ic_fluent_text_more_24_regular, GlobalUserPreferences.disableMarquee, i -> {
|
||||
GlobalUserPreferences.disableMarquee = i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
needAppRestart = true;
|
||||
}));
|
||||
items.add(new SettingsBaseFragment.SwitchItem(R.string.sk_settings_uniform_icon_for_notifications, R.drawable.ic_ntf_logo, GlobalUserPreferences.uniformNotificationIcon, i -> {
|
||||
items.add(new SwitchItem(R.string.sk_settings_uniform_icon_for_notifications, R.drawable.ic_ntf_logo, GlobalUserPreferences.uniformNotificationIcon, i -> {
|
||||
GlobalUserPreferences.uniformNotificationIcon = i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
}));
|
||||
items.add(new SettingsBaseFragment.SwitchItem(R.string.sk_settings_reduce_motion, R.drawable.ic_fluent_star_emphasis_24_regular, GlobalUserPreferences.reduceMotion, i -> {
|
||||
items.add(new SwitchItem(R.string.sk_settings_reduce_motion, R.drawable.ic_fluent_star_emphasis_24_regular, GlobalUserPreferences.reduceMotion, i -> {
|
||||
GlobalUserPreferences.reduceMotion = i.checked;
|
||||
GlobalUserPreferences.save();
|
||||
needAppRestart = true;
|
||||
}));
|
||||
}
|
||||
|
||||
private boolean onColorPreferenceClick(MenuItem item) {
|
||||
GlobalUserPreferences.ColorPreference pref = null;
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.m3_color) pref = GlobalUserPreferences.ColorPreference.MATERIAL3;
|
||||
else if (id == R.id.pink_color) pref = GlobalUserPreferences.ColorPreference.PINK;
|
||||
else if (id == R.id.purple_color) pref = GlobalUserPreferences.ColorPreference.PURPLE;
|
||||
else if (id == R.id.green_color) pref = GlobalUserPreferences.ColorPreference.GREEN;
|
||||
else if (id == R.id.blue_color) pref = GlobalUserPreferences.ColorPreference.BLUE;
|
||||
else if (id == R.id.brown_color) pref = GlobalUserPreferences.ColorPreference.BROWN;
|
||||
else if (id == R.id.red_color) pref = GlobalUserPreferences.ColorPreference.RED;
|
||||
else if (id == R.id.yellow_color) pref = GlobalUserPreferences.ColorPreference.YELLOW;
|
||||
else if (id == R.id.nord_color) pref = GlobalUserPreferences.ColorPreference.NORD;
|
||||
|
||||
if (pref == null) return false;
|
||||
|
||||
GlobalUserPreferences.color=pref;
|
||||
GlobalUserPreferences.save();
|
||||
restartActivityToApplyNewTheme();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
|
||||
protected boolean needAppRestart;
|
||||
|
||||
protected SettingsBaseFragment.NotificationPolicyItem notificationPolicyItem;
|
||||
protected NotificationPolicyItem notificationPolicyItem;
|
||||
|
||||
protected PushSubscription pushSubscription;
|
||||
protected ArrayList<Item> items=new ArrayList<>();
|
||||
|
@ -173,7 +173,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
protected class UpdateItem extends SettingsBaseFragment.Item {
|
||||
protected class UpdateItem extends Item {
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
|
@ -181,7 +181,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
protected static class ThemeItem extends SettingsBaseFragment.Item {
|
||||
protected static class ThemeItem extends Item {
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
|
@ -189,7 +189,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
protected static class NotificationPolicyItem extends SettingsBaseFragment.Item {
|
||||
protected static class NotificationPolicyItem extends Item {
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
|
@ -395,28 +395,6 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean onColorPreferenceClick(MenuItem item){
|
||||
GlobalUserPreferences.ColorPreference pref = null;
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.m3_color) pref = GlobalUserPreferences.ColorPreference.MATERIAL3;
|
||||
else if (id == R.id.pink_color) pref = GlobalUserPreferences.ColorPreference.PINK;
|
||||
else if (id == R.id.purple_color) pref = GlobalUserPreferences.ColorPreference.PURPLE;
|
||||
else if (id == R.id.green_color) pref = GlobalUserPreferences.ColorPreference.GREEN;
|
||||
else if (id == R.id.blue_color) pref = GlobalUserPreferences.ColorPreference.BLUE;
|
||||
else if (id == R.id.brown_color) pref = GlobalUserPreferences.ColorPreference.BROWN;
|
||||
else if (id == R.id.red_color) pref = GlobalUserPreferences.ColorPreference.RED;
|
||||
else if (id == R.id.yellow_color) pref = GlobalUserPreferences.ColorPreference.YELLOW;
|
||||
else if (id == R.id.nord_color) pref = GlobalUserPreferences.ColorPreference.NORD;
|
||||
|
||||
if (pref == null) return false;
|
||||
|
||||
GlobalUserPreferences.color=pref;
|
||||
GlobalUserPreferences.save();
|
||||
restartActivityToApplyNewTheme();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onThemePreferenceClick(GlobalUserPreferences.ThemePreference theme){
|
||||
GlobalUserPreferences.theme=theme;
|
||||
GlobalUserPreferences.save();
|
||||
|
@ -456,13 +434,13 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
|
||||
protected void onTrueBlackThemeChanged(SettingsBaseFragment.SwitchItem item){
|
||||
protected void onTrueBlackThemeChanged(SwitchItem item){
|
||||
GlobalUserPreferences.trueBlackTheme=item.checked;
|
||||
GlobalUserPreferences.save();
|
||||
|
||||
RecyclerView.ViewHolder themeHolder=list.findViewHolderForAdapterPosition(items.indexOf(themeItem));
|
||||
if(themeHolder!=null){
|
||||
((SettingsBaseFragment.ThemeViewHolder)themeHolder).bindSubitems();
|
||||
((ThemeViewHolder)themeHolder).bindSubitems();
|
||||
}else{
|
||||
list.getAdapter().notifyItemChanged(items.indexOf(themeItem));
|
||||
}
|
||||
|
@ -504,7 +482,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBind(SettingsBaseFragment.NotificationPolicyItem item){
|
||||
public void onBind(NotificationPolicyItem item){
|
||||
button.setText(switch(getPushSubscription().policy){
|
||||
case ALL -> R.string.notify_anyone;
|
||||
case FOLLOWED -> R.string.notify_followed;
|
||||
|
@ -523,7 +501,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
int index=items.indexOf(notificationPolicyItem);
|
||||
RecyclerView.ViewHolder policyHolder=list.findViewHolderForAdapterPosition(index);
|
||||
if(policyHolder!=null){
|
||||
((SettingsBaseFragment.NotificationPolicyViewHolder)policyHolder).rebind();
|
||||
((NotificationPolicyViewHolder)policyHolder).rebind();
|
||||
}else{
|
||||
list.getAdapter().notifyItemChanged(index);
|
||||
}
|
||||
|
@ -533,7 +511,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
onNotificationsChanged(value, newState);
|
||||
}
|
||||
index++;
|
||||
while(items.get(index) instanceof SettingsBaseFragment.SwitchItem si){
|
||||
while(items.get(index) instanceof SwitchItem si){
|
||||
si.enabled=si.checked=newState;
|
||||
RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(index);
|
||||
if(holder!=null)
|
||||
|
@ -622,7 +600,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBind(SettingsBaseFragment.ThemeItem item){
|
||||
public void onBind(ThemeItem item){
|
||||
bindSubitems();
|
||||
}
|
||||
|
||||
|
@ -810,7 +788,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBind(SettingsBaseFragment.UpdateItem item){
|
||||
public void onBind(UpdateItem item){
|
||||
GithubSelfUpdater updater=GithubSelfUpdater.getInstance();
|
||||
GithubSelfUpdater.UpdateState state=updater.getState();
|
||||
if (state == GithubSelfUpdater.UpdateState.CHECKING) return;
|
||||
|
|
Loading…
Reference in New Issue