Skip to content

Commit

Permalink
Merge branch 'hotfix/1.7.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Jul 19, 2017
2 parents 526830b + bf24cc6 commit 540a618
Show file tree
Hide file tree
Showing 29 changed files with 868 additions and 613 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 1.7.6 (July 18, 2017)

* Fix bug that caused widgets not to render sometimes
* Fix other minor bugs
* Update translations

### 1.7.3 (May 30, 2017)

* Improve performance of 'sort by score'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ public void testArchiveHabits()
clickMenuItem(R.string.archive);
assertHabitsDontExist(names);

clickMenuItem(R.string.show_archived);
clickMenuItem(R.string.hide_archived);

assertHabitsExist(names);
selectHabits(names);
clickMenuItem(R.string.unarchive);

clickMenuItem(R.string.show_archived);
clickMenuItem(R.string.hide_archived);

assertHabitsExist(names);
deleteHabits(names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,41 @@ public void testInvalidateNewerThan()
assertThat(records.get(0).timestamp, equalTo(today - 21 * day));
}

@Test
public void testFixRecords() throws Exception
{
long day = DateUtils.millisecondsInOneDay;
long from = DateUtils.getStartOfToday();
long to = from + 5 * day;

List<CheckmarkRecord> original, actual, expected;
HabitRecord habit = new HabitRecord();

original = new ArrayList<>();
original.add(new CheckmarkRecord(habit, from + 8*day, 2));
original.add(new CheckmarkRecord(habit, from + 5*day, 0));
original.add(new CheckmarkRecord(habit, from + 4*day, 0));
original.add(new CheckmarkRecord(habit, from + 4*day, 2));
original.add(new CheckmarkRecord(habit, from + 3*day, 2));
original.add(new CheckmarkRecord(habit, from + 2*day, 1));
original.add(new CheckmarkRecord(habit, from + 2*day + 100, 1));
original.add(new CheckmarkRecord(habit, from, 0));
original.add(new CheckmarkRecord(habit, from, 2));
original.add(new CheckmarkRecord(habit, from - day, 2));

actual = SQLiteCheckmarkList.fixRecords(original, habit, from, to);

expected = new ArrayList<>();
expected.add(new CheckmarkRecord(habit, from + 5*day, 0));
expected.add(new CheckmarkRecord(habit, from + 4*day, 2));
expected.add(new CheckmarkRecord(habit, from + 3*day, 2));
expected.add(new CheckmarkRecord(habit, from + 2*day, 1));
expected.add(new CheckmarkRecord(habit, from + day, 0));
expected.add(new CheckmarkRecord(habit, from, 2));

assertThat(actual, equalTo(expected));
}

