Create a class for Reminders

This commit is contained in:
2016-06-16 15:19:02 -04:00
parent efc7b2cebb
commit b13f2b4228
19 changed files with 486 additions and 531 deletions

View File

@@ -38,9 +38,7 @@ import android.support.v4.content.LocalBroadcastManager;
import org.isoron.uhabits.commands.CommandRunner;
import org.isoron.uhabits.commands.ToggleRepetitionCommand;
import org.isoron.uhabits.models.Checkmark;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.HabitList;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.BaseTask;
import org.isoron.uhabits.ui.habits.show.ShowHabitActivity;
import org.isoron.uhabits.utils.DateUtils;
@@ -192,11 +190,14 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
private boolean checkWeekday(Intent intent, Habit habit)
{
if(!habit.hasReminder()) return false;
Reminder reminder = habit.getReminder();
Long timestamp =
intent.getLongExtra("timestamp", DateUtils.getStartOfToday());
boolean reminderDays[] =
DateUtils.unpackWeekdayList(habit.getReminderDays());
DateUtils.unpackWeekdayList(reminder.getDays());
int weekday = DateUtils.getWeekday(timestamp);
return reminderDays[weekday];

View File

@@ -19,17 +19,16 @@
package org.isoron.uhabits.io;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;
import android.database.*;
import android.database.sqlite.*;
import android.support.annotation.*;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.DatabaseUtils;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.utils.*;
import java.io.File;
import java.io.IOException;
import java.util.GregorianCalendar;
import java.io.*;
import java.util.*;
/**
* Class that imports database files exported by Rewire.
@@ -39,13 +38,14 @@ public class RewireDBImporter extends AbstractImporter
@Override
public boolean canHandle(@NonNull File file) throws IOException
{
if(!isSQLite3File(file)) return false;
if (!isSQLite3File(file)) return false;
SQLiteDatabase db = SQLiteDatabase.openDatabase(file.getPath(), null,
SQLiteDatabase.OPEN_READONLY);
SQLiteDatabase.OPEN_READONLY);
Cursor c = db.rawQuery("select count(*) from SQLITE_MASTER where name=? or name=?",
new String[]{"CHECKINS", "UNIT"});
Cursor c = db.rawQuery(
"select count(*) from SQLITE_MASTER where name=? or name=?",
new String[]{ "CHECKINS", "UNIT" });
boolean result = (c.moveToFirst() && c.getInt(0) == 2);
@@ -57,7 +57,8 @@ public class RewireDBImporter extends AbstractImporter
@Override
public void importHabitsFromFile(@NonNull File file) throws IOException
{
final SQLiteDatabase db = SQLiteDatabase.openDatabase(file.getPath(), null,
final SQLiteDatabase db =
SQLiteDatabase.openDatabase(file.getPath(), null,
SQLiteDatabase.OPEN_READONLY);
DatabaseUtils.executeAsTransaction(new DatabaseUtils.Callback()
@@ -72,14 +73,48 @@ public class RewireDBImporter extends AbstractImporter
db.close();
}
private void createCheckmarks(@NonNull SQLiteDatabase db,
@NonNull Habit habit,
int rewireHabitId)
{
Cursor c = null;
try
{
String[] params = { Integer.toString(rewireHabitId) };
c = db.rawQuery(
"select distinct date from checkins where habit_id=? and type=2",
params);
if (!c.moveToFirst()) return;
do
{
String date = c.getString(0);
int year = Integer.parseInt(date.substring(0, 4));
int month = Integer.parseInt(date.substring(4, 6));
int day = Integer.parseInt(date.substring(6, 8));
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
cal.set(year, month - 1, day);
habit.getRepetitions().toggleTimestamp(cal.getTimeInMillis());
} while (c.moveToNext());
}
finally
{
if (c != null) c.close();
}
}
private void createHabits(SQLiteDatabase db)
{
Cursor c = null;
try
{
c = db.rawQuery("select _id, name, description, schedule, active_days, " +
"repeating_count, days, period from habits", new String[0]);
c = db.rawQuery(
"select _id, name, description, schedule, active_days, " +
"repeating_count, days, period from habits", new String[0]);
if (!c.moveToFirst()) return;
do
@@ -122,8 +157,7 @@ public class RewireDBImporter extends AbstractImporter
createReminder(db, habit, id);
createCheckmarks(db, habit, id);
}
while (c.moveToNext());
} while (c.moveToNext());
}
finally
{
@@ -131,14 +165,18 @@ public class RewireDBImporter extends AbstractImporter
}
}
private void createReminder(SQLiteDatabase db, Habit habit, int rewireHabitId)
private void createReminder(SQLiteDatabase db,
Habit habit,
int rewireHabitId)
{
String[] params = { Integer.toString(rewireHabitId) };
Cursor c = null;
try
{
c = db.rawQuery("select time, active_days from reminders where habit_id=? limit 1", params);
c = db.rawQuery(
"select time, active_days from reminders where habit_id=? limit 1",
params);
if (!c.moveToFirst()) return;
int rewireReminder = Integer.parseInt(c.getString(0));
@@ -147,49 +185,21 @@ public class RewireDBImporter extends AbstractImporter
boolean reminderDays[] = new boolean[7];
String activeDays[] = c.getString(1).split(",");
for(String d : activeDays)
for (String d : activeDays)
{
int idx = (Integer.parseInt(d) + 1) % 7;
reminderDays[idx] = true;
}
habit.setReminderDays(DateUtils.packWeekdayList(reminderDays));
habit.setReminderHour(rewireReminder / 60);
habit.setReminderMin(rewireReminder % 60);
int hour = rewireReminder / 60;
int minute = rewireReminder % 60;
Integer days = DateUtils.packWeekdayList(reminderDays);
Reminder reminder = new Reminder(hour, minute, days);
habit.setReminder(reminder);
habitList.update(habit);
}
finally
{
if(c != null) c.close();
}
}
private void createCheckmarks(@NonNull SQLiteDatabase db, @NonNull
Habit habit, int rewireHabitId)
{
Cursor c = null;
try
{
String[] params = { Integer.toString(rewireHabitId) };
c = db.rawQuery("select distinct date from checkins where habit_id=? and type=2", params);
if (!c.moveToFirst()) return;
do
{
String date = c.getString(0);
int year = Integer.parseInt(date.substring(0, 4));
int month = Integer.parseInt(date.substring(4, 6));
int day = Integer.parseInt(date.substring(6, 8));
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
cal.set(year, month - 1, day);
habit.getRepetitions().toggleTimestamp(cal.getTimeInMillis());
}
while (c.moveToNext());
}
finally
{
if (c != null) c.close();
}

View File

@@ -49,15 +49,12 @@ public class Checkmark
*/
public static final int UNCHECKED = 0;
private final Habit habit;
private final long timestamp;
private final int value;
public Checkmark(Habit habit, long timestamp, int value)
public Checkmark(long timestamp, int value)
{
this.habit = habit;
this.timestamp = timestamp;
this.value = value;
}
@@ -67,11 +64,6 @@ public class Checkmark
return Long.signum(this.getTimestamp() - other.getTimestamp());
}
public Habit getHabit()
{
return habit;
}
public long getTimestamp()
{
return timestamp;

View File

@@ -221,7 +221,7 @@ public abstract class CheckmarkList
{
int value = checks[i];
long timestamp = to - i * day;
checkmarks.add(new Checkmark(habit, timestamp, value));
checkmarks.add(new Checkmark(timestamp, value));
}
add(checkmarks);

View File

@@ -24,7 +24,6 @@ import android.support.annotation.*;
import org.apache.commons.lang3.builder.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.utils.*;
import java.util.*;
@@ -56,15 +55,6 @@ public class Habit
@NonNull
private Integer color;
@Nullable
private Integer reminderHour;
@Nullable
private Integer reminderMin;
@NonNull
private Integer reminderDays;
@NonNull
private Integer highlight;
@@ -83,6 +73,9 @@ public class Habit
@NonNull
private CheckmarkList checkmarks;
@Nullable
private Reminder reminder;
private ModelObservable observable = new ModelObservable();
@Inject
@@ -97,8 +90,6 @@ public class Habit
{
HabitsApplication.getComponent().inject(this);
reminderDays = DateUtils.ALL_WEEK_DAYS;
copyFrom(model);
checkmarks = factory.buildCheckmarkList(this);
@@ -122,7 +113,6 @@ public class Habit
this.archived = 0;
this.freqDen = 7;
this.freqNum = 3;
this.reminderDays = DateUtils.ALL_WEEK_DAYS;
checkmarks = factory.buildCheckmarkList(this);
streaks = factory.buildStreakList(this);
@@ -136,9 +126,7 @@ public class Habit
*/
public void clearReminder()
{
reminderHour = null;
reminderMin = null;
reminderDays = DateUtils.ALL_WEEK_DAYS;
reminder = null;
observable.notifyListeners();
}
@@ -154,9 +142,7 @@ public class Habit
this.freqNum = model.getFreqNum();
this.freqDen = model.getFreqDen();
this.color = model.getColor();
this.reminderHour = model.getReminderHour();
this.reminderMin = model.getReminderMin();
this.reminderDays = model.getReminderDays();
this.reminder = model.reminder;
this.highlight = model.getHighlight();
this.archived = model.getArchived();
observable.notifyListeners();
@@ -193,6 +179,13 @@ public class Habit
return color;
}
@NonNull
public Reminder getReminder()
{
if(reminder == null) throw new IllegalStateException();
return reminder;
}
public void setColor(Integer color)
{
this.color = color;
@@ -283,54 +276,6 @@ public class Habit
return observable;
}
/**
* Days of the week the reminder should be shown. This field can be
* converted to a list of booleans using the method DateHelper.unpackWeekdayList
* and converted back to an integer by using the method
* DateHelper.packWeekdayList. If the habit has no reminders, this value
* should be ignored.
*/
@NonNull
public Integer getReminderDays()
{
return reminderDays;
}
public void setReminderDays(@NonNull Integer reminderDays)
{
this.reminderDays = reminderDays;
}
/**
* Hour of the day the reminder should be shown. If there is no reminder,
* this equals to null.
*/
@Nullable
public Integer getReminderHour()
{
return reminderHour;
}
public void setReminderHour(@Nullable Integer reminderHour)
{
this.reminderHour = reminderHour;
}
/**
* Minute the reminder should be shown. If there is no reminder, this equals
* to null.
*/
@Nullable
public Integer getReminderMin()
{
return reminderMin;
}
public void setReminderMin(@Nullable Integer reminderMin)
{
this.reminderMin = reminderMin;
}
/**
* List of repetitions belonging to this habit.
*/
@@ -376,7 +321,7 @@ public class Habit
*/
public boolean hasReminder()
{
return (reminderHour != null && reminderMin != null);
return reminder != null;
}
/**
@@ -394,6 +339,11 @@ public class Habit
this.archived = archived;
}
public void setReminder(@Nullable Reminder reminder)
{
this.reminder = reminder;
}
@Override
public String toString()
{
@@ -404,9 +354,6 @@ public class Habit
.append("freqNum", freqNum)
.append("freqDen", freqDen)
.append("color", color)
.append("reminderHour", reminderHour)
.append("reminderMin", reminderMin)
.append("reminderDays", reminderDays)
.append("highlight", highlight)
.append("archived", archived)
.toString();

View File

@@ -0,0 +1,58 @@
/*
* 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.models;
public class Reminder
{
private final int hour;
private final int minute;
private final int days;
public Reminder(int hour, int minute, int days)
{
this.hour = hour;
this.minute = minute;
this.days = days;
}
/**
* Returns the days of the week the reminder should be shown.
* <p>
* This field can be converted to a list of booleans using the method
* DateHelper.unpackWeekdayList and converted back to an integer by using
* the method DateHelper.packWeekdayList.
*/
public int getDays()
{
return days;
}
public int getHour()
{
return hour;
}
public int getMinute()
{
return minute;
}
}

