mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Make history editor functional
This commit is contained in:
@@ -35,6 +35,9 @@ import org.isoron.uhabits.views.HabitHistoryView;
|
||||
public class HistoryEditorDialog extends DialogFragment
|
||||
implements DialogInterface.OnClickListener
|
||||
{
|
||||
private Habit habit;
|
||||
HabitHistoryView historyView;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
@@ -42,9 +45,9 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
|
||||
int p = (int) getResources().getDimension(R.dimen.history_editor_padding);
|
||||
|
||||
HabitHistoryView historyView = new HabitHistoryView(context, null);
|
||||
historyView.setHabit(Habit.get(4L));
|
||||
historyView = new HabitHistoryView(context, null);
|
||||
historyView.setPadding(p, 0, p, 0);
|
||||
historyView.setHabit(habit);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle("History Editor")
|
||||
@@ -74,4 +77,10 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void setHabit(Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
if(historyView != null) historyView.setHabit(habit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
||||
public void onClick(View v)
|
||||
{
|
||||
HistoryEditorDialog frag = new HistoryEditorDialog();
|
||||
frag.setHabit(habit);
|
||||
frag.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -68,6 +68,8 @@ public class RepetitionList
|
||||
|
||||
public void toggle(long timestamp)
|
||||
{
|
||||
timestamp = DateHelper.getStartOfDay(timestamp);
|
||||
|
||||
if (contains(timestamp))
|
||||
{
|
||||
delete(timestamp);
|
||||
|
||||
@@ -25,7 +25,9 @@ import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Rect;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
@@ -346,4 +348,52 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||
createColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e)
|
||||
{
|
||||
int pointerId = e.getPointerId(0);
|
||||
float x = e.getX(pointerId);
|
||||
float y = e.getY(pointerId);
|
||||
|
||||
final Long timestamp = positionToTimestamp(x, y);
|
||||
if(timestamp == null) return false;
|
||||
|
||||
new AsyncTask<Void, Void, Void>()
|
||||
{
|
||||
@Override
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
habit.repetitions.toggle(timestamp);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
fetchData();
|
||||
invalidate();
|
||||
}
|
||||
}.execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Long positionToTimestamp(float x, float y)
|
||||
{
|
||||
int col = (int) (x / columnWidth);
|
||||
int row = (int) (y / columnWidth);
|
||||
|
||||
if(row == 0) return null;
|
||||
if(col == nColumns - 1) return null;
|
||||
|
||||
int offset = col * 7 + (row - 1);
|
||||
Calendar date = (Calendar) baseDate.clone();
|
||||
date.add(Calendar.DAY_OF_YEAR, offset);
|
||||
|
||||
if(DateHelper.getStartOfDay(date.getTimeInMillis()) > DateHelper.getStartOfToday())
|
||||
return null;
|
||||
|
||||
return date.getTimeInMillis();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user