From 2164c2fe911e597d4927b752687ad02b866e6c5c Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 30 Dec 2022 16:01:51 +0100 Subject: [PATCH] comment #702 - Separated settings --- .../android/ui/drawer/StatusAdapter.java | 4 +- .../FragmentExtraFeaturesSettings.java | 103 ++++++++++++++++++ .../settings/FragmentInterfaceSettings.java | 1 + .../settings/FragmentSettingsCategories.java | 10 ++ .../settings/FragmentTimelinesSettings.java | 27 ++++- .../res/drawable/ic_baseline_extension_24.xml | 10 ++ .../res/navigation/nav_graph_settings.xml | 13 +++ app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/pref_categories.xml | 7 ++ app/src/main/res/xml/pref_extra_features.xml | 31 ++++++ app/src/main/res/xml/pref_interface.xml | 8 -- 11 files changed, 207 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentExtraFeaturesSettings.java create mode 100644 app/src/main/res/drawable/ic_baseline_extension_24.xml create mode 100644 app/src/main/res/xml/pref_extra_features.xml diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 0d1bebfec..57236adfa 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -392,8 +392,8 @@ public class StatusAdapter extends RecyclerView.Adapter boolean confirmFav = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION_FAV), false); boolean confirmBoost = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION), true); boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false); - boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK), true); - boolean displayTranslate = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_TRANSLATE), false); + boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true); + boolean displayTranslate = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false); boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false); boolean removeLeftMargin = sharedpreferences.getBoolean(context.getString(R.string.SET_REMOVE_LEFT_MARGIN), false); boolean extraFeatures = sharedpreferences.getBoolean(context.getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, false); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentExtraFeaturesSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentExtraFeaturesSettings.java new file mode 100644 index 000000000..1d11a5db7 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentExtraFeaturesSettings.java @@ -0,0 +1,103 @@ +package app.fedilab.android.ui.fragment.settings; +/* Copyright 2022 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + +import android.content.SharedPreferences; +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceManager; +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreferenceCompat; + +import app.fedilab.android.R; +import app.fedilab.android.activities.MainActivity; + +public class FragmentExtraFeaturesSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { + + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.pref_extra_features); + createPref(); + } + + private void createPref() { + + getPreferenceScreen().removeAll(); + addPreferencesFromResource(R.xml.pref_extra_features); + PreferenceScreen preferenceScreen = getPreferenceScreen(); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + SwitchPreferenceCompat SET_EXTAND_EXTRA_FEATURES = findPreference(getString(R.string.SET_EXTAND_EXTRA_FEATURES)); + if (SET_EXTAND_EXTRA_FEATURES != null) { + boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, false); + SET_EXTAND_EXTRA_FEATURES.setChecked(checked); + } + SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK)); + if (SET_DISPLAY_BOOKMARK != null) { + boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true); + SET_DISPLAY_BOOKMARK.setChecked(checked); + } + SwitchPreferenceCompat SET_DISPLAY_TRANSLATE = findPreference(getString(R.string.SET_DISPLAY_TRANSLATE)); + if (SET_DISPLAY_TRANSLATE != null) { + boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false); + SET_DISPLAY_TRANSLATE.setChecked(checked); + } + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (getActivity() != null) { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + SharedPreferences.Editor editor = sharedpreferences.edit(); + if (key.compareToIgnoreCase(getString(R.string.SET_EXTAND_EXTRA_FEATURES)) == 0) { + SwitchPreferenceCompat SET_EXTAND_EXTRA_FEATURES = findPreference(getString(R.string.SET_EXTAND_EXTRA_FEATURES)); + if (SET_EXTAND_EXTRA_FEATURES != null) { + editor.putBoolean(getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, SET_EXTAND_EXTRA_FEATURES.isChecked()); + } + } + if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_BOOKMARK)) == 0) { + SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK)); + if (SET_DISPLAY_BOOKMARK != null) { + editor.putBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_BOOKMARK.isChecked()); + } + } + if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_TRANSLATE)) == 0) { + SwitchPreferenceCompat SET_DISPLAY_TRANSLATE = findPreference(getString(R.string.SET_DISPLAY_TRANSLATE)); + if (SET_DISPLAY_TRANSLATE != null) { + editor.putBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_TRANSLATE.isChecked()); + } + } + editor.apply(); + } + } + + @Override + public void onResume() { + super.onResume(); + + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onPause() { + super.onPause(); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); + } + + +} diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java index ca7ff5f84..998db5779 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentInterfaceSettings.java @@ -108,6 +108,7 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen if (SET_EXTAND_EXTRA_FEATURES != null) { editor.putBoolean(getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, SET_EXTAND_EXTRA_FEATURES.isChecked()); } + recreate = true; } if (key.compareToIgnoreCase(getString(R.string.SET_LOGO_LAUNCHER)) == 0) { ListPreference SET_LOGO_LAUNCHER = findPreference(getString(R.string.SET_LOGO_LAUNCHER)); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java index eb11a00ba..258e32b5a 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java @@ -121,6 +121,16 @@ public class FragmentSettingsCategories extends PreferenceFragmentCompat { return false; }); } + + Preference pref_category_key_extra_features = findPreference(getString(R.string.pref_category_key_extra_features)); + if (pref_category_key_extra_features != null) { + pref_category_key_extra_features.setOnPreferenceClickListener(preference -> { + NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container); + navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToExtraFeatures()); + return false; + }); + } + ActivityResultLauncher permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { try { diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java index 04fd9e9f8..49867c7f4 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java @@ -22,8 +22,10 @@ import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreferenceCompat; import app.fedilab.android.R; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.helper.Helper; public class FragmentTimelinesSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -37,6 +39,7 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen private void createPref() { getPreferenceScreen().removeAll(); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); addPreferencesFromResource(R.xml.pref_timelines); PreferenceScreen preferenceScreen = getPreferenceScreen(); ListPreference SET_LOAD_MEDIA_TYPE = findPreference(getString(R.string.SET_LOAD_MEDIA_TYPE)); @@ -60,6 +63,16 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_VERSION"); } } + SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK)); + if (SET_DISPLAY_BOOKMARK != null) { + boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true); + SET_DISPLAY_BOOKMARK.setChecked(checked); + } + SwitchPreferenceCompat SET_DISPLAY_TRANSLATE = findPreference(getString(R.string.SET_DISPLAY_TRANSLATE)); + if (SET_DISPLAY_TRANSLATE != null) { + boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false); + SET_DISPLAY_TRANSLATE.setChecked(checked); + } } @Override @@ -67,10 +80,22 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen if (getActivity() != null) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.apply(); if (key.compareToIgnoreCase(getString(R.string.SET_TRANSLATOR)) == 0) { createPref(); } + if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_BOOKMARK)) == 0) { + SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK)); + if (SET_DISPLAY_BOOKMARK != null) { + editor.putBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_BOOKMARK.isChecked()); + } + } + if (key.compareToIgnoreCase(getString(R.string.SET_DISPLAY_TRANSLATE)) == 0) { + SwitchPreferenceCompat SET_DISPLAY_TRANSLATE = findPreference(getString(R.string.SET_DISPLAY_TRANSLATE)); + if (SET_DISPLAY_TRANSLATE != null) { + editor.putBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_TRANSLATE.isChecked()); + } + } + editor.apply(); } } diff --git a/app/src/main/res/drawable/ic_baseline_extension_24.xml b/app/src/main/res/drawable/ic_baseline_extension_24.xml new file mode 100644 index 000000000..bc61292c5 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_extension_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/navigation/nav_graph_settings.xml b/app/src/main/res/navigation/nav_graph_settings.xml index 729f2caf4..4290ad790 100644 --- a/app/src/main/res/navigation/nav_graph_settings.xml +++ b/app/src/main/res/navigation/nav_graph_settings.xml @@ -68,6 +68,14 @@ app:exitAnim="@anim/exit" app:popEnterAnim="@anim/pop_enter" app:popExitAnim="@anim/pop_exit" /> + + + + pref_category_theming pref_category_administration pref_category_languages + pref_category_key_extra_features + pref_export_settings pref_import_settings Export settings @@ -2150,4 +2152,6 @@ Translator version Extra features By enabling that option the app will display extra features. This feature is done for social softwares like Pleroma, Akkoma or Glitch Social + Icons visibility + You can safely hide these icons at the bottom to have more space. They are also in the submenu. \ No newline at end of file diff --git a/app/src/main/res/xml/pref_categories.xml b/app/src/main/res/xml/pref_categories.xml index 3d2669c56..826f560c5 100644 --- a/app/src/main/res/xml/pref_categories.xml +++ b/app/src/main/res/xml/pref_categories.xml @@ -70,6 +70,13 @@ app:key="@string/pref_category_key_languages" /> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_interface.xml b/app/src/main/res/xml/pref_interface.xml index 4097c3a81..55b5f58ec 100644 --- a/app/src/main/res/xml/pref_interface.xml +++ b/app/src/main/res/xml/pref_interface.xml @@ -28,14 +28,6 @@ app:summary="@string/set_remove_left_margin" app:title="@string/set_remove_left_margin_title" /> - -