Perform additional checks to avoid negative lengths

This commit is contained in:
2016-02-28 15:23:20 -05:00
parent 88455acc76
commit 4def8f0409
2 changed files with 5 additions and 2 deletions

View File

@@ -267,7 +267,7 @@ public class ListHabitsFragment extends Fragment
{
DisplayMetrics dm = getResources().getDisplayMetrics();
int width = (int) (dm.widthPixels / dm.density);
buttonCount = (int) ((width - 160) / 42.0);
buttonCount = Math.max(0, (int) ((width - 160) / 42.0));
tvNameWidth = (int) ((width - 30 - buttonCount * 42) * dm.density);
loader = new HabitListLoader();
@@ -719,6 +719,7 @@ public class ListHabitsFragment extends Fragment
TextView tvCheck = (TextView) llButtons.getChildAt(i);
tvCheck.setTag(R.string.habit_key, habitId);
tvCheck.setTag(R.string.offset_key, i);
if(isChecked.length > i)
updateCheckmark(activeColor, tvCheck, isChecked[i]);
}
}

View File

@@ -269,6 +269,8 @@ public class Habit extends Model
{
updateCheckmarks();
if(fromTimestamp > toTimestamp) return new int[0];
String query = "select value, timestamp from Checkmarks where " +
"habit = ? and timestamp >= ? and timestamp <= ?";