1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

Reorganise settings, add update check setting

This commit is contained in:
Ammar Githam 2020-09-07 22:08:49 +09:00
parent 95b362970b
commit 0d7b5199ea
3 changed files with 61 additions and 22 deletions

View File

@ -112,7 +112,8 @@ public class MainActivity extends BaseLanguageActivity {
} }
setupScrollingListener(); setupScrollingListener();
setupSuggestions(); setupSuggestions();
FlavorTown.updateCheck(this); final boolean checkUpdates = settingsHelper.getBoolean(Constants.CHECK_UPDATES);
if (checkUpdates) FlavorTown.updateCheck(this);
FlavorTown.changelogCheck(this); FlavorTown.changelogCheck(this);
final Intent intent = getIntent(); final Intent intent = getIntent();

View File

@ -10,7 +10,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.DropDownPreference;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
@ -21,6 +20,7 @@ import androidx.preference.SwitchPreferenceCompat;
import com.google.android.material.switchmaterial.SwitchMaterial; import com.google.android.material.switchmaterial.SwitchMaterial;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.dialogs.TimeSettingsDialog; import awais.instagrabber.dialogs.TimeSettingsDialog;
@ -44,26 +44,47 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
@Override @Override
void setupPreferenceScreen(final PreferenceScreen screen) { void setupPreferenceScreen(final PreferenceScreen screen) {
screen.addPreference(getLanguagePreference());
screen.addPreference(getDefaultTabPreference()); final PreferenceCategory generalCategory = new PreferenceCategory(requireContext());
screen.addPreference(getThemePreference()); screen.addPreference(generalCategory);
screen.addPreference(getAmoledThemePreference()); generalCategory.setTitle(getString(R.string.pref_category_general));
screen.addPreference(getDownloadUserFolderPreference()); generalCategory.setIconSpaceReserved(false);
screen.addPreference(getSaveToCustomFolderPreference()); generalCategory.addPreference(getDefaultTabPreference());
screen.addPreference(getAutoPlayVideosPreference()); generalCategory.addPreference(getUpdateCheckPreference());
screen.addPreference(getAlwaysMuteVideosPreference()); generalCategory.addPreference(getAutoPlayVideosPreference());
screen.addPreference(getPostTimePreference()); generalCategory.addPreference(getAlwaysMuteVideosPreference());
final PreferenceCategory themeCategory = new PreferenceCategory(requireContext());
screen.addPreference(themeCategory);
themeCategory.setTitle(getString(R.string.pref_category_theme));
themeCategory.setIconSpaceReserved(false);
themeCategory.addPreference(getThemePreference());
themeCategory.addPreference(getAmoledThemePreference());
final PreferenceCategory downloadsCategory = new PreferenceCategory(requireContext());
screen.addPreference(downloadsCategory);
downloadsCategory.setTitle(getString(R.string.pref_category_downloads));
downloadsCategory.setIconSpaceReserved(false);
downloadsCategory.addPreference(getDownloadUserFolderPreference());
downloadsCategory.addPreference(getSaveToCustomFolderPreference());
final PreferenceCategory localeCategory = new PreferenceCategory(requireContext());
screen.addPreference(localeCategory);
localeCategory.setTitle(getString(R.string.pref_category_locale));
localeCategory.setIconSpaceReserved(false);
localeCategory.addPreference(getLanguagePreference());
localeCategory.addPreference(getPostTimePreference());
final PreferenceCategory loggedInUsersPreferenceCategory = new PreferenceCategory(requireContext()); final PreferenceCategory loggedInUsersPreferenceCategory = new PreferenceCategory(requireContext());
loggedInUsersPreferenceCategory.setIconSpaceReserved(false);
screen.addPreference(loggedInUsersPreferenceCategory); screen.addPreference(loggedInUsersPreferenceCategory);
loggedInUsersPreferenceCategory.setIconSpaceReserved(false);
loggedInUsersPreferenceCategory.setTitle(R.string.login_settings); loggedInUsersPreferenceCategory.setTitle(R.string.login_settings);
loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference()); loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference());
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference()); loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(requireContext()); final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(requireContext());
anonUsersPreferenceCategory.setIconSpaceReserved(false);
screen.addPreference(anonUsersPreferenceCategory); screen.addPreference(anonUsersPreferenceCategory);
anonUsersPreferenceCategory.setIconSpaceReserved(false);
anonUsersPreferenceCategory.setTitle(R.string.anonymous_settings); anonUsersPreferenceCategory.setTitle(R.string.anonymous_settings);
anonUsersPreferenceCategory.addPreference(getUseInstaDpPreference()); anonUsersPreferenceCategory.addPreference(getUseInstaDpPreference());
anonUsersPreferenceCategory.addPreference(getUseStoriesIgPreference()); anonUsersPreferenceCategory.addPreference(getUseStoriesIgPreference());
@ -71,8 +92,8 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
} }
@NonNull @NonNull
private DropDownPreference getLanguagePreference() { private Preference getLanguagePreference() {
final DropDownPreference preference = new DropDownPreference(requireContext()); final ListPreference preference = new ListPreference(requireContext());
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance()); preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance());
final int length = getResources().getStringArray(R.array.languages).length; final int length = getResources().getStringArray(R.array.languages).length;
final String[] values = new String[length]; final String[] values = new String[length];
@ -81,6 +102,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
} }
preference.setKey(Constants.APP_LANGUAGE); preference.setKey(Constants.APP_LANGUAGE);
preference.setTitle(R.string.select_language); preference.setTitle(R.string.select_language);
preference.setDialogTitle(R.string.select_language);
preference.setEntries(R.array.languages); preference.setEntries(R.array.languages);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
preference.setEntryValues(values); preference.setEntryValues(values);
@ -92,7 +114,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
} }
private Preference getDefaultTabPreference() { private Preference getDefaultTabPreference() {
final DropDownPreference preference = new DropDownPreference(requireContext()); final ListPreference preference = new ListPreference(requireContext());
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance()); preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance());
final FragmentActivity activity = getActivity(); final FragmentActivity activity = getActivity();
if (activity == null) { if (activity == null) {
@ -108,7 +130,8 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
} }
mainNavIds.recycle(); mainNavIds.recycle();
preference.setKey(Constants.DEFAULT_TAB); preference.setKey(Constants.DEFAULT_TAB);
preference.setTitle(R.string.select_default_tab); preference.setTitle(R.string.pref_start_screen);
preference.setDialogTitle(R.string.pref_start_screen);
preference.setEntries(R.array.main_nav_ids_values); preference.setEntries(R.array.main_nav_ids_values);
preference.setEntryValues(values); preference.setEntryValues(values);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
@ -119,9 +142,17 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
return preference; return preference;
} }
private Preference getUpdateCheckPreference() {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(requireContext());
preference.setKey(Constants.CHECK_UPDATES);
preference.setTitle(R.string.update_check);
preference.setIconSpaceReserved(false);
return preference;
}
@NonNull @NonNull
private DropDownPreference getThemePreference() { private Preference getThemePreference() {
final DropDownPreference preference = new DropDownPreference(requireContext()); final ListPreference preference = new ListPreference(requireContext());
preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance()); preference.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance());
final int length = getResources().getStringArray(R.array.theme_presets).length; final int length = getResources().getStringArray(R.array.theme_presets).length;
final String[] values = new String[length]; final String[] values = new String[length];
@ -130,6 +161,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
} }
preference.setKey(Constants.APP_THEME); preference.setKey(Constants.APP_THEME);
preference.setTitle(R.string.theme_settings); preference.setTitle(R.string.theme_settings);
preference.setDialogTitle(R.string.theme_settings);
preference.setEntries(R.array.theme_presets); preference.setEntries(R.array.theme_presets);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
preference.setEntryValues(values); preference.setEntryValues(values);
@ -226,6 +258,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
private Preference getPostTimePreference() { private Preference getPostTimePreference() {
final Preference preference = new Preference(requireContext()); final Preference preference = new Preference(requireContext());
preference.setTitle(R.string.time_settings); preference.setTitle(R.string.time_settings);
preference.setSummary(Utils.datetimeParser.format(new Date()));
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
preference.setOnPreferenceClickListener(preference1 -> { preference.setOnPreferenceClickListener(preference1 -> {
new TimeSettingsDialog( new TimeSettingsDialog(
@ -249,6 +282,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
} }
settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat); settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat);
Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone(); Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone();
preference.setSummary(Utils.datetimeParser.format(new Date()));
} }
).show(getParentFragmentManager(), null); ).show(getParentFragmentManager(), null);
return true; return true;

