mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Improve usage of dagger
This commit is contained in:
@@ -66,8 +66,6 @@ public class BaseAndroidTest
|
||||
@Inject
|
||||
protected HabitLogger logger;
|
||||
|
||||
protected AndroidTestComponent androidTestComponent;
|
||||
|
||||
protected HabitFixtures fixtures;
|
||||
|
||||
protected CountDownLatch latch;
|
||||
@@ -87,9 +85,13 @@ public class BaseAndroidTest
|
||||
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
|
||||
setTheme(R.style.AppBaseTheme);
|
||||
|
||||
androidTestComponent = DaggerAndroidTestComponent.builder().build();
|
||||
HabitsApplication.setComponent(androidTestComponent);
|
||||
androidTestComponent.inject(this);
|
||||
AppComponent component = DaggerAppComponent.builder().build();
|
||||
HabitsApplication.setComponent(component);
|
||||
prefs = component.getPreferences();
|
||||
habitList = component.getHabitList();
|
||||
commandRunner = component.getCommandRunner();
|
||||
taskRunner = component.getTaskRunner();
|
||||
logger = component.getHabitsLogger();
|
||||
|
||||
fixtures = new HabitFixtures(habitList);
|
||||
|
||||
|
||||
@@ -45,9 +45,6 @@ public class HabitsApplicationTest extends BaseAndroidTest
|
||||
String msg = "LOGCAT TEST";
|
||||
new RuntimeException(msg).printStackTrace();
|
||||
|
||||
HabitsApplication app = HabitsApplication.getInstance();
|
||||
assert(app != null);
|
||||
|
||||
BaseSystem system = new BaseSystem(targetContext);
|
||||
String log = system.getLogcat();
|
||||
assertThat(log, containsString(msg));
|
||||
|
||||
@@ -23,24 +23,29 @@ import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.receivers.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
/**
|
||||
* Base component for dependency injection.
|
||||
*/
|
||||
public interface BaseComponent
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
AppModule.class, AndroidTaskRunner.class, SQLModelFactory.class
|
||||
})
|
||||
public interface AppComponent
|
||||
{
|
||||
CommandRunner getCommandRunner();
|
||||
|
||||
DialogFactory getDialogFactory();
|
||||
|
||||
DirFinder getDirFinder();
|
||||
|
||||
HabitList getHabitList();
|
||||
|
||||
HabitLogger getHabitLogger();
|
||||
HabitLogger getHabitsLogger();
|
||||
|
||||
IntentFactory getIntentFactory();
|
||||
|
||||
@@ -52,9 +57,13 @@ public interface BaseComponent
|
||||
|
||||
Preferences getPreferences();
|
||||
|
||||
ReceiverActions getReceiverActions();
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
TaskRunner getTaskRunner();
|
||||
|
||||
WidgetPreferences getWidgetPreferences();
|
||||
|
||||
WidgetUpdater getWidgetUpdater();
|
||||
}
|
||||
@@ -19,14 +19,13 @@
|
||||
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import dagger.Component;
|
||||
import javax.inject.*;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {AndroidModule.class})
|
||||
public interface AndroidTestComponent extends BaseComponent
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AppContext
|
||||
{
|
||||
void inject(BaseAndroidTest baseAndroidTest);
|
||||
}
|
||||
|
||||
@@ -21,47 +21,22 @@ package org.isoron.uhabits;
|
||||
|
||||
import android.content.*;
|
||||
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
/**
|
||||
* Module that provides dependencies when the application is running on
|
||||
* Android.
|
||||
* <p>
|
||||
* This module is also used for instrumented tests.
|
||||
*/
|
||||
@Module
|
||||
public class AndroidModule
|
||||
public class AppModule
|
||||
{
|
||||
@Provides
|
||||
@Singleton
|
||||
static HabitList provideHabitList()
|
||||
private final Context context;
|
||||
|
||||
public AppModule(@AppContext Context context)
|
||||
{
|
||||
return SQLiteHabitList.getInstance();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Provides
|
||||
static ModelFactory provideModelFactory()
|
||||
@AppContext
|
||||
Context getContext()
|
||||
{
|
||||
return new SQLModelFactory();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Context provideApplicationContext()
|
||||
{
|
||||
return HabitsApplication.getContext();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static TaskRunner provideTaskRunner()
|
||||
{
|
||||
return new AndroidTaskRunner();
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -35,30 +35,18 @@ import java.io.*;
|
||||
*/
|
||||
public class HabitsApplication extends Application
|
||||
{
|
||||
public static final int RESULT_BUG_REPORT = 4;
|
||||
|
||||
public static final int RESULT_EXPORT_CSV = 2;
|
||||
|
||||
public static final int RESULT_EXPORT_DB = 3;
|
||||
|
||||
public static final int RESULT_IMPORT_DATA = 1;
|
||||
|
||||
@Nullable
|
||||
private static HabitsApplication application;
|
||||
|
||||
private static BaseComponent component;
|
||||
|
||||
@Nullable
|
||||
private static Context context;
|
||||
|
||||
private static AppComponent component;
|
||||
|
||||
private static WidgetUpdater widgetUpdater;
|
||||
|
||||
public static BaseComponent getComponent()
|
||||
public static AppComponent getComponent()
|
||||
{
|
||||
return component;
|
||||
}
|
||||
|
||||
public static void setComponent(BaseComponent component)
|
||||
public static void setComponent(AppComponent component)
|
||||
{
|
||||
HabitsApplication.component = component;
|
||||
}
|
||||
@@ -70,21 +58,6 @@ public class HabitsApplication extends Application
|
||||
return context;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static HabitsApplication getInstance()
|
||||
{
|
||||
return application;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static WidgetUpdater getWidgetUpdater()
|
||||
{
|
||||
if (widgetUpdater == null) throw new RuntimeException(
|
||||
"widgetUpdater is null");
|
||||
|
||||
return widgetUpdater;
|
||||
}
|
||||
|
||||
public static boolean isTestMode()
|
||||
{
|
||||
try
|
||||
@@ -107,8 +80,11 @@ public class HabitsApplication extends Application
|
||||
{
|
||||
super.onCreate();
|
||||
HabitsApplication.context = this;
|
||||
HabitsApplication.application = this;
|
||||
component = DaggerAndroidComponent.builder().build();
|
||||
|
||||
component = DaggerAppComponent
|
||||
.builder()
|
||||
.appModule(new AppModule(context))
|
||||
.build();
|
||||
|
||||
if (isTestMode())
|
||||
{
|
||||
@@ -116,7 +92,7 @@ public class HabitsApplication extends Application
|
||||
if (db.exists()) db.delete();
|
||||
}
|
||||
|
||||
widgetUpdater = new WidgetUpdater(this);
|
||||
widgetUpdater = component.getWidgetUpdater();
|
||||
widgetUpdater.startListening();
|
||||
|
||||
DatabaseUtils.initializeActiveAndroid();
|
||||
|
||||
@@ -24,6 +24,8 @@ import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.app.AlarmManager.*;
|
||||
@@ -35,7 +37,7 @@ public class IntentScheduler
|
||||
private final AlarmManager manager;
|
||||
|
||||
@Inject
|
||||
public IntentScheduler(@NonNull Context context)
|
||||
public IntentScheduler(@AppContext Context context)
|
||||
{
|
||||
manager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
|
||||
}
|
||||
|
||||
@@ -35,13 +35,12 @@ import static android.app.PendingIntent.*;
|
||||
@Singleton
|
||||
public class PendingIntentFactory
|
||||
{
|
||||
@NonNull
|
||||
private final Context context;
|
||||
|
||||
private IntentFactory intentFactory;
|
||||
|
||||
@Inject
|
||||
public PendingIntentFactory(@NonNull Context context)
|
||||
public PendingIntentFactory(@AppContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
intentFactory = HabitsApplication.getComponent().getIntentFactory();
|
||||
|
||||
@@ -42,9 +42,9 @@ public class DirFinder
|
||||
private final Context context;
|
||||
|
||||
@Inject
|
||||
public DirFinder()
|
||||
public DirFinder(@AppContext Context context)
|
||||
{
|
||||
context = HabitsApplication.getContext();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.support.annotation.NonNull;
|
||||
import com.activeandroid.ActiveAndroid;
|
||||
import com.opencsv.CSVReader;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.database.*;
|
||||
import android.database.sqlite.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.DatabaseUtils;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
@@ -19,17 +19,16 @@
|
||||
|
||||
package org.isoron.uhabits.io;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.database.*;
|
||||
import android.database.sqlite.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.DatabaseUtils;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class that imports data from database files exported by Tickmate.
|
||||
|
||||
@@ -70,19 +70,6 @@ public class Habit
|
||||
|
||||
private ModelObservable observable = new ModelObservable();
|
||||
|
||||
private ModelFactory factory;
|
||||
|
||||
/**
|
||||
* Constructs a habit with the same attributes as the specified habit.
|
||||
*
|
||||
* @param model the model whose attributes should be copied from
|
||||
*/
|
||||
public Habit(Habit model)
|
||||
{
|
||||
copyFrom(model);
|
||||
buildLists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a habit with default attributes.
|
||||
* <p>
|
||||
@@ -95,13 +82,8 @@ public class Habit
|
||||
this.archived = false;
|
||||
this.frequency = new Frequency(3, 7);
|
||||
|
||||
buildLists();
|
||||
}
|
||||
|
||||
private void buildLists()
|
||||
{
|
||||
factory = HabitsApplication.getComponent().getModelFactory();
|
||||
|
||||
ModelFactory factory =
|
||||
HabitsApplication.getComponent().getModelFactory();
|
||||
checkmarks = factory.buildCheckmarkList(this);
|
||||
streaks = factory.buildStreakList(this);
|
||||
scores = factory.buildScoreList(this);
|
||||
|
||||
@@ -21,12 +21,31 @@ package org.isoron.uhabits.models.memory;
|
||||
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
public class MemoryModelFactory implements ModelFactory
|
||||
{
|
||||
@Override
|
||||
public RepetitionList buildRepetitionList(Habit habit)
|
||||
@Provides
|
||||
@Singleton
|
||||
public static HabitList provideHabitList()
|
||||
{
|
||||
return new MemoryRepetitionList(habit);
|
||||
return new MemoryHabitList();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public static ModelFactory provideModelFactory()
|
||||
{
|
||||
return new MemoryModelFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckmarkList buildCheckmarkList(Habit habit)
|
||||
{
|
||||
return new MemoryCheckmarkList(habit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,9 +55,9 @@ public class MemoryModelFactory implements ModelFactory
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckmarkList buildCheckmarkList(Habit habit)
|
||||
public RepetitionList buildRepetitionList(Habit habit)
|
||||
{
|
||||
return new MemoryCheckmarkList(habit);
|
||||
return new MemoryRepetitionList(habit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,22 +23,25 @@ import org.isoron.uhabits.models.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
/**
|
||||
* Factory that provides models backed by an SQLite database.
|
||||
*/
|
||||
@Singleton
|
||||
@Module
|
||||
public class SQLModelFactory implements ModelFactory
|
||||
{
|
||||
@Inject
|
||||
public SQLModelFactory()
|
||||
@Provides
|
||||
public static ModelFactory provideModelFactory()
|
||||
{
|
||||
|
||||
return new SQLModelFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepetitionList buildRepetitionList(Habit habit)
|
||||
@Provides
|
||||
@Singleton
|
||||
static HabitList provideHabitList()
|
||||
{
|
||||
return new SQLiteRepetitionList(habit);
|
||||
return SQLiteHabitList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,6 +56,12 @@ public class SQLModelFactory implements ModelFactory
|
||||
return SQLiteHabitList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepetitionList buildRepetitionList(Habit habit)
|
||||
{
|
||||
return new SQLiteRepetitionList(habit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScoreList buildScoreList(Habit habit)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PebbleReceiver extends PebbleDataReceiver
|
||||
public PebbleReceiver()
|
||||
{
|
||||
super(WATCHAPP_UUID);
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
commandRunner = component.getCommandRunner();
|
||||
taskRunner = component.getTaskRunner();
|
||||
allHabits = component.getHabitList();
|
||||
|
||||
@@ -21,34 +21,37 @@ package org.isoron.uhabits.receivers;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@Singleton
|
||||
public class ReceiverActions
|
||||
{
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
public ReceiverActions()
|
||||
@Inject
|
||||
public ReceiverActions(CommandRunner commandRunner)
|
||||
{
|
||||
commandRunner = HabitsApplication.getComponent().getCommandRunner();
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
|
||||
public void add_repetition(@NonNull Habit habit, long timestamp)
|
||||
public void addRepetition(@NonNull Habit habit, long timestamp)
|
||||
{
|
||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||
if (rep != null) return;
|
||||
toggle_repetition(habit, timestamp);
|
||||
toggleRepetition(habit, timestamp);
|
||||
}
|
||||
|
||||
public void remove_repetition(@NonNull Habit habit, long timestamp)
|
||||
public void removeRepetition(@NonNull Habit habit, long timestamp)
|
||||
{
|
||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||
if (rep == null) return;
|
||||
toggle_repetition(habit, timestamp);
|
||||
toggleRepetition(habit, timestamp);
|
||||
}
|
||||
|
||||
public void toggle_repetition(@NonNull Habit habit, long timestamp)
|
||||
public void toggleRepetition(@NonNull Habit habit, long timestamp)
|
||||
{
|
||||
commandRunner.execute(new ToggleRepetitionCommand(habit, timestamp),
|
||||
habit.getId());
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ReminderReceiver extends BroadcastReceiver
|
||||
{
|
||||
super();
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
habits = component.getHabitList();
|
||||
taskRunner = component.getTaskRunner();
|
||||
reminderScheduler = component.getReminderScheduler();
|
||||
|
||||
@@ -57,11 +57,10 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
|
||||
public WidgetReceiver()
|
||||
{
|
||||
super();
|
||||
habits = HabitsApplication.getComponent().getHabitList();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
habits = component.getHabitList();
|
||||
actions = component.getReceiverActions();
|
||||
parser = new IntentParser(habits);
|
||||
actions = new ReceiverActions();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,20 +95,20 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
{
|
||||
IntentParser.CheckmarkIntentData data;
|
||||
data = parser.parseCheckmarkIntent(intent);
|
||||
actions.add_repetition(data.habit, data.timestamp);
|
||||
actions.addRepetition(data.habit, data.timestamp);
|
||||
}
|
||||
|
||||
private void onActionRemoveRepetition(Intent intent)
|
||||
{
|
||||
IntentParser.CheckmarkIntentData data;
|
||||
data = parser.parseCheckmarkIntent(intent);
|
||||
actions.remove_repetition(data.habit, data.timestamp);
|
||||
actions.removeRepetition(data.habit, data.timestamp);
|
||||
}
|
||||
|
||||
private void onActionToggleRepetition(Intent intent)
|
||||
{
|
||||
IntentParser.CheckmarkIntentData data;
|
||||
data = parser.parseCheckmarkIntent(intent);
|
||||
actions.toggle_repetition(data.habit, data.timestamp);
|
||||
actions.toggleRepetition(data.habit, data.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,17 +26,25 @@ import java.util.concurrent.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
@Singleton
|
||||
public class AndroidTaskRunner implements TaskRunner
|
||||
{
|
||||
private final LinkedList<CustomAsyncTask> activeTasks;
|
||||
|
||||
@Inject
|
||||
public AndroidTaskRunner()
|
||||
{
|
||||
activeTasks = new LinkedList<>();
|
||||
}
|
||||
|
||||
@Provides
|
||||
public static TaskRunner provideTaskRunner()
|
||||
{
|
||||
return new AndroidTaskRunner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Task task)
|
||||
{
|
||||
@@ -56,7 +64,8 @@ public class AndroidTaskRunner implements TaskRunner
|
||||
throws TimeoutException, InterruptedException
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
|
||||
throw new UnsupportedOperationException("waitForTasks requires API 16+");
|
||||
throw new UnsupportedOperationException(
|
||||
"waitForTasks requires API 16+");
|
||||
|
||||
int poolInterval = 100;
|
||||
|
||||
@@ -104,17 +113,17 @@ public class AndroidTaskRunner implements TaskRunner
|
||||
activeTasks.remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... values)
|
||||
{
|
||||
task.onProgressUpdate(values[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
activeTasks.add(this);
|
||||
task.onPreExecute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... values)
|
||||
{
|
||||
task.onProgressUpdate(values[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,20 @@ package org.isoron.uhabits.tasks;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
public class SingleThreadTaskRunner implements TaskRunner
|
||||
{
|
||||
@Provides
|
||||
@Singleton
|
||||
public static SingleThreadTaskRunner getInstance()
|
||||
{
|
||||
return new SingleThreadTaskRunner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Task task)
|
||||
{
|
||||
|
||||
@@ -17,18 +17,14 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits;
|
||||
package org.isoron.uhabits.ui;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.*;
|
||||
|
||||
/**
|
||||
* Dependency injection component for classes that are specific to Android.
|
||||
*/
|
||||
@Singleton
|
||||
@Component(modules = {AndroidModule.class})
|
||||
public interface AndroidComponent extends BaseComponent
|
||||
@Component(modules = { ActivityModule.class })
|
||||
public interface ActivityComponent
|
||||
{
|
||||
DialogFactory getDialogFactory();
|
||||
}
|
||||
|
||||
31
app/src/main/java/org/isoron/uhabits/ui/ActivityContext.java
Normal file
31
app/src/main/java/org/isoron/uhabits/ui/ActivityContext.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ActivityContext
|
||||
{
|
||||
}
|
||||
42
app/src/main/java/org/isoron/uhabits/ui/ActivityModule.java
Normal file
42
app/src/main/java/org/isoron/uhabits/ui/ActivityModule.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.ui;
|
||||
|
||||
import android.content.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
public class ActivityModule
|
||||
{
|
||||
private final Context context;
|
||||
|
||||
public ActivityModule(@ActivityContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@ActivityContext
|
||||
Context getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,13 @@ abstract public class BaseActivity extends AppCompatActivity
|
||||
@Nullable
|
||||
private BaseScreen screen;
|
||||
|
||||
private ActivityComponent component;
|
||||
|
||||
public ActivityComponent getComponent()
|
||||
{
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@Nullable Menu menu)
|
||||
{
|
||||
@@ -123,5 +130,10 @@ abstract public class BaseActivity extends AppCompatActivity
|
||||
InterfaceUtils.applyCurrentTheme(this);
|
||||
androidExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
|
||||
component = DaggerActivityComponent
|
||||
.builder()
|
||||
.activityModule(new ActivityModule(this))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -46,9 +45,6 @@ public class BaseSystem
|
||||
{
|
||||
private Context context;
|
||||
|
||||
@Inject
|
||||
HabitList habitList;
|
||||
|
||||
@Inject
|
||||
ReminderScheduler reminderScheduler;
|
||||
|
||||
@@ -56,8 +52,7 @@ public class BaseSystem
|
||||
{
|
||||
this.context = context;
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
habitList = component.getHabitList();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
reminderScheduler = component.getReminderScheduler();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ import org.isoron.uhabits.utils.*;
|
||||
*/
|
||||
public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
|
||||
{
|
||||
public static ColorPickerDialog newInstance(int paletteColor)
|
||||
public static ColorPickerDialog newInstance(Context context,
|
||||
int paletteColor)
|
||||
{
|
||||
ColorPickerDialog dialog = new ColorPickerDialog();
|
||||
Context context = dialog.getContext();
|
||||
StyledResources res = new StyledResources(context);
|
||||
|
||||
int color = ColorUtils.getColor(context, paletteColor);
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.edit.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -31,21 +32,22 @@ import javax.inject.*;
|
||||
|
||||
public class DialogFactory
|
||||
{
|
||||
@Inject
|
||||
public DialogFactory()
|
||||
{
|
||||
private final Context context;
|
||||
|
||||
@Inject
|
||||
public DialogFactory(@ActivityContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ColorPickerDialog buildColorPicker(int paletteColor)
|
||||
{
|
||||
return ColorPickerDialog.newInstance(paletteColor);
|
||||
return ColorPickerDialog.newInstance(context, paletteColor);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ConfirmDeleteDialog buildConfirmDeleteDialog(
|
||||
@NonNull Context context,
|
||||
@NonNull ConfirmDeleteDialog.Callback callback)
|
||||
{
|
||||
return new ConfirmDeleteDialog(context, callback);
|
||||
@@ -64,7 +66,7 @@ public class DialogFactory
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public FilePickerDialog buildFilePicker(Context context, File dir)
|
||||
public FilePickerDialog buildFilePicker(File dir)
|
||||
{
|
||||
return new FilePickerDialog(context, dir);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.edit;
|
||||
|
||||
import android.app.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.app.*;
|
||||
@@ -26,10 +27,12 @@ import android.text.format.*;
|
||||
import android.view.*;
|
||||
|
||||
import com.android.datetimepicker.time.*;
|
||||
import com.android.datetimepicker.time.TimePickerDialog;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
@@ -63,11 +66,10 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
||||
{
|
||||
View view = inflater.inflate(R.layout.edit_habit, container, false);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
prefs = component.getPreferences();
|
||||
habitList = component.getHabitList();
|
||||
commandRunner = component.getCommandRunner();
|
||||
dialogFactory = component.getDialogFactory();
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
@@ -79,6 +81,16 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity)
|
||||
{
|
||||
super.onAttach(activity);
|
||||
|
||||
BaseActivity baseActivity = (BaseActivity) activity;
|
||||
ActivityComponent component = baseActivity.getComponent();
|
||||
dialogFactory = component.getDialogFactory();
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.sFrequency)
|
||||
public void onFrequencySelected(int position)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -68,7 +69,7 @@ public class ListHabitsController
|
||||
this.habitList = habitList;
|
||||
this.adapter = adapter;
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
prefs = component.getPreferences();
|
||||
taskRunner = component.getTaskRunner();
|
||||
commandRunner = component.getCommandRunner();
|
||||
@@ -165,11 +166,16 @@ public class ListHabitsController
|
||||
prefs.updateLastAppVersion();
|
||||
if (prefs.isFirstRun()) onFirstRun();
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
ReminderScheduler reminderScheduler =
|
||||
HabitsApplication.getComponent().getReminderScheduler();
|
||||
taskRunner.execute(() -> reminderScheduler.schedule(habitList));
|
||||
HabitsApplication.getWidgetUpdater().updateWidgets();
|
||||
new Handler().postDelayed(() ->
|
||||
{
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
ReminderScheduler scheduler = component.getReminderScheduler();
|
||||
WidgetUpdater widgetUpdater = component.getWidgetUpdater();
|
||||
|
||||
taskRunner.execute(() -> {
|
||||
scheduler.schedule(habitList);
|
||||
widgetUpdater.updateWidgets();
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,14 @@ import java.io.*;
|
||||
public class ListHabitsScreen extends BaseScreen
|
||||
implements CommandRunner.Listener
|
||||
{
|
||||
public static final int RESULT_BUG_REPORT = 4;
|
||||
|
||||
public static final int RESULT_EXPORT_CSV = 2;
|
||||
|
||||
public static final int RESULT_EXPORT_DB = 3;
|
||||
|
||||
public static final int RESULT_IMPORT_DATA = 1;
|
||||
|
||||
@Nullable
|
||||
ListHabitsController controller;
|
||||
|
||||
@@ -59,11 +67,11 @@ public class ListHabitsScreen extends BaseScreen
|
||||
super(activity);
|
||||
setRootView(rootView);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
dialogFactory = component.getDialogFactory();
|
||||
intentFactory = component.getIntentFactory();
|
||||
dirFinder = component.getDirFinder();
|
||||
commandRunner = component.getCommandRunner();
|
||||
AppComponent comp = HabitsApplication.getComponent();
|
||||
intentFactory = comp.getIntentFactory();
|
||||
dirFinder = comp.getDirFinder();
|
||||
commandRunner = comp.getCommandRunner();
|
||||
dialogFactory = activity.getComponent().getDialogFactory();
|
||||
}
|
||||
|
||||
public void onAttached()
|
||||
@@ -90,19 +98,19 @@ public class ListHabitsScreen extends BaseScreen
|
||||
|
||||
switch (resultCode)
|
||||
{
|
||||
case HabitsApplication.RESULT_IMPORT_DATA:
|
||||
case RESULT_IMPORT_DATA:
|
||||
showImportScreen();
|
||||
break;
|
||||
|
||||
case HabitsApplication.RESULT_EXPORT_CSV:
|
||||
case RESULT_EXPORT_CSV:
|
||||
controller.onExportCSV();
|
||||
break;
|
||||
|
||||
case HabitsApplication.RESULT_EXPORT_DB:
|
||||
case RESULT_EXPORT_DB:
|
||||
controller.onExportDB();
|
||||
break;
|
||||
|
||||
case HabitsApplication.RESULT_BUG_REPORT:
|
||||
case RESULT_BUG_REPORT:
|
||||
controller.onSendBugReport();
|
||||
break;
|
||||
}
|
||||
@@ -145,7 +153,7 @@ public class ListHabitsScreen extends BaseScreen
|
||||
public void showDeleteConfirmationScreen(ConfirmDeleteDialog.Callback callback)
|
||||
{
|
||||
ConfirmDeleteDialog dialog =
|
||||
dialogFactory.buildConfirmDeleteDialog(activity, callback);
|
||||
dialogFactory.buildConfirmDeleteDialog(callback);
|
||||
activity.showDialog(dialog);
|
||||
}
|
||||
|
||||
@@ -177,7 +185,7 @@ public class ListHabitsScreen extends BaseScreen
|
||||
return;
|
||||
}
|
||||
|
||||
FilePickerDialog picker = dialogFactory.buildFilePicker(activity, dir);
|
||||
FilePickerDialog picker = dialogFactory.buildFilePicker(dir);
|
||||
if (controller != null)
|
||||
picker.setListener(file -> controller.onImportData(file));
|
||||
activity.showDialog(picker.getDialog());
|
||||
|
||||
@@ -66,7 +66,7 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
this.listener = new Listener() {};
|
||||
data = new CacheData();
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
commandRunner = component.getCommandRunner();
|
||||
taskRunner = component.getTaskRunner();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.ui.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
@@ -39,7 +38,7 @@ public class ShowHabitScreen extends BaseScreen
|
||||
ShowHabitRootView view)
|
||||
{
|
||||
super(activity);
|
||||
dialogFactory = HabitsApplication.getComponent().getDialogFactory();
|
||||
dialogFactory = activity.getComponent().getDialogFactory();
|
||||
|
||||
this.habit = habit;
|
||||
setRootView(view);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ScoreCard extends HabitCard
|
||||
public void onItemSelected(int position)
|
||||
{
|
||||
setBucketSizeFromPosition(position);
|
||||
HabitsApplication.getWidgetUpdater().updateWidgets();
|
||||
HabitsApplication.getComponent().getWidgetUpdater().updateWidgets();
|
||||
refreshData();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,9 @@ import android.os.*;
|
||||
import android.support.v7.preference.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ui.habits.list.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import static org.isoron.uhabits.HabitsApplication.*;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
{
|
||||
@@ -55,10 +54,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
setResultOnPreferenceClick("importData", RESULT_IMPORT_DATA);
|
||||
setResultOnPreferenceClick("exportCSV", RESULT_EXPORT_CSV);
|
||||
setResultOnPreferenceClick("exportDB", RESULT_EXPORT_DB);
|
||||
setResultOnPreferenceClick("bugReport", RESULT_BUG_REPORT);
|
||||
setResultOnPreferenceClick("importData", ListHabitsScreen.RESULT_IMPORT_DATA);
|
||||
setResultOnPreferenceClick("exportCSV", ListHabitsScreen.RESULT_EXPORT_CSV);
|
||||
setResultOnPreferenceClick("exportDB", ListHabitsScreen.RESULT_EXPORT_DB);
|
||||
setResultOnPreferenceClick("bugReport", ListHabitsScreen.RESULT_BUG_REPORT);
|
||||
|
||||
updateRingtoneDescription();
|
||||
|
||||
|
||||
@@ -52,7 +52,8 @@ public class HabitPickerDialog extends Activity
|
||||
{
|
||||
Long habitId = habitIds.get(position);
|
||||
preferences.addWidget(widgetId, habitId);
|
||||
HabitsApplication.getWidgetUpdater().updateWidgets();
|
||||
|
||||
HabitsApplication.getComponent().getWidgetUpdater().updateWidgets();
|
||||
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(EXTRA_APPWIDGET_ID, widgetId);
|
||||
@@ -66,7 +67,7 @@ public class HabitPickerDialog extends Activity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.widget_configure_activity);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
habitList = component.getHabitList();
|
||||
preferences = component.getWidgetPreferences();
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* A WidgetUpdater listens to the commands being executed by the application and
|
||||
* updates the home-screen widgets accordingly.
|
||||
@@ -36,15 +38,18 @@ import org.isoron.uhabits.widgets.*;
|
||||
*/
|
||||
public class WidgetUpdater implements CommandRunner.Listener
|
||||
{
|
||||
@NonNull
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
@NonNull
|
||||
private final Context context;
|
||||
|
||||
public WidgetUpdater(@NonNull Context context)
|
||||
@Inject
|
||||
public WidgetUpdater(@NonNull @AppContext Context context,
|
||||
@NonNull CommandRunner commandRunner)
|
||||
{
|
||||
this.context = context;
|
||||
commandRunner = HabitsApplication.getComponent().getCommandRunner();
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,14 +29,14 @@ import javax.inject.*;
|
||||
@Singleton
|
||||
public class Preferences
|
||||
{
|
||||
private Context context;
|
||||
private final Context context;
|
||||
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@Inject
|
||||
public Preferences()
|
||||
public Preferences(@AppContext Context context)
|
||||
{
|
||||
this.context = HabitsApplication.getContext();
|
||||
this.context = context;
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,10 @@ public class ReminderScheduler
|
||||
@Inject
|
||||
public ReminderScheduler()
|
||||
{
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
pendingIntentFactory = component.getPendingIntentFactory();
|
||||
intentScheduler = component.getIntentScheduler();
|
||||
logger = component.getHabitLogger();
|
||||
logger = component.getHabitsLogger();
|
||||
}
|
||||
|
||||
public void schedule(@NonNull Habit habit, @Nullable Long reminderTime)
|
||||
|
||||
@@ -22,16 +22,17 @@ package org.isoron.uhabits.utils;
|
||||
import android.content.*;
|
||||
import android.preference.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@Singleton
|
||||
public class WidgetPreferences
|
||||
{
|
||||
|
||||
private SharedPreferences prefs;
|
||||
private final SharedPreferences prefs;
|
||||
|
||||
@Inject
|
||||
public WidgetPreferences(Context context)
|
||||
public WidgetPreferences(@AppContext Context context)
|
||||
{
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
|
||||
public BaseWidgetProvider()
|
||||
{
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
AppComponent component = HabitsApplication.getComponent();
|
||||
habits = component.getHabitList();
|
||||
widgetPrefs = component.getWidgetPreferences();
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ package org.isoron.uhabits;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.models.memory.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
@@ -34,7 +34,7 @@ import dagger.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@Module
|
||||
public class TestModule
|
||||
public class MockModule
|
||||
{
|
||||
@Provides
|
||||
@Singleton
|
||||
@@ -56,13 +56,6 @@ public class TestModule
|
||||
return mock(Habit.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
HabitList provideHabitList()
|
||||
{
|
||||
return new MemoryHabitList();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
IntentFactory provideIntentFactory()
|
||||
@@ -84,13 +77,6 @@ public class TestModule
|
||||
return mock(HabitLogger.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ModelFactory provideModelFactory()
|
||||
{
|
||||
return new MemoryModelFactory();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
PendingIntentFactory providePendingIntentFactory()
|
||||
@@ -125,4 +111,11 @@ public class TestModule
|
||||
{
|
||||
return new SingleThreadTaskRunner();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
WidgetUpdater provideWidgetUpdate()
|
||||
{
|
||||
return mock(WidgetUpdater.class);
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,15 @@
|
||||
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import org.isoron.uhabits.models.memory.*;
|
||||
|
||||
import dagger.Component;
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {TestModule.class})
|
||||
public interface TestComponent extends BaseComponent
|
||||
@Component(modules = { MockModule.class, MemoryModelFactory.class })
|
||||
public interface TestComponent extends AppComponent
|
||||
{
|
||||
void inject(BaseUnitTest baseUnitTest);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,11 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
ActivityComponent activityComponent = mock(ActivityComponent.class);
|
||||
|
||||
activity = mock(BaseActivity.class);
|
||||
when(activity.getComponent()).thenReturn(activityComponent);
|
||||
|
||||
rootView = mock(ListHabitsRootView.class);
|
||||
controller = mock(ListHabitsController.class);
|
||||
intent = mock(Intent.class);
|
||||
@@ -82,28 +86,28 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testOnResult_bugReport()
|
||||
{
|
||||
screen.onResult(0, HabitsApplication.RESULT_BUG_REPORT, null);
|
||||
screen.onResult(0, ListHabitsScreen.RESULT_BUG_REPORT, null);
|
||||
verify(controller).onSendBugReport();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnResult_exportCSV()
|
||||
{
|
||||
screen.onResult(0, HabitsApplication.RESULT_EXPORT_CSV, null);
|
||||
screen.onResult(0, ListHabitsScreen.RESULT_EXPORT_CSV, null);
|
||||
verify(controller).onExportCSV();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnResult_exportDB()
|
||||
{
|
||||
screen.onResult(0, HabitsApplication.RESULT_EXPORT_DB, null);
|
||||
screen.onResult(0, ListHabitsScreen.RESULT_EXPORT_DB, null);
|
||||
verify(controller).onExportDB();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnResult_importData()
|
||||
{
|
||||
screen.onResult(0, HabitsApplication.RESULT_IMPORT_DATA, null);
|
||||
screen.onResult(0, ListHabitsScreen.RESULT_IMPORT_DATA, null);
|
||||
testShowImportScreen();
|
||||
}
|
||||
|
||||
@@ -136,8 +140,7 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
||||
callback = mock(ConfirmDeleteDialog.Callback.class);
|
||||
|
||||
ConfirmDeleteDialog dialog = mock(ConfirmDeleteDialog.class);
|
||||
when(dialogFactory.buildConfirmDeleteDialog(activity,
|
||||
callback)).thenReturn(dialog);
|
||||
when(dialogFactory.buildConfirmDeleteDialog(callback)).thenReturn(dialog);
|
||||
|
||||
screen.showDeleteConfirmationScreen(callback);
|
||||
|
||||
@@ -180,7 +183,7 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
||||
FilePickerDialog picker = mock(FilePickerDialog.class);
|
||||
AppCompatDialog dialog = mock(AppCompatDialog.class);
|
||||
when(picker.getDialog()).thenReturn(dialog);
|
||||
when(dialogFactory.buildFilePicker(activity, dir)).thenReturn(picker);
|
||||
when(dialogFactory.buildFilePicker(dir)).thenReturn(picker);
|
||||
|
||||
screen.showImportScreen();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user