pull/175/head
RegularCoder 9 years ago
commit 04500791f2

@ -80,7 +80,8 @@ public class ListHabitsController
@NonNull ReminderScheduler reminderScheduler,
@NonNull TaskRunner taskRunner,
@NonNull WidgetUpdater widgetUpdater,
@NonNull ImportDataTaskFactory importTaskFactory,
@NonNull
ImportDataTaskFactory importTaskFactory,
@NonNull ExportCSVTaskFactory exportCSVFactory)
{
this.adapter = adapter;
@ -155,6 +156,18 @@ public class ListHabitsController
screen.showMessage(R.string.long_press_to_toggle);
}
public void onRepairDB()
{
taskRunner.execute(() -> {
for(Habit h : habitList) {
h.getCheckmarks().invalidateNewerThan(0);
h.getStreaks().invalidateNewerThan(0);
h.getScores().invalidateNewerThan(0);
}
screen.showMessage(R.string.database_repaired);
});
}
public void onSendBugReport()
{
try

@ -46,6 +46,8 @@ public class ListHabitsScreen extends BaseScreen
public static final int RESULT_EXPORT_DB = 3;
public static final int RESULT_REPAIR_DB = 5;
public static final int RESULT_IMPORT_DATA = 1;
@Nullable
@ -143,6 +145,10 @@ public class ListHabitsScreen extends BaseScreen
case RESULT_BUG_REPORT:
controller.onSendBugReport();
break;
case RESULT_REPAIR_DB:
controller.onRepairDB();
break;
}
}

@ -57,6 +57,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
setResultOnPreferenceClick("importData", ListHabitsScreen.RESULT_IMPORT_DATA);
setResultOnPreferenceClick("exportCSV", ListHabitsScreen.RESULT_EXPORT_CSV);
setResultOnPreferenceClick("exportDB", ListHabitsScreen.RESULT_EXPORT_DB);
setResultOnPreferenceClick("repairDB", ListHabitsScreen.RESULT_REPAIR_DB);
setResultOnPreferenceClick("bugReport", ListHabitsScreen.RESULT_BUG_REPORT);
updateRingtoneDescription();

@ -130,6 +130,8 @@ public abstract class CheckmarkList
*/
public final int[] getValues(long from, long to)
{
if(from > to) return new int[0];
List<Checkmark> checkmarks = getByInterval(from, to);
int values[] = new int[checkmarks.size()];

@ -0,0 +1,28 @@
/*
* 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.sqlite;
public class InconsistentDatabaseException extends RuntimeException
{
public InconsistentDatabaseException(String message)
{
super(message);
}
}

@ -28,6 +28,7 @@ import com.activeandroid.query.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.models.sqlite.records.*;
import org.isoron.uhabits.utils.*;
import org.jetbrains.annotations.*;
import java.util.*;
@ -99,6 +100,15 @@ public class SQLiteCheckmarkList extends CheckmarkList
List<CheckmarkRecord> records = sqlite.query(query, params);
for (CheckmarkRecord record : records) record.habit = habitRecord;
int nDays = DateUtils.getDaysBetween(fromTimestamp, toTimestamp) + 1;
if (records.size() != nDays)
{
throw new InconsistentDatabaseException(
String.format("habit=%s, %d expected, %d found",
habit.getName(), nDays, records.size()));
}
return toCheckmarks(records);
}

@ -21,6 +21,7 @@ package org.isoron.uhabits.notifications;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.support.annotation.*;
import android.support.v4.app.*;
import android.support.v4.app.NotificationCompat.*;
@ -102,7 +103,7 @@ public class NotificationTray
{
DeleteHabitsCommand deleteCommand = (DeleteHabitsCommand) command;
List<Habit> deleted = deleteCommand.getHabits();
for(Habit habit : deleted)
for (Habit habit : deleted)
cancel(habit);
}
}
@ -191,9 +192,24 @@ public class NotificationTray
if (!shouldShowReminderToday()) return;
if (!habit.hasReminder()) return;
WearableExtender wearableExtender =
new WearableExtender().setBackground(
decodeResource(context.getResources(), R.drawable.stripe));
Action checkAction = new Action(R.drawable.ic_action_check,
context.getString(R.string.check),
pendingIntents.addCheckmark(habit, timestamp));
Action snoozeAction = new Action(R.drawable.ic_action_snooze,
context.getString(R.string.snooze),
pendingIntents.snoozeNotification(habit));
Bitmap wearableBg =
decodeResource(context.getResources(), R.drawable.stripe);
// Even though the set of actions is the same on the phone and
// on the watch, Pebble requires us to add them to the
// WearableExtender.
WearableExtender wearableExtender = new WearableExtender()
.setBackground(wearableBg)
.addAction(checkAction)
.addAction(snoozeAction);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
@ -201,12 +217,8 @@ public class NotificationTray
.setContentText(habit.getDescription())
.setContentIntent(pendingIntents.showHabit(habit))
.setDeleteIntent(pendingIntents.dismissNotification(habit))
.addAction(R.drawable.ic_action_check,
context.getString(R.string.check),
pendingIntents.addCheckmark(habit, timestamp))
.addAction(R.drawable.ic_action_snooze,
context.getString(R.string.snooze),
pendingIntents.snoozeNotification(habit))
.addAction(checkAction)
.addAction(snoozeAction)
.setSound(getRingtoneUri(context))
.extend(wearableExtender)
.setWhen(reminderTime)

@ -189,4 +189,6 @@
<string name="sticky_notifications">Make notifications sticky</string>
<string name="sticky_notifications_description">Prevents notifications from being swiped away.</string>
<string name="repair_database">Repair database</string>
<string name="database_repaired">Database repaired.</string>
</resources>

@ -100,8 +100,11 @@
<Preference
android:key="bugReport"
android:title="@string/generate_bug_report">
</Preference>
android:title="@string/generate_bug_report"/>
<Preference
android:key="repairDB"
android:title="@string/repair_database"/>
</PreferenceCategory>

@ -139,9 +139,12 @@ public class DateUtilsTest extends BaseUnitTest
public void test_getDaysBetween()
{
long t1 = timestamp(2016, JANUARY, 1);
long t2 = timestamp(2016, DECEMBER, 31);
int expected = 365;
assertThat(DateUtils.getDaysBetween(t1, t2), equalTo(expected));
assertThat(DateUtils.getDaysBetween(t2, t1), equalTo(expected));
long t2 = timestamp(2016, JANUARY, 10);
long t3 = timestamp(2016, DECEMBER, 31);
assertThat(DateUtils.getDaysBetween(t1, t1), equalTo(0));
assertThat(DateUtils.getDaysBetween(t1, t2), equalTo(9));
assertThat(DateUtils.getDaysBetween(t1, t3), equalTo(365));
assertThat(DateUtils.getDaysBetween(t3, t1), equalTo(365));
}
}

Loading…
Cancel
Save