mirror of https://github.com/iSoron/uhabits.git
parent
19f4a19dba
commit
fe7e8ef039
@ -1,212 +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.annotation.*;
|
|
||||||
import android.support.annotation.*;
|
|
||||||
import android.support.v4.app.*;
|
|
||||||
import android.view.*;
|
|
||||||
import android.widget.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
|
||||||
import org.isoron.uhabits.models.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
|
|
||||||
import butterknife.*;
|
|
||||||
|
|
||||||
public class BaseDialogHelper
|
|
||||||
{
|
|
||||||
private DialogFragment frag;
|
|
||||||
|
|
||||||
@BindView(R.id.tvName)
|
|
||||||
TextView tvName;
|
|
||||||
|
|
||||||
@BindView(R.id.tvDescription)
|
|
||||||
TextView tvDescription;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@BindView(R.id.tvFreqNum)
|
|
||||||
TextView tvFreqNum;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@BindView(R.id.tvFreqDen)
|
|
||||||
TextView tvFreqDen;
|
|
||||||
|
|
||||||
@BindView(R.id.tvReminderTime)
|
|
||||||
TextView tvReminderTime;
|
|
||||||
|
|
||||||
@BindView(R.id.tvReminderDays)
|
|
||||||
TextView tvReminderDays;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@BindView(R.id.sFrequency)
|
|
||||||
Spinner sFrequency;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@BindView(R.id.llCustomFrequency)
|
|
||||||
ViewGroup llCustomFrequency;
|
|
||||||
|
|
||||||
@BindView(R.id.llReminderDays)
|
|
||||||
ViewGroup llReminderDays;
|
|
||||||
|
|
||||||
public BaseDialogHelper(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());
|
|
||||||
populateFrequencyFields(habit);
|
|
||||||
populateReminderFields(habit);
|
|
||||||
}
|
|
||||||
|
|
||||||
void parseFormIntoHabit(Habit habit)
|
|
||||||
{
|
|
||||||
habit.setName(tvName.getText().toString().trim());
|
|
||||||
habit.setDescription(tvDescription.getText().toString().trim());
|
|
||||||
|
|
||||||
if (tvFreqDen != null && tvFreqNum != null)
|
|
||||||
{
|
|
||||||
String freqNum = tvFreqNum.getText().toString();
|
|
||||||
String freqDen = tvFreqDen.getText().toString();
|
|
||||||
if (!freqNum.isEmpty() && !freqDen.isEmpty())
|
|
||||||
{
|
|
||||||
int numerator = Integer.parseInt(freqNum);
|
|
||||||
int denominator = Integer.parseInt(freqDen);
|
|
||||||
habit.setFrequency(new Frequency(numerator, denominator));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void populateColor(int paletteColor)
|
|
||||||
{
|
|
||||||
tvName.setTextColor(
|
|
||||||
ColorUtils.getColor(frag.getContext(), paletteColor));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
void populateFrequencyFields(Habit habit)
|
|
||||||
{
|
|
||||||
if (tvFreqNum == null) return;
|
|
||||||
if (tvFreqDen == null) return;
|
|
||||||
|
|
||||||
int quickSelectPosition = -1;
|
|
||||||
|
|
||||||
Frequency freq = habit.getFrequency();
|
|
||||||
|
|
||||||
if (freq.equals(Frequency.DAILY)) quickSelectPosition = 0;
|
|
||||||
|
|
||||||
else if (freq.equals(Frequency.WEEKLY)) quickSelectPosition = 1;
|
|
||||||
|
|
||||||
else if (freq.equals(Frequency.TWO_TIMES_PER_WEEK))
|
|
||||||
quickSelectPosition = 2;
|
|
||||||
|
|
||||||
else if (freq.equals(Frequency.FIVE_TIMES_PER_WEEK))
|
|
||||||
quickSelectPosition = 3;
|
|
||||||
|
|
||||||
if (quickSelectPosition >= 0)
|
|
||||||
showSimplifiedFrequency(quickSelectPosition);
|
|
||||||
|
|
||||||
else showCustomFrequency();
|
|
||||||
|
|
||||||
tvFreqNum.setText(Integer.toString(freq.getNumerator()));
|
|
||||||
tvFreqDen.setText(Integer.toString(freq.getDenominator()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
void populateReminderFields(Habit habit)
|
|
||||||
{
|
|
||||||
if (!habit.hasReminder())
|
|
||||||
{
|
|
||||||
tvReminderTime.setText(R.string.reminder_off);
|
|
||||||
llReminderDays.setVisibility(View.GONE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Reminder reminder = habit.getReminder();
|
|
||||||
|
|
||||||
String time =
|
|
||||||
DateUtils.formatTime(frag.getContext(), reminder.getHour(),
|
|
||||||
reminder.getMinute());
|
|
||||||
tvReminderTime.setText(time);
|
|
||||||
llReminderDays.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
boolean weekdays[] = reminder.getDays().toArray();
|
|
||||||
tvReminderDays.setText(
|
|
||||||
DateUtils.formatWeekdayList(frag.getContext(), weekdays));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showCustomFrequency()
|
|
||||||
{
|
|
||||||
if(sFrequency == null) return;
|
|
||||||
if(llCustomFrequency == null) return;
|
|
||||||
|
|
||||||
sFrequency.setVisibility(View.GONE);
|
|
||||||
llCustomFrequency.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
private void showSimplifiedFrequency(int quickSelectPosition)
|
|
||||||
{
|
|
||||||
if(sFrequency == null) return;
|
|
||||||
if(llCustomFrequency == null) return;
|
|
||||||
|
|
||||||
sFrequency.setVisibility(View.VISIBLE);
|
|
||||||
sFrequency.setSelection(quickSelectPosition);
|
|
||||||
llCustomFrequency.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean validate(Habit habit)
|
|
||||||
{
|
|
||||||
Boolean valid = true;
|
|
||||||
|
|
||||||
if (habit.getName().length() == 0)
|
|
||||||
{
|
|
||||||
tvName.setError(
|
|
||||||
frag.getString(R.string.validation_name_should_not_be_blank));
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Frequency freq = habit.getFrequency();
|
|
||||||
if (tvFreqNum != null && tvFreqDen != null)
|
|
||||||
{
|
|
||||||
if (freq.getNumerator() <= 0)
|
|
||||||
{
|
|
||||||
tvFreqNum.setError(frag.getString(
|
|
||||||
R.string.validation_number_should_be_positive));
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (freq.getNumerator() > freq.getDenominator())
|
|
||||||
{
|
|
||||||
tvFreqNum.setError(frag.getString(
|
|
||||||
R.string.validation_at_most_one_rep_per_day));
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
* 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.annotation.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.content.res.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.util.*;
|
||||||
|
import android.view.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
* 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.os.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.util.*;
|
||||||
|
import android.view.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
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.models.*;
|
||||||
|
|
||||||
|
import butterknife.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.utils.DateUtils.*;
|
||||||
|
|
||||||
|
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 = formatTime(ctx, reminder.getHour(), reminder.getMinute());
|
||||||
|
tvReminderTime.setText(time);
|
||||||
|
llReminderDays.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
boolean weekdays[] = reminder.getDays().toArray();
|
||||||
|
tvReminderDays.setText(formatWeekdayList(ctx, weekdays));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeCleared(RadialPickerLayout view)
|
||||||
|
{
|
||||||
|
setReminder(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeSet(RadialPickerLayout view, int hour, int minute)
|
||||||
|
{
|
||||||
|
setReminder(new Reminder(hour, minute, WeekdayList.EVERY_DAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
<?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 style="@style/dialogFormRow"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/dialogFormLabel"
|
||||||
|
android:text="@string/repeat"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatSpinner
|
||||||
|
android:id="@+id/spinner"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="25dp"
|
||||||
|
android:entries="@array/frequencyQuickSelect"
|
||||||
|
android:minWidth="400dp"
|
||||||
|
android:theme="@style/dialogFormText"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<org.apmem.tools.layouts.FlowLayout
|
||||||
|
android:id="@+id/customFreqPanel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="fill"
|
||||||
|
android:visibility="visible">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/numerator"
|
||||||
|
style="@style/dialogFormInputLargeNumber"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/dialogFormText"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/times_every"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/denominator"
|
||||||
|
style="@style/dialogFormInputLargeNumber"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/dialogFormText"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:text="@string/days"/>
|
||||||
|
|
||||||
|
</org.apmem.tools.layouts.FlowLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,50 @@
|
|||||||
|
<?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"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
style="@style/dialogFormRow">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/dialogFormLabel"
|
||||||
|
android:text="@string/reminder"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvReminderTime"
|
||||||
|
style="@style/dialogFormSpinner"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llReminderDays"
|
||||||
|
style="@style/dialogFormRow">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/dialogFormLabel"
|
||||||
|
android:text=""/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvReminderDays"
|
||||||
|
style="@style/dialogFormSpinner"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue