mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Remove DialogFactory
This commit is contained in:
@@ -29,5 +29,5 @@ import dagger.*;
|
|||||||
dependencies = { AppComponent.class })
|
dependencies = { AppComponent.class })
|
||||||
public interface ActivityComponent
|
public interface ActivityComponent
|
||||||
{
|
{
|
||||||
DialogFactory getDialogFactory();
|
ColorPickerDialogFactory getColorPickerDialogFactory();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.activities.common.dialogs;
|
package org.isoron.uhabits.activities.common.dialogs;
|
||||||
|
|
||||||
import android.content.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,20 +26,6 @@ import org.isoron.uhabits.utils.*;
|
|||||||
*/
|
*/
|
||||||
public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
|
public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
|
||||||
{
|
{
|
||||||
public static ColorPickerDialog newInstance(Context context,
|
|
||||||
int paletteColor)
|
|
||||||
{
|
|
||||||
ColorPickerDialog dialog = new ColorPickerDialog();
|
|
||||||
StyledResources res = new StyledResources(context);
|
|
||||||
|
|
||||||
int color = ColorUtils.getColor(context, paletteColor);
|
|
||||||
|
|
||||||
dialog.initialize(R.string.color_picker_default_title, res.getPalette(),
|
|
||||||
color, 4, com.android.colorpicker.ColorPickerDialog.SIZE_SMALL);
|
|
||||||
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setListener(OnColorSelectedListener listener)
|
public void setListener(OnColorSelectedListener listener)
|
||||||
{
|
{
|
||||||
super.setOnColorSelectedListener(c -> {
|
super.setOnColorSelectedListener(c -> {
|
||||||
|
|||||||
@@ -20,33 +20,33 @@
|
|||||||
package org.isoron.uhabits.activities.common.dialogs;
|
package org.isoron.uhabits.activities.common.dialogs;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.support.annotation.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.activities.*;
|
import org.isoron.uhabits.activities.*;
|
||||||
import org.isoron.uhabits.activities.habits.edit.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class DialogFactory
|
@ActivityScope
|
||||||
|
public class ColorPickerDialogFactory
|
||||||
{
|
{
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DialogFactory(@ActivityContext Context context)
|
public ColorPickerDialogFactory(@ActivityContext Context context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
public ColorPickerDialog create(int paletteColor)
|
||||||
public ColorPickerDialog buildColorPicker(int paletteColor)
|
|
||||||
{
|
{
|
||||||
return ColorPickerDialog.newInstance(context, paletteColor);
|
ColorPickerDialog dialog = new ColorPickerDialog();
|
||||||
}
|
StyledResources res = new StyledResources(context);
|
||||||
|
int color = ColorUtils.getColor(context, paletteColor);
|
||||||
|
|
||||||
@NonNull
|
dialog.initialize(R.string.color_picker_default_title, res.getPalette(),
|
||||||
public EditHabitDialog buildEditHabitDialog(Habit habit)
|
color, 4, com.android.colorpicker.ColorPickerDialog.SIZE_SMALL);
|
||||||
{
|
|
||||||
return EditHabitDialog.newInstance(habit);
|
return dialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,12 +55,22 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
|||||||
|
|
||||||
protected HabitList habitList;
|
protected HabitList habitList;
|
||||||
|
|
||||||
private DialogFactory dialogFactory;
|
protected AppComponent appComponent;
|
||||||
|
|
||||||
protected AppComponent component;
|
|
||||||
|
|
||||||
protected ModelFactory modelFactory;
|
protected ModelFactory modelFactory;
|
||||||
|
|
||||||
|
private ColorPickerDialogFactory colorPickerDialogFactory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
BaseActivity activity = (BaseActivity) getActivity();
|
||||||
|
colorPickerDialogFactory =
|
||||||
|
activity.getComponent().getColorPickerDialogFactory();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
ViewGroup container,
|
ViewGroup container,
|
||||||
@@ -68,12 +78,13 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
|||||||
{
|
{
|
||||||
View view = inflater.inflate(R.layout.edit_habit, container, false);
|
View view = inflater.inflate(R.layout.edit_habit, container, false);
|
||||||
|
|
||||||
HabitsApplication app = (HabitsApplication) getContext().getApplicationContext();
|
HabitsApplication app =
|
||||||
component = app.getComponent();
|
(HabitsApplication) getContext().getApplicationContext();
|
||||||
prefs = component.getPreferences();
|
|
||||||
habitList = component.getHabitList();
|
prefs = app.getComponent().getPreferences();
|
||||||
commandRunner = component.getCommandRunner();
|
habitList = app.getComponent().getHabitList();
|
||||||
modelFactory = component.getModelFactory();
|
commandRunner = app.getComponent().getCommandRunner();
|
||||||
|
modelFactory = app.getComponent().getModelFactory();
|
||||||
|
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
@@ -85,16 +96,6 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState)
|
|
||||||
{
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
|
|
||||||
BaseActivity baseActivity = (BaseActivity) getActivity();
|
|
||||||
ActivityComponent component = baseActivity.getComponent();
|
|
||||||
dialogFactory = component.getDialogFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnItemSelected(R.id.sFrequency)
|
@OnItemSelected(R.id.sFrequency)
|
||||||
public void onFrequencySelected(int position)
|
public void onFrequencySelected(int position)
|
||||||
{
|
{
|
||||||
@@ -196,7 +197,7 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
|||||||
void showColorPicker()
|
void showColorPicker()
|
||||||
{
|
{
|
||||||
int color = modifiedHabit.getColor();
|
int color = modifiedHabit.getColor();
|
||||||
ColorPickerDialog picker = dialogFactory.buildColorPicker(color);
|
ColorPickerDialog picker = colorPickerDialogFactory.create(color);
|
||||||
|
|
||||||
picker.setListener(c -> {
|
picker.setListener(c -> {
|
||||||
prefs.setDefaultHabitColor(c);
|
prefs.setDefaultHabitColor(c);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class CreateHabitDialog extends BaseDialog
|
|||||||
@Override
|
@Override
|
||||||
protected void saveHabit()
|
protected void saveHabit()
|
||||||
{
|
{
|
||||||
Command command = component
|
Command command = appComponent
|
||||||
.getCreateHabitCommandFactory()
|
.getCreateHabitCommandFactory()
|
||||||
.create(habitList, modifiedHabit);
|
.create(habitList, modifiedHabit);
|
||||||
commandRunner.execute(command, null);
|
commandRunner.execute(command, null);
|
||||||
|
|||||||
@@ -19,26 +19,11 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.edit;
|
package org.isoron.uhabits.activities.habits.edit;
|
||||||
|
|
||||||
import android.os.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.commands.*;
|
import org.isoron.uhabits.commands.*;
|
||||||
import org.isoron.uhabits.models.*;
|
|
||||||
|
|
||||||
public class EditHabitDialog extends BaseDialog
|
public class EditHabitDialog extends BaseDialog
|
||||||
{
|
{
|
||||||
public static EditHabitDialog newInstance(Habit habit)
|
|
||||||
{
|
|
||||||
if (habit.getId() == null)
|
|
||||||
throw new IllegalArgumentException("habit not saved");
|
|
||||||
|
|
||||||
EditHabitDialog frag = new EditHabitDialog();
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putLong("habitId", habit.getId());
|
|
||||||
frag.setArguments(args);
|
|
||||||
return frag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getTitle()
|
protected int getTitle()
|
||||||
{
|
{
|
||||||
@@ -60,7 +45,7 @@ public class EditHabitDialog extends BaseDialog
|
|||||||
@Override
|
@Override
|
||||||
protected void saveHabit()
|
protected void saveHabit()
|
||||||
{
|
{
|
||||||
Command command = component.getEditHabitCommandFactory().
|
Command command = appComponent.getEditHabitCommandFactory().
|
||||||
create(habitList, originalHabit, modifiedHabit);
|
create(habitList, originalHabit, modifiedHabit);
|
||||||
commandRunner.execute(command, originalHabit.getId());
|
commandRunner.execute(command, originalHabit.getId());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.activities.habits.edit;
|
||||||
|
|
||||||
|
import android.os.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
|
||||||
|
import javax.inject.*;
|
||||||
|
|
||||||
|
public class EditHabitDialogFactory
|
||||||
|
{
|
||||||
|
@Inject
|
||||||
|
public EditHabitDialogFactory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditHabitDialog create(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
if (habit.getId() == null)
|
||||||
|
throw new IllegalArgumentException("habit not saved");
|
||||||
|
|
||||||
|
EditHabitDialog dialog = new EditHabitDialog();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLong("habitId", habit.getId());
|
||||||
|
dialog.setArguments(args);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ import dagger.*;
|
|||||||
@ActivityScope
|
@ActivityScope
|
||||||
@Component(modules = { ActivityModule.class },
|
@Component(modules = { ActivityModule.class },
|
||||||
dependencies = { AppComponent.class })
|
dependencies = { AppComponent.class })
|
||||||
public interface ListHabitsComponent
|
public interface ListHabitsComponent extends ActivityComponent
|
||||||
{
|
{
|
||||||
CheckmarkButtonControllerFactory getCheckmarkButtonControllerFactory();
|
CheckmarkButtonControllerFactory getCheckmarkButtonControllerFactory();
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ import android.os.*;
|
|||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.commands.*;
|
|
||||||
import org.isoron.uhabits.intents.*;
|
|
||||||
import org.isoron.uhabits.io.*;
|
|
||||||
import org.isoron.uhabits.models.*;
|
|
||||||
import org.isoron.uhabits.activities.*;
|
import org.isoron.uhabits.activities.*;
|
||||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||||
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
|
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
|
||||||
import org.isoron.uhabits.activities.habits.edit.*;
|
import org.isoron.uhabits.activities.habits.edit.*;
|
||||||
|
import org.isoron.uhabits.commands.*;
|
||||||
|
import org.isoron.uhabits.intents.*;
|
||||||
|
import org.isoron.uhabits.io.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -53,9 +53,6 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
@Nullable
|
@Nullable
|
||||||
private ListHabitsController controller;
|
private ListHabitsController controller;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final DialogFactory dialogFactory;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final IntentFactory intentFactory;
|
private final IntentFactory intentFactory;
|
||||||
|
|
||||||
@@ -74,23 +71,31 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final FilePickerDialogFactory filePickerDialogFactory;
|
private final FilePickerDialogFactory filePickerDialogFactory;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final ColorPickerDialogFactory colorPickerFactory;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private EditHabitDialogFactory editHabitDialogFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ListHabitsScreen(@NonNull BaseActivity activity,
|
public ListHabitsScreen(@NonNull BaseActivity activity,
|
||||||
@NonNull CommandRunner commandRunner,
|
@NonNull CommandRunner commandRunner,
|
||||||
@NonNull DirFinder dirFinder,
|
@NonNull DirFinder dirFinder,
|
||||||
@NonNull DialogFactory dialogFactory,
|
|
||||||
@NonNull ListHabitsRootView rootView,
|
@NonNull ListHabitsRootView rootView,
|
||||||
@NonNull IntentFactory intentFactory,
|
@NonNull IntentFactory intentFactory,
|
||||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||||
@NonNull CreateHabitDialogFactory createHabitDialogFactory,
|
@NonNull CreateHabitDialogFactory createHabitDialogFactory,
|
||||||
@NonNull FilePickerDialogFactory filePickerDialogFactory)
|
@NonNull FilePickerDialogFactory filePickerDialogFactory,
|
||||||
|
@NonNull ColorPickerDialogFactory colorPickerFactory,
|
||||||
|
@NonNull EditHabitDialogFactory editHabitDialogFactory)
|
||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
setRootView(rootView);
|
setRootView(rootView);
|
||||||
|
this.editHabitDialogFactory = editHabitDialogFactory;
|
||||||
|
this.colorPickerFactory = colorPickerFactory;
|
||||||
this.commandRunner = commandRunner;
|
this.commandRunner = commandRunner;
|
||||||
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
||||||
this.createHabitDialogFactory = createHabitDialogFactory;
|
this.createHabitDialogFactory = createHabitDialogFactory;
|
||||||
this.dialogFactory = dialogFactory;
|
|
||||||
this.dirFinder = dirFinder;
|
this.dirFinder = dirFinder;
|
||||||
this.filePickerDialogFactory = filePickerDialogFactory;
|
this.filePickerDialogFactory = filePickerDialogFactory;
|
||||||
this.intentFactory = intentFactory;
|
this.intentFactory = intentFactory;
|
||||||
@@ -160,8 +165,7 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
public void showColorPicker(@NonNull Habit habit,
|
public void showColorPicker(@NonNull Habit habit,
|
||||||
@NonNull OnColorSelectedListener callback)
|
@NonNull OnColorSelectedListener callback)
|
||||||
{
|
{
|
||||||
ColorPickerDialog picker =
|
ColorPickerDialog picker = colorPickerFactory.create(habit.getColor());
|
||||||
dialogFactory.buildColorPicker(habit.getColor());
|
|
||||||
picker.setListener(callback);
|
picker.setListener(callback);
|
||||||
activity.showDialog(picker, "picker");
|
activity.showDialog(picker, "picker");
|
||||||
}
|
}
|
||||||
@@ -178,7 +182,7 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
|
|
||||||
public void showEditHabitScreen(Habit habit)
|
public void showEditHabitScreen(Habit habit)
|
||||||
{
|
{
|
||||||
EditHabitDialog dialog = dialogFactory.buildEditHabitDialog(habit);
|
EditHabitDialog dialog = editHabitDialogFactory.create(habit);
|
||||||
activity.showDialog(dialog, "editHabit");
|
activity.showDialog(dialog, "editHabit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,21 +34,22 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final Habit habit;
|
private final Habit habit;
|
||||||
|
|
||||||
private DialogFactory dialogFactory;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ShowHabitController controller;
|
private ShowHabitController controller;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final EditHabitDialogFactory editHabitDialogFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ShowHabitScreen(@NonNull BaseActivity activity,
|
public ShowHabitScreen(@NonNull BaseActivity activity,
|
||||||
@NonNull Habit habit,
|
@NonNull Habit habit,
|
||||||
@NonNull ShowHabitRootView view,
|
@NonNull ShowHabitRootView view,
|
||||||
@NonNull DialogFactory dialogFactory)
|
@NonNull EditHabitDialogFactory editHabitDialogFactory)
|
||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
setRootView(view);
|
setRootView(view);
|
||||||
|
this.editHabitDialogFactory = editHabitDialogFactory;
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.dialogFactory = dialogFactory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setController(@NonNull ShowHabitController controller)
|
public void setController(@NonNull ShowHabitController controller)
|
||||||
@@ -70,7 +71,7 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
|
|
||||||
public void showEditHabitDialog()
|
public void showEditHabitDialog()
|
||||||
{
|
{
|
||||||
EditHabitDialog dialog = dialogFactory.buildEditHabitDialog(habit);
|
EditHabitDialog dialog = editHabitDialogFactory.create(habit);
|
||||||
activity.showDialog(dialog, "editHabit");
|
activity.showDialog(dialog, "editHabit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ import android.content.*;
|
|||||||
import android.support.v7.app.*;
|
import android.support.v7.app.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.commands.*;
|
|
||||||
import org.isoron.uhabits.intents.*;
|
|
||||||
import org.isoron.uhabits.io.*;
|
|
||||||
import org.isoron.uhabits.models.*;
|
|
||||||
import org.isoron.uhabits.activities.*;
|
import org.isoron.uhabits.activities.*;
|
||||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||||
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
|
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
|
||||||
import org.isoron.uhabits.activities.habits.edit.*;
|
import org.isoron.uhabits.activities.habits.edit.*;
|
||||||
|
import org.isoron.uhabits.commands.*;
|
||||||
|
import org.isoron.uhabits.intents.*;
|
||||||
|
import org.isoron.uhabits.io.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.junit.runner.*;
|
import org.junit.runner.*;
|
||||||
import org.junit.runners.*;
|
import org.junit.runners.*;
|
||||||
@@ -66,12 +66,14 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
|
|
||||||
private IntentFactory intentFactory;
|
private IntentFactory intentFactory;
|
||||||
|
|
||||||
private DialogFactory dialogFactory;
|
|
||||||
|
|
||||||
private DirFinder dirFinder;
|
private DirFinder dirFinder;
|
||||||
|
|
||||||
private CommandRunner commandRunner;
|
private CommandRunner commandRunner;
|
||||||
|
|
||||||
|
private ColorPickerDialogFactory colorPickerDialogFactory;
|
||||||
|
|
||||||
|
private EditHabitDialogFactory editHabitDialogFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp()
|
public void setUp()
|
||||||
@@ -81,16 +83,19 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
activity = mock(BaseActivity.class);
|
activity = mock(BaseActivity.class);
|
||||||
commandRunner = mock(CommandRunner.class);
|
commandRunner = mock(CommandRunner.class);
|
||||||
dirFinder = mock(DirFinder.class);
|
dirFinder = mock(DirFinder.class);
|
||||||
dialogFactory = mock(DialogFactory.class);
|
|
||||||
rootView = mock(ListHabitsRootView.class);
|
rootView = mock(ListHabitsRootView.class);
|
||||||
intentFactory = mock(IntentFactory.class);
|
intentFactory = mock(IntentFactory.class);
|
||||||
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
|
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
|
||||||
createHabitDialogFactory = mock(CreateHabitDialogFactory.class);
|
createHabitDialogFactory = mock(CreateHabitDialogFactory.class);
|
||||||
filePickerDialogFactory = mock(FilePickerDialogFactory.class);
|
filePickerDialogFactory = mock(FilePickerDialogFactory.class);
|
||||||
|
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
|
||||||
|
editHabitDialogFactory = mock(EditHabitDialogFactory.class);
|
||||||
|
|
||||||
screen = new ListHabitsScreen(activity, commandRunner, dirFinder,
|
screen =
|
||||||
dialogFactory, rootView, intentFactory, confirmDeleteDialogFactory,
|
new ListHabitsScreen(activity, commandRunner, dirFinder, rootView,
|
||||||
createHabitDialogFactory, filePickerDialogFactory);
|
intentFactory, confirmDeleteDialogFactory,
|
||||||
|
createHabitDialogFactory, filePickerDialogFactory,
|
||||||
|
colorPickerDialogFactory, editHabitDialogFactory);
|
||||||
|
|
||||||
controller = mock(ListHabitsController.class);
|
controller = mock(ListHabitsController.class);
|
||||||
screen.setController(controller);
|
screen.setController(controller);
|
||||||
@@ -151,7 +156,7 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
habit.setColor(999);
|
habit.setColor(999);
|
||||||
ColorPickerDialog picker = mock(ColorPickerDialog.class);
|
ColorPickerDialog picker = mock(ColorPickerDialog.class);
|
||||||
when(dialogFactory.buildColorPicker(999)).thenReturn(picker);
|
when(colorPickerDialogFactory.create(999)).thenReturn(picker);
|
||||||
OnColorSelectedListener callback = mock(OnColorSelectedListener.class);
|
OnColorSelectedListener callback = mock(OnColorSelectedListener.class);
|
||||||
|
|
||||||
screen.showColorPicker(habit, callback);
|
screen.showColorPicker(habit, callback);
|
||||||
@@ -178,7 +183,7 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
public void testShowEditHabitScreen()
|
public void testShowEditHabitScreen()
|
||||||
{
|
{
|
||||||
EditHabitDialog dialog = mock(EditHabitDialog.class);
|
EditHabitDialog dialog = mock(EditHabitDialog.class);
|
||||||
when(dialogFactory.buildEditHabitDialog(habit)).thenReturn(dialog);
|
when(editHabitDialogFactory.create(habit)).thenReturn(dialog);
|
||||||
|
|
||||||
screen.showEditHabitScreen(habit);
|
screen.showEditHabitScreen(habit);
|
||||||
verify(activity).showDialog(eq(dialog), any());
|
verify(activity).showDialog(eq(dialog), any());
|
||||||
|
|||||||
Reference in New Issue
Block a user