View File

@ -34,7 +34,7 @@
<string name="title_user_story">User Story</string> <string name="title_user_story">User Story</string>
<string name="title_changelog">Changelog</string> <string name="title_changelog">Changelog</string>
<string name="bottom_toolbar">Show toolbar at bottom</string> <string name="bottom_toolbar">Show toolbar at bottom</string>
<string name="update_check">Check for new updates on GitHub at startup</string> <string name="update_check">Check for updates at startup</string>
<string name="download_user_folder">Download posts to username folder in Downloads</string> <string name="download_user_folder">Download posts to username folder in Downloads</string>
<string name="autoload_posts">Auto-load all posts from user</string> <string name="autoload_posts">Auto-load all posts from user</string>
<string name="mark_as_seen_setting">Mark stories as seen after viewing</string> <string name="mark_as_seen_setting">Mark stories as seen after viewing</string>
@ -98,7 +98,7 @@
<string name="login">Login</string> <string name="login">Login</string>
<string name="logout">Logout</string> <string name="logout">Logout</string>
<string name="send_logs">Send Debug Logs</string> <string name="send_logs">Send Debug Logs</string>
<string name="time_settings">Post time format</string> <string name="time_settings">Date format</string>
<string name="project_link">Visit Project Page</string> <string name="project_link">Visit Project Page</string>
<string name="telegram_link">Join Telegram Group</string> <string name="telegram_link">Join Telegram Group</string>
<string name="matrix_link">Join Matrix Room</string> <string name="matrix_link">Join Matrix Room</string>
@ -253,5 +253,9 @@
<string name="mark_as_seen">Mark as seen</string> <string name="mark_as_seen">Mark as seen</string>
<string name="skip_update_checkbox">Do not show again until next update</string> <string name="skip_update_checkbox">Do not show again until next update</string>
<string name="version">Version</string> <string name="version">Version</string>
<string name="select_default_tab">Default tab</string> <string name="pref_start_screen">Start screen</string>
<string name="pref_category_general">General</string>
<string name="pref_category_theme">Theme</string>
<string name="pref_category_downloads">Downloads</string>
<string name="pref_category_locale">Locale</string>
</resources> </resources>