private List<CheckmarkRecord> getAllRecords()
{
return new Select()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<manifest
package="org.isoron.uhabits"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="32"
android:versionName="1.7.5">
android:versionCode="33"
android:versionName="1.7.6">

<uses-permission android:name="android.permission.VIBRATE"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import java.text.*;
import java.util.*;

import static org.isoron.uhabits.models.Checkmark.*;
import static org.isoron.uhabits.models.Checkmark.CHECKED_EXPLICITLY;
import static org.isoron.uhabits.models.Checkmark.UNCHECKED;

public class HistoryChart extends ScrollableChart
{
Expand Down Expand Up @@ -112,10 +113,21 @@ public boolean onSingleTapUp(MotionEvent e)
if (!isEditable) return false;

performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
float x, y;

int pointerId = e.getPointerId(0);
float x = e.getX(pointerId);
float y = e.getY(pointerId);
try
{
int pointerId = e.getPointerId(0);
x = e.getX(pointerId);
y = e.getY(pointerId);
}
catch (RuntimeException ex)
{
// Android often throws IllegalArgumentException here. Apparently,
// the pointer id may become invalid shortly after calling
// e.getPointerId.
return false;
}

final Long timestamp = positionToTimestamp(x, y);
if (timestamp == null) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ public void clearSelection()
* Returns the item that occupies a certain position on the list
*
* @param position position of the item
* @return the item at given position
* @throws IndexOutOfBoundsException if position is not valid
* @return the item at given position or null if position is invalid
*/
@Deprecated
@NonNull
@Nullable
public Habit getItem(int position)
{
return cache.getHabitByPosition(position);
Expand Down Expand Up @@ -314,6 +313,8 @@ public void setOrder(HabitList.Order order)
public void toggleSelection(int position)
{
Habit h = getItem(position);
if (h == null) return;

int k = selected.indexOf(h);
if (k < 0) selected.add(h);
else selected.remove(h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public int[] getCheckmarks(long habitId)
* Returns the habits that occupies a certain position on the list.
*
* @param position the position of the habit
* @return the habit at given position
* @throws IndexOutOfBoundsException if position is not valid
* @return the habit at given position or null if position is invalid
*/
@NonNull
public Habit getHabitByPosition(int position)
@Nullable
public synchronized Habit getHabitByPosition(int position)
{
if(position < 0 || position >= data.habits.size()) return null;
return data.habits.get(position);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ public void setSelected(boolean isSelected)
updateBackground(isSelected);
}

public void triggerRipple(long timestamp)
public synchronized void triggerRipple(long timestamp)
{
long today = DateUtils.getStartOfToday();
long day = DateUtils.millisecondsInOneDay;
int offset = (int) ((today - timestamp) / day) - dataOffset;
CheckmarkButtonView button = checkmarkPanel.indexToButton(offset);
if (button == null) return;

float y = button.getHeight() / 2.0f;
float x = checkmarkPanel.getX() + button.getX() + button.getWidth() / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,27 @@ public class SQLiteCheckmarkList extends CheckmarkList
@Nullable
private CachedData cache;

@NonNull
private final SQLiteStatement invalidateStatement;

@NonNull
private final SQLiteStatement addStatement;

@NonNull
private final SQLiteDatabase db;

public SQLiteCheckmarkList(Habit habit)
{
super(habit);
sqlite = new SQLiteUtils<>(CheckmarkRecord.class);

db = Cache.openDatabase();
addStatement = db.compileStatement(ADD_QUERY);
invalidateStatement = db.compileStatement(INVALIDATE_QUERY);
}

@Override
public void add(List<Checkmark> checkmarks)
{
check(habit.getId());
SQLiteDatabase db = Cache.openDatabase();
SQLiteStatement statement = db.compileStatement(ADD_QUERY);
db.beginTransaction();
try
{
for (Checkmark c : checkmarks)
{
addStatement.bindLong(1, habit.getId());
addStatement.bindLong(2, c.getTimestamp());
addStatement.bindLong(3, c.getValue());
addStatement.execute();
statement.bindLong(1, habit.getId());
statement.bindLong(2, c.getTimestamp());
statement.bindLong(3, c.getValue());
statement.execute();
}

db.setTransactionSuccessful();
Expand Down Expand Up @@ -115,14 +104,7 @@ public List<Checkmark> getByInterval(long fromTimestamp, long toTimestamp)
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()));
}

records = fixRecords(records, habitRecord, fromTimestamp, toTimestamp);
return toCheckmarks(records);
}

Expand All @@ -139,9 +121,11 @@ public int getTodayValue()
public void invalidateNewerThan(long timestamp)
{
cache = null;
invalidateStatement.bindLong(1, habit.getId());
invalidateStatement.bindLong(2, timestamp);
invalidateStatement.execute();
SQLiteDatabase db = Cache.openDatabase();
SQLiteStatement statement = db.compileStatement(INVALIDATE_QUERY);
statement.bindLong(1, habit.getId());
statement.bindLong(2, timestamp);
statement.execute();
observable.notifyListeners();
}

Expand Down Expand Up @@ -198,6 +182,28 @@ private List<Checkmark> toCheckmarks(@NonNull List<CheckmarkRecord> records)
return checkmarks;
}

public static List<CheckmarkRecord> fixRecords(List<CheckmarkRecord> original,
HabitRecord habit,
long fromTimestamp,
long toTimestamp)
{
long day = DateUtils.millisecondsInOneDay;
ArrayList<CheckmarkRecord> records = new ArrayList<>();

for (long t = toTimestamp; t >= fromTimestamp; t -= day)
records.add(new CheckmarkRecord(habit, t, Checkmark.UNCHECKED));

for (CheckmarkRecord record : original)
{
if ((toTimestamp - record.timestamp) % day != 0) continue;
int offset = (int) ((toTimestamp - record.timestamp) / day);
if (offset < 0 || offset >= records.size()) continue;
records.set(offset, record);
}

return records;
}

private static class CachedData
{
int todayValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public class SQLiteScoreList extends ScoreList
@NonNull
private final SQLiteUtils<ScoreRecord> sqlite;

@NonNull
private final SQLiteStatement invalidateStatement;

@NonNull
private final SQLiteStatement addStatement;

private final SQLiteDatabase db;

@Nullable
private CachedData cache = null;

Expand All @@ -69,25 +61,23 @@ public SQLiteScoreList(@NonNull Habit habit)
{
super(habit);
sqlite = new SQLiteUtils<>(ScoreRecord.class);

db = Cache.openDatabase();
addStatement = db.compileStatement(ADD_QUERY);
invalidateStatement = db.compileStatement(INVALIDATE_QUERY);
}

@Override
public void add(List<Score> scores)
{
check(habit.getId());
SQLiteDatabase db = Cache.openDatabase();
SQLiteStatement statement = db.compileStatement(ADD_QUERY);
db.beginTransaction();
try
{
for (Score s : scores)
{
addStatement.bindLong(1, habit.getId());
addStatement.bindLong(2, s.getTimestamp());
addStatement.bindLong(3, s.getValue());
addStatement.execute();
statement.bindLong(1, habit.getId());
statement.bindLong(2, s.getTimestamp());
statement.bindLong(3, s.getValue());
statement.execute();
}

db.setTransactionSuccessful();
Expand Down Expand Up @@ -150,9 +140,11 @@ public synchronized int getTodayValue()
public synchronized void invalidateNewerThan(long timestamp)
{
cache = null;
invalidateStatement.bindLong(1, habit.getId());
invalidateStatement.bindLong(2, timestamp);
invalidateStatement.execute();
SQLiteDatabase db = Cache.openDatabase();
SQLiteStatement statement = db.compileStatement(INVALIDATE_QUERY);
statement.bindLong(1, habit.getId());
statement.bindLong(2, timestamp);
statement.execute();
getObservable().notifyListeners();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@
*/
public class SQLiteStreakList extends StreakList
{

private static final String INVALIDATE_QUERY =
"delete from Streak where habit = ? and end >= ?";

private HabitRecord habitRecord;

@NonNull
private final SQLiteUtils<StreakRecord> sqlite;

private final SQLiteStatement invalidateStatement;

public SQLiteStreakList(Habit habit)
{
super(habit);
sqlite = new SQLiteUtils<>(StreakRecord.class);

SQLiteDatabase db = Cache.openDatabase();
String invalidateQuery = "delete from Streak where habit = ? " +
"and end >= ?";
invalidateStatement = db.compileStatement(invalidateQuery);
}

@Override
Expand Down Expand Up @@ -81,9 +78,11 @@ public Streak getNewestComputed()
@Override
public void invalidateNewerThan(long timestamp)
{
invalidateStatement.bindLong(1, habit.getId());
invalidateStatement.bindLong(2, timestamp - DateUtils.millisecondsInOneDay);
invalidateStatement.execute();
SQLiteDatabase db = Cache.openDatabase();
SQLiteStatement statement = db.compileStatement(INVALIDATE_QUERY);
statement.bindLong(1, habit.getId());
statement.bindLong(2, timestamp - DateUtils.millisecondsInOneDay);
statement.execute();
observable.notifyListeners();
}

Expand Down
Loading

0 comments on commit 540a618

Please sign in to comment.