mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Simplify BooleanHabitDialog subclasses and factories
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.edit;
|
package org.isoron.uhabits.activities.habits.edit;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.v7.app.*;
|
import android.support.v7.app.*;
|
||||||
@@ -38,24 +39,31 @@ import org.isoron.uhabits.preferences.*;
|
|||||||
|
|
||||||
import butterknife.*;
|
import butterknife.*;
|
||||||
|
|
||||||
public abstract class BooleanHabitDialog extends AppCompatDialogFragment
|
public class BooleanHabitDialog extends AppCompatDialogFragment
|
||||||
{
|
{
|
||||||
|
public static final String BUNDLE_HABIT_ID = "habitId";
|
||||||
|
|
||||||
protected Habit originalHabit;
|
protected Habit originalHabit;
|
||||||
|
|
||||||
protected Habit modifiedHabit;
|
|
||||||
|
|
||||||
protected BooleanHabitDialogHelper helper;
|
|
||||||
|
|
||||||
protected Preferences prefs;
|
protected Preferences prefs;
|
||||||
|
|
||||||
protected CommandRunner commandRunner;
|
protected CommandRunner commandRunner;
|
||||||
|
|
||||||
protected HabitList habitList;
|
protected HabitList habitList;
|
||||||
|
|
||||||
protected AppComponent appComponent;
|
protected AppComponent component;
|
||||||
|
|
||||||
protected ModelFactory modelFactory;
|
protected ModelFactory modelFactory;
|
||||||
|
|
||||||
|
@BindView(R.id.namePanel)
|
||||||
|
NameDescriptionPanel namePanel;
|
||||||
|
|
||||||
|
@BindView(R.id.reminderPanel)
|
||||||
|
ReminderPanel reminderPanel;
|
||||||
|
|
||||||
|
@BindView(R.id.frequencyPanel)
|
||||||
|
FrequencyPanel frequencyPanel;
|
||||||
|
|
||||||
private ColorPickerDialogFactory colorPickerDialogFactory;
|
private ColorPickerDialogFactory colorPickerDialogFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,76 +87,54 @@ public abstract class BooleanHabitDialog extends AppCompatDialogFragment
|
|||||||
ViewGroup container,
|
ViewGroup container,
|
||||||
Bundle savedInstanceState)
|
Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
View view =
|
View view;
|
||||||
inflater.inflate(R.layout.edit_boolean_habit, container, false);
|
view = inflater.inflate(R.layout.edit_boolean_habit, container, false);
|
||||||
|
|
||||||
HabitsApplication app =
|
|
||||||
(HabitsApplication) getContext().getApplicationContext();
|
|
||||||
|
|
||||||
appComponent = app.getComponent();
|
|
||||||
prefs = appComponent.getPreferences();
|
|
||||||
habitList = appComponent.getHabitList();
|
|
||||||
commandRunner = appComponent.getCommandRunner();
|
|
||||||
modelFactory = appComponent.getModelFactory();
|
|
||||||
|
|
||||||
|
initDependencies();
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
helper = new BooleanHabitDialogHelper(this, view);
|
|
||||||
getDialog().setTitle(getTitle());
|
getDialog().setTitle(getTitle());
|
||||||
initializeHabits();
|
originalHabit = parseHabitFromArguments();
|
||||||
restoreSavedInstance(savedInstanceState);
|
|
||||||
helper.populateForm(modifiedHabit);
|
|
||||||
|
|
||||||
helper.frequencyPanel.setFrequency(modifiedHabit.getFrequency());
|
populateForm();
|
||||||
|
setupReminderController();
|
||||||
if (modifiedHabit.hasReminder())
|
setupNameController();
|
||||||
helper.reminderPanel.setReminder(modifiedHabit.getReminder());
|
|
||||||
|
|
||||||
helper.reminderPanel.setController(new ReminderPanel.Controller()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onTimeClicked(int currentHour, int currentMin)
|
|
||||||
{
|
|
||||||
TimePickerDialog timePicker;
|
|
||||||
boolean is24HourMode = DateFormat.is24HourFormat(getContext());
|
|
||||||
timePicker = TimePickerDialog.newInstance(helper.reminderPanel,
|
|
||||||
currentHour, currentMin, is24HourMode);
|
|
||||||
timePicker.show(getFragmentManager(), "timePicker");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onWeekdayClicked(WeekdayList currentDays)
|
|
||||||
{
|
|
||||||
WeekdayPickerDialog dialog = new WeekdayPickerDialog();
|
|
||||||
dialog.setListener(helper.reminderPanel);
|
|
||||||
dialog.setSelectedDays(currentDays);
|
|
||||||
dialog.show(getFragmentManager(), "weekdayPicker");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected int getTitle()
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
public void onSaveInstanceState(Bundle outState)
|
|
||||||
{
|
{
|
||||||
super.onSaveInstanceState(outState);
|
if (originalHabit == null) return R.string.edit_habit;
|
||||||
outState.putInt("color", modifiedHabit.getColor());
|
else return R.string.create_habit;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getTitle();
|
protected void saveHabit(@NonNull Habit habit)
|
||||||
|
|
||||||
protected abstract void initializeHabits();
|
|
||||||
|
|
||||||
protected void restoreSavedInstance(@Nullable Bundle bundle)
|
|
||||||
{
|
{
|
||||||
if (bundle == null) return;
|
if (originalHabit == null)
|
||||||
modifiedHabit.setColor(
|
{
|
||||||
bundle.getInt("color", modifiedHabit.getColor()));
|
commandRunner.execute(component
|
||||||
|
.getCreateHabitCommandFactory()
|
||||||
|
.create(habitList, habit), null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commandRunner.execute(component.getEditHabitCommandFactory().
|
||||||
|
create(habitList, originalHabit, habit), originalHabit.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void saveHabit();
|
private void initDependencies()
|
||||||
|
{
|
||||||
|
Context appContext = getContext().getApplicationContext();
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
|
||||||
|
component = app.getComponent();
|
||||||
|
prefs = component.getPreferences();
|
||||||
|
habitList = component.getHabitList();
|
||||||
|
commandRunner = component.getCommandRunner();
|
||||||
|
modelFactory = component.getModelFactory();
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.buttonDiscard)
|
@OnClick(R.id.buttonDiscard)
|
||||||
void onButtonDiscardClick()
|
void onButtonDiscardClick()
|
||||||
@@ -159,30 +145,92 @@ public abstract class BooleanHabitDialog extends AppCompatDialogFragment
|
|||||||
@OnClick(R.id.buttonSave)
|
@OnClick(R.id.buttonSave)
|
||||||
void onSaveButtonClick()
|
void onSaveButtonClick()
|
||||||
{
|
{
|
||||||
helper.parseFormIntoHabit(modifiedHabit);
|
if (!namePanel.validate()) return;
|
||||||
modifiedHabit.setReminder(helper.reminderPanel.getReminder());
|
if (!frequencyPanel.validate()) return;
|
||||||
modifiedHabit.setFrequency(helper.frequencyPanel.getFrequency());
|
|
||||||
|
|
||||||
if (!helper.frequencyPanel.validate()) return;
|
Habit habit = modelFactory.buildHabit();
|
||||||
if (!helper.validate(modifiedHabit)) return;
|
habit.setName(namePanel.getName());
|
||||||
|
habit.setDescription(namePanel.getDescription());
|
||||||
|
habit.setColor(namePanel.getColor());
|
||||||
|
habit.setReminder(reminderPanel.getReminder());
|
||||||
|
habit.setFrequency(frequencyPanel.getFrequency());
|
||||||
|
|
||||||
saveHabit();
|
saveHabit(habit);
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.buttonPickColor)
|
@Nullable
|
||||||
void showColorPicker()
|
private Habit parseHabitFromArguments()
|
||||||
{
|
{
|
||||||
int color = modifiedHabit.getColor();
|
Bundle arguments = getArguments();
|
||||||
ColorPickerDialog picker = colorPickerDialogFactory.create(color);
|
if (arguments == null) return null;
|
||||||
|
|
||||||
|
Long id = (Long) arguments.get(BUNDLE_HABIT_ID);
|
||||||
|
if (id == null) return null;
|
||||||
|
|
||||||
|
Habit habit = habitList.getById(id);
|
||||||
|
if (habit == null) throw new IllegalStateException();
|
||||||
|
|
||||||
|
return habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateForm()
|
||||||
|
{
|
||||||
|
Habit habit = modelFactory.buildHabit();
|
||||||
|
habit.setFrequency(Frequency.DAILY);
|
||||||
|
habit.setColor(prefs.getDefaultHabitColor(habit.getColor()));
|
||||||
|
|
||||||
|
if (originalHabit != null) habit.copyFrom(originalHabit);
|
||||||
|
|
||||||
|
namePanel.populateFrom(habit);
|
||||||
|
frequencyPanel.setFrequency(habit.getFrequency());
|
||||||
|
if (habit.hasReminder()) reminderPanel.setReminder(habit.getReminder());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupNameController()
|
||||||
|
{
|
||||||
|
namePanel.setController(new NameDescriptionPanel.Controller()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onColorPickerClicked(int previousColor)
|
||||||
|
{
|
||||||
|
ColorPickerDialog picker =
|
||||||
|
colorPickerDialogFactory.create(previousColor);
|
||||||
|
|
||||||
picker.setListener(c ->
|
picker.setListener(c ->
|
||||||
{
|
{
|
||||||
prefs.setDefaultHabitColor(c);
|
prefs.setDefaultHabitColor(c);
|
||||||
modifiedHabit.setColor(c);
|
namePanel.setColor(c);
|
||||||
helper.populateColor(c);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
picker.show(getFragmentManager(), "picker");
|
picker.show(getFragmentManager(), "picker");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupReminderController()
|
||||||
|
{
|
||||||
|
reminderPanel.setController(new ReminderPanel.Controller()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onTimeClicked(int currentHour, int currentMin)
|
||||||
|
{
|
||||||
|
TimePickerDialog timePicker;
|
||||||
|
boolean is24HourMode = DateFormat.is24HourFormat(getContext());
|
||||||
|
timePicker =
|
||||||
|
TimePickerDialog.newInstance(reminderPanel, currentHour,
|
||||||
|
currentMin, is24HourMode);
|
||||||
|
timePicker.show(getFragmentManager(), "timePicker");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWeekdayClicked(WeekdayList currentDays)
|
||||||
|
{
|
||||||
|
WeekdayPickerDialog dialog = new WeekdayPickerDialog();
|
||||||
|
dialog.setListener(reminderPanel);
|
||||||
|
dialog.setSelectedDays(currentDays);
|
||||||
|
dialog.show(getFragmentManager(), "weekdayPicker");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,21 +26,28 @@ import org.isoron.uhabits.models.*;
|
|||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class EditBooleanHabitDialogFactory
|
import static org.isoron.uhabits.activities.habits.edit.BooleanHabitDialog.*;
|
||||||
|
|
||||||
|
public class BooleanHabitDialogFactory
|
||||||
{
|
{
|
||||||
@Inject
|
@Inject
|
||||||
public EditBooleanHabitDialogFactory()
|
public BooleanHabitDialogFactory()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditBooleanHabitDialog create(@NonNull Habit habit)
|
public BooleanHabitDialog create()
|
||||||
|
{
|
||||||
|
return new BooleanHabitDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanHabitDialog edit(@NonNull Habit habit)
|
||||||
{
|
{
|
||||||
if (habit.getId() == null)
|
if (habit.getId() == null)
|
||||||
throw new IllegalArgumentException("habit not saved");
|
throw new IllegalArgumentException("habit not saved");
|
||||||
|
|
||||||
EditBooleanHabitDialog dialog = new EditBooleanHabitDialog();
|
BooleanHabitDialog dialog = new BooleanHabitDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("habitId", habit.getId());
|
args.putLong(BUNDLE_HABIT_ID, habit.getId());
|
||||||
dialog.setArguments(args);
|
dialog.setArguments(args);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.edit;
|
|
||||||
|
|
||||||
import android.support.v4.app.*;
|
|
||||||
import android.view.*;
|
|
||||||
import android.widget.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
|
||||||
import org.isoron.uhabits.activities.habits.edit.views.*;
|
|
||||||
import org.isoron.uhabits.models.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
|
|
||||||
import butterknife.*;
|
|
||||||
|
|
||||||
public class BooleanHabitDialogHelper
|
|
||||||
{
|
|
||||||
private DialogFragment frag;
|
|
||||||
|
|
||||||
@BindView(R.id.tvName)
|
|
||||||
TextView tvName;
|
|
||||||
|
|
||||||
@BindView(R.id.tvDescription)
|
|
||||||
TextView tvDescription;
|
|
||||||
|
|
||||||
@BindView(R.id.reminderPanel)
|
|
||||||
ReminderPanel reminderPanel;
|
|
||||||
|
|
||||||
@BindView(R.id.frequencyPanel)
|
|
||||||
FrequencyPanel frequencyPanel;
|
|
||||||
|
|
||||||
public BooleanHabitDialogHelper(DialogFragment frag, View view)
|
|
||||||
{
|
|
||||||
this.frag = frag;
|
|
||||||
ButterKnife.bind(this, view);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void populateForm(final Habit habit)
|
|
||||||
{
|
|
||||||
tvName.setText(habit.getName());
|
|
||||||
tvDescription.setText(habit.getDescription());
|
|
||||||
populateColor(habit.getColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
void parseFormIntoHabit(Habit habit)
|
|
||||||
{
|
|
||||||
habit.setName(tvName.getText().toString().trim());
|
|
||||||
habit.setDescription(tvDescription.getText().toString().trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
void populateColor(int paletteColor)
|
|
||||||
{
|
|
||||||
tvName.setTextColor(
|
|
||||||
ColorUtils.getColor(frag.getContext(), paletteColor));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean validate(Habit habit)
|
|
||||||
{
|
|
||||||
Boolean valid = true;
|
|
||||||
|
|
||||||
if (habit.getName().isEmpty())
|
|
||||||
{
|
|
||||||
tvName.setError(frag.getString(R.string.validation_name_should_not_be_blank));
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.edit;
|
|
||||||
|
|
||||||
import com.google.auto.factory.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.isoron.uhabits.commands.*;
|
|
||||||
import org.isoron.uhabits.models.*;
|
|
||||||
|
|
||||||
@AutoFactory(allowSubclasses = true)
|
|
||||||
public class CreateBooleanHabitDialog extends BooleanHabitDialog
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected int getTitle()
|
|
||||||
{
|
|
||||||
return R.string.create_habit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initializeHabits()
|
|
||||||
{
|
|
||||||
modifiedHabit = modelFactory.buildHabit();
|
|
||||||
modifiedHabit.setFrequency(Frequency.DAILY);
|
|
||||||
modifiedHabit.setColor(prefs.getDefaultHabitColor(modifiedHabit.getColor()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void saveHabit()
|
|
||||||
{
|
|
||||||
Command command = appComponent
|
|
||||||
.getCreateHabitCommandFactory()
|
|
||||||
.create(habitList, modifiedHabit);
|
|
||||||
commandRunner.execute(command, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.edit;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.isoron.uhabits.commands.*;
|
|
||||||
|
|
||||||
public class EditBooleanHabitDialog extends BooleanHabitDialog
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected int getTitle()
|
|
||||||
{
|
|
||||||
return R.string.edit_habit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initializeHabits()
|
|
||||||
{
|
|
||||||
Long habitId = (Long) getArguments().get("habitId");
|
|
||||||
if (habitId == null)
|
|
||||||
throw new IllegalArgumentException("habitId must be specified");
|
|
||||||
|
|
||||||
originalHabit = habitList.getById(habitId);
|
|
||||||
modifiedHabit = modelFactory.buildHabit();
|
|
||||||
modifiedHabit.copyFrom(originalHabit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void saveHabit()
|
|
||||||
{
|
|
||||||
Command command = appComponent.getEditHabitCommandFactory().
|
|
||||||
create(habitList, originalHabit, modifiedHabit);
|
|
||||||
commandRunner.execute(command, originalHabit.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -60,8 +60,6 @@ public class NumericalHabitDialogHelper
|
|||||||
|
|
||||||
public void parseForm(Habit habit)
|
public void parseForm(Habit habit)
|
||||||
{
|
{
|
||||||
tvUnit.clearFocus();
|
|
||||||
tvDescription.clearFocus();
|
|
||||||
habit.setName(tvName.getText().toString().trim());
|
habit.setName(tvName.getText().toString().trim());
|
||||||
habit.setDescription(tvDescription.getRealText().trim());
|
habit.setDescription(tvDescription.getRealText().trim());
|
||||||
habit.setTargetType(tvTargetType.getSelectedItemPosition());
|
habit.setTargetType(tvTargetType.getSelectedItemPosition());
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ public class ExampleEditText extends EditText
|
|||||||
|
|
||||||
public String getRealText()
|
public String getRealText()
|
||||||
{
|
{
|
||||||
return realText;
|
if(hasFocus()) return getText().toString();
|
||||||
|
else return realText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* 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.views;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
import android.content.res.*;
|
||||||
|
import android.os.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.util.*;
|
||||||
|
import android.view.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.activities.common.views.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
import butterknife.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class NameDescriptionPanel extends FrameLayout
|
||||||
|
{
|
||||||
|
@BindView(R.id.tvName)
|
||||||
|
EditText tvName;
|
||||||
|
|
||||||
|
@BindView(R.id.tvDescription)
|
||||||
|
ExampleEditText tvDescription;
|
||||||
|
|
||||||
|
private int color;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Controller controller;
|
||||||
|
|
||||||
|
public NameDescriptionPanel(@NonNull Context context,
|
||||||
|
@Nullable AttributeSet attrs)
|
||||||
|
{
|
||||||
|
super(context, attrs);
|
||||||
|
|
||||||
|
View view = inflate(context, R.layout.edit_habit_name, null);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
addView(view);
|
||||||
|
|
||||||
|
controller = new Controller() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColor()
|
||||||
|
{
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(int color)
|
||||||
|
{
|
||||||
|
this.color = color;
|
||||||
|
tvName.setTextColor(ColorUtils.getColor(getContext(), color));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getDescription()
|
||||||
|
{
|
||||||
|
return tvDescription.getRealText().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return tvName.getText().toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void populateFrom(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
Resources res = getResources();
|
||||||
|
|
||||||
|
if(habit.isNumerical())
|
||||||
|
tvDescription.setExample(res.getString(R.string.example_question_numerical));
|
||||||
|
else
|
||||||
|
tvDescription.setExample(res.getString(R.string.example_question_boolean));
|
||||||
|
|
||||||
|
setColor(habit.getColor());
|
||||||
|
tvName.setText(habit.getName());
|
||||||
|
tvDescription.setRealText(habit.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validate()
|
||||||
|
{
|
||||||
|
Resources res = getResources();
|
||||||
|
|
||||||
|
if (getName().isEmpty())
|
||||||
|
{
|
||||||
|
tvName.setError(
|
||||||
|
res.getString(R.string.validation_name_should_not_be_blank));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Parcelable state)
|
||||||
|
{
|
||||||
|
BundleSavedState bss = (BundleSavedState) state;
|
||||||
|
setColor(bss.bundle.getInt("color"));
|
||||||
|
super.onRestoreInstanceState(bss.getSuperState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Parcelable onSaveInstanceState()
|
||||||
|
{
|
||||||
|
Parcelable superState = super.onSaveInstanceState();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt("color", color);
|
||||||
|
return new BundleSavedState(superState, bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.buttonPickColor)
|
||||||
|
void showColorPicker()
|
||||||
|
{
|
||||||
|
controller.onColorPickerClicked(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setController(@NonNull Controller controller)
|
||||||
|
{
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Called when the user has clicked the widget to select a new
|
||||||
|
* color for the habit.
|
||||||
|
*
|
||||||
|
* @param previousColor the color previously selected
|
||||||
|
*/
|
||||||
|
default void onColorPickerClicked(int previousColor) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,10 +82,6 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final CreateBooleanHabitDialogFactory
|
|
||||||
createBooleanHabitDialogFactory;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final FilePickerDialogFactory filePickerDialogFactory;
|
private final FilePickerDialogFactory filePickerDialogFactory;
|
||||||
|
|
||||||
@@ -93,7 +89,7 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
private final ColorPickerDialogFactory colorPickerFactory;
|
private final ColorPickerDialogFactory colorPickerFactory;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final EditBooleanHabitDialogFactory editBooleanHabitDialogFactory;
|
private final BooleanHabitDialogFactory booleanHabitDialogFactory;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ThemeSwitcher themeSwitcher;
|
private final ThemeSwitcher themeSwitcher;
|
||||||
@@ -112,10 +108,9 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
@NonNull IntentFactory intentFactory,
|
@NonNull IntentFactory intentFactory,
|
||||||
@NonNull ThemeSwitcher themeSwitcher,
|
@NonNull ThemeSwitcher themeSwitcher,
|
||||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||||
@NonNull CreateBooleanHabitDialogFactory createBooleanHabitDialogFactory,
|
|
||||||
@NonNull FilePickerDialogFactory filePickerDialogFactory,
|
@NonNull FilePickerDialogFactory filePickerDialogFactory,
|
||||||
@NonNull ColorPickerDialogFactory colorPickerFactory,
|
@NonNull ColorPickerDialogFactory colorPickerFactory,
|
||||||
@NonNull EditBooleanHabitDialogFactory editBooleanHabitDialogFactory,
|
@NonNull BooleanHabitDialogFactory booleanHabitDialogFactory,
|
||||||
@NonNull EditNumericalHabitDialogFactory editNumericalHabitDialogFactory,
|
@NonNull EditNumericalHabitDialogFactory editNumericalHabitDialogFactory,
|
||||||
@NonNull CreateNumericalHabitDialogFactory createNumericalHabitDialogFactory)
|
@NonNull CreateNumericalHabitDialogFactory createNumericalHabitDialogFactory)
|
||||||
{
|
{
|
||||||
@@ -125,8 +120,7 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
this.commandRunner = commandRunner;
|
this.commandRunner = commandRunner;
|
||||||
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
||||||
this.createNumericalHabitDialogFactory = createNumericalHabitDialogFactory;
|
this.createNumericalHabitDialogFactory = createNumericalHabitDialogFactory;
|
||||||
this.createBooleanHabitDialogFactory = createBooleanHabitDialogFactory;
|
this.booleanHabitDialogFactory = booleanHabitDialogFactory;
|
||||||
this.editBooleanHabitDialogFactory = editBooleanHabitDialogFactory;
|
|
||||||
this.editNumericalHabitDialogFactory = editNumericalHabitDialogFactory;
|
this.editNumericalHabitDialogFactory = editNumericalHabitDialogFactory;
|
||||||
this.dirFinder = dirFinder;
|
this.dirFinder = dirFinder;
|
||||||
this.filePickerDialogFactory = filePickerDialogFactory;
|
this.filePickerDialogFactory = filePickerDialogFactory;
|
||||||
@@ -209,8 +203,8 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
|
|
||||||
public void showCreateBooleanHabitScreen()
|
public void showCreateBooleanHabitScreen()
|
||||||
{
|
{
|
||||||
CreateBooleanHabitDialog dialog;
|
BooleanHabitDialog dialog;
|
||||||
dialog = createBooleanHabitDialogFactory.create();
|
dialog = booleanHabitDialogFactory.create();
|
||||||
activity.showDialog(dialog, "editHabit");
|
activity.showDialog(dialog, "editHabit");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,8 +223,8 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EditBooleanHabitDialog dialog;
|
BooleanHabitDialog dialog;
|
||||||
dialog = editBooleanHabitDialogFactory.create(habit);
|
dialog = booleanHabitDialogFactory.edit(habit);
|
||||||
activity.showDialog(dialog, "editHabit");
|
activity.showDialog(dialog, "editHabit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,18 +38,19 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
private ShowHabitController controller;
|
private ShowHabitController controller;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final EditBooleanHabitDialogFactory editBooleanHabitDialogFactory;
|
private final BooleanHabitDialogFactory booleanHabitDialogFactory;
|
||||||
|
|
||||||
@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
|
@NonNull
|
||||||
EditBooleanHabitDialogFactory editBooleanHabitDialogFactory)
|
BooleanHabitDialogFactory
|
||||||
|
booleanHabitDialogFactory)
|
||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
setRootView(view);
|
setRootView(view);
|
||||||
this.editBooleanHabitDialogFactory = editBooleanHabitDialogFactory;
|
this.booleanHabitDialogFactory = booleanHabitDialogFactory;
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +73,9 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
|
|
||||||
public void showEditHabitDialog()
|
public void showEditHabitDialog()
|
||||||
{
|
{
|
||||||
EditBooleanHabitDialog dialog = editBooleanHabitDialogFactory.create(habit);
|
activity.showDialog(
|
||||||
activity.showDialog(dialog, "editHabit");
|
booleanHabitDialogFactory.edit(habit),
|
||||||
|
"editHabit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showEditHistoryDialog()
|
public void showEditHistoryDialog()
|
||||||
|
|||||||
@@ -29,29 +29,10 @@
|
|||||||
android:id="@+id/formPanel"
|
android:id="@+id/formPanel"
|
||||||
style="@style/dialogFormPanel">
|
style="@style/dialogFormPanel">
|
||||||
|
|
||||||
<LinearLayout
|
<org.isoron.uhabits.activities.habits.edit.views.NameDescriptionPanel
|
||||||
android:id="@+id/namePanel"
|
android:id="@+id/namePanel"
|
||||||
style="@style/dialogFormRow">
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
<EditText
|
|
||||||
android:id="@+id/tvName"
|
|
||||||
style="@style/dialogFormInput"
|
|
||||||
android:hint="@string/name">
|
|
||||||
|
|
||||||
<requestFocus/>
|
|
||||||
</EditText>
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/buttonPickColor"
|
|
||||||
style="@style/dialogFormInputColor"
|
|
||||||
android:contentDescription="@string/color_picker_default_title"
|
|
||||||
android:src="?dialogIconChangeColor"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/tvDescription"
|
|
||||||
style="@style/dialogFormInputMultiline"
|
|
||||||
android:hint="@string/description_hint"/>
|
|
||||||
|
|
||||||
<org.isoron.uhabits.activities.habits.edit.views.FrequencyPanel
|
<org.isoron.uhabits.activities.habits.edit.views.FrequencyPanel
|
||||||
android:id="@+id/frequencyPanel"
|
android:id="@+id/frequencyPanel"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
70
app/src/main/res/layout/edit_habit_name.xml
Normal file
70
app/src/main/res/layout/edit_habit_name.xml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://isoron.org/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
style="@style/dialogFormRow">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/tilName"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="6">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/tvName"
|
||||||
|
style="@style/dialogFormInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/name">
|
||||||
|
|
||||||
|
<requestFocus/>
|
||||||
|
</EditText>
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/buttonPickColor"
|
||||||
|
style="@style/dialogFormInputColor"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:contentDescription="@string/color_picker_default_title"
|
||||||
|
android:src="?dialogIconChangeColor"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<org.isoron.uhabits.activities.habits.edit.views.ExampleEditText
|
||||||
|
android:id="@+id/tvDescription"
|
||||||
|
style="@style/dialogFormInputMultiline"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/question"
|
||||||
|
app:example="@string/example_question_numerical"/>
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -19,12 +19,13 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
style="@style/dialogFormRow">
|
style="@style/dialogFormRow"
|
||||||
|
android:layout_marginTop="12dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/dialogFormLabel"
|
style="@style/dialogFormLabel"
|
||||||
@@ -37,7 +38,8 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/llReminderDays"
|
android:id="@+id/llReminderDays"
|
||||||
style="@style/dialogFormRow">
|
style="@style/dialogFormRow"
|
||||||
|
android:layout_marginTop="12dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/dialogFormLabel"
|
style="@style/dialogFormLabel"
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">Loop Habit Tracker</string>
|
<string name="app_name">Loop Habit Tracker</string>
|
||||||
<string name="main_activity_title">Habits</string>
|
<string name="main_activity_title">Habits</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
@@ -211,4 +210,7 @@
|
|||||||
<string name="unit">Unit</string>
|
<string name="unit">Unit</string>
|
||||||
<string name="count">Count</string>
|
<string name="count">Count</string>
|
||||||
<string name="validation_show_not_be_blank">This field should not be blank</string>
|
<string name="validation_show_not_be_blank">This field should not be blank</string>
|
||||||
|
<string name="example_question_numerical">e.g. How many steps did you walk today?</string>
|
||||||
|
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
||||||
|
<string name="question">Question</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -61,8 +61,6 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
|
|
||||||
private ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
private ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
||||||
|
|
||||||
private CreateBooleanHabitDialogFactory createHabitDialogFactory;
|
|
||||||
|
|
||||||
private FilePickerDialogFactory filePickerDialogFactory;
|
private FilePickerDialogFactory filePickerDialogFactory;
|
||||||
|
|
||||||
private IntentFactory intentFactory;
|
private IntentFactory intentFactory;
|
||||||
@@ -73,7 +71,7 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
|
|
||||||
private ColorPickerDialogFactory colorPickerDialogFactory;
|
private ColorPickerDialogFactory colorPickerDialogFactory;
|
||||||
|
|
||||||
private EditBooleanHabitDialogFactory editHabitDialogFactory;
|
private BooleanHabitDialogFactory dialogFactory;
|
||||||
|
|
||||||
private ThemeSwitcher themeSwitcher;
|
private ThemeSwitcher themeSwitcher;
|
||||||
|
|
||||||
@@ -96,10 +94,9 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
intentFactory = mock(IntentFactory.class);
|
intentFactory = mock(IntentFactory.class);
|
||||||
themeSwitcher = mock(ThemeSwitcher.class);
|
themeSwitcher = mock(ThemeSwitcher.class);
|
||||||
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
|
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
|
||||||
createHabitDialogFactory = mock(CreateBooleanHabitDialogFactory.class);
|
|
||||||
filePickerDialogFactory = mock(FilePickerDialogFactory.class);
|
filePickerDialogFactory = mock(FilePickerDialogFactory.class);
|
||||||
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
|
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
|
||||||
editHabitDialogFactory = mock(EditBooleanHabitDialogFactory.class);
|
dialogFactory = mock(BooleanHabitDialogFactory.class);
|
||||||
editNumericalHabitDialogFactory =
|
editNumericalHabitDialogFactory =
|
||||||
mock(EditNumericalHabitDialogFactory.class);
|
mock(EditNumericalHabitDialogFactory.class);
|
||||||
createNumericalHabitDialogFactory =
|
createNumericalHabitDialogFactory =
|
||||||
@@ -107,8 +104,7 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
|
|
||||||
screen = spy(new ListHabitsScreen(activity, commandRunner, dirFinder,
|
screen = spy(new ListHabitsScreen(activity, commandRunner, dirFinder,
|
||||||
rootView, intentFactory, themeSwitcher, confirmDeleteDialogFactory,
|
rootView, intentFactory, themeSwitcher, confirmDeleteDialogFactory,
|
||||||
createHabitDialogFactory, filePickerDialogFactory,
|
filePickerDialogFactory, colorPickerDialogFactory, dialogFactory,
|
||||||
colorPickerDialogFactory, editHabitDialogFactory,
|
|
||||||
editNumericalHabitDialogFactory,
|
editNumericalHabitDialogFactory,
|
||||||
createNumericalHabitDialogFactory));
|
createNumericalHabitDialogFactory));
|
||||||
|
|
||||||
@@ -222,8 +218,8 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testShowEditHabitScreen()
|
public void testShowEditHabitScreen()
|
||||||
{
|
{
|
||||||
EditBooleanHabitDialog dialog = mock(EditBooleanHabitDialog.class);
|
BooleanHabitDialog dialog = mock(BooleanHabitDialog.class);
|
||||||
when(editHabitDialogFactory.create(habit)).thenReturn(dialog);
|
when(dialogFactory.edit(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