diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialog.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialog.java deleted file mode 100644 index 60bc5c520..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialog.java +++ /dev/null @@ -1,291 +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.app.*; -import android.content.*; -import android.graphics.*; -import android.os.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.*; -import android.text.format.*; -import android.view.*; - -import com.android.datetimepicker.time.TimePickerDialog; - -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.activities.habits.edit.views.*; -import org.isoron.uhabits.core.commands.*; -import org.isoron.uhabits.core.models.*; -import org.isoron.uhabits.core.preferences.*; - -import butterknife.*; - -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"; - - private static final String WEEKDAY_PICKER_TAG = "weekdayPicker"; - - protected Habit originalHabit; - - protected Preferences prefs; - - protected CommandRunner commandRunner; - - protected HabitList habitList; - - protected HabitsApplicationComponent component; - - protected ModelFactory modelFactory; - - @BindView(R.id.namePanel) - NameDescriptionPanel namePanel; - - @BindView(R.id.reminderPanel) - ReminderPanel reminderPanel; - - @BindView(R.id.frequencyPanel) - FrequencyPanel frequencyPanel; - - @BindView(R.id.targetPanel) - TargetPanel targetPanel; - - private ColorPickerDialogFactory colorPickerDialogFactory; - - @Override - public int getTheme() - { - HabitsActivity activity = (HabitsActivity) getActivity(); - return ((AndroidThemeSwitcher) activity.getComponent().getThemeSwitcher()).getDialogTheme(); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) - { - super.onActivityCreated(savedInstanceState); - - HabitsActivity activity = (HabitsActivity) getActivity(); - colorPickerDialogFactory = - activity.getComponent().getColorPickerDialogFactory(); - } - - @Override - public View onCreateView(LayoutInflater inflater, - ViewGroup container, - Bundle savedInstanceState) - { - View view; - view = inflater.inflate(R.layout.edit_habit, container, false); - - initDependencies(); - ButterKnife.bind(this, view); - - originalHabit = parseHabitFromArguments(); - getDialog().setTitle(getTitle()); - - populateForm(); - setupReminderController(); - setupNameController(); - - restoreChildFragmentListeners(); - - return view; - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - final Dialog dialog = super.onCreateDialog(savedInstanceState); - final Window window = dialog.getWindow(); - if (window != null) { - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - } - return dialog; - } - - protected int getTitle() - { - if (originalHabit != null) return R.string.edit_habit; - else return R.string.create_habit; - } - - protected void saveHabit(@NonNull Habit habit) - { - if (originalHabit == null) - { - commandRunner.execute(component - .getCreateHabitCommandFactory() - .create(habitList, habit), null); - } - else - { - commandRunner.execute(component.getEditHabitCommandFactory(). - create(habitList, originalHabit, habit), originalHabit.getId()); - } - } - - private int getTypeFromArguments() - { - return getArguments().getInt(BUNDLE_HABIT_TYPE); - } - - 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) - void onButtonDiscardClick() - { - dismiss(); - } - - @OnClick(R.id.buttonSave) - void onSaveButtonClick() - { - int type = getTypeFromArguments(); - - if (!namePanel.validate()) return; - if (type == Habit.YES_NO_HABIT && !frequencyPanel.validate()) return; - if (type == Habit.NUMBER_HABIT && !targetPanel.validate()) return; - - Habit habit = modelFactory.buildHabit(); - if( originalHabit != null ) - habit.copyFrom(originalHabit); - habit.setName(namePanel.getName()); - habit.setDescription(namePanel.getDescription()); - habit.setQuestion(namePanel.getQuestion()); - 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(); - } - - @Nullable - private Habit parseHabitFromArguments() - { - Bundle arguments = getArguments(); - 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())); - 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()); - } - - private void setupNameController() - { - namePanel.setController(new NameDescriptionPanel.Controller() - { - @Override - public void onColorPickerClicked(int previousColor) - { - ColorPickerDialog picker = - colorPickerDialogFactory.create(previousColor); - - picker.setListener(c -> - { - prefs.setDefaultHabitColor(c); - namePanel.setColor(c); - }); - - 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, Color.BLUE); - timePicker.show(getFragmentManager(), "timePicker"); - } - - @Override - public void onWeekdayClicked(WeekdayList currentDays) - { - WeekdayPickerDialog dialog = new WeekdayPickerDialog(); - dialog.setListener(reminderPanel); - dialog.setSelectedDays(currentDays); - dialog.show(getChildFragmentManager(), WEEKDAY_PICKER_TAG); - } - }); - } - - private void restoreChildFragmentListeners() - { - final WeekdayPickerDialog dialog = - (WeekdayPickerDialog) getChildFragmentManager() - .findFragmentByTag(WEEKDAY_PICKER_TAG); - if(dialog != null) dialog.setListener(reminderPanel); - } -} diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialogFactory.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialogFactory.java deleted file mode 100644 index 966126d59..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitDialogFactory.java +++ /dev/null @@ -1,69 +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 androidx.annotation.NonNull; - -import org.isoron.uhabits.core.models.*; - -import javax.inject.*; - -import static org.isoron.uhabits.activities.habits.edit.EditHabitDialog.*; - -public class EditHabitDialogFactory -{ - @Inject - public EditHabitDialogFactory() - { - } - - public EditHabitDialog createBoolean() - { - 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 EditHabitDialog edit(@NonNull Habit habit) - { - if (habit.getId() == null) - throw new IllegalArgumentException("habit not saved"); - - 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/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/ExampleEditText.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/ExampleEditText.java deleted file mode 100644 index a3e14387f..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/ExampleEditText.java +++ /dev/null @@ -1,116 +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.views; - -import android.content.*; -import android.text.*; -import android.util.*; -import android.view.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatEditText; - -import org.isoron.androidbase.utils.*; -import org.isoron.uhabits.*; - -import static org.isoron.uhabits.utils.AttributeSetUtils.*; - -/** - * An EditText that shows an example usage when there is no text - * currently set. The example disappears when the widget gains focus. - */ -public class ExampleEditText extends AppCompatEditText - implements View.OnFocusChangeListener -{ - - private String example; - - private String realText; - - private int color; - - private int exampleColor; - - private int inputType; - - public ExampleEditText(Context context, @Nullable AttributeSet attrs) - { - super(context, attrs); - - if (attrs != null) - example = getAttribute(context, attrs, "example", ""); - - inputType = getInputType(); - realText = getText().toString(); - color = getCurrentTextColor(); - init(); - } - - public String getRealText() - { - if(hasFocus()) return getText().toString(); - else return realText; - } - - @Override - public void onFocusChange(View v, boolean hasFocus) - { - if (!hasFocus) realText = getText().toString(); - updateText(); - } - - public void setExample(String example) - { - this.example = example; - updateText(); - } - - public void setRealText(@NonNull String realText) - { - this.realText = realText; - updateText(); - } - - private void init() - { - StyledResources sr = new StyledResources(getContext()); - exampleColor = sr.getColor(R.attr.mediumContrastTextColor); - setOnFocusChangeListener(this); - updateText(); - } - - private void updateText() - { - if (realText.isEmpty() && !isFocused()) - { - setTextColor(exampleColor); - setText(example); - setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); - } - else - { - setText(realText); - setTextColor(color); - setInputType(inputType); - } - - } -} diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/FrequencyPanel.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/FrequencyPanel.java deleted file mode 100644 index 4a0436601..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/FrequencyPanel.java +++ /dev/null @@ -1,166 +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.views; - -import android.annotation.*; -import android.content.*; -import android.content.res.*; -import android.util.*; -import android.view.*; -import android.widget.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.isoron.uhabits.R; -import org.isoron.uhabits.core.models.*; - -import butterknife.*; - -import static org.isoron.uhabits.R.id.*; - - -public class FrequencyPanel extends FrameLayout -{ - @BindView(numerator) - TextView tvNumerator; - - @BindView(R.id.denominator) - TextView tvDenominator; - - @BindView(R.id.spinner) - Spinner spinner; - - @BindView(R.id.customFreqPanel) - ViewGroup customFreqPanel; - - public FrequencyPanel(@NonNull Context context, - @Nullable AttributeSet attrs) - { - super(context, attrs); - - View view = inflate(context, R.layout.edit_habit_frequency, null); - ButterKnife.bind(this, view); - addView(view); - } - - @NonNull - public Frequency getFrequency() - { - String freqNum = tvNumerator.getText().toString(); - String freqDen = tvDenominator.getText().toString(); - - if (!freqNum.isEmpty() && !freqDen.isEmpty()) - { - int numerator = Integer.parseInt(freqNum); - int denominator = Integer.parseInt(freqDen); - return new Frequency(numerator, denominator); - } - - return Frequency.DAILY; - } - - @SuppressLint("SetTextI18n") - public void setFrequency(@NonNull Frequency freq) - { - int position = getQuickSelectPosition(freq); - - if (position >= 0) showSimplifiedFrequency(position); - else showCustomFrequency(); - - tvNumerator.setText(Integer.toString(freq.getNumerator())); - tvDenominator.setText(Integer.toString(freq.getDenominator())); - } - - @OnItemSelected(R.id.spinner) - public void onFrequencySelected(int position) - { - if (position < 0 || position > 4) throw new IllegalArgumentException(); - int freqNums[] = { 1, 1, 2, 5, 3 }; - int freqDens[] = { 1, 7, 7, 7, 7 }; - setFrequency(new Frequency(freqNums[position], freqDens[position])); - } - - public boolean validate() - { - boolean valid = true; - Resources res = getResources(); - - String freqNum = tvNumerator.getText().toString(); - String freqDen = tvDenominator.getText().toString(); - - if (freqDen.isEmpty()) - { - tvDenominator.setError( - res.getString(R.string.validation_show_not_be_blank)); - valid = false; - } - - if (freqNum.isEmpty()) - { - tvNumerator.setError( - res.getString(R.string.validation_show_not_be_blank)); - valid = false; - } - - if (!valid) return false; - - int numerator = Integer.parseInt(freqNum); - int denominator = Integer.parseInt(freqDen); - - if (numerator <= 0) - { - tvNumerator.setError( - res.getString(R.string.validation_number_should_be_positive)); - valid = false; - } - - if (numerator > denominator) - { - tvNumerator.setError( - res.getString(R.string.validation_at_most_one_rep_per_day)); - valid = false; - } - - return valid; - } - - private int getQuickSelectPosition(@NonNull Frequency freq) - { - if (freq.equals(Frequency.DAILY)) return 0; - if (freq.equals(Frequency.WEEKLY)) return 1; - if (freq.equals(Frequency.TWO_TIMES_PER_WEEK)) return 2; - if (freq.equals(Frequency.FIVE_TIMES_PER_WEEK)) return 3; - return -1; - } - - private void showCustomFrequency() - { - spinner.setVisibility(View.GONE); - customFreqPanel.setVisibility(View.VISIBLE); - } - - private void showSimplifiedFrequency(int quickSelectPosition) - { - spinner.setVisibility(View.VISIBLE); - spinner.setSelection(quickSelectPosition); - customFreqPanel.setVisibility(View.GONE); - } -} diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/NameDescriptionPanel.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/NameDescriptionPanel.java deleted file mode 100644 index b08a55a47..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/NameDescriptionPanel.java +++ /dev/null @@ -1,164 +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.views; - -import android.content.*; -import android.content.res.*; -import android.os.*; -import android.util.*; -import android.view.*; -import android.widget.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.isoron.uhabits.R; -import org.isoron.uhabits.activities.common.views.*; -import org.isoron.uhabits.core.models.*; -import org.isoron.uhabits.utils.*; - -import butterknife.*; - - -public class NameDescriptionPanel extends FrameLayout -{ - @BindView(R.id.tvName) - EditText tvName; - - @BindView(R.id.tvQuestion) - ExampleEditText tvQuestion; - - @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(PaletteUtils.getColor(getContext(), color)); - } - - @NonNull - public String getDescription() - { - return tvDescription.getRealText().trim(); - } - - @NonNull - public String getQuestion() - { - return tvQuestion.getRealText().trim(); - } - - @NonNull - public String getName() - { - return tvName.getText().toString().trim(); - } - - public void populateFrom(@NonNull Habit habit) - { - Resources res = getResources(); - - if(habit.isNumerical()) - tvQuestion.setExample(res.getString(R.string.example_question_numerical)); - else - tvQuestion.setExample(res.getString(R.string.example_question_boolean)); - - setColor(habit.getColor()); - tvName.setText(habit.getName()); - tvQuestion.setRealText(habit.getQuestion()); - 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) {} - } -} diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/ReminderPanel.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/ReminderPanel.java deleted file mode 100644 index e20f908c4..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/ReminderPanel.java +++ /dev/null @@ -1,197 +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.views; - -import android.content.*; -import android.os.*; -import android.util.*; -import android.view.*; -import android.widget.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.android.datetimepicker.time.*; - -import org.isoron.uhabits.R; -import org.isoron.uhabits.activities.common.dialogs.*; -import org.isoron.uhabits.activities.common.views.*; -import org.isoron.uhabits.core.models.*; -import org.isoron.uhabits.utils.*; - -import butterknife.*; - -public class ReminderPanel extends FrameLayout - implements TimePickerDialog.OnTimeSetListener, - WeekdayPickerDialog.OnWeekdaysPickedListener -{ - @BindView(R.id.tvReminderTime) - TextView tvReminderTime; - - @BindView(R.id.llReminderDays) - ViewGroup llReminderDays; - - @BindView(R.id.tvReminderDays) - TextView tvReminderDays; - - @Nullable - private Reminder reminder; - - @NonNull - private Controller controller; - - public ReminderPanel(@NonNull Context context, @Nullable AttributeSet attrs) - { - super(context, attrs); - - View view = inflate(context, R.layout.edit_habit_reminder, null); - ButterKnife.bind(this, view); - addView(view); - - controller = new Controller() {}; - setReminder(null); - } - - @Nullable - public Reminder getReminder() - { - return reminder; - } - - public void setReminder(@Nullable Reminder reminder) - { - this.reminder = reminder; - - if (reminder == null) - { - tvReminderTime.setText(R.string.reminder_off); - llReminderDays.setVisibility(View.GONE); - return; - } - - Context ctx = getContext(); - String time = AndroidDateUtils.formatTime(ctx, reminder.getHour(), reminder.getMinute()); - tvReminderTime.setText(time); - llReminderDays.setVisibility(View.VISIBLE); - - boolean weekdays[] = reminder.getDays().toArray(); - tvReminderDays.setText(AndroidDateUtils.formatWeekdayList(ctx, weekdays)); - } - - @Override - public void onTimeCleared(RadialPickerLayout view) - { - setReminder(null); - } - - @Override - public void onTimeSet(RadialPickerLayout view, int hour, int minute) - { - WeekdayList days = WeekdayList.EVERY_DAY; - if (reminder != null) days = reminder.getDays(); - setReminder(new Reminder(hour, minute, days)); - } - - @Override - public void onWeekdaysSet(WeekdayList selectedDays) - { - if (reminder == null) return; - if (selectedDays.isEmpty()) selectedDays = WeekdayList.EVERY_DAY; - - setReminder(new Reminder(reminder.getHour(), reminder.getMinute(), - selectedDays)); - } - - public void setController(@NonNull Controller controller) - { - this.controller = controller; - } - - @Override - protected void onRestoreInstanceState(Parcelable state) - { - BundleSavedState bss = (BundleSavedState) state; - if (!bss.bundle.isEmpty()) - { - int days = bss.bundle.getInt("days"); - int hour = bss.bundle.getInt("hour"); - int minute = bss.bundle.getInt("minute"); - reminder = new Reminder(hour, minute, new WeekdayList(days)); - setReminder(reminder); - } - super.onRestoreInstanceState(bss.getSuperState()); - } - - @Override - protected Parcelable onSaveInstanceState() - { - Parcelable superState = super.onSaveInstanceState(); - Bundle bundle = new Bundle(); - if (reminder != null) - { - bundle.putInt("days", reminder.getDays().toInteger()); - bundle.putInt("hour", reminder.getHour()); - bundle.putInt("minute", reminder.getMinute()); - } - return new BundleSavedState(superState, bundle); - } - - @OnClick(R.id.tvReminderTime) - void onDateSpinnerClick() - { - int hour = 8; - int min = 0; - - if (reminder != null) - { - hour = reminder.getHour(); - min = reminder.getMinute(); - } - - controller.onTimeClicked(hour, min); - } - - @OnClick(R.id.tvReminderDays) - void onWeekdayClicked() - { - if (reminder == null) return; - controller.onWeekdayClicked(reminder.getDays()); - } - - public interface Controller - { - /** - * Called when the user has clicked the widget to change the time of - * the reminder. - * - * @param currentHour hour previously picked by the user - * @param currentMin minute previously picked by the user - */ - default void onTimeClicked(int currentHour, int currentMin) {} - - /** - * Called when the used has clicked the widget to change the days - * of the reminder. - * - * @param currentDays days previously selected by the user. - */ - default void onWeekdayClicked(WeekdayList currentDays) {} - } -} diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/TargetPanel.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/TargetPanel.java deleted file mode 100644 index ee25dd645..000000000 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/views/TargetPanel.java +++ /dev/null @@ -1,93 +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.views; - -import android.content.*; -import android.content.res.*; -import android.util.*; -import android.view.*; -import android.widget.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.isoron.uhabits.R; - -import java.text.DecimalFormat; - -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/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt index da34194ca..bd963f50e 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt @@ -58,14 +58,12 @@ class ListHabitsScreen private val commandRunner: CommandRunner, private val intentFactory: IntentFactory, private val themeSwitcher: ThemeSwitcher, - private val preferences: Preferences, private val adapter: HabitCardListAdapter, private val taskRunner: TaskRunner, private val exportDBFactory: ExportDBTaskFactory, private val importTaskFactory: ImportDataTaskFactory, private val confirmDeleteDialogFactory: ConfirmDeleteDialogFactory, private val colorPickerFactory: ColorPickerDialogFactory, - private val editHabitDialogFactory: EditHabitDialogFactory, private val numberPickerFactory: NumberPickerFactory, private val behavior: Lazy, private val menu: Lazy, diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java index ea432b2e6..d19eb7cb5 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitScreen.java @@ -19,6 +19,8 @@ package org.isoron.uhabits.activities.habits.show; +import android.content.*; + import androidx.annotation.NonNull; import org.isoron.androidbase.activities.*; @@ -28,6 +30,7 @@ import org.isoron.uhabits.activities.habits.edit.*; import org.isoron.uhabits.core.models.*; import org.isoron.uhabits.core.ui.callbacks.*; import org.isoron.uhabits.core.ui.screens.habits.show.*; +import org.isoron.uhabits.intents.*; import javax.inject.*; @@ -43,30 +46,30 @@ public class ShowHabitScreen extends BaseScreen @NonNull private final Habit habit; - @NonNull - private final EditHabitDialogFactory editHabitDialogFactory; - @NonNull private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory; private final Lazy behavior; + @NonNull + private final IntentFactory intentFactory; + @Inject public ShowHabitScreen(@NonNull BaseActivity activity, @NonNull Habit habit, @NonNull ShowHabitRootView view, @NonNull ShowHabitsMenu menu, - @NonNull EditHabitDialogFactory editHabitDialogFactory, @NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory, + @NonNull IntentFactory intentFactory, @NonNull Lazy behavior) { super(activity); + this.intentFactory = intentFactory; setMenu(menu); setRootView(view); this.habit = habit; this.behavior = behavior; - this.editHabitDialogFactory = editHabitDialogFactory; this.confirmDeleteDialogFactory = confirmDeleteDialogFactory; view.setController(this); } @@ -102,7 +105,8 @@ public class ShowHabitScreen extends BaseScreen @Override public void showEditHabitScreen(@NonNull Habit habit) { - activity.showDialog(editHabitDialogFactory.edit(habit), "editHabit"); + Intent intent = intentFactory.startEditActivity(activity, habit); + activity.startActivity(intent); } @Override diff --git a/android/uhabits-android/src/main/res/layout/edit_habit.xml b/android/uhabits-android/src/main/res/layout/edit_habit.xml deleted file mode 100644 index 4aa3c697e..000000000 --- a/android/uhabits-android/src/main/res/layout/edit_habit.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -