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