mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Fix HistoryEditorDialog
This commit is contained in:
@@ -19,30 +19,18 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits;
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
import org.isoron.uhabits.commands.ArchiveHabitsCommand;
|
import org.isoron.uhabits.commands.*;
|
||||||
import org.isoron.uhabits.commands.ChangeHabitColorCommand;
|
import org.isoron.uhabits.io.*;
|
||||||
import org.isoron.uhabits.commands.CreateHabitCommand;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.commands.DeleteHabitsCommand;
|
import org.isoron.uhabits.tasks.*;
|
||||||
import org.isoron.uhabits.commands.EditHabitCommand;
|
import org.isoron.uhabits.ui.*;
|
||||||
import org.isoron.uhabits.commands.UnarchiveHabitsCommand;
|
import org.isoron.uhabits.ui.habits.edit.*;
|
||||||
import org.isoron.uhabits.io.AbstractImporter;
|
import org.isoron.uhabits.ui.habits.list.*;
|
||||||
import org.isoron.uhabits.io.HabitsCSVExporter;
|
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||||
import org.isoron.uhabits.tasks.ToggleRepetitionTask;
|
import org.isoron.uhabits.ui.habits.list.views.*;
|
||||||
import org.isoron.uhabits.ui.BaseSystem;
|
import org.isoron.uhabits.ui.habits.show.*;
|
||||||
import org.isoron.uhabits.ui.habits.edit.BaseDialogFragment;
|
import org.isoron.uhabits.widgets.*;
|
||||||
import org.isoron.uhabits.ui.habits.edit.HistoryEditorDialog;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.ListHabitsActivity;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.ListHabitsController;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.ListHabitsSelectionMenu;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.controllers.CheckmarkButtonController;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListAdapter;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListCache;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.model.HintList;
|
|
||||||
import org.isoron.uhabits.ui.habits.list.views.CheckmarkPanelView;
|
|
||||||
import org.isoron.uhabits.ui.habits.show.ShowHabitActivity;
|
|
||||||
import org.isoron.uhabits.widgets.BaseWidgetProvider;
|
|
||||||
import org.isoron.uhabits.widgets.HabitPickerDialog;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base component for dependency injection.
|
* Base component for dependency injection.
|
||||||
@@ -100,4 +88,6 @@ public interface BaseComponent
|
|||||||
void inject(HabitsCSVExporter habitsCSVExporter);
|
void inject(HabitsCSVExporter habitsCSVExporter);
|
||||||
|
|
||||||
void inject(BaseDialogFragment baseDialogFragment);
|
void inject(BaseDialogFragment baseDialogFragment);
|
||||||
|
|
||||||
|
void inject(ShowHabitController showHabitController);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.tasks;
|
|||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ public abstract class BaseTask extends AsyncTask<Void, Integer, Void>
|
|||||||
{
|
{
|
||||||
private static int activeTaskCount;
|
private static int activeTaskCount;
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute()
|
protected void onPreExecute()
|
||||||
{
|
{
|
||||||
@@ -35,6 +37,7 @@ public abstract class BaseTask extends AsyncTask<Void, Integer, Void>
|
|||||||
activeTaskCount++;
|
activeTaskCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid)
|
protected void onPostExecute(Void aVoid)
|
||||||
{
|
{
|
||||||
|
|||||||
42
app/src/main/java/org/isoron/uhabits/tasks/SimpleTask.java
Normal file
42
app/src/main/java/org/isoron/uhabits/tasks/SimpleTask.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.tasks;
|
||||||
|
|
||||||
|
public class SimpleTask
|
||||||
|
{
|
||||||
|
private final BaseTask baseTask;
|
||||||
|
|
||||||
|
public SimpleTask(Runnable runnable)
|
||||||
|
{
|
||||||
|
this.baseTask = new BaseTask()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void doInBackground()
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
baseTask.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -234,17 +234,19 @@ public abstract class BaseScreen
|
|||||||
{
|
{
|
||||||
if (rootView == null) return;
|
if (rootView == null) return;
|
||||||
|
|
||||||
Toolbar toolbar = rootView.getToolbar();
|
activity.runOnUiThread(() -> {
|
||||||
activity.setSupportActionBar(toolbar);
|
Toolbar toolbar = rootView.getToolbar();
|
||||||
ActionBar actionBar = activity.getSupportActionBar();
|
activity.setSupportActionBar(toolbar);
|
||||||
if (actionBar == null) return;
|
ActionBar actionBar = activity.getSupportActionBar();
|
||||||
|
if (actionBar == null) return;
|
||||||
|
|
||||||
actionBar.setDisplayHomeAsUpEnabled(rootView.getDisplayHomeAsUp());
|
actionBar.setDisplayHomeAsUpEnabled(rootView.getDisplayHomeAsUp());
|
||||||
|
|
||||||
int color = rootView.getToolbarColor();
|
int color = rootView.getToolbarColor();
|
||||||
setActionBarColor(actionBar, color);
|
setActionBarColor(actionBar, color);
|
||||||
setStatusBarColor(color);
|
setStatusBarColor(color);
|
||||||
setupToolbarElevation(toolbar);
|
setupToolbarElevation(toolbar);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActionBarColor(@NonNull ActionBar actionBar, int color)
|
private void setActionBarColor(@NonNull ActionBar actionBar, int color)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.ui.common.views;
|
|||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.Paint.*;
|
import android.graphics.Paint.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
@@ -82,6 +83,9 @@ public class HistoryChart extends ScrollableChart
|
|||||||
|
|
||||||
private float headerOverflow = 0;
|
private float headerOverflow = 0;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Controller controller;
|
||||||
|
|
||||||
public HistoryChart(Context context)
|
public HistoryChart(Context context)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
@@ -114,13 +118,12 @@ public class HistoryChart extends ScrollableChart
|
|||||||
final Long timestamp = positionToTimestamp(x, y);
|
final Long timestamp = positionToTimestamp(x, y);
|
||||||
if (timestamp == null) return false;
|
if (timestamp == null) return false;
|
||||||
|
|
||||||
// ToggleRepetitionTask task = new ToggleRepetitionTask(habit, timestamp);
|
controller.onToggleCheckmark(timestamp);
|
||||||
// task.setListener(this);
|
|
||||||
// task.execute();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void populateWithRandomData()
|
public void populateWithRandomData()
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -152,6 +155,11 @@ public class HistoryChart extends ScrollableChart
|
|||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setController(@NonNull Controller controller)
|
||||||
|
{
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||||
{
|
{
|
||||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||||
@@ -330,6 +338,7 @@ public class HistoryChart extends ScrollableChart
|
|||||||
{
|
{
|
||||||
isEditable = false;
|
isEditable = false;
|
||||||
checkmarks = new int[0];
|
checkmarks = new int[0];
|
||||||
|
controller = new Controller() {};
|
||||||
|
|
||||||
initColors();
|
initColors();
|
||||||
initPaints();
|
initPaints();
|
||||||
@@ -412,4 +421,9 @@ public class HistoryChart extends ScrollableChart
|
|||||||
baseDate.add(Calendar.DAY_OF_YEAR, -nDays);
|
baseDate.add(Calendar.DAY_OF_YEAR, -nDays);
|
||||||
baseDate.add(Calendar.DAY_OF_YEAR, -todayPositionInColumn);
|
baseDate.add(Calendar.DAY_OF_YEAR, -todayPositionInColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Controller
|
||||||
|
{
|
||||||
|
default void onToggleCheckmark(long timestamp) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,42 +19,56 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.ui.habits.edit;
|
package org.isoron.uhabits.ui.habits.edit;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.*;
|
||||||
import android.content.Context;
|
import android.content.*;
|
||||||
import android.content.DialogInterface;
|
import android.os.*;
|
||||||
import android.os.Bundle;
|
import android.support.annotation.*;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatDialogFragment;
|
import android.support.v7.app.*;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.*;
|
||||||
|
|
||||||
import org.apache.commons.lang3.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.HabitsApplication;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.tasks.*;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.ui.common.views.*;
|
||||||
import org.isoron.uhabits.models.HabitList;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.tasks.BaseTask;
|
|
||||||
import org.isoron.uhabits.ui.common.views.HistoryChart;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.*;
|
||||||
|
|
||||||
public class HistoryEditorDialog extends AppCompatDialogFragment
|
public class HistoryEditorDialog extends AppCompatDialogFragment
|
||||||
implements DialogInterface.OnClickListener
|
implements DialogInterface.OnClickListener, ModelObservable.Listener
|
||||||
{
|
{
|
||||||
|
@Nullable
|
||||||
private Habit habit;
|
private Habit habit;
|
||||||
|
|
||||||
private Listener listener;
|
@Nullable
|
||||||
|
|
||||||
HistoryChart historyChart;
|
HistoryChart historyChart;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
HabitList habitList;
|
HabitList habitList;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Controller controller;
|
||||||
|
|
||||||
|
public HistoryEditorDialog()
|
||||||
|
{
|
||||||
|
this.controller = new Controller() {};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
public void onClick(DialogInterface dialog, int which)
|
||||||
|
{
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
Context context = getActivity();
|
Context context = getActivity();
|
||||||
HabitsApplication.getComponent().inject(this);
|
HabitsApplication.getComponent().inject(this);
|
||||||
historyChart = new HistoryChart(context, null);
|
historyChart = new HistoryChart(context);
|
||||||
|
historyChart.setController(controller);
|
||||||
|
|
||||||
if (savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
{
|
{
|
||||||
@@ -65,9 +79,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
int padding =
|
int padding =
|
||||||
(int) getResources().getDimension(R.dimen.history_editor_padding);
|
(int) getResources().getDimension(R.dimen.history_editor_padding);
|
||||||
|
|
||||||
if(true) throw new NotImplementedException("");
|
|
||||||
historyChart.setPadding(padding, 0, padding, 0);
|
historyChart.setPadding(padding, 0, padding, 0);
|
||||||
// historyChart.setHabit(habit);
|
|
||||||
historyChart.setIsEditable(true);
|
historyChart.setIsEditable(true);
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
@@ -76,21 +88,13 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
.setView(historyChart)
|
.setView(historyChart)
|
||||||
.setPositiveButton(android.R.string.ok, this);
|
.setPositiveButton(android.R.string.ok, this);
|
||||||
|
|
||||||
refreshData();
|
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshData()
|
@Override
|
||||||
|
public void onModelChange()
|
||||||
{
|
{
|
||||||
new BaseTask()
|
refreshData();
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected void doInBackground()
|
|
||||||
{
|
|
||||||
// historyChart.refreshData();
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,25 +109,16 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
int height = Math.min(metrics.heightPixels, maxHeight);
|
int height = Math.min(metrics.heightPixels, maxHeight);
|
||||||
|
|
||||||
getDialog().getWindow().setLayout(width, height);
|
getDialog().getWindow().setLayout(width, height);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
refreshData();
|
||||||
public void onClick(DialogInterface dialog, int which)
|
habit.getCheckmarks().observable.addListener(this);
|
||||||
{
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHabit(Habit habit)
|
|
||||||
{
|
|
||||||
// this.habit = habit;
|
|
||||||
// if (historyChart != null) historyChart.setHabit(habit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
|
habit.getCheckmarks().observable.removeListener(this);
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (listener != null) listener.onHistoryEditorClosed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -132,13 +127,42 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
outState.putLong("habit", habit.getId());
|
outState.putLong("habit", habit.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(Listener listener)
|
public void setController(@NonNull Controller controller)
|
||||||
{
|
{
|
||||||
this.listener = listener;
|
this.controller = controller;
|
||||||
|
if (historyChart != null) historyChart.setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Listener
|
public void setHabit(@Nullable Habit habit)
|
||||||
{
|
{
|
||||||
void onHistoryEditorClosed();
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshData()
|
||||||
|
{
|
||||||
|
if (habit == null) return;
|
||||||
|
new RefreshTask().execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Controller extends HistoryChart.Controller {}
|
||||||
|
|
||||||
|
private class RefreshTask extends BaseTask
|
||||||
|
{
|
||||||
|
public int[] checkmarks;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doInBackground()
|
||||||
|
{
|
||||||
|
checkmarks = habit.getCheckmarks().getAllValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid)
|
||||||
|
{
|
||||||
|
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
|
historyChart.setColor(color);
|
||||||
|
historyChart.setCheckmarks(checkmarks);
|
||||||
|
super.onPostExecute(aVoid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,14 @@ public class ShowHabitActivity extends BaseActivity
|
|||||||
|
|
||||||
Habit habit = getHabitFromIntent();
|
Habit habit = getHabitFromIntent();
|
||||||
ShowHabitScreen screen = new ShowHabitScreen(this, habit);
|
ShowHabitScreen screen = new ShowHabitScreen(this, habit);
|
||||||
setScreen(screen);
|
ShowHabitRootView view = new ShowHabitRootView(this, habit);
|
||||||
|
screen.setRootView(view);
|
||||||
|
this.setScreen(screen);
|
||||||
|
|
||||||
|
ShowHabitsMenu menu = new ShowHabitsMenu(this, screen);
|
||||||
|
ShowHabitController controller = new ShowHabitController(screen, habit);
|
||||||
|
screen.setMenu(menu);
|
||||||
|
view.setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.habits.show;
|
||||||
|
|
||||||
|
import android.support.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.commands.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.tasks.*;
|
||||||
|
import org.isoron.uhabits.ui.habits.edit.*;
|
||||||
|
|
||||||
|
import javax.inject.*;
|
||||||
|
|
||||||
|
public class ShowHabitController implements ShowHabitRootView.Controller,
|
||||||
|
HistoryEditorDialog.Controller
|
||||||
|
{
|
||||||
|
@NonNull
|
||||||
|
private final ShowHabitScreen screen;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final Habit habit;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CommandRunner commandRunner;
|
||||||
|
|
||||||
|
public ShowHabitController(@NonNull ShowHabitScreen screen,
|
||||||
|
@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
HabitsApplication.getComponent().inject(this);
|
||||||
|
this.screen = screen;
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onToolbarChanged()
|
||||||
|
{
|
||||||
|
screen.invalidateToolbar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEditHistoryButtonClick()
|
||||||
|
{
|
||||||
|
screen.showEditHistoryDialog(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onToggleCheckmark(long timestamp)
|
||||||
|
{
|
||||||
|
new SimpleTask(() -> {
|
||||||
|
ToggleRepetitionCommand command;
|
||||||
|
command = new ToggleRepetitionCommand(habit, timestamp);
|
||||||
|
commandRunner.execute(command, null);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,8 @@ import butterknife.*;
|
|||||||
|
|
||||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||||
|
|
||||||
public class ShowHabitRootView extends BaseRootView implements ModelObservable.Listener
|
public class ShowHabitRootView extends BaseRootView
|
||||||
|
implements ModelObservable.Listener
|
||||||
{
|
{
|
||||||
@NonNull
|
@NonNull
|
||||||
private Habit habit;
|
private Habit habit;
|
||||||
@@ -59,27 +60,63 @@ public class ShowHabitRootView extends BaseRootView implements ModelObservable.L
|
|||||||
@BindView(R.id.toolbar)
|
@BindView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
|
||||||
private final ShowHabitScreen screen;
|
@NonNull
|
||||||
|
private Controller controller;
|
||||||
|
|
||||||
public ShowHabitRootView(@NonNull Context context,
|
public ShowHabitRootView(@NonNull Context context,
|
||||||
@NonNull Habit habit,
|
@NonNull Habit habit)
|
||||||
@NonNull ShowHabitScreen screen)
|
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.screen = screen;
|
|
||||||
|
|
||||||
addView(inflate(getContext(), R.layout.show_habit, null));
|
addView(inflate(getContext(), R.layout.show_habit, null));
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
controller = new Controller() {};
|
||||||
|
|
||||||
initCards();
|
initCards();
|
||||||
initToolbar();
|
initToolbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getDisplayHomeAsUp()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Toolbar getToolbar()
|
||||||
|
{
|
||||||
|
return toolbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setController(@NonNull Controller controller)
|
||||||
|
{
|
||||||
|
this.controller = controller;
|
||||||
|
historyCard.setController(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getToolbarColor()
|
||||||
|
{
|
||||||
|
if (!getStyledBoolean(getContext(), R.attr.useHabitColorAsPrimary))
|
||||||
|
return super.getToolbarColor();
|
||||||
|
|
||||||
|
return ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModelChange()
|
public void onModelChange()
|
||||||
{
|
{
|
||||||
post(() -> screen.invalidateToolbar());
|
controller.onToolbarChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initToolbar()
|
||||||
|
{
|
||||||
|
super.initToolbar();
|
||||||
|
toolbar.setTitle(habit.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,35 +133,6 @@ public class ShowHabitRootView extends BaseRootView implements ModelObservable.L
|
|||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getDisplayHomeAsUp()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Toolbar getToolbar()
|
|
||||||
{
|
|
||||||
return toolbar;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getToolbarColor()
|
|
||||||
{
|
|
||||||
if (!getStyledBoolean(getContext(), R.attr.useHabitColorAsPrimary))
|
|
||||||
return super.getToolbarColor();
|
|
||||||
|
|
||||||
return ColorUtils.getColor(getContext(), habit.getColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initToolbar()
|
|
||||||
{
|
|
||||||
super.initToolbar();
|
|
||||||
toolbar.setTitle(habit.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCards()
|
private void initCards()
|
||||||
{
|
{
|
||||||
subtitleCard.setHabit(habit);
|
subtitleCard.setHabit(habit);
|
||||||
@@ -134,4 +142,9 @@ public class ShowHabitRootView extends BaseRootView implements ModelObservable.L
|
|||||||
streakCard.setHabit(habit);
|
streakCard.setHabit(habit);
|
||||||
frequencyCard.setHabit(habit);
|
frequencyCard.setHabit(habit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Controller extends HistoryCard.Controller
|
||||||
|
{
|
||||||
|
default void onToolbarChanged(){}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,19 +35,23 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
|
|
||||||
ShowHabitRootView view = new ShowHabitRootView(activity, habit, this);
|
|
||||||
ShowHabitsMenu menu = new ShowHabitsMenu(activity, this);
|
|
||||||
|
|
||||||
setRootView(view);
|
|
||||||
setMenu(menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showEditHabitDialog()
|
public void showEditHabitDialog()
|
||||||
{
|
{
|
||||||
|
Long id = habit.getId();
|
||||||
|
if (id == null) throw new RuntimeException("habit not saved");
|
||||||
|
|
||||||
FragmentManager manager = activity.getSupportFragmentManager();
|
FragmentManager manager = activity.getSupportFragmentManager();
|
||||||
EditHabitDialogFragment
|
EditHabitDialogFragment.newInstance(id).show(manager, "editHabit");
|
||||||
.newInstance(habit.getId())
|
}
|
||||||
.show(manager, "editHabit");
|
|
||||||
|
public void showEditHistoryDialog(
|
||||||
|
@NonNull HistoryEditorDialog.Controller controller)
|
||||||
|
{
|
||||||
|
HistoryEditorDialog dialog = new HistoryEditorDialog();
|
||||||
|
dialog.setHabit(habit);
|
||||||
|
dialog.setController(controller);
|
||||||
|
dialog.show(activity.getSupportFragmentManager(), "historyEditor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package org.isoron.uhabits.ui.habits.show.views;
|
package org.isoron.uhabits.ui.habits.show.views;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
@@ -39,6 +40,9 @@ public class HistoryCard extends HabitCard
|
|||||||
@BindView(R.id.title)
|
@BindView(R.id.title)
|
||||||
TextView title;
|
TextView title;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Controller controller;
|
||||||
|
|
||||||
public HistoryCard(Context context)
|
public HistoryCard(Context context)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
@@ -55,10 +59,13 @@ public class HistoryCard extends HabitCard
|
|||||||
public void onClickEditButton()
|
public void onClickEditButton()
|
||||||
{
|
{
|
||||||
Log.d("HistoryCard", "onClickEditButton");
|
Log.d("HistoryCard", "onClickEditButton");
|
||||||
|
controller.onEditHistoryButtonClick();
|
||||||
|
}
|
||||||
|
|
||||||
// HistoryEditorDialog frag = new HistoryEditorDialog();
|
public void setController(@NonNull Controller controller)
|
||||||
// frag.setHabit(habit);
|
{
|
||||||
// frag.show(getContext().getFragmentManager(), "historyEditor");
|
this.controller = controller;
|
||||||
|
chart.setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,7 +97,7 @@ public class HistoryCard extends HabitCard
|
|||||||
{
|
{
|
||||||
inflate(getContext(), R.layout.show_habit_history, this);
|
inflate(getContext(), R.layout.show_habit_history, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
controller = new Controller() {};
|
||||||
if (isInEditMode()) initEditMode();
|
if (isInEditMode()) initEditMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,4 +108,9 @@ public class HistoryCard extends HabitCard
|
|||||||
chart.setColor(color);
|
chart.setColor(color);
|
||||||
chart.populateWithRandomData();
|
chart.populateWithRandomData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Controller extends HistoryChart.Controller
|
||||||
|
{
|
||||||
|
default void onEditHistoryButtonClick() {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class StreakCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected void refreshData()
|
protected void refreshData()
|
||||||
{
|
{
|
||||||
new MyBaseTask().execute();
|
new RefreshTask().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
@@ -77,20 +77,21 @@ public class StreakCard extends HabitCard
|
|||||||
streakChart.populateWithRandomData();
|
streakChart.populateWithRandomData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MyBaseTask extends BaseTask
|
private class RefreshTask extends BaseTask
|
||||||
{
|
{
|
||||||
public List<Streak> streaks;
|
public List<Streak> bestStreaks;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInBackground()
|
protected void doInBackground()
|
||||||
{
|
{
|
||||||
streaks = getHabit().getStreaks().getBest(NUM_STREAKS);
|
StreakList streaks = getHabit().getStreaks();
|
||||||
|
bestStreaks = streaks.getBest(NUM_STREAKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid)
|
protected void onPostExecute(Void aVoid)
|
||||||
{
|
{
|
||||||
streakChart.setStreaks(streaks);
|
streakChart.setStreaks(bestStreaks);
|
||||||
super.onPostExecute(aVoid);
|
super.onPostExecute(aVoid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user