mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Create a class for Reminders
This commit is contained in:
@@ -19,69 +19,35 @@
|
||||
|
||||
package org.isoron.uhabits.espresso;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.espresso.NoMatchingViewException;
|
||||
import android.support.test.espresso.intent.rule.IntentsTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.support.test.*;
|
||||
import android.support.test.espresso.*;
|
||||
import android.support.test.espresso.intent.rule.*;
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.hamcrest.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.sqlite.records.HabitRecord;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.isoron.uhabits.MainActivity;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.isoron.uhabits.models.sqlite.records.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onData;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.Espresso.*;
|
||||
import static android.support.test.espresso.Espresso.pressBack;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||
import static android.support.test.espresso.action.ViewActions.scrollTo;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeLeft;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeRight;
|
||||
import static android.support.test.espresso.action.ViewActions.swipeUp;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.intent.Intents.intended;
|
||||
import static android.support.test.espresso.intent.Intents.intending;
|
||||
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.isoron.uhabits.espresso.HabitViewActions.clickAtRandomLocations;
|
||||
import static org.isoron.uhabits.espresso.HabitViewActions.toggleAllCheckmarks;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.addHabit;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.assertHabitExists;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.assertHabitsDontExist;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.assertHabitsExist;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.clickMenuItem;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.clickSettingsItem;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.deleteHabit;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.deleteHabits;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.selectHabit;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.selectHabits;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.typeHabitData;
|
||||
import static org.isoron.uhabits.espresso.ShowHabitActivityActions.openHistoryEditor;
|
||||
import static android.support.test.espresso.action.ViewActions.*;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.*;
|
||||
import static android.support.test.espresso.intent.Intents.*;
|
||||
import static android.support.test.espresso.intent.matcher.IntentMatchers.*;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.isoron.uhabits.espresso.HabitViewActions.*;
|
||||
import static org.isoron.uhabits.espresso.MainActivityActions.*;
|
||||
import static org.isoron.uhabits.espresso.ShowHabitActivityActions.*;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
@@ -90,45 +56,38 @@ public class MainTest
|
||||
private SystemHelper sys;
|
||||
|
||||
@Rule
|
||||
public IntentsTestRule<MainActivity> activityRule = new IntentsTestRule<>(
|
||||
MainActivity.class);
|
||||
|
||||
private Context targetContext;
|
||||
public IntentsTestRule<MainActivity> activityRule =
|
||||
new IntentsTestRule<>(MainActivity.class);
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
Context context = InstrumentationRegistry.getInstrumentation().getContext();
|
||||
Context context =
|
||||
InstrumentationRegistry.getInstrumentation().getContext();
|
||||
sys = new SystemHelper(context);
|
||||
sys.disableAllAnimations();
|
||||
sys.acquireWakeLock();
|
||||
sys.unlockScreen();
|
||||
|
||||
targetContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
Instrumentation.ActivityResult okResult = new Instrumentation.ActivityResult(
|
||||
Activity.RESULT_OK, new Intent());
|
||||
Instrumentation.ActivityResult okResult =
|
||||
new Instrumentation.ActivityResult(Activity.RESULT_OK,
|
||||
new Intent());
|
||||
|
||||
intending(hasAction(equalTo(Intent.ACTION_SEND))).respondWith(okResult);
|
||||
intending(hasAction(equalTo(Intent.ACTION_SENDTO))).respondWith(okResult);
|
||||
intending(hasAction(equalTo(Intent.ACTION_SENDTO))).respondWith(
|
||||
okResult);
|
||||
intending(hasAction(equalTo(Intent.ACTION_VIEW))).respondWith(okResult);
|
||||
|
||||
skipTutorial();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
sys.releaseWakeLock();
|
||||
}
|
||||
|
||||
public void skipTutorial()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
onView(allOf(withClassName(endsWith("AppCompatImageButton")),
|
||||
isDisplayed())).perform(click());
|
||||
isDisplayed())).perform(click());
|
||||
}
|
||||
catch (NoMatchingViewException e)
|
||||
{
|
||||
@@ -136,16 +95,75 @@ public class MainTest
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
sys.releaseWakeLock();
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens the app, creates some habits, selects them, archives them, select 'show archived'
|
||||
* on the menu, selects the previously archived habits and then deletes them.
|
||||
* User opens menu, clicks about, sees about screen.
|
||||
*/
|
||||
@Test
|
||||
public void testAbout()
|
||||
{
|
||||
clickMenuItem(R.string.about);
|
||||
onView(isRoot()).perform(swipeUp());
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, toggles a bunch of checkmarks, clicks the habit to
|
||||
* open the statistics screen, scrolls down to some views, then scrolls the
|
||||
* views backwards and forwards in time.
|
||||
*/
|
||||
@Test
|
||||
public void testAddHabitAndViewStats() throws InterruptedException
|
||||
{
|
||||
String name = addHabit(true);
|
||||
|
||||
onData(Matchers.allOf(is(instanceOf(HabitRecord.class)),
|
||||
HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.checkmarkPanel))
|
||||
.perform(toggleAllCheckmarks());
|
||||
|
||||
Thread.sleep(1200);
|
||||
|
||||
onData(Matchers.allOf(is(instanceOf(HabitRecord.class)),
|
||||
HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(click());
|
||||
|
||||
onView(withId(R.id.scoreView)).perform(scrollTo(), swipeRight());
|
||||
|
||||
onView(withId(R.id.punchcardView)).perform(scrollTo(), swipeRight());
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens the app, clicks the add button, types some bogus information,
|
||||
* tries to save, dialog displays an error.
|
||||
*/
|
||||
@Test
|
||||
public void testAddInvalidHabit()
|
||||
{
|
||||
onView(withId(R.id.action_add)).perform(click());
|
||||
|
||||
typeHabitData("", "", "15", "7");
|
||||
|
||||
onView(withId(R.id.buttonSave)).perform(click());
|
||||
onView(withId(R.id.tvName)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens the app, creates some habits, selects them, archives them,
|
||||
* select 'show archived' on the menu, selects the previously archived
|
||||
* habits and then deletes them.
|
||||
*/
|
||||
@Test
|
||||
public void testArchiveHabits()
|
||||
{
|
||||
List<String> names = new LinkedList<>();
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
for (int i = 0; i < 3; i++)
|
||||
names.add(addHabit());
|
||||
|
||||
selectHabits(names);
|
||||
@@ -166,71 +184,26 @@ public class MainTest
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens the app, clicks the add button, types some bogus information, tries to save,
|
||||
* dialog displays an error.
|
||||
*/
|
||||
@Test
|
||||
public void testAddInvalidHabit()
|
||||
{
|
||||
onView(withId(R.id.action_add))
|
||||
.perform(click());
|
||||
|
||||
typeHabitData("", "", "15", "7");
|
||||
|
||||
onView(withId(R.id.buttonSave)).perform(click());
|
||||
onView(withId(R.id.tvName)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, toggles a bunch of checkmarks, clicks the habit to open the statistics
|
||||
* screen, scrolls down to some views, then scrolls the views backwards and forwards in time.
|
||||
*/
|
||||
@Test
|
||||
public void testAddHabitAndViewStats() throws InterruptedException
|
||||
{
|
||||
String name = addHabit(true);
|
||||
|
||||
onData(
|
||||
Matchers.allOf(is(instanceOf(HabitRecord.class)), HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.checkmarkPanel))
|
||||
.perform(toggleAllCheckmarks());
|
||||
|
||||
Thread.sleep(1200);
|
||||
|
||||
onData(
|
||||
Matchers.allOf(is(instanceOf(HabitRecord.class)), HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(click());
|
||||
|
||||
onView(withId(R.id.scoreView))
|
||||
.perform(scrollTo(), swipeRight());
|
||||
|
||||
onView(withId(R.id.punchcardView))
|
||||
.perform(scrollTo(), swipeRight());
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, selects the habit, clicks edit button, changes some information about
|
||||
* the habit, click save button, sees changes on the main window, selects habit again,
|
||||
* changes color, then deletes the habit.
|
||||
* User creates a habit, selects the habit, clicks edit button, changes some
|
||||
* information about the habit, click save button, sees changes on the main
|
||||
* window, selects habit again, changes color, then deletes the habit.
|
||||
*/
|
||||
@Test
|
||||
public void testEditHabit()
|
||||
{
|
||||
String name = addHabit();
|
||||
|
||||
onData(
|
||||
Matchers.allOf(is(instanceOf(HabitRecord.class)), HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(longClick());
|
||||
onData(Matchers.allOf(is(instanceOf(HabitRecord.class)),
|
||||
HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(longClick());
|
||||
|
||||
clickMenuItem(R.string.edit);
|
||||
|
||||
String modifiedName = "Modified " + new Random().nextInt(10000);
|
||||
typeHabitData(modifiedName, "", "1", "1");
|
||||
|
||||
onView(withId(R.id.buttonSave))
|
||||
.perform(click());
|
||||
onView(withId(R.id.buttonSave)).perform(click());
|
||||
|
||||
assertHabitExists(modifiedName);
|
||||
|
||||
@@ -242,45 +215,85 @@ public class MainTest
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, opens statistics page, clicks button to edit history, adds some
|
||||
* checkmarks, closes dialog, sees the modified history calendar.
|
||||
* User creates a habit, opens statistics page, clicks button to edit
|
||||
* history, adds some checkmarks, closes dialog, sees the modified history
|
||||
* calendar.
|
||||
*/
|
||||
@Test
|
||||
public void testEditHistory()
|
||||
{
|
||||
String name = addHabit();
|
||||
|
||||
onData(
|
||||
Matchers.allOf(is(instanceOf(HabitRecord.class)), HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(click());
|
||||
onData(Matchers.allOf(is(instanceOf(HabitRecord.class)),
|
||||
HabitMatchers.withName(name)))
|
||||
.onChildView(withId(R.id.label))
|
||||
.perform(click());
|
||||
|
||||
openHistoryEditor();
|
||||
onView(withClassName(endsWith("HabitHistoryView")))
|
||||
.perform(clickAtRandomLocations(20));
|
||||
onView(withClassName(endsWith("HabitHistoryView"))).perform(
|
||||
clickAtRandomLocations(20));
|
||||
|
||||
pressBack();
|
||||
onView(withId(R.id.historyView))
|
||||
.perform(scrollTo(), swipeRight(), swipeLeft());
|
||||
onView(withId(R.id.historyView)).perform(scrollTo(), swipeRight(),
|
||||
swipeLeft());
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens menu, clicks settings, sees settings screen.
|
||||
* User creates a habit, opens settings, clicks export as CSV, is asked what
|
||||
* activity should handle the file.
|
||||
*/
|
||||
@Test
|
||||
public void testSettings()
|
||||
public void testExportCSV()
|
||||
{
|
||||
addHabit();
|
||||
clickMenuItem(R.string.settings);
|
||||
clickSettingsItem("Export as CSV");
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, exports full backup, deletes the habit, restores
|
||||
* backup, sees that the previously created habit has appeared back.
|
||||
*/
|
||||
@Test
|
||||
public void testExportImportDB()
|
||||
{
|
||||
String name = addHabit();
|
||||
|
||||
clickMenuItem(R.string.settings);
|
||||
|
||||
String date =
|
||||
DateUtils.getBackupDateFormat().format(DateUtils.getLocalTime());
|
||||
date = date.substring(0, date.length() - 2);
|
||||
|
||||
clickSettingsItem("Export full backup");
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
|
||||
deleteHabit(name);
|
||||
|
||||
clickMenuItem(R.string.settings);
|
||||
clickSettingsItem("Import data");
|
||||
|
||||
onData(
|
||||
allOf(is(instanceOf(String.class)), startsWith("Backups"))).perform(
|
||||
click());
|
||||
|
||||
onData(
|
||||
allOf(is(instanceOf(String.class)), containsString(date))).perform(
|
||||
click());
|
||||
|
||||
selectHabit(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens the settings and generates a bug report.
|
||||
*/
|
||||
@Test
|
||||
public void testGenerateBugReport()
|
||||
{
|
||||
clickMenuItem(R.string.settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens menu, clicks about, sees about screen.
|
||||
*/
|
||||
@Test
|
||||
public void testAbout()
|
||||
{
|
||||
clickMenuItem(R.string.about);
|
||||
onView(isRoot()).perform(swipeUp());
|
||||
clickSettingsItem("Generate bug report");
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,57 +307,11 @@ public class MainTest
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, exports full backup, deletes the habit, restores backup, sees that the
|
||||
* previously created habit has appeared back.
|
||||
* User opens menu, clicks settings, sees settings screen.
|
||||
*/
|
||||
@Test
|
||||
public void testExportImportDB()
|
||||
{
|
||||
String name = addHabit();
|
||||
|
||||
clickMenuItem(R.string.settings);
|
||||
|
||||
String date = DateUtils.getBackupDateFormat().format(DateUtils.getLocalTime());
|
||||
date = date.substring(0, date.length() - 2);
|
||||
|
||||
clickSettingsItem("Export full backup");
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
|
||||
deleteHabit(name);
|
||||
|
||||
clickMenuItem(R.string.settings);
|
||||
clickSettingsItem("Import data");
|
||||
|
||||
onData(allOf(is(instanceOf(String.class)), startsWith("Backups")))
|
||||
.perform(click());
|
||||
|
||||
onData(allOf(is(instanceOf(String.class)), containsString(date)))
|
||||
.perform(click());
|
||||
|
||||
selectHabit(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* User creates a habit, opens settings, clicks export as CSV, is asked what activity should
|
||||
* handle the file.
|
||||
*/
|
||||
@Test
|
||||
public void testExportCSV()
|
||||
{
|
||||
addHabit();
|
||||
clickMenuItem(R.string.settings);
|
||||
clickSettingsItem("Export as CSV");
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
}
|
||||
|
||||
/**
|
||||
* User opens the settings and generates a bug report.
|
||||
*/
|
||||
@Test
|
||||
public void testGenerateBugReport()
|
||||
public void testSettings()
|
||||
{
|
||||
clickMenuItem(R.string.settings);
|
||||
clickSettingsItem("Generate bug report");
|
||||
intended(hasAction(Intent.ACTION_SEND));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,31 +19,22 @@
|
||||
|
||||
package org.isoron.uhabits.io;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.content.*;
|
||||
import android.support.test.*;
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.BaseAndroidTest;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.utils.FileUtils;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
@@ -128,10 +119,13 @@ public class ImportTest extends BaseAndroidTest
|
||||
assertThat(habit.getName(), equalTo("brush teeth"));
|
||||
assertThat(habit.getFreqNum(), equalTo(3));
|
||||
assertThat(habit.getFreqDen(), equalTo(7));
|
||||
assertThat(habit.getReminderHour(), equalTo(8));
|
||||
assertThat(habit.getReminderMin(), equalTo(0));
|
||||
assertThat(habit.hasReminder(), equalTo(true));
|
||||
|
||||
Reminder reminder = habit.getReminder();
|
||||
assertThat(reminder.getHour(), equalTo(8));
|
||||
assertThat(reminder.getMinute(), equalTo(0));
|
||||
boolean[] reminderDays = {false, true, true, true, true, true, false};
|
||||
assertThat(habit.getReminderDays(), equalTo(DateUtils.packWeekdayList(reminderDays)));
|
||||
assertThat(reminder.getDays(), equalTo(DateUtils.packWeekdayList(reminderDays)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -67,9 +67,9 @@ public class SQLiteCheckmarkListTest extends BaseAndroidTest
|
||||
checkmarks.invalidateNewerThan(0);
|
||||
|
||||
List<Checkmark> list = new LinkedList<>();
|
||||
list.add(new Checkmark(habit, 0, 0));
|
||||
list.add(new Checkmark(habit, 1, 1));
|
||||
list.add(new Checkmark(habit, 2, 2));
|
||||
list.add(new Checkmark(0, 0));
|
||||
list.add(new Checkmark(1, 1));
|
||||
list.add(new Checkmark(2, 2));
|
||||
|
||||
checkmarks.add(list);
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
58
app/src/main/java/org/isoron/uhabits/models/Reminder.java
Normal file
58
app/src/main/java/org/isoron/uhabits/models/Reminder.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -19,16 +19,11 @@
|
||||
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.models.HabitFixtures;
|
||||
import org.isoron.uhabits.models.HabitList;
|
||||
import org.isoron.uhabits.models.ModelFactory;
|
||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListCache;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.isoron.uhabits.utils.Preferences;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.*;
|
||||
|
||||
public class BaseUnitTest
|
||||
{
|
||||
@@ -38,9 +33,6 @@ public class BaseUnitTest
|
||||
@Inject
|
||||
protected Preferences prefs;
|
||||
|
||||
@Inject
|
||||
protected HabitCardListCache listCache;
|
||||
|
||||
@Inject
|
||||
protected ModelFactory modelFactory;
|
||||
|
||||
|
||||
@@ -54,11 +54,7 @@ public class HabitListTest extends BaseUnitTest
|
||||
list.add(habit);
|
||||
|
||||
if (i % 3 == 0)
|
||||
{
|
||||
habit.setReminderDays(DateUtils.ALL_WEEK_DAYS);
|
||||
habit.setReminderHour(8);
|
||||
habit.setReminderMin(30);
|
||||
}
|
||||
habit.setReminder(new Reminder(8, 30, DateUtils.ALL_WEEK_DAYS));
|
||||
}
|
||||
|
||||
habits.get(0).setArchived(1);
|
||||
@@ -130,14 +126,14 @@ public class HabitListTest extends BaseUnitTest
|
||||
public void test_reorder()
|
||||
{
|
||||
int operations[][] = {
|
||||
{5, 2}, {3, 7}, {4, 4}, {3, 2}
|
||||
{ 5, 2 }, { 3, 7 }, { 4, 4 }, { 3, 2 }
|
||||
};
|
||||
|
||||
int expectedPosition[][] = {
|
||||
{0, 1, 3, 4, 5, 2, 6, 7, 8, 9},
|
||||
{0, 1, 7, 3, 4, 2, 5, 6, 8, 9},
|
||||
{0, 1, 7, 3, 4, 2, 5, 6, 8, 9},
|
||||
{0, 1, 7, 2, 4, 3, 5, 6, 8, 9},
|
||||
{ 0, 1, 3, 4, 5, 2, 6, 7, 8, 9 },
|
||||
{ 0, 1, 7, 3, 4, 2, 5, 6, 8, 9 },
|
||||
{ 0, 1, 7, 3, 4, 2, 5, 6, 8, 9 },
|
||||
{ 0, 1, 7, 2, 4, 3, 5, 6, 8, 9 },
|
||||
};
|
||||
|
||||
for (int i = 0; i < operations.length; i++)
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.isoron.uhabits.BaseUnitTest;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
@@ -38,12 +39,9 @@ public class HabitTest extends BaseUnitTest
|
||||
assertThat(habit.getArchived(), is(0));
|
||||
assertThat(habit.getHighlight(), is(0));
|
||||
|
||||
assertThat(habit.getReminderHour(), is(nullValue()));
|
||||
assertThat(habit.getReminderMin(), is(nullValue()));
|
||||
|
||||
assertThat(habit.getReminderDays(), is(not(nullValue())));
|
||||
// assertThat(habit.getStreaks(), is(not(nullValue())));
|
||||
// assertThat(habit.getScores(), is(not(nullValue())));
|
||||
assertThat(habit.hasReminder(), is(false));
|
||||
assertThat(habit.getStreaks(), is(not(nullValue())));
|
||||
assertThat(habit.getScores(), is(not(nullValue())));
|
||||
assertThat(habit.getRepetitions(), is(not(nullValue())));
|
||||
assertThat(habit.getCheckmarks(), is(not(nullValue())));
|
||||
}
|
||||
@@ -57,9 +55,7 @@ public class HabitTest extends BaseUnitTest
|
||||
model.setColor(0);
|
||||
model.setFreqNum(10);
|
||||
model.setFreqDen(20);
|
||||
model.setReminderDays(1);
|
||||
model.setReminderHour(8);
|
||||
model.setReminderMin(30);
|
||||
model.setReminder(new Reminder(8, 30, 1));
|
||||
|
||||
Habit habit = new Habit();
|
||||
habit.copyFrom(model);
|
||||
@@ -68,9 +64,7 @@ public class HabitTest extends BaseUnitTest
|
||||
assertThat(habit.getColor(), is(model.getColor()));
|
||||
assertThat(habit.getFreqNum(), is(model.getFreqNum()));
|
||||
assertThat(habit.getFreqDen(), is(model.getFreqDen()));
|
||||
assertThat(habit.getReminderDays(), is(model.getReminderDays()));
|
||||
assertThat(habit.getReminderHour(), is(model.getReminderHour()));
|
||||
assertThat(habit.getReminderMin(), is(model.getReminderMin()));
|
||||
assertThat(habit.getReminder(), equalTo(model.getReminder()));
|
||||
}
|
||||
|
||||
// @Test
|
||||
@@ -103,9 +97,7 @@ public class HabitTest extends BaseUnitTest
|
||||
Habit h = new Habit();
|
||||
assertThat(h.hasReminder(), is(false));
|
||||
|
||||
h.setReminderDays(DateUtils.ALL_WEEK_DAYS);
|
||||
h.setReminderHour(8);
|
||||
h.setReminderMin(30);
|
||||
h.setReminder(new Reminder(8, 30, DateUtils.ALL_WEEK_DAYS));
|
||||
assertThat(h.hasReminder(), is(true));
|
||||
|
||||
h.clearReminder();
|
||||
|
||||
@@ -19,15 +19,13 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list.views;
|
||||
|
||||
import org.isoron.uhabits.BaseUnitTest;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.HabitCardController;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class HabitCardControllerTest extends BaseUnitTest
|
||||
{
|
||||
@@ -68,7 +66,7 @@ public class HabitCardControllerTest extends BaseUnitTest
|
||||
{
|
||||
long timestamp = DateUtils.getStartOfToday();
|
||||
controller.onToggle(habit, timestamp);
|
||||
verify(view).triggerRipple(0, 0);
|
||||
verify(view).triggerRipple(timestamp);
|
||||
verify(listener).onToggle(habit, timestamp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user