Skip to content

Commit

Permalink
Refactoring: Move preferences constants to InstanceSettings in order …
Browse files Browse the repository at this point in the history
…to have these constants and corresponding fields in one place
  • Loading branch information
yvolk committed Sep 15, 2019
1 parent 9c8bfb7 commit 7f94634
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import androidx.test.platform.app.InstrumentationRegistry;

import static org.andstatus.todoagenda.prefs.AllSettings.getStorageKey;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_WIDGET_ID;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_WIDGET_ID;
import static org.andstatus.todoagenda.provider.QueryResultsStorage.KEY_SETTINGS;

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ public void addResults(List<QueryResult> results) {
if (!results.isEmpty()) {
Context context = getSettings().getContext();
int widgetId = getSettings().getWidgetId();
ApplicationPreferences.startEditing(context, widgetId);
ApplicationPreferences.fromInstanceSettings(context, widgetId);
ApplicationPreferences.setLockedTimeZoneId(context, results.get(0).getExecutedAt().getZone().getID());
ApplicationPreferences.save(context, widgetId);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public int getWidgetId() {
}

public void startEditing() {
ApplicationPreferences.startEditing(getContext(), getWidgetId());
ApplicationPreferences.fromInstanceSettings(getContext(), getWidgetId());
}

public void saveSettings() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/andstatus/todoagenda/Theme.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.andstatus.todoagenda;

import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_ENTRY_THEME_DEFAULT;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_ENTRY_THEME_DEFAULT;

public enum Theme {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ protected void onResume() {

@Override
protected void onCreate(Bundle savedInstanceState) {
prepareForNewIntent(getIntent());
super.onCreate(savedInstanceState);
if (openThisActivity(getIntent())) {
super.onCreate(savedInstanceState);
}
}

private void prepareForNewIntent(Intent newIntent) {
private boolean openThisActivity(Intent newIntent) {
int newWidgetId = newIntent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
if (newWidgetId == 0) {
newWidgetId = ApplicationPreferences.getWidgetId(this);
Expand All @@ -59,13 +60,14 @@ private void prepareForNewIntent(Intent newIntent) {
restartIntent = MainActivity.intentToConfigure(this, newWidgetId);
} else if (widgetId == 0) {
widgetId = newWidgetId;
ApplicationPreferences.startEditing(this, widgetId);
ApplicationPreferences.fromInstanceSettings(this, widgetId);
}
if (restartIntent != null) {
widgetId = 0;
startActivity(restartIntent);
finish();
}
return restartIntent == null;
}

private void restartIfNeeded() {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ private void showStatus() {
}

private void showEventsEnded() {
ListPreference preference = (ListPreference) findPreference(ApplicationPreferences.PREF_EVENTS_ENDED);
ListPreference preference = (ListPreference) findPreference(InstanceSettings.PREF_EVENTS_ENDED);
preference.setSummary(preference.getEntry());
}

private void showEvenRange() {
ListPreference preference = (ListPreference) findPreference(ApplicationPreferences.PREF_EVENT_RANGE);
ListPreference preference = (ListPreference) findPreference(InstanceSettings.PREF_EVENT_RANGE);
preference.setSummary(preference.getEntry());
}

private void showHideBasedOnKeywords() {
EditTextPreference preference = (EditTextPreference) findPreference(ApplicationPreferences.PREF_HIDE_BASED_ON_KEYWORDS);
EditTextPreference preference = (EditTextPreference) findPreference(InstanceSettings.PREF_HIDE_BASED_ON_KEYWORDS);
KeywordsFilter filter = new KeywordsFilter(preference.getText());
if (filter.isEmpty()) {
preference.setSummary(R.string.this_option_is_turned_off);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FeedbackPreferencesFragment extends PreferenceFragment {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
switch (preference.getKey()) {
case ApplicationPreferences.KEY_SHARE_EVENTS_FOR_DEBUGGING:
case InstanceSettings.KEY_SHARE_EVENTS_FOR_DEBUGGING:
QueryResultsStorage.shareEventsForDebugging(getActivity(),
ApplicationPreferences.getWidgetId(getActivity()));
default:
Expand Down
226 changes: 125 additions & 101 deletions app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public void onResume() {
}

private void showEventEntryLayout() {
Preference preference = findPreference(ApplicationPreferences.PREF_EVENT_ENTRY_LAYOUT);
Preference preference = findPreference(InstanceSettings.PREF_EVENT_ENTRY_LAYOUT);
if (preference != null) {
preference.setSummary(ApplicationPreferences.getEventEntryLayout(getActivity()).summaryResId);
}
}

private void showWidgetHeaderLayout() {
Preference preference = findPreference(ApplicationPreferences.PREF_WIDGET_HEADER_LAYOUT);
Preference preference = findPreference(InstanceSettings.PREF_WIDGET_HEADER_LAYOUT);
if (preference != null) {
preference.setSummary(ApplicationPreferences.getWidgetHeaderLayout(getActivity()).summaryResId);
}
Expand All @@ -47,10 +47,10 @@ public void onPause() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
case ApplicationPreferences.PREF_EVENT_ENTRY_LAYOUT:
case InstanceSettings.PREF_EVENT_ENTRY_LAYOUT:
showEventEntryLayout();
break;
case ApplicationPreferences.PREF_WIDGET_HEADER_LAYOUT:
case InstanceSettings.PREF_WIDGET_HEADER_LAYOUT:
showWidgetHeaderLayout();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onResume() {
}

private void showLockTimeZone(boolean setAlso) {
CheckBoxPreference preference = (CheckBoxPreference) findPreference(ApplicationPreferences.PREF_LOCK_TIME_ZONE);
CheckBoxPreference preference = (CheckBoxPreference) findPreference(InstanceSettings.PREF_LOCK_TIME_ZONE);
if (preference != null) {
boolean isChecked = setAlso ? ApplicationPreferences.isTimeZoneLocked(getActivity()) : preference.isChecked();
if (setAlso && preference.isChecked() != isChecked) {
Expand All @@ -50,7 +50,7 @@ private void showLockTimeZone(boolean setAlso) {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
switch (preference.getKey()) {
case ApplicationPreferences.PREF_LOCK_TIME_ZONE:
case InstanceSettings.PREF_LOCK_TIME_ZONE:
if (preference instanceof CheckBoxPreference) {
CheckBoxPreference checkPref = (CheckBoxPreference) preference;
ApplicationPreferences.setLockedTimeZoneId(getActivity(),
Expand All @@ -73,7 +73,7 @@ public void onPause() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
case ApplicationPreferences.PREF_WIDGET_INSTANCE_NAME:
case InstanceSettings.PREF_WIDGET_INSTANCE_NAME:
getActivity().finish();
startActivity(MainActivity.intentToConfigure(getActivity(), ApplicationPreferences
.getWidgetId(getActivity())));
Expand All @@ -84,7 +84,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}

private void showWidgetInstanceName() {
Preference preference = findPreference(ApplicationPreferences.PREF_WIDGET_INSTANCE_NAME);
Preference preference = findPreference(InstanceSettings.PREF_WIDGET_INSTANCE_NAME);
if (preference != null) {
preference.setSummary(ApplicationPreferences.getWidgetInstanceName(getActivity()));
}
Expand Down

0 comments on commit 7f94634

Please sign in to comment.