diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/CreateNumericalHabitDialog.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/CreateNumericalHabitDialog.java deleted file mode 100644 index c8754f72c..000000000 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/CreateNumericalHabitDialog.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -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 CreateNumericalHabitDialog extends NumericalHabitDialog -{ - @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())); - modifiedHabit.setType(Habit.NUMBER_HABIT); - modifiedHabit.setTargetValue(100); - } - - @Override - protected void saveHabit() - { - Command command = appComponent - .getCreateHabitCommandFactory() - .create(habitList, modifiedHabit); - commandRunner.execute(command, null); - } -} diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/BooleanHabitDialog.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialog.java similarity index 87% rename from app/src/main/java/org/isoron/uhabits/activities/habits/edit/BooleanHabitDialog.java rename to app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialog.java index d91ebd193..b3ed6bf3f 100644 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/BooleanHabitDialog.java +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialog.java @@ -39,10 +39,14 @@ import org.isoron.uhabits.preferences.*; import butterknife.*; -public class BooleanHabitDialog extends AppCompatDialogFragment +import static android.view.View.*; + +public class EditHabitDialog extends AppCompatDialogFragment { public static final String BUNDLE_HABIT_ID = "habitId"; + public static final String BUNDLE_HABIT_TYPE = "habitType"; + protected Habit originalHabit; protected Preferences prefs; @@ -64,6 +68,9 @@ public class BooleanHabitDialog extends AppCompatDialogFragment @BindView(R.id.frequencyPanel) FrequencyPanel frequencyPanel; + @BindView(R.id.targetPanel) + TargetPanel targetPanel; + private ColorPickerDialogFactory colorPickerDialogFactory; @Override @@ -88,7 +95,7 @@ public class BooleanHabitDialog extends AppCompatDialogFragment Bundle savedInstanceState) { View view; - view = inflater.inflate(R.layout.edit_boolean_habit, container, false); + view = inflater.inflate(R.layout.edit_habit, container, false); initDependencies(); ButterKnife.bind(this, view); @@ -124,6 +131,11 @@ public class BooleanHabitDialog extends AppCompatDialogFragment } } + private int getTypeFromArguments() + { + return getArguments().getInt(BUNDLE_HABIT_TYPE); + } + private void initDependencies() { Context appContext = getContext().getApplicationContext(); @@ -145,8 +157,11 @@ public class BooleanHabitDialog extends AppCompatDialogFragment @OnClick(R.id.buttonSave) void onSaveButtonClick() { + int type = getTypeFromArguments(); + if (!namePanel.validate()) return; - if (!frequencyPanel.validate()) return; + if (type == Habit.YES_NO_HABIT && !frequencyPanel.validate()) return; + if (type == Habit.NUMBER_HABIT && !targetPanel.validate()) return; Habit habit = modelFactory.buildHabit(); habit.setName(namePanel.getName()); @@ -154,6 +169,9 @@ public class BooleanHabitDialog extends AppCompatDialogFragment habit.setColor(namePanel.getColor()); habit.setReminder(reminderPanel.getReminder()); habit.setFrequency(frequencyPanel.getFrequency()); + habit.setUnit(targetPanel.getUnit()); + habit.setTargetValue(targetPanel.getTargetValue()); + habit.setType(type); saveHabit(habit); dismiss(); @@ -179,11 +197,17 @@ public class BooleanHabitDialog extends AppCompatDialogFragment Habit habit = modelFactory.buildHabit(); habit.setFrequency(Frequency.DAILY); habit.setColor(prefs.getDefaultHabitColor(habit.getColor())); + habit.setType(getTypeFromArguments()); if (originalHabit != null) habit.copyFrom(originalHabit); + if (habit.isNumerical()) frequencyPanel.setVisibility(GONE); + else targetPanel.setVisibility(GONE); + namePanel.populateFrom(habit); frequencyPanel.setFrequency(habit.getFrequency()); + targetPanel.setTargetValue(habit.getTargetValue()); + targetPanel.setUnit(habit.getUnit()); if (habit.hasReminder()) reminderPanel.setReminder(habit.getReminder()); } diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/BooleanHabitDialogFactory.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialogFactory.java similarity index 60% rename from app/src/main/java/org/isoron/uhabits/activities/habits/edit/BooleanHabitDialogFactory.java rename to app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialogFactory.java index 83ac9403b..7ca3ef391 100644 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/BooleanHabitDialogFactory.java +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialogFactory.java @@ -26,28 +26,42 @@ import org.isoron.uhabits.models.*; import javax.inject.*; -import static org.isoron.uhabits.activities.habits.edit.BooleanHabitDialog.*; +import static org.isoron.uhabits.activities.habits.edit.EditHabitDialog.*; -public class BooleanHabitDialogFactory +public class EditHabitDialogFactory { @Inject - public BooleanHabitDialogFactory() + public EditHabitDialogFactory() { } - public BooleanHabitDialog create() + public EditHabitDialog createBoolean() { - return new BooleanHabitDialog(); + EditHabitDialog dialog = new EditHabitDialog(); + Bundle args = new Bundle(); + args.putInt(BUNDLE_HABIT_TYPE, Habit.YES_NO_HABIT); + dialog.setArguments(args); + return dialog; + } + + public EditHabitDialog createNumerical() + { + EditHabitDialog dialog = new EditHabitDialog(); + Bundle args = new Bundle(); + args.putInt(BUNDLE_HABIT_TYPE, Habit.NUMBER_HABIT); + dialog.setArguments(args); + return dialog; } - public BooleanHabitDialog edit(@NonNull Habit habit) + public EditHabitDialog edit(@NonNull Habit habit) { if (habit.getId() == null) throw new IllegalArgumentException("habit not saved"); - BooleanHabitDialog dialog = new BooleanHabitDialog(); + EditHabitDialog dialog = new EditHabitDialog(); Bundle args = new Bundle(); args.putLong(BUNDLE_HABIT_ID, habit.getId()); + args.putInt(BUNDLE_HABIT_TYPE, habit.getType()); dialog.setArguments(args); return dialog; } diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditNumericalHabitDialog.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditNumericalHabitDialog.java deleted file mode 100644 index 87ba58a44..000000000 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditNumericalHabitDialog.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.edit; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.commands.*; - -public class EditNumericalHabitDialog extends NumericalHabitDialog -{ - @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); - if (originalHabit == null) - throw new IllegalStateException("habit is null"); - - modifiedHabit = modelFactory.buildHabit(); - modifiedHabit.copyFrom(originalHabit); - } - - @Override - protected void saveHabit() - { - Command command = appComponent.getEditHabitCommandFactory(). - create(habitList, originalHabit, modifiedHabit); - commandRunner.execute(command, originalHabit.getId()); - } -} diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditNumericalHabitDialogFactory.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditNumericalHabitDialogFactory.java deleted file mode 100644 index 084b61434..000000000 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/EditNumericalHabitDialogFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.edit; - -import android.os.*; -import android.support.annotation.*; - -import org.isoron.uhabits.models.*; - -import javax.inject.*; - -public class EditNumericalHabitDialogFactory -{ - @Inject - public EditNumericalHabitDialogFactory() - { - } - - public EditNumericalHabitDialog create(@NonNull Habit habit) - { - if (habit.getId() == null) - throw new IllegalArgumentException("habit not saved"); - - EditNumericalHabitDialog dialog = new EditNumericalHabitDialog(); - Bundle args = new Bundle(); - args.putLong("habitId", habit.getId()); - dialog.setArguments(args); - return dialog; - } -} diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/NumericalHabitDialog.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/NumericalHabitDialog.java deleted file mode 100644 index ed2c01fa8..000000000 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/NumericalHabitDialog.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.edit; - -import android.os.*; -import android.support.annotation.*; -import android.support.v7.app.*; -import android.view.*; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.R; -import org.isoron.uhabits.activities.*; -import org.isoron.uhabits.activities.common.dialogs.*; -import org.isoron.uhabits.commands.*; -import org.isoron.uhabits.models.*; -import org.isoron.uhabits.preferences.*; - -import butterknife.*; - -public abstract class NumericalHabitDialog extends AppCompatDialogFragment -{ - @Nullable - protected Habit originalHabit; - - @Nullable - protected Habit modifiedHabit; - - protected Preferences prefs; - - protected CommandRunner commandRunner; - - protected HabitList habitList; - - protected AppComponent appComponent; - - protected ModelFactory modelFactory; - - private ColorPickerDialogFactory colorPickerDialogFactory; - - private NumericalHabitDialogHelper helper; - - @Override - public int getTheme() - { - return R.style.DialogWithTitle; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) - { - super.onActivityCreated(savedInstanceState); - BaseActivity activity = (BaseActivity) getActivity(); - ActivityComponent component = activity.getComponent(); - colorPickerDialogFactory = component.getColorPickerDialogFactory(); - } - - @Override - public View onCreateView(LayoutInflater inflater, - ViewGroup container, - Bundle savedInstanceState) - { - View view = - inflater.inflate(R.layout.edit_numerical_habit, container, false); - - HabitsApplication app = - (HabitsApplication) getContext().getApplicationContext(); - - appComponent = app.getComponent(); - prefs = appComponent.getPreferences(); - habitList = appComponent.getHabitList(); - commandRunner = appComponent.getCommandRunner(); - modelFactory = appComponent.getModelFactory(); - - ButterKnife.bind(this, view); - - helper = new NumericalHabitDialogHelper(this, view); - getDialog().setTitle(getTitle()); - initializeHabits(); - restoreSavedInstance(savedInstanceState); - helper.populateForm(modifiedHabit); - return view; - } - - @Override - public void onSaveInstanceState(Bundle outState) - { - super.onSaveInstanceState(outState); - outState.putInt("color", modifiedHabit.getColor()); - } - - protected abstract int getTitle(); - - protected abstract void initializeHabits(); - - protected void restoreSavedInstance(@Nullable Bundle bundle) - { - if (bundle == null) return; - if (modifiedHabit == null) return; - - int color = bundle.getInt("color", modifiedHabit.getColor()); - - modifiedHabit.setColor(color); - modifiedHabit.setReminder(null); - } - - protected abstract void saveHabit(); - - - @OnClick(R.id.buttonDiscard) - void onButtonDiscardClick() - { - dismiss(); - } - - @OnClick(R.id.buttonSave) - void onSaveButtonClick() - { - helper.parseForm(modifiedHabit); - if (!helper.validate(modifiedHabit)) return; - saveHabit(); - dismiss(); - } - - @OnClick(R.id.buttonPickColor) - void showColorPicker() - { - if (modifiedHabit == null) return; - - int color = modifiedHabit.getColor(); - ColorPickerDialog picker = colorPickerDialogFactory.create(color); - - picker.setListener(c -> - { - prefs.setDefaultHabitColor(c); - modifiedHabit.setColor(c); - helper.populateColor(c); - }); - - picker.show(getFragmentManager(), "picker"); - } -} diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/NumericalHabitDialogHelper.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/NumericalHabitDialogHelper.java deleted file mode 100644 index 270069a58..000000000 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/NumericalHabitDialogHelper.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.uhabits.activities.habits.edit; - -import android.icu.text.*; -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 NumericalHabitDialogHelper -{ - private DialogFragment frag; - - private DecimalFormat valueFormatter = new DecimalFormat("#.##"); - - @BindView(R.id.tvName) - TextView tvName; - - @BindView(R.id.tvDescription) - ExampleEditText tvDescription; - - @BindView(R.id.tvUnit) - ExampleEditText tvUnit; - - @BindView(R.id.tvTargetCount) - TextView tvTargetValue; - - @BindView(R.id.tvTargetType) - Spinner tvTargetType; - - public NumericalHabitDialogHelper(DialogFragment frag, View view) - { - this.frag = frag; - ButterKnife.bind(this, view); - } - - public void parseForm(Habit habit) - { - habit.setName(tvName.getText().toString().trim()); - habit.setDescription(tvDescription.getRealText().trim()); - habit.setTargetType(tvTargetType.getSelectedItemPosition()); - habit.setTargetValue( - Double.parseDouble(tvTargetValue.getText().toString())); - habit.setUnit(tvUnit.getRealText().trim()); - } - - public void populateColor(int paletteColor) - { - tvName.setTextColor( - ColorUtils.getColor(frag.getContext(), paletteColor)); - } - - public void populateForm(final Habit habit) - { - tvName.setText(habit.getName()); - - if(!habit.getDescription().isEmpty()) - tvDescription.setRealText(habit.getDescription()); - - if(!habit.getUnit().isEmpty()) - tvUnit.setRealText(habit.getUnit()); - - tvTargetType.setSelection(habit.getTargetType()); - tvTargetValue.setText(valueFormatter.format(habit.getTargetValue())); - populateColor(habit.getColor()); - } - - public boolean validate(Habit habit) - { - Boolean valid = true; - if (!validateName(habit)) valid = false; - if (!validateTargetValue()) valid = false; - return valid; - } - - private boolean validateTargetValue() - { - double value = Double.parseDouble(tvTargetValue.getText().toString()); - if(value <= 0) - { - tvTargetValue.setError(frag.getString(R.string.validation_number_should_be_positive)); - return false; - } - return true; - } - - private Boolean validateName(Habit habit) - { - if (habit.getName().isEmpty()) - { - tvName.setError(frag.getString(R.string.validation_name_should_not_be_blank)); - return false; - } - - return true; - } -} diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/edit/views/TargetPanel.java b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/views/TargetPanel.java new file mode 100644 index 000000000..7319bb967 --- /dev/null +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/edit/views/TargetPanel.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * 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 . + */ + +package org.isoron.uhabits.activities.habits.edit.views; + +import android.content.*; +import android.content.res.*; +import android.icu.text.*; +import android.support.annotation.*; +import android.util.*; +import android.view.*; +import android.widget.*; + +import org.isoron.uhabits.R; + +import butterknife.*; + + +public class TargetPanel extends FrameLayout +{ + private DecimalFormat valueFormatter = new DecimalFormat("#.##"); + + @BindView(R.id.tvUnit) + ExampleEditText tvUnit; + + @BindView(R.id.tvTargetCount) + TextView tvTargetValue; + + public TargetPanel(@NonNull Context context, @Nullable AttributeSet attrs) + { + super(context, attrs); + + View view = inflate(context, R.layout.edit_habit_target, null); + ButterKnife.bind(this, view); + addView(view); + } + + public double getTargetValue() + { + String sValue = tvTargetValue.getText().toString(); + return Double.parseDouble(sValue); + } + + public void setTargetValue(double targetValue) + { + tvTargetValue.setText(valueFormatter.format(targetValue)); + } + + public String getUnit() + { + return tvUnit.getRealText(); + } + + public void setUnit(String unit) + { + tvUnit.setRealText(unit); + } + + public boolean validate() + { + Resources res = getResources(); + String sValue = tvTargetValue.getText().toString(); + double value = Double.parseDouble(sValue); + + if (value <= 0) + { + tvTargetValue.setError( + res.getString(R.string.validation_number_should_be_positive)); + return false; + } + + return true; + } +} diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java b/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java index 2b3f30a9a..2539b879d 100644 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java @@ -89,17 +89,11 @@ public class ListHabitsScreen extends BaseScreen private final ColorPickerDialogFactory colorPickerFactory; @NonNull - private final BooleanHabitDialogFactory booleanHabitDialogFactory; + private final EditHabitDialogFactory editHabitDialogFactory; @NonNull private final ThemeSwitcher themeSwitcher; - @NonNull - private CreateNumericalHabitDialogFactory createNumericalHabitDialogFactory; - - @NonNull - private EditNumericalHabitDialogFactory editNumericalHabitDialogFactory; - @Inject public ListHabitsScreen(@NonNull BaseActivity activity, @NonNull CommandRunner commandRunner, @@ -110,18 +104,14 @@ public class ListHabitsScreen extends BaseScreen @NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory, @NonNull FilePickerDialogFactory filePickerDialogFactory, @NonNull ColorPickerDialogFactory colorPickerFactory, - @NonNull BooleanHabitDialogFactory booleanHabitDialogFactory, - @NonNull EditNumericalHabitDialogFactory editNumericalHabitDialogFactory, - @NonNull CreateNumericalHabitDialogFactory createNumericalHabitDialogFactory) + @NonNull EditHabitDialogFactory editHabitDialogFactory) { super(activity); setRootView(rootView); this.colorPickerFactory = colorPickerFactory; this.commandRunner = commandRunner; this.confirmDeleteDialogFactory = confirmDeleteDialogFactory; - this.createNumericalHabitDialogFactory = createNumericalHabitDialogFactory; - this.booleanHabitDialogFactory = booleanHabitDialogFactory; - this.editNumericalHabitDialogFactory = editNumericalHabitDialogFactory; + this.editHabitDialogFactory = editHabitDialogFactory; this.dirFinder = dirFinder; this.filePickerDialogFactory = filePickerDialogFactory; this.intentFactory = intentFactory; @@ -196,15 +186,15 @@ public class ListHabitsScreen extends BaseScreen private void showCreateNumericalHabitScreen() { - CreateNumericalHabitDialog dialog; - dialog = createNumericalHabitDialogFactory.create(); + EditHabitDialog dialog; + dialog = editHabitDialogFactory.createNumerical(); activity.showDialog(dialog, "editHabit"); } public void showCreateBooleanHabitScreen() { - BooleanHabitDialog dialog; - dialog = booleanHabitDialogFactory.create(); + EditHabitDialog dialog; + dialog = editHabitDialogFactory.createBoolean(); activity.showDialog(dialog, "editHabit"); } @@ -215,18 +205,9 @@ public class ListHabitsScreen extends BaseScreen public void showEditHabitScreen(Habit habit) { - if(habit.isNumerical()) - { - EditNumericalHabitDialog dialog; - dialog = editNumericalHabitDialogFactory.create(habit); - activity.showDialog(dialog, "editNumericalHabit"); - } - else - { - BooleanHabitDialog dialog; - dialog = booleanHabitDialogFactory.edit(habit); - activity.showDialog(dialog, "editHabit"); - } + EditHabitDialog dialog; + dialog = editHabitDialogFactory.edit(habit); + activity.showDialog(dialog, "editNumericalHabit"); } public void showFAQScreen() diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java b/app/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java index 172944155..ec61d3b8f 100644 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java @@ -38,19 +38,18 @@ public class ShowHabitScreen extends BaseScreen private ShowHabitController controller; @NonNull - private final BooleanHabitDialogFactory booleanHabitDialogFactory; + private final EditHabitDialogFactory editHabitDialogFactory; @Inject public ShowHabitScreen(@NonNull BaseActivity activity, @NonNull Habit habit, @NonNull ShowHabitRootView view, @NonNull - BooleanHabitDialogFactory - booleanHabitDialogFactory) + EditHabitDialogFactory editHabitDialogFactory) { super(activity); setRootView(view); - this.booleanHabitDialogFactory = booleanHabitDialogFactory; + this.editHabitDialogFactory = editHabitDialogFactory; this.habit = habit; } @@ -74,7 +73,7 @@ public class ShowHabitScreen extends BaseScreen public void showEditHabitDialog() { activity.showDialog( - booleanHabitDialogFactory.edit(habit), + editHabitDialogFactory.edit(habit), "editHabit"); } diff --git a/app/src/main/java/org/isoron/uhabits/models/Habit.java b/app/src/main/java/org/isoron/uhabits/models/Habit.java index 97eea4b08..fbc6d5d88 100644 --- a/app/src/main/java/org/isoron/uhabits/models/Habit.java +++ b/app/src/main/java/org/isoron/uhabits/models/Habit.java @@ -104,7 +104,7 @@ public class Habit this.name = ""; this.description = ""; this.targetType = AT_LEAST; - this.targetValue = 1; + this.targetValue = 100; this.unit = ""; checkmarks = factory.buildCheckmarkList(this); diff --git a/app/src/main/res/layout/edit_boolean_habit.xml b/app/src/main/res/layout/edit_habit.xml similarity index 90% rename from app/src/main/res/layout/edit_boolean_habit.xml rename to app/src/main/res/layout/edit_habit.xml index 2f5d2c410..da5357c7b 100644 --- a/app/src/main/res/layout/edit_boolean_habit.xml +++ b/app/src/main/res/layout/edit_habit.xml @@ -22,7 +22,7 @@ style="@style/dialogForm" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - tools:context=".activities.habits.edit.BooleanHabitDialog" + tools:context=".activities.habits.edit.EditHabitDialog" tools:ignore="MergeRootFrame"> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/edit_numerical_habit.xml b/app/src/main/res/layout/edit_numerical_habit.xml deleted file mode 100644 index ea13786a6..000000000 --- a/app/src/main/res/layout/edit_numerical_habit.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -