|
|
@ -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,7 +106,15 @@ 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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
originalHabit = Habit.get((Long) args.get("habitId"));
|
|
|
|
originalHabit = Habit.get((Long) args.get("habitId"));
|
|
|
@ -109,12 +123,11 @@ 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());
|
|
|
|
|
|
|
|
tvFreqDen.append(modified_habit.freq_den.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tvFreqNum.append(modified_habit.freq_num.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);
|
|
|
|
|
|
|
|
|
|
|
|