mirror of https://github.com/iSoron/uhabits.git
parent
fe7e8ef039
commit
7de69c1c10
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.edit;
|
||||
|
||||
import android.support.v4.app.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.activities.habits.edit.views.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
public class BooleanHabitDialogHelper
|
||||
{
|
||||
private DialogFragment frag;
|
||||
|
||||
@BindView(R.id.tvName)
|
||||
TextView tvName;
|
||||
|
||||
@BindView(R.id.tvDescription)
|
||||
TextView tvDescription;
|
||||
|
||||
@BindView(R.id.reminderPanel)
|
||||
ReminderPanel reminderPanel;
|
||||
|
||||
@BindView(R.id.frequencyPanel)
|
||||
FrequencyPanel frequencyPanel;
|
||||
|
||||
public BooleanHabitDialogHelper(DialogFragment frag, View view)
|
||||
{
|
||||
this.frag = frag;
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
protected void populateForm(final Habit habit)
|
||||
{
|
||||
tvName.setText(habit.getName());
|
||||
tvDescription.setText(habit.getDescription());
|
||||
populateColor(habit.getColor());
|
||||
}
|
||||
|
||||
void parseFormIntoHabit(Habit habit)
|
||||
{
|
||||
habit.setName(tvName.getText().toString().trim());
|
||||
habit.setDescription(tvDescription.getText().toString().trim());
|
||||
}
|
||||
|
||||
void populateColor(int paletteColor)
|
||||
{
|
||||
tvName.setTextColor(
|
||||
ColorUtils.getColor(frag.getContext(), paletteColor));
|
||||
}
|
||||
|
||||
boolean validate(Habit habit)
|
||||
{
|
||||
Boolean valid = true;
|
||||
|
||||
if (habit.getName().isEmpty())
|
||||
{
|
||||
tvName.setError(frag.getString(R.string.validation_name_should_not_be_blank));
|
||||
valid = false;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.edit;
|
||||
|
||||
import com.google.auto.factory.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
|
||||
@AutoFactory(allowSubclasses = true)
|
||||
public class CreateBooleanHabitDialog extends BooleanHabitDialog
|
||||
{
|
||||
@Override
|
||||
protected int getTitle()
|
||||
{
|
||||
return R.string.create_habit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeHabits()
|
||||
{
|
||||
modifiedHabit = modelFactory.buildHabit();
|
||||
modifiedHabit.setFrequency(Frequency.DAILY);
|
||||
modifiedHabit.setColor(prefs.getDefaultHabitColor(modifiedHabit.getColor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveHabit()
|
||||
{
|
||||
Command command = appComponent
|
||||
.getCreateHabitCommandFactory()
|
||||
.create(habitList, modifiedHabit);
|
||||
commandRunner.execute(command, null);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.edit;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
|
||||
public class EditBooleanHabitDialog extends BooleanHabitDialog
|
||||
{
|
||||
@Override
|
||||
protected int getTitle()
|
||||
{
|
||||
return R.string.edit_habit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeHabits()
|
||||
{
|
||||
Long habitId = (Long) getArguments().get("habitId");
|
||||
if (habitId == null)
|
||||
throw new IllegalArgumentException("habitId must be specified");
|
||||
|
||||
originalHabit = habitList.getById(habitId);
|
||||
modifiedHabit = modelFactory.buildHabit();
|
||||
modifiedHabit.copyFrom(originalHabit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveHabit()
|
||||
{
|
||||
Command command = appComponent.getEditHabitCommandFactory().
|
||||
create(habitList, originalHabit, modifiedHabit);
|
||||
commandRunner.execute(command, originalHabit.getId());
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.edit.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.content.res.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.activities.common.views.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
|
||||
public class NameDescriptionPanel extends FrameLayout
|
||||
{
|
||||
@BindView(R.id.tvName)
|
||||
EditText tvName;
|
||||
|
||||
@BindView(R.id.tvDescription)
|
||||
ExampleEditText tvDescription;
|
||||
|
||||
private int color;
|
||||
|
||||
@NonNull
|
||||
private Controller controller;
|
||||
|
||||
public NameDescriptionPanel(@NonNull Context context,
|
||||
@Nullable AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
|
||||
View view = inflate(context, R.layout.edit_habit_name, null);
|
||||
ButterKnife.bind(this, view);
|
||||
addView(view);
|
||||
|
||||
controller = new Controller() {};
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(int color)
|
||||
{
|
||||
this.color = color;
|
||||
tvName.setTextColor(ColorUtils.getColor(getContext(), color));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getDescription()
|
||||
{
|
||||
return tvDescription.getRealText().trim();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getName()
|
||||
{
|
||||
return tvName.getText().toString().trim();
|
||||
}
|
||||
|
||||
public void populateFrom(@NonNull Habit habit)
|
||||
{
|
||||
Resources res = getResources();
|
||||
|
||||
if(habit.isNumerical())
|
||||
tvDescription.setExample(res.getString(R.string.example_question_numerical));
|
||||
else
|
||||
tvDescription.setExample(res.getString(R.string.example_question_boolean));
|
||||
|
||||
setColor(habit.getColor());
|
||||
tvName.setText(habit.getName());
|
||||
tvDescription.setRealText(habit.getDescription());
|
||||
}
|
||||
|
||||
public boolean validate()
|
||||
{
|
||||
Resources res = getResources();
|
||||
|
||||
if (getName().isEmpty())
|
||||
{
|
||||
tvName.setError(
|
||||
res.getString(R.string.validation_name_should_not_be_blank));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state)
|
||||
{
|
||||
BundleSavedState bss = (BundleSavedState) state;
|
||||
setColor(bss.bundle.getInt("color"));
|
||||
super.onRestoreInstanceState(bss.getSuperState());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState()
|
||||
{
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("color", color);
|
||||
return new BundleSavedState(superState, bundle);
|
||||
}
|
||||
|
||||
@OnClick(R.id.buttonPickColor)
|
||||
void showColorPicker()
|
||||
{
|
||||
controller.onColorPickerClicked(color);
|
||||
}
|
||||
|
||||
public void setController(@NonNull Controller controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public interface Controller
|
||||
{
|
||||
/**
|
||||
* Called when the user has clicked the widget to select a new
|
||||
* color for the habit.
|
||||
*
|
||||
* @param previousColor the color previously selected
|
||||
*/
|
||||
default void onColorPickerClicked(int previousColor) {}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://isoron.org/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
style="@style/dialogFormRow">
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/tilName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="6">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tvName"
|
||||
style="@style/dialogFormInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/name">
|
||||
|
||||
<requestFocus/>
|
||||
</EditText>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/buttonPickColor"
|
||||
style="@style/dialogFormInputColor"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/color_picker_default_title"
|
||||
android:src="?dialogIconChangeColor"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<org.isoron.uhabits.activities.habits.edit.views.ExampleEditText
|
||||
android:id="@+id/tvDescription"
|
||||
style="@style/dialogFormInputMultiline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/question"
|
||||
app:example="@string/example_question_numerical"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue