Refresh data after closing history editor

pull/30/head
Alinson S. Xavier 10 years ago
parent 821373a340
commit aa86826bdb

@ -36,6 +36,7 @@ public class HistoryEditorDialog extends DialogFragment
implements DialogInterface.OnClickListener implements DialogInterface.OnClickListener
{ {
private Habit habit; private Habit habit;
private Listener listener;
HabitHistoryView historyView; HabitHistoryView historyView;
@Override @Override
@ -75,7 +76,7 @@ public class HistoryEditorDialog extends DialogFragment
@Override @Override
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
if(listener != null) listener.onHistoryEditorClosed();
} }
public void setHabit(Habit habit) public void setHabit(Habit habit)
@ -83,4 +84,13 @@ public class HistoryEditorDialog extends DialogFragment
this.habit = habit; this.habit = habit;
if(historyView != null) historyView.setHabit(habit); if(historyView != null) historyView.setHabit(habit);
} }
public void setListener(Listener listener)
{
this.listener = listener;
}
public interface Listener {
void onHistoryEditorClosed();
}
} }

@ -45,10 +45,14 @@ import org.isoron.uhabits.views.HabitScoreView;
import org.isoron.uhabits.views.HabitStreakView; import org.isoron.uhabits.views.HabitStreakView;
import org.isoron.uhabits.views.RingView; import org.isoron.uhabits.views.RingView;
public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedListener public class ShowHabitFragment extends Fragment
implements DialogHelper.OnSavedListener, HistoryEditorDialog.Listener
{ {
protected ShowHabitActivity activity; protected ShowHabitActivity activity;
private Habit habit; private Habit habit;
private HabitStreakView streakView;
private HabitScoreView scoreView;
private HabitHistoryView historyView;
@Override @Override
public void onStart() public void onStart()
@ -66,29 +70,14 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
habit.checkmarks.rebuild(); habit.checkmarks.rebuild();
if (android.os.Build.VERSION.SDK_INT >= 21)
{
int darkerHabitColor = ColorHelper.mixColors(habit.color, Color.BLACK, 0.75f);
activity.getWindow().setStatusBarColor(darkerHabitColor);
}
TextView tvHistory = (TextView) view.findViewById(R.id.tvHistory);
TextView tvOverview = (TextView) view.findViewById(R.id.tvOverview);
TextView tvStrength = (TextView) view.findViewById(R.id.tvStrength);
TextView tvStreaks = (TextView) view.findViewById(R.id.tvStreaks);
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
Button btEditHistory = (Button) view.findViewById(R.id.btEditHistory); Button btEditHistory = (Button) view.findViewById(R.id.btEditHistory);
HabitStreakView streakView = (HabitStreakView) view.findViewById(R.id.streakView); streakView = (HabitStreakView) view.findViewById(R.id.streakView);
HabitScoreView scoreView = (HabitScoreView) view.findViewById(R.id.scoreView); scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
HabitHistoryView historyView = (HabitHistoryView) view.findViewById(R.id.historyView); historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
tvHistory.setTextColor(habit.color); updateHeaders(view);
tvOverview.setTextColor(habit.color); updateScoreRing(view);
tvStrength.setTextColor(habit.color);
tvStreaks.setTextColor(habit.color);
scoreRing.setColor(habit.color);
scoreRing.setPercentage((float) habit.scores.getNewestValue() / Score.MAX_SCORE);
streakView.setHabit(habit); streakView.setHabit(habit);
scoreView.setHabit(habit); scoreView.setHabit(habit);
historyView.setHabit(habit); historyView.setHabit(habit);
@ -100,6 +89,7 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
{ {
HistoryEditorDialog frag = new HistoryEditorDialog(); HistoryEditorDialog frag = new HistoryEditorDialog();
frag.setHabit(habit); frag.setHabit(habit);
frag.setListener(ShowHabitFragment.this);
frag.show(getFragmentManager(), "dialog"); frag.show(getFragmentManager(), "dialog");
} }
}); });
@ -108,6 +98,31 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
return view; return view;
} }
private void updateScoreRing(View view)
{
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
scoreRing.setColor(habit.color);
scoreRing.setPercentage((float) habit.scores.getNewestValue() / Score.MAX_SCORE);
}
private void updateHeaders(View view)
{
if (android.os.Build.VERSION.SDK_INT >= 21)
{
int darkerHabitColor = ColorHelper.mixColors(habit.color, Color.BLACK, 0.75f);
activity.getWindow().setStatusBarColor(darkerHabitColor);
}
TextView tvHistory = (TextView) view.findViewById(R.id.tvHistory);
TextView tvOverview = (TextView) view.findViewById(R.id.tvOverview);
TextView tvStrength = (TextView) view.findViewById(R.id.tvStrength);
TextView tvStreaks = (TextView) view.findViewById(R.id.tvStreaks);
tvHistory.setTextColor(habit.color);
tvOverview.setTextColor(habit.color);
tvStrength.setTextColor(habit.color);
tvStreaks.setTextColor(habit.color);
}
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{ {
@ -142,4 +157,18 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
ReminderHelper.createReminderAlarms(activity); ReminderHelper.createReminderAlarms(activity);
activity.recreate(); activity.recreate();
} }
@Override
public void onHistoryEditorClosed()
{
refreshData();
}
private void refreshData()
{
streakView.refreshData();
historyView.refreshData();
scoreView.refreshData();
updateScoreRing(getView());
}
} }

