mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove code duplication
This commit is contained in:
@@ -56,11 +56,22 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
Bundle savedInstanceState)
|
Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
View view = inflater.inflate(R.layout.edit_habit, container, false);
|
View view = inflater.inflate(R.layout.edit_habit, container, false);
|
||||||
helper = new BaseDialogHelper(this, view);
|
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
|
helper = new BaseDialogHelper(this, view);
|
||||||
|
getDialog().setTitle(getTitle());
|
||||||
|
initializeHabits();
|
||||||
|
restoreSavedInstance(savedInstanceState);
|
||||||
|
helper.populateForm(modifiedHabit);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void initializeHabits();
|
||||||
|
|
||||||
|
protected abstract void saveHabit();
|
||||||
|
|
||||||
|
protected abstract int getTitle();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
public void onSaveInstanceState(Bundle outState)
|
public void onSaveInstanceState(Bundle outState)
|
||||||
@@ -138,8 +149,6 @@ public abstract class BaseDialogFragment extends AppCompatDialogFragment
|
|||||||
helper.populateFrequencyFields(modifiedHabit);
|
helper.populateFrequencyFields(modifiedHabit);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void saveHabit();
|
|
||||||
|
|
||||||
@OnClick(R.id.buttonPickColor)
|
@OnClick(R.id.buttonPickColor)
|
||||||
void showColorPicker()
|
void showColorPicker()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,11 +19,6 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.ui.habits.edit;
|
package org.isoron.uhabits.ui.habits.edit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.commands.Command;
|
import org.isoron.uhabits.commands.Command;
|
||||||
import org.isoron.uhabits.commands.CommandRunner;
|
import org.isoron.uhabits.commands.CommandRunner;
|
||||||
@@ -33,18 +28,13 @@ import org.isoron.uhabits.models.Habit;
|
|||||||
public class CreateHabitDialogFragment extends BaseDialogFragment
|
public class CreateHabitDialogFragment extends BaseDialogFragment
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
protected int getTitle()
|
||||||
Bundle savedInstanceState)
|
|
||||||
{
|
{
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
return R.string.create_habit;
|
||||||
getDialog().setTitle(R.string.create_habit);
|
|
||||||
initializeHabits();
|
|
||||||
restoreSavedInstance(savedInstanceState);
|
|
||||||
helper.populateForm(modifiedHabit);
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeHabits()
|
@Override
|
||||||
|
protected void initializeHabits()
|
||||||
{
|
{
|
||||||
modifiedHabit = new Habit();
|
modifiedHabit = new Habit();
|
||||||
modifiedHabit.freqNum = 1;
|
modifiedHabit.freqNum = 1;
|
||||||
|
|||||||
@@ -20,9 +20,6 @@
|
|||||||
package org.isoron.uhabits.ui.habits.edit;
|
package org.isoron.uhabits.ui.habits.edit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.commands.Command;
|
import org.isoron.uhabits.commands.Command;
|
||||||
@@ -42,18 +39,13 @@ public class EditHabitDialogFragment extends BaseDialogFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
protected int getTitle()
|
||||||
Bundle savedInstanceState)
|
|
||||||
{
|
{
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
return R.string.edit_habit;
|
||||||
getDialog().setTitle(R.string.edit_habit);
|
|
||||||
initializeHabits();
|
|
||||||
restoreSavedInstance(savedInstanceState);
|
|
||||||
helper.populateForm(modifiedHabit);
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeHabits()
|
@Override
|
||||||
|
protected void initializeHabits()
|
||||||
{
|
{
|
||||||
Long habitId = (Long) getArguments().get("habitId");
|
Long habitId = (Long) getArguments().get("habitId");
|
||||||
if(habitId == null) throw new IllegalArgumentException("habitId must be specified");
|
if(habitId == null) throw new IllegalArgumentException("habitId must be specified");
|
||||||
|
|||||||
Reference in New Issue
Block a user