mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
@@ -330,17 +330,18 @@ public class ListHabitsFragment extends Fragment
|
||||
|
||||
private void toggleCheck(View v)
|
||||
{
|
||||
Long tag = (Long) v.getTag(R.string.habit_key);
|
||||
Integer offset = (Integer) v.getTag(R.string.offset_key);
|
||||
long timestamp = DateHelper.getStartOfDay(
|
||||
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
|
||||
|
||||
Habit habit = loader.habits.get(tag);
|
||||
Long id = helper.getHabitIdFromCheckmarkView(v);
|
||||
Habit habit = loader.habits.get(id);
|
||||
if(habit == null) return;
|
||||
|
||||
listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||
float x = v.getX() + v.getWidth() / 2.0f + ((View) v.getParent()).getX();
|
||||
float y = v.getY() + v.getHeight() / 2.0f + ((View) v.getParent()).getY();
|
||||
helper.triggerRipple((View) v.getParent().getParent(), x, y);
|
||||
|
||||
listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||
helper.toggleCheckmarkView(v, habit);
|
||||
|
||||
long timestamp = helper.getTimestampFromCheckmarkView(v);
|
||||
executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -241,6 +242,36 @@ public class ListHabitsHelper
|
||||
updateCheckmark(androidColor, (TextView) v, 2);
|
||||
}
|
||||
|
||||
public Long getHabitIdFromCheckmarkView(View v)
|
||||
{
|
||||
return (Long) v.getTag(R.string.habit_key);
|
||||
}
|
||||
|
||||
public long getTimestampFromCheckmarkView(View v)
|
||||
{
|
||||
Integer offset = (Integer) v.getTag(R.string.offset_key);
|
||||
return DateHelper.getStartOfDay(DateHelper.getLocalTime() -
|
||||
offset * DateHelper.millisecondsInOneDay);
|
||||
}
|
||||
|
||||
public void triggerRipple(View v, final float x, final float y)
|
||||
{
|
||||
final Drawable background = v.getBackground();
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
||||
background.setHotspot(x, y);
|
||||
|
||||
background.setState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled});
|
||||
|
||||
new Handler().postDelayed(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
background.setState(new int[]{});
|
||||
}
|
||||
}, 25);
|
||||
}
|
||||
|
||||
private static class HotspotTouchListener implements View.OnTouchListener
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -28,8 +28,4 @@
|
||||
<item name="android:layout_alignParentTop">true</item>
|
||||
<item name="android:paddingRight">4dp</item>
|
||||
</style>
|
||||
|
||||
<style name="ListHabits.Checkmark" parent="ListHabits.CheckmarkCommon">
|
||||
<item name="android:background">@drawable/ripple_transparent</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -72,17 +72,13 @@
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<style name="ListHabits.CheckmarkCommon">
|
||||
<style name="ListHabits.Checkmark">
|
||||
<item name="android:focusable">false</item>
|
||||
<item name="android:minHeight">@dimen/checkmarkHeight</item>
|
||||
<item name="android:width">@dimen/checkmarkWidth</item>
|
||||
<item name="android:gravity">center</item>
|
||||
</style>
|
||||
|
||||
<style name="ListHabits.Checkmark" parent="ListHabits.CheckmarkCommon">
|
||||
</style>
|
||||
|
||||
|
||||
<style name="ListHabits.EmptyState">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
||||
Reference in New Issue
Block a user