mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Make ScoreView use custom interval also on widgets
This commit is contained in:
@@ -19,9 +19,7 @@
|
||||
|
||||
package org.isoron.uhabits.fragments;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -74,9 +72,6 @@ public class ShowHabitFragment extends Fragment
|
||||
@Nullable
|
||||
private HabitScoreView scoreView;
|
||||
|
||||
@Nullable
|
||||
private SharedPreferences prefs;
|
||||
|
||||
private int previousScoreInterval;
|
||||
|
||||
private float todayScore;
|
||||
@@ -112,9 +107,7 @@ public class ShowHabitFragment extends Fragment
|
||||
|
||||
scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
||||
if(defaultScoreInterval > 5 || defaultScoreInterval < 0) defaultScoreInterval = 1;
|
||||
int defaultScoreInterval = UIHelper.getDefaultScoreInterval(getContext());
|
||||
previousScoreInterval = defaultScoreInterval;
|
||||
setScoreBucketSize(defaultScoreInterval);
|
||||
|
||||
@@ -291,6 +284,8 @@ public class ShowHabitFragment extends Fragment
|
||||
else activity.executeCommand(command, h.getId());
|
||||
|
||||
ReminderHelper.createReminderAlarms(activity);
|
||||
HabitBroadcastReceiver.sendRefreshBroadcast(getActivity());
|
||||
|
||||
activity.recreate();
|
||||
}
|
||||
|
||||
@@ -349,15 +344,15 @@ public class ShowHabitFragment extends Fragment
|
||||
{
|
||||
if(scoreView == null) return;
|
||||
|
||||
int sizes[] = { 1, 7, 31, 92, 365 };
|
||||
int size = sizes[position];
|
||||
scoreView.setBucketSize(HabitScoreView.DEFAULT_BUCKET_SIZES[position]);
|
||||
|
||||
scoreView.setBucketSize(size);
|
||||
if(position != previousScoreInterval) refreshData();
|
||||
|
||||
if(prefs != null)
|
||||
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
||||
if(position != previousScoreInterval)
|
||||
{
|
||||
refreshData();
|
||||
HabitBroadcastReceiver.sendRefreshBroadcast(getActivity());
|
||||
}
|
||||
|
||||
UIHelper.setDefaultScoreInterval(getContext(), position);
|
||||
previousScoreInterval = position;
|
||||
}
|
||||
|
||||
|
||||
@@ -302,4 +302,20 @@ public abstract class UIHelper
|
||||
{
|
||||
return getCurrentTheme() == THEME_DARK;
|
||||
}
|
||||
|
||||
|
||||
public static void setDefaultScoreInterval(Context context, int position)
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
||||
}
|
||||
|
||||
public static int getDefaultScoreInterval(Context context)
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
||||
if(defaultScoreInterval > 5 || defaultScoreInterval < 0) defaultScoreInterval = 1;
|
||||
|
||||
return defaultScoreInterval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public class HabitScoreView extends ScrollableDataView implements HabitDataView
|
||||
public static final PorterDuffXfermode XFERMODE_SRC =
|
||||
new PorterDuffXfermode(PorterDuff.Mode.SRC);
|
||||
|
||||
public static int DEFAULT_BUCKET_SIZES[] = { 1, 7, 31, 92, 365 };
|
||||
|
||||
private Paint pGrid;
|
||||
private float em;
|
||||
private Habit habit;
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.view.View;
|
||||
|
||||
import org.isoron.uhabits.HabitBroadcastReceiver;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.helpers.UIHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.views.GraphWidgetView;
|
||||
import org.isoron.uhabits.views.HabitDataView;
|
||||
@@ -34,8 +35,13 @@ public class ScoreWidgetProvider extends BaseWidgetProvider
|
||||
@Override
|
||||
protected View buildCustomView(Context context, Habit habit)
|
||||
{
|
||||
int defaultScoreInterval = UIHelper.getDefaultScoreInterval(context);
|
||||
int size = HabitScoreView.DEFAULT_BUCKET_SIZES[defaultScoreInterval];
|
||||
|
||||
HabitScoreView dataView = new HabitScoreView(context);
|
||||
dataView.setIsTransparencyEnabled(true);
|
||||
dataView.setBucketSize(size);
|
||||
|
||||
GraphWidgetView view = new GraphWidgetView(context, dataView);
|
||||
view.setHabit(habit);
|
||||
return view;
|
||||
|
||||
Reference in New Issue
Block a user