View File

@@ -65,6 +65,6 @@ public class CheckmarkRecord extends Model implements SQLiteRecord
{
SQLiteHabitList habitList = SQLiteHabitList.getInstance();
Habit h = habitList.getById(habit.getId());
return new Checkmark(h, timestamp, value);
return new Checkmark(timestamp, value);
}
}

View File

@@ -39,9 +39,6 @@ import java.lang.reflect.*;
@Table(name = "Habits")
public class HabitRecord extends Model implements SQLiteRecord
{
public static final String HABIT_URI_FORMAT =
"content://org.isoron.uhabits/habit/%d";
public static String SELECT =
"select id, color, description, freq_den, freq_num, " +
"name, position, reminder_hour, reminder_min, " +
@@ -148,9 +145,13 @@ public class HabitRecord extends Model implements SQLiteRecord
this.freqNum = model.getFreqNum();
this.freqDen = model.getFreqDen();
this.color = model.getColor();
this.reminderHour = model.getReminderHour();
this.reminderMin = model.getReminderMin();
this.reminderDays = model.getReminderDays();
if(model.hasReminder())
{
Reminder reminder = model.getReminder();
this.reminderHour = reminder.getHour();
this.reminderMin = reminder.getMinute();
this.reminderDays = reminder.getDays();
}
this.highlight = model.getHighlight();
this.archived = model.getArchived();
}
@@ -171,7 +172,7 @@ public class HabitRecord extends Model implements SQLiteRecord
archived = c.getInt(10);
reminderDays = c.getInt(11);
}
public void copyTo(Habit habit)
{
habit.setName(this.name);
@@ -179,12 +180,15 @@ public class HabitRecord extends Model implements SQLiteRecord
habit.setFreqNum(this.freqNum);
habit.setFreqDen(this.freqDen);
habit.setColor(this.color);
habit.setReminderHour(this.reminderHour);
habit.setReminderMin(this.reminderMin);
habit.setReminderDays(this.reminderDays);
habit.setHighlight(this.highlight);
habit.setArchived(this.archived);
habit.setId(this.getId());
if (reminderHour != null && reminderMin != null)
{
habit.setReminder(
new Reminder(reminderHour, reminderMin, reminderDays));
}
}
/**

View File

@@ -19,35 +19,26 @@
package org.isoron.uhabits.ui.habits.edit;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.os.*;
import android.support.annotation.*;
import android.support.v7.app.*;
import android.text.format.*;
import android.view.*;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.android.datetimepicker.time.RadialPickerLayout;
import com.android.datetimepicker.time.TimePickerDialog;
import com.android.colorpicker.*;
import com.android.datetimepicker.time.*;
import org.isoron.uhabits.HabitsApplication;
import org.isoron.uhabits.R;
import org.isoron.uhabits.commands.CommandRunner;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.HabitList;
import org.isoron.uhabits.utils.ColorUtils;
import org.isoron.uhabits.*;
import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.utils.Preferences;
import java.util.Arrays;
import java.util.*;
import javax.inject.Inject;
import javax.inject.*;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemSelected;
import butterknife.*;
public abstract class BaseDialogFragment extends AppCompatDialogFragment
{
@@ -90,8 +81,8 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
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};
int freqNums[] = { 1, 1, 2, 5, 3 };
int freqDens[] = { 1, 7, 7, 7, 7 };
modifiedHabit.setFreqNum(freqNums[position]);
modifiedHabit.setFreqDen(freqDens[position]);
helper.populateFrequencyFields(modifiedHabit);
@@ -105,9 +96,10 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
outState.putInt("color", modifiedHabit.getColor());
if (modifiedHabit.hasReminder())
{
outState.putInt("reminderMin", modifiedHabit.getReminderMin());
outState.putInt("reminderHour", modifiedHabit.getReminderHour());
outState.putInt("reminderDays", modifiedHabit.getReminderDays());
Reminder reminder = modifiedHabit.getReminder();
outState.putInt("reminderMin", reminder.getMinute());
outState.putInt("reminderHour", reminder.getHour());
outState.putInt("reminderDays", reminder.getDays());
}
}
@@ -115,6 +107,28 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
protected abstract void initializeHabits();
protected void restoreSavedInstance(@Nullable Bundle bundle)
{
if (bundle == null) return;
modifiedHabit.setColor(
bundle.getInt("color", modifiedHabit.getColor()));
modifiedHabit.setReminder(null);
int hour = (bundle.getInt("reminderHour", -1));
int minute = (bundle.getInt("reminderMin", -1));
int days = (bundle.getInt("reminderDays", -1));
if (hour >= 0 && minute >= 0)
{
Reminder reminder = new Reminder(hour, minute, days);
modifiedHabit.setReminder(reminder);
}
}
protected abstract void saveHabit();
@OnClick(R.id.buttonDiscard)
void onButtonDiscardClick()
{
@@ -130,8 +144,9 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
if (modifiedHabit.hasReminder())
{
defaultHour = modifiedHabit.getReminderHour();
defaultMin = modifiedHabit.getReminderMin();
Reminder reminder = modifiedHabit.getReminder();
defaultHour = reminder.getHour();
defaultMin = reminder.getMinute();
}
showTimePicker(defaultHour, defaultMin);
@@ -151,26 +166,15 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
void onWeekdayClick()
{
if (!modifiedHabit.hasReminder()) return;
Reminder reminder = modifiedHabit.getReminder();
WeekdayPickerDialog dialog = new WeekdayPickerDialog();
dialog.setListener(new OnWeekdaysPickedListener());
dialog.setSelectedDays(
DateUtils.unpackWeekdayList(modifiedHabit.getReminderDays()));
DateUtils.unpackWeekdayList(reminder.getDays()));
dialog.show(getFragmentManager(), "weekdayPicker");
}
protected void restoreSavedInstance(@Nullable Bundle bundle)
{
if (bundle == null) return;
modifiedHabit.setColor(
bundle.getInt("color", modifiedHabit.getColor()));
modifiedHabit.setReminderMin(bundle.getInt("reminderMin", -1));
modifiedHabit.setReminderHour(bundle.getInt("reminderHour", -1));
modifiedHabit.setReminderDays(bundle.getInt("reminderDays", -1));
if (modifiedHabit.getReminderMin() < 0) modifiedHabit.clearReminder();
}
protected abstract void saveHabit();
@OnClick(R.id.buttonPickColor)
void showColorPicker()
{
@@ -222,9 +226,9 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
@Override
public void onTimeSet(RadialPickerLayout view, int hour, int minute)
{
modifiedHabit.setReminderHour(hour);
modifiedHabit.setReminderMin(minute);
modifiedHabit.setReminderDays(DateUtils.ALL_WEEK_DAYS);
Reminder reminder =
new Reminder(hour, minute, DateUtils.ALL_WEEK_DAYS);
modifiedHabit.setReminder(reminder);
helper.populateReminderFields(modifiedHabit);
}
}
@@ -237,8 +241,10 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
{
if (isSelectionEmpty(selectedDays)) Arrays.fill(selectedDays, true);
modifiedHabit.setReminderDays(
DateUtils.packWeekdayList(selectedDays));
Reminder oldReminder = modifiedHabit.getReminder();
modifiedHabit.setReminder(
new Reminder(oldReminder.getHour(), oldReminder.getMinute(),
DateUtils.packWeekdayList(selectedDays)));
helper.populateReminderFields(modifiedHabit);
}

View File

@@ -19,20 +19,16 @@
package org.isoron.uhabits.ui.habits.edit;
import android.annotation.SuppressLint;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.annotation.*;
import android.support.v4.app.*;
import android.view.*;
import android.widget.*;
import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.utils.ColorUtils;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.*;
public class BaseDialogHelper
{
@@ -71,6 +67,17 @@ public class BaseDialogHelper
ButterKnife.bind(this, view);
}
protected void populateForm(final Habit habit)
{
if (habit.getName() != null) tvName.setText(habit.getName());
if (habit.getDescription() != null)
tvDescription.setText(habit.getDescription());
populateColor(habit.getColor());
populateFrequencyFields(habit);
populateReminderFields(habit);
}
void parseFormIntoHabit(Habit habit)
{
habit.setName(tvName.getText().toString().trim());
@@ -87,23 +94,13 @@ public class BaseDialogHelper
ColorUtils.getColor(frag.getContext(), paletteColor));
}
protected void populateForm(final Habit habit)
{
if (habit.getName() != null) tvName.setText(habit.getName());
if (habit.getDescription() != null) tvDescription.setText(
habit.getDescription());
populateColor(habit.getColor());
populateFrequencyFields(habit);
populateReminderFields(habit);
}
@SuppressLint("SetTextI18n")
void populateFrequencyFields(Habit habit)
{
int quickSelectPosition = -1;
if (habit.getFreqNum().equals(habit.getFreqDen())) quickSelectPosition = 0;
if (habit.getFreqNum().equals(habit.getFreqDen()))
quickSelectPosition = 0;
else if (habit.getFreqNum() == 1 && habit.getFreqDen() == 7)
quickSelectPosition = 1;
@@ -133,14 +130,16 @@ public class BaseDialogHelper
return;
}
Reminder reminder = habit.getReminder();
String time =
DateUtils.formatTime(frag.getContext(), habit.getReminderHour(),
habit.getReminderMin());
DateUtils.formatTime(frag.getContext(), reminder.getHour(),
reminder.getMinute());
tvReminderTime.setText(time);
llReminderDays.setVisibility(View.VISIBLE);
boolean weekdays[] = DateUtils.unpackWeekdayList(
habit.getReminderDays());
boolean weekdays[] =
DateUtils.unpackWeekdayList(reminder.getDays());
tvReminderDays.setText(
DateUtils.formatWeekdayList(frag.getContext(), weekdays));
}

View File

@@ -101,12 +101,19 @@ public class ShowHabitHelper
TextView reminderLabel =
(TextView) view.findViewById(R.id.reminderLabel);
if (fragment.habit.hasReminder()) reminderLabel.setText(
DateUtils.formatTime(fragment.getActivity(),
fragment.habit.getReminderHour(),
fragment.habit.getReminderMin()));
else reminderLabel.setText(
fragment.getResources().getString(R.string.reminder_off));
if (fragment.habit.hasReminder())
{
Reminder reminder = fragment.habit.getReminder();
reminderLabel.setText(
DateUtils.formatTime(fragment.getActivity(), reminder.getHour(),
reminder.getMinute()));
}
else
{
reminderLabel.setText(
fragment.getResources().getString(R.string.reminder_off));
}
TextView frequencyLabel =
(TextView) view.findViewById(R.id.frequencyLabel);

View File

@@ -19,29 +19,22 @@
package org.isoron.uhabits.utils;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.app.*;
import android.content.*;
import android.media.*;
import android.net.*;
import android.os.*;
import android.preference.*;
import android.provider.*;
import android.support.annotation.*;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.util.*;
import org.isoron.uhabits.HabitBroadcastReceiver;
import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.HabitList;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.text.*;
import java.util.*;
public abstract class ReminderUtils
{
@@ -50,15 +43,14 @@ public abstract class ReminderUtils
@Nullable Long reminderTime)
{
if (!habit.hasReminder()) return;
Reminder reminder = habit.getReminder();
if (reminderTime == null)
{
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
//noinspection ConstantConditions
calendar.set(Calendar.HOUR_OF_DAY, habit.getReminderHour());
//noinspection ConstantConditions
calendar.set(Calendar.MINUTE, habit.getReminderMin());
calendar.set(Calendar.HOUR_OF_DAY, reminder.getHour());
calendar.set(Calendar.MINUTE, reminder.getMinute());
calendar.set(Calendar.SECOND, 0);
reminderTime = calendar.getTimeInMillis();