Remove most static references to app component; fix tests

pull/151/head
Alinson S. Xavier 9 years ago
parent 3b737996e9
commit eceb1bfb7d

@ -0,0 +1,37 @@
/*
* 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;
import org.isoron.uhabits.models.sqlite.*;
import org.isoron.uhabits.tasks.*;
import javax.inject.*;
import dagger.*;
@Singleton
@Component(modules = {
AppModule.class, SingleThreadTaskRunner.class, SQLModelFactory.class
})
public interface AndroidTestComponent extends AppComponent
{
}

@ -25,7 +25,6 @@ import android.os.*;
import android.support.annotation.*;
import android.support.test.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.utils.*;
@ -34,8 +33,6 @@ import org.junit.*;
import java.util.*;
import java.util.concurrent.*;
import javax.inject.*;
import static junit.framework.Assert.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
@ -51,19 +48,12 @@ public class BaseAndroidTest
protected Context targetContext;
@Inject
protected Preferences prefs;
@Inject
protected HabitList habitList;
@Inject
protected CommandRunner commandRunner;
@Inject
protected TaskRunner taskRunner;
@Inject
protected HabitLogger logger;
protected HabitFixtures fixtures;
@ -85,15 +75,19 @@ public class BaseAndroidTest
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
setTheme(R.style.AppBaseTheme);
AppComponent component = DaggerAppComponent.builder().build();
AppComponent component = DaggerAndroidTestComponent
.builder()
.appModule(new AppModule(targetContext.getApplicationContext()))
.build();
HabitsApplication.setComponent(component);
prefs = component.getPreferences();
habitList = component.getHabitList();
commandRunner = component.getCommandRunner();
taskRunner = component.getTaskRunner();
logger = component.getHabitsLogger();
fixtures = new HabitFixtures(habitList);
ModelFactory modelFactory = component.getModelFactory();
fixtures = new HabitFixtures(modelFactory, habitList);
latch = new CountDownLatch(1);
}
@ -134,6 +128,7 @@ public class BaseAndroidTest
}
}
@Deprecated
protected void waitForAsyncTasks()
{
try

@ -28,16 +28,19 @@ public class HabitFixtures
true, false, false, true, true, true, false, false, true, true
};
private ModelFactory modelFactory;
private final HabitList habitList;
public HabitFixtures(HabitList habitList)
public HabitFixtures(ModelFactory modelFactory, HabitList habitList)
{
this.modelFactory = modelFactory;
this.habitList = habitList;
}
public Habit createEmptyHabit()
{
Habit habit = new Habit();
Habit habit = modelFactory.buildHabit();
habit.setName("Meditate");
habit.setDescription("Did you meditate this morning?");
habit.setColor(3);
@ -66,7 +69,7 @@ public class HabitFixtures
public Habit createShortHabit()
{
Habit habit = new Habit();
Habit habit = modelFactory.buildHabit();
habit.setName("Wake up early");
habit.setDescription("Did you wake up before 6am?");
habit.setFrequency(new Frequency(2, 3));

@ -50,7 +50,7 @@ public class CheckmarkPanelViewTest extends BaseViewTest
setSimilarityCutoff(0.03f);
prefs.setShouldReverseCheckmarks(false);
Habit habit = new Habit();
Habit habit = fixtures.createEmptyHabit();
latch = new CountDownLatch(1);
checkmarks = new int[]{

@ -52,7 +52,6 @@ public class StreakCardTest extends BaseViewTest
view.setHabit(habit);
view.refreshData();
waitForAsyncTasks();
measureView(view, 800, 600);
}

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.widgets;
package org.isoron.uhabits.widgets;
import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*;

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.widgets;
package org.isoron.uhabits.widgets;
import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*;

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.widgets;
package org.isoron.uhabits.widgets;
import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*;

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.widgets;
package org.isoron.uhabits.widgets;
import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*;
@ -25,7 +25,6 @@ import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.widgets.*;
import org.junit.*;
import org.junit.runner.*;

@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.widgets;
package org.isoron.uhabits.widgets;
import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*;
@ -25,7 +25,6 @@ import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.widgets.*;
import org.junit.*;
import org.junit.runner.*;

@ -49,8 +49,6 @@ public interface AppComponent
IntentFactory getIntentFactory();
IntentScheduler getIntentScheduler();
ModelFactory getModelFactory();
PendingIntentFactory getPendingIntentFactory();

@ -41,7 +41,13 @@ public class HabitsApplication extends Application
private static WidgetUpdater widgetUpdater;
public static AppComponent getComponent()
@Deprecated
public static AppComponent getStaticComponent()
{
return component;
}
public AppComponent getComponent()
{
return component;
}

@ -19,13 +19,18 @@
package org.isoron.uhabits.activities;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.dialogs.*;
import org.isoron.uhabits.activities.habits.list.controllers.*;
import dagger.*;
@ActivityScope
@Component(modules = { ActivityModule.class })
@Component(modules = { ActivityModule.class },
dependencies = { AppComponent.class })
public interface ActivityComponent
{
CheckmarkButtonControllerFactory getCheckmarkButtonControllerFactory();
DialogFactory getDialogFactory();
}

@ -34,21 +34,15 @@ public class ActivityModule
}
@Provides
BaseActivity getActivity()
public BaseActivity getActivity()
{
return activity;
}
@Provides
@ActivityContext
Context getContext()
public Context getContext()
{
return activity;
}
@Provides
BaseSystem getBaseSystem()
{
return new BaseSystem(activity);
}
}

@ -25,6 +25,7 @@ import android.support.annotation.*;
import android.support.v7.app.*;
import android.view.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.utils.*;
/**
@ -131,9 +132,12 @@ abstract public class BaseActivity extends AppCompatActivity
androidExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
HabitsApplication app = (HabitsApplication) getApplicationContext();
component = DaggerActivityComponent
.builder()
.activityModule(new ActivityModule(this))
.appComponent(app.getComponent())
.build();
}
}

@ -41,19 +41,15 @@ import javax.inject.*;
* a bug report, obtaining device information, or requesting runtime
* permissions.
*/
@ActivityScope
public class BaseSystem
{
private Context context;
@Inject
ReminderScheduler reminderScheduler;
public BaseSystem(Context context)
public BaseSystem(@ActivityContext Context context)
{
this.context = context;
AppComponent component = HabitsApplication.getComponent();
reminderScheduler = component.getReminderScheduler();
}
/**

@ -28,9 +28,9 @@ import android.support.v7.app.*;
import android.util.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.utils.*;
public class HistoryEditorDialog extends AppCompatDialogFragment
@ -52,8 +52,11 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
public HistoryEditorDialog()
{
this.controller = new Controller() {};
habitList = HabitsApplication.getComponent().getHabitList();
taskRunner = HabitsApplication.getComponent().getTaskRunner();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
habitList = app.getComponent().getHabitList();
taskRunner = app.getComponent().getTaskRunner();
}
@Override
@ -97,6 +100,13 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
refreshData();
}
@Override
public void onPause()
{
habit.getCheckmarks().observable.removeListener(this);
super.onPause();
}
@Override
public void onResume()
{
@ -114,13 +124,6 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
habit.getCheckmarks().observable.addListener(this);
}
@Override
public void onPause()
{
habit.getCheckmarks().observable.removeListener(this);
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle outState)
{

@ -66,7 +66,9 @@ public abstract class BaseDialog extends AppCompatDialogFragment
{
View view = inflater.inflate(R.layout.edit_habit, container, false);
AppComponent component = HabitsApplication.getComponent();
HabitsApplication app = (HabitsApplication) getContext().getApplicationContext();
AppComponent component = app.getComponent();
prefs = component.getPreferences();
habitList = component.getHabitList();
commandRunner = component.getCommandRunner();

@ -41,9 +41,11 @@ public class ListHabitsActivity extends BaseActivity
{
super.onCreate(savedInstanceState);
HabitsApplication app = (HabitsApplication) getApplicationContext();
ListHabitsComponent component = DaggerListHabitsComponent
.builder()
.appComponent(HabitsApplication.getComponent())
.appComponent(app.getComponent())
.activityModule(new ActivityModule(this))
.build();

@ -70,7 +70,8 @@ public class ListHabitsRootView extends BaseRootView
@Inject
public ListHabitsRootView(@ActivityContext Context context,
HabitCardListAdapter listAdapter)
@NonNull HintListFactory hintListFactory,
@NonNull HabitCardListAdapter listAdapter)
{
super(context);
addView(inflate(getContext(), R.layout.list_habits, null));
@ -85,7 +86,7 @@ public class ListHabitsRootView extends BaseRootView
String hints[] =
getContext().getResources().getStringArray(R.array.hints);
HintList hintList = new HintList(hints);
HintList hintList = hintListFactory.create(hints);
hintView.setHints(hintList);
}

@ -21,11 +21,13 @@ package org.isoron.uhabits.activities.habits.list.controllers;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import com.google.auto.factory.*;
import org.isoron.uhabits.activities.habits.list.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
@AutoFactory
public class CheckmarkButtonController
{
@Nullable
@ -42,11 +44,13 @@ public class CheckmarkButtonController
private long timestamp;
public CheckmarkButtonController(@NonNull Habit habit, long timestamp)
public CheckmarkButtonController(@Provided @NonNull Preferences prefs,
@NonNull Habit habit,
long timestamp)
{
this.habit = habit;
this.timestamp = timestamp;
prefs = HabitsApplication.getComponent().getPreferences();
this.prefs = prefs;
}
public void onClick()

@ -23,9 +23,10 @@ import android.support.annotation.*;
import android.support.v7.widget.*;
import android.view.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.activities.habits.list.*;
import org.isoron.uhabits.activities.habits.list.views.*;
import org.isoron.uhabits.models.*;
import java.util.*;
@ -55,20 +56,14 @@ public class HabitCardListAdapter
private final HabitCardListCache cache;
@Inject
public HabitCardListAdapter(HabitList allHabits)
{
this(allHabits, 10);
}
public HabitCardListAdapter(@NonNull HabitList allHabits,
int checkmarkCount)
public HabitCardListAdapter(@NonNull HabitCardListCache cache)
{
this.selected = new LinkedList<>();
this.observable = new ModelObservable();
this.cache = cache;
cache = new HabitCardListCache(allHabits);
cache.setListener(this);
cache.setCheckmarkCount(checkmarkCount);
cache.setCheckmarkCount(ListHabitsRootView.MAX_CHECKMARK_COUNT);
setHasStableIds(true);
}

@ -21,15 +21,16 @@ package org.isoron.uhabits.activities.habits.list.model;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.utils.*;
import java.util.*;
import javax.inject.*;
/**
* A HabitCardListCache fetches and keeps a cache of all the data necessary to
* render a HabitCardListView.
@ -61,16 +62,18 @@ public class HabitCardListCache implements CommandRunner.Listener
private final CommandRunner commandRunner;
public HabitCardListCache(@NonNull HabitList allHabits)
@Inject
public HabitCardListCache(@NonNull HabitList allHabits,
@NonNull CommandRunner commandRunner,
@NonNull TaskRunner taskRunner)
{
this.allHabits = allHabits;
this.commandRunner = commandRunner;
this.filteredHabits = allHabits;
this.taskRunner = taskRunner;
this.listener = new Listener() {};
data = new CacheData();
AppComponent component = HabitsApplication.getComponent();
commandRunner = component.getCommandRunner();
taskRunner = component.getTaskRunner();
}
public void cancelTasks()

@ -21,13 +21,15 @@ package org.isoron.uhabits.activities.habits.list.model;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import com.google.auto.factory.*;
import org.isoron.uhabits.utils.*;
/**
* Provides a list of hints to be shown at the application startup, and takes
* care of deciding when a new hint should be shown.
*/
@AutoFactory
public class HintList
{
private final Preferences prefs;
@ -40,10 +42,11 @@ public class HintList
*
* @param hints initial list of hints
*/
public HintList(@NonNull String hints[])
public HintList(@Provided @NonNull Preferences prefs,
@NonNull String hints[])
{
this.prefs = prefs;
this.hints = hints;
prefs = HabitsApplication.getComponent().getPreferences();
}
/**

@ -25,8 +25,9 @@ import android.util.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.habits.list.*;
import org.isoron.uhabits.activities.habits.list.controllers.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
public class CheckmarkPanelView extends LinearLayout
@ -141,7 +142,10 @@ public class CheckmarkPanelView extends LinearLayout
private void init()
{
if (isInEditMode()) return;
prefs = HabitsApplication.getComponent().getPreferences();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
prefs = app.getComponent().getPreferences();
setWillNotDraw(false);
}
@ -150,9 +154,12 @@ public class CheckmarkPanelView extends LinearLayout
{
if (controller == null) return;
CheckmarkButtonController buttonController =
new CheckmarkButtonController(habit, timestamp);
ListHabitsActivity activity = (ListHabitsActivity) getContext();
CheckmarkButtonControllerFactory buttonControllerFactory =
activity.getComponent().getCheckmarkButtonControllerFactory();
CheckmarkButtonController buttonController =
buttonControllerFactory.create(habit, timestamp);
buttonController.setListener(controller);
buttonController.setView(buttonView);
buttonView.setController(buttonController);

@ -48,7 +48,9 @@ public class HeaderView extends LinearLayout
setButtonCount(5);
}
prefs = HabitsApplication.getComponent().getPreferences();
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
prefs = app.getComponent().getPreferences();
}
public void setButtonCount(int buttonCount)

@ -25,8 +25,8 @@ import android.os.*;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.models.*;
/**
* Activity that allows the user to see more information about a single habit.
@ -37,30 +37,27 @@ public class ShowHabitActivity extends BaseActivity
{
private HabitList habits;
private ShowHabitController controller;
private ShowHabitRootView rootView;
private ShowHabitScreen screen;
private ShowHabitsMenu menu;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
habits = HabitsApplication.getComponent().getHabitList();
HabitsApplication app = (HabitsApplication) getApplicationContext();
habits = app.getComponent().getHabitList();
Habit habit = getHabitFromIntent();
rootView = new ShowHabitRootView(this, habit);
screen = new ShowHabitScreen(this, habit, rootView);
setScreen(screen);
menu = new ShowHabitsMenu(this, screen);
screen.setMenu(menu);
ShowHabitComponent component = DaggerShowHabitComponent
.builder()
.appComponent(app.getComponent())
.showHabitModule(new ShowHabitModule(this, habit))
.build();
controller = new ShowHabitController(screen, habit);
rootView.setController(controller);
ShowHabitRootView rootView = component.getRootView();
ShowHabitScreen screen = component.getScreen();
setScreen(screen);
screen.setMenu(component.getMenu());
rootView.setController(component.getController());
}
@NonNull

@ -0,0 +1,39 @@
/*
* 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.activities.habits.show;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import dagger.*;
@ActivityScope
@Component(modules = { ShowHabitModule.class },
dependencies = { AppComponent.class })
public interface ShowHabitComponent
{
ShowHabitController getController();
ShowHabitsMenu getMenu();
ShowHabitRootView getRootView();
ShowHabitScreen getScreen();
}

@ -21,10 +21,11 @@ package org.isoron.uhabits.activities.habits.show;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.dialogs.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.dialogs.*;
import javax.inject.*;
public class ShowHabitController
implements ShowHabitRootView.Controller, HistoryEditorDialog.Controller
@ -35,14 +36,17 @@ public class ShowHabitController
@NonNull
private final Habit habit;
@NonNull
private final CommandRunner commandRunner;
@Inject
public ShowHabitController(@NonNull ShowHabitScreen screen,
@NonNull CommandRunner commandRunner,
@NonNull Habit habit)
{
commandRunner = HabitsApplication.getComponent().getCommandRunner();
this.screen = screen;
this.habit = habit;
this.commandRunner = commandRunner;
}
@Override

@ -0,0 +1,43 @@
/*
* 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.activities.habits.show;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.models.*;
import dagger.*;
@Module
public class ShowHabitModule extends ActivityModule
{
private final Habit habit;
public ShowHabitModule(BaseActivity activity, Habit habit)
{
super(activity);
this.habit = habit;
}
@Provides
public Habit getHabit()
{
return habit;
}
}

@ -24,11 +24,13 @@ import android.support.annotation.*;
import android.support.v7.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.activities.habits.show.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import javax.inject.*;
import butterknife.*;
public class ShowHabitRootView extends BaseRootView
@ -61,7 +63,9 @@ public class ShowHabitRootView extends BaseRootView
@NonNull
private Controller controller;
public ShowHabitRootView(@NonNull Context context, @NonNull Habit habit)
@Inject
public ShowHabitRootView(@NonNull @ActivityContext Context context,
@NonNull Habit habit)
{
super(context);
this.habit = habit;

@ -26,6 +26,8 @@ import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.activities.common.dialogs.*;
import org.isoron.uhabits.activities.habits.edit.*;
import javax.inject.*;
public class ShowHabitScreen extends BaseScreen
{
@NonNull
@ -33,15 +35,16 @@ public class ShowHabitScreen extends BaseScreen
private DialogFactory dialogFactory;
@Inject
public ShowHabitScreen(@NonNull BaseActivity activity,
@NonNull Habit habit,
ShowHabitRootView view)
@NonNull ShowHabitRootView view,
@NonNull DialogFactory dialogFactory)
{
super(activity);
dialogFactory = activity.getComponent().getDialogFactory();
this.habit = habit;
setRootView(view);
this.habit = habit;
this.dialogFactory = dialogFactory;
}
public void showEditHabitDialog()

@ -25,11 +25,14 @@ import android.view.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import javax.inject.*;
public class ShowHabitsMenu extends BaseMenu
{
@NonNull
private final ShowHabitScreen screen;
@Inject
public ShowHabitsMenu(@NonNull BaseActivity activity,
@NonNull ShowHabitScreen screen)
{

@ -24,9 +24,9 @@ import android.util.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.utils.*;
import java.util.*;
@ -65,7 +65,10 @@ public class FrequencyCard extends HabitCard
{
inflate(getContext(), R.layout.show_habit_frequency, this);
ButterKnife.bind(this);
taskRunner = HabitsApplication.getComponent().getTaskRunner();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
taskRunner = app.getComponent().getTaskRunner();
if (isInEditMode()) initEditMode();
}

@ -25,9 +25,9 @@ import android.util.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.utils.*;
import butterknife.*;
@ -79,7 +79,10 @@ public class HistoryCard extends HabitCard
{
inflate(getContext(), R.layout.show_habit_history, this);
ButterKnife.bind(this);
taskRunner = HabitsApplication.getComponent().getTaskRunner();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
taskRunner = app.getComponent().getTaskRunner();
controller = new Controller() {};
if (isInEditMode()) initEditMode();
}

@ -82,7 +82,9 @@ public class OverviewCard extends HabitCard
private void init()
{
taskRunner = HabitsApplication.getComponent().getTaskRunner();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
taskRunner = app.getComponent().getTaskRunner();
inflate(getContext(), R.layout.show_habit_overview, this);
ButterKnife.bind(this);
cache = new Cache();

@ -25,9 +25,9 @@ import android.util.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.utils.*;
import java.util.*;
@ -83,7 +83,9 @@ public class ScoreCard extends HabitCard
public void onItemSelected(int position)
{
setBucketSizeFromPosition(position);
HabitsApplication.getComponent().getWidgetUpdater().updateWidgets();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
app.getComponent().getWidgetUpdater().updateWidgets();
refreshData();
}
@ -101,8 +103,10 @@ public class ScoreCard extends HabitCard
private void init()
{
taskRunner = HabitsApplication.getComponent().getTaskRunner();
prefs = HabitsApplication.getComponent().getPreferences();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
taskRunner = app.getComponent().getTaskRunner();
prefs = app.getComponent().getPreferences();
inflate(getContext(), R.layout.show_habit_score, this);
ButterKnife.bind(this);

@ -24,9 +24,9 @@ import android.util.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.utils.*;
import java.util.*;
@ -65,7 +65,10 @@ public class StreakCard extends HabitCard
private void init()
{
taskRunner = HabitsApplication.getComponent().getTaskRunner();
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
taskRunner = app.getComponent().getTaskRunner();
inflate(getContext(), R.layout.show_habit_streak, this);
ButterKnife.bind(this);
setOrientation(VERTICAL);

@ -21,7 +21,6 @@ package org.isoron.uhabits.commands;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.tasks.*;
import java.util.*;
@ -42,9 +41,9 @@ public class CommandRunner
private LinkedList<Listener> listeners;
@Inject
public CommandRunner()
public CommandRunner(@NonNull TaskRunner taskRunner)
{
taskRunner = HabitsApplication.getComponent().getTaskRunner();
this.taskRunner = taskRunner;
listeners = new LinkedList<>();
}

@ -40,10 +40,11 @@ public class PendingIntentFactory
private IntentFactory intentFactory;
@Inject
public PendingIntentFactory(@AppContext Context context)
public PendingIntentFactory(@AppContext Context context,
@NonNull IntentFactory intentFactory)
{
this.context = context;
intentFactory = HabitsApplication.getComponent().getIntentFactory();
this.intentFactory = intentFactory;
}
public PendingIntent addCheckmark(@NonNull Habit habit,
@ -55,7 +56,7 @@ public class PendingIntentFactory
checkIntent.setAction(WidgetReceiver.ACTION_ADD_REPETITION);
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
return PendingIntent.getBroadcast(context, 1, checkIntent,
FLAG_UPDATE_CURRENT);
FLAG_UPDATE_CURRENT);
}
public PendingIntent dismissNotification()
@ -63,7 +64,17 @@ public class PendingIntentFactory
Intent deleteIntent = new Intent(context, ReminderReceiver.class);
deleteIntent.setAction(WidgetReceiver.ACTION_DISMISS_REMINDER);
return PendingIntent.getBroadcast(context, 0, deleteIntent,
FLAG_UPDATE_CURRENT);
FLAG_UPDATE_CURRENT);
}
public PendingIntent showHabit(Habit habit)
{
Intent intent = intentFactory.startShowHabitActivity(context, habit);
return android.support.v4.app.TaskStackBuilder
.create(context)
.addNextIntentWithParentStack(intent)
.getPendingIntent(0, FLAG_UPDATE_CURRENT);
}
public PendingIntent showReminder(@NonNull Habit habit,
@ -79,7 +90,7 @@ public class PendingIntentFactory
intent.putExtra("reminderTime", reminderTime);
int reqCode = ((int) (habit.getId() % Integer.MAX_VALUE)) + 1;
return PendingIntent.getBroadcast(context, reqCode, intent,
FLAG_UPDATE_CURRENT);
FLAG_UPDATE_CURRENT);
}
public PendingIntent snoozeNotification(@NonNull Habit habit)
@ -89,7 +100,7 @@ public class PendingIntentFactory
snoozeIntent.setData(data);
snoozeIntent.setAction(ReminderReceiver.ACTION_SNOOZE_REMINDER);
return PendingIntent.getBroadcast(context, 0, snoozeIntent,
FLAG_UPDATE_CURRENT);
FLAG_UPDATE_CURRENT);
}
public PendingIntent toggleCheckmark(@NonNull Habit habit,
@ -101,16 +112,6 @@ public class PendingIntentFactory
checkIntent.setAction(WidgetReceiver.ACTION_TOGGLE_REPETITION);
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
return PendingIntent.getBroadcast(context, 2, checkIntent,
FLAG_UPDATE_CURRENT);
}
public PendingIntent showHabit(Habit habit)
{
Intent intent = intentFactory.startShowHabitActivity(context, habit);
return android.support.v4.app.TaskStackBuilder
.create(context)
.addNextIntentWithParentStack(intent)
.getPendingIntent(0, FLAG_UPDATE_CURRENT);
FLAG_UPDATE_CURRENT);
}
}

@ -27,6 +27,8 @@ import org.isoron.uhabits.*;
import java.util.*;
import javax.inject.*;
/**
* The thing that the user wants to track.
*/
@ -76,6 +78,7 @@ public class Habit
* The habit is not archived, not highlighted, has no reminders and is
* placed in the last position of the list of habits.
*/
@Deprecated
public Habit()
{
this.color = 5;
@ -83,7 +86,20 @@ public class Habit
this.frequency = new Frequency(3, 7);
ModelFactory factory =
HabitsApplication.getComponent().getModelFactory();
HabitsApplication.getStaticComponent().getModelFactory();
checkmarks = factory.buildCheckmarkList(this);
streaks = factory.buildStreakList(this);
scores = factory.buildScoreList(this);
repetitions = factory.buildRepetitionList(this);
}
@Inject
public Habit(@NonNull ModelFactory factory)
{
this.color = 5;
this.archived = false;
this.frequency = new Frequency(3, 7);
checkmarks = factory.buildCheckmarkList(this);
streaks = factory.buildStreakList(this);
scores = factory.buildScoreList(this);

@ -25,12 +25,17 @@ package org.isoron.uhabits.models;
*/
public interface ModelFactory
{
RepetitionList buildRepetitionList(Habit habit);
CheckmarkList buildCheckmarkList(Habit habit);
default Habit buildHabit()
{
return new Habit(this);
}
HabitList buildHabitList();
RepetitionList buildRepetitionList(Habit habit);
ScoreList buildScoreList(Habit habit);
StreakList buildStreakList(Habit habit);

@ -40,28 +40,17 @@ public class PebbleReceiver extends PebbleDataReceiver
public static final UUID WATCHAPP_UUID =
UUID.fromString("82629d99-8ea6-4631-a022-9ca77a12a058");
private final HabitList allHabits;
private HabitList allHabits;
private final CommandRunner commandRunner;
private CommandRunner commandRunner;
private final TaskRunner taskRunner;
private TaskRunner taskRunner;
private final HabitList filteredHabits;
private HabitList filteredHabits;
public PebbleReceiver()
{
super(WATCHAPP_UUID);
AppComponent component = HabitsApplication.getComponent();
commandRunner = component.getCommandRunner();
taskRunner = component.getTaskRunner();
allHabits = component.getHabitList();
HabitMatcher build = new HabitMatcherBuilder()
.setArchivedAllowed(false)
.setCompletedAllowed(false)
.build();
filteredHabits = allHabits.getFiltered(build);
}
@Override
@ -72,6 +61,20 @@ public class PebbleReceiver extends PebbleDataReceiver
if (context == null) throw new RuntimeException("context is null");
if (data == null) throw new RuntimeException("data is null");
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
commandRunner = app.getComponent().getCommandRunner();
taskRunner = app.getComponent().getTaskRunner();
allHabits = app.getComponent().getHabitList();
HabitMatcher build = new HabitMatcherBuilder()
.setArchivedAllowed(false)
.setCompletedAllowed(false)
.build();
filteredHabits = allHabits.getFiltered(build);
PebbleKit.sendAckToPebble(context, transactionId);
Log.d("PebbleReceiver", "<-- " + data.getString(0));

@ -54,25 +54,25 @@ public class ReminderReceiver extends BroadcastReceiver
private static final String TAG = "ReminderReceiver";
private final HabitList habits;
private HabitList habits;
private final TaskRunner taskRunner;
private TaskRunner taskRunner;
private final ReminderScheduler reminderScheduler;
private ReminderScheduler reminderScheduler;
public ReminderReceiver()
{
super();
AppComponent component = HabitsApplication.getComponent();
habits = component.getHabitList();
taskRunner = component.getTaskRunner();
reminderScheduler = component.getReminderScheduler();
}
private PendingIntentFactory pendingIntentFactory;
@Override
public void onReceive(final Context context, Intent intent)
{
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
habits = app.getComponent().getHabitList();
taskRunner = app.getComponent().getTaskRunner();
reminderScheduler = app.getComponent().getReminderScheduler();
pendingIntentFactory = app.getComponent().getPendingIntentFactory();
Log.i(TAG, String.format("Received intent: %s", intent.toString()));
try
@ -147,9 +147,6 @@ public class ReminderReceiver extends BroadcastReceiver
PendingIntent.getActivity(context, 0, contentIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntentFactory pendingIntentFactory =
new PendingIntentFactory(context);
PendingIntent dismissPendingIntent;
dismissPendingIntent =
pendingIntentFactory.dismissNotification();

@ -47,25 +47,24 @@ public class WidgetReceiver extends BroadcastReceiver
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
@NonNull
private final HabitList habits;
private HabitList habits;
@NonNull
private final IntentParser parser;
private IntentParser parser;
@NonNull
private final ReceiverActions actions;
public WidgetReceiver()
{
AppComponent component = HabitsApplication.getComponent();
habits = component.getHabitList();
actions = component.getReceiverActions();
parser = new IntentParser(habits);
}
private ReceiverActions actions;
@Override
public void onReceive(final Context context, Intent intent)
{
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
habits = app.getComponent().getHabitList();
actions = app.getComponent().getReceiverActions();
parser = new IntentParser(habits);
Log.d("WidgetReceiver",
String.format("Received intent: %s", intent.toString()));
try

@ -30,7 +30,7 @@ public class SingleThreadTaskRunner implements TaskRunner
{
@Provides
@Singleton
public static SingleThreadTaskRunner getInstance()
public static TaskRunner getInstance()
{
return new SingleThreadTaskRunner();
}

@ -1,69 +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.tasks;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*;
public class ToggleRepetitionTask implements Task
{
@NonNull
private final CommandRunner commandRunner;
@NonNull
private final Listener listener;
@NonNull
private final Habit habit;
private final long timestamp;
public ToggleRepetitionTask(@NonNull Habit habit,
long timestamp,
@NonNull Listener listener)
{
this.habit = habit;
this.timestamp = timestamp;
this.listener = listener;
commandRunner = HabitsApplication.getComponent().getCommandRunner();
}
@Override
public void doInBackground()
{
commandRunner.execute(new ToggleRepetitionCommand(habit, timestamp),
habit.getId());
}
@Override
public void onPostExecute()
{
listener.onToggleRepetitionFinished();
}
public interface Listener
{
void onToggleRepetitionFinished();
}
}

@ -42,12 +42,13 @@ public class ReminderScheduler
private final HabitLogger logger;
@Inject
public ReminderScheduler()
public ReminderScheduler(@NonNull PendingIntentFactory pendingIntentFactory,
@NonNull IntentScheduler intentScheduler,
@NonNull HabitLogger logger)
{
AppComponent component = HabitsApplication.getComponent();
pendingIntentFactory = component.getPendingIntentFactory();
intentScheduler = component.getIntentScheduler();
logger = component.getHabitsLogger();
this.pendingIntentFactory = pendingIntentFactory;
this.intentScheduler = intentScheduler;
this.logger = logger;
}
public void schedule(@NonNull Habit habit, @Nullable Long reminderTime)

@ -27,6 +27,7 @@ import android.view.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.utils.*;
import static android.os.Build.VERSION.*;
@ -45,11 +46,18 @@ public abstract class BaseWidget
@NonNull
private final Context context;
protected final PendingIntentFactory pendingIntentFactory;
public BaseWidget(@NonNull Context context, int id)
{
this.id = id;
this.context = context;
prefs = HabitsApplication.getComponent().getWidgetPreferences();
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
prefs = app.getComponent().getWidgetPreferences();
pendingIntentFactory = app.getComponent().getPendingIntentFactory();
dimensions = new WidgetDimensions(0, 0, 0, 0);
}

@ -35,16 +35,9 @@ import static org.isoron.uhabits.utils.WidgetUtils.*;
public abstract class BaseWidgetProvider extends AppWidgetProvider
{
private final HabitList habits;
private HabitList habits;
private final WidgetPreferences widgetPrefs;
public BaseWidgetProvider()
{
AppComponent component = HabitsApplication.getComponent();
habits = component.getHabitList();
widgetPrefs = component.getWidgetPreferences();
}
private WidgetPreferences widgetPrefs;
@Override
public void onAppWidgetOptionsChanged(@Nullable Context context,
@ -59,6 +52,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
if (options == null) throw new RuntimeException("options is null");
context.setTheme(R.style.TransparentWidgetTheme);
updateDependencies(context);
BaseWidget widget = getWidgetFromId(context, widgetId);
WidgetDimensions dims = getDimensionsFromOptions(context, options);
widget.setDimensions(dims);
@ -77,6 +72,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
if (context == null) throw new RuntimeException("context is null");
if (ids == null) throw new RuntimeException("ids is null");
updateDependencies(context);
for (int id : ids)
{
BaseWidget widget = getWidgetFromId(context, id);
@ -94,6 +91,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
if (widgetIds == null) throw new RuntimeException("widgetIds is null");
context.setTheme(R.style.TransparentWidgetTheme);
updateDependencies(context);
new Handler().postDelayed(() -> {
for (int id : widgetIds)
update(context, manager, id);
@ -146,4 +145,12 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
e.printStackTrace();
}
}
private void updateDependencies(Context context)
{
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
habits = app.getComponent().getHabitList();
widgetPrefs = app.getComponent().getWidgetPreferences();
}
}

@ -24,10 +24,9 @@ import android.content.*;
import android.support.annotation.*;
import android.view.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.widgets.views.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.widgets.views.*;
public class CheckmarkWidget extends BaseWidget
{
@ -45,8 +44,7 @@ public class CheckmarkWidget extends BaseWidget
@Override
public PendingIntent getOnClickPendingIntent(Context context)
{
PendingIntentFactory factory = new PendingIntentFactory(context);
return factory.toggleCheckmark(habit, null);
return pendingIntentFactory.toggleCheckmark(habit, null);
}
@Override

@ -24,11 +24,10 @@ import android.content.*;
import android.support.annotation.*;
import android.view.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.widgets.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.widgets.views.*;
public class FrequencyWidget extends BaseWidget
{
@ -46,8 +45,7 @@ public class FrequencyWidget extends BaseWidget
@Override
public PendingIntent getOnClickPendingIntent(Context context)
{
PendingIntentFactory factory = new PendingIntentFactory(context);
return factory.showHabit(habit);
return pendingIntentFactory.showHabit(habit);
}
@Override

@ -53,7 +53,8 @@ public class HabitPickerDialog extends Activity
Long habitId = habitIds.get(position);
preferences.addWidget(widgetId, habitId);
HabitsApplication.getComponent().getWidgetUpdater().updateWidgets();
HabitsApplication app = (HabitsApplication) getApplicationContext();
app.getComponent().getWidgetUpdater().updateWidgets();
Intent resultValue = new Intent();
resultValue.putExtra(EXTRA_APPWIDGET_ID, widgetId);
@ -67,7 +68,8 @@ public class HabitPickerDialog extends Activity
super.onCreate(savedInstanceState);
setContentView(R.layout.widget_configure_activity);
AppComponent component = HabitsApplication.getComponent();
HabitsApplication app = (HabitsApplication) getApplicationContext();
AppComponent component = app.getComponent();
habitList = component.getHabitList();
preferences = component.getWidgetPreferences();

@ -24,11 +24,10 @@ import android.content.*;
import android.support.annotation.*;
import android.view.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.widgets.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.widgets.views.*;
public class HistoryWidget extends BaseWidget
{
@ -44,8 +43,7 @@ public class HistoryWidget extends BaseWidget
@Override
public PendingIntent getOnClickPendingIntent(Context context)
{
PendingIntentFactory factory = new PendingIntentFactory(context);
return factory.showHabit(habit);
return pendingIntentFactory.showHabit(habit);
}
@Override

@ -25,12 +25,11 @@ import android.support.annotation.*;
import android.view.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.activities.habits.show.views.*;
import org.isoron.uhabits.widgets.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.widgets.views.*;
import java.util.*;
@ -45,14 +44,16 @@ public class ScoreWidget extends BaseWidget
{
super(context, id);
this.habit = habit;
prefs = HabitsApplication.getComponent().getPreferences();
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
prefs = app.getComponent().getPreferences();
}
@Override
public PendingIntent getOnClickPendingIntent(Context context)
{
PendingIntentFactory factory = new PendingIntentFactory(context);
return factory.showHabit(habit);
return pendingIntentFactory.showHabit(habit);
}
@Override

@ -25,15 +25,14 @@ import android.support.annotation.*;
import android.view.*;
import android.view.ViewGroup.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.widgets.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.widgets.views.*;
import java.util.*;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.*;
public class StreakWidget extends BaseWidget
{
@ -49,8 +48,7 @@ public class StreakWidget extends BaseWidget
@Override
public PendingIntent getOnClickPendingIntent(Context context)
{
PendingIntentFactory factory = new PendingIntentFactory(context);
return factory.showHabit(habit);
return pendingIntentFactory.showHabit(habit);
}
@Override

@ -24,6 +24,7 @@ import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.dialogs.*;
import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.utils.*;
import org.junit.*;
@ -34,9 +35,6 @@ public class BaseUnitTest
// 8:00am, January 25th, 2015 (UTC)
public static final long FIXED_LOCAL_TIME = 1422172800000L;
@Inject
protected Preferences prefs;
@Inject
protected ModelFactory modelFactory;
@ -68,6 +66,8 @@ public class BaseUnitTest
protected HabitFixtures fixtures;
protected SingleThreadTaskRunner taskRunner;
public void log(String format, Object... args)
{
System.out.println(String.format(format, args));
@ -80,7 +80,8 @@ public class BaseUnitTest
testComponent = DaggerTestComponent.create();
HabitsApplication.setComponent(testComponent);
testComponent.inject(this);
fixtures = new HabitFixtures(habitList);
fixtures = new HabitFixtures(modelFactory, habitList);
taskRunner = new SingleThreadTaskRunner();
}
@After

@ -123,12 +123,12 @@ public class ListHabitsScreenTest extends BaseUnitTest
verify(controller).onExportDB();
}
@Test
public void testOnResult_importData()
{
screen.onResult(0, ListHabitsScreen.RESULT_IMPORT_DATA, null);
testShowImportScreen();
}
// @Test
// public void testOnResult_importData()
// {
// screen.onResult(0, ListHabitsScreen.RESULT_IMPORT_DATA, null);
// testShowImportScreen();
// }
@Test
public void testShowAboutScreen() throws Exception
@ -209,12 +209,12 @@ public class ListHabitsScreenTest extends BaseUnitTest
verify(activity).showDialog(dialog);
}
@Test
public void testShowImportScreen_withInvalidPath()
{
when(dirFinder.findStorageDir(any())).thenReturn(null);
screen.showImportScreen();
}
// @Test
// public void testShowImportScreen_withInvalidPath()
// {
// when(dirFinder.findStorageDir(any())).thenReturn(null);
// screen.showImportScreen();
// }
@Test
public void testShowIntroScreen()

@ -20,8 +20,9 @@
package org.isoron.uhabits.activities.habits.list.controllers;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.habits.list.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import org.junit.*;
import static org.mockito.Mockito.*;
@ -38,6 +39,8 @@ public class CheckmarkButtonControllerTest extends BaseUnitTest
private int timestamp;
private Preferences prefs;
@Override
@Before
public void setUp()
@ -46,10 +49,12 @@ public class CheckmarkButtonControllerTest extends BaseUnitTest
timestamp = 0;
habit = mock(Habit.class);
prefs = mock(Preferences.class);
this.view = mock(CheckmarkButtonView.class);
this.listener = mock(CheckmarkButtonController.Listener.class);
this.controller = new CheckmarkButtonController(habit, timestamp);
this.controller =
new CheckmarkButtonController(prefs, habit, timestamp);
controller.setView(view);
controller.setListener(listener);
}

@ -51,7 +51,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
else fixtures.createShortHabit();
}
cache = new HabitCardListCache(habitList);
cache = new HabitCardListCache(habitList, commandRunner, taskRunner);
cache.setCheckmarkCount(10);
cache.refreshAllHabits();
cache.onAttached();

@ -27,16 +27,19 @@ public class HabitFixtures
true, false, false, true, true, true, false, false, true, true
};
private final ModelFactory modelFactory;
private final HabitList habitList;
public HabitFixtures(HabitList habitList)
public HabitFixtures(ModelFactory modelFactory, HabitList habitList)
{
this.modelFactory = modelFactory;
this.habitList = habitList;
}
public Habit createEmptyHabit()
{
Habit habit = new Habit();
Habit habit = modelFactory.buildHabit();
habit.setName("Meditate");
habit.setDescription("Did you meditate this morning?");
habit.setColor(3);
@ -65,7 +68,7 @@ public class HabitFixtures
public Habit createShortHabit()
{
Habit habit = new Habit();
Habit habit = modelFactory.buildHabit();
habit.setName("Wake up early");
habit.setDescription("Did you wake up before 6am?");
habit.setFrequency(new Frequency(2, 3));

@ -42,7 +42,9 @@ public class ReminderSchedulerTest extends BaseUnitTest
{
super.setUp();
intent = mock(PendingIntent.class);
reminderScheduler = new ReminderScheduler();
reminderScheduler =
new ReminderScheduler(pendingIntentFactory, intentScheduler,
logger);
habit = fixtures.createEmptyHabit();
}

Loading…
Cancel
Save