mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| be3d7145ab | |||
| cf66587644 | |||
| 0dc9ec2e5f | |||
| 0a375ded96 | |||
| fa5d6f8fee | |||
| 534e6c2d9d | |||
| b6501c9a29 | |||
| 238a1c724d | |||
| 34ca9d17a2 | |||
| e844390614 | |||
| 5e00d07b73 | |||
| 28b6ae7014 | |||
| 2a1bf5fc2e | |||
| ef7483f9dc | |||
| bbb9ed8f99 | |||
| c49d576871 | |||
| bc66ae4f7a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,3 +21,4 @@ docs/
|
|||||||
gen/
|
gen/
|
||||||
local.properties
|
local.properties
|
||||||
crowdin.yaml
|
crowdin.yaml
|
||||||
|
local
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### 1.7.3 (May 30, 2017)
|
||||||
|
|
||||||
|
* Improve performance of 'sort by score'
|
||||||
|
* Other minor bug fixes
|
||||||
|
|
||||||
|
### 1.7.2 (May 27, 2017)
|
||||||
|
|
||||||
|
* Fix crash at startup
|
||||||
|
|
||||||
### 1.7.1 (May 21, 2017)
|
### 1.7.1 (May 21, 2017)
|
||||||
|
|
||||||
* Fix crash (BadParcelableException)
|
* Fix crash (BadParcelableException)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.content.*;
|
|||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.test.*;
|
import android.support.test.*;
|
||||||
|
import android.util.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.preferences.*;
|
import org.isoron.uhabits.preferences.*;
|
||||||
@@ -31,6 +32,7 @@ import org.isoron.uhabits.tasks.*;
|
|||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
@@ -132,4 +134,18 @@ public class BaseAndroidTest
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void startTracing()
|
||||||
|
{
|
||||||
|
File dir = FileUtils.getFilesDir(targetContext, "Profile");
|
||||||
|
assertNotNull(dir);
|
||||||
|
String tracePath = dir.getAbsolutePath() + "/performance.trace";
|
||||||
|
Log.d("PerformanceTest", String.format("Saving trace file to %s", tracePath));
|
||||||
|
Debug.startMethodTracingSampling(tracePath, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void stopTracing()
|
||||||
|
{
|
||||||
|
Debug.stopMethodTracing();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Á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.performance;
|
||||||
|
|
||||||
|
import android.support.test.filters.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
@MediumTest
|
||||||
|
public class PerformanceTest extends BaseAndroidTest
|
||||||
|
{
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
habit = fixtures.createLongHabit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 1000)
|
||||||
|
public void testRepeatedGetTodayValue()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100000; i++)
|
||||||
|
{
|
||||||
|
habit.getScores().getTodayValue();
|
||||||
|
habit.getCheckmarks().getTodayValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
<manifest
|
<manifest
|
||||||
package="org.isoron.uhabits"
|
package="org.isoron.uhabits"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:versionCode="28"
|
android:versionCode="31"
|
||||||
android:versionName="1.7.1">
|
android:versionName="1.7.4">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
|
|
||||||
|
|||||||
@@ -20,24 +20,27 @@
|
|||||||
package org.isoron.uhabits.activities.common.views;
|
package org.isoron.uhabits.activities.common.views;
|
||||||
|
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
import android.support.v4.os.*;
|
||||||
|
|
||||||
public class BundleSavedState extends android.support.v4.view.AbsSavedState
|
public class BundleSavedState extends android.support.v4.view.AbsSavedState
|
||||||
{
|
{
|
||||||
public static final Parcelable.Creator<BundleSavedState> CREATOR =
|
public static final Parcelable.Creator<BundleSavedState> CREATOR =
|
||||||
new Parcelable.Creator<BundleSavedState>()
|
ParcelableCompat.newCreator(
|
||||||
{
|
new ParcelableCompatCreatorCallbacks<BundleSavedState>()
|
||||||
@Override
|
|
||||||
public BundleSavedState createFromParcel(Parcel source)
|
|
||||||
{
|
{
|
||||||
return new BundleSavedState(source);
|
@Override
|
||||||
}
|
public BundleSavedState createFromParcel(Parcel source,
|
||||||
|
ClassLoader loader)
|
||||||
|
{
|
||||||
|
return new BundleSavedState(source, loader);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BundleSavedState[] newArray(int size)
|
public BundleSavedState[] newArray(int size)
|
||||||
{
|
{
|
||||||
return new BundleSavedState[size];
|
return new BundleSavedState[size];
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
public final Bundle bundle;
|
public final Bundle bundle;
|
||||||
|
|
||||||
@@ -47,10 +50,10 @@ public class BundleSavedState extends android.support.v4.view.AbsSavedState
|
|||||||
this.bundle = bundle;
|
this.bundle = bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BundleSavedState(Parcel source)
|
public BundleSavedState(Parcel source, ClassLoader loader)
|
||||||
{
|
{
|
||||||
super(source);
|
super(source, loader);
|
||||||
this.bundle = source.readBundle(getClass().getClassLoader());
|
this.bundle = source.readBundle(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ public abstract class ScrollableChart extends View
|
|||||||
@Override
|
@Override
|
||||||
public void onRestoreInstanceState(Parcelable state)
|
public void onRestoreInstanceState(Parcelable state)
|
||||||
{
|
{
|
||||||
|
if(!(state instanceof BundleSavedState))
|
||||||
|
{
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BundleSavedState bss = (BundleSavedState) state;
|
BundleSavedState bss = (BundleSavedState) state;
|
||||||
int x = bss.bundle.getInt("x");
|
int x = bss.bundle.getInt("x");
|
||||||
int y = bss.bundle.getInt("y");
|
int y = bss.bundle.getInt("y");
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import java.util.*;
|
|||||||
|
|
||||||
import butterknife.*;
|
import butterknife.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.activities.ThemeSwitcher.*;
|
||||||
|
|
||||||
public abstract class BaseDialog extends AppCompatDialogFragment
|
public abstract class BaseDialog extends AppCompatDialogFragment
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -65,7 +67,13 @@ public abstract class BaseDialog extends AppCompatDialogFragment
|
|||||||
@Override
|
@Override
|
||||||
public int getTheme()
|
public int getTheme()
|
||||||
{
|
{
|
||||||
return R.style.DialogWithTitle;
|
AppComponent component =
|
||||||
|
((HabitsApplication) getContext().getApplicationContext()).getComponent();
|
||||||
|
|
||||||
|
if(component.getPreferences().getTheme() == THEME_LIGHT)
|
||||||
|
return R.style.DialogWithTitle;
|
||||||
|
else
|
||||||
|
return R.style.DarkDialogWithTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -153,6 +153,12 @@ public class HabitCardListView extends RecyclerView
|
|||||||
@Override
|
@Override
|
||||||
protected void onRestoreInstanceState(Parcelable state)
|
protected void onRestoreInstanceState(Parcelable state)
|
||||||
{
|
{
|
||||||
|
if(!(state instanceof BundleSavedState))
|
||||||
|
{
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BundleSavedState bss = (BundleSavedState) state;
|
BundleSavedState bss = (BundleSavedState) state;
|
||||||
dataOffset = bss.bundle.getInt("dataOffset");
|
dataOffset = bss.bundle.getInt("dataOffset");
|
||||||
super.onRestoreInstanceState(bss.getSuperState());
|
super.onRestoreInstanceState(bss.getSuperState());
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public abstract class CheckmarkList
|
|||||||
*
|
*
|
||||||
* @return value of today's checkmark
|
* @return value of today's checkmark
|
||||||
*/
|
*/
|
||||||
public final int getTodayValue()
|
public int getTodayValue()
|
||||||
{
|
{
|
||||||
Checkmark today = getToday();
|
Checkmark today = getToday();
|
||||||
if (today != null) return today.getValue();
|
if (today != null) return today.getValue();
|
||||||
@@ -192,7 +192,7 @@ public abstract class CheckmarkList
|
|||||||
Checkmark newest = getNewestComputed();
|
Checkmark newest = getNewestComputed();
|
||||||
Checkmark oldest = getOldestComputed();
|
Checkmark oldest = getOldestComputed();
|
||||||
|
|
||||||
if (newest == null)
|
if (newest == null || oldest == null)
|
||||||
{
|
{
|
||||||
forceRecompute(from, to);
|
forceRecompute(from, to);
|
||||||
}
|
}
|
||||||
@@ -208,6 +208,7 @@ public abstract class CheckmarkList
|
|||||||
*
|
*
|
||||||
* @return oldest checkmark already computed
|
* @return oldest checkmark already computed
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected abstract Checkmark getOldestComputed();
|
protected abstract Checkmark getOldestComputed();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,5 +286,6 @@ public abstract class CheckmarkList
|
|||||||
*
|
*
|
||||||
* @return newest checkmark already computed
|
* @return newest checkmark already computed
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected abstract Checkmark getNewestComputed();
|
protected abstract Checkmark getNewestComputed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
* @param timestamp the timestamp of a day
|
* @param timestamp the timestamp of a day
|
||||||
* @return score value for that day
|
* @return score value for that day
|
||||||
*/
|
*/
|
||||||
public final int getValue(long timestamp)
|
public final synchronized int getValue(long timestamp)
|
||||||
{
|
{
|
||||||
compute(timestamp, timestamp);
|
compute(timestamp, timestamp);
|
||||||
Score s = getComputedByTimestamp(timestamp);
|
Score s = getComputedByTimestamp(timestamp);
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class MemoryCheckmarkList extends CheckmarkList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
protected Checkmark getOldestComputed()
|
protected Checkmark getOldestComputed()
|
||||||
{
|
{
|
||||||
if(list.isEmpty()) return null;
|
if(list.isEmpty()) return null;
|
||||||
@@ -79,6 +80,7 @@ public class MemoryCheckmarkList extends CheckmarkList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
protected Checkmark getNewestComputed()
|
protected Checkmark getNewestComputed()
|
||||||
{
|
{
|
||||||
if(list.isEmpty()) return null;
|
if(list.isEmpty()) return null;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.support.annotation.*;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.activeandroid.*;
|
import com.activeandroid.*;
|
||||||
import com.activeandroid.query.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.sqlite.records.*;
|
import org.isoron.uhabits.models.sqlite.records.*;
|
||||||
@@ -38,38 +37,54 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class SQLiteCheckmarkList extends CheckmarkList
|
public class SQLiteCheckmarkList extends CheckmarkList
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final String ADD_QUERY =
|
||||||
|
"insert into Checkmarks(habit, timestamp, value) values (?,?,?)";
|
||||||
|
|
||||||
|
private static final String INVALIDATE_QUERY =
|
||||||
|
"delete from Checkmarks where habit = ? and timestamp >= ?";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private HabitRecord habitRecord;
|
private HabitRecord habitRecord;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SQLiteUtils<CheckmarkRecord> sqlite;
|
private final SQLiteUtils<CheckmarkRecord> sqlite;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private CachedData cache;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final SQLiteStatement invalidateStatement;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final SQLiteStatement addStatement;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final SQLiteDatabase db;
|
||||||
|
|
||||||
public SQLiteCheckmarkList(Habit habit)
|
public SQLiteCheckmarkList(Habit habit)
|
||||||
{
|
{
|
||||||
super(habit);
|
super(habit);
|
||||||
sqlite = new SQLiteUtils<>(CheckmarkRecord.class);
|
sqlite = new SQLiteUtils<>(CheckmarkRecord.class);
|
||||||
|
|
||||||
|
db = Cache.openDatabase();
|
||||||
|
addStatement = db.compileStatement(ADD_QUERY);
|
||||||
|
invalidateStatement = db.compileStatement(INVALIDATE_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(List<Checkmark> checkmarks)
|
public void add(List<Checkmark> checkmarks)
|
||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
|
|
||||||
String query =
|
|
||||||
"insert into Checkmarks(habit, timestamp, value) values (?,?,?)";
|
|
||||||
|
|
||||||
SQLiteDatabase db = Cache.openDatabase();
|
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SQLiteStatement statement = db.compileStatement(query);
|
|
||||||
|
|
||||||
for (Checkmark c : checkmarks)
|
for (Checkmark c : checkmarks)
|
||||||
{
|
{
|
||||||
statement.bindLong(1, habit.getId());
|
addStatement.bindLong(1, habit.getId());
|
||||||
statement.bindLong(2, c.getTimestamp());
|
addStatement.bindLong(2, c.getTimestamp());
|
||||||
statement.bindLong(3, c.getValue());
|
addStatement.bindLong(3, c.getValue());
|
||||||
statement.execute();
|
addStatement.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
@@ -87,8 +102,7 @@ public class SQLiteCheckmarkList extends CheckmarkList
|
|||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
compute(fromTimestamp, toTimestamp);
|
compute(fromTimestamp, toTimestamp);
|
||||||
|
|
||||||
String query = "select habit, timestamp, value " +
|
String query = "select habit, timestamp, value from checkmarks " +
|
||||||
"from checkmarks " +
|
|
||||||
"where habit = ? and timestamp >= ? and timestamp <= ? " +
|
"where habit = ? and timestamp >= ? and timestamp <= ? " +
|
||||||
"order by timestamp desc";
|
"order by timestamp desc";
|
||||||
|
|
||||||
@@ -112,15 +126,22 @@ public class SQLiteCheckmarkList extends CheckmarkList
|
|||||||
return toCheckmarks(records);
|
return toCheckmarks(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTodayValue()
|
||||||
|
{
|
||||||
|
if (cache == null || cache.expired())
|
||||||
|
cache = new CachedData(super.getTodayValue());
|
||||||
|
|
||||||
|
return cache.todayValue;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateNewerThan(long timestamp)
|
public void invalidateNewerThan(long timestamp)
|
||||||
{
|
{
|
||||||
new Delete()
|
cache = null;
|
||||||
.from(CheckmarkRecord.class)
|
invalidateStatement.bindLong(1, habit.getId());
|
||||||
.where("habit = ?", habit.getId())
|
invalidateStatement.bindLong(2, timestamp);
|
||||||
.and("timestamp >= ?", timestamp)
|
invalidateStatement.execute();
|
||||||
.execute();
|
|
||||||
|
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,10 +150,8 @@ public class SQLiteCheckmarkList extends CheckmarkList
|
|||||||
protected Checkmark getNewestComputed()
|
protected Checkmark getNewestComputed()
|
||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
String query = "select habit, timestamp, value " +
|
String query = "select habit, timestamp, value from checkmarks " +
|
||||||
"from checkmarks " +
|
"where habit = ? " + "order by timestamp desc " +
|
||||||
"where habit = ? " +
|
|
||||||
"order by timestamp desc " +
|
|
||||||
"limit 1";
|
"limit 1";
|
||||||
|
|
||||||
String params[] = { Long.toString(habit.getId()) };
|
String params[] = { Long.toString(habit.getId()) };
|
||||||
@@ -140,13 +159,12 @@ public class SQLiteCheckmarkList extends CheckmarkList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
protected Checkmark getOldestComputed()
|
protected Checkmark getOldestComputed()
|
||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
String query = "select habit, timestamp, value " +
|
String query = "select habit, timestamp, value from checkmarks " +
|
||||||
"from checkmarks " +
|
"where habit = ? " + "order by timestamp asc " +
|
||||||
"where habit = ? " +
|
|
||||||
"order by timestamp asc " +
|
|
||||||
"limit 1";
|
"limit 1";
|
||||||
|
|
||||||
String params[] = { Long.toString(habit.getId()) };
|
String params[] = { Long.toString(habit.getId()) };
|
||||||
@@ -179,4 +197,22 @@ public class SQLiteCheckmarkList extends CheckmarkList
|
|||||||
for (CheckmarkRecord r : records) checkmarks.add(r.toCheckmark());
|
for (CheckmarkRecord r : records) checkmarks.add(r.toCheckmark());
|
||||||
return checkmarks;
|
return checkmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class CachedData
|
||||||
|
{
|
||||||
|
int todayValue;
|
||||||
|
|
||||||
|
private long today;
|
||||||
|
|
||||||
|
CachedData(int todayValue)
|
||||||
|
{
|
||||||
|
this.todayValue = todayValue;
|
||||||
|
this.today = DateUtils.getStartOfToday();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean expired()
|
||||||
|
{
|
||||||
|
return today != DateUtils.getStartOfToday();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Habit> toList()
|
protected synchronized List<Habit> toList()
|
||||||
{
|
{
|
||||||
String query = buildSelectQuery();
|
String query = buildSelectQuery();
|
||||||
List<HabitRecord> recordList = sqlite.query(query, null);
|
List<HabitRecord> recordList = sqlite.query(query, null);
|
||||||
@@ -270,9 +270,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
for (HabitRecord record : recordList)
|
for (HabitRecord record : recordList)
|
||||||
{
|
{
|
||||||
Habit habit = getById(record.getId());
|
Habit habit = getById(record.getId());
|
||||||
if (habit == null)
|
if (habit == null) continue;
|
||||||
throw new RuntimeException("habit not in database");
|
|
||||||
|
|
||||||
if (!filter.matches(habit)) continue;
|
if (!filter.matches(habit)) continue;
|
||||||
habits.add(habit);
|
habits.add(habit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,12 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.models.sqlite;
|
package org.isoron.uhabits.models.sqlite;
|
||||||
|
|
||||||
import android.database.DatabaseUtils;
|
import android.database.*;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.activeandroid.Cache;
|
import com.activeandroid.*;
|
||||||
import com.activeandroid.query.*;
|
import com.activeandroid.query.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
@@ -43,10 +43,16 @@ public class SQLiteRepetitionList extends RepetitionList
|
|||||||
@Nullable
|
@Nullable
|
||||||
private HabitRecord habitRecord;
|
private HabitRecord habitRecord;
|
||||||
|
|
||||||
|
private SQLiteStatement addStatement;
|
||||||
|
|
||||||
public SQLiteRepetitionList(@NonNull Habit habit)
|
public SQLiteRepetitionList(@NonNull Habit habit)
|
||||||
{
|
{
|
||||||
super(habit);
|
super(habit);
|
||||||
sqlite = new SQLiteUtils<>(RepetitionRecord.class);
|
sqlite = new SQLiteUtils<>(RepetitionRecord.class);
|
||||||
|
|
||||||
|
SQLiteDatabase db = Cache.openDatabase();
|
||||||
|
String addQuery = "insert into repetitions(habit, timestamp) values (?,?)";
|
||||||
|
addStatement = db.compileStatement(addQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,11 +67,9 @@ public class SQLiteRepetitionList extends RepetitionList
|
|||||||
public void add(Repetition rep)
|
public void add(Repetition rep)
|
||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
|
addStatement.bindLong(1, habit.getId());
|
||||||
RepetitionRecord record = new RepetitionRecord();
|
addStatement.bindLong(2, rep.getTimestamp());
|
||||||
record.copyFrom(rep);
|
addStatement.execute();
|
||||||
record.habit = habitRecord;
|
|
||||||
record.save();
|
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ import android.support.annotation.*;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.activeandroid.*;
|
import com.activeandroid.*;
|
||||||
import com.activeandroid.query.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.sqlite.records.*;
|
import org.isoron.uhabits.models.sqlite.records.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.jetbrains.annotations.*;
|
import org.jetbrains.annotations.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -37,12 +37,29 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class SQLiteScoreList extends ScoreList
|
public class SQLiteScoreList extends ScoreList
|
||||||
{
|
{
|
||||||
|
public static final String ADD_QUERY =
|
||||||
|
"insert into Score(habit, timestamp, score) values (?,?,?)";
|
||||||
|
|
||||||
|
public static final String INVALIDATE_QUERY =
|
||||||
|
"delete from Score where habit = ? and timestamp >= ?";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private HabitRecord habitRecord;
|
private HabitRecord habitRecord;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SQLiteUtils<ScoreRecord> sqlite;
|
private final SQLiteUtils<ScoreRecord> sqlite;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final SQLiteStatement invalidateStatement;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final SQLiteStatement addStatement;
|
||||||
|
|
||||||
|
private final SQLiteDatabase db;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private CachedData cache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ScoreList associated with the given habit.
|
* Constructs a new ScoreList associated with the given habit.
|
||||||
*
|
*
|
||||||
@@ -52,28 +69,25 @@ public class SQLiteScoreList extends ScoreList
|
|||||||
{
|
{
|
||||||
super(habit);
|
super(habit);
|
||||||
sqlite = new SQLiteUtils<>(ScoreRecord.class);
|
sqlite = new SQLiteUtils<>(ScoreRecord.class);
|
||||||
|
|
||||||
|
db = Cache.openDatabase();
|
||||||
|
addStatement = db.compileStatement(ADD_QUERY);
|
||||||
|
invalidateStatement = db.compileStatement(INVALIDATE_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(List<Score> scores)
|
public void add(List<Score> scores)
|
||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
String query =
|
|
||||||
"insert into Score(habit, timestamp, score) values (?,?,?)";
|
|
||||||
|
|
||||||
SQLiteDatabase db = Cache.openDatabase();
|
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SQLiteStatement statement = db.compileStatement(query);
|
|
||||||
|
|
||||||
for (Score s : scores)
|
for (Score s : scores)
|
||||||
{
|
{
|
||||||
statement.bindLong(1, habit.getId());
|
addStatement.bindLong(1, habit.getId());
|
||||||
statement.bindLong(2, s.getTimestamp());
|
addStatement.bindLong(2, s.getTimestamp());
|
||||||
statement.bindLong(3, s.getValue());
|
addStatement.bindLong(3, s.getValue());
|
||||||
statement.execute();
|
addStatement.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
@@ -91,15 +105,14 @@ public class SQLiteScoreList extends ScoreList
|
|||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
compute(fromTimestamp, toTimestamp);
|
compute(fromTimestamp, toTimestamp);
|
||||||
|
|
||||||
String query = "select habit, timestamp, score " +
|
String query = "select habit, timestamp, score from Score " +
|
||||||
"from Score " +
|
"where habit = ? and timestamp >= ? and timestamp <= ? " +
|
||||||
"where habit = ? and timestamp >= ? and timestamp <= ? " +
|
"order by timestamp desc";
|
||||||
"order by timestamp desc";
|
|
||||||
|
|
||||||
String params[] = {
|
String params[] = {
|
||||||
Long.toString(habit.getId()),
|
Long.toString(habit.getId()),
|
||||||
Long.toString(fromTimestamp),
|
Long.toString(fromTimestamp),
|
||||||
Long.toString(toTimestamp)
|
Long.toString(toTimestamp)
|
||||||
};
|
};
|
||||||
|
|
||||||
List<ScoreRecord> records = sqlite.query(query, params);
|
List<ScoreRecord> records = sqlite.query(query, params);
|
||||||
@@ -123,15 +136,22 @@ public class SQLiteScoreList extends ScoreList
|
|||||||
return getScoreFromQuery(query, params);
|
return getScoreFromQuery(query, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTodayValue()
|
||||||
|
{
|
||||||
|
if (cache == null || cache.expired())
|
||||||
|
cache = new CachedData(super.getTodayValue());
|
||||||
|
|
||||||
|
return cache.todayValue;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateNewerThan(long timestamp)
|
public void invalidateNewerThan(long timestamp)
|
||||||
{
|
{
|
||||||
new Delete()
|
cache = null;
|
||||||
.from(ScoreRecord.class)
|
invalidateStatement.bindLong(1, habit.getId());
|
||||||
.where("habit = ?", habit.getId())
|
invalidateStatement.bindLong(2, timestamp);
|
||||||
.and("timestamp >= ?", timestamp)
|
invalidateStatement.execute();
|
||||||
.execute();
|
|
||||||
|
|
||||||
getObservable().notifyListeners();
|
getObservable().notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,8 +179,7 @@ public class SQLiteScoreList extends ScoreList
|
|||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
String query = "select habit, timestamp, score from Score " +
|
String query = "select habit, timestamp, score from Score " +
|
||||||
"where habit = ? order by timestamp desc " +
|
"where habit = ? order by timestamp desc limit 1";
|
||||||
"limit 1";
|
|
||||||
|
|
||||||
String params[] = { Long.toString(habit.getId()) };
|
String params[] = { Long.toString(habit.getId()) };
|
||||||
return getScoreFromQuery(query, params);
|
return getScoreFromQuery(query, params);
|
||||||
@@ -172,8 +191,7 @@ public class SQLiteScoreList extends ScoreList
|
|||||||
{
|
{
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
String query = "select habit, timestamp, score from Score " +
|
String query = "select habit, timestamp, score from Score " +
|
||||||
"where habit = ? order by timestamp asc " +
|
"where habit = ? order by timestamp asc limit 1";
|
||||||
"limit 1";
|
|
||||||
|
|
||||||
String params[] = { Long.toString(habit.getId()) };
|
String params[] = { Long.toString(habit.getId()) };
|
||||||
return getScoreFromQuery(query, params);
|
return getScoreFromQuery(query, params);
|
||||||
@@ -204,4 +222,22 @@ public class SQLiteScoreList extends ScoreList
|
|||||||
for (ScoreRecord r : records) scores.add(r.toScore());
|
for (ScoreRecord r : records) scores.add(r.toScore());
|
||||||
return scores;
|
return scores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class CachedData
|
||||||
|
{
|
||||||
|
int todayValue;
|
||||||
|
|
||||||
|
private long today;
|
||||||
|
|
||||||
|
CachedData(int todayValue)
|
||||||
|
{
|
||||||
|
this.todayValue = todayValue;
|
||||||
|
this.today = DateUtils.getStartOfToday();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean expired()
|
||||||
|
{
|
||||||
|
return today != DateUtils.getStartOfToday();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,11 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.models.sqlite;
|
package org.isoron.uhabits.models.sqlite;
|
||||||
|
|
||||||
|
import android.database.sqlite.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.activeandroid.query.*;
|
import com.activeandroid.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.sqlite.records.*;
|
import org.isoron.uhabits.models.sqlite.records.*;
|
||||||
@@ -41,10 +42,17 @@ public class SQLiteStreakList extends StreakList
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final SQLiteUtils<StreakRecord> sqlite;
|
private final SQLiteUtils<StreakRecord> sqlite;
|
||||||
|
|
||||||
|
private final SQLiteStatement invalidateStatement;
|
||||||
|
|
||||||
public SQLiteStreakList(Habit habit)
|
public SQLiteStreakList(Habit habit)
|
||||||
{
|
{
|
||||||
super(habit);
|
super(habit);
|
||||||
sqlite = new SQLiteUtils<>(StreakRecord.class);
|
sqlite = new SQLiteUtils<>(StreakRecord.class);
|
||||||
|
|
||||||
|
SQLiteDatabase db = Cache.openDatabase();
|
||||||
|
String invalidateQuery = "delete from Streak where habit = ? " +
|
||||||
|
"and end >= ?";
|
||||||
|
invalidateStatement = db.compileStatement(invalidateQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,12 +81,9 @@ public class SQLiteStreakList extends StreakList
|
|||||||
@Override
|
@Override
|
||||||
public void invalidateNewerThan(long timestamp)
|
public void invalidateNewerThan(long timestamp)
|
||||||
{
|
{
|
||||||
new Delete()
|
invalidateStatement.bindLong(1, habit.getId());
|
||||||
.from(StreakRecord.class)
|
invalidateStatement.bindLong(2, timestamp - DateUtils.millisecondsInOneDay);
|
||||||
.where("habit = ?", habit.getId())
|
invalidateStatement.execute();
|
||||||
.and("end >= ?", timestamp - DateUtils.millisecondsInOneDay)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@
|
|||||||
<string name="reminder_sound">Zvuk podsjetnika</string>
|
<string name="reminder_sound">Zvuk podsjetnika</string>
|
||||||
<string name="none">Nijedan</string>
|
<string name="none">Nijedan</string>
|
||||||
<string name="filter">Filtar</string>
|
<string name="filter">Filtar</string>
|
||||||
<string name="hide_completed">Skrivanje je uspjelo</string>
|
<string name="hide_completed">Sakrij završeno</string>
|
||||||
<string name="hide_archived">Sakrij arhivirano</string>
|
<string name="hide_archived">Sakrij arhivirano</string>
|
||||||
<string name="sticky_notifications">Učini obavijesti trajnima</string>
|
<string name="sticky_notifications">Učini obavijesti trajnima</string>
|
||||||
<string name="sticky_notifications_description">Spriječava da se obavijesti zanemare.</string>
|
<string name="sticky_notifications_description">Spriječava da se obavijesti zanemare.</string>
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
<string name="interval_4_hour">4 שעות</string>
|
<string name="interval_4_hour">4 שעות</string>
|
||||||
<string name="interval_8_hour">8 שעות</string>
|
<string name="interval_8_hour">8 שעות</string>
|
||||||
<string name="interval_24_hour">24 שעות</string>
|
<string name="interval_24_hour">24 שעות</string>
|
||||||
<string name="pref_toggle_title">החלפה להפעלה עם לחיצה קצרה</string>
|
<string name="pref_toggle_title">סימון הרגלים בלחיצה קצרה</string>
|
||||||
<string name="pref_toggle_description">סמנו יעדים בהקשה קצרה במקום לחיצה ממושכת. נוח יותר, אך יכול להוביל ללחיצות לא מכוונות.</string>
|
<string name="pref_toggle_description">סמנו יעדים בהקשה קצרה במקום לחיצה ממושכת. נוח יותר, אך יכול להוביל ללחיצות לא מכוונות.</string>
|
||||||
<string name="pref_snooze_interval_title">מרווח נדנוד לתזכורות</string>
|
<string name="pref_snooze_interval_title">מרווח נדנוד לתזכורות</string>
|
||||||
<string name="pref_rate_this_app">דרג/י אותנו ב- Google Play</string>
|
<string name="pref_rate_this_app">דרג/י אותנו ב- Google Play</string>
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
<string name="developers">מפתחים</string>
|
<string name="developers">מפתחים</string>
|
||||||
<string name="version_n">גרסה %s</string>
|
<string name="version_n">גרסה %s</string>
|
||||||
<string name="frequency">תדירות</string>
|
<string name="frequency">תדירות</string>
|
||||||
<string name="checkmark">סימן</string>
|
<string name="checkmark">סימון הרגל</string>
|
||||||
<string name="strength">חוזק</string>
|
<string name="strength">חוזק</string>
|
||||||
<string name="best_streaks">רצף שיא</string>
|
<string name="best_streaks">רצף שיא</string>
|
||||||
<string name="current_streaks">רצף נוכחי</string>
|
<string name="current_streaks">רצף נוכחי</string>
|
||||||
|
|||||||
@@ -260,4 +260,9 @@
|
|||||||
<style name="DialogWithTitle" parent="@style/Theme.AppCompat.Light.Dialog">
|
<style name="DialogWithTitle" parent="@style/Theme.AppCompat.Light.Dialog">
|
||||||
<item name="windowNoTitle">false</item>
|
<item name="windowNoTitle">false</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="DarkDialogWithTitle"
|
||||||
|
parent="@style/Theme.AppCompat.Dialog">
|
||||||
|
<item name="windowNoTitle">false</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user