mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Move UI behavior to uhabits-core
This commit is contained in:
@@ -51,7 +51,7 @@ public class BaseAndroidTest extends TestCase
|
||||
|
||||
protected Context targetContext;
|
||||
|
||||
protected Preferences prefs;
|
||||
protected AndroidPreferences prefs;
|
||||
|
||||
protected HabitList habitList;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ListHabitsControllerTest extends BaseAndroidTest
|
||||
|
||||
private ListHabitsScreen screen;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private ReminderScheduler reminderScheduler;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ListHabitsControllerTest extends BaseAndroidTest
|
||||
commandRunner = mock(CommandRunner.class);
|
||||
adapter = mock(HabitCardListAdapter.class);
|
||||
screen = mock(ListHabitsScreen.class);
|
||||
prefs = mock(Preferences.class);
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
reminderScheduler = mock(ReminderScheduler.class);
|
||||
taskRunner = new SingleThreadTaskRunner();
|
||||
widgetUpdater = mock(WidgetUpdater.class);
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ListHabitsMenuTest extends BaseAndroidTest
|
||||
|
||||
private HabitCardListAdapter adapter;
|
||||
|
||||
private Preferences preferences;
|
||||
private AndroidPreferences preferences;
|
||||
|
||||
private ThemeSwitcher themeSwitcher;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ListHabitsMenuTest extends BaseAndroidTest
|
||||
activity = mock(BaseActivity.class);
|
||||
screen = mock(ListHabitsScreen.class);
|
||||
adapter = mock(HabitCardListAdapter.class);
|
||||
preferences = mock(Preferences.class);
|
||||
preferences = mock(AndroidPreferences.class);
|
||||
themeSwitcher = mock(ThemeSwitcher.class);
|
||||
|
||||
when(preferences.getShowArchived()).thenReturn(false);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ListHabitsScreenTest extends BaseAndroidTest
|
||||
|
||||
private ThemeSwitcher themeSwitcher;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private CommandParser commandParser;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ListHabitsScreenTest extends BaseAndroidTest
|
||||
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
|
||||
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
|
||||
dialogFactory = mock(EditHabitDialogFactory.class);
|
||||
prefs = mock(Preferences.class);
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
commandParser = mock(CommandParser.class);
|
||||
|
||||
screen = spy(new ListHabitsScreen(activity, commandRunner, rootView,
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CheckmarkButtonControllerTest extends BaseAndroidTest
|
||||
|
||||
private int timestamp;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
@@ -49,7 +49,7 @@ public class CheckmarkButtonControllerTest extends BaseAndroidTest
|
||||
|
||||
timestamp = 0;
|
||||
habit = mock(Habit.class);
|
||||
prefs = mock(Preferences.class);
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
|
||||
this.view = mock(CheckmarkButtonView.class);
|
||||
this.listener = mock(CheckmarkButtonController.Listener.class);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class HeaderViewTest extends BaseViewTest
|
||||
|
||||
private HeaderView view;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private MidnightTimer midnightTimer;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class HeaderViewTest extends BaseViewTest
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
prefs = mock(Preferences.class);
|
||||
prefs = mock(AndroidPreferences.class);
|
||||
midnightTimer = mock(MidnightTimer.class);
|
||||
view = new HeaderView(targetContext, prefs, midnightTimer);
|
||||
view.setButtonCount(5);
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.activities.habits.show;
|
||||
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ShowHabitsMenuTest extends BaseAndroidTest
|
||||
{
|
||||
private ShowHabitActivity activity;
|
||||
|
||||
private ShowHabitScreen screen;
|
||||
|
||||
private ShowHabitsMenu menu;
|
||||
|
||||
private Habit habit;
|
||||
|
||||
private ExportCSVTaskFactory exportCSVFactory;
|
||||
|
||||
private TaskRunner taskRunner;
|
||||
|
||||
private BaseSystem system;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
activity = mock(ShowHabitActivity.class);
|
||||
system = mock(BaseSystem.class);
|
||||
screen = mock(ShowHabitScreen.class);
|
||||
habit = mock(Habit.class);
|
||||
exportCSVFactory = mock(ExportCSVTaskFactory.class);
|
||||
taskRunner = mock(TaskRunner.class);
|
||||
menu = new ShowHabitsMenu(activity, system, screen, habit,
|
||||
exportCSVFactory, taskRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDownloadHabit()
|
||||
{
|
||||
onItemSelected(R.id.export);
|
||||
verify(taskRunner).execute(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEditHabit()
|
||||
{
|
||||
onItemSelected(R.id.action_edit_habit);
|
||||
verify(screen).showEditHabitDialog();
|
||||
}
|
||||
|
||||
protected void onItemSelected(int actionId)
|
||||
{
|
||||
MenuItem item = mock(MenuItem.class);
|
||||
when(item.getItemId()).thenReturn(actionId);
|
||||
menu.onItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class ReminderControllerTest extends BaseAndroidTest
|
||||
|
||||
private NotificationTray notificationTray;
|
||||
|
||||
private Preferences preferences;
|
||||
private AndroidPreferences preferences;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
@@ -46,7 +46,7 @@ public class ReminderControllerTest extends BaseAndroidTest
|
||||
|
||||
reminderScheduler = mock(ReminderScheduler.class);
|
||||
notificationTray = mock(NotificationTray.class);
|
||||
preferences = mock(Preferences.class);
|
||||
preferences = mock(AndroidPreferences.class);
|
||||
|
||||
controller = new ReminderController(reminderScheduler,
|
||||
notificationTray, preferences);
|
||||
|
||||
@@ -48,6 +48,8 @@ public abstract class BaseRootView extends FrameLayout
|
||||
|
||||
private final ThemeSwitcher themeSwitcher;
|
||||
|
||||
boolean shouldDisplayHomeAsUp = false;
|
||||
|
||||
public BaseRootView(@NonNull Context context)
|
||||
{
|
||||
super(context);
|
||||
@@ -58,11 +60,23 @@ public abstract class BaseRootView extends FrameLayout
|
||||
|
||||
public boolean getDisplayHomeAsUp()
|
||||
{
|
||||
return false;
|
||||
return shouldDisplayHomeAsUp;
|
||||
}
|
||||
|
||||
public void setDisplayHomeAsUp(boolean b)
|
||||
{
|
||||
shouldDisplayHomeAsUp = b;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public abstract Toolbar getToolbar();
|
||||
public Toolbar getToolbar()
|
||||
{
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (toolbar == null) throw new RuntimeException(
|
||||
"Your BaseRootView should have a " +
|
||||
"toolbar with id R.id.toolbar");
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
public int getToolbarColor()
|
||||
{
|
||||
@@ -86,7 +100,7 @@ public abstract class BaseRootView extends FrameLayout
|
||||
if (view != null) view.setVisibility(GONE);
|
||||
|
||||
view = findViewById(R.id.headerShadow);
|
||||
if(view != null) view.setVisibility(GONE);
|
||||
if (view != null) view.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public interface AppComponent
|
||||
|
||||
PendingIntentFactory getPendingIntentFactory();
|
||||
|
||||
Preferences getPreferences();
|
||||
AndroidPreferences getPreferences();
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public class HabitsApplication extends Application
|
||||
notificationTray = component.getNotificationTray();
|
||||
notificationTray.startListening();
|
||||
|
||||
Preferences prefs = component.getPreferences();
|
||||
AndroidPreferences prefs = component.getPreferences();
|
||||
prefs.initialize();
|
||||
prefs.updateLastAppVersion();
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ public class ThemeSwitcher
|
||||
@NonNull
|
||||
private final BaseActivity activity;
|
||||
|
||||
private Preferences preferences;
|
||||
private AndroidPreferences preferences;
|
||||
|
||||
@Inject
|
||||
public ThemeSwitcher(@NonNull BaseActivity activity,
|
||||
@NonNull Preferences preferences)
|
||||
@NonNull AndroidPreferences preferences)
|
||||
{
|
||||
this.activity = activity;
|
||||
this.preferences = preferences;
|
||||
|
||||
@@ -22,7 +22,8 @@ package org.isoron.uhabits.activities.about;
|
||||
import android.os.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.ui.about.*;
|
||||
|
||||
/**
|
||||
* Activity that allows the user to see information about the app itself.
|
||||
@@ -34,8 +35,11 @@ public class AboutActivity extends BaseActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
AboutRootView rootView = new AboutRootView(this, new IntentFactory());
|
||||
BaseScreen screen = new BaseScreen(this);
|
||||
HabitsApplication app = (HabitsApplication) getApplication();
|
||||
AppComponent cmp = app.getComponent();
|
||||
AboutScreen screen = new AboutScreen(this, cmp.getIntentFactory());
|
||||
AboutBehavior behavior = new AboutBehavior(cmp.getPreferences(), screen);
|
||||
AboutRootView rootView = new AboutRootView(this, behavior);
|
||||
screen.setRootView(rootView);
|
||||
setScreen(screen);
|
||||
}
|
||||
|
||||
@@ -21,15 +21,12 @@ package org.isoron.uhabits.activities.about;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.BuildConfig;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.ui.about.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.*;
|
||||
@@ -48,47 +45,22 @@ public class AboutRootView extends BaseRootView
|
||||
@BindView(R.id.tvSource)
|
||||
TextView tvSource;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@NonNull
|
||||
private final AboutBehavior behavior;
|
||||
|
||||
int developerCountdown = 10;
|
||||
|
||||
@Nullable
|
||||
Preferences prefs;
|
||||
|
||||
private final IntentFactory intents;
|
||||
|
||||
public AboutRootView(Context context, IntentFactory intents)
|
||||
public AboutRootView(@NonNull Context context,
|
||||
@NonNull AboutBehavior behavior)
|
||||
{
|
||||
super(context);
|
||||
this.intents = intents;
|
||||
this.behavior = behavior;
|
||||
|
||||
addView(inflate(getContext(), R.layout.about, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
tvVersion.setText(
|
||||
String.format(getResources().getString(R.string.version_n),
|
||||
BuildConfig.VERSION_NAME));
|
||||
String version = getResources().getString(R.string.version_n);
|
||||
tvVersion.setText(String.format(version, BuildConfig.VERSION_NAME));
|
||||
|
||||
if (context.getApplicationContext() instanceof HabitsApplication)
|
||||
{
|
||||
HabitsApplication app =
|
||||
(HabitsApplication) context.getApplicationContext();
|
||||
prefs = app.getComponent().getPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDisplayHomeAsUp()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Toolbar getToolbar()
|
||||
{
|
||||
return toolbar;
|
||||
setDisplayHomeAsUp(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,48 +76,37 @@ public class AboutRootView extends BaseRootView
|
||||
@OnClick(R.id.tvFeedback)
|
||||
public void onClickFeedback()
|
||||
{
|
||||
Intent intent = intents.sendFeedback(getContext());
|
||||
getContext().startActivity(intent);
|
||||
behavior.onSendFeedback();
|
||||
}
|
||||
|
||||
@OnClick(R.id.tvVersion)
|
||||
public void onClickIcon()
|
||||
{
|
||||
developerCountdown--;
|
||||
if (developerCountdown <= 0)
|
||||
{
|
||||
if (prefs == null) return;
|
||||
prefs.setDeveloper(true);
|
||||
String text = "You are now a developer";
|
||||
Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
behavior.onPressDeveloperCountdown();
|
||||
}
|
||||
|
||||
@OnClick(R.id.tvRate)
|
||||
public void onClickRate()
|
||||
{
|
||||
Intent intent = intents.rateApp(getContext());
|
||||
getContext().startActivity(intent);
|
||||
behavior.onRateApp();
|
||||
}
|
||||
|
||||
@OnClick(R.id.tvSource)
|
||||
public void onClickSource()
|
||||
{
|
||||
Intent intent = intents.viewSourceCode(getContext());
|
||||
getContext().startActivity(intent);
|
||||
behavior.onViewSourceCode();
|
||||
}
|
||||
|
||||
@OnClick(R.id.tvTranslate)
|
||||
public void onClickTranslate()
|
||||
{
|
||||
Intent intent = intents.helpTranslate(getContext());
|
||||
getContext().startActivity(intent);
|
||||
behavior.onTranslateApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initToolbar()
|
||||
{
|
||||
super.initToolbar();
|
||||
toolbar.setTitle(getResources().getString(R.string.about));
|
||||
getToolbar().setTitle(getResources().getString(R.string.about));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.activities.about;
|
||||
|
||||
import android.support.annotation.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.ui.about.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class AboutScreen extends BaseScreen implements AboutBehavior.Screen
|
||||
{
|
||||
@NonNull
|
||||
private final IntentFactory intents;
|
||||
|
||||
@Inject
|
||||
public AboutScreen(@NonNull BaseActivity activity,
|
||||
@NonNull IntentFactory intents)
|
||||
{
|
||||
super(activity);
|
||||
this.intents = intents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(AboutBehavior.Message message)
|
||||
{
|
||||
Toast.makeText(activity, "OK", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showRateAppWebsite()
|
||||
{
|
||||
activity.startActivity(intents.rateApp(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSendFeedbackScreen()
|
||||
{
|
||||
activity.startActivity(intents.sendFeedback(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSourceCodeWebsite()
|
||||
{
|
||||
activity.startActivity(intents.viewSourceCode(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTranslationWebsite()
|
||||
{
|
||||
activity.startActivity(intents.helpTranslate(activity));
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
|
||||
|
||||
protected Habit originalHabit;
|
||||
|
||||
protected Preferences prefs;
|
||||
protected AndroidPreferences prefs;
|
||||
|
||||
protected CommandRunner commandRunner;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ListHabitsActivity extends BaseActivity
|
||||
|
||||
private boolean pureBlack;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private MidnightTimer midnightTimer;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ListHabitsController
|
||||
private final HabitCardListAdapter adapter;
|
||||
|
||||
@NonNull
|
||||
private final Preferences prefs;
|
||||
private final AndroidPreferences prefs;
|
||||
|
||||
@NonNull
|
||||
private final CommandRunner commandRunner;
|
||||
@@ -81,7 +81,7 @@ public class ListHabitsController
|
||||
@NonNull HabitList habitList,
|
||||
@NonNull HabitCardListAdapter adapter,
|
||||
@NonNull ListHabitsScreen screen,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull AndroidPreferences prefs,
|
||||
@NonNull ReminderScheduler reminderScheduler,
|
||||
@NonNull TaskRunner taskRunner,
|
||||
@NonNull WidgetUpdater widgetUpdater,
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ListHabitsMenu extends BaseMenu
|
||||
|
||||
private boolean showCompleted;
|
||||
|
||||
private final Preferences preferences;
|
||||
private final AndroidPreferences preferences;
|
||||
|
||||
private ThemeSwitcher themeSwitcher;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ListHabitsMenu extends BaseMenu
|
||||
public ListHabitsMenu(@NonNull BaseActivity activity,
|
||||
@NonNull ListHabitsScreen screen,
|
||||
@NonNull HabitCardListAdapter adapter,
|
||||
@NonNull Preferences preferences,
|
||||
@NonNull AndroidPreferences preferences,
|
||||
@NonNull ThemeSwitcher themeSwitcher)
|
||||
{
|
||||
super(activity);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class ListHabitsScreen extends BaseScreen
|
||||
private final ThemeSwitcher themeSwitcher;
|
||||
|
||||
@NonNull
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
@NonNull
|
||||
private final CommandParser commandParser;
|
||||
@@ -103,7 +103,7 @@ public class ListHabitsScreen extends BaseScreen
|
||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||
@NonNull ColorPickerDialogFactory colorPickerFactory,
|
||||
@NonNull EditHabitDialogFactory editHabitDialogFactory,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull AndroidPreferences prefs,
|
||||
@NonNull CommandParser commandParser)
|
||||
{
|
||||
super(activity);
|
||||
|
||||
@@ -37,14 +37,14 @@ public class CheckmarkButtonController
|
||||
private Listener listener;
|
||||
|
||||
@NonNull
|
||||
private final Preferences prefs;
|
||||
private final AndroidPreferences prefs;
|
||||
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
public CheckmarkButtonController(@Provided @NonNull Preferences prefs,
|
||||
public CheckmarkButtonController(@Provided @NonNull AndroidPreferences prefs,
|
||||
@NonNull Habit habit,
|
||||
long timestamp)
|
||||
{
|
||||
|
||||
@@ -37,14 +37,14 @@ public class NumberButtonController
|
||||
private Listener listener;
|
||||
|
||||
@NonNull
|
||||
private final Preferences prefs;
|
||||
private final AndroidPreferences prefs;
|
||||
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
public NumberButtonController(@Provided @NonNull Preferences prefs,
|
||||
public NumberButtonController(@Provided @NonNull AndroidPreferences prefs,
|
||||
@NonNull Habit habit,
|
||||
long timestamp)
|
||||
{
|
||||
|
||||
@@ -58,13 +58,13 @@ public class HabitCardListAdapter
|
||||
private final HabitCardListCache cache;
|
||||
|
||||
@NonNull
|
||||
private Preferences preferences;
|
||||
private AndroidPreferences preferences;
|
||||
|
||||
private final MidnightTimer midnightTimer;
|
||||
|
||||
@Inject
|
||||
public HabitCardListAdapter(@NonNull HabitCardListCache cache,
|
||||
@NonNull Preferences preferences,
|
||||
@NonNull AndroidPreferences preferences,
|
||||
@NonNull MidnightTimer midnightTimer)
|
||||
{
|
||||
this.preferences = preferences;
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.isoron.uhabits.utils.*;
|
||||
@AutoFactory
|
||||
public class HintList
|
||||
{
|
||||
private final Preferences prefs;
|
||||
private final AndroidPreferences prefs;
|
||||
|
||||
@NonNull
|
||||
private final String[] hints;
|
||||
@@ -43,7 +43,7 @@ public class HintList
|
||||
*
|
||||
* @param hints initial list of hints
|
||||
*/
|
||||
public HintList(@Provided @NonNull Preferences prefs,
|
||||
public HintList(@Provided @NonNull AndroidPreferences prefs,
|
||||
@NonNull String hints[])
|
||||
{
|
||||
this.prefs = prefs;
|
||||
|
||||
@@ -39,14 +39,14 @@ import static org.isoron.uhabits.utils.ColorUtils.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.getDimension;
|
||||
|
||||
public class CheckmarkPanelView extends LinearLayout
|
||||
implements Preferences.Listener
|
||||
implements AndroidPreferences.Listener
|
||||
{
|
||||
private static final int LEFT_TO_RIGHT = 0;
|
||||
|
||||
private static final int RIGHT_TO_LEFT = 1;
|
||||
|
||||
@Nullable
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private int values[];
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.views.*;
|
||||
import org.isoron.uhabits.activities.habits.list.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
@@ -36,13 +35,13 @@ import java.util.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public class HeaderView extends ScrollableChart
|
||||
implements Preferences.Listener, MidnightTimer.MidnightListener
|
||||
implements AndroidPreferences.Listener, MidnightTimer.MidnightListener
|
||||
{
|
||||
|
||||
private int buttonCount;
|
||||
|
||||
@Nullable
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
@Nullable
|
||||
private MidnightTimer midnightTimer;
|
||||
@@ -52,7 +51,7 @@ public class HeaderView extends ScrollableChart
|
||||
private RectF rect;
|
||||
|
||||
public HeaderView(@NonNull Context context,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull AndroidPreferences prefs,
|
||||
@NonNull MidnightTimer midnightTimer)
|
||||
{
|
||||
super(context);
|
||||
|
||||
@@ -39,14 +39,14 @@ import static org.isoron.uhabits.utils.ColorUtils.*;
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public class NumberPanelView extends LinearLayout
|
||||
implements Preferences.Listener
|
||||
implements AndroidPreferences.Listener
|
||||
{
|
||||
private static final int LEFT_TO_RIGHT = 0;
|
||||
|
||||
private static final int RIGHT_TO_LEFT = 1;
|
||||
|
||||
@Nullable
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private double values[];
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ import android.support.annotation.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Activity that allows the user to see more information about a single habit.
|
||||
@@ -34,8 +37,24 @@ import org.isoron.uhabits.models.*;
|
||||
* Shows all the metadata for the habit, in addition to several charts.
|
||||
*/
|
||||
public class ShowHabitActivity extends BaseActivity
|
||||
implements ShowHabitMenuBehavior.System
|
||||
{
|
||||
private HabitList habits;
|
||||
@Nullable
|
||||
private HabitList habitList;
|
||||
|
||||
@Nullable
|
||||
private AppComponent appComponent;
|
||||
|
||||
@Nullable
|
||||
private ShowHabitScreen screen;
|
||||
|
||||
@Override
|
||||
public File getCSVOutputDir()
|
||||
{
|
||||
if(appComponent == null) throw new IllegalStateException();
|
||||
|
||||
return appComponent.getBaseSystem().getFilesDir("CSV");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
@@ -43,7 +62,8 @@ public class ShowHabitActivity extends BaseActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
HabitsApplication app = (HabitsApplication) getApplicationContext();
|
||||
habits = app.getComponent().getHabitList();
|
||||
appComponent = app.getComponent();
|
||||
habitList = appComponent.getHabitList();
|
||||
Habit habit = getHabitFromIntent();
|
||||
|
||||
ShowHabitComponent component = DaggerShowHabitComponent
|
||||
@@ -52,22 +72,30 @@ public class ShowHabitActivity extends BaseActivity
|
||||
.showHabitModule(new ShowHabitModule(this, habit))
|
||||
.build();
|
||||
|
||||
ShowHabitRootView rootView = component.getRootView();
|
||||
ShowHabitScreen screen = component.getScreen();
|
||||
|
||||
setScreen(screen);
|
||||
screen = component.getScreen();
|
||||
screen.setMenu(component.getMenu());
|
||||
screen.setController(component.getController());
|
||||
rootView.setController(component.getController());
|
||||
|
||||
component.getRootView().setController(component.getController());
|
||||
setScreen(screen);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
if(screen == null) throw new IllegalStateException();
|
||||
|
||||
super.onResume();
|
||||
screen.reattachDialogs();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Habit getHabitFromIntent()
|
||||
{
|
||||
if(habitList == null) throw new IllegalStateException();
|
||||
|
||||
Uri data = getIntent().getData();
|
||||
Habit habit = habits.getById(ContentUris.parseId(data));
|
||||
Habit habit = habitList.getById(ContentUris.parseId(data));
|
||||
if (habit == null) throw new RuntimeException("habit not found");
|
||||
return habit;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package org.isoron.uhabits.activities.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
|
||||
@@ -29,11 +31,15 @@ import dagger.*;
|
||||
dependencies = { AppComponent.class })
|
||||
public interface ShowHabitComponent
|
||||
{
|
||||
@NonNull
|
||||
ShowHabitController getController();
|
||||
|
||||
@NonNull
|
||||
ShowHabitsMenu getMenu();
|
||||
|
||||
@NonNull
|
||||
ShowHabitRootView getRootView();
|
||||
|
||||
@NonNull
|
||||
ShowHabitScreen getScreen();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -21,50 +21,39 @@ package org.isoron.uhabits.activities.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.activities.habits.show.views.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@ActivityScope
|
||||
public class ShowHabitController
|
||||
implements ShowHabitRootView.Controller, HistoryEditorDialog.Controller
|
||||
implements HistoryCard.Controller, HistoryEditorDialog.Controller
|
||||
{
|
||||
@NonNull
|
||||
private final ShowHabitScreen screen;
|
||||
private ShowHabitBehavior behavior;
|
||||
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
|
||||
@NonNull
|
||||
private final CommandRunner commandRunner;
|
||||
private ShowHabitScreen screen;
|
||||
|
||||
@Inject
|
||||
public ShowHabitController(@NonNull ShowHabitScreen screen,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@NonNull Habit habit)
|
||||
public ShowHabitController(@NonNull ShowHabitBehavior behavior,
|
||||
@NonNull ShowHabitScreen screen)
|
||||
{
|
||||
this.behavior = behavior;
|
||||
this.screen = screen;
|
||||
this.habit = habit;
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditHistoryButtonClick()
|
||||
{
|
||||
screen.showEditHistoryDialog();
|
||||
behavior.onEditHistory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onToggleCheckmark(long timestamp)
|
||||
{
|
||||
commandRunner.execute(new ToggleRepetitionCommand(habit, timestamp),
|
||||
null);
|
||||
behavior.onToggleCheckmark(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onToolbarChanged()
|
||||
{
|
||||
screen.invalidateToolbar();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -19,17 +19,20 @@
|
||||
|
||||
package org.isoron.uhabits.activities.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
public class ShowHabitModule extends ActivityModule
|
||||
{
|
||||
private final Habit habit;
|
||||
private Habit habit;
|
||||
|
||||
public ShowHabitModule(BaseActivity activity, Habit habit)
|
||||
public ShowHabitModule(@NonNull BaseActivity activity, @NonNull Habit habit)
|
||||
{
|
||||
super(activity);
|
||||
this.habit = habit;
|
||||
@@ -40,4 +43,22 @@ public class ShowHabitModule extends ActivityModule
|
||||
{
|
||||
return habit;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public ShowHabitBehavior.Screen getScreen(ShowHabitScreen screen)
|
||||
{
|
||||
return screen;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public ShowHabitMenuBehavior.Screen getMenuScreen(ShowHabitScreen screen)
|
||||
{
|
||||
return screen;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public ShowHabitMenuBehavior.System getSystem(BaseActivity activity)
|
||||
{
|
||||
return (ShowHabitActivity) activity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ public class ShowHabitRootView extends BaseRootView
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@NonNull
|
||||
private Controller controller;
|
||||
@Nullable
|
||||
private ShowHabitController controller;
|
||||
|
||||
@Inject
|
||||
public ShowHabitRootView(@NonNull @ActivityContext Context context,
|
||||
@@ -78,25 +78,11 @@ public class ShowHabitRootView extends BaseRootView
|
||||
addView(inflate(getContext(), R.layout.show_habit, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
controller = new Controller() {};
|
||||
|
||||
setDisplayHomeAsUp(true);
|
||||
initCards();
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDisplayHomeAsUp()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Toolbar getToolbar()
|
||||
{
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToolbarColor()
|
||||
{
|
||||
@@ -114,10 +100,10 @@ public class ShowHabitRootView extends BaseRootView
|
||||
toolbar.setTitle(habit.getName());
|
||||
});
|
||||
|
||||
controller.onToolbarChanged();
|
||||
if(controller != null) controller.onToolbarChanged();
|
||||
}
|
||||
|
||||
public void setController(@NonNull Controller controller)
|
||||
public void setController(@NonNull ShowHabitController controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
historyCard.setController(controller);
|
||||
@@ -158,9 +144,4 @@ public class ShowHabitRootView extends BaseRootView
|
||||
else
|
||||
barCard.setVisibility(GONE);
|
||||
}
|
||||
|
||||
public interface Controller extends HistoryCard.Controller
|
||||
{
|
||||
default void onToolbarChanged() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,17 @@ package org.isoron.uhabits.activities.habits.show;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@ActivityScope
|
||||
public class ShowHabitScreen extends BaseScreen
|
||||
implements ShowHabitMenuBehavior.Screen, ShowHabitBehavior.Screen
|
||||
{
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
@@ -44,8 +47,7 @@ public class ShowHabitScreen extends BaseScreen
|
||||
public ShowHabitScreen(@NonNull BaseActivity activity,
|
||||
@NonNull Habit habit,
|
||||
@NonNull ShowHabitRootView view,
|
||||
@NonNull
|
||||
EditHabitDialogFactory editHabitDialogFactory)
|
||||
@NonNull EditHabitDialogFactory editHabitDialogFactory)
|
||||
{
|
||||
super(activity);
|
||||
setRootView(view);
|
||||
@@ -53,37 +55,46 @@ public class ShowHabitScreen extends BaseScreen
|
||||
this.habit = habit;
|
||||
}
|
||||
|
||||
public void setController(@NonNull ShowHabitController controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void reattachDialogs()
|
||||
{
|
||||
if(controller == null) throw new IllegalStateException();
|
||||
if (controller == null) throw new IllegalStateException();
|
||||
|
||||
HistoryEditorDialog historyEditor = (HistoryEditorDialog) activity
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentByTag("historyEditor");
|
||||
|
||||
if (historyEditor != null)
|
||||
historyEditor.setController(controller);
|
||||
if (historyEditor != null) historyEditor.setController(controller);
|
||||
}
|
||||
|
||||
public void showEditHabitDialog()
|
||||
public void setController(@NonNull ShowHabitController controller)
|
||||
{
|
||||
activity.showDialog(
|
||||
editHabitDialogFactory.edit(habit),
|
||||
"editHabit");
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void showEditHistoryDialog()
|
||||
@Override
|
||||
public void showEditHabitScreen(@NonNull Habit habit)
|
||||
{
|
||||
if(controller == null) throw new IllegalStateException();
|
||||
activity.showDialog(editHabitDialogFactory.edit(habit), "editHabit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showEditHistoryScreen()
|
||||
{
|
||||
if (controller == null) throw new IllegalStateException();
|
||||
|
||||
HistoryEditorDialog dialog = new HistoryEditorDialog();
|
||||
dialog.setHabit(habit);
|
||||
dialog.setController(controller);
|
||||
dialog.show(activity.getSupportFragmentManager(), "historyEditor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(ShowHabitMenuBehavior.Message m)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
case COULD_NOT_EXPORT:
|
||||
showMessage(R.string.could_not_export);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,9 @@ package org.isoron.uhabits.activities.habits.show;
|
||||
import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@@ -37,47 +32,14 @@ import javax.inject.*;
|
||||
public class ShowHabitsMenu extends BaseMenu
|
||||
{
|
||||
@NonNull
|
||||
private final BaseSystem system;
|
||||
|
||||
@NonNull
|
||||
private final ShowHabitScreen screen;
|
||||
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
|
||||
@NonNull
|
||||
private final TaskRunner taskRunner;
|
||||
|
||||
@NonNull
|
||||
private ExportCSVTaskFactory exportCSVFactory;
|
||||
ShowHabitMenuBehavior behavior;
|
||||
|
||||
@Inject
|
||||
public ShowHabitsMenu(@NonNull BaseActivity activity,
|
||||
@NonNull BaseSystem system,
|
||||
@NonNull ShowHabitScreen screen,
|
||||
@NonNull Habit habit,
|
||||
@NonNull ExportCSVTaskFactory exportCSVFactory,
|
||||
@NonNull TaskRunner taskRunner)
|
||||
@NonNull ShowHabitMenuBehavior behavior)
|
||||
{
|
||||
super(activity);
|
||||
this.system = system;
|
||||
this.screen = screen;
|
||||
this.habit = habit;
|
||||
this.taskRunner = taskRunner;
|
||||
this.exportCSVFactory = exportCSVFactory;
|
||||
}
|
||||
|
||||
public void exportHabit()
|
||||
{
|
||||
List<Habit> selected = new LinkedList<>();
|
||||
selected.add(habit);
|
||||
File outputDir = system.getFilesDir("CSV");
|
||||
ExportCSVTask task = exportCSVFactory.create(selected,
|
||||
outputDir, filename -> {
|
||||
if (filename != null) screen.showSendFileScreen(filename);
|
||||
else screen.showMessage(R.string.could_not_export);
|
||||
});
|
||||
taskRunner.execute(task);
|
||||
this.behavior = behavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,11 +48,11 @@ public class ShowHabitsMenu extends BaseMenu
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.action_edit_habit:
|
||||
screen.showEditHabitDialog();
|
||||
behavior.onEditHabit();
|
||||
return true;
|
||||
|
||||
case R.id.export:
|
||||
this.exportHabit();
|
||||
behavior.onExportCSV();
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ScoreCard extends HabitCard
|
||||
private TaskRunner taskRunner;
|
||||
|
||||
@Nullable
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
public ScoreCard(Context context)
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private SharedPreferences sharedPrefs;
|
||||
|
||||
@Nullable
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.isoron.uhabits.notifications.RingtoneManager.*;
|
||||
|
||||
@AppScope
|
||||
public class NotificationTray
|
||||
implements CommandRunner.Listener, Preferences.Listener
|
||||
implements CommandRunner.Listener, AndroidPreferences.Listener
|
||||
{
|
||||
@NonNull
|
||||
private final Context context;
|
||||
@@ -59,7 +59,7 @@ public class NotificationTray
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
@NonNull
|
||||
private final Preferences preferences;
|
||||
private final AndroidPreferences preferences;
|
||||
|
||||
@NonNull
|
||||
private final HashMap<Habit, NotificationData> active;
|
||||
@@ -69,7 +69,7 @@ public class NotificationTray
|
||||
@NonNull TaskRunner taskRunner,
|
||||
@NonNull PendingIntentFactory pendingIntents,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@NonNull Preferences preferences)
|
||||
@NonNull AndroidPreferences preferences)
|
||||
{
|
||||
this.context = context;
|
||||
this.taskRunner = taskRunner;
|
||||
|
||||
@@ -32,8 +32,8 @@ import java.util.*;
|
||||
import javax.inject.*;
|
||||
|
||||
@AppScope
|
||||
public class Preferences
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
public class AndroidPreferences
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener, Preferences
|
||||
{
|
||||
private final Context context;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Preferences
|
||||
private LinkedList<Listener> listeners;
|
||||
|
||||
@Inject
|
||||
public Preferences(@AppContext Context context)
|
||||
public AndroidPreferences(@AppContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
listeners = new LinkedList<>();
|
||||
@@ -78,26 +78,6 @@ public class Preferences
|
||||
}
|
||||
}
|
||||
|
||||
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 boolean isSyncFeatureEnabled()
|
||||
{
|
||||
return prefs.getBoolean("pref_feature_sync", false);
|
||||
}
|
||||
|
||||
public void setDefaultOrder(HabitList.Order order)
|
||||
{
|
||||
prefs.edit().putString("pref_default_order", order.name()).apply();
|
||||
@@ -171,6 +151,22 @@ public class Preferences
|
||||
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", "");
|
||||
@@ -232,6 +228,11 @@ public class Preferences
|
||||
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)
|
||||
@@ -53,7 +53,7 @@ public class PebbleReceiver extends PebbleDataReceiver
|
||||
|
||||
private HabitList filteredHabits;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
public PebbleReceiver()
|
||||
{
|
||||
|
||||
@@ -37,12 +37,12 @@ public class ReminderController
|
||||
@NonNull
|
||||
private final NotificationTray notificationTray;
|
||||
|
||||
private Preferences preferences;
|
||||
private AndroidPreferences preferences;
|
||||
|
||||
@Inject
|
||||
public ReminderController(@NonNull ReminderScheduler reminderScheduler,
|
||||
@NonNull NotificationTray notificationTray,
|
||||
@NonNull Preferences preferences)
|
||||
@NonNull AndroidPreferences preferences)
|
||||
{
|
||||
this.reminderScheduler = reminderScheduler;
|
||||
this.notificationTray = notificationTray;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
|
||||
IntentParser parser = app.getComponent().getIntentParser();
|
||||
WidgetController controller = component.getWidgetController();
|
||||
Preferences prefs = app.getComponent().getPreferences();
|
||||
AndroidPreferences prefs = app.getComponent().getPreferences();
|
||||
|
||||
if(prefs.isSyncFeatureEnabled())
|
||||
context.startService(new Intent(context, SyncService.class));
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SyncManager implements CommandRunner.Listener
|
||||
private boolean readyToEmit = false;
|
||||
|
||||
@NonNull
|
||||
private final Preferences prefs;
|
||||
private final AndroidPreferences prefs;
|
||||
|
||||
@NonNull
|
||||
private CommandRunner commandRunner;
|
||||
@@ -86,7 +86,7 @@ public class SyncManager implements CommandRunner.Listener
|
||||
|
||||
@Inject
|
||||
public SyncManager(@NonNull BaseSystem system,
|
||||
@NonNull Preferences prefs,
|
||||
@NonNull AndroidPreferences prefs,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@NonNull CommandParser commandParser)
|
||||
{
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.receivers.*;
|
||||
|
||||
public class SyncService extends Service implements Preferences.Listener
|
||||
public class SyncService extends Service implements AndroidPreferences.Listener
|
||||
{
|
||||
private SyncManager syncManager;
|
||||
|
||||
private Preferences prefs;
|
||||
private AndroidPreferences prefs;
|
||||
|
||||
private ConnectivityReceiver connectivityReceiver;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ScoreWidget extends BaseWidget
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
private final Preferences prefs;
|
||||
private final AndroidPreferences prefs;
|
||||
|
||||
public ScoreWidget(@NonNull Context context, int id, @NonNull Habit habit)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user