mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Create a class for Reminders
This commit is contained in:
@@ -19,69 +19,35 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.espresso;
|
package org.isoron.uhabits.espresso;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.*;
|
||||||
import android.app.Instrumentation;
|
import android.content.*;
|
||||||
import android.content.Context;
|
import android.support.test.*;
|
||||||
import android.content.Intent;
|
import android.support.test.espresso.*;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.espresso.intent.rule.*;
|
||||||
import android.support.test.espresso.NoMatchingViewException;
|
import android.support.test.runner.*;
|
||||||
import android.support.test.espresso.intent.rule.IntentsTestRule;
|
import android.test.suitebuilder.annotation.*;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
|
||||||
|
|
||||||
import org.hamcrest.*;
|
import org.hamcrest.*;
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.models.sqlite.records.HabitRecord;
|
import org.isoron.uhabits.models.sqlite.records.*;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.MainActivity;
|
import org.junit.*;
|
||||||
import org.junit.After;
|
import org.junit.runner.*;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static android.support.test.espresso.Espresso.onData;
|
import static android.support.test.espresso.Espresso.*;
|
||||||
import static android.support.test.espresso.Espresso.onView;
|
|
||||||
import static android.support.test.espresso.Espresso.pressBack;
|
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.*;
|
||||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
import static android.support.test.espresso.assertion.ViewAssertions.*;
|
||||||
import static android.support.test.espresso.action.ViewActions.scrollTo;
|
import static android.support.test.espresso.intent.Intents.*;
|
||||||
import static android.support.test.espresso.action.ViewActions.swipeLeft;
|
import static android.support.test.espresso.intent.matcher.IntentMatchers.*;
|
||||||
import static android.support.test.espresso.action.ViewActions.swipeRight;
|
import static android.support.test.espresso.matcher.ViewMatchers.*;
|
||||||
import static android.support.test.espresso.action.ViewActions.swipeUp;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
import static org.isoron.uhabits.espresso.HabitViewActions.*;
|
||||||
import static android.support.test.espresso.intent.Intents.intended;
|
import static org.isoron.uhabits.espresso.MainActivityActions.*;
|
||||||
import static android.support.test.espresso.intent.Intents.intending;
|
import static org.isoron.uhabits.espresso.ShowHabitActivityActions.*;
|
||||||
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;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -90,45 +56,38 @@ public class MainTest
|
|||||||
private SystemHelper sys;
|
private SystemHelper sys;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public IntentsTestRule<MainActivity> activityRule = new IntentsTestRule<>(
|
public IntentsTestRule<MainActivity> activityRule =
|
||||||
MainActivity.class);
|
new IntentsTestRule<>(MainActivity.class);
|
||||||
|
|
||||||
private Context targetContext;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup()
|
public void setup()
|
||||||
{
|
{
|
||||||
Context context = InstrumentationRegistry.getInstrumentation().getContext();
|
Context context =
|
||||||
|
InstrumentationRegistry.getInstrumentation().getContext();
|
||||||
sys = new SystemHelper(context);
|
sys = new SystemHelper(context);
|
||||||
sys.disableAllAnimations();
|
sys.disableAllAnimations();
|
||||||
sys.acquireWakeLock();
|
sys.acquireWakeLock();
|
||||||
sys.unlockScreen();
|
sys.unlockScreen();
|
||||||
|
|
||||||
targetContext = InstrumentationRegistry.getTargetContext();
|
Instrumentation.ActivityResult okResult =
|
||||||
|
new Instrumentation.ActivityResult(Activity.RESULT_OK,
|
||||||
Instrumentation.ActivityResult okResult = new Instrumentation.ActivityResult(
|
new Intent());
|
||||||
Activity.RESULT_OK, new Intent());
|
|
||||||
|
|
||||||
intending(hasAction(equalTo(Intent.ACTION_SEND))).respondWith(okResult);
|
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);
|
intending(hasAction(equalTo(Intent.ACTION_VIEW))).respondWith(okResult);
|
||||||
|
|
||||||
skipTutorial();
|
skipTutorial();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown()
|
|
||||||
{
|
|
||||||
sys.releaseWakeLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void skipTutorial()
|
public void skipTutorial()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
onView(allOf(withClassName(endsWith("AppCompatImageButton")),
|
onView(allOf(withClassName(endsWith("AppCompatImageButton")),
|
||||||
isDisplayed())).perform(click());
|
isDisplayed())).perform(click());
|
||||||
}
|
}
|
||||||
catch (NoMatchingViewException e)
|
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'
|
* User opens menu, clicks about, sees about screen.
|
||||||
* on the menu, selects the previously archived habits and then deletes them.
|
*/
|
||||||
|
@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
|
@Test
|
||||||
public void testArchiveHabits()
|
public void testArchiveHabits()
|
||||||
{
|
{
|
||||||
List<String> names = new LinkedList<>();
|
List<String> names = new LinkedList<>();
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
names.add(addHabit());
|
names.add(addHabit());
|
||||||
|
|
||||||
selectHabits(names);
|
selectHabits(names);
|
||||||
@@ -166,71 +184,26 @@ public class MainTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User opens the app, clicks the add button, types some bogus information, tries to save,
|
* User creates a habit, selects the habit, clicks edit button, changes some
|
||||||
* dialog displays an error.
|
* 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 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.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEditHabit()
|
public void testEditHabit()
|
||||||
{
|
{
|
||||||
String name = addHabit();
|
String name = addHabit();
|
||||||
|
|
||||||
onData(
|
onData(Matchers.allOf(is(instanceOf(HabitRecord.class)),
|
||||||
Matchers.allOf(is(instanceOf(HabitRecord.class)), HabitMatchers.withName(name)))
|
HabitMatchers.withName(name)))
|
||||||
.onChildView(withId(R.id.label))
|
.onChildView(withId(R.id.label))
|
||||||
.perform(longClick());
|
.perform(longClick());
|
||||||
|
|
||||||
clickMenuItem(R.string.edit);
|
clickMenuItem(R.string.edit);
|
||||||
|
|
||||||
String modifiedName = "Modified " + new Random().nextInt(10000);
|
String modifiedName = "Modified " + new Random().nextInt(10000);
|
||||||
typeHabitData(modifiedName, "", "1", "1");
|
typeHabitData(modifiedName, "", "1", "1");
|
||||||
|
|
||||||
onView(withId(R.id.buttonSave))
|
onView(withId(R.id.buttonSave)).perform(click());
|
||||||
.perform(click());
|
|
||||||
|
|
||||||
assertHabitExists(modifiedName);
|
assertHabitExists(modifiedName);
|
||||||
|
|
||||||
@@ -242,45 +215,85 @@ public class MainTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User creates a habit, opens statistics page, clicks button to edit history, adds some
|
* User creates a habit, opens statistics page, clicks button to edit
|
||||||
* checkmarks, closes dialog, sees the modified history calendar.
|
* history, adds some checkmarks, closes dialog, sees the modified history
|
||||||
|
* calendar.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEditHistory()
|
public void testEditHistory()
|
||||||
{
|
{
|
||||||
String name = addHabit();
|
String name = addHabit();
|
||||||
|
|
||||||
onData(
|
onData(Matchers.allOf(is(instanceOf(HabitRecord.class)),
|
||||||
Matchers.allOf(is(instanceOf(HabitRecord.class)), HabitMatchers.withName(name)))
|
HabitMatchers.withName(name)))
|
||||||
.onChildView(withId(R.id.label))
|
.onChildView(withId(R.id.label))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
|
|
||||||
openHistoryEditor();
|
openHistoryEditor();
|
||||||
onView(withClassName(endsWith("HabitHistoryView")))
|
onView(withClassName(endsWith("HabitHistoryView"))).perform(
|
||||||
.perform(clickAtRandomLocations(20));
|
clickAtRandomLocations(20));
|
||||||
|
|
||||||
pressBack();
|
pressBack();
|
||||||
onView(withId(R.id.historyView))
|
onView(withId(R.id.historyView)).perform(scrollTo(), swipeRight(),
|
||||||
.perform(scrollTo(), swipeRight(), swipeLeft());
|
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
|
@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);
|
clickMenuItem(R.string.settings);
|
||||||
}
|
clickSettingsItem("Generate bug report");
|
||||||
|
intended(hasAction(Intent.ACTION_SEND));
|
||||||
/**
|
|
||||||
* User opens menu, clicks about, sees about screen.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testAbout()
|
|
||||||
{
|
|
||||||
clickMenuItem(R.string.about);
|
|
||||||
onView(isRoot()).perform(swipeUp());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,57 +307,11 @@ public class MainTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User creates a habit, exports full backup, deletes the habit, restores backup, sees that the
|
* User opens menu, clicks settings, sees settings screen.
|
||||||
* previously created habit has appeared back.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExportImportDB()
|
public void testSettings()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
clickMenuItem(R.string.settings);
|
clickMenuItem(R.string.settings);
|
||||||
clickSettingsItem("Generate bug report");
|
|
||||||
intended(hasAction(Intent.ACTION_SEND));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,31 +19,22 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.io;
|
package org.isoron.uhabits.io;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.*;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.*;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.*;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.BaseAndroidTest;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.FileUtils;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
import org.junit.*;
|
||||||
import org.junit.Before;
|
import org.junit.runner.*;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.util.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@@ -128,10 +119,13 @@ public class ImportTest extends BaseAndroidTest
|
|||||||
assertThat(habit.getName(), equalTo("brush teeth"));
|
assertThat(habit.getName(), equalTo("brush teeth"));
|
||||||
assertThat(habit.getFreqNum(), equalTo(3));
|
assertThat(habit.getFreqNum(), equalTo(3));
|
||||||
assertThat(habit.getFreqDen(), equalTo(7));
|
assertThat(habit.getFreqDen(), equalTo(7));
|
||||||
assertThat(habit.getReminderHour(), equalTo(8));
|
assertThat(habit.hasReminder(), equalTo(true));
|
||||||
assertThat(habit.getReminderMin(), equalTo(0));
|
|
||||||
|
Reminder reminder = habit.getReminder();
|
||||||
|
assertThat(reminder.getHour(), equalTo(8));
|
||||||
|
assertThat(reminder.getMinute(), equalTo(0));
|
||||||
boolean[] reminderDays = {false, true, true, true, true, true, false};
|
boolean[] reminderDays = {false, true, true, true, true, true, false};
|
||||||
assertThat(habit.getReminderDays(), equalTo(DateUtils.packWeekdayList(reminderDays)));
|
assertThat(reminder.getDays(), equalTo(DateUtils.packWeekdayList(reminderDays)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ public class SQLiteCheckmarkListTest extends BaseAndroidTest
|
|||||||
checkmarks.invalidateNewerThan(0);
|
checkmarks.invalidateNewerThan(0);
|
||||||
|
|
||||||
List<Checkmark> list = new LinkedList<>();
|
List<Checkmark> list = new LinkedList<>();
|
||||||
list.add(new Checkmark(habit, 0, 0));
|
list.add(new Checkmark(0, 0));
|
||||||
list.add(new Checkmark(habit, 1, 1));
|
list.add(new Checkmark(1, 1));
|
||||||
list.add(new Checkmark(habit, 2, 2));
|
list.add(new Checkmark(2, 2));
|
||||||
|
|
||||||
checkmarks.add(list);
|
checkmarks.add(list);
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ import android.support.v4.content.LocalBroadcastManager;
|
|||||||
|
|
||||||
import org.isoron.uhabits.commands.CommandRunner;
|
import org.isoron.uhabits.commands.CommandRunner;
|
||||||
import org.isoron.uhabits.commands.ToggleRepetitionCommand;
|
import org.isoron.uhabits.commands.ToggleRepetitionCommand;
|
||||||
import org.isoron.uhabits.models.Checkmark;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
|
||||||
import org.isoron.uhabits.models.HabitList;
|
|
||||||
import org.isoron.uhabits.tasks.BaseTask;
|
import org.isoron.uhabits.tasks.BaseTask;
|
||||||
import org.isoron.uhabits.ui.habits.show.ShowHabitActivity;
|
import org.isoron.uhabits.ui.habits.show.ShowHabitActivity;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
import org.isoron.uhabits.utils.DateUtils;
|
||||||
@@ -192,11 +190,14 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
|
|||||||
|
|
||||||
private boolean checkWeekday(Intent intent, Habit habit)
|
private boolean checkWeekday(Intent intent, Habit habit)
|
||||||
{
|
{
|
||||||
|
if(!habit.hasReminder()) return false;
|
||||||
|
Reminder reminder = habit.getReminder();
|
||||||
|
|
||||||
Long timestamp =
|
Long timestamp =
|
||||||
intent.getLongExtra("timestamp", DateUtils.getStartOfToday());
|
intent.getLongExtra("timestamp", DateUtils.getStartOfToday());
|
||||||
|
|
||||||
boolean reminderDays[] =
|
boolean reminderDays[] =
|
||||||
DateUtils.unpackWeekdayList(habit.getReminderDays());
|
DateUtils.unpackWeekdayList(reminder.getDays());
|
||||||
int weekday = DateUtils.getWeekday(timestamp);
|
int weekday = DateUtils.getWeekday(timestamp);
|
||||||
|
|
||||||
return reminderDays[weekday];
|
return reminderDays[weekday];
|
||||||
|
|||||||
@@ -19,17 +19,16 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.io;
|
package org.isoron.uhabits.io;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.*;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.*;
|
||||||
import android.support.annotation.NonNull;
|
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.DatabaseUtils;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.util.*;
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that imports database files exported by Rewire.
|
* Class that imports database files exported by Rewire.
|
||||||
@@ -39,13 +38,14 @@ public class RewireDBImporter extends AbstractImporter
|
|||||||
@Override
|
@Override
|
||||||
public boolean canHandle(@NonNull File file) throws IOException
|
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 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=?",
|
Cursor c = db.rawQuery(
|
||||||
new String[]{"CHECKINS", "UNIT"});
|
"select count(*) from SQLITE_MASTER where name=? or name=?",
|
||||||
|
new String[]{ "CHECKINS", "UNIT" });
|
||||||
|
|
||||||
boolean result = (c.moveToFirst() && c.getInt(0) == 2);
|
boolean result = (c.moveToFirst() && c.getInt(0) == 2);
|
||||||
|
|
||||||
@@ -57,7 +57,8 @@ public class RewireDBImporter extends AbstractImporter
|
|||||||
@Override
|
@Override
|
||||||
public void importHabitsFromFile(@NonNull File file) throws IOException
|
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);
|
SQLiteDatabase.OPEN_READONLY);
|
||||||
|
|
||||||
DatabaseUtils.executeAsTransaction(new DatabaseUtils.Callback()
|
DatabaseUtils.executeAsTransaction(new DatabaseUtils.Callback()
|
||||||
@@ -72,14 +73,48 @@ public class RewireDBImporter extends AbstractImporter
|
|||||||
db.close();
|
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)
|
private void createHabits(SQLiteDatabase db)
|
||||||
{
|
{
|
||||||
Cursor c = null;
|
Cursor c = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
c = db.rawQuery("select _id, name, description, schedule, active_days, " +
|
c = db.rawQuery(
|
||||||
"repeating_count, days, period from habits", new String[0]);
|
"select _id, name, description, schedule, active_days, " +
|
||||||
|
"repeating_count, days, period from habits", new String[0]);
|
||||||
if (!c.moveToFirst()) return;
|
if (!c.moveToFirst()) return;
|
||||||
|
|
||||||
do
|
do
|
||||||
@@ -122,8 +157,7 @@ public class RewireDBImporter extends AbstractImporter
|
|||||||
createReminder(db, habit, id);
|
createReminder(db, habit, id);
|
||||||
createCheckmarks(db, habit, id);
|
createCheckmarks(db, habit, id);
|
||||||
|
|
||||||
}
|
} while (c.moveToNext());
|
||||||
while (c.moveToNext());
|
|
||||||
}
|
}
|
||||||
finally
|
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) };
|
String[] params = { Integer.toString(rewireHabitId) };
|
||||||
Cursor c = null;
|
Cursor c = null;
|
||||||
|
|
||||||
try
|
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;
|
if (!c.moveToFirst()) return;
|
||||||
int rewireReminder = Integer.parseInt(c.getString(0));
|
int rewireReminder = Integer.parseInt(c.getString(0));
|
||||||
@@ -147,49 +185,21 @@ public class RewireDBImporter extends AbstractImporter
|
|||||||
boolean reminderDays[] = new boolean[7];
|
boolean reminderDays[] = new boolean[7];
|
||||||
|
|
||||||
String activeDays[] = c.getString(1).split(",");
|
String activeDays[] = c.getString(1).split(",");
|
||||||
for(String d : activeDays)
|
for (String d : activeDays)
|
||||||
{
|
{
|
||||||
int idx = (Integer.parseInt(d) + 1) % 7;
|
int idx = (Integer.parseInt(d) + 1) % 7;
|
||||||
reminderDays[idx] = true;
|
reminderDays[idx] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
habit.setReminderDays(DateUtils.packWeekdayList(reminderDays));
|
int hour = rewireReminder / 60;
|
||||||
habit.setReminderHour(rewireReminder / 60);
|
int minute = rewireReminder % 60;
|
||||||
habit.setReminderMin(rewireReminder % 60);
|
Integer days = DateUtils.packWeekdayList(reminderDays);
|
||||||
|
|
||||||
|
Reminder reminder = new Reminder(hour, minute, days);
|
||||||
|
habit.setReminder(reminder);
|
||||||
habitList.update(habit);
|
habitList.update(habit);
|
||||||
}
|
}
|
||||||
finally
|
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();
|
if (c != null) c.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,15 +49,12 @@ public class Checkmark
|
|||||||
*/
|
*/
|
||||||
public static final int UNCHECKED = 0;
|
public static final int UNCHECKED = 0;
|
||||||
|
|
||||||
private final Habit habit;
|
|
||||||
|
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
|
|
||||||
private final int value;
|
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.timestamp = timestamp;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@@ -67,11 +64,6 @@ public class Checkmark
|
|||||||
return Long.signum(this.getTimestamp() - other.getTimestamp());
|
return Long.signum(this.getTimestamp() - other.getTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Habit getHabit()
|
|
||||||
{
|
|
||||||
return habit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimestamp()
|
public long getTimestamp()
|
||||||
{
|
{
|
||||||
return timestamp;
|
return timestamp;
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ public abstract class CheckmarkList
|
|||||||
{
|
{
|
||||||
int value = checks[i];
|
int value = checks[i];
|
||||||
long timestamp = to - i * day;
|
long timestamp = to - i * day;
|
||||||
checkmarks.add(new Checkmark(habit, timestamp, value));
|
checkmarks.add(new Checkmark(timestamp, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
add(checkmarks);
|
add(checkmarks);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.support.annotation.*;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.builder.*;
|
import org.apache.commons.lang3.builder.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -56,15 +55,6 @@ public class Habit
|
|||||||
@NonNull
|
@NonNull
|
||||||
private Integer color;
|
private Integer color;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Integer reminderHour;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Integer reminderMin;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private Integer reminderDays;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Integer highlight;
|
private Integer highlight;
|
||||||
|
|
||||||
@@ -83,6 +73,9 @@ public class Habit
|
|||||||
@NonNull
|
@NonNull
|
||||||
private CheckmarkList checkmarks;
|
private CheckmarkList checkmarks;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Reminder reminder;
|
||||||
|
|
||||||
private ModelObservable observable = new ModelObservable();
|
private ModelObservable observable = new ModelObservable();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -97,8 +90,6 @@ public class Habit
|
|||||||
{
|
{
|
||||||
HabitsApplication.getComponent().inject(this);
|
HabitsApplication.getComponent().inject(this);
|
||||||
|
|
||||||
reminderDays = DateUtils.ALL_WEEK_DAYS;
|
|
||||||
|
|
||||||
copyFrom(model);
|
copyFrom(model);
|
||||||
|
|
||||||
checkmarks = factory.buildCheckmarkList(this);
|
checkmarks = factory.buildCheckmarkList(this);
|
||||||
@@ -122,7 +113,6 @@ public class Habit
|
|||||||
this.archived = 0;
|
this.archived = 0;
|
||||||
this.freqDen = 7;
|
this.freqDen = 7;
|
||||||
this.freqNum = 3;
|
this.freqNum = 3;
|
||||||
this.reminderDays = DateUtils.ALL_WEEK_DAYS;
|
|
||||||
|
|
||||||
checkmarks = factory.buildCheckmarkList(this);
|
checkmarks = factory.buildCheckmarkList(this);
|
||||||
streaks = factory.buildStreakList(this);
|
streaks = factory.buildStreakList(this);
|
||||||
@@ -136,9 +126,7 @@ public class Habit
|
|||||||
*/
|
*/
|
||||||
public void clearReminder()
|
public void clearReminder()
|
||||||
{
|
{
|
||||||
reminderHour = null;
|
reminder = null;
|
||||||
reminderMin = null;
|
|
||||||
reminderDays = DateUtils.ALL_WEEK_DAYS;
|
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,9 +142,7 @@ public class Habit
|
|||||||
this.freqNum = model.getFreqNum();
|
this.freqNum = model.getFreqNum();
|
||||||
this.freqDen = model.getFreqDen();
|
this.freqDen = model.getFreqDen();
|
||||||
this.color = model.getColor();
|
this.color = model.getColor();
|
||||||
this.reminderHour = model.getReminderHour();
|
this.reminder = model.reminder;
|
||||||
this.reminderMin = model.getReminderMin();
|
|
||||||
this.reminderDays = model.getReminderDays();
|
|
||||||
this.highlight = model.getHighlight();
|
this.highlight = model.getHighlight();
|
||||||
this.archived = model.getArchived();
|
this.archived = model.getArchived();
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
@@ -193,6 +179,13 @@ public class Habit
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Reminder getReminder()
|
||||||
|
{
|
||||||
|
if(reminder == null) throw new IllegalStateException();
|
||||||
|
return reminder;
|
||||||
|
}
|
||||||
|
|
||||||
public void setColor(Integer color)
|
public void setColor(Integer color)
|
||||||
{
|
{
|
||||||
this.color = color;
|
this.color = color;
|
||||||
@@ -283,54 +276,6 @@ public class Habit
|
|||||||
return observable;
|
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.
|
* List of repetitions belonging to this habit.
|
||||||
*/
|
*/
|
||||||
@@ -376,7 +321,7 @@ public class Habit
|
|||||||
*/
|
*/
|
||||||
public boolean hasReminder()
|
public boolean hasReminder()
|
||||||
{
|
{
|
||||||
return (reminderHour != null && reminderMin != null);
|
return reminder != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -394,6 +339,11 @@ public class Habit
|
|||||||
this.archived = archived;
|
this.archived = archived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setReminder(@Nullable Reminder reminder)
|
||||||
|
{
|
||||||
|
this.reminder = reminder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
@@ -404,9 +354,6 @@ public class Habit
|
|||||||
.append("freqNum", freqNum)
|
.append("freqNum", freqNum)
|
||||||
.append("freqDen", freqDen)
|
.append("freqDen", freqDen)
|
||||||
.append("color", color)
|
.append("color", color)
|
||||||
.append("reminderHour", reminderHour)
|
|
||||||
.append("reminderMin", reminderMin)
|
|
||||||
.append("reminderDays", reminderDays)
|
|
||||||
.append("highlight", highlight)
|
.append("highlight", highlight)
|
||||||
.append("archived", archived)
|
.append("archived", archived)
|
||||||
.toString();
|
.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();
|
SQLiteHabitList habitList = SQLiteHabitList.getInstance();
|
||||||
Habit h = habitList.getById(habit.getId());
|
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")
|
@Table(name = "Habits")
|
||||||
public class HabitRecord extends Model implements SQLiteRecord
|
public class HabitRecord extends Model implements SQLiteRecord
|
||||||
{
|
{
|
||||||
public static final String HABIT_URI_FORMAT =
|
|
||||||
"content://org.isoron.uhabits/habit/%d";
|
|
||||||
|
|
||||||
public static String SELECT =
|
public static String SELECT =
|
||||||
"select id, color, description, freq_den, freq_num, " +
|
"select id, color, description, freq_den, freq_num, " +
|
||||||
"name, position, reminder_hour, reminder_min, " +
|
"name, position, reminder_hour, reminder_min, " +
|
||||||
@@ -148,9 +145,13 @@ public class HabitRecord extends Model implements SQLiteRecord
|
|||||||
this.freqNum = model.getFreqNum();
|
this.freqNum = model.getFreqNum();
|
||||||
this.freqDen = model.getFreqDen();
|
this.freqDen = model.getFreqDen();
|
||||||
this.color = model.getColor();
|
this.color = model.getColor();
|
||||||
this.reminderHour = model.getReminderHour();
|
if(model.hasReminder())
|
||||||
this.reminderMin = model.getReminderMin();
|
{
|
||||||
this.reminderDays = model.getReminderDays();
|
Reminder reminder = model.getReminder();
|
||||||
|
this.reminderHour = reminder.getHour();
|
||||||
|
this.reminderMin = reminder.getMinute();
|
||||||
|
this.reminderDays = reminder.getDays();
|
||||||
|
}
|
||||||
this.highlight = model.getHighlight();
|
this.highlight = model.getHighlight();
|
||||||
this.archived = model.getArchived();
|
this.archived = model.getArchived();
|
||||||
}
|
}
|
||||||
@@ -179,12 +180,15 @@ public class HabitRecord extends Model implements SQLiteRecord
|
|||||||
habit.setFreqNum(this.freqNum);
|
habit.setFreqNum(this.freqNum);
|
||||||
habit.setFreqDen(this.freqDen);
|
habit.setFreqDen(this.freqDen);
|
||||||
habit.setColor(this.color);
|
habit.setColor(this.color);
|
||||||
habit.setReminderHour(this.reminderHour);
|
|
||||||
habit.setReminderMin(this.reminderMin);
|
|
||||||
habit.setReminderDays(this.reminderDays);
|
|
||||||
habit.setHighlight(this.highlight);
|
habit.setHighlight(this.highlight);
|
||||||
habit.setArchived(this.archived);
|
habit.setArchived(this.archived);
|
||||||
habit.setId(this.getId());
|
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;
|
package org.isoron.uhabits.ui.habits.edit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.*;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.*;
|
||||||
import android.support.v7.app.AppCompatDialogFragment;
|
import android.support.v7.app.*;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.*;
|
||||||
import android.view.LayoutInflater;
|
import android.view.*;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import com.android.colorpicker.ColorPickerDialog;
|
import com.android.colorpicker.*;
|
||||||
import com.android.colorpicker.ColorPickerSwatch;
|
import com.android.datetimepicker.time.*;
|
||||||
import com.android.datetimepicker.time.RadialPickerLayout;
|
|
||||||
import com.android.datetimepicker.time.TimePickerDialog;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.HabitsApplication;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.commands.*;
|
||||||
import org.isoron.uhabits.commands.CommandRunner;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.models.HabitList;
|
|
||||||
import org.isoron.uhabits.utils.ColorUtils;
|
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
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.*;
|
||||||
import butterknife.OnClick;
|
|
||||||
import butterknife.OnItemSelected;
|
|
||||||
|
|
||||||
public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
||||||
{
|
{
|
||||||
@@ -90,8 +81,8 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
public void onFrequencySelected(int position)
|
public void onFrequencySelected(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position > 4) throw new IllegalArgumentException();
|
if (position < 0 || position > 4) throw new IllegalArgumentException();
|
||||||
int freqNums[] = {1, 1, 2, 5, 3};
|
int freqNums[] = { 1, 1, 2, 5, 3 };
|
||||||
int freqDens[] = {1, 7, 7, 7, 7};
|
int freqDens[] = { 1, 7, 7, 7, 7 };
|
||||||
modifiedHabit.setFreqNum(freqNums[position]);
|
modifiedHabit.setFreqNum(freqNums[position]);
|
||||||
modifiedHabit.setFreqDen(freqDens[position]);
|
modifiedHabit.setFreqDen(freqDens[position]);
|
||||||
helper.populateFrequencyFields(modifiedHabit);
|
helper.populateFrequencyFields(modifiedHabit);
|
||||||
@@ -105,9 +96,10 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
outState.putInt("color", modifiedHabit.getColor());
|
outState.putInt("color", modifiedHabit.getColor());
|
||||||
if (modifiedHabit.hasReminder())
|
if (modifiedHabit.hasReminder())
|
||||||
{
|
{
|
||||||
outState.putInt("reminderMin", modifiedHabit.getReminderMin());
|
Reminder reminder = modifiedHabit.getReminder();
|
||||||
outState.putInt("reminderHour", modifiedHabit.getReminderHour());
|
outState.putInt("reminderMin", reminder.getMinute());
|
||||||
outState.putInt("reminderDays", modifiedHabit.getReminderDays());
|
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 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)
|
@OnClick(R.id.buttonDiscard)
|
||||||
void onButtonDiscardClick()
|
void onButtonDiscardClick()
|
||||||
{
|
{
|
||||||
@@ -130,8 +144,9 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
|
|
||||||
if (modifiedHabit.hasReminder())
|
if (modifiedHabit.hasReminder())
|
||||||
{
|
{
|
||||||
defaultHour = modifiedHabit.getReminderHour();
|
Reminder reminder = modifiedHabit.getReminder();
|
||||||
defaultMin = modifiedHabit.getReminderMin();
|
defaultHour = reminder.getHour();
|
||||||
|
defaultMin = reminder.getMinute();
|
||||||
}
|
}
|
||||||
|
|
||||||
showTimePicker(defaultHour, defaultMin);
|
showTimePicker(defaultHour, defaultMin);
|
||||||
@@ -151,26 +166,15 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
void onWeekdayClick()
|
void onWeekdayClick()
|
||||||
{
|
{
|
||||||
if (!modifiedHabit.hasReminder()) return;
|
if (!modifiedHabit.hasReminder()) return;
|
||||||
|
Reminder reminder = modifiedHabit.getReminder();
|
||||||
|
|
||||||
WeekdayPickerDialog dialog = new WeekdayPickerDialog();
|
WeekdayPickerDialog dialog = new WeekdayPickerDialog();
|
||||||
dialog.setListener(new OnWeekdaysPickedListener());
|
dialog.setListener(new OnWeekdaysPickedListener());
|
||||||
dialog.setSelectedDays(
|
dialog.setSelectedDays(
|
||||||
DateUtils.unpackWeekdayList(modifiedHabit.getReminderDays()));
|
DateUtils.unpackWeekdayList(reminder.getDays()));
|
||||||
dialog.show(getFragmentManager(), "weekdayPicker");
|
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)
|
@OnClick(R.id.buttonPickColor)
|
||||||
void showColorPicker()
|
void showColorPicker()
|
||||||
{
|
{
|
||||||
@@ -222,9 +226,9 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onTimeSet(RadialPickerLayout view, int hour, int minute)
|
public void onTimeSet(RadialPickerLayout view, int hour, int minute)
|
||||||
{
|
{
|
||||||
modifiedHabit.setReminderHour(hour);
|
Reminder reminder =
|
||||||
modifiedHabit.setReminderMin(minute);
|
new Reminder(hour, minute, DateUtils.ALL_WEEK_DAYS);
|
||||||
modifiedHabit.setReminderDays(DateUtils.ALL_WEEK_DAYS);
|
modifiedHabit.setReminder(reminder);
|
||||||
helper.populateReminderFields(modifiedHabit);
|
helper.populateReminderFields(modifiedHabit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,8 +241,10 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
{
|
{
|
||||||
if (isSelectionEmpty(selectedDays)) Arrays.fill(selectedDays, true);
|
if (isSelectionEmpty(selectedDays)) Arrays.fill(selectedDays, true);
|
||||||
|
|
||||||
modifiedHabit.setReminderDays(
|
Reminder oldReminder = modifiedHabit.getReminder();
|
||||||
DateUtils.packWeekdayList(selectedDays));
|
modifiedHabit.setReminder(
|
||||||
|
new Reminder(oldReminder.getHour(), oldReminder.getMinute(),
|
||||||
|
DateUtils.packWeekdayList(selectedDays)));
|
||||||
helper.populateReminderFields(modifiedHabit);
|
helper.populateReminderFields(modifiedHabit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,20 +19,16 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.ui.habits.edit;
|
package org.isoron.uhabits.ui.habits.edit;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.*;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.*;
|
||||||
import android.view.View;
|
import android.view.*;
|
||||||
import android.view.ViewGroup;
|
import android.widget.*;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.ColorUtils;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.*;
|
||||||
import butterknife.ButterKnife;
|
|
||||||
|
|
||||||
public class BaseDialogHelper
|
public class BaseDialogHelper
|
||||||
{
|
{
|
||||||
@@ -71,6 +67,17 @@ public class BaseDialogHelper
|
|||||||
ButterKnife.bind(this, view);
|
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)
|
void parseFormIntoHabit(Habit habit)
|
||||||
{
|
{
|
||||||
habit.setName(tvName.getText().toString().trim());
|
habit.setName(tvName.getText().toString().trim());
|
||||||
@@ -87,23 +94,13 @@ public class BaseDialogHelper
|
|||||||
ColorUtils.getColor(frag.getContext(), paletteColor));
|
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")
|
@SuppressLint("SetTextI18n")
|
||||||
void populateFrequencyFields(Habit habit)
|
void populateFrequencyFields(Habit habit)
|
||||||
{
|
{
|
||||||
int quickSelectPosition = -1;
|
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)
|
else if (habit.getFreqNum() == 1 && habit.getFreqDen() == 7)
|
||||||
quickSelectPosition = 1;
|
quickSelectPosition = 1;
|
||||||
@@ -133,14 +130,16 @@ public class BaseDialogHelper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reminder reminder = habit.getReminder();
|
||||||
|
|
||||||
String time =
|
String time =
|
||||||
DateUtils.formatTime(frag.getContext(), habit.getReminderHour(),
|
DateUtils.formatTime(frag.getContext(), reminder.getHour(),
|
||||||
habit.getReminderMin());
|
reminder.getMinute());
|
||||||
tvReminderTime.setText(time);
|
tvReminderTime.setText(time);
|
||||||
llReminderDays.setVisibility(View.VISIBLE);
|
llReminderDays.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
boolean weekdays[] = DateUtils.unpackWeekdayList(
|
boolean weekdays[] =
|
||||||
habit.getReminderDays());
|
DateUtils.unpackWeekdayList(reminder.getDays());
|
||||||
tvReminderDays.setText(
|
tvReminderDays.setText(
|
||||||
DateUtils.formatWeekdayList(frag.getContext(), weekdays));
|
DateUtils.formatWeekdayList(frag.getContext(), weekdays));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,12 +101,19 @@ public class ShowHabitHelper
|
|||||||
|
|
||||||
TextView reminderLabel =
|
TextView reminderLabel =
|
||||||
(TextView) view.findViewById(R.id.reminderLabel);
|
(TextView) view.findViewById(R.id.reminderLabel);
|
||||||
if (fragment.habit.hasReminder()) reminderLabel.setText(
|
|
||||||
DateUtils.formatTime(fragment.getActivity(),
|
if (fragment.habit.hasReminder())
|
||||||
fragment.habit.getReminderHour(),
|
{
|
||||||
fragment.habit.getReminderMin()));
|
Reminder reminder = fragment.habit.getReminder();
|
||||||
else reminderLabel.setText(
|
reminderLabel.setText(
|
||||||
fragment.getResources().getString(R.string.reminder_off));
|
DateUtils.formatTime(fragment.getActivity(), reminder.getHour(),
|
||||||
|
reminder.getMinute()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reminderLabel.setText(
|
||||||
|
fragment.getResources().getString(R.string.reminder_off));
|
||||||
|
}
|
||||||
|
|
||||||
TextView frequencyLabel =
|
TextView frequencyLabel =
|
||||||
(TextView) view.findViewById(R.id.frequencyLabel);
|
(TextView) view.findViewById(R.id.frequencyLabel);
|
||||||
|
|||||||
@@ -19,29 +19,22 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.utils;
|
package org.isoron.uhabits.utils;
|
||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.*;
|
||||||
import android.app.PendingIntent;
|
import android.content.*;
|
||||||
import android.content.Context;
|
import android.media.*;
|
||||||
import android.content.Intent;
|
import android.net.*;
|
||||||
import android.content.SharedPreferences;
|
import android.os.*;
|
||||||
import android.media.Ringtone;
|
import android.preference.*;
|
||||||
import android.media.RingtoneManager;
|
import android.provider.*;
|
||||||
import android.net.Uri;
|
import android.support.annotation.*;
|
||||||
import android.os.Build;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.HabitBroadcastReceiver;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
|
||||||
import org.isoron.uhabits.models.HabitList;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.*;
|
||||||
import java.util.Calendar;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public abstract class ReminderUtils
|
public abstract class ReminderUtils
|
||||||
{
|
{
|
||||||
@@ -50,15 +43,14 @@ public abstract class ReminderUtils
|
|||||||
@Nullable Long reminderTime)
|
@Nullable Long reminderTime)
|
||||||
{
|
{
|
||||||
if (!habit.hasReminder()) return;
|
if (!habit.hasReminder()) return;
|
||||||
|
Reminder reminder = habit.getReminder();
|
||||||
|
|
||||||
if (reminderTime == null)
|
if (reminderTime == null)
|
||||||
{
|
{
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||||
//noinspection ConstantConditions
|
calendar.set(Calendar.HOUR_OF_DAY, reminder.getHour());
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, habit.getReminderHour());
|
calendar.set(Calendar.MINUTE, reminder.getMinute());
|
||||||
//noinspection ConstantConditions
|
|
||||||
calendar.set(Calendar.MINUTE, habit.getReminderMin());
|
|
||||||
calendar.set(Calendar.SECOND, 0);
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
|
||||||
reminderTime = calendar.getTimeInMillis();
|
reminderTime = calendar.getTimeInMillis();
|
||||||
|
|||||||
@@ -19,16 +19,11 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits;
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
import org.isoron.uhabits.models.HabitFixtures;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.HabitList;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.models.ModelFactory;
|
import org.junit.*;
|
||||||
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 javax.inject.Inject;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class BaseUnitTest
|
public class BaseUnitTest
|
||||||
{
|
{
|
||||||
@@ -38,9 +33,6 @@ public class BaseUnitTest
|
|||||||
@Inject
|
@Inject
|
||||||
protected Preferences prefs;
|
protected Preferences prefs;
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected HabitCardListCache listCache;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected ModelFactory modelFactory;
|
protected ModelFactory modelFactory;
|
||||||
|
|
||||||
|
|||||||
@@ -54,11 +54,7 @@ public class HabitListTest extends BaseUnitTest
|
|||||||
list.add(habit);
|
list.add(habit);
|
||||||
|
|
||||||
if (i % 3 == 0)
|
if (i % 3 == 0)
|
||||||
{
|
habit.setReminder(new Reminder(8, 30, DateUtils.ALL_WEEK_DAYS));
|
||||||
habit.setReminderDays(DateUtils.ALL_WEEK_DAYS);
|
|
||||||
habit.setReminderHour(8);
|
|
||||||
habit.setReminderMin(30);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
habits.get(0).setArchived(1);
|
habits.get(0).setArchived(1);
|
||||||
@@ -130,14 +126,14 @@ public class HabitListTest extends BaseUnitTest
|
|||||||
public void test_reorder()
|
public void test_reorder()
|
||||||
{
|
{
|
||||||
int operations[][] = {
|
int operations[][] = {
|
||||||
{5, 2}, {3, 7}, {4, 4}, {3, 2}
|
{ 5, 2 }, { 3, 7 }, { 4, 4 }, { 3, 2 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int expectedPosition[][] = {
|
int expectedPosition[][] = {
|
||||||
{0, 1, 3, 4, 5, 2, 6, 7, 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, 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, 7, 2, 4, 3, 5, 6, 8, 9 },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < operations.length; i++)
|
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.isoron.uhabits.utils.DateUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.core.IsNot.not;
|
import static org.hamcrest.core.IsNot.not;
|
||||||
@@ -38,12 +39,9 @@ public class HabitTest extends BaseUnitTest
|
|||||||
assertThat(habit.getArchived(), is(0));
|
assertThat(habit.getArchived(), is(0));
|
||||||
assertThat(habit.getHighlight(), is(0));
|
assertThat(habit.getHighlight(), is(0));
|
||||||
|
|
||||||
assertThat(habit.getReminderHour(), is(nullValue()));
|
assertThat(habit.hasReminder(), is(false));
|
||||||
assertThat(habit.getReminderMin(), is(nullValue()));
|
assertThat(habit.getStreaks(), is(not(nullValue())));
|
||||||
|
assertThat(habit.getScores(), is(not(nullValue())));
|
||||||
assertThat(habit.getReminderDays(), is(not(nullValue())));
|
|
||||||
// assertThat(habit.getStreaks(), is(not(nullValue())));
|
|
||||||
// assertThat(habit.getScores(), is(not(nullValue())));
|
|
||||||
assertThat(habit.getRepetitions(), is(not(nullValue())));
|
assertThat(habit.getRepetitions(), is(not(nullValue())));
|
||||||
assertThat(habit.getCheckmarks(), is(not(nullValue())));
|
assertThat(habit.getCheckmarks(), is(not(nullValue())));
|
||||||
}
|
}
|
||||||
@@ -57,9 +55,7 @@ public class HabitTest extends BaseUnitTest
|
|||||||
model.setColor(0);
|
model.setColor(0);
|
||||||
model.setFreqNum(10);
|
model.setFreqNum(10);
|
||||||
model.setFreqDen(20);
|
model.setFreqDen(20);
|
||||||
model.setReminderDays(1);
|
model.setReminder(new Reminder(8, 30, 1));
|
||||||
model.setReminderHour(8);
|
|
||||||
model.setReminderMin(30);
|
|
||||||
|
|
||||||
Habit habit = new Habit();
|
Habit habit = new Habit();
|
||||||
habit.copyFrom(model);
|
habit.copyFrom(model);
|
||||||
@@ -68,9 +64,7 @@ public class HabitTest extends BaseUnitTest
|
|||||||
assertThat(habit.getColor(), is(model.getColor()));
|
assertThat(habit.getColor(), is(model.getColor()));
|
||||||
assertThat(habit.getFreqNum(), is(model.getFreqNum()));
|
assertThat(habit.getFreqNum(), is(model.getFreqNum()));
|
||||||
assertThat(habit.getFreqDen(), is(model.getFreqDen()));
|
assertThat(habit.getFreqDen(), is(model.getFreqDen()));
|
||||||
assertThat(habit.getReminderDays(), is(model.getReminderDays()));
|
assertThat(habit.getReminder(), equalTo(model.getReminder()));
|
||||||
assertThat(habit.getReminderHour(), is(model.getReminderHour()));
|
|
||||||
assertThat(habit.getReminderMin(), is(model.getReminderMin()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
@@ -103,9 +97,7 @@ public class HabitTest extends BaseUnitTest
|
|||||||
Habit h = new Habit();
|
Habit h = new Habit();
|
||||||
assertThat(h.hasReminder(), is(false));
|
assertThat(h.hasReminder(), is(false));
|
||||||
|
|
||||||
h.setReminderDays(DateUtils.ALL_WEEK_DAYS);
|
h.setReminder(new Reminder(8, 30, DateUtils.ALL_WEEK_DAYS));
|
||||||
h.setReminderHour(8);
|
|
||||||
h.setReminderMin(30);
|
|
||||||
assertThat(h.hasReminder(), is(true));
|
assertThat(h.hasReminder(), is(true));
|
||||||
|
|
||||||
h.clearReminder();
|
h.clearReminder();
|
||||||
|
|||||||
@@ -19,15 +19,13 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.ui.habits.list.views;
|
package org.isoron.uhabits.ui.habits.list.views;
|
||||||
|
|
||||||
import org.isoron.uhabits.BaseUnitTest;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.ui.habits.list.controllers.HabitCardController;
|
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.junit.Before;
|
import org.junit.*;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
public class HabitCardControllerTest extends BaseUnitTest
|
public class HabitCardControllerTest extends BaseUnitTest
|
||||||
{
|
{
|
||||||
@@ -68,7 +66,7 @@ public class HabitCardControllerTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
long timestamp = DateUtils.getStartOfToday();
|
long timestamp = DateUtils.getStartOfToday();
|
||||||
controller.onToggle(habit, timestamp);
|
controller.onToggle(habit, timestamp);
|
||||||
verify(view).triggerRipple(0, 0);
|
verify(view).triggerRipple(timestamp);
|
||||||
verify(listener).onToggle(habit, timestamp);
|
verify(listener).onToggle(habit, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user