mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Move preferences to uhabits-core
This commit is contained in:
@@ -32,9 +32,9 @@ import junit.framework.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BaseAndroidTest extends TestCase
|
||||
|
||||
protected Context targetContext;
|
||||
|
||||
protected AndroidPreferences prefs;
|
||||
protected Preferences prefs;
|
||||
|
||||
protected HabitList habitList;
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import android.support.test.uiautomator.*;
|
||||
import com.linkedin.android.testbutler.*;
|
||||
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.junit.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -44,7 +44,7 @@ public class BaseUserInterfaceTest
|
||||
|
||||
private HabitList habitList;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private HabitFixtures fixtures;
|
||||
|
||||
|
||||
@@ -23,15 +23,12 @@ import android.support.test.filters.*;
|
||||
import android.support.test.runner.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
@@ -41,7 +38,7 @@ public class HeaderViewTest extends BaseViewTest
|
||||
|
||||
private HeaderView view;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private MidnightTimer midnightTimer;
|
||||
|
||||
@@ -50,7 +47,7 @@ public class HeaderViewTest extends BaseViewTest
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
prefs = mock(Preferences.class);
|
||||
midnightTimer = mock(MidnightTimer.class);
|
||||
view = new HeaderView(targetContext, prefs, midnightTimer);
|
||||
view.setButtonCount(5);
|
||||
|
||||
@@ -25,10 +25,10 @@ import android.content.*;
|
||||
import com.activeandroid.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
|
||||
@@ -109,9 +109,8 @@ public class HabitsApplication extends Application
|
||||
notificationTray = component.getAndroidNotificationTray();
|
||||
notificationTray.startListening();
|
||||
|
||||
AndroidPreferences prefs = component.getPreferences();
|
||||
prefs.initialize();
|
||||
prefs.updateLastAppVersion();
|
||||
Preferences prefs = component.getPreferences();
|
||||
prefs.setLastAppVersion(BuildConfig.VERSION_CODE);
|
||||
|
||||
TaskRunner taskRunner = component.getTaskRunner();
|
||||
taskRunner.execute(() -> {
|
||||
|
||||
@@ -24,18 +24,17 @@ import android.content.*;
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
@@ -51,6 +50,8 @@ import dagger.*;
|
||||
})
|
||||
public interface HabitsComponent
|
||||
{
|
||||
AndroidNotificationTray getAndroidNotificationTray();
|
||||
|
||||
BaseSystem getBaseSystem();
|
||||
|
||||
CommandRunner getCommandRunner();
|
||||
@@ -58,8 +59,6 @@ public interface HabitsComponent
|
||||
@AppContext
|
||||
Context getContext();
|
||||
|
||||
Preferences getCorePreferences();
|
||||
|
||||
CreateHabitCommandFactory getCreateHabitCommandFactory();
|
||||
|
||||
EditHabitCommandFactory getEditHabitCommandFactory();
|
||||
@@ -84,9 +83,7 @@ public interface HabitsComponent
|
||||
|
||||
PendingIntentFactory getPendingIntentFactory();
|
||||
|
||||
AndroidPreferences getPreferences();
|
||||
|
||||
AndroidNotificationTray getAndroidNotificationTray();
|
||||
Preferences getPreferences();
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import dagger.*;
|
||||
@@ -32,17 +32,24 @@ public class HabitsModule
|
||||
{
|
||||
@Provides
|
||||
@AppScope
|
||||
public static Preferences getPreferences(AndroidPreferences preferences)
|
||||
public static Preferences getPreferences(SharedPreferencesStorage storage)
|
||||
{
|
||||
return preferences;
|
||||
return new Preferences(storage);
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@AppScope
|
||||
public static NotificationTray getTray(AndroidNotificationTray tray)
|
||||
{
|
||||
return tray;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@AppScope
|
||||
public static WidgetPreferences getWidgetPreferences(
|
||||
SharedPreferencesStorage storage)
|
||||
{
|
||||
return new WidgetPreferences(storage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@ import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.views.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
import static android.view.View.*;
|
||||
import static org.isoron.uhabits.core.ui.ThemeSwitcher.THEME_LIGHT;
|
||||
import static org.isoron.uhabits.core.ui.ThemeSwitcher.*;
|
||||
|
||||
public class EditHabitDialog extends AppCompatDialogFragment
|
||||
{
|
||||
@@ -50,7 +50,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
|
||||
|
||||
protected Habit originalHabit;
|
||||
|
||||
protected AndroidPreferences prefs;
|
||||
protected Preferences prefs;
|
||||
|
||||
protected CommandRunner commandRunner;
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ import android.os.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.habits.list.model.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
|
||||
/**
|
||||
* Activity that allows the user to see and modify the list of habits.
|
||||
@@ -45,7 +45,7 @@ public class ListHabitsActivity extends BaseActivity
|
||||
|
||||
private boolean pureBlack;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private MidnightTimer midnightTimer;
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ListHabitsActivity extends BaseActivity
|
||||
screen.setSelectionMenu(selectionMenu);
|
||||
rootView.setController(controller, selectionMenu);
|
||||
|
||||
if(prefs.isSyncFeatureEnabled())
|
||||
if(prefs.isSyncEnabled())
|
||||
startService(new Intent(this, SyncService.class));
|
||||
|
||||
setScreen(screen);
|
||||
|
||||
@@ -35,12 +35,12 @@ import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -94,7 +94,7 @@ public class ListHabitsScreen extends BaseScreen
|
||||
private final ThemeSwitcher themeSwitcher;
|
||||
|
||||
@NonNull
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
@Nullable
|
||||
private HabitCardListController listController;
|
||||
@@ -110,7 +110,7 @@ public class ListHabitsScreen extends BaseScreen
|
||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||
@NonNull ColorPickerDialogFactory colorPickerFactory,
|
||||
@NonNull EditHabitDialogFactory editHabitDialogFactory,
|
||||
@NonNull AndroidPreferences prefs)
|
||||
@NonNull Preferences prefs)
|
||||
{
|
||||
super(activity);
|
||||
setRootView(rootView);
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.google.auto.factory.*;
|
||||
|
||||
import org.isoron.uhabits.activities.habits.list.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
@AutoFactory
|
||||
public class CheckmarkButtonController
|
||||
@@ -37,14 +37,14 @@ public class CheckmarkButtonController
|
||||
private Listener listener;
|
||||
|
||||
@NonNull
|
||||
private final AndroidPreferences prefs;
|
||||
private final Preferences prefs;
|
||||
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
public CheckmarkButtonController(@Provided @NonNull AndroidPreferences prefs,
|
||||
public CheckmarkButtonController(@Provided @NonNull Preferences prefs,
|
||||
@NonNull Habit habit,
|
||||
long timestamp)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.google.auto.factory.*;
|
||||
|
||||
import org.isoron.uhabits.activities.habits.list.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
@AutoFactory
|
||||
public class NumberButtonController
|
||||
@@ -37,14 +37,14 @@ public class NumberButtonController
|
||||
private Listener listener;
|
||||
|
||||
@NonNull
|
||||
private final AndroidPreferences prefs;
|
||||
private final Preferences prefs;
|
||||
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
public NumberButtonController(@Provided @NonNull AndroidPreferences prefs,
|
||||
public NumberButtonController(@Provided @NonNull Preferences prefs,
|
||||
@NonNull Habit habit,
|
||||
long timestamp)
|
||||
{
|
||||
|
||||
@@ -27,9 +27,9 @@ import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.activities.habits.list.*;
|
||||
import org.isoron.uhabits.activities.habits.list.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -62,13 +62,13 @@ public class HabitCardListAdapter
|
||||
private final HabitCardListCache cache;
|
||||
|
||||
@NonNull
|
||||
private AndroidPreferences preferences;
|
||||
private Preferences preferences;
|
||||
|
||||
private final MidnightTimer midnightTimer;
|
||||
|
||||
@Inject
|
||||
public HabitCardListAdapter(@NonNull HabitCardListCache cache,
|
||||
@NonNull AndroidPreferences preferences,
|
||||
@NonNull Preferences preferences,
|
||||
@NonNull MidnightTimer midnightTimer)
|
||||
{
|
||||
this.preferences = preferences;
|
||||
|
||||
@@ -28,25 +28,25 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.habits.list.*;
|
||||
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static android.view.View.MeasureSpec.*;
|
||||
import static org.isoron.uhabits.utils.AttributeSetUtils.*;
|
||||
import static org.isoron.uhabits.utils.ColorUtils.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.getDimension;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public class CheckmarkPanelView extends LinearLayout
|
||||
implements AndroidPreferences.Listener
|
||||
implements Preferences.Listener
|
||||
{
|
||||
private static final int LEFT_TO_RIGHT = 0;
|
||||
|
||||
private static final int RIGHT_TO_LEFT = 1;
|
||||
|
||||
@Nullable
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private int values[];
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.views.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -36,13 +36,13 @@ import java.util.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public class HeaderView extends ScrollableChart
|
||||
implements AndroidPreferences.Listener, MidnightTimer.MidnightListener
|
||||
implements Preferences.Listener, MidnightTimer.MidnightListener
|
||||
{
|
||||
|
||||
private int buttonCount;
|
||||
|
||||
@Nullable
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
@Nullable
|
||||
private MidnightTimer midnightTimer;
|
||||
@@ -52,7 +52,7 @@ public class HeaderView extends ScrollableChart
|
||||
private RectF rect;
|
||||
|
||||
public HeaderView(@NonNull Context context,
|
||||
@NonNull AndroidPreferences prefs,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull MidnightTimer midnightTimer)
|
||||
{
|
||||
super(context);
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.habits.list.*;
|
||||
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -39,14 +39,14 @@ import static org.isoron.uhabits.utils.ColorUtils.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public class NumberPanelView extends LinearLayout
|
||||
implements AndroidPreferences.Listener
|
||||
implements Preferences.Listener
|
||||
{
|
||||
private static final int LEFT_TO_RIGHT = 0;
|
||||
|
||||
private static final int RIGHT_TO_LEFT = 1;
|
||||
|
||||
@Nullable
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private double values[];
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.activities.common.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -56,7 +56,7 @@ public class ScoreCard extends HabitCard
|
||||
private TaskRunner taskRunner;
|
||||
|
||||
@Nullable
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
public ScoreCard(Context context)
|
||||
{
|
||||
|
||||
@@ -28,8 +28,8 @@ import android.support.v7.preference.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private SharedPreferences sharedPrefs;
|
||||
|
||||
@Nullable
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
@@ -63,7 +63,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
Context appContext = getContext().getApplicationContext();
|
||||
if(appContext instanceof HabitsApplication)
|
||||
if (appContext instanceof HabitsApplication)
|
||||
{
|
||||
HabitsApplication app = (HabitsApplication) appContext;
|
||||
prefs = app.getComponent().getPreferences();
|
||||
@@ -79,20 +79,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
updateSync();
|
||||
}
|
||||
|
||||
private void updateSync()
|
||||
{
|
||||
if(prefs == null) return;
|
||||
boolean enabled = prefs.isSyncFeatureEnabled();
|
||||
|
||||
Preference syncKey = findPreference("pref_sync_key");
|
||||
syncKey.setSummary(prefs.getSyncKey());
|
||||
syncKey.setVisible(enabled);
|
||||
|
||||
Preference syncAddress = findPreference("pref_sync_address");
|
||||
syncAddress.setSummary(prefs.getSyncAddress());
|
||||
syncAddress.setVisible(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s)
|
||||
{
|
||||
@@ -114,8 +100,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
if (key.equals("reminderSound"))
|
||||
{
|
||||
BaseScreen.showRingtonePicker(this,
|
||||
RINGTONE_REQUEST_CODE);
|
||||
BaseScreen.showRingtonePicker(this, RINGTONE_REQUEST_CODE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -129,7 +114,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
sharedPrefs = getPreferenceManager().getSharedPreferences();
|
||||
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
if(prefs != null && !prefs.isDeveloper())
|
||||
if (prefs != null && !prefs.isDeveloper())
|
||||
{
|
||||
PreferenceCategory devCategory =
|
||||
(PreferenceCategory) findPreference("devCategory");
|
||||
@@ -164,4 +149,24 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
Preference ringtonePreference = findPreference("reminderSound");
|
||||
ringtonePreference.setSummary(ringtoneName);
|
||||
}
|
||||
|
||||
private void updateSync()
|
||||
{
|
||||
if (prefs == null) return;
|
||||
boolean enabled = prefs.isSyncEnabled();
|
||||
|
||||
Preference syncKey = findPreference("pref_sync_key");
|
||||
if (syncKey != null)
|
||||
{
|
||||
syncKey.setSummary(prefs.getSyncKey());
|
||||
syncKey.setVisible(enabled);
|
||||
}
|
||||
|
||||
Preference syncAddress = findPreference("pref_sync_address");
|
||||
if (syncAddress != null)
|
||||
{
|
||||
syncAddress.setSummary(prefs.getSyncAddress());
|
||||
syncAddress.setVisible(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,12 @@ import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -46,7 +46,7 @@ import static org.isoron.uhabits.notifications.RingtoneManager.*;
|
||||
|
||||
@AppScope
|
||||
public class AndroidNotificationTray
|
||||
implements CommandRunner.Listener, AndroidPreferences.Listener,
|
||||
implements CommandRunner.Listener, Preferences.Listener,
|
||||
NotificationTray
|
||||
{
|
||||
@NonNull
|
||||
@@ -62,7 +62,7 @@ public class AndroidNotificationTray
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
@NonNull
|
||||
private final AndroidPreferences preferences;
|
||||
private final Preferences preferences;
|
||||
|
||||
@NonNull
|
||||
private final HashMap<Habit, NotificationData> active;
|
||||
@@ -72,7 +72,7 @@ public class AndroidNotificationTray
|
||||
@NonNull TaskRunner taskRunner,
|
||||
@NonNull PendingIntentFactory pendingIntents,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@NonNull AndroidPreferences preferences)
|
||||
@NonNull Preferences preferences)
|
||||
{
|
||||
this.context = context;
|
||||
this.taskRunner = taskRunner;
|
||||
|
||||
@@ -1,337 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker 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.
|
||||
*
|
||||
* Loop Habit Tracker 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.preferences;
|
||||
|
||||
import android.content.*;
|
||||
import android.preference.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@AppScope
|
||||
public class AndroidPreferences
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener, Preferences
|
||||
{
|
||||
private final Context context;
|
||||
|
||||
private SharedPreferences prefs;
|
||||
|
||||
private Boolean shouldReverseCheckmarks = null;
|
||||
|
||||
private LinkedList<Listener> listeners;
|
||||
|
||||
@Inject
|
||||
public AndroidPreferences(@AppContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
listeners = new LinkedList<>();
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void addListener(Listener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public Integer getDefaultHabitColor(int fallbackColor)
|
||||
{
|
||||
return prefs.getInt("pref_default_habit_palette_color", fallbackColor);
|
||||
}
|
||||
|
||||
public HabitList.Order getDefaultOrder()
|
||||
{
|
||||
String name = prefs.getString("pref_default_order", "BY_POSITION");
|
||||
|
||||
try
|
||||
{
|
||||
return HabitList.Order.valueOf(name);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
setDefaultOrder(HabitList.Order.BY_POSITION);
|
||||
return HabitList.Order.BY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
if(!HabitsApplication.isTestMode()) throw new IllegalStateException(
|
||||
"this method can only be used while testing");
|
||||
prefs.edit().clear().commit();
|
||||
}
|
||||
|
||||
public void setDefaultOrder(HabitList.Order order)
|
||||
{
|
||||
prefs.edit().putString("pref_default_order", order.name()).apply();
|
||||
}
|
||||
|
||||
public int getDefaultScoreSpinnerPosition()
|
||||
{
|
||||
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
||||
if (defaultScoreInterval > 5 || defaultScoreInterval < 0)
|
||||
defaultScoreInterval = 1;
|
||||
return defaultScoreInterval;
|
||||
}
|
||||
|
||||
public void setDefaultScoreSpinnerPosition(int position)
|
||||
{
|
||||
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of the last hint shown to the user.
|
||||
*
|
||||
* @return number of last hint shown
|
||||
*/
|
||||
@Override
|
||||
public int getLastHintNumber()
|
||||
{
|
||||
return prefs.getInt("last_hint_number", -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time when the last hint was shown to the user.
|
||||
*
|
||||
* @return timestamp of the day the last hint was shown
|
||||
*/
|
||||
@Override
|
||||
public long getLastHintTimestamp()
|
||||
{
|
||||
return prefs.getLong("last_hint_timestamp", -1);
|
||||
}
|
||||
|
||||
public long getLastSync()
|
||||
{
|
||||
return prefs.getLong("last_sync", 0);
|
||||
}
|
||||
|
||||
public void setLastSync(long timestamp)
|
||||
{
|
||||
prefs.edit().putLong("last_sync", timestamp).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShowArchived()
|
||||
{
|
||||
return prefs.getBoolean("pref_show_archived", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowArchived(boolean showArchived)
|
||||
{
|
||||
prefs.edit().putBoolean("pref_show_archived", showArchived).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getShowCompleted()
|
||||
{
|
||||
return prefs.getBoolean("pref_show_completed", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowCompleted(boolean showCompleted)
|
||||
{
|
||||
prefs.edit().putBoolean("pref_show_completed", showCompleted).apply();
|
||||
}
|
||||
|
||||
public long getSnoozeInterval()
|
||||
{
|
||||
return Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
|
||||
}
|
||||
|
||||
public String getSyncAddress()
|
||||
{
|
||||
return prefs.getString("pref_sync_address", "https://sync.loophabits.org:4000");
|
||||
}
|
||||
|
||||
public String getSyncClientId()
|
||||
{
|
||||
String id = prefs.getString("pref_sync_client_id", "");
|
||||
if (!id.isEmpty()) return id;
|
||||
|
||||
id = UUID.randomUUID().toString();
|
||||
prefs.edit().putString("pref_sync_client_id", id).apply();
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getSyncKey()
|
||||
{
|
||||
return prefs.getString("pref_sync_key", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTheme()
|
||||
{
|
||||
return prefs.getInt("pref_theme", ThemeSwitcher.THEME_LIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTheme(int theme)
|
||||
{
|
||||
prefs.edit().putInt("pref_theme", theme).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementLaunchCount()
|
||||
{
|
||||
int count = prefs.getInt("launch_count", 0);
|
||||
prefs.edit().putInt("launch_count", count + 1).apply();
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
|
||||
}
|
||||
|
||||
public boolean isDeveloper()
|
||||
{
|
||||
return prefs.getBoolean("pref_developer", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeveloper(boolean isDeveloper)
|
||||
{
|
||||
prefs.edit().putBoolean("pref_developer", isDeveloper).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirstRun()
|
||||
{
|
||||
return prefs.getBoolean("pref_first_run", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFirstRun(boolean isFirstRun)
|
||||
{
|
||||
prefs.edit().putBoolean("pref_first_run", isFirstRun).apply();
|
||||
}
|
||||
|
||||
public boolean isNumericalHabitsFeatureEnabled()
|
||||
{
|
||||
return prefs.getBoolean("pref_feature_numerical_habits", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPureBlackEnabled()
|
||||
{
|
||||
return prefs.getBoolean("pref_pure_black", false);
|
||||
}
|
||||
|
||||
public boolean isShortToggleEnabled()
|
||||
{
|
||||
return prefs.getBoolean("pref_short_toggle", false);
|
||||
}
|
||||
|
||||
public boolean isSyncFeatureEnabled()
|
||||
{
|
||||
return prefs.getBoolean("pref_feature_sync", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key)
|
||||
{
|
||||
if (key.equals("pref_checkmark_reverse_order"))
|
||||
{
|
||||
shouldReverseCheckmarks = null;
|
||||
for (Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||
}
|
||||
|
||||
if (key.equals("pref_sticky_notifications"))
|
||||
for (Listener l : listeners) l.onNotificationsChanged();
|
||||
|
||||
if (key.equals("pref_feature_sync"))
|
||||
for (Listener l : listeners) l.onSyncFeatureChanged();
|
||||
}
|
||||
|
||||
public void removeListener(Listener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void setDefaultHabitColor(int color)
|
||||
{
|
||||
prefs.edit().putInt("pref_default_habit_palette_color", color).apply();
|
||||
}
|
||||
|
||||
public void setShouldReverseCheckmarks(boolean reverse)
|
||||
{
|
||||
shouldReverseCheckmarks = null;
|
||||
prefs
|
||||
.edit()
|
||||
.putBoolean("pref_checkmark_reverse_order", reverse)
|
||||
.apply();
|
||||
|
||||
for (Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||
}
|
||||
|
||||
public boolean shouldMakeNotificationsSticky()
|
||||
{
|
||||
return prefs.getBoolean("pref_sticky_notifications", false);
|
||||
}
|
||||
|
||||
public boolean shouldReverseCheckmarks()
|
||||
{
|
||||
if (shouldReverseCheckmarks == null) shouldReverseCheckmarks =
|
||||
prefs.getBoolean("pref_checkmark_reverse_order", false);
|
||||
|
||||
return shouldReverseCheckmarks;
|
||||
}
|
||||
|
||||
public void updateLastAppVersion()
|
||||
{
|
||||
prefs.edit().putInt("last_version", BuildConfig.VERSION_CODE).apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last hint shown to the user, and the time that it was shown.
|
||||
*
|
||||
* @param number number of the last hint shown
|
||||
* @param timestamp timestamp for the day the last hint was shown
|
||||
*/
|
||||
@Override
|
||||
public void updateLastHint(int number, long timestamp)
|
||||
{
|
||||
prefs
|
||||
.edit()
|
||||
.putInt("last_hint_number", number)
|
||||
.putLong("last_hint_timestamp", timestamp)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public interface Listener
|
||||
{
|
||||
default void onCheckmarkOrderChanged() {}
|
||||
|
||||
default void onNotificationsChanged() {}
|
||||
|
||||
default void onSyncFeatureChanged() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker 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.
|
||||
*
|
||||
* Loop Habit Tracker 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.preferences;
|
||||
|
||||
import android.content.*;
|
||||
import android.preference.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@AppScope
|
||||
public class SharedPreferencesStorage
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
Preferences.Storage
|
||||
{
|
||||
@NonNull
|
||||
private SharedPreferences sharedPrefs;
|
||||
|
||||
@Nullable
|
||||
private Preferences preferences;
|
||||
|
||||
@Inject
|
||||
public SharedPreferencesStorage(@AppContext Context context)
|
||||
{
|
||||
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
sharedPrefs.edit().clear().apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String key, boolean defValue)
|
||||
{
|
||||
return sharedPrefs.getBoolean(key, defValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String key, int defValue)
|
||||
{
|
||||
return sharedPrefs.getInt(key, defValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(String key, int defValue)
|
||||
{
|
||||
return sharedPrefs.getLong(key, defValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String key, String defValue)
|
||||
{
|
||||
return sharedPrefs.getString(key, defValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached(Preferences preferences)
|
||||
{
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key)
|
||||
{
|
||||
if(preferences == null) return;
|
||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||
switch (key)
|
||||
{
|
||||
case "pref_checkmark_reverse_order":
|
||||
preferences.setShouldReverseCheckmarks(getBoolean(key, false));
|
||||
break;
|
||||
|
||||
case "pref_sticky_notifications":
|
||||
preferences.setNotificationsSticky(getBoolean(key, false));
|
||||
break;
|
||||
|
||||
case "pref_feature_sync":
|
||||
preferences.setSyncEnabled(getBoolean(key, false));
|
||||
break;
|
||||
}
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBoolean(String key, boolean value)
|
||||
{
|
||||
sharedPrefs.edit().putBoolean(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInt(String key, int value)
|
||||
{
|
||||
sharedPrefs.edit().putInt(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putLong(String key, long value)
|
||||
{
|
||||
sharedPrefs.edit().putLong(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putString(String key, String value)
|
||||
{
|
||||
sharedPrefs.edit().putString(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(String key)
|
||||
{
|
||||
sharedPrefs.edit().remove(key).apply();
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,10 @@ import com.getpebble.android.kit.util.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PebbleReceiver extends PebbleDataReceiver
|
||||
|
||||
private HabitList filteredHabits;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
public PebbleReceiver()
|
||||
{
|
||||
@@ -79,7 +79,7 @@ public class PebbleReceiver extends PebbleDataReceiver
|
||||
allHabits = component.getHabitList();
|
||||
prefs = component.getPreferences();
|
||||
|
||||
if(prefs.isSyncFeatureEnabled())
|
||||
if(prefs.isSyncEnabled())
|
||||
context.startService(new Intent(context, SyncService.class));
|
||||
|
||||
HabitMatcher build = new HabitMatcherBuilder()
|
||||
|
||||
@@ -22,9 +22,9 @@ package org.isoron.uhabits.receivers;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
@@ -38,12 +38,12 @@ public class ReminderController
|
||||
@NonNull
|
||||
private final AndroidNotificationTray notificationTray;
|
||||
|
||||
private AndroidPreferences preferences;
|
||||
private Preferences preferences;
|
||||
|
||||
@Inject
|
||||
public ReminderController(@NonNull ReminderScheduler reminderScheduler,
|
||||
@NonNull AndroidNotificationTray notificationTray,
|
||||
@NonNull AndroidPreferences preferences)
|
||||
@NonNull Preferences preferences)
|
||||
{
|
||||
this.reminderScheduler = reminderScheduler;
|
||||
this.notificationTray = notificationTray;
|
||||
|
||||
@@ -23,10 +23,10 @@ import android.content.*;
|
||||
import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.widgets.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@@ -62,9 +62,9 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
|
||||
IntentParser parser = app.getComponent().getIntentParser();
|
||||
WidgetBehavior controller = component.getWidgetController();
|
||||
AndroidPreferences prefs = app.getComponent().getPreferences();
|
||||
Preferences prefs = app.getComponent().getPreferences();
|
||||
|
||||
if(prefs.isSyncFeatureEnabled())
|
||||
if(prefs.isSyncEnabled())
|
||||
context.startService(new Intent(context, SyncService.class));
|
||||
|
||||
try
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.json.*;
|
||||
|
||||
import java.net.*;
|
||||
@@ -73,7 +73,7 @@ public class SyncManager implements CommandRunner.Listener
|
||||
private boolean readyToEmit = false;
|
||||
|
||||
@NonNull
|
||||
private final AndroidPreferences prefs;
|
||||
private final Preferences prefs;
|
||||
|
||||
@NonNull
|
||||
private CommandRunner commandRunner;
|
||||
@@ -87,7 +87,7 @@ public class SyncManager implements CommandRunner.Listener
|
||||
|
||||
@Inject
|
||||
public SyncManager(@NonNull BaseSystem system,
|
||||
@NonNull AndroidPreferences prefs,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@NonNull CommandParser commandParser)
|
||||
{
|
||||
@@ -148,7 +148,7 @@ public class SyncManager implements CommandRunner.Listener
|
||||
|
||||
public void startListening()
|
||||
{
|
||||
if (!prefs.isSyncFeatureEnabled()) return;
|
||||
if (!prefs.isSyncEnabled()) return;
|
||||
if (groupKey.isEmpty()) return;
|
||||
if (isListening) return;
|
||||
|
||||
|
||||
@@ -26,14 +26,14 @@ import android.os.*;
|
||||
import android.support.v7.app.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.receivers.*;
|
||||
|
||||
public class SyncService extends Service implements AndroidPreferences.Listener
|
||||
public class SyncService extends Service implements Preferences.Listener
|
||||
{
|
||||
private SyncManager syncManager;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private ConnectivityReceiver connectivityReceiver;
|
||||
|
||||
@@ -78,7 +78,7 @@ public class SyncService extends Service implements AndroidPreferences.Listener
|
||||
@Override
|
||||
public void onSyncFeatureChanged()
|
||||
{
|
||||
if(!prefs.isSyncFeatureEnabled()) stopSelf();
|
||||
if(!prefs.isSyncEnabled()) stopSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,8 +27,8 @@ import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
import static android.view.View.MeasureSpec.*;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.activeandroid.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
import static android.appwidget.AppWidgetManager.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.views.*;
|
||||
import org.isoron.uhabits.activities.habits.show.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.isoron.uhabits.widgets.views.*;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ScoreWidget extends BaseWidget
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
private final AndroidPreferences prefs;
|
||||
private final Preferences prefs;
|
||||
|
||||
public ScoreWidget(@NonNull Context context, int id, @NonNull Habit habit)
|
||||
{
|
||||
|
||||
@@ -23,9 +23,9 @@ import android.view.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -34,7 +34,7 @@ public class ListHabitsMenuTest extends BaseAndroidUnitTest
|
||||
{
|
||||
private BaseActivity activity;
|
||||
|
||||
private AndroidPreferences preferences;
|
||||
private Preferences preferences;
|
||||
|
||||
private ThemeSwitcher themeSwitcher;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ListHabitsMenuTest extends BaseAndroidUnitTest
|
||||
public void setUp()
|
||||
{
|
||||
activity = mock(BaseActivity.class);
|
||||
preferences = mock(AndroidPreferences.class);
|
||||
preferences = mock(Preferences.class);
|
||||
themeSwitcher = mock(ThemeSwitcher.class);
|
||||
behavior = mock(ListHabitsMenuBehavior.class);
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
import org.mockito.junit.*;
|
||||
@@ -71,7 +71,7 @@ public class ListHabitsScreenTest
|
||||
|
||||
private ThemeSwitcher themeSwitcher;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private CommandParser commandParser;
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ListHabitsScreenTest
|
||||
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
|
||||
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
|
||||
dialogFactory = mock(EditHabitDialogFactory.class);
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
prefs = mock(Preferences.class);
|
||||
commandParser = mock(CommandParser.class);
|
||||
|
||||
screen = spy(new ListHabitsScreen(activity, commandRunner, rootView,
|
||||
|
||||
@@ -22,7 +22,7 @@ package org.isoron.uhabits.activities.habits.list.controllers;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.habits.list.views.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -39,7 +39,7 @@ public class CheckmarkButtonControllerTest extends BaseAndroidUnitTest
|
||||
|
||||
private int timestamp;
|
||||
|
||||
private AndroidPreferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
@@ -49,7 +49,7 @@ public class CheckmarkButtonControllerTest extends BaseAndroidUnitTest
|
||||
|
||||
timestamp = 0;
|
||||
habit = mock(Habit.class);
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
prefs = mock(Preferences.class);
|
||||
|
||||
this.view = mock(CheckmarkButtonView.class);
|
||||
this.listener = mock(CheckmarkButtonController.Listener.class);
|
||||
|
||||
@@ -21,9 +21,9 @@ package org.isoron.uhabits.receivers;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ReminderControllerTest extends BaseAndroidUnitTest
|
||||
|
||||
private AndroidNotificationTray notificationTray;
|
||||
|
||||
private AndroidPreferences preferences;
|
||||
private Preferences preferences;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
@@ -47,7 +47,7 @@ public class ReminderControllerTest extends BaseAndroidUnitTest
|
||||
|
||||
reminderScheduler = mock(ReminderScheduler.class);
|
||||
notificationTray = mock(AndroidNotificationTray.class);
|
||||
preferences = mock(AndroidPreferences.class);
|
||||
preferences = mock(Preferences.class);
|
||||
|
||||
controller = new ReminderController(reminderScheduler,
|
||||
notificationTray, preferences);
|
||||
|
||||
@@ -19,33 +19,293 @@
|
||||
|
||||
package org.isoron.uhabits.core.preferences;
|
||||
|
||||
public interface Preferences
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Preferences
|
||||
{
|
||||
int getLastHintNumber();
|
||||
@NonNull
|
||||
private final Storage storage;
|
||||
|
||||
long getLastHintTimestamp();
|
||||
@NonNull
|
||||
private List<Listener> listeners;
|
||||
|
||||
boolean getShowArchived();
|
||||
@Nullable
|
||||
private Boolean shouldReverseCheckmarks = null;
|
||||
|
||||
boolean getShowCompleted();
|
||||
public Preferences(@NonNull Storage storage)
|
||||
{
|
||||
this.storage = storage;
|
||||
listeners = new LinkedList<>();
|
||||
storage.onAttached(this);
|
||||
}
|
||||
|
||||
int getTheme();
|
||||
public void addListener(Listener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
void incrementLaunchCount();
|
||||
public Integer getDefaultHabitColor(int fallbackColor)
|
||||
{
|
||||
return storage.getInt("pref_default_habit_palette_color",
|
||||
fallbackColor);
|
||||
}
|
||||
|
||||
boolean isFirstRun();
|
||||
public HabitList.Order getDefaultOrder()
|
||||
{
|
||||
String name = storage.getString("pref_default_order", "BY_POSITION");
|
||||
|
||||
boolean isPureBlackEnabled();
|
||||
try
|
||||
{
|
||||
return HabitList.Order.valueOf(name);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
setDefaultOrder(HabitList.Order.BY_POSITION);
|
||||
return HabitList.Order.BY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
void setDeveloper(boolean isDeveloper);
|
||||
public void setDefaultOrder(HabitList.Order order)
|
||||
{
|
||||
storage.putString("pref_default_order", order.name());
|
||||
}
|
||||
|
||||
void setFirstRun(boolean b);
|
||||
public int getDefaultScoreSpinnerPosition()
|
||||
{
|
||||
int defaultScoreInterval =
|
||||
storage.getInt("pref_score_view_interval", 1);
|
||||
if (defaultScoreInterval > 5 || defaultScoreInterval < 0)
|
||||
defaultScoreInterval = 1;
|
||||
return defaultScoreInterval;
|
||||
}
|
||||
|
||||
void setShowArchived(boolean showArchived);
|
||||
public void setDefaultScoreSpinnerPosition(int position)
|
||||
{
|
||||
storage.putInt("pref_score_view_interval", position);
|
||||
}
|
||||
|
||||
void setShowCompleted(boolean showCompleted);
|
||||
public int getLastHintNumber()
|
||||
{
|
||||
return storage.getInt("last_hint_number", -1);
|
||||
}
|
||||
|
||||
void setTheme(int theme);
|
||||
public long getLastHintTimestamp()
|
||||
{
|
||||
return storage.getLong("last_hint_timestamp", -1);
|
||||
}
|
||||
|
||||
void updateLastHint(int i, long startOfToday);
|
||||
public long getLastSync()
|
||||
{
|
||||
return storage.getLong("last_sync", 0);
|
||||
}
|
||||
|
||||
public void setLastSync(long timestamp)
|
||||
{
|
||||
storage.putLong("last_sync", timestamp);
|
||||
}
|
||||
|
||||
public boolean getShowArchived()
|
||||
{
|
||||
return storage.getBoolean("pref_show_archived", false);
|
||||
}
|
||||
|
||||
public void setShowArchived(boolean showArchived)
|
||||
{
|
||||
storage.putBoolean("pref_show_archived", showArchived);
|
||||
}
|
||||
|
||||
public boolean getShowCompleted()
|
||||
{
|
||||
return storage.getBoolean("pref_show_completed", true);
|
||||
}
|
||||
|
||||
public void setShowCompleted(boolean showCompleted)
|
||||
{
|
||||
storage.putBoolean("pref_show_completed", showCompleted);
|
||||
}
|
||||
|
||||
public long getSnoozeInterval()
|
||||
{
|
||||
return Long.parseLong(storage.getString("pref_snooze_interval", "15"));
|
||||
}
|
||||
|
||||
public String getSyncAddress()
|
||||
{
|
||||
return storage.getString("pref_sync_address",
|
||||
"https://sync.loophabits.org:4000");
|
||||
}
|
||||
|
||||
public void setSyncAddress(String address)
|
||||
{
|
||||
storage.putString("pref_sync_address", address);
|
||||
for (Listener l : listeners) l.onSyncFeatureChanged();
|
||||
}
|
||||
|
||||
public String getSyncClientId()
|
||||
{
|
||||
String id = storage.getString("pref_sync_client_id", "");
|
||||
if (!id.isEmpty()) return id;
|
||||
|
||||
id = UUID.randomUUID().toString();
|
||||
storage.putString("pref_sync_client_id", id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getSyncKey()
|
||||
{
|
||||
return storage.getString("pref_sync_key", "");
|
||||
}
|
||||
|
||||
public int getTheme()
|
||||
{
|
||||
return storage.getInt("pref_theme", ThemeSwitcher.THEME_LIGHT);
|
||||
}
|
||||
|
||||
public void setTheme(int theme)
|
||||
{
|
||||
storage.putInt("pref_theme", theme);
|
||||
}
|
||||
|
||||
public void incrementLaunchCount()
|
||||
{
|
||||
int count = storage.getInt("launch_count", 0);
|
||||
storage.putInt("launch_count", count + 1);
|
||||
}
|
||||
|
||||
public boolean isDeveloper()
|
||||
{
|
||||
return storage.getBoolean("pref_developer", false);
|
||||
}
|
||||
|
||||
public void setDeveloper(boolean isDeveloper)
|
||||
{
|
||||
storage.putBoolean("pref_developer", isDeveloper);
|
||||
}
|
||||
|
||||
public boolean isFirstRun()
|
||||
{
|
||||
return storage.getBoolean("pref_first_run", true);
|
||||
}
|
||||
|
||||
public void setFirstRun(boolean isFirstRun)
|
||||
{
|
||||
storage.putBoolean("pref_first_run", isFirstRun);
|
||||
}
|
||||
|
||||
public boolean isNumericalHabitsFeatureEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_feature_numerical_habits", false);
|
||||
}
|
||||
|
||||
public boolean isPureBlackEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_pure_black", false);
|
||||
}
|
||||
|
||||
public boolean isShortToggleEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_short_toggle", false);
|
||||
}
|
||||
|
||||
public boolean isSyncEnabled()
|
||||
{
|
||||
return storage.getBoolean("pref_feature_sync", false);
|
||||
}
|
||||
|
||||
public void removeListener(Listener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
storage.clear();
|
||||
}
|
||||
|
||||
public void setDefaultHabitColor(int color)
|
||||
{
|
||||
storage.putInt("pref_default_habit_palette_color", color);
|
||||
}
|
||||
|
||||
public void setLastAppVersion(int version)
|
||||
{
|
||||
storage.putInt("last_version", version);
|
||||
}
|
||||
|
||||
public void setNotificationsSticky(boolean sticky)
|
||||
{
|
||||
storage.getBoolean("pref_sticky_notifications", sticky);
|
||||
for (Listener l : listeners) l.onNotificationsChanged();
|
||||
}
|
||||
|
||||
public void setShouldReverseCheckmarks(boolean reverse)
|
||||
{
|
||||
shouldReverseCheckmarks = reverse;
|
||||
storage.putBoolean("pref_checkmark_reverse_order", reverse);
|
||||
for (Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||
}
|
||||
|
||||
public void setSyncEnabled(boolean isEnabled)
|
||||
{
|
||||
storage.putBoolean("pref_feature_sync", isEnabled);
|
||||
for(Listener l : listeners) l.onSyncFeatureChanged();
|
||||
}
|
||||
|
||||
public boolean shouldMakeNotificationsSticky()
|
||||
{
|
||||
return storage.getBoolean("pref_sticky_notifications", false);
|
||||
}
|
||||
|
||||
public boolean shouldReverseCheckmarks()
|
||||
{
|
||||
if (shouldReverseCheckmarks == null) shouldReverseCheckmarks =
|
||||
storage.getBoolean("pref_checkmark_reverse_order", false);
|
||||
|
||||
return shouldReverseCheckmarks;
|
||||
}
|
||||
|
||||
public void updateLastHint(int number, long timestamp)
|
||||
{
|
||||
storage.putInt("last_hint_number", number);
|
||||
storage.putLong("last_hint_timestamp", timestamp);
|
||||
}
|
||||
|
||||
public interface Listener
|
||||
{
|
||||
default void onCheckmarkOrderChanged() {}
|
||||
|
||||
default void onNotificationsChanged() {}
|
||||
|
||||
default void onSyncFeatureChanged() {}
|
||||
}
|
||||
|
||||
public interface Storage
|
||||
{
|
||||
void clear();
|
||||
|
||||
boolean getBoolean(String key, boolean defValue);
|
||||
|
||||
int getInt(String key, int defValue);
|
||||
|
||||
long getLong(String key, int defValue);
|
||||
|
||||
String getString(String key, String defValue);
|
||||
|
||||
void onAttached(Preferences preferences);
|
||||
|
||||
void putBoolean(String key, boolean value);
|
||||
|
||||
void putInt(String key, int value);
|
||||
|
||||
void putLong(String key, long value);
|
||||
|
||||
void putString(String key, String value);
|
||||
|
||||
void remove(String key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,8 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.preferences;
|
||||
package org.isoron.uhabits.core.preferences;
|
||||
|
||||
import android.content.*;
|
||||
import android.preference.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
|
||||
@@ -31,25 +27,22 @@ import javax.inject.*;
|
||||
@AppScope
|
||||
public class WidgetPreferences
|
||||
{
|
||||
private final SharedPreferences prefs;
|
||||
private Preferences.Storage storage;
|
||||
|
||||
@Inject
|
||||
public WidgetPreferences(@AppContext Context context)
|
||||
public WidgetPreferences(Preferences.Storage storage)
|
||||
{
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public void addWidget(int widgetId, long habitId)
|
||||
{
|
||||
prefs
|
||||
.edit()
|
||||
.putLong(getHabitIdKey(widgetId), habitId)
|
||||
.commit();
|
||||
storage.putLong(getHabitIdKey(widgetId), habitId);
|
||||
}
|
||||
|
||||
public long getHabitIdFromWidgetId(int widgetId)
|
||||
{
|
||||
Long habitId = prefs.getLong(getHabitIdKey(widgetId), -1);
|
||||
Long habitId = storage.getLong(getHabitIdKey(widgetId), -1);
|
||||
if (habitId < 0) throw new HabitNotFoundException();
|
||||
|
||||
return habitId;
|
||||
@@ -58,7 +51,7 @@ public class WidgetPreferences
|
||||
public void removeWidget(int id)
|
||||
{
|
||||
String habitIdKey = getHabitIdKey(id);
|
||||
prefs.edit().remove(habitIdKey).apply();
|
||||
storage.remove(habitIdKey);
|
||||
}
|
||||
|
||||
private String getHabitIdKey(int id)
|
||||
Reference in New Issue
Block a user