mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Fix ShowHabitFragment and HistoryEditorDialog
This commit is contained in:
@@ -30,6 +30,7 @@ import android.util.Log;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.isoron.uhabits.views.HabitHistoryView;
|
||||
|
||||
public class HistoryEditorDialog extends DialogFragment
|
||||
@@ -44,7 +45,6 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
{
|
||||
Context context = getActivity();
|
||||
historyView = new HabitHistoryView(context, null);
|
||||
int p = (int) getResources().getDimension(R.dimen.history_editor_padding);
|
||||
|
||||
if(savedInstanceState != null)
|
||||
{
|
||||
@@ -52,7 +52,8 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
if(id > 0) this.habit = Habit.get(id);
|
||||
}
|
||||
|
||||
historyView.setPadding(p, 0, p, 0);
|
||||
int padding = (int) getResources().getDimension(R.dimen.history_editor_padding);
|
||||
historyView.setPadding(padding, 0, padding, 0);
|
||||
historyView.setHabit(habit);
|
||||
historyView.setIsEditable(true);
|
||||
|
||||
@@ -61,9 +62,25 @@ public class HistoryEditorDialog extends DialogFragment
|
||||
.setView(historyView)
|
||||
.setPositiveButton(android.R.string.ok, this);
|
||||
|
||||
refreshData();
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void refreshData()
|
||||
{
|
||||
new BaseTask()
|
||||
{
|
||||
@Override
|
||||
@SuppressWarnings("ResourceType")
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
historyView.refreshData();
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
|
||||
@@ -117,7 +117,6 @@ public class ShowHabitFragment extends Fragment
|
||||
dataViews.add((RepetitionCountView) llRepetition.getChildAt(i));
|
||||
|
||||
updateHeaders(view);
|
||||
updateScoreRing(view);
|
||||
|
||||
for(HabitDataView dataView : dataViews)
|
||||
dataView.setHabit(habit);
|
||||
@@ -146,6 +145,8 @@ public class ShowHabitFragment extends Fragment
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
refreshData();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -272,7 +273,7 @@ public class ShowHabitFragment extends Fragment
|
||||
if(scoreView != null)
|
||||
{
|
||||
scoreView.setBucketSize(size);
|
||||
scoreView.refreshData();
|
||||
refreshData();
|
||||
}
|
||||
|
||||
if(prefs != null)
|
||||
|
||||
@@ -106,7 +106,6 @@ public class CheckmarkView extends View
|
||||
public void setHabit(Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
refreshData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,6 +191,7 @@ public class CheckmarkView extends View
|
||||
this.label = habit.name;
|
||||
|
||||
textPaint.setColor(Color.WHITE);
|
||||
postInvalidate();
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,13 +84,10 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
||||
{
|
||||
this.habit = habit;
|
||||
createColors();
|
||||
refreshData();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
refreshData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -180,6 +177,8 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
||||
generateRandomData();
|
||||
else if(habit != null)
|
||||
frequency = habit.repetitions.getWeekdayFrequency();
|
||||
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.isoron.uhabits.helpers.ColorHelper;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.helpers.UIHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.isoron.uhabits.tasks.ToggleRepetitionTask;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -88,13 +89,10 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
|
||||
{
|
||||
this.habit = habit;
|
||||
createColors();
|
||||
refreshData();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
refreshData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -220,6 +218,7 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
|
||||
}
|
||||
|
||||
updateDate();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
@@ -386,11 +385,23 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
|
||||
this.isEditable = isEditable;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onToggleRepetitionFinished()
|
||||
{
|
||||
refreshData();
|
||||
invalidate();
|
||||
new BaseTask() {
|
||||
@Override
|
||||
@SuppressWarnings("ResourceType")
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
refreshData();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
invalidate();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,15 +93,12 @@ public class HabitScoreView extends ScrollableDataView implements HabitDataView
|
||||
{
|
||||
this.habit = habit;
|
||||
createColors();
|
||||
refreshData();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
createPaints();
|
||||
createColors();
|
||||
if(isInEditMode()) refreshData();
|
||||
|
||||
dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
|
||||
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
|
||||
@@ -185,6 +182,8 @@ public class HabitScoreView extends ScrollableDataView implements HabitDataView
|
||||
if (habit == null) return;
|
||||
scores = habit.scores.getAllValues(bucketSize);
|
||||
}
|
||||
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setBucketSize(int bucketSize)
|
||||
|
||||
@@ -78,9 +78,7 @@ public class HabitStreakView extends View implements HabitDataView
|
||||
public void setHabit(Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
|
||||
createColors();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
@@ -118,7 +116,6 @@ public class HabitStreakView extends View implements HabitDataView
|
||||
em = paint.getFontSpacing();
|
||||
textMargin = 0.5f * em;
|
||||
|
||||
refreshData();
|
||||
updateMaxMin();
|
||||
}
|
||||
|
||||
@@ -169,6 +166,7 @@ public class HabitStreakView extends View implements HabitDataView
|
||||
if(habit == null) return;
|
||||
streaks = habit.streaks.getAll(maxStreakCount);
|
||||
updateMaxMin();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,8 +44,6 @@ public class RepetitionCountView extends NumberView implements HabitDataView
|
||||
getResources().getString(R.string.last_x_days));
|
||||
|
||||
setLabel(String.format(labelFormat, labelValue));
|
||||
|
||||
refreshData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,6 +71,8 @@ public class RepetitionCountView extends NumberView implements HabitDataView
|
||||
|
||||
if(habit != null)
|
||||
setNumber(habit.repetitions.count(from, to));
|
||||
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +80,5 @@ public class RepetitionCountView extends NumberView implements HabitDataView
|
||||
{
|
||||
this.habit = habit;
|
||||
setColor(habit.color);
|
||||
refreshData();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user