mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
First working task creating/update form
This commit is contained in:
parent
73f8c596d3
commit
bbe80a30c4
14 changed files with 395 additions and 45 deletions
|
|
@ -139,30 +139,29 @@
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="72dp">
|
android:layout_height="72dp">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:text="@string/negative_habit_form"
|
|
||||||
android:id="@+id/textView8"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginTop="11dp" />
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/task_negative_checkbox"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginTop="0dp" />
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="@string/negative_habit_form"
|
||||||
|
android:id="@+id/textView8"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginTop="11dp" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/task_negative_checkbox"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginTop="0dp" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
@ -182,5 +181,35 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:id="@+id/task_weekdays_wrapper"
|
||||||
|
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:text="@string/frequency"
|
||||||
|
android:id="@+id/textView10" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:id="@+id/task_frequency_spinner" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/task_frequency_container"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
22
Habitica/res/layout/row_checklist.xml
Normal file
22
Habitica/res/layout/row_checklist.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="72dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:id="@+id/label"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginTop="11dp" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/checkbox"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginTop="0dp" />
|
||||||
|
</RelativeLayout>
|
||||||
27
Habitica/res/layout/row_number_picker.xml
Normal file
27
Habitica/res/layout/row_number_picker.xml
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="72dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:id="@+id/label"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginTop="11dp" />
|
||||||
|
|
||||||
|
<NumberPicker
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/numberPicker"
|
||||||
|
android:layout_toRightOf="@id/label"
|
||||||
|
android:layout_toEndOf="@id/label"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true" />
|
||||||
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
@ -124,6 +124,10 @@
|
||||||
<string name="notes">Notes</string>
|
<string name="notes">Notes</string>
|
||||||
<string name="text">Text</string>
|
<string name="text">Text</string>
|
||||||
<string name="difficulty">Difficulty</string>
|
<string name="difficulty">Difficulty</string>
|
||||||
|
<string name="trivial">Trivial</string>
|
||||||
|
<string name="easy">Easy</string>
|
||||||
|
<string name="medium">Medium</string>
|
||||||
|
<string name="hard">Hard</string>
|
||||||
<string name="start_date">Start Date</string>
|
<string name="start_date">Start Date</string>
|
||||||
<string name="positive_habit_form">Positive ( + )</string>
|
<string name="positive_habit_form">Positive ( + )</string>
|
||||||
<string name="negative_habit_form">Negative ( - )</string>
|
<string name="negative_habit_form">Negative ( - )</string>
|
||||||
|
|
@ -131,4 +135,16 @@
|
||||||
<string name="actions">Actions</string>
|
<string name="actions">Actions</string>
|
||||||
<string name="task">Task</string>
|
<string name="task">Task</string>
|
||||||
|
|
||||||
|
<string name="frequency">Frequency</string>
|
||||||
|
<string name="frequency_weekly">On Certain Days of the Week</string>
|
||||||
|
<string name="frequency_daily">Every X Days</string>
|
||||||
|
|
||||||
|
<string name="monday">Monday</string>
|
||||||
|
<string name="tuesday">Tuesday</string>
|
||||||
|
<string name="wednesday">Wednesday</string>
|
||||||
|
<string name="thursday">Thursday</string>
|
||||||
|
<string name="friday">Friday</string>
|
||||||
|
<string name="saturday">Saturday</string>
|
||||||
|
<string name="sunday">Sunday</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<string-array name="task_difficulties">
|
|
||||||
<item>Trivial</item>
|
|
||||||
<item>Easy</item>
|
|
||||||
<item>Medium</item>
|
|
||||||
<item>Hard</item>
|
|
||||||
</string-array>
|
|
||||||
</resources>
|
|
||||||
|
|
@ -7,4 +7,26 @@
|
||||||
<string-array name="prefs_items_values">
|
<string-array name="prefs_items_values">
|
||||||
<item>https://habitrpg.com/</item>
|
<item>https://habitrpg.com/</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="task_difficulties">
|
||||||
|
<item>@string/trivial</item>
|
||||||
|
<item>@string/easy</item>
|
||||||
|
<item>@string/medium</item>
|
||||||
|
<item>@string/hard</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="daily_frequencies">
|
||||||
|
<item>@string/frequency_weekly</item>
|
||||||
|
<item>@string/frequency_daily</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="weekdays">
|
||||||
|
<item>@string/monday</item>
|
||||||
|
<item>@string/tuesday</item>
|
||||||
|
<item>@string/wednesday</item>
|
||||||
|
<item>@string/thursday</item>
|
||||||
|
<item>@string/friday</item>
|
||||||
|
<item>@string/saturday</item>
|
||||||
|
<item>@string/sunday</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ public class APIHelper implements ErrorHandler, Profiler {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public void createUndefNewTask(HabitItem item, Callback cb) {
|
public void createNewTask(HabitItem item, Callback cb) {
|
||||||
if(item instanceof Habit) {
|
if(item instanceof Habit) {
|
||||||
createNewTask((Habit) item, cb);
|
createNewTask((Habit) item, cb);
|
||||||
} else if(item instanceof Daily) {
|
} else if(item instanceof Daily) {
|
||||||
|
|
@ -175,6 +175,19 @@ public class APIHelper implements ErrorHandler, Profiler {
|
||||||
public void deleteTask(HabitItem item, TaskDeletionCallback cb) {
|
public void deleteTask(HabitItem item, TaskDeletionCallback cb) {
|
||||||
this.apiService.deleteTask(item.getId(), cb);
|
this.apiService.deleteTask(item.getId(), cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateTask(HabitItem item, Callback cb) {
|
||||||
|
if(item instanceof Habit) {
|
||||||
|
updateTask((Habit) item, cb);
|
||||||
|
} else if(item instanceof Daily) {
|
||||||
|
updateTask((Daily) item, cb);
|
||||||
|
} else if(item instanceof ToDo) {
|
||||||
|
updateTask((ToDo) item, cb);
|
||||||
|
} else if(item instanceof Reward) {
|
||||||
|
updateTask((Reward) item, cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateTask(Daily item, Callback<Daily> cb) {
|
public void updateTask(Daily item, Callback<Daily> cb) {
|
||||||
this.apiService.updateTask(item.getId(), item, cb);
|
this.apiService.updateTask(item.getId(), item, cb);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
||||||
Callback<List<ItemData>> {
|
Callback<List<ItemData>> {
|
||||||
static final int SETTINGS = 11;
|
static final int SETTINGS = 11;
|
||||||
static final int ABOUT = 12;
|
static final int ABOUT = 12;
|
||||||
|
static final int TASK_CREATED_RESULT = 1;
|
||||||
|
static final int TASK_UPDATED_RESULT = 2;
|
||||||
|
|
||||||
//region View Elements
|
//region View Elements
|
||||||
@InjectView(R.id.materialViewPager)
|
@InjectView(R.id.materialViewPager)
|
||||||
|
|
@ -289,7 +291,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
||||||
|
|
||||||
Intent intent = new Intent(this, TaskFormActivity.class);
|
Intent intent = new Intent(this, TaskFormActivity.class);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
startActivity(intent);
|
startActivityForResult(intent, TASK_UPDATED_RESULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEvent(TaskLongPressedEvent event) {
|
public void onEvent(TaskLongPressedEvent event) {
|
||||||
|
|
@ -310,7 +312,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
||||||
|
|
||||||
Intent intent = new Intent(this, TaskFormActivity.class);
|
Intent intent = new Intent(this, TaskFormActivity.class);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
startActivity(intent);
|
startActivityForResult(intent, TASK_CREATED_RESULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEvent(final BuyRewardTappedEvent event) {
|
public void onEvent(final BuyRewardTappedEvent event) {
|
||||||
|
|
@ -361,6 +363,15 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEvent(final TaskSaveEvent event) {
|
||||||
|
HabitItem task = (HabitItem) event.task;
|
||||||
|
if (event.created) {
|
||||||
|
this.mAPIHelper.createNewTask(task, new TaskCreationCallback(this));
|
||||||
|
} else {
|
||||||
|
this.mAPIHelper.updateTask(task, new TaskUpdateCallback(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void notifyUser(double xp, double hp, double gold,
|
private void notifyUser(double xp, double hp, double gold,
|
||||||
double lvl, double delta) {
|
double lvl, double delta) {
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
|
|
@ -690,7 +701,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
||||||
@Override
|
@Override
|
||||||
public void onTaskCreation(HabitItem task, boolean editMode) {
|
public void onTaskCreation(HabitItem task, boolean editMode) {
|
||||||
if (!editMode) {
|
if (!editMode) {
|
||||||
this.mAPIHelper.createUndefNewTask(task, new TaskCreationCallback(this));
|
this.mAPIHelper.createNewTask(task, new TaskCreationCallback(this));
|
||||||
} else {
|
} else {
|
||||||
this.mAPIHelper.uprateUndefinedTask(task, new TaskUpdateCallback(this));
|
this.mAPIHelper.uprateUndefinedTask(task, new TaskUpdateCallback(this));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,55 @@
|
||||||
package com.habitrpg.android.habitica;
|
package com.habitrpg.android.habitica;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.NumberPicker;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.R;
|
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Days;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo;
|
||||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.greenrobot.event.EventBus;
|
||||||
|
import io.fabric.sdk.android.services.concurrency.Task;
|
||||||
|
|
||||||
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.daily;
|
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.daily;
|
||||||
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.habit;
|
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.habit;
|
||||||
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.reward;
|
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.reward;
|
||||||
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.todo;
|
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.todo;
|
||||||
|
|
||||||
public class TaskFormActivity extends AppCompatActivity {
|
public class TaskFormActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
|
||||||
|
|
||||||
private HabitType taskType;
|
private HabitType taskType;
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
private HabitItem task;
|
||||||
|
|
||||||
private EditText taskText, taskNotes;
|
private EditText taskText, taskNotes;
|
||||||
private Spinner taskDifficulty;
|
private Spinner taskDifficultySpinner, dailyFrequencySpinner;
|
||||||
private CheckBox positiveCheckBox, negativeCheckBox;
|
private CheckBox positiveCheckBox, negativeCheckBox;
|
||||||
|
|
||||||
|
private List<CheckBox> weekdayCheckboxes = new ArrayList<CheckBox>();
|
||||||
|
private NumberPicker frequencyPicker;
|
||||||
|
private LinearLayout frequencyContainer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
@ -54,12 +70,12 @@ public class TaskFormActivity extends AppCompatActivity {
|
||||||
LinearLayout mainWrapper = (LinearLayout) findViewById(R.id.task_main_wrapper);
|
LinearLayout mainWrapper = (LinearLayout) findViewById(R.id.task_main_wrapper);
|
||||||
taskText = (EditText) findViewById(R.id.task_text_edittext);
|
taskText = (EditText) findViewById(R.id.task_text_edittext);
|
||||||
taskNotes = (EditText) findViewById(R.id.task_notes_edittext);
|
taskNotes = (EditText) findViewById(R.id.task_notes_edittext);
|
||||||
taskDifficulty = (Spinner) findViewById(R.id.task_difficulty_spinner);
|
taskDifficultySpinner = (Spinner) findViewById(R.id.task_difficulty_spinner);
|
||||||
|
|
||||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
|
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
|
||||||
R.array.task_difficulties, android.R.layout.simple_spinner_item);
|
R.array.task_difficulties, android.R.layout.simple_spinner_item);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
taskDifficulty.setAdapter(adapter);
|
taskDifficultySpinner.setAdapter(adapter);
|
||||||
|
|
||||||
if (taskType == habit) {
|
if (taskType == habit) {
|
||||||
LinearLayout startDateLayout = (LinearLayout) findViewById(R.id.task_startdate_layout);
|
LinearLayout startDateLayout = (LinearLayout) findViewById(R.id.task_startdate_layout);
|
||||||
|
|
@ -78,24 +94,82 @@ public class TaskFormActivity extends AppCompatActivity {
|
||||||
mainWrapper.removeView(actionsLayout);
|
mainWrapper.removeView(actionsLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinearLayout weekdayWrapper = (LinearLayout)findViewById(R.id.task_weekdays_wrapper);
|
||||||
|
if (taskType == daily) {
|
||||||
|
this.dailyFrequencySpinner = (Spinner) weekdayWrapper.findViewById(R.id.task_frequency_spinner);
|
||||||
|
|
||||||
|
ArrayAdapter<CharSequence> frequencyAdapter = ArrayAdapter.createFromResource(this,
|
||||||
|
R.array.daily_frequencies, android.R.layout.simple_spinner_item);
|
||||||
|
frequencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
this.dailyFrequencySpinner.setAdapter(frequencyAdapter);
|
||||||
|
this.dailyFrequencySpinner.setOnItemSelectedListener(this);
|
||||||
|
|
||||||
|
this.frequencyContainer = (LinearLayout) weekdayWrapper.findViewById(R.id.task_frequency_container);
|
||||||
|
} else {
|
||||||
|
mainWrapper.removeView(weekdayWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
if (taskId != null) {
|
if (taskId != null) {
|
||||||
switch (taskType) {
|
switch (taskType) {
|
||||||
case todo:
|
case todo:
|
||||||
ToDo todo = new Select().from(ToDo.class).byIds(taskId).querySingle();
|
ToDo todo = new Select().from(ToDo.class).byIds(taskId).querySingle();
|
||||||
|
this.task = todo;
|
||||||
this.populate(todo);
|
this.populate(todo);
|
||||||
break;
|
break;
|
||||||
case daily:
|
case daily:
|
||||||
Daily daily = new Select().from(Daily.class).byIds(taskId).querySingle();
|
Daily daily = new Select().from(Daily.class).byIds(taskId).querySingle();
|
||||||
|
this.task = daily;
|
||||||
this.populate(daily);
|
this.populate(daily);
|
||||||
break;
|
break;
|
||||||
case habit:
|
case habit:
|
||||||
Habit habit = new Select().from(Habit.class).byIds(taskId).querySingle();
|
Habit habit = new Select().from(Habit.class).byIds(taskId).querySingle();
|
||||||
|
this.task = habit;
|
||||||
this.populate(habit);
|
this.populate(habit);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDailyFrequencyViews() {
|
||||||
|
this.frequencyContainer.removeAllViews();
|
||||||
|
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
||||||
|
String[] weekdays = getResources().getStringArray(R.array.weekdays);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
View weekdayRow = getLayoutInflater().inflate(R.layout.row_checklist, null);
|
||||||
|
TextView tv = (TextView) weekdayRow.findViewById(R.id.label);
|
||||||
|
CheckBox checkbox = (CheckBox) weekdayRow.findViewById(R.id.checkbox);
|
||||||
|
this.weekdayCheckboxes.add(checkbox);
|
||||||
|
tv.setText(weekdays[i]);
|
||||||
|
this.frequencyContainer.addView(weekdayRow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
View dayRow = getLayoutInflater().inflate(R.layout.row_number_picker, null);
|
||||||
|
this.frequencyPicker = (NumberPicker) dayRow.findViewById(R.id.numberPicker);
|
||||||
|
this.frequencyPicker.setMinValue(1);
|
||||||
|
this.frequencyPicker.setMaxValue(366);
|
||||||
|
TextView tv = (TextView) dayRow.findViewById(R.id.label);
|
||||||
|
tv.setText(getResources().getString(R.string.frequency_daily));
|
||||||
|
this.frequencyContainer.addView(dayRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.task != null) {
|
||||||
|
Daily daily = (Daily) this.task;
|
||||||
|
|
||||||
|
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
||||||
|
this.weekdayCheckboxes.get(0).setChecked(daily.getRepeat().getM());
|
||||||
|
this.weekdayCheckboxes.get(1).setChecked(daily.getRepeat().getT());
|
||||||
|
this.weekdayCheckboxes.get(2).setChecked(daily.getRepeat().getW());
|
||||||
|
this.weekdayCheckboxes.get(3).setChecked(daily.getRepeat().getTh());
|
||||||
|
this.weekdayCheckboxes.get(4).setChecked(daily.getRepeat().getF());
|
||||||
|
this.weekdayCheckboxes.get(5).setChecked(daily.getRepeat().getS());
|
||||||
|
this.weekdayCheckboxes.get(6).setChecked(daily.getRepeat().getSu());
|
||||||
|
} else {
|
||||||
|
this.frequencyPicker.setValue(daily.getEveryX());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
|
@ -122,6 +196,16 @@ public class TaskFormActivity extends AppCompatActivity {
|
||||||
private void populate(HabitItem task) {
|
private void populate(HabitItem task) {
|
||||||
taskText.setText(task.text);
|
taskText.setText(task.text);
|
||||||
taskNotes.setText(task.notes);
|
taskNotes.setText(task.notes);
|
||||||
|
float priority = task.getPriority();
|
||||||
|
if (priority == 0.1) {
|
||||||
|
this.taskDifficultySpinner.setSelection(0);
|
||||||
|
} else if (priority == 1.0) {
|
||||||
|
this.taskDifficultySpinner.setSelection(1);
|
||||||
|
} else if (priority == 1.5) {
|
||||||
|
this.taskDifficultySpinner.setSelection(2);
|
||||||
|
} else if (priority == 2.0) {
|
||||||
|
this.taskDifficultySpinner.setSelection(3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populate(Habit task) {
|
private void populate(Habit task) {
|
||||||
|
|
@ -132,9 +216,113 @@ public class TaskFormActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private void populate(Daily task) {
|
private void populate(Daily task) {
|
||||||
populate((HabitItem) task);
|
populate((HabitItem) task);
|
||||||
|
|
||||||
|
if (task.getFrequency().equals("weekly")) {
|
||||||
|
this.dailyFrequencySpinner.setSelection(0);
|
||||||
|
if (weekdayCheckboxes.size() == 7) {
|
||||||
|
this.weekdayCheckboxes.get(0).setChecked(task.getRepeat().getM());
|
||||||
|
this.weekdayCheckboxes.get(1).setChecked(task.getRepeat().getT());
|
||||||
|
this.weekdayCheckboxes.get(2).setChecked(task.getRepeat().getW());
|
||||||
|
this.weekdayCheckboxes.get(3).setChecked(task.getRepeat().getTh());
|
||||||
|
this.weekdayCheckboxes.get(4).setChecked(task.getRepeat().getF());
|
||||||
|
this.weekdayCheckboxes.get(5).setChecked(task.getRepeat().getS());
|
||||||
|
this.weekdayCheckboxes.get(6).setChecked(task.getRepeat().getSu());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.dailyFrequencySpinner.setSelection(1);
|
||||||
|
if (this.frequencyPicker != null) {
|
||||||
|
this.frequencyPicker.setValue(task.getEveryX());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populate(ToDo task) {
|
private void populate(ToDo task) {
|
||||||
populate((HabitItem) task);
|
populate((HabitItem) task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveTask(HabitItem task) {
|
||||||
|
task.text = taskText.getText().toString();
|
||||||
|
task.notes = taskNotes.getText().toString();
|
||||||
|
|
||||||
|
if (this.taskDifficultySpinner.getSelectedItemPosition() == 0) {
|
||||||
|
task.setPriority((float) 0.1);
|
||||||
|
} else if (this.taskDifficultySpinner.getSelectedItemPosition() == 1) {
|
||||||
|
task.setPriority((float) 1.0);
|
||||||
|
} else if (this.taskDifficultySpinner.getSelectedItemPosition() == 2) {
|
||||||
|
task.setPriority((float) 1.5);
|
||||||
|
} else if (this.taskDifficultySpinner.getSelectedItemPosition() == 3) {
|
||||||
|
task.setPriority((float) 2.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveTask(Habit task) {
|
||||||
|
task.setUp(positiveCheckBox.isChecked());
|
||||||
|
task.setDown(negativeCheckBox.isChecked());
|
||||||
|
this.saveTask((HabitItem) task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveTask(Daily task) {
|
||||||
|
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
||||||
|
task.setFrequency("weekly");
|
||||||
|
task.getRepeat().setM(this.weekdayCheckboxes.get(0).isChecked());
|
||||||
|
task.getRepeat().setT(this.weekdayCheckboxes.get(1).isChecked());
|
||||||
|
task.getRepeat().setW(this.weekdayCheckboxes.get(2).isChecked());
|
||||||
|
task.getRepeat().setTh(this.weekdayCheckboxes.get(3).isChecked());
|
||||||
|
task.getRepeat().setF(this.weekdayCheckboxes.get(4).isChecked());
|
||||||
|
task.getRepeat().setS(this.weekdayCheckboxes.get(5).isChecked());
|
||||||
|
task.getRepeat().setSu(this.weekdayCheckboxes.get(6).isChecked());
|
||||||
|
} else {
|
||||||
|
task.setFrequency("daily");
|
||||||
|
task.setEveryX(this.frequencyPicker.getValue());
|
||||||
|
}
|
||||||
|
this.saveTask((HabitItem) task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveTask(ToDo task) {
|
||||||
|
this.saveTask((HabitItem) task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view,
|
||||||
|
int pos, long id) {
|
||||||
|
this.setDailyFrequencyViews();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
this.setDailyFrequencyViews();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareSave() {
|
||||||
|
TaskSaveEvent event = new TaskSaveEvent();
|
||||||
|
if (this.task == null) {
|
||||||
|
event.created = true;
|
||||||
|
switch (taskType) {
|
||||||
|
case todo:
|
||||||
|
this.task = new ToDo();
|
||||||
|
break;
|
||||||
|
case daily:
|
||||||
|
this.task = new Daily();
|
||||||
|
break;
|
||||||
|
case habit:
|
||||||
|
this.task = new Habit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.saveTask(this.task);
|
||||||
|
|
||||||
|
event.task = this.task;
|
||||||
|
EventBus.getDefault().post(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSupportNavigateUp() {
|
||||||
|
this.prepareSave();
|
||||||
|
return super.onSupportNavigateUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
this.prepareSave();
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ public class TaskCreationCallback implements Callback<HabitItem> {
|
||||||
public TaskCreationCallback(OnHabitCreated cb) {
|
public TaskCreationCallback(OnHabitCreated cb) {
|
||||||
callback = cb;
|
callback = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success(HabitItem habit, Response response) {
|
public void success(HabitItem habit, Response response) {
|
||||||
callback.onTaskCreated(habit);
|
callback.onTaskCreated(habit);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.habitrpg.android.habitica.events;
|
||||||
|
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by viirus on 03/08/15.
|
||||||
|
*/
|
||||||
|
public class TaskSaveEvent {
|
||||||
|
public HabitItem task;
|
||||||
|
public boolean created;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ public class TaskRecyclerViewFragment extends Fragment implements View.OnClickLi
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
AddTaskTappedEvent event = new AddTaskTappedEvent();
|
AddTaskTappedEvent event = new AddTaskTappedEvent();
|
||||||
event.ClassType = classType;
|
event.ClassType = this.classType;
|
||||||
|
|
||||||
EventBus.getDefault().post(event);
|
EventBus.getDefault().post(event);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -25,6 +26,12 @@ public class Daily extends Checklist{
|
||||||
@Column
|
@Column
|
||||||
private Boolean completed;
|
private Boolean completed;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String frequency;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private Integer everyX;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "days_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "days_id",
|
||||||
columnType = Long.class,
|
columnType = Long.class,
|
||||||
|
|
@ -58,11 +65,11 @@ public class Daily extends Checklist{
|
||||||
}
|
}
|
||||||
public Daily(String id, String notes, Float priority, String text,
|
public Daily(String id, String notes, Float priority, String text,
|
||||||
Double value, Boolean completed, Days repeat) {
|
Double value, Boolean completed, Days repeat) {
|
||||||
this(id, notes, priority, text, value,completed,repeat,null,null);
|
this(id, notes, priority, text, value, completed, repeat, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Daily() {
|
public Daily() {
|
||||||
this(null,null,null,null,null,null,null);
|
this(null, null, null, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -78,6 +85,13 @@ public class Daily extends Checklist{
|
||||||
public void setCompleted(Boolean completed) {
|
public void setCompleted(Boolean completed) {
|
||||||
this.completed = completed;
|
this.completed = completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFrequency() { return frequency; }
|
||||||
|
public void setFrequency(String frequency) { this.frequency = frequency; }
|
||||||
|
|
||||||
|
public Integer getEveryX() { return everyX; }
|
||||||
|
public void setEveryX(Integer everyX) { this.everyX = everyX; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the repeat array.<br/>
|
* @return the repeat array.<br/>
|
||||||
* This array contains 7 values, one for each days, starting from monday.
|
* This array contains 7 values, one for each days, starting from monday.
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -15,7 +17,7 @@ import java.util.List;
|
||||||
* @author MagicMicky
|
* @author MagicMicky
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class HabitItem extends BaseModel {
|
public abstract class HabitItem extends BaseModel implements Serializable {
|
||||||
private String _id;
|
private String _id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
|
|
@ -124,7 +126,7 @@ public abstract class HabitItem extends BaseModel {
|
||||||
public void setValue(double value) {
|
public void setValue(double value) {
|
||||||
this.setValue(Double.valueOf(value));
|
this.setValue(Double.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the tags
|
* @return the tags
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue