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