Save default color and frequency

pull/30/head
Alinson S. Xavier 10 years ago
parent 903aee951b
commit ed6167c3f7

@ -7,9 +7,11 @@ import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
import android.app.DialogFragment;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -35,6 +37,8 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
private Habit originalHabit, modified_habit;
private TextView tvName, tvDescription, tvFreqNum, tvFreqDen, tvInputReminder;
private SharedPreferences prefs;
static class SolidColorMatrix extends ColorMatrix
{
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);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
Bundle args = getArguments();
mode = (Integer) args.get("editMode");
@ -100,6 +106,14 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
{
getDialog().setTitle("Create 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)
{
@ -109,11 +123,10 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
getDialog().setTitle("Edit habit");
tvName.append(modified_habit.name);
tvDescription.append(modified_habit.description);
tvFreqNum.setText(null);
tvFreqDen.setText(null);
}
tvFreqNum.append(modified_habit.freq_num.toString());
tvFreqDen.append(modified_habit.freq_den.toString());
}
changeColor(modified_habit.color);
updateReminder();
@ -130,7 +143,6 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
{
public void onColorSelected(int color)
{
modified_habit.color = color;
changeColor(color);
}
});
@ -143,13 +155,12 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
private void changeColor(Integer color)
{
// SolidColorMatrix matrix = new SolidColorMatrix(color);
// ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
// Drawable background = getActivity().getResources().getDrawable(
// R.drawable.apptheme_edit_text_holo_light);
// background.setColorFilter(filter);
// tvName.setBackgroundDrawable(background);
modified_habit.color = color;
tvName.setTextColor(color);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("pref_default_habit_color", color);
editor.apply();
}
private void updateReminder()
@ -247,6 +258,11 @@ public class EditHabitFragment extends DialogFragment implements OnClickListener
if(!valid)
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)
command = originalHabit.new EditCommand(modified_habit);

@ -70,10 +70,12 @@ public class Habit extends Model
public Habit()
{
this.color = ColorHelper.palette[7];
this.color = ColorHelper.palette[5];
this.position = Habit.getCount();
this.highlight = 0;
this.archived = 0;
this.freq_den = 7;
this.freq_num = 3;
}
public static Habit get(Long id)

@ -43,7 +43,6 @@
<EditText
android:id="@+id/input_freq_num"
android:text="@string/default_freq_num"
style="@style/dialogFormInputSmallNumber" />
<TextView
@ -54,7 +53,6 @@
<EditText
android:id="@+id/input_freq_den"
android:text="@string/default_freq_den"
style="@style/dialogFormInputSmallNumber" />
<TextView

@ -53,9 +53,7 @@
<string name="description">Description</string>
<string name="description_hint">Description</string>
<string name="repeat">Repeat</string>
<string name="default_freq_num">3</string>
<string name="times_every">times every</string>
<string name="default_freq_den">7</string>
<string name="days">days</string>
<string name="reminder">Reminder</string>
<string name="discard">Discard</string>

Loading…
Cancel
Save