mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Refresh data after closing history editor
This commit is contained in:
@@ -36,6 +36,7 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
implements DialogInterface.OnClickListener
|
||||
{
|
||||
private Habit habit;
|
||||
private Listener listener;
|
||||
HabitHistoryView historyView;
|
||||
|
||||
@Override
|
||||
@@ -75,7 +76,7 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
|
||||
if(listener != null) listener.onHistoryEditorClosed();
|
||||
}
|
||||
|
||||
public void setHabit(Habit habit)
|
||||
@@ -83,4 +84,13 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
this.habit = 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.RingView;
|
||||
|
||||
public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedListener
|
||||
public class ShowHabitFragment extends Fragment
|
||||
implements DialogHelper.OnSavedListener, HistoryEditorDialog.Listener
|
||||
{
|
||||
protected ShowHabitActivity activity;
|
||||
private Habit habit;
|
||||
private HabitStreakView streakView;
|
||||
private HabitScoreView scoreView;
|
||||
private HabitHistoryView historyView;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
@@ -66,29 +70,14 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
||||
|
||||
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);
|
||||
HabitStreakView streakView = (HabitStreakView) view.findViewById(R.id.streakView);
|
||||
HabitScoreView scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
|
||||
HabitHistoryView historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
|
||||
streakView = (HabitStreakView) view.findViewById(R.id.streakView);
|
||||
scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
|
||||
historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
|
||||
|
||||
tvHistory.setTextColor(habit.color);
|
||||
tvOverview.setTextColor(habit.color);
|
||||
tvStrength.setTextColor(habit.color);
|
||||
tvStreaks.setTextColor(habit.color);
|
||||
updateHeaders(view);
|
||||
updateScoreRing(view);
|
||||
|
||||
scoreRing.setColor(habit.color);
|
||||
scoreRing.setPercentage((float) habit.scores.getNewestValue() / Score.MAX_SCORE);
|
||||
streakView.setHabit(habit);
|
||||
scoreView.setHabit(habit);
|
||||
historyView.setHabit(habit);
|
||||
@@ -100,6 +89,7 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
||||
{
|
||||
HistoryEditorDialog frag = new HistoryEditorDialog();
|
||||
frag.setHabit(habit);
|
||||
frag.setListener(ShowHabitFragment.this);
|
||||
frag.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
});
|
||||
@@ -108,6 +98,31 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
||||
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
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
@@ -142,4 +157,18 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
||||
ReminderHelper.createReminderAlarms(activity);
|
||||
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;
|
||||
createColors();
|
||||
fetchData();
|
||||
refreshData();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
fetchData();
|
||||
refreshData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -202,7 +202,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
pSquareFg.setTextAlign(Align.CENTER);
|
||||
}
|
||||
|
||||
protected void fetchData()
|
||||
public void refreshData()
|
||||
{
|
||||
if(isInEditMode())
|
||||
generateRandomData();
|
||||
@@ -213,6 +213,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
}
|
||||
|
||||
updateDate();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
@@ -371,7 +372,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
fetchData();
|
||||
refreshData();
|
||||
invalidate();
|
||||
}
|
||||
}.execute();
|
||||
|
||||
@@ -79,13 +79,13 @@ public class HabitScoreView extends ScrollableDataView
|
||||
{
|
||||
this.habit = habit;
|
||||
createColors();
|
||||
fetchData();
|
||||
refreshData();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
fetchData();
|
||||
refreshData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -164,7 +164,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
em = pText.getFontSpacing();
|
||||
}
|
||||
|
||||
protected void fetchData()
|
||||
public void refreshData()
|
||||
{
|
||||
if(isInEditMode())
|
||||
generateRandomData();
|
||||
@@ -174,6 +174,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
|
||||
@@ -74,13 +74,13 @@ public class HabitStreakView extends ScrollableDataView
|
||||
this.habit = habit;
|
||||
|
||||
createColors();
|
||||
fetchData();
|
||||
refreshData();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
fetchData();
|
||||
refreshData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -159,7 +159,7 @@ public class HabitStreakView extends ScrollableDataView
|
||||
pBar.setAntiAlias(true);
|
||||
}
|
||||
|
||||
protected void fetchData()
|
||||
public void refreshData()
|
||||
{
|
||||
if(isInEditMode())
|
||||
generateRandomData();
|
||||
@@ -185,6 +185,8 @@ public class HabitStreakView extends ScrollableDataView
|
||||
maxStreakLength = Math.max(maxStreakLength, s.length);
|
||||
}
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
|
||||
@@ -58,8 +58,6 @@ public abstract class ScrollableDataView extends View implements GestureDetector
|
||||
scrollAnimator.addUpdateListener(this);
|
||||
}
|
||||
|
||||
protected abstract void fetchData();
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user