diff --git a/CHANGELOG.md b/CHANGELOG.md index dc0407636..307b541c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d42a9f55..a3cb482d4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -4,3 +4,4 @@ distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-4.0-20170417000025+0000-all.zip + diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java index 871614092..0f23f0b55 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java @@ -24,6 +24,7 @@ import android.support.test.uiautomator.*; import com.linkedin.android.testbutler.*; +import org.isoron.androidbase.*; import org.junit.*; import static android.support.test.InstrumentationRegistry.*; @@ -39,8 +40,14 @@ public class BaseUIAutomatorTest public void setUp() { TestButler.setup(getTargetContext()); - TestButler.verifyAnimationsDisabled(getTargetContext()); device = getInstance(getInstrumentation()); + + HabitsComponent component = DaggerHabitsComponent + .builder() + .appModule(new AppModule(getTargetContext())) + .build(); + + HabitsApplication.setComponent(component); } @After diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionListTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionListTest.java index 06ebca674..529050696 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionListTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionListTest.java @@ -34,9 +34,8 @@ import org.junit.runner.*; import java.util.*; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.core.IsNot.not; +import static android.support.test.espresso.matcher.ViewMatchers.*; +import static org.hamcrest.core.IsEqual.*; import static org.isoron.uhabits.core.models.Checkmark.*; @RunWith(AndroidJUnit4.class) @@ -66,13 +65,14 @@ public class SQLiteRepetitionListTest extends BaseAndroidTest public void testAdd() { RepetitionRecord record = getByTimestamp(today + day); - assertThat(record, is(nullValue())); + assertNull(record); Repetition rep = new Repetition(today + day, CHECKED_EXPLICITLY); habit.getRepetitions().add(rep); record = getByTimestamp(today + day); - assertThat(record, is(not(nullValue()))); + assertNotNull(record); + assertThat(record.value, equalTo(CHECKED_EXPLICITLY)); } @Test @@ -91,18 +91,18 @@ public class SQLiteRepetitionListTest extends BaseAndroidTest public void testGetByTimestamp() { Repetition rep = repetitions.getByTimestamp(today); - assertThat(rep, is(not(nullValue()))); + assertNotNull(rep); assertThat(rep.getTimestamp(), equalTo(today)); rep = repetitions.getByTimestamp(today - 2 * day); - assertThat(rep, is(nullValue())); + assertNull(rep); } @Test public void testGetOldest() { Repetition rep = repetitions.getOldest(); - assertThat(rep, is(not(nullValue()))); + assertNotNull(rep); assertThat(rep.getTimestamp(), equalTo(today - 120 * day)); } @@ -111,20 +111,20 @@ public class SQLiteRepetitionListTest extends BaseAndroidTest { Habit empty = fixtures.createEmptyHabit(); Repetition rep = empty.getRepetitions().getOldest(); - assertThat(rep, is(nullValue())); + assertNull(rep); } @Test public void testRemove() { RepetitionRecord record = getByTimestamp(today); - assertThat(record, is(not(nullValue()))); + assertNotNull(record); Repetition rep = record.toRepetition(); repetitions.remove(rep); record = getByTimestamp(today); - assertThat(record, is(nullValue())); + assertNull(record); } @Nullable diff --git a/uhabits-android/src/main/AndroidManifest.xml b/uhabits-android/src/main/AndroidManifest.xml index ee4fb56df..ac3389550 100644 --- a/uhabits-android/src/main/AndroidManifest.xml +++ b/uhabits-android/src/main/AndroidManifest.xml @@ -20,8 +20,8 @@ + android:versionCode="30" + android:versionName="1.7.3"> diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/BundleSavedState.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/BundleSavedState.java index b5011b03c..6f9e1163d 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/BundleSavedState.java +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/BundleSavedState.java @@ -20,24 +20,27 @@ package org.isoron.uhabits.activities.common.views; import android.os.*; +import android.support.v4.os.*; public class BundleSavedState extends android.support.v4.view.AbsSavedState { public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() - { - @Override - public BundleSavedState createFromParcel(Parcel source) + ParcelableCompat.newCreator( + new ParcelableCompatCreatorCallbacks() { - return new BundleSavedState(source, getClass().getClassLoader()); - } + @Override + public BundleSavedState createFromParcel(Parcel source, + ClassLoader loader) + { + return new BundleSavedState(source, loader); + } - @Override - public BundleSavedState[] newArray(int size) - { - return new BundleSavedState[size]; - } - }; + @Override + public BundleSavedState[] newArray(int size) + { + return new BundleSavedState[size]; + } + }); public final Bundle bundle; @@ -50,7 +53,7 @@ public class BundleSavedState extends android.support.v4.view.AbsSavedState public BundleSavedState(Parcel source, ClassLoader loader) { super(source, loader); - this.bundle = source.readBundle(getClass().getClassLoader()); + this.bundle = source.readBundle(loader); } @Override diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.java index 8b54b324f..c488cb17a 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.java +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.java @@ -107,6 +107,12 @@ public abstract class ScrollableChart extends View @Override public void onRestoreInstanceState(Parcelable state) { + if(!(state instanceof BundleSavedState)) + { + super.onRestoreInstanceState(state); + return; + } + BundleSavedState bss = (BundleSavedState) state; int x = bss.bundle.getInt("x"); int y = bss.bundle.getInt("y"); diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardListView.java b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardListView.java index 1f0b538fd..975902cc8 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardListView.java +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardListView.java @@ -155,6 +155,12 @@ public class HabitCardListView extends RecyclerView @Override protected void onRestoreInstanceState(Parcelable state) { + if(!(state instanceof BundleSavedState)) + { + super.onRestoreInstanceState(state); + return; + } + BundleSavedState bss = (BundleSavedState) state; dataOffset = bss.bundle.getInt("dataOffset"); super.onRestoreInstanceState(bss.getSuperState()); diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteCheckmarkList.java b/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteCheckmarkList.java index 74e2f73a9..dc6f2e2d2 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteCheckmarkList.java +++ b/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteCheckmarkList.java @@ -153,6 +153,7 @@ public class SQLiteCheckmarkList extends CheckmarkList } @Override + @Nullable protected Checkmark getOldestComputed() { check(habit.getId()); diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java b/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java index 0a4969cd4..1ebac67f7 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java +++ b/uhabits-android/src/main/java/org/isoron/uhabits/models/sqlite/SQLiteRepetitionList.java @@ -38,6 +38,7 @@ import java.util.*; */ public class SQLiteRepetitionList extends RepetitionList { + private final SQLiteUtils sqlite; @Nullable @@ -45,14 +46,17 @@ public class SQLiteRepetitionList extends RepetitionList private SQLiteStatement addStatement; + public static final String ADD_QUERY = + "insert into repetitions(habit, timestamp, value) " + + "values (?,?,?)"; + public SQLiteRepetitionList(@NonNull Habit habit) { super(habit); sqlite = new SQLiteUtils<>(RepetitionRecord.class); SQLiteDatabase db = Cache.openDatabase(); - String addQuery = "insert into repetitions(habit, timestamp) values (?,?)"; - addStatement = db.compileStatement(addQuery); + addStatement = db.compileStatement(ADD_QUERY); } /** @@ -69,6 +73,7 @@ public class SQLiteRepetitionList extends RepetitionList check(habit.getId()); addStatement.bindLong(1, habit.getId()); addStatement.bindLong(2, rep.getTimestamp()); + addStatement.bindLong(3, rep.getValue()); addStatement.execute(); observable.notifyListeners(); } diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/CheckmarkList.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/CheckmarkList.java index 75a34e42b..847775127 100644 --- a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/CheckmarkList.java +++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/CheckmarkList.java @@ -202,7 +202,7 @@ public abstract class CheckmarkList Checkmark newest = getNewestComputed(); Checkmark oldest = getOldestComputed(); - if (newest == null) + if (newest == null || oldest == null) { forceRecompute(from, to); } @@ -218,6 +218,7 @@ public abstract class CheckmarkList * * @return oldest checkmark already computed */ + @Nullable protected abstract Checkmark getOldestComputed(); /** @@ -295,5 +296,6 @@ public abstract class CheckmarkList * * @return newest checkmark already computed */ + @Nullable protected abstract Checkmark getNewestComputed(); } diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryCheckmarkList.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryCheckmarkList.java index ec847acc5..fb33a168a 100644 --- a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryCheckmarkList.java +++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryCheckmarkList.java @@ -72,6 +72,7 @@ public class MemoryCheckmarkList extends CheckmarkList } @Override + @Nullable protected Checkmark getOldestComputed() { if(list.isEmpty()) return null; @@ -79,6 +80,7 @@ public class MemoryCheckmarkList extends CheckmarkList } @Override + @Nullable protected Checkmark getNewestComputed() { if(list.isEmpty()) return null;