Dagger: replace injects by getters

pull/151/head
Alinson S. Xavier 9 years ago
parent 15a4a2c002
commit 748cec06a8

@ -23,19 +23,9 @@ import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.intents.*; import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.io.*; import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.receivers.*;
import org.isoron.uhabits.tasks.*; import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.ui.common.dialogs.*; 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.utils.*;
import org.isoron.uhabits.widgets.*;
/** /**
* Base component for dependency injection. * Base component for dependency injection.
@ -44,81 +34,27 @@ public interface BaseComponent
{ {
CommandRunner getCommandRunner(); CommandRunner getCommandRunner();
HabitList getHabitList(); DialogFactory getDialogFactory();
IntentFactory getIntentFactory();
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); DirFinder getDirFinder();
void inject(HabitPickerDialog habitPickerDialog); HabitList getHabitList();
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); HabitLogger getHabitLogger();
void inject(PebbleReceiver receiver); IntentFactory getIntentFactory();
void inject(HeaderView headerView); IntentScheduler getIntentScheduler();
void inject(ReceiverActions receiverActions); ModelFactory getModelFactory();
void inject(ReminderScheduler reminderScheduler); PendingIntentFactory getPendingIntentFactory();
void inject(ListHabitsScreen listHabitsScreen); Preferences getPreferences();
void inject(ShowHabitScreen showHabitScreen); ReminderScheduler getReminderScheduler();
void inject(ConfirmDeleteDialog confirmDeleteDialog); TaskRunner getTaskRunner();
void inject(PendingIntentFactory pendingIntentFactory); WidgetPreferences getWidgetPreferences();
} }

@ -109,7 +109,6 @@ public class HabitsApplication extends Application
HabitsApplication.context = this; HabitsApplication.context = this;
HabitsApplication.application = this; HabitsApplication.application = this;
component = DaggerAndroidComponent.builder().build(); component = DaggerAndroidComponent.builder().build();
component.inject(this);
if (isTestMode()) if (isTestMode())
{ {

@ -36,7 +36,6 @@ public class ArchiveHabitsCommand extends Command
public ArchiveHabitsCommand(HabitList habitList, List<Habit> selectedHabits) public ArchiveHabitsCommand(HabitList habitList, List<Habit> selectedHabits)
{ {
this.habitList = habitList; this.habitList = habitList;
HabitsApplication.getComponent().inject(this);
this.selectedHabits = selectedHabits; this.selectedHabits = selectedHabits;
} }

@ -38,14 +38,13 @@ public class PendingIntentFactory
@NonNull @NonNull
private final Context context; private final Context context;
@Inject private IntentFactory intentFactory;
protected IntentFactory intentFactory;
@Inject @Inject
public PendingIntentFactory(@NonNull Context context) public PendingIntentFactory(@NonNull Context context)
{ {
this.context = context; this.context = context;
HabitsApplication.getComponent().inject(this); intentFactory = HabitsApplication.getComponent().getIntentFactory();
} }
public PendingIntent addCheckmark(@NonNull Habit habit, public PendingIntent addCheckmark(@NonNull Habit habit,

@ -21,7 +21,6 @@ package org.isoron.uhabits.io;
import android.support.annotation.*; import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import java.io.*; import java.io.*;
@ -37,7 +36,6 @@ public abstract class AbstractImporter
public AbstractImporter(HabitList habits) public AbstractImporter(HabitList habits)
{ {
HabitsApplication.getComponent().inject(this);
this.habits = habits; this.habits = habits;
} }

@ -21,7 +21,6 @@ package org.isoron.uhabits.io;
import android.support.annotation.*; import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
@ -50,8 +49,6 @@ public class HabitsCSVExporter
@NonNull List<Habit> selectedHabits, @NonNull List<Habit> selectedHabits,
@NonNull File dir) @NonNull File dir)
{ {
HabitsApplication.getComponent().inject(this);
this.allHabits = allHabits; this.allHabits = allHabits;
this.selectedHabits = selectedHabits; this.selectedHabits = selectedHabits;
this.exportDirName = dir.getAbsolutePath() + "/"; this.exportDirName = dir.getAbsolutePath() + "/";

@ -24,12 +24,9 @@ import android.support.annotation.*;
import org.apache.commons.lang3.builder.*; import org.apache.commons.lang3.builder.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.models.memory.*;
import java.util.*; import java.util.*;
import javax.inject.*;
/** /**
* The thing that the user wants to track. * The thing that the user wants to track.
*/ */
@ -73,8 +70,7 @@ public class Habit
private ModelObservable observable = new ModelObservable(); private ModelObservable observable = new ModelObservable();
@Inject private ModelFactory factory;
ModelFactory factory;
/** /**
* Constructs a habit with the same attributes as the specified habit. * Constructs a habit with the same attributes as the specified habit.
@ -104,9 +100,7 @@ public class Habit
private void buildLists() private void buildLists()
{ {
BaseComponent component = HabitsApplication.getComponent(); factory = HabitsApplication.getComponent().getModelFactory();
if(component == null) factory = new MemoryModelFactory();
else component.inject(this);
checkmarks = factory.buildCheckmarkList(this); checkmarks = factory.buildCheckmarkList(this);
streaks = factory.buildStreakList(this); streaks = factory.buildStreakList(this);

@ -35,28 +35,26 @@ import org.isoron.uhabits.utils.*;
import java.util.*; import java.util.*;
import javax.inject.*;
public class PebbleReceiver extends PebbleDataReceiver public class PebbleReceiver extends PebbleDataReceiver
{ {
public static final UUID WATCHAPP_UUID = public static final UUID WATCHAPP_UUID =
UUID.fromString("82629d99-8ea6-4631-a022-9ca77a12a058"); UUID.fromString("82629d99-8ea6-4631-a022-9ca77a12a058");
@Inject private final HabitList allHabits;
protected HabitList allHabits;
@Inject private final CommandRunner commandRunner;
protected CommandRunner commandRunner;
@Inject private final TaskRunner taskRunner;
protected TaskRunner taskRunner;
protected HabitList filteredHabits; private final HabitList filteredHabits;
public PebbleReceiver() public PebbleReceiver()
{ {
super(WATCHAPP_UUID); super(WATCHAPP_UUID);
HabitsApplication.getComponent().inject(this); BaseComponent component = HabitsApplication.getComponent();
commandRunner = component.getCommandRunner();
taskRunner = component.getTaskRunner();
allHabits = component.getHabitList();
HabitMatcher build = new HabitMatcherBuilder() HabitMatcher build = new HabitMatcherBuilder()
.setArchivedAllowed(false) .setArchivedAllowed(false)

@ -25,16 +25,13 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.commands.*; import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import javax.inject.*;
public class ReceiverActions public class ReceiverActions
{ {
@Inject private final CommandRunner commandRunner;
CommandRunner commandRunner;
public ReceiverActions() public ReceiverActions()
{ {
HabitsApplication.getComponent().inject(this); commandRunner = HabitsApplication.getComponent().getCommandRunner();
} }
public void add_repetition(@NonNull Habit habit, long timestamp) 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) public void toggle_repetition(@NonNull Habit habit, long timestamp)
{ {
commandRunner.execute( commandRunner.execute(new ToggleRepetitionCommand(habit, timestamp),
new ToggleRepetitionCommand(habit, timestamp), habit.getId()); habit.getId());
} }
} }

@ -27,8 +27,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.intents.*; import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import javax.inject.*;
/** /**
* The Android BroadcastReceiver for Loop Habit Tracker. * The Android BroadcastReceiver for Loop Habit Tracker.
* <p> * <p>
@ -48,8 +46,8 @@ public class WidgetReceiver extends BroadcastReceiver
public static final String ACTION_TOGGLE_REPETITION = public static final String ACTION_TOGGLE_REPETITION =
"org.isoron.uhabits.ACTION_TOGGLE_REPETITION"; "org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
@Inject @NonNull
HabitList habits; private final HabitList habits;
@NonNull @NonNull
private final IntentParser parser; private final IntentParser parser;
@ -60,9 +58,10 @@ public class WidgetReceiver extends BroadcastReceiver
public WidgetReceiver() public WidgetReceiver()
{ {
super(); super();
HabitsApplication.getComponent().inject(this); habits = HabitsApplication.getComponent().getHabitList();
parser = new IntentParser(habits); parser = new IntentParser(habits);
actions = new ReceiverActions(); actions = new ReceiverActions();
} }
@Override @Override

@ -55,7 +55,10 @@ public class BaseSystem
public BaseSystem(Context context) public BaseSystem(Context context)
{ {
this.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 java.util.*;
import javax.inject.*;
import butterknife.*; import butterknife.*;
public abstract class BaseDialog extends AppCompatDialogFragment public abstract class BaseDialog extends AppCompatDialogFragment
@ -50,17 +48,13 @@ public abstract class BaseDialog extends AppCompatDialogFragment
@Nullable @Nullable
protected BaseDialogHelper helper; protected BaseDialogHelper helper;
@Inject
protected Preferences prefs; protected Preferences prefs;
@Inject
protected CommandRunner commandRunner; protected CommandRunner commandRunner;
@Inject
protected HabitList habitList; protected HabitList habitList;
@Inject private DialogFactory dialogFactory;
protected DialogFactory dialogFactory;
@Override @Override
public View onCreateView(LayoutInflater inflater, public View onCreateView(LayoutInflater inflater,
@ -68,7 +62,13 @@ public abstract class BaseDialog extends AppCompatDialogFragment
Bundle savedInstanceState) Bundle savedInstanceState)
{ {
View view = inflater.inflate(R.layout.edit_habit, container, false); 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); ButterKnife.bind(this, view);
helper = new BaseDialogHelper(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.*;
import org.isoron.uhabits.ui.habits.list.model.*; import org.isoron.uhabits.ui.habits.list.model.*;
import javax.inject.*;
/** /**
* Activity that allows the user to see and modify the list of habits. * Activity that allows the user to see and modify the list of habits.
*/ */
public class ListHabitsActivity extends BaseActivity public class ListHabitsActivity extends BaseActivity
{ {
@Inject private HabitList habits;
HabitList habits;
private HabitCardListAdapter adapter; private HabitCardListAdapter adapter;
@ -54,7 +51,7 @@ public class ListHabitsActivity extends BaseActivity
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
HabitsApplication.getComponent().inject(this); habits = HabitsApplication.getComponent().getHabitList();
int checkmarkCount = ListHabitsRootView.MAX_CHECKMARK_COUNT; int checkmarkCount = ListHabitsRootView.MAX_CHECKMARK_COUNT;

@ -34,8 +34,6 @@ import org.isoron.uhabits.utils.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import javax.inject.*;
public class ListHabitsController public class ListHabitsController
implements HabitCardListController.HabitListener implements HabitCardListController.HabitListener
{ {
@ -51,17 +49,17 @@ public class ListHabitsController
@NonNull @NonNull
private final HabitCardListAdapter adapter; private final HabitCardListAdapter adapter;
@Inject @NonNull
Preferences prefs; private final Preferences prefs;
@Inject @NonNull
CommandRunner commandRunner; private final CommandRunner commandRunner;
@Inject @NonNull
ReminderScheduler reminderScheduler; private final ReminderScheduler reminderScheduler;
@Inject @NonNull
TaskRunner taskRuner; private final TaskRunner taskRunner;
public ListHabitsController(@NonNull HabitList habitList, public ListHabitsController(@NonNull HabitList habitList,
@NonNull ListHabitsScreen screen, @NonNull ListHabitsScreen screen,
@ -72,7 +70,12 @@ public class ListHabitsController
this.system = system; this.system = system;
this.habitList = habitList; this.habitList = habitList;
this.adapter = adapter; 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() public void onExportCSV()
@ -80,7 +83,7 @@ public class ListHabitsController
List<Habit> selected = new LinkedList<>(); List<Habit> selected = new LinkedList<>();
for (Habit h : habitList) selected.add(h); 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); if (filename != null) screen.showSendFileScreen(filename);
else screen.showMessage(R.string.could_not_export); else screen.showMessage(R.string.could_not_export);
})); }));
@ -88,7 +91,7 @@ public class ListHabitsController
public void onExportDB() public void onExportDB()
{ {
taskRuner.execute(new ExportDBTask(filename -> { taskRunner.execute(new ExportDBTask(filename -> {
if (filename != null) screen.showSendFileScreen(filename); if (filename != null) screen.showSendFileScreen(filename);
else screen.showMessage(R.string.could_not_export); else screen.showMessage(R.string.could_not_export);
})); }));
@ -103,12 +106,12 @@ public class ListHabitsController
@Override @Override
public void onHabitReorder(@NonNull Habit from, @NonNull Habit to) 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) public void onImportData(@NonNull File file)
{ {
taskRuner.execute(new ImportDataTask(habitList, file, result -> { taskRunner.execute(new ImportDataTask(habitList, file, result -> {
switch (result) switch (result)
{ {
case ImportDataTask.SUCCESS: case ImportDataTask.SUCCESS:
@ -169,7 +172,7 @@ public class ListHabitsController
if (prefs.isFirstRun()) onFirstRun(); if (prefs.isFirstRun()) onFirstRun();
new Handler().postDelayed(() -> { new Handler().postDelayed(() -> {
taskRuner.execute(() -> reminderScheduler.schedule(habitList)); taskRunner.execute(() -> reminderScheduler.schedule(habitList));
HabitsApplication.getWidgetUpdater().updateWidgets(); HabitsApplication.getWidgetUpdater().updateWidgets();
}, 1000); }, 1000);
} }

@ -28,8 +28,6 @@ import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.ui.habits.list.model.*; import org.isoron.uhabits.ui.habits.list.model.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import javax.inject.*;
public class ListHabitsMenu extends BaseMenu public class ListHabitsMenu extends BaseMenu
{ {
@NonNull @NonNull
@ -41,18 +39,18 @@ public class ListHabitsMenu extends BaseMenu
private boolean showCompleted; private boolean showCompleted;
@Inject private final Preferences preferences;
Preferences preferences;
public ListHabitsMenu(@NonNull BaseActivity activity, public ListHabitsMenu(@NonNull BaseActivity activity,
@NonNull ListHabitsScreen screen, @NonNull ListHabitsScreen screen,
@NonNull HabitCardListAdapter adapter) @NonNull HabitCardListAdapter adapter)
{ {
super(activity); super(activity);
HabitsApplication.getComponent().inject(this);
this.screen = screen; this.screen = screen;
this.adapter = adapter; this.adapter = adapter;
preferences = HabitsApplication.getComponent().getPreferences();
showCompleted = preferences.getShowCompleted(); showCompleted = preferences.getShowCompleted();
showArchived = preferences.getShowArchived(); showArchived = preferences.getShowArchived();
updateAdapterFilter(); updateAdapterFilter();

@ -35,28 +35,30 @@ import org.isoron.uhabits.utils.*;
import java.io.*; import java.io.*;
import javax.inject.*;
public class ListHabitsScreen extends BaseScreen public class ListHabitsScreen extends BaseScreen
{ {
@Nullable @Nullable
ListHabitsController controller; ListHabitsController controller;
@Inject @NonNull
protected DialogFactory dialogFactory; private final DialogFactory dialogFactory;
@Inject @NonNull
protected IntentFactory intentFactory; private final IntentFactory intentFactory;
@Inject @NonNull
protected DirFinder dirFinder; private final DirFinder dirFinder;
public ListHabitsScreen(@NonNull BaseActivity activity, public ListHabitsScreen(@NonNull BaseActivity activity,
@NonNull ListHabitsRootView rootView) @NonNull ListHabitsRootView rootView)
{ {
super(activity); super(activity);
setRootView(rootView); setRootView(rootView);
HabitsApplication.getComponent().inject(this);
BaseComponent component = HabitsApplication.getComponent();
dialogFactory = component.getDialogFactory();
intentFactory = component.getIntentFactory();
dirFinder = component.getDirFinder();
} }
@Override @Override

@ -57,8 +57,9 @@ public class ListHabitsSelectionMenu extends BaseSelectionMenu
{ {
this.habitList = habitList; this.habitList = habitList;
this.screen = screen; this.screen = screen;
HabitsApplication.getComponent().inject(this);
this.listAdapter = listAdapter; this.listAdapter = listAdapter;
commandRunner = HabitsApplication.getComponent().getCommandRunner();
} }
@Override @Override

@ -19,15 +19,12 @@
package org.isoron.uhabits.ui.habits.list.controllers; package org.isoron.uhabits.ui.habits.list.controllers;
import android.support.annotation.NonNull; import android.support.annotation.*;
import android.support.annotation.Nullable;
import org.isoron.uhabits.HabitsApplication; import org.isoron.uhabits.*;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.habits.list.views.CheckmarkButtonView; import org.isoron.uhabits.ui.habits.list.views.*;
import org.isoron.uhabits.utils.Preferences; import org.isoron.uhabits.utils.*;
import javax.inject.Inject;
public class CheckmarkButtonController public class CheckmarkButtonController
{ {
@ -37,8 +34,8 @@ public class CheckmarkButtonController
@Nullable @Nullable
private Listener listener; private Listener listener;
@Inject @NonNull
Preferences prefs; private final Preferences prefs;
@NonNull @NonNull
private Habit habit; private Habit habit;
@ -49,7 +46,7 @@ public class CheckmarkButtonController
{ {
this.habit = habit; this.habit = habit;
this.timestamp = timestamp; this.timestamp = timestamp;
HabitsApplication.getComponent().inject(this); prefs = HabitsApplication.getComponent().getPreferences();
} }
public void onClick() public void onClick()

@ -23,7 +23,6 @@ import android.support.annotation.*;
import android.support.v7.widget.*; import android.support.v7.widget.*;
import android.view.*; import android.view.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.habits.list.views.*; import org.isoron.uhabits.ui.habits.list.views.*;
@ -57,8 +56,6 @@ public class HabitCardListAdapter
this.selected = new LinkedList<>(); this.selected = new LinkedList<>();
this.observable = new ModelObservable(); this.observable = new ModelObservable();
HabitsApplication.getComponent().inject(this);
cache = new HabitCardListCache(allHabits); cache = new HabitCardListCache(allHabits);
cache.setListener(this); cache.setListener(this);
cache.setCheckmarkCount(checkmarkCount); cache.setCheckmarkCount(checkmarkCount);

@ -19,13 +19,10 @@
package org.isoron.uhabits.ui.habits.list.model; 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.*;
import org.isoron.uhabits.utils.DateUtils; import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.utils.Preferences;
import javax.inject.Inject;
/** /**
* Provides a list of hints to be shown at the application startup, and takes * 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 public class HintList
{ {
@Inject private final Preferences prefs;
Preferences prefs;
@NonNull @NonNull
private final String[] hints; private final String[] hints;
@ -47,7 +43,7 @@ public class HintList
public HintList(@NonNull String hints[]) public HintList(@NonNull String hints[])
{ {
this.hints = 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.ui.habits.list.controllers.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import javax.inject.*;
public class CheckmarkPanelView extends LinearLayout public class CheckmarkPanelView extends LinearLayout
{ {
private static final int CHECKMARK_LEFT_TO_RIGHT = 0; private static final int CHECKMARK_LEFT_TO_RIGHT = 0;
private static final int CHECKMARK_RIGHT_TO_LEFT = 1; private static final int CHECKMARK_RIGHT_TO_LEFT = 1;
@Inject private Preferences prefs;
Preferences prefs;
private int checkmarkValues[]; private int checkmarkValues[];
@ -144,7 +141,7 @@ public class CheckmarkPanelView extends LinearLayout
private void init() private void init()
{ {
if (isInEditMode()) return; if (isInEditMode()) return;
HabitsApplication.getComponent().inject(this); prefs = HabitsApplication.getComponent().getPreferences();
setWillNotDraw(false); setWillNotDraw(false);
} }

@ -30,16 +30,13 @@ import org.isoron.uhabits.utils.*;
import java.util.*; import java.util.*;
import javax.inject.*;
public class HeaderView extends LinearLayout public class HeaderView extends LinearLayout
{ {
private final Context context; private final Context context;
private int buttonCount; private int buttonCount;
@Inject private Preferences prefs;
Preferences prefs;
public HeaderView(Context context, AttributeSet attrs) public HeaderView(Context context, AttributeSet attrs)
{ {
@ -49,10 +46,9 @@ public class HeaderView extends LinearLayout
if (isInEditMode()) if (isInEditMode())
{ {
setButtonCount(5); setButtonCount(5);
return;
} }
HabitsApplication.getComponent().inject(this); prefs = HabitsApplication.getComponent().getPreferences();
} }
public void setButtonCount(int buttonCount) public void setButtonCount(int buttonCount)

@ -28,8 +28,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.*; import org.isoron.uhabits.ui.*;
import javax.inject.*;
/** /**
* Activity that allows the user to see more information about a single habit. * Activity that allows the user to see more information about a single habit.
* <p> * <p>
@ -37,8 +35,7 @@ import javax.inject.*;
*/ */
public class ShowHabitActivity extends BaseActivity public class ShowHabitActivity extends BaseActivity
{ {
@Inject private HabitList habits;
HabitList habits;
private ShowHabitController controller; private ShowHabitController controller;
@ -52,7 +49,7 @@ public class ShowHabitActivity extends BaseActivity
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
HabitsApplication.getComponent().inject(this); habits = HabitsApplication.getComponent().getHabitList();
Habit habit = getHabitFromIntent(); Habit habit = getHabitFromIntent();
rootView = new ShowHabitRootView(this, habit); rootView = new ShowHabitRootView(this, habit);

@ -26,8 +26,6 @@ import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.common.dialogs.*; import org.isoron.uhabits.ui.common.dialogs.*;
import javax.inject.*;
public class ShowHabitController public class ShowHabitController
implements ShowHabitRootView.Controller, HistoryEditorDialog.Controller implements ShowHabitRootView.Controller, HistoryEditorDialog.Controller
{ {
@ -37,13 +35,12 @@ public class ShowHabitController
@NonNull @NonNull
private final Habit habit; private final Habit habit;
@Inject private final CommandRunner commandRunner;
CommandRunner commandRunner;
public ShowHabitController(@NonNull ShowHabitScreen screen, public ShowHabitController(@NonNull ShowHabitScreen screen,
@NonNull Habit habit) @NonNull Habit habit)
{ {
HabitsApplication.getComponent().inject(this); commandRunner = HabitsApplication.getComponent().getCommandRunner();
this.screen = screen; this.screen = screen;
this.habit = habit; this.habit = habit;
} }

@ -27,22 +27,19 @@ import org.isoron.uhabits.ui.*;
import org.isoron.uhabits.ui.common.dialogs.*; import org.isoron.uhabits.ui.common.dialogs.*;
import org.isoron.uhabits.ui.habits.edit.*; import org.isoron.uhabits.ui.habits.edit.*;
import javax.inject.*;
public class ShowHabitScreen extends BaseScreen public class ShowHabitScreen extends BaseScreen
{ {
@NonNull @NonNull
private final Habit habit; private final Habit habit;
@Inject private DialogFactory dialogFactory;
protected DialogFactory dialogFactory;
public ShowHabitScreen(@NonNull BaseActivity activity, public ShowHabitScreen(@NonNull BaseActivity activity,
@NonNull Habit habit, @NonNull Habit habit,
ShowHabitRootView view) ShowHabitRootView view)
{ {
super(activity); super(activity);
HabitsApplication.getComponent().inject(this); dialogFactory = HabitsApplication.getComponent().getDialogFactory();
this.habit = habit; this.habit = habit;
setRootView(view); setRootView(view);

@ -29,16 +29,13 @@ import android.widget.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import javax.inject.*;
import static android.os.Build.VERSION.*; import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*; import static android.os.Build.VERSION_CODES.*;
import static android.view.View.MeasureSpec.*; import static android.view.View.MeasureSpec.*;
public abstract class BaseWidget public abstract class BaseWidget
{ {
@Inject private final WidgetPreferences prefs;
WidgetPreferences preferences;
private final int id; private final int id;
@ -52,13 +49,13 @@ public abstract class BaseWidget
{ {
this.id = id; this.id = id;
this.context = context; this.context = context;
HabitsApplication.getComponent().inject(this); prefs = HabitsApplication.getComponent().getWidgetPreferences();
dimensions = new WidgetDimensions(0, 0, 0, 0); dimensions = new WidgetDimensions(0, 0, 0, 0);
} }
public void delete() public void delete()
{ {
preferences.removeWidget(id); prefs.removeWidget(id);
} }
@NonNull @NonNull

@ -31,18 +31,14 @@ import org.isoron.uhabits.utils.*;
import java.util.*; import java.util.*;
import javax.inject.*;
import static android.appwidget.AppWidgetManager.*; import static android.appwidget.AppWidgetManager.*;
public class HabitPickerDialog extends Activity public class HabitPickerDialog extends Activity
implements AdapterView.OnItemClickListener implements AdapterView.OnItemClickListener
{ {
@Inject private HabitList habitList;
HabitList habitList;
@Inject private WidgetPreferences preferences;
WidgetPreferences preferences;
private Integer widgetId; private Integer widgetId;
@ -69,7 +65,10 @@ public class HabitPickerDialog extends Activity
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.widget_configure_activity); setContentView(R.layout.widget_configure_activity);
HabitsApplication.getComponent().inject(this);
BaseComponent component = HabitsApplication.getComponent();
habitList = component.getHabitList();
preferences = component.getWidgetPreferences();
Intent intent = getIntent(); Intent intent = getIntent();
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();

@ -27,8 +27,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.commands.*; import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.widgets.*; import org.isoron.uhabits.widgets.*;
import javax.inject.*;
/** /**
* A WidgetUpdater listens to the commands being executed by the application and * A WidgetUpdater listens to the commands being executed by the application and
* updates the home-screen widgets accordingly. * updates the home-screen widgets accordingly.
@ -38,8 +36,7 @@ import javax.inject.*;
*/ */
public class WidgetUpdater implements CommandRunner.Listener public class WidgetUpdater implements CommandRunner.Listener
{ {
@Inject private final CommandRunner commandRunner;
CommandRunner commandRunner;
@NonNull @NonNull
private final Context context; private final Context context;
@ -47,7 +44,7 @@ public class WidgetUpdater implements CommandRunner.Listener
public WidgetUpdater(@NonNull Context context) public WidgetUpdater(@NonNull Context context)
{ {
this.context = context; this.context = context;
HabitsApplication.getComponent().inject(this); commandRunner = HabitsApplication.getComponent().getCommandRunner();
} }
@Override @Override

@ -35,19 +35,19 @@ import static org.isoron.uhabits.utils.DateUtils.*;
@Singleton @Singleton
public class ReminderScheduler public class ReminderScheduler
{ {
@Inject private final PendingIntentFactory pendingIntentFactory;
protected PendingIntentFactory pendingIntentFactory;
@Inject private final IntentScheduler intentScheduler;
protected IntentScheduler intentScheduler;
@Inject private final HabitLogger logger;
HabitLogger logger;
@Inject @Inject
public ReminderScheduler() 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) public void schedule(@NonNull Habit habit, @Nullable Long reminderTime)
@ -57,8 +57,8 @@ public class ReminderScheduler
if (reminderTime == null) reminderTime = getReminderTime(reminder); if (reminderTime == null) reminderTime = getReminderTime(reminder);
long timestamp = getStartOfDay(toLocalTime(reminderTime)); long timestamp = getStartOfDay(toLocalTime(reminderTime));
PendingIntent intent = pendingIntentFactory.showReminder(habit, PendingIntent intent =
reminderTime, timestamp); pendingIntentFactory.showReminder(habit, reminderTime, timestamp);
intentScheduler.schedule(reminderTime, intent); intentScheduler.schedule(reminderTime, intent);
logger.logReminderScheduled(habit, reminderTime); logger.logReminderScheduled(habit, reminderTime);
} }
@ -79,8 +79,7 @@ public class ReminderScheduler
calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.SECOND, 0);
Long time = calendar.getTimeInMillis(); Long time = calendar.getTimeInMillis();
if (DateUtils.getLocalTime() > time) if (DateUtils.getLocalTime() > time) time += AlarmManager.INTERVAL_DAY;
time += AlarmManager.INTERVAL_DAY;
return time; return time;
} }

@ -30,23 +30,21 @@ import org.isoron.uhabits.models.*;
import org.isoron.uhabits.ui.widgets.*; import org.isoron.uhabits.ui.widgets.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import javax.inject.*;
import static android.os.Build.VERSION.*; import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*; import static android.os.Build.VERSION_CODES.*;
import static org.isoron.uhabits.utils.WidgetUtils.*; import static org.isoron.uhabits.utils.WidgetUtils.*;
public abstract class BaseWidgetProvider extends AppWidgetProvider public abstract class BaseWidgetProvider extends AppWidgetProvider
{ {
@Inject private final HabitList habits;
HabitList habits;
@Inject private final WidgetPreferences widgetPrefs;
WidgetPreferences widgetPrefs;
public BaseWidgetProvider() public BaseWidgetProvider()
{ {
HabitsApplication.getComponent().inject(this); BaseComponent component = HabitsApplication.getComponent();
habits = component.getHabitList();
widgetPrefs = component.getWidgetPreferences();
} }
@Override @Override
@ -97,7 +95,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
if (widgetIds == null) throw new RuntimeException("widgetIds is null"); if (widgetIds == null) throw new RuntimeException("widgetIds is null");
context.setTheme(R.style.TransparentWidgetTheme); context.setTheme(R.style.TransparentWidgetTheme);
new Handler().postDelayed(() ->{ new Handler().postDelayed(() -> {
for (int id : widgetIds) for (int id : widgetIds)
update(context, manager, id); update(context, manager, id);
}, 500); }, 500);

Loading…
Cancel
Save