mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Save default color and frequency
This commit is contained in:
@@ -7,9 +7,11 @@ import org.isoron.uhabits.R;
|
|||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.ColorMatrix;
|
import android.graphics.ColorMatrix;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -35,6 +37,8 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
private Habit originalHabit, modified_habit;
|
private Habit originalHabit, modified_habit;
|
||||||
private TextView tvName, tvDescription, tvFreqNum, tvFreqDen, tvInputReminder;
|
private TextView tvName, tvDescription, tvFreqNum, tvFreqDen, tvInputReminder;
|
||||||
|
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
static class SolidColorMatrix extends ColorMatrix
|
static class SolidColorMatrix extends ColorMatrix
|
||||||
{
|
{
|
||||||
public SolidColorMatrix(int color)
|
public SolidColorMatrix(int color)
|
||||||
@@ -93,6 +97,8 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
|
|
||||||
ImageButton buttonPickColor = (ImageButton) view.findViewById(R.id.button_pick_color);
|
ImageButton buttonPickColor = (ImageButton) view.findViewById(R.id.button_pick_color);
|
||||||
|
|
||||||
|
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
mode = (Integer) args.get("editMode");
|
mode = (Integer) args.get("editMode");
|
||||||
|
|
||||||
@@ -100,6 +106,14 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
{
|
{
|
||||||
getDialog().setTitle("Create habit");
|
getDialog().setTitle("Create habit");
|
||||||
modified_habit = new Habit();
|
modified_habit = new Habit();
|
||||||
|
|
||||||
|
int defaultNum = prefs.getInt("pref_default_habit_freq_num", modified_habit.freq_num);
|
||||||
|
int defaultDen = prefs.getInt("pref_default_habit_freq_den", modified_habit.freq_den);
|
||||||
|
int defaultColor = prefs.getInt("pref_default_habit_color", modified_habit.color);
|
||||||
|
|
||||||
|
modified_habit.color = defaultColor;
|
||||||
|
modified_habit.freq_num = defaultNum;
|
||||||
|
modified_habit.freq_den = defaultDen;
|
||||||
}
|
}
|
||||||
else if(mode == EDIT_MODE)
|
else if(mode == EDIT_MODE)
|
||||||
{
|
{
|
||||||
@@ -109,11 +123,10 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
getDialog().setTitle("Edit habit");
|
getDialog().setTitle("Edit habit");
|
||||||
tvName.append(modified_habit.name);
|
tvName.append(modified_habit.name);
|
||||||
tvDescription.append(modified_habit.description);
|
tvDescription.append(modified_habit.description);
|
||||||
tvFreqNum.setText(null);
|
}
|
||||||
tvFreqDen.setText(null);
|
|
||||||
tvFreqNum.append(modified_habit.freq_num.toString());
|
tvFreqNum.append(modified_habit.freq_num.toString());
|
||||||
tvFreqDen.append(modified_habit.freq_den.toString());
|
tvFreqDen.append(modified_habit.freq_den.toString());
|
||||||
}
|
|
||||||
|
|
||||||
changeColor(modified_habit.color);
|
changeColor(modified_habit.color);
|
||||||
updateReminder();
|
updateReminder();
|
||||||
@@ -130,7 +143,6 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
{
|
{
|
||||||
public void onColorSelected(int color)
|
public void onColorSelected(int color)
|
||||||
{
|
{
|
||||||
modified_habit.color = color;
|
|
||||||
changeColor(color);
|
changeColor(color);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -143,13 +155,12 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
|
|
||||||
private void changeColor(Integer color)
|
private void changeColor(Integer color)
|
||||||
{
|
{
|
||||||
// SolidColorMatrix matrix = new SolidColorMatrix(color);
|
modified_habit.color = color;
|
||||||
// ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
|
|
||||||
// Drawable background = getActivity().getResources().getDrawable(
|
|
||||||
// R.drawable.apptheme_edit_text_holo_light);
|
|
||||||
// background.setColorFilter(filter);
|
|
||||||
// tvName.setBackgroundDrawable(background);
|
|
||||||
tvName.setTextColor(color);
|
tvName.setTextColor(color);
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putInt("pref_default_habit_color", color);
|
||||||
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateReminder()
|
private void updateReminder()
|
||||||
@@ -247,6 +258,11 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
|
|||||||
if(!valid)
|
if(!valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putInt("pref_default_habit_freq_num", modified_habit.freq_num);
|
||||||
|
editor.putInt("pref_default_habit_freq_den", modified_habit.freq_den);
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
if(mode == EDIT_MODE)
|
if(mode == EDIT_MODE)
|
||||||
command = originalHabit.new EditCommand(modified_habit);
|
command = originalHabit.new EditCommand(modified_habit);
|
||||||
|
|
||||||
|
|||||||
@@ -70,10 +70,12 @@ public class Habit extends Model
|
|||||||
|
|
||||||
public Habit()
|
public Habit()
|
||||||
{
|
{
|
||||||
this.color = ColorHelper.palette[7];
|
this.color = ColorHelper.palette[5];
|
||||||
this.position = Habit.getCount();
|
this.position = Habit.getCount();
|
||||||
this.highlight = 0;
|
this.highlight = 0;
|
||||||
this.archived = 0;
|
this.archived = 0;
|
||||||
|
this.freq_den = 7;
|
||||||
|
this.freq_num = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Habit get(Long id)
|
public static Habit get(Long id)
|
||||||
|
|||||||
@@ -43,7 +43,6 @@
|
|||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/input_freq_num"
|
android:id="@+id/input_freq_num"
|
||||||
android:text="@string/default_freq_num"
|
|
||||||
style="@style/dialogFormInputSmallNumber" />
|
style="@style/dialogFormInputSmallNumber" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -54,7 +53,6 @@
|
|||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/input_freq_den"
|
android:id="@+id/input_freq_den"
|
||||||
android:text="@string/default_freq_den"
|
|
||||||
style="@style/dialogFormInputSmallNumber" />
|
style="@style/dialogFormInputSmallNumber" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
@@ -53,9 +53,7 @@
|
|||||||
<string name="description">Description</string>
|
<string name="description">Description</string>
|
||||||
<string name="description_hint">Description</string>
|
<string name="description_hint">Description</string>
|
||||||
<string name="repeat">Repeat</string>
|
<string name="repeat">Repeat</string>
|
||||||
<string name="default_freq_num">3</string>
|
|
||||||
<string name="times_every">times every</string>
|
<string name="times_every">times every</string>
|
||||||
<string name="default_freq_den">7</string>
|
|
||||||
<string name="days">days</string>
|
<string name="days">days</string>
|
||||||
<string name="reminder">Reminder</string>
|
<string name="reminder">Reminder</string>
|
||||||
<string name="discard">Discard</string>
|
<string name="discard">Discard</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user