mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Dagger: replace injects by getters
This commit is contained in:
@@ -23,19 +23,9 @@ import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.receivers.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
import org.isoron.uhabits.ui.habits.edit.*;
|
||||
import org.isoron.uhabits.ui.habits.list.*;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
|
||||
/**
|
||||
* Base component for dependency injection.
|
||||
@@ -44,81 +34,27 @@ public interface BaseComponent
|
||||
{
|
||||
CommandRunner getCommandRunner();
|
||||
|
||||
DialogFactory getDialogFactory();
|
||||
|
||||
DirFinder getDirFinder();
|
||||
|
||||
HabitList getHabitList();
|
||||
|
||||
HabitLogger getHabitLogger();
|
||||
|
||||
IntentFactory getIntentFactory();
|
||||
|
||||
IntentScheduler getIntentScheduler();
|
||||
|
||||
ModelFactory getModelFactory();
|
||||
|
||||
PendingIntentFactory getPendingIntentFactory();
|
||||
|
||||
Preferences getPreferences();
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
TaskRunner getTaskRunner();
|
||||
|
||||
void inject(CheckmarkButtonController checkmarkButtonController);
|
||||
|
||||
void inject(ListHabitsController listHabitsController);
|
||||
|
||||
void inject(CheckmarkPanelView checkmarkPanelView);
|
||||
|
||||
void inject(WidgetReceiver widgetReceiver);
|
||||
|
||||
void inject(ListHabitsSelectionMenu listHabitsSelectionMenu);
|
||||
|
||||
void inject(HintList hintList);
|
||||
|
||||
void inject(HabitCardListAdapter habitCardListAdapter);
|
||||
|
||||
void inject(ArchiveHabitsCommand archiveHabitsCommand);
|
||||
|
||||
void inject(ChangeHabitColorCommand changeHabitColorCommand);
|
||||
|
||||
void inject(UnarchiveHabitsCommand unarchiveHabitsCommand);
|
||||
|
||||
void inject(EditHabitCommand editHabitCommand);
|
||||
|
||||
void inject(CreateHabitCommand createHabitCommand);
|
||||
|
||||
void inject(HabitPickerDialog habitPickerDialog);
|
||||
|
||||
void inject(BaseWidgetProvider baseWidgetProvider);
|
||||
|
||||
void inject(ShowHabitActivity showHabitActivity);
|
||||
|
||||
void inject(DeleteHabitsCommand deleteHabitsCommand);
|
||||
|
||||
void inject(ListHabitsActivity listHabitsActivity);
|
||||
|
||||
void inject(BaseSystem baseSystem);
|
||||
|
||||
void inject(HabitsApplication application);
|
||||
|
||||
void inject(Habit habit);
|
||||
|
||||
void inject(AbstractImporter abstractImporter);
|
||||
|
||||
void inject(HabitsCSVExporter habitsCSVExporter);
|
||||
|
||||
void inject(BaseDialog baseDialog);
|
||||
|
||||
void inject(ShowHabitController showHabitController);
|
||||
|
||||
void inject(BaseWidget baseWidget);
|
||||
|
||||
void inject(WidgetUpdater widgetManager);
|
||||
|
||||
void inject(ListHabitsMenu listHabitsMenu);
|
||||
|
||||
void inject(PebbleReceiver receiver);
|
||||
|
||||
void inject(HeaderView headerView);
|
||||
|
||||
void inject(ReceiverActions receiverActions);
|
||||
|
||||
void inject(ReminderScheduler reminderScheduler);
|
||||
|
||||
void inject(ListHabitsScreen listHabitsScreen);
|
||||
|
||||
void inject(ShowHabitScreen showHabitScreen);
|
||||
|
||||
void inject(ConfirmDeleteDialog confirmDeleteDialog);
|
||||
|
||||
void inject(PendingIntentFactory pendingIntentFactory);
|
||||
WidgetPreferences getWidgetPreferences();
|
||||
}
|
||||
|
||||
@@ -109,7 +109,6 @@ public class HabitsApplication extends Application
|
||||
HabitsApplication.context = this;
|
||||
HabitsApplication.application = this;
|
||||
component = DaggerAndroidComponent.builder().build();
|
||||
component.inject(this);
|
||||
|
||||
if (isTestMode())
|
||||
{
|
||||
|
||||
@@ -36,7 +36,6 @@ public class ArchiveHabitsCommand extends Command
|
||||
public ArchiveHabitsCommand(HabitList habitList, List<Habit> selectedHabits)
|
||||
{
|
||||
this.habitList = habitList;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
this.selectedHabits = selectedHabits;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,14 +38,13 @@ public class PendingIntentFactory
|
||||
@NonNull
|
||||
private final Context context;
|
||||
|
||||
@Inject
|
||||
protected IntentFactory intentFactory;
|
||||
private IntentFactory intentFactory;
|
||||
|
||||
@Inject
|
||||
public PendingIntentFactory(@NonNull Context context)
|
||||
{
|
||||
this.context = context;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
intentFactory = HabitsApplication.getComponent().getIntentFactory();
|
||||
}
|
||||
|
||||
public PendingIntent addCheckmark(@NonNull Habit habit,
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.io;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -37,7 +36,6 @@ public abstract class AbstractImporter
|
||||
|
||||
public AbstractImporter(HabitList habits)
|
||||
{
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
this.habits = habits;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.io;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
@@ -50,8 +49,6 @@ public class HabitsCSVExporter
|
||||
@NonNull List<Habit> selectedHabits,
|
||||
@NonNull File dir)
|
||||
{
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
this.allHabits = allHabits;
|
||||
this.selectedHabits = selectedHabits;
|
||||
this.exportDirName = dir.getAbsolutePath() + "/";
|
||||
|
||||
@@ -24,12 +24,9 @@ import android.support.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.builder.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.memory.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* The thing that the user wants to track.
|
||||
*/
|
||||
@@ -73,8 +70,7 @@ public class Habit
|
||||
|
||||
private ModelObservable observable = new ModelObservable();
|
||||
|
||||
@Inject
|
||||
ModelFactory factory;
|
||||
private ModelFactory factory;
|
||||
|
||||
/**
|
||||
* Constructs a habit with the same attributes as the specified habit.
|
||||
@@ -104,9 +100,7 @@ public class Habit
|
||||
|
||||
private void buildLists()
|
||||
{
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
if(component == null) factory = new MemoryModelFactory();
|
||||
else component.inject(this);
|
||||
factory = HabitsApplication.getComponent().getModelFactory();
|
||||
|
||||
checkmarks = factory.buildCheckmarkList(this);
|
||||
streaks = factory.buildStreakList(this);
|
||||
|
||||
@@ -35,28 +35,26 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class PebbleReceiver extends PebbleDataReceiver
|
||||
{
|
||||
public static final UUID WATCHAPP_UUID =
|
||||
UUID.fromString("82629d99-8ea6-4631-a022-9ca77a12a058");
|
||||
|
||||
@Inject
|
||||
protected HabitList allHabits;
|
||||
private final HabitList allHabits;
|
||||
|
||||
@Inject
|
||||
protected CommandRunner commandRunner;
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
@Inject
|
||||
protected TaskRunner taskRunner;
|
||||
private final TaskRunner taskRunner;
|
||||
|
||||
protected HabitList filteredHabits;
|
||||
private final HabitList filteredHabits;
|
||||
|
||||
public PebbleReceiver()
|
||||
{
|
||||
super(WATCHAPP_UUID);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
commandRunner = component.getCommandRunner();
|
||||
taskRunner = component.getTaskRunner();
|
||||
allHabits = component.getHabitList();
|
||||
|
||||
HabitMatcher build = new HabitMatcherBuilder()
|
||||
.setArchivedAllowed(false)
|
||||
|
||||
@@ -25,16 +25,13 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ReceiverActions
|
||||
{
|
||||
@Inject
|
||||
CommandRunner commandRunner;
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
public ReceiverActions()
|
||||
{
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
commandRunner = HabitsApplication.getComponent().getCommandRunner();
|
||||
}
|
||||
|
||||
public void add_repetition(@NonNull Habit habit, long timestamp)
|
||||
@@ -53,7 +50,7 @@ public class ReceiverActions
|
||||
|
||||
public void toggle_repetition(@NonNull Habit habit, long timestamp)
|
||||
{
|
||||
commandRunner.execute(
|
||||
new ToggleRepetitionCommand(habit, timestamp), habit.getId());
|
||||
commandRunner.execute(new ToggleRepetitionCommand(habit, timestamp),
|
||||
habit.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* The Android BroadcastReceiver for Loop Habit Tracker.
|
||||
* <p>
|
||||
@@ -48,8 +46,8 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
public static final String ACTION_TOGGLE_REPETITION =
|
||||
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
|
||||
|
||||
@Inject
|
||||
HabitList habits;
|
||||
@NonNull
|
||||
private final HabitList habits;
|
||||
|
||||
@NonNull
|
||||
private final IntentParser parser;
|
||||
@@ -60,9 +58,10 @@ public class WidgetReceiver extends BroadcastReceiver
|
||||
public WidgetReceiver()
|
||||
{
|
||||
super();
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
habits = HabitsApplication.getComponent().getHabitList();
|
||||
parser = new IntentParser(habits);
|
||||
actions = new ReceiverActions();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,10 @@ public class BaseSystem
|
||||
public BaseSystem(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
habitList = component.getHabitList();
|
||||
reminderScheduler = component.getReminderScheduler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,8 +35,6 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
public abstract class BaseDialog extends AppCompatDialogFragment
|
||||
@@ -50,17 +48,13 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
||||
@Nullable
|
||||
protected BaseDialogHelper helper;
|
||||
|
||||
@Inject
|
||||
protected Preferences prefs;
|
||||
|
||||
@Inject
|
||||
protected CommandRunner commandRunner;
|
||||
|
||||
@Inject
|
||||
protected HabitList habitList;
|
||||
|
||||
@Inject
|
||||
protected DialogFactory dialogFactory;
|
||||
private DialogFactory dialogFactory;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@@ -68,7 +62,13 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
View view = inflater.inflate(R.layout.edit_habit, container, false);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
prefs = component.getPreferences();
|
||||
habitList = component.getHabitList();
|
||||
commandRunner = component.getCommandRunner();
|
||||
dialogFactory = component.getDialogFactory();
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
helper = new BaseDialogHelper(this, view);
|
||||
|
||||
@@ -26,15 +26,12 @@ import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* Activity that allows the user to see and modify the list of habits.
|
||||
*/
|
||||
public class ListHabitsActivity extends BaseActivity
|
||||
{
|
||||
@Inject
|
||||
HabitList habits;
|
||||
private HabitList habits;
|
||||
|
||||
private HabitCardListAdapter adapter;
|
||||
|
||||
@@ -54,7 +51,7 @@ public class ListHabitsActivity extends BaseActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
habits = HabitsApplication.getComponent().getHabitList();
|
||||
|
||||
int checkmarkCount = ListHabitsRootView.MAX_CHECKMARK_COUNT;
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ import org.isoron.uhabits.utils.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ListHabitsController
|
||||
implements HabitCardListController.HabitListener
|
||||
{
|
||||
@@ -51,17 +49,17 @@ public class ListHabitsController
|
||||
@NonNull
|
||||
private final HabitCardListAdapter adapter;
|
||||
|
||||
@Inject
|
||||
Preferences prefs;
|
||||
@NonNull
|
||||
private final Preferences prefs;
|
||||
|
||||
@Inject
|
||||
CommandRunner commandRunner;
|
||||
@NonNull
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
@Inject
|
||||
ReminderScheduler reminderScheduler;
|
||||
@NonNull
|
||||
private final ReminderScheduler reminderScheduler;
|
||||
|
||||
@Inject
|
||||
TaskRunner taskRuner;
|
||||
@NonNull
|
||||
private final TaskRunner taskRunner;
|
||||
|
||||
public ListHabitsController(@NonNull HabitList habitList,
|
||||
@NonNull ListHabitsScreen screen,
|
||||
@@ -72,7 +70,12 @@ public class ListHabitsController
|
||||
this.system = system;
|
||||
this.habitList = habitList;
|
||||
this.adapter = adapter;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
prefs = component.getPreferences();
|
||||
taskRunner = component.getTaskRunner();
|
||||
commandRunner = component.getCommandRunner();
|
||||
reminderScheduler = component.getReminderScheduler();
|
||||
}
|
||||
|
||||
public void onExportCSV()
|
||||
@@ -80,7 +83,7 @@ public class ListHabitsController
|
||||
List<Habit> selected = new LinkedList<>();
|
||||
for (Habit h : habitList) selected.add(h);
|
||||
|
||||
taskRuner.execute(new ExportCSVTask(habitList, selected, filename -> {
|
||||
taskRunner.execute(new ExportCSVTask(habitList, selected, filename -> {
|
||||
if (filename != null) screen.showSendFileScreen(filename);
|
||||
else screen.showMessage(R.string.could_not_export);
|
||||
}));
|
||||
@@ -88,7 +91,7 @@ public class ListHabitsController
|
||||
|
||||
public void onExportDB()
|
||||
{
|
||||
taskRuner.execute(new ExportDBTask(filename -> {
|
||||
taskRunner.execute(new ExportDBTask(filename -> {
|
||||
if (filename != null) screen.showSendFileScreen(filename);
|
||||
else screen.showMessage(R.string.could_not_export);
|
||||
}));
|
||||
@@ -103,12 +106,12 @@ public class ListHabitsController
|
||||
@Override
|
||||
public void onHabitReorder(@NonNull Habit from, @NonNull Habit to)
|
||||
{
|
||||
taskRuner.execute(() -> habitList.reorder(from, to));
|
||||
taskRunner.execute(() -> habitList.reorder(from, to));
|
||||
}
|
||||
|
||||
public void onImportData(@NonNull File file)
|
||||
{
|
||||
taskRuner.execute(new ImportDataTask(habitList, file, result -> {
|
||||
taskRunner.execute(new ImportDataTask(habitList, file, result -> {
|
||||
switch (result)
|
||||
{
|
||||
case ImportDataTask.SUCCESS:
|
||||
@@ -169,7 +172,7 @@ public class ListHabitsController
|
||||
if (prefs.isFirstRun()) onFirstRun();
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
taskRuner.execute(() -> reminderScheduler.schedule(habitList));
|
||||
taskRunner.execute(() -> reminderScheduler.schedule(habitList));
|
||||
HabitsApplication.getWidgetUpdater().updateWidgets();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ListHabitsMenu extends BaseMenu
|
||||
{
|
||||
@NonNull
|
||||
@@ -41,18 +39,18 @@ public class ListHabitsMenu extends BaseMenu
|
||||
|
||||
private boolean showCompleted;
|
||||
|
||||
@Inject
|
||||
Preferences preferences;
|
||||
private final Preferences preferences;
|
||||
|
||||
public ListHabitsMenu(@NonNull BaseActivity activity,
|
||||
@NonNull ListHabitsScreen screen,
|
||||
@NonNull HabitCardListAdapter adapter)
|
||||
{
|
||||
super(activity);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
this.screen = screen;
|
||||
this.adapter = adapter;
|
||||
|
||||
preferences = HabitsApplication.getComponent().getPreferences();
|
||||
|
||||
showCompleted = preferences.getShowCompleted();
|
||||
showArchived = preferences.getShowArchived();
|
||||
updateAdapterFilter();
|
||||
|
||||
@@ -35,28 +35,30 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ListHabitsScreen extends BaseScreen
|
||||
{
|
||||
@Nullable
|
||||
ListHabitsController controller;
|
||||
|
||||
@Inject
|
||||
protected DialogFactory dialogFactory;
|
||||
@NonNull
|
||||
private final DialogFactory dialogFactory;
|
||||
|
||||
@Inject
|
||||
protected IntentFactory intentFactory;
|
||||
@NonNull
|
||||
private final IntentFactory intentFactory;
|
||||
|
||||
@Inject
|
||||
protected DirFinder dirFinder;
|
||||
@NonNull
|
||||
private final DirFinder dirFinder;
|
||||
|
||||
public ListHabitsScreen(@NonNull BaseActivity activity,
|
||||
@NonNull ListHabitsRootView rootView)
|
||||
{
|
||||
super(activity);
|
||||
setRootView(rootView);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
dialogFactory = component.getDialogFactory();
|
||||
intentFactory = component.getIntentFactory();
|
||||
dirFinder = component.getDirFinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,8 +57,9 @@ public class ListHabitsSelectionMenu extends BaseSelectionMenu
|
||||
{
|
||||
this.habitList = habitList;
|
||||
this.screen = screen;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
this.listAdapter = listAdapter;
|
||||
|
||||
commandRunner = HabitsApplication.getComponent().getCommandRunner();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,15 +19,12 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list.controllers;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.HabitsApplication;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.list.views.CheckmarkButtonView;
|
||||
import org.isoron.uhabits.utils.Preferences;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
public class CheckmarkButtonController
|
||||
{
|
||||
@@ -37,8 +34,8 @@ public class CheckmarkButtonController
|
||||
@Nullable
|
||||
private Listener listener;
|
||||
|
||||
@Inject
|
||||
Preferences prefs;
|
||||
@NonNull
|
||||
private final Preferences prefs;
|
||||
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
@@ -49,7 +46,7 @@ public class CheckmarkButtonController
|
||||
{
|
||||
this.habit = habit;
|
||||
this.timestamp = timestamp;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
prefs = HabitsApplication.getComponent().getPreferences();
|
||||
}
|
||||
|
||||
public void onClick()
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.support.annotation.*;
|
||||
import android.support.v7.widget.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||
|
||||
@@ -57,8 +56,6 @@ public class HabitCardListAdapter
|
||||
this.selected = new LinkedList<>();
|
||||
this.observable = new ModelObservable();
|
||||
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
cache = new HabitCardListCache(allHabits);
|
||||
cache.setListener(this);
|
||||
cache.setCheckmarkCount(checkmarkCount);
|
||||
|
||||
@@ -19,13 +19,10 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.HabitsApplication;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.isoron.uhabits.utils.Preferences;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
/**
|
||||
* Provides a list of hints to be shown at the application startup, and takes
|
||||
@@ -33,8 +30,7 @@ import javax.inject.Inject;
|
||||
*/
|
||||
public class HintList
|
||||
{
|
||||
@Inject
|
||||
Preferences prefs;
|
||||
private final Preferences prefs;
|
||||
|
||||
@NonNull
|
||||
private final String[] hints;
|
||||
@@ -47,7 +43,7 @@ public class HintList
|
||||
public HintList(@NonNull String hints[])
|
||||
{
|
||||
this.hints = hints;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
prefs = HabitsApplication.getComponent().getPreferences();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,16 +29,13 @@ import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class CheckmarkPanelView extends LinearLayout
|
||||
{
|
||||
private static final int CHECKMARK_LEFT_TO_RIGHT = 0;
|
||||
|
||||
private static final int CHECKMARK_RIGHT_TO_LEFT = 1;
|
||||
|
||||
@Inject
|
||||
Preferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
private int checkmarkValues[];
|
||||
|
||||
@@ -144,7 +141,7 @@ public class CheckmarkPanelView extends LinearLayout
|
||||
private void init()
|
||||
{
|
||||
if (isInEditMode()) return;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
prefs = HabitsApplication.getComponent().getPreferences();
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,16 +30,13 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class HeaderView extends LinearLayout
|
||||
{
|
||||
private final Context context;
|
||||
|
||||
private int buttonCount;
|
||||
|
||||
@Inject
|
||||
Preferences prefs;
|
||||
private Preferences prefs;
|
||||
|
||||
public HeaderView(Context context, AttributeSet attrs)
|
||||
{
|
||||
@@ -49,10 +46,9 @@ public class HeaderView extends LinearLayout
|
||||
if (isInEditMode())
|
||||
{
|
||||
setButtonCount(5);
|
||||
return;
|
||||
}
|
||||
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
prefs = HabitsApplication.getComponent().getPreferences();
|
||||
}
|
||||
|
||||
public void setButtonCount(int buttonCount)
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* Activity that allows the user to see more information about a single habit.
|
||||
* <p>
|
||||
@@ -37,8 +35,7 @@ import javax.inject.*;
|
||||
*/
|
||||
public class ShowHabitActivity extends BaseActivity
|
||||
{
|
||||
@Inject
|
||||
HabitList habits;
|
||||
private HabitList habits;
|
||||
|
||||
private ShowHabitController controller;
|
||||
|
||||
@@ -52,7 +49,7 @@ public class ShowHabitActivity extends BaseActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
habits = HabitsApplication.getComponent().getHabitList();
|
||||
|
||||
Habit habit = getHabitFromIntent();
|
||||
rootView = new ShowHabitRootView(this, habit);
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ShowHabitController
|
||||
implements ShowHabitRootView.Controller, HistoryEditorDialog.Controller
|
||||
{
|
||||
@@ -37,13 +35,12 @@ public class ShowHabitController
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
|
||||
@Inject
|
||||
CommandRunner commandRunner;
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
public ShowHabitController(@NonNull ShowHabitScreen screen,
|
||||
@NonNull Habit habit)
|
||||
{
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
commandRunner = HabitsApplication.getComponent().getCommandRunner();
|
||||
this.screen = screen;
|
||||
this.habit = habit;
|
||||
}
|
||||
|
||||
@@ -27,22 +27,19 @@ import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||
import org.isoron.uhabits.ui.habits.edit.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ShowHabitScreen extends BaseScreen
|
||||
{
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
|
||||
@Inject
|
||||
protected DialogFactory dialogFactory;
|
||||
private DialogFactory dialogFactory;
|
||||
|
||||
public ShowHabitScreen(@NonNull BaseActivity activity,
|
||||
@NonNull Habit habit,
|
||||
ShowHabitRootView view)
|
||||
{
|
||||
super(activity);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
dialogFactory = HabitsApplication.getComponent().getDialogFactory();
|
||||
|
||||
this.habit = habit;
|
||||
setRootView(view);
|
||||
|
||||
@@ -29,16 +29,13 @@ import android.widget.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.os.Build.VERSION.*;
|
||||
import static android.os.Build.VERSION_CODES.*;
|
||||
import static android.view.View.MeasureSpec.*;
|
||||
|
||||
public abstract class BaseWidget
|
||||
{
|
||||
@Inject
|
||||
WidgetPreferences preferences;
|
||||
private final WidgetPreferences prefs;
|
||||
|
||||
private final int id;
|
||||
|
||||
@@ -52,13 +49,13 @@ public abstract class BaseWidget
|
||||
{
|
||||
this.id = id;
|
||||
this.context = context;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
prefs = HabitsApplication.getComponent().getWidgetPreferences();
|
||||
dimensions = new WidgetDimensions(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void delete()
|
||||
{
|
||||
preferences.removeWidget(id);
|
||||
prefs.removeWidget(id);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
@@ -31,18 +31,14 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.appwidget.AppWidgetManager.*;
|
||||
|
||||
public class HabitPickerDialog extends Activity
|
||||
implements AdapterView.OnItemClickListener
|
||||
{
|
||||
@Inject
|
||||
HabitList habitList;
|
||||
private HabitList habitList;
|
||||
|
||||
@Inject
|
||||
WidgetPreferences preferences;
|
||||
private WidgetPreferences preferences;
|
||||
|
||||
private Integer widgetId;
|
||||
|
||||
@@ -69,7 +65,10 @@ public class HabitPickerDialog extends Activity
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.widget_configure_activity);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
habitList = component.getHabitList();
|
||||
preferences = component.getWidgetPreferences();
|
||||
|
||||
Intent intent = getIntent();
|
||||
Bundle extras = intent.getExtras();
|
||||
|
||||
@@ -27,8 +27,6 @@ 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.
|
||||
@@ -38,8 +36,7 @@ import javax.inject.*;
|
||||
*/
|
||||
public class WidgetUpdater implements CommandRunner.Listener
|
||||
{
|
||||
@Inject
|
||||
CommandRunner commandRunner;
|
||||
private final CommandRunner commandRunner;
|
||||
|
||||
@NonNull
|
||||
private final Context context;
|
||||
@@ -47,7 +44,7 @@ public class WidgetUpdater implements CommandRunner.Listener
|
||||
public WidgetUpdater(@NonNull Context context)
|
||||
{
|
||||
this.context = context;
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
commandRunner = HabitsApplication.getComponent().getCommandRunner();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,19 +35,19 @@ import static org.isoron.uhabits.utils.DateUtils.*;
|
||||
@Singleton
|
||||
public class ReminderScheduler
|
||||
{
|
||||
@Inject
|
||||
protected PendingIntentFactory pendingIntentFactory;
|
||||
private final PendingIntentFactory pendingIntentFactory;
|
||||
|
||||
@Inject
|
||||
protected IntentScheduler intentScheduler;
|
||||
private final IntentScheduler intentScheduler;
|
||||
|
||||
@Inject
|
||||
HabitLogger logger;
|
||||
private final HabitLogger logger;
|
||||
|
||||
@Inject
|
||||
public ReminderScheduler()
|
||||
{
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
pendingIntentFactory = component.getPendingIntentFactory();
|
||||
intentScheduler = component.getIntentScheduler();
|
||||
logger = component.getHabitLogger();
|
||||
}
|
||||
|
||||
public void schedule(@NonNull Habit habit, @Nullable Long reminderTime)
|
||||
@@ -57,8 +57,8 @@ public class ReminderScheduler
|
||||
if (reminderTime == null) reminderTime = getReminderTime(reminder);
|
||||
long timestamp = getStartOfDay(toLocalTime(reminderTime));
|
||||
|
||||
PendingIntent intent = pendingIntentFactory.showReminder(habit,
|
||||
reminderTime, timestamp);
|
||||
PendingIntent intent =
|
||||
pendingIntentFactory.showReminder(habit, reminderTime, timestamp);
|
||||
intentScheduler.schedule(reminderTime, intent);
|
||||
logger.logReminderScheduled(habit, reminderTime);
|
||||
}
|
||||
@@ -79,8 +79,7 @@ public class ReminderScheduler
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
Long time = calendar.getTimeInMillis();
|
||||
|
||||
if (DateUtils.getLocalTime() > time)
|
||||
time += AlarmManager.INTERVAL_DAY;
|
||||
if (DateUtils.getLocalTime() > time) time += AlarmManager.INTERVAL_DAY;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
@@ -30,23 +30,21 @@ import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.os.Build.VERSION.*;
|
||||
import static android.os.Build.VERSION_CODES.*;
|
||||
import static org.isoron.uhabits.utils.WidgetUtils.*;
|
||||
|
||||
public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
{
|
||||
@Inject
|
||||
HabitList habits;
|
||||
private final HabitList habits;
|
||||
|
||||
@Inject
|
||||
WidgetPreferences widgetPrefs;
|
||||
private final WidgetPreferences widgetPrefs;
|
||||
|
||||
public BaseWidgetProvider()
|
||||
{
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
BaseComponent component = HabitsApplication.getComponent();
|
||||
habits = component.getHabitList();
|
||||
widgetPrefs = component.getWidgetPreferences();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +95,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
||||
if (widgetIds == null) throw new RuntimeException("widgetIds is null");
|
||||
context.setTheme(R.style.TransparentWidgetTheme);
|
||||
|
||||
new Handler().postDelayed(() ->{
|
||||
new Handler().postDelayed(() -> {
|
||||
for (int id : widgetIds)
|
||||
update(context, manager, id);
|
||||
}, 500);
|
||||
|
||||
Reference in New Issue
Block a user