mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Update views on background thread
This commit is contained in:
@@ -47,6 +47,7 @@ import org.isoron.uhabits.dialogs.HistoryEditorDialog;
|
||||
import org.isoron.uhabits.helpers.ReminderHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.Score;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.isoron.uhabits.views.HabitDataView;
|
||||
import org.isoron.uhabits.views.HabitFrequencyView;
|
||||
import org.isoron.uhabits.views.HabitHistoryView;
|
||||
@@ -151,6 +152,7 @@ public class ShowHabitFragment extends Fragment
|
||||
private void updateScoreRing(View view)
|
||||
{
|
||||
if(habit == null) return;
|
||||
if(view == null) return;
|
||||
|
||||
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
|
||||
scoreRing.setColor(habit.color);
|
||||
@@ -230,11 +232,29 @@ public class ShowHabitFragment extends Fragment
|
||||
|
||||
public void refreshData()
|
||||
{
|
||||
if(dataViews == null) return;
|
||||
updateScoreRing(getView());
|
||||
new BaseTask()
|
||||
{
|
||||
@Override
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
if(dataViews == null) return null;
|
||||
updateScoreRing(getView());
|
||||
|
||||
for(HabitDataView view : dataViews)
|
||||
view.refreshData();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
if(dataViews == null) return;
|
||||
for(HabitDataView view : dataViews)
|
||||
view.invalidate();
|
||||
}
|
||||
}.execute();
|
||||
|
||||
for(HabitDataView view : dataViews)
|
||||
view.refreshData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,4 +26,6 @@ public interface HabitDataView
|
||||
void setHabit(Habit habit);
|
||||
|
||||
void refreshData();
|
||||
|
||||
void invalidate();
|
||||
}
|
||||
|
||||
@@ -180,8 +180,6 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
||||
generateRandomData();
|
||||
else if(habit != null)
|
||||
frequency = habit.repetitions.getWeekdayFrequency();
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
@@ -221,7 +220,6 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
|
||||
}
|
||||
|
||||
updateDate();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void generateRandomData()
|
||||
|
||||
@@ -185,8 +185,6 @@ public class HabitScoreView extends ScrollableDataView implements HabitDataView
|
||||
if (habit == null) return;
|
||||
scores = habit.scores.getAllValues(bucketSize);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setBucketSize(int bucketSize)
|
||||
|
||||
@@ -169,7 +169,6 @@ public class HabitStreakView extends View implements HabitDataView
|
||||
if(habit == null) return;
|
||||
streaks = habit.streaks.getAll(maxStreakCount);
|
||||
updateMaxMin();
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user