HistoryEditorDialog: Listen to commands

pull/699/head
Alinson S. Xavier 5 years ago
parent 0f2f010f94
commit 27023e50ae

@ -31,6 +31,7 @@ import android.util.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.common.views.*; import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.core.commands.*;
import org.isoron.uhabits.core.models.*; import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.preferences.*; import org.isoron.uhabits.core.preferences.*;
import org.isoron.uhabits.core.tasks.*; import org.isoron.uhabits.core.tasks.*;
@ -41,7 +42,7 @@ import org.jetbrains.annotations.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*; import static org.isoron.uhabits.utils.InterfaceUtils.*;
public class HistoryEditorDialog extends AppCompatDialogFragment public class HistoryEditorDialog extends AppCompatDialogFragment
implements DialogInterface.OnClickListener implements DialogInterface.OnClickListener, CommandRunner.Listener
{ {
@Nullable @Nullable
private Habit habit; private Habit habit;
@ -58,6 +59,8 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
private Preferences prefs; private Preferences prefs;
private CommandRunner commandRunner;
public HistoryEditorDialog() public HistoryEditorDialog()
{ {
this.onToggleCheckmarkListener = new OnToggleCheckmarkListener() this.onToggleCheckmarkListener = new OnToggleCheckmarkListener()
@ -85,6 +88,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
(HabitsApplication) getActivity().getApplicationContext(); (HabitsApplication) getActivity().getApplicationContext();
habitList = app.getComponent().getHabitList(); habitList = app.getComponent().getHabitList();
taskRunner = app.getComponent().getTaskRunner(); taskRunner = app.getComponent().getTaskRunner();
commandRunner = app.getComponent().getCommandRunner();
prefs = app.getComponent().getPreferences(); prefs = app.getComponent().getPreferences();
historyChart = new HistoryChart(context); historyChart = new HistoryChart(context);
@ -127,9 +131,17 @@ 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);
commandRunner.addListener(this);
refreshData(); refreshData();
} }
@Override
public void onPause()
{
commandRunner.removeListener(this);
super.onPause();
}
@Override @Override
public void onSaveInstanceState(Bundle outState) public void onSaveInstanceState(Bundle outState)
{ {
@ -153,6 +165,12 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
taskRunner.execute(new RefreshTask()); taskRunner.execute(new RefreshTask());
} }
@Override
public void onCommandExecuted(@Nullable Command command, @Nullable Long refreshKey)
{
refreshData();
}
private class RefreshTask implements Task private class RefreshTask implements Task
{ {
public int[] checkmarks; public int[] checkmarks;

Loading…
Cancel
Save