@ -80,13 +80,13 @@ public class HabitHistoryView extends ScrollableDataView
{ {
this.habit = habit; this.habit = habit;
createColors(); createColors();
fetchData(); refreshData();
postInvalidate(); postInvalidate();
} }
private void init() private void init()
{ {
fetchData(); refreshData();
createPaints(); createPaints();
createColors(); createColors();
@ -202,7 +202,7 @@ public class HabitHistoryView extends ScrollableDataView
pSquareFg.setTextAlign(Align.CENTER); pSquareFg.setTextAlign(Align.CENTER);
} }
protected void fetchData() public void refreshData()
{ {
if(isInEditMode()) if(isInEditMode())
generateRandomData(); generateRandomData();
@ -213,6 +213,7 @@ public class HabitHistoryView extends ScrollableDataView
} }
updateDate(); updateDate();
invalidate();
} }
private void generateRandomData() private void generateRandomData()
@ -371,7 +372,7 @@ public class HabitHistoryView extends ScrollableDataView
@Override @Override
protected void onPostExecute(Void aVoid) protected void onPostExecute(Void aVoid)
{ {
fetchData(); refreshData();
invalidate(); invalidate();
} }
}.execute(); }.execute();

@ -79,13 +79,13 @@ public class HabitScoreView extends ScrollableDataView
{ {
this.habit = habit; this.habit = habit;
createColors(); createColors();
fetchData(); refreshData();
postInvalidate(); postInvalidate();
} }
private void init() private void init()
{ {
fetchData(); refreshData();
createPaints(); createPaints();
createColors(); createColors();
@ -164,7 +164,7 @@ public class HabitScoreView extends ScrollableDataView
em = pText.getFontSpacing(); em = pText.getFontSpacing();
} }
protected void fetchData() public void refreshData()
{ {
if(isInEditMode()) if(isInEditMode())
generateRandomData(); generateRandomData();
@ -174,6 +174,7 @@ public class HabitScoreView extends ScrollableDataView
scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay); scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay);
} }
invalidate();
} }
private void generateRandomData() private void generateRandomData()

@ -74,13 +74,13 @@ public class HabitStreakView extends ScrollableDataView
this.habit = habit; this.habit = habit;
createColors(); createColors();
fetchData(); refreshData();
postInvalidate(); postInvalidate();
} }
private void init() private void init()
{ {
fetchData(); refreshData();
createPaints(); createPaints();
createColors(); createColors();
@ -159,7 +159,7 @@ public class HabitStreakView extends ScrollableDataView
pBar.setAntiAlias(true); pBar.setAntiAlias(true);
} }
protected void fetchData() public void refreshData()
{ {
if(isInEditMode()) if(isInEditMode())
generateRandomData(); generateRandomData();
@ -185,6 +185,8 @@ public class HabitStreakView extends ScrollableDataView
maxStreakLength = Math.max(maxStreakLength, s.length); maxStreakLength = Math.max(maxStreakLength, s.length);
} }
} }
invalidate();
} }
private void generateRandomData() private void generateRandomData()

@ -58,8 +58,6 @@ public abstract class ScrollableDataView extends View implements GestureDetector
scrollAnimator.addUpdateListener(this); scrollAnimator.addUpdateListener(this);
} }
protected abstract void fetchData();
@Override @Override
public boolean onTouchEvent(MotionEvent event) public boolean onTouchEvent(MotionEvent event)
{ {

Loading…
Cancel
Save