Reintroduce longClick hack

This commit is contained in:
2016-03-12 05:17:55 -05:00
parent fb8a09c95c
commit d326be1224

View File

@@ -22,7 +22,6 @@ package org.isoron.uhabits.fragments;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.ActionMode; import android.view.ActionMode;
@@ -70,6 +69,7 @@ public class ListHabitsFragment extends Fragment
OnClickListener, HabitListLoader.Listener, AdapterView.OnItemLongClickListener, OnClickListener, HabitListLoader.Listener, AdapterView.OnItemLongClickListener,
HabitSelectionCallback.Listener HabitSelectionCallback.Listener
{ {
long lastLongClick = 0;
private boolean isShortToggleEnabled; private boolean isShortToggleEnabled;
private boolean showArchived; private boolean showArchived;
@@ -230,6 +230,8 @@ public class ListHabitsFragment extends Fragment
@Override @Override
public void onItemClick(AdapterView parent, View view, int position, long id) public void onItemClick(AdapterView parent, View view, int position, long id)
{ {
if (new Date().getTime() - lastLongClick < 1000) return;
if(actionMode == null) if(actionMode == null)
{ {
Habit habit = loader.habitsList.get(position); Habit habit = loader.habitsList.get(position);
@@ -295,6 +297,8 @@ public class ListHabitsFragment extends Fragment
@Override @Override
public boolean onLongClick(View v) public boolean onLongClick(View v)
{ {
lastLongClick = new Date().getTime();
switch (v.getId()) switch (v.getId())
{ {
case R.id.tvCheck: case R.id.tvCheck:
@@ -313,36 +317,18 @@ public class ListHabitsFragment extends Fragment
DialogHelper.vibrate(activity, 100); DialogHelper.vibrate(activity, 100);
} }
private void toggleCheck(final View v) private void toggleCheck(View v)
{ {
final Long tag = (Long) v.getTag(R.string.habit_key); Long tag = (Long) v.getTag(R.string.habit_key);
final Integer offset = (Integer) v.getTag(R.string.offset_key); Integer offset = (Integer) v.getTag(R.string.offset_key);
long timestamp = DateHelper.getStartOfDay(
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
new AsyncTask<Void, Void, Void>() Habit habit = loader.habits.get(tag);
{ if(habit == null) return;
private Habit habit;
@Override helper.toggleCheckmarkView(v, habit);
protected Void doInBackground(Void... params) executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
{
long timestamp = DateHelper.getStartOfDay(
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
habit = loader.habits.get(tag);
if(habit == null) return null;
executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
return null;
}
@Override
protected void onPostExecute(Void aVoid)
{
if(habit != null)
helper.toggleCheckmarkView(v, habit);
}
}.execute();
} }
private void executeCommand(Command c, Long refreshKey) private void executeCommand(Command c, Long refreshKey)