From ab84bf83d9625121ee76a97ec1bc68d2441bf4ae Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 10 Aug 2015 15:56:52 +0200 Subject: [PATCH] Combine task classes into one --- Habitica/res/layout/daily_item_card.xml | 4 +- Habitica/res/layout/habit_item_card.xml | 4 +- Habitica/res/layout/reward_item_card.xml | 4 +- Habitica/res/layout/todo_item_card.xml | 4 +- .../habitrpg/android/habitica/APIHelper.java | 84 +--- .../android/habitica/AddTaskDialog.java | 418 ------------------ .../android/habitica/ChecklistDialog.java | 212 --------- .../android/habitica/MainActivity.java | 50 +-- .../habitica/OnTaskCreationListener.java | 4 +- .../android/habitica/OnTasksChanged.java | 4 +- .../android/habitica/TaskFormActivity.java | 173 +++----- .../callbacks/TaskCreationCallback.java | 8 +- .../callbacks/TaskDeletionCallback.java | 8 +- .../callbacks/TaskUpdateCallback.java | 8 +- .../habitica/events/HabitScoreEvent.java | 4 +- .../habitica/events/TaskLongPressedEvent.java | 4 +- .../habitica/events/TaskSaveEvent.java | 4 +- .../habitica/events/TaskTappedEvent.java | 4 +- .../habitica/events/TodoCheckedEvent.java | 4 +- .../adapter/HabitItemRecyclerViewAdapter.java | 37 +- .../fragments/TaskRecyclerViewFragment.java | 2 - .../habitica/widget/UpdateWidgetService.java | 6 +- .../lib/HabitRPGInteractor.java | 97 +--- .../habitrpgwrapper/lib/api/ApiService.java | 28 +- .../lib/api/HabitItemCallback.java | 27 +- .../lib/api/TypeAdapter/TagsAdapter.java | 41 +- .../lib/models/HabitRPGUser.java | 34 +- .../habitrpgwrapper/lib/models/Tag.java | 18 +- .../lib/models/tasks/Checklist.java | 81 ---- .../lib/models/tasks/ChecklistItem.java | 12 +- .../lib/models/tasks/Daily.java | 138 ------ .../lib/models/tasks/Habit.java | 73 --- .../lib/models/tasks/HabitItem.java | 238 ---------- .../lib/models/tasks/HabitType.java | 9 - .../lib/models/tasks/Reward.java | 131 +----- .../lib/models/tasks/Tags.java | 26 -- .../lib/models/tasks/Task.java | 284 ++++++++++++ .../lib/models/tasks/TaskTag.java | 55 +++ .../lib/models/tasks/ToDo.java | 88 ---- .../habitrpgwrapper/lib/utils/DaysUtils.java | 1 - 40 files changed, 573 insertions(+), 1858 deletions(-) delete mode 100644 Habitica/src/com/habitrpg/android/habitica/AddTaskDialog.java delete mode 100644 Habitica/src/com/habitrpg/android/habitica/ChecklistDialog.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/TaskTag.java delete mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java diff --git a/Habitica/res/layout/daily_item_card.xml b/Habitica/res/layout/daily_item_card.xml index d429cd71a..9b54d9a01 100644 --- a/Habitica/res/layout/daily_item_card.xml +++ b/Habitica/res/layout/daily_item_card.xml @@ -2,11 +2,11 @@ - + + type="Task" /> - + + type="Task" /> - + + type="Reward" /> - + + type="Task" /> callback) { - this.apiService.createItem(habit, callback); - } - public void createNewTask(ToDo toDo, Callback callback) { - this.apiService.createItem(toDo, callback); - } - public void createNewTask(Daily d,Callback callback) { - this.apiService.createItem(d, callback); - } - public void createNewTask(Reward r,Callback callback) { - this.apiService.createItem(r, callback); + public void createNewTask(Task item, Callback cb) { + this.apiService.createItem(item, cb); } public void retrieveUser(HabitRPGUserCallback callback) { @@ -172,47 +147,18 @@ public class APIHelper implements ErrorHandler, Profiler { this.apiService.connectLocal(auth, callback); } - public void deleteTask(HabitItem item, TaskDeletionCallback cb) { + public void deleteTask(Task item, TaskDeletionCallback 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); + public void updateTask(Task item, Callback cb) { + if(item instanceof Task) { + this.apiService.updateTask(item.getId(), item, cb); } else if(item instanceof Reward) { - updateTask((Reward) item, cb); + this.apiService.updateTask(item.getId(), item, cb); } } - public void updateTask(Daily item, Callback cb) { - this.apiService.updateTask(item.getId(), item, cb); - } - public void updateTask(Habit item, Callback cb) { - this.apiService.updateTask(item.getId(), item, cb); - } - public void updateTask(ToDo item, Callback cb) { - this.apiService.updateTask(item.getId(), item, cb); - } - public void updateTask(Reward item, Callback cb) { - this.apiService.updateTask(item.getId(), item, cb); - } - public void uprateUndefinedTask(HabitItem task, Callback cb) { - if(task instanceof ToDo) { - this.updateTask((ToDo) task, cb); - } else if(task instanceof Daily) { - this.updateTask((Daily) task, cb); - } else if(task instanceof Reward) { - this.updateTask((Reward) task, cb); - } else if(task instanceof Habit) { - this.updateTask((Habit) task,cb); - } - } - - //public void buyItem(Reward.SpecialReward itemBought, View btn) { // ATaskBuyItem buyItem = new ATaskBuyItem(mResultListener,btn, mConfig); // buyItem.execute(itemBought); @@ -329,7 +275,7 @@ public class APIHelper implements ErrorHandler, Profiler { } - private class ATaskPostTask extends AsyncTask { + private class ATaskPostTask extends AsyncTask { private OnHabitsAPIResult callback; private HostConfig config; public ATaskPostTask(OnHabitsAPIResult callback, HostConfig config) { @@ -342,7 +288,7 @@ public class APIHelper implements ErrorHandler, Profiler { this.callback.onPreResult(); } @Override - protected Void doInBackground(HabitItem... habit) { + protected Void doInBackground(Task... habit) { PostTask post = new PostTask(callback, config, habit[0]); Answer as = post.getData(); if(as!=null) @@ -351,7 +297,7 @@ public class APIHelper implements ErrorHandler, Profiler { } } - private class ATaskDeleteTask extends AsyncTask { + private class ATaskDeleteTask extends AsyncTask { private OnHabitsAPIResult callback; private HostConfig config; public ATaskDeleteTask(OnHabitsAPIResult callback, HostConfig config) { @@ -364,7 +310,7 @@ public class APIHelper implements ErrorHandler, Profiler { this.callback.onPreResult(); } @Override - protected Void doInBackground(HabitItem... habit) { + protected Void doInBackground(Task... habit) { DeleteTask del = new DeleteTask(callback, config, habit[0]); Answer as = del.getData(); if(as!=null) @@ -372,7 +318,7 @@ public class APIHelper implements ErrorHandler, Profiler { return null; } } - private class ATaskUpdateTask extends AsyncTask { + private class ATaskUpdateTask extends AsyncTask { private OnHabitsAPIResult callback; private HostConfig config; public ATaskUpdateTask(OnHabitsAPIResult callback, HostConfig config) { @@ -385,7 +331,7 @@ public class APIHelper implements ErrorHandler, Profiler { this.callback.onPreResult(); } @Override - protected Void doInBackground(HabitItem... habit) { + protected Void doInBackground(Task... habit) { PutTask put = new PutTask(callback, config, habit[0]); Answer as = put.getData(); if(as!=null) diff --git a/Habitica/src/com/habitrpg/android/habitica/AddTaskDialog.java b/Habitica/src/com/habitrpg/android/habitica/AddTaskDialog.java deleted file mode 100644 index 073c2f16c..000000000 --- a/Habitica/src/com/habitrpg/android/habitica/AddTaskDialog.java +++ /dev/null @@ -1,418 +0,0 @@ -package com.habitrpg.android.habitica; - -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.DatePickerDialog.OnDateSetListener; -import android.app.Dialog; -import android.content.DialogInterface; -import android.graphics.Typeface; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.DatePicker; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.ToggleButton; - -import com.crashlytics.android.Crashlytics; -import com.habitrpg.android.habitica.ChecklistDialog.CheckListUpdater; -import com.habitrpg.android.habitica.ui.fragments.DatePickerFragment; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Checklist; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem; -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.HabitItem; -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.utils.DaysUtils; -import com.raizlabs.android.dbflow.sql.language.Select; - -import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.*; -import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.habit; - -/** - * Updated by Negue on 21/06/15 - */ -public class AddTaskDialog extends DialogFragment implements OnDateSetListener, CheckListUpdater { - private EditText taskText, taskNote, taskValue; - private boolean[] repeat = {false, false, false, false, false, false, false}; - private boolean[] down_up = {true, true}; - private String toDoDate; - private HabitType hType; - - private String[] mShortWeekDayStrings = {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}; - private int colorDesactivated; - private int colorActivated; - private Typeface mRobotoBold; - private Typeface mRobotoNormal; - private ToggleButton[] buttons; - private ViewGroup[] buttonsHolder = new ViewGroup[7]; - private LayoutInflater inflater; - private TextView spinner; - - private OnTaskCreationListener mListener; - private boolean mEditMode = false; - private String mEditingId; - private Double oldValue = null; - private Checklist mChecklist = new Checklist() { - - @Override - public HabitType getType() { - return daily; - } - }; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - mListener = (OnTaskCreationListener) activity; - } catch (ClassCastException e) { - e.printStackTrace(); - this.dismiss(); - } - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - //getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - } - - public Dialog onCreateDialog(Bundle savedInstanceState) { - // Use the Builder class for convenient dialog construction - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - this.inflater = getActivity().getLayoutInflater(); - View mainView = inflater.inflate(R.layout.add_task_dialog, null); - builder.setView(mainView); - this.colorActivated = this.getResources().getColor(R.color.days_black); - this.colorDesactivated = this.getResources().getColor(R.color.days_gray); - this.mRobotoBold = Typeface.create("sans-serif-condensed", Typeface.BOLD); - this.mRobotoNormal = Typeface.create("sans-serif-condensed", Typeface.NORMAL); - this.taskNote = (EditText) mainView.findViewById(R.id.ET_taskNote); - this.taskText = (EditText) mainView.findViewById(R.id.ET_taskText); - this.taskValue = (EditText) mainView.findViewById(R.id.ET_taskValue); - - Bundle b = this.getArguments(); - String taskId = b.getString("taskId", ""); - String type; - String text; - if (!taskId.isEmpty()) { - this.mEditMode = true; - } - - type = b.getString("type"); - text = b.getString("text"); - - this.taskText.setText(text); - Log.d("AddTaskDialog", "type=" + type); - hType = type.equals(daily.toString()) ? daily - : type.equals(reward.toString()) ? reward - : type.equals(todo.toString()) ? todo - : habit; - LinearLayout specialView = (LinearLayout) mainView.findViewById(R.id.repeat_days); - if (hType == daily) { - this.initializeSpecialButtons(specialView, mShortWeekDayStrings, repeat); - - showChecklistButton(mainView); - - } else if (hType == habit) { - String[] texts = {getString(R.string.minus_sign), getString(R.string.plus_sign)}; - this.initializeSpecialButtons(specialView, texts, this.down_up); - } else if (hType == todo) { - LinearLayout dueDate = (LinearLayout) mainView.findViewById(R.id.due_date); - this.initializeDatePicker(dueDate); - - - showChecklistButton(mainView); - - } else if (hType == reward) { - LinearLayout value = (LinearLayout) mainView.findViewById(R.id.value); - value.setVisibility(View.VISIBLE); - } - - if (mEditMode) { - switch (hType) { - case todo: - ToDo todo = new Select().from(ToDo.class).byIds(taskId).querySingle(); - - this.populate(todo); - break; - case daily: - Daily daily = new Select().from(Daily.class).byIds(taskId).querySingle(); - - this.populate(daily); - break; - case reward: - Reward reward = new Select().from(Reward.class).byIds(taskId).querySingle(); - - this.populate(reward); - break; - case habit: - Habit habit = new Select().from(Habit.class).byIds(taskId).querySingle(); - - this.populate(habit); - break; - } - } - builder.setTitle(getString(R.string.new_task, hType.toString())) - .setPositiveButton(R.string.dialog_confirm_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - - if (AddTaskDialog.this.taskText.getText().length() > 0) { - - mListener.onTaskCreation(AddTaskDialog.this.createTask(), mEditMode); - } else { - mListener.onTaskCreationFail(getActivity().getString(R.string.task_creation_fail)); - } - } - }) - .setNegativeButton(R.string.dialog_cancel_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User cancelled the dialog - } - }); - // Create the AlertDialog object and return it - Dialog d = builder.create(); - d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - - return d; - } - - private void showChecklistButton(View mainView) { - ImageButton btn = (ImageButton) mainView.findViewById(R.id.BT_checklist); - - btn.setVisibility(View.VISIBLE); - - btn.setOnClickListener(new View.OnClickListener() { - - @Override - - public void onClick(View v) { - ChecklistDialog dialog = new ChecklistDialog(getActivity(), AddTaskDialog.this, null, mChecklist, mEditMode); - dialog.show(); - } - - }); - } - - private void initializeDatePicker(LinearLayout specialView) { - specialView.setVisibility(ViewGroup.VISIBLE); - this.spinner = (TextView) specialView.findViewById(R.id.due_date_spinner); - spinner.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DialogFragment newFragment = new DatePickerFragment(); - newFragment.setTargetFragment(AddTaskDialog.this, 0); - newFragment.show(getActivity().getSupportFragmentManager(), "timePicker"); - } - }); - } - - - private void initializeSpecialButtons(LinearLayout specialView, String[] texts, final boolean[] resArray) { - int length = texts.length; - this.buttonsHolder = new ViewGroup[length]; - this.buttons = new ToggleButton[length]; - specialView.setVisibility(ViewGroup.VISIBLE); - for (int i = 0; i < length; i++) { - final ViewGroup viewgroup = (ViewGroup) inflater.inflate(R.layout.button_day_of_week, - specialView, false); - final ToggleButton button = (ToggleButton) viewgroup.getChildAt(0); - button.setText(texts[i]); - button.setTextOn(texts[i]); - button.setTextOff(texts[i]); - specialView.addView(viewgroup); - this.buttonsHolder[i] = viewgroup; - this.buttons[i] = button; - if (i < 5) { - buttonOn(i); - resArray[i] = true; - } - } - for (int i = 0; i < length; i++) { - final int buttonIndex = i; - this.buttonsHolder[i].setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - buttons[buttonIndex].toggle(); - final boolean checked = buttons[buttonIndex].isChecked(); - if (checked) { - buttonOn(buttonIndex); - resArray[buttonIndex] = true; - } else { - buttonOff(buttonIndex); - resArray[buttonIndex] = false; - } - - } - }); - } - } - - private void buttonOff(int index) { - buttons[index].setChecked(false); - buttons[index].setTextColor(this.colorDesactivated); - buttons[index].setTypeface(this.mRobotoNormal); - } - - private void buttonOn(int index) { - buttons[index].setChecked(true); - buttons[index].setTextColor(this.colorActivated); - buttons[index].setTypeface(this.mRobotoBold); - } - - public HabitItem createTask() { - HabitItem h = null; - - String notes = this.taskNote.getText().toString(); - String text = this.taskText.getText().toString(); - if (text != null) { - switch (this.hType) { - case daily: - Days d = DaysUtils.getDaysFromBooleans(repeat); - h = new Daily(null, notes, null, text, oldValue != null ? oldValue : 0, false, d); - break; - case habit: - h = new Habit(null, notes, null, text, oldValue != null ? oldValue : 0, this.down_up[1], this.down_up[0]); - break; - case todo: - h = new ToDo(null, notes, null, text, oldValue != null ? oldValue : 0, false, toDoDate); - break; - case reward: - int value = 20; - try { - value = Double.valueOf(this.taskValue.getText().toString()).intValue(); - } catch (Exception e) { - Crashlytics.logException(e); - e.printStackTrace(); - } - h = new Reward(null, notes, null, text, value); - } - if (mEditMode) { - h.setId(this.mEditingId); - } - - if (h instanceof Checklist) { - Checklist checklist = (Checklist) h; - - - checklist.addItems(mChecklist); - } - } - - return h; - - } - - @Override - public void onDateSet(DatePicker view, int year, int monthOfYear, - int dayOfMonth) { - Calendar c = Calendar.getInstance(); - c.set(year, monthOfYear, dayOfMonth); - Date d = c.getTime(); - String date = android.text.format.DateFormat.getMediumDateFormat(getActivity()).format(d); - int month = (c.get(Calendar.MONTH) + 1) % 12; - this.toDoDate = getString(R.string.format_todo_date, month, c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.YEAR)); - Log.v("AddTaskDialog", "modifying todoDate to:" + toDoDate); - if (this.spinner != null) - this.spinner.setText(date); - } - - - private void populate(ToDo result) { - populate((HabitItem) result); - mChecklist = result; - if (result.getDate() != null) { - String[] newDate = result.getDate().split("-"); - if (newDate.length != 3) { - newDate = result.getDate().split("/"); - } - if (newDate.length == 3) { - Calendar c = Calendar.getInstance(); - Log.e("date", "date is here!!!" + result.getDate()); - c.set(Integer.valueOf(newDate[2]), (Integer.valueOf(newDate[0]) + 11) % 12, Integer.valueOf(newDate[1])); - Date d = c.getTime(); - String date = android.text.format.DateFormat.getMediumDateFormat(getActivity()).format(d); - int month = c.get(Calendar.MONTH); - this.toDoDate = getString(R.string.format_todo_date, month, c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.YEAR)); - if (this.spinner != null) - this.spinner.setText(date); - } - } - } - - private void populate(Reward result) { - populate((HabitItem) result); - this.taskValue.setText(Double.valueOf(result.getValue()).intValue() + ""); - } - - private void populate(Habit result) { - populate((HabitItem) result); - if (result.getUp()) { - buttonOn(1); - down_up[1] = true; - } else { - buttonOff(1); - down_up[1] = false; - - } - - if (result.getDown()) { - buttonOn(0); - down_up[0] = true; - - } else { - buttonOff(0); - down_up[0] = false; - - } - - } - - private void populate(Daily result) { - populate((HabitItem) result); - mChecklist = result; - int length = buttons.length; - if (result.getRepeat() != null) { - for (int i = 0; i < length; i++) { - if (DaysUtils.getBooleansFromDays(result.getRepeat())[i]) { - buttonOn(i); - repeat[i] = true; - - } else { - buttonOff(i); - repeat[i] = false; - - } - } - } - } - - private void populate(HabitItem result) { - if (this.taskNote != null) - this.taskNote.setText(result.getNotes()); - if (this.taskText != null) - this.taskText.setText(result.getText()); - this.mEditingId = result.getId(); - this.oldValue = result.getValue(); - } - - @Override - public void onChecklistChosen(Checklist list) { - this.mChecklist = list; - } -} diff --git a/Habitica/src/com/habitrpg/android/habitica/ChecklistDialog.java b/Habitica/src/com/habitrpg/android/habitica/ChecklistDialog.java deleted file mode 100644 index 8bd2d2e0b..000000000 --- a/Habitica/src/com/habitrpg/android/habitica/ChecklistDialog.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.habitrpg.android.habitica; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.support.annotation.Nullable; -import android.support.v4.app.DialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.ListView; -import android.widget.TextView; - -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Checklist; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; - -import java.util.Objects; - -import retrofit.Callback; -import retrofit.RetrofitError; -import retrofit.client.Response; - - -/** - * Created by MagicMicky on 30/04/14. - * Updated by Negue on 21/06/15 - */ -public class ChecklistDialog implements DialogInterface.OnClickListener { - private final Context mContext; - private Checklist checklist; - private THabitItem item; - private Callback updateCallback; - private final LayoutInflater mInflater; - private final APIHelper mAPIHelper; - private CheckListUpdater checklistUpdater; - private boolean mEditMode; - - public ChecklistDialog(Context act, APIHelper apiHelper, THabitItem todo, Checklist checklist) { - this.mContext = act; - this.item = todo; - - this.checklist = todo != null ? todo : checklist; - this.mInflater = LayoutInflater.from(mContext); - this.mAPIHelper = apiHelper; - this.checklistUpdater = null; - mEditMode = false; - } - - public ChecklistDialog(Context context, CheckListUpdater checkListUpdater, THabitItem todo, Checklist checklist, boolean editMode) { - this(context, null, todo, checklist); - - this.checklistUpdater = checkListUpdater; - this.mEditMode = editMode; - } - - public void show() { - View convertView = mInflater.inflate(R.layout.checklist_dialog, null); - AlertDialog d = new AlertDialog.Builder(mContext) - .setTitle(item != null ? item.getText() : mEditMode - ? mContext.getString(R.string.checklist_title_edit) - : mContext.getString(R.string.checklist_title_add)) - .setView(convertView) - .setPositiveButton(mContext.getString(R.string.update_btn), this) - .setNegativeButton(mContext.getString(R.string.dialog_cancel_button), null) - .create(); - ListView lv = (ListView) convertView.findViewById(R.id.LV_checklist); - - final CheckListAdapter adapter = new CheckListAdapter(mContext, checklist); - - lv.setAdapter(adapter); - d.show(); - - if (mAPIHelper == null) { - convertView.findViewById(R.id.RL_addItem).setVisibility(View.VISIBLE); - ImageButton btn = (ImageButton) convertView.findViewById(R.id.BT_addItem); - final EditText addItem = (EditText) convertView.findViewById(R.id.ET_addItem); - btn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (addItem.getText() != null && addItem.getText().length() > 0) { - ChecklistItem item = new ChecklistItem(); - item.setText(addItem.getText().toString()); - adapter.addItem(item); - adapter.notifyDataSetChanged(); - addItem.setText(""); - } - } - }); - } - } - - @Override - public void onClick(DialogInterface dialog, int which) { - if (checklistUpdater != null) { - checklistUpdater.onChecklistChosen(checklist); - } else { - if (item instanceof ToDo) { - mAPIHelper.updateTask((ToDo) item, new Callback() { - @Override - public void success(ToDo toDo, Response response) { - - } - - @Override - public void failure(RetrofitError error) { - - } - }); - } - - if (item instanceof Daily) { - mAPIHelper.updateTask((Daily) item, new Callback() { - @Override - public void success(Daily daily, Response response) { - - } - - @Override - public void failure(RetrofitError error) { - - } - }); - } - } - } - - private class CheckListAdapter extends BaseAdapter { - - private final Checklist checklist; - private final Context mContext; - - public CheckListAdapter(Context context, Checklist list) { - this.checklist = list; - this.mContext = context; - } - - @Override - public int getCount() { - return checklist.getSize(); - } - - @Override - public ChecklistItem getItem(int position) { - return checklist.getItems().get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - if (convertView == null) { - convertView = inflator.inflate(R.layout.checklist_dialog_list_item, parent, false); - } - CheckBox completed = (CheckBox) convertView.findViewById(R.id.plus); - TextView text = (TextView) convertView.findViewById(R.id.TV_title); - ChecklistItem currentItem = this.getItem(position); - text.setText(currentItem.getText()); - convertView.setId(position); - completed.setChecked(currentItem.getCompleted()); - completed.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (v.getParent() != null) { - getItem(((View) v.getParent()).getId()).setCompleted(((CheckBox) v).isChecked()); - } - } - }); - - - ImageButton delete = (ImageButton) convertView.findViewById(R.id.BT_delete); - - if(mAPIHelper == null) { - delete.setVisibility(View.VISIBLE); - } - delete.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (v .getParent() != null){ - removeItem(((View)v.getParent()).getId()); - } - } - }); - - return convertView; - } - - private void removeItem(int pos) { - this.checklist.getItems().remove(pos); - - this.notifyDataSetChanged(); - } - - public void addItem(ChecklistItem item) { - this.checklist.addItem(item); - } - } - - public interface CheckListUpdater { - void onChecklistChosen(Checklist list); - } -} \ No newline at end of file diff --git a/Habitica/src/com/habitrpg/android/habitica/MainActivity.java b/Habitica/src/com/habitrpg/android/habitica/MainActivity.java index 865621579..a0f9968bb 100644 --- a/Habitica/src/com/habitrpg/android/habitica/MainActivity.java +++ b/Habitica/src/com/habitrpg/android/habitica/MainActivity.java @@ -35,13 +35,10 @@ import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser; import com.magicmicky.habitrpgwrapper.lib.models.Tag; import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection; import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData; import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; import com.magicmicky.habitrpgwrapper.lib.models.tasks.RewardItem; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.DrawerBuilder; import com.mikepenz.materialdrawer.model.DividerDrawerItem; @@ -90,7 +87,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU Map ViewFragmentsDictionary = new HashMap(); - List TaskList = new ArrayList(); + List TaskList = new ArrayList(); private HostConfig hostConfig; APIHelper mAPIHelper; @@ -364,7 +361,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU } public void onEvent(final TaskSaveEvent event) { - HabitItem task = (HabitItem) event.task; + Task task = (Task) event.task; if (event.created) { this.mAPIHelper.createNewTask(task, new TaskCreationCallback(this)); } else { @@ -434,25 +431,20 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU switch (position) { case 0: layoutOfType = R.layout.habit_item_card; - fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(Habit.class, layoutOfType, HabitItemRecyclerViewAdapter.HabitViewHolder.class, context), Habit.class); + fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter("habit", Task.class, layoutOfType, HabitItemRecyclerViewAdapter.HabitViewHolder.class, context), Task.class); break; case 1: layoutOfType = R.layout.daily_item_card; - fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(Daily.class, layoutOfType, HabitItemRecyclerViewAdapter.DailyViewHolder.class, context), Daily.class); + fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter("daily", Task.class, layoutOfType, HabitItemRecyclerViewAdapter.DailyViewHolder.class, context), Task.class); break; case 3: layoutOfType = R.layout.reward_item_card; - fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(Reward.class, layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, context), Reward.class); - break; - case 4: - layoutOfType = R.layout.reward_item_card; - fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(RewardItem.class, layoutOfType, HabitItemRecyclerViewAdapter.RewardItemViewHolder.class, - context, GearRewards), RewardItem.class, false); + fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter("reward", Reward.class, layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, context), Reward.class); break; default: layoutOfType = R.layout.todo_item_card; - fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(ToDo.class, layoutOfType, HabitItemRecyclerViewAdapter.TodoViewHolder.class, context), ToDo.class); + fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter("todo", Task.class, layoutOfType, HabitItemRecyclerViewAdapter.TodoViewHolder.class, context), Task.class); } ViewFragmentsDictionary.put(position, fragment); @@ -462,7 +454,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU @Override public int getCount() { - return 5; + return 4; } @Override @@ -476,8 +468,6 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU return "Todos"; case 3: return "Rewards"; - case 4: - return "Gear"; } return ""; } @@ -495,25 +485,11 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU for (Tag t : User.getTags()) { filterDrawer.addItem( - new PrimaryDrawerItem().withName(t.getName()).withBadge("" + CountTagUsedInTasks(t.getId())) + new PrimaryDrawerItem().withName(t.getName()).withBadge("" + t.getTasks().size()) ); } } - /** - * Anyone a better solution to count the Tag? - */ - public int CountTagUsedInTasks(String tagId) { - int count = 0; - - for (HabitItem task : TaskList) { - if (task.getTags().contains(tagId)) - count++; - } - - return count; - } - public int adjustAlpha(int color, float factor) { int alpha = Math.round(Color.alpha(color) * factor); int red = Color.red(color); @@ -699,11 +675,11 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU } @Override - public void onTaskCreation(HabitItem task, boolean editMode) { + public void onTaskCreation(Task task, boolean editMode) { if (!editMode) { this.mAPIHelper.createNewTask(task, new TaskCreationCallback(this)); } else { - this.mAPIHelper.uprateUndefinedTask(task, new TaskUpdateCallback(this)); + this.mAPIHelper.updateTask(task, new TaskUpdateCallback(this)); } // TODO update task in list @@ -716,7 +692,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU // TaskCreationCallback @Override - public void onTaskCreated(HabitItem habit) { + public void onTaskCreated(Task habit) { habit.save(); } @@ -727,7 +703,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU // TaskUpdateCallback @Override - public void onTaskUpdated(HabitItem habit) { + public void onTaskUpdated(Task habit) { habit.save(); } diff --git a/Habitica/src/com/habitrpg/android/habitica/OnTaskCreationListener.java b/Habitica/src/com/habitrpg/android/habitica/OnTaskCreationListener.java index c615fff54..ef10abd75 100644 --- a/Habitica/src/com/habitrpg/android/habitica/OnTaskCreationListener.java +++ b/Habitica/src/com/habitrpg/android/habitica/OnTaskCreationListener.java @@ -1,9 +1,9 @@ package com.habitrpg.android.habitica; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; public interface OnTaskCreationListener { - public void onTaskCreation(HabitItem task, boolean editMode); + public void onTaskCreation(Task task, boolean editMode); public void onTaskCreationFail(String message); } diff --git a/Habitica/src/com/habitrpg/android/habitica/OnTasksChanged.java b/Habitica/src/com/habitrpg/android/habitica/OnTasksChanged.java index e167d1603..d27f3e58b 100644 --- a/Habitica/src/com/habitrpg/android/habitica/OnTasksChanged.java +++ b/Habitica/src/com/habitrpg/android/habitica/OnTasksChanged.java @@ -1,12 +1,12 @@ package com.habitrpg.android.habitica; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import java.util.List; public interface OnTasksChanged { - void onChange(List tasks); + void onChange(List tasks); void onTagFilter(List tags); } diff --git a/Habitica/src/com/habitrpg/android/habitica/TaskFormActivity.java b/Habitica/src/com/habitrpg/android/habitica/TaskFormActivity.java index 483e68ad9..ef01fce8e 100644 --- a/Habitica/src/com/habitrpg/android/habitica/TaskFormActivity.java +++ b/Habitica/src/com/habitrpg/android/habitica/TaskFormActivity.java @@ -1,6 +1,5 @@ package com.habitrpg.android.habitica; -import android.app.Activity; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; @@ -17,30 +16,19 @@ import android.widget.Spinner; import android.widget.TextView; import com.habitrpg.android.habitica.events.TaskSaveEvent; -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.HabitItem; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; 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.habit; -import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.reward; -import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.todo; public class TaskFormActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { - private HabitType taskType; + private String taskType; private String taskId; - private HabitItem task; + private Task task; private EditText taskText, taskNotes; private Spinner taskDifficultySpinner, dailyFrequencySpinner; @@ -62,10 +50,6 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O if (type == null) { return; } - taskType = type.equals(daily.toString()) ? daily - : type.equals(reward.toString()) ? reward - : type.equals(todo.toString()) ? todo - : habit; LinearLayout mainWrapper = (LinearLayout) findViewById(R.id.task_main_wrapper); taskText = (EditText) findViewById(R.id.task_text_edittext); @@ -77,7 +61,7 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); taskDifficultySpinner.setAdapter(adapter); - if (taskType == habit) { + if (taskType.equals("habit")) { LinearLayout startDateLayout = (LinearLayout) findViewById(R.id.task_startdate_layout); LinearLayout taskWrapper = (LinearLayout) findViewById(R.id.task_task_wrapper); taskWrapper.removeView(startDateLayout); @@ -89,13 +73,13 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O negativeCheckBox = (CheckBox) findViewById(R.id.task_negative_checkbox); } - if (taskType != habit) { + if (taskType.equals("habit")) { LinearLayout actionsLayout = (LinearLayout) findViewById(R.id.task_actions_wrapper); mainWrapper.removeView(actionsLayout); } LinearLayout weekdayWrapper = (LinearLayout)findViewById(R.id.task_weekdays_wrapper); - if (taskType == daily) { + if (taskType.equals("daily")) { this.dailyFrequencySpinner = (Spinner) weekdayWrapper.findViewById(R.id.task_frequency_spinner); ArrayAdapter frequencyAdapter = ArrayAdapter.createFromResource(this, @@ -110,23 +94,9 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O } if (taskId != null) { - switch (taskType) { - case todo: - ToDo todo = new Select().from(ToDo.class).byIds(taskId).querySingle(); - this.task = todo; - this.populate(todo); - break; - case daily: - Daily daily = new Select().from(Daily.class).byIds(taskId).querySingle(); - this.task = daily; - this.populate(daily); - break; - case habit: - Habit habit = new Select().from(Habit.class).byIds(taskId).querySingle(); - this.task = habit; - this.populate(habit); - break; - } + Task task = new Select().from(Task.class).byIds(taskId).querySingle(); + this.task = task; + this.populate(task); } } @@ -153,18 +123,17 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O } 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()); + this.weekdayCheckboxes.get(0).setChecked(this.task.getRepeat().getM()); + this.weekdayCheckboxes.get(1).setChecked(this.task.getRepeat().getT()); + this.weekdayCheckboxes.get(2).setChecked(this.task.getRepeat().getW()); + this.weekdayCheckboxes.get(3).setChecked(this.task.getRepeat().getTh()); + this.weekdayCheckboxes.get(4).setChecked(this.task.getRepeat().getF()); + this.weekdayCheckboxes.get(5).setChecked(this.task.getRepeat().getS()); + this.weekdayCheckboxes.get(6).setChecked(this.task.getRepeat().getSu()); } else { - this.frequencyPicker.setValue(daily.getEveryX()); + this.frequencyPicker.setValue(this.task.getEveryX()); } } @@ -193,7 +162,7 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O } - private void populate(HabitItem task) { + private void populate(Task task) { taskText.setText(task.text); taskNotes.setText(task.notes); float priority = task.getPriority(); @@ -206,41 +175,36 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O } else if (priority == 2.0) { this.taskDifficultySpinner.setSelection(3); } - } - private void populate(Habit task) { - populate((HabitItem) task); - positiveCheckBox.setChecked(task.getUp()); - negativeCheckBox.setChecked(task.getDown()); - } + if (task.type.equals("habit")) { + positiveCheckBox.setChecked(task.getUp()); + negativeCheckBox.setChecked(task.getDown()); + } - private void populate(Daily 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()); + if (task.type.equals("daily")) { + 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) { - populate((HabitItem) task); - } - private void saveTask(HabitItem task) { + private void saveTask(Task task) { task.text = taskText.getText().toString(); task.notes = taskNotes.getText().toString(); @@ -253,33 +217,27 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O } 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()); + if (task.type.equals("habit")) { + task.setUp(positiveCheckBox.isChecked()); + task.setDown(negativeCheckBox.isChecked()); } - this.saveTask((HabitItem) task); - } - private void saveTask(ToDo task) { - this.saveTask((HabitItem) task); + if (task.type.equals("daily")) { + 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()); + } + } } public void onItemSelected(AdapterView parent, View view, @@ -295,17 +253,8 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O 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.task = new Task(); + this.task.setType(taskType); } this.saveTask(this.task); diff --git a/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskCreationCallback.java b/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskCreationCallback.java index 7f0183206..6715684a8 100644 --- a/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskCreationCallback.java +++ b/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskCreationCallback.java @@ -3,7 +3,7 @@ package com.habitrpg.android.habitica.callbacks; import android.util.Log; import com.crashlytics.android.Crashlytics; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import retrofit.Callback; import retrofit.RetrofitError; @@ -12,7 +12,7 @@ import retrofit.client.Response; /** * Created by magicmicky on 02/04/15. */ -public class TaskCreationCallback implements Callback { +public class TaskCreationCallback implements Callback { private OnHabitCreated callback; public TaskCreationCallback(OnHabitCreated cb) { @@ -22,7 +22,7 @@ public class TaskCreationCallback implements Callback { @Override - public void success(HabitItem habit, Response response) { + public void success(Task habit, Response response) { callback.onTaskCreated(habit); } @@ -35,7 +35,7 @@ public class TaskCreationCallback implements Callback { } public interface OnHabitCreated { - public void onTaskCreated(HabitItem habit); + public void onTaskCreated(Task habit); public void onTaskCreationFail(); } } diff --git a/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskDeletionCallback.java b/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskDeletionCallback.java index 43ffe4b70..3317527f6 100644 --- a/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskDeletionCallback.java +++ b/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskDeletionCallback.java @@ -3,7 +3,7 @@ package com.habitrpg.android.habitica.callbacks; import android.util.Log; import com.crashlytics.android.Crashlytics; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import retrofit.Callback; import retrofit.RetrofitError; @@ -14,9 +14,9 @@ import retrofit.client.Response; */ public class TaskDeletionCallback implements Callback { private final OnTaskDeleted callback; - private final HabitItem taskToDelete; + private final Task taskToDelete; - public TaskDeletionCallback(OnTaskDeleted cb, HabitItem taskToDelete) { + public TaskDeletionCallback(OnTaskDeleted cb, Task taskToDelete) { this.callback = cb; this.taskToDelete = taskToDelete; } @@ -35,6 +35,6 @@ public class TaskDeletionCallback implements Callback { public interface OnTaskDeleted { - public void onTaskDeleted(HabitItem deleted); + public void onTaskDeleted(Task deleted); public void onTaskDeletionFail(); }} diff --git a/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskUpdateCallback.java b/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskUpdateCallback.java index 3c9f3ff99..e41df195b 100644 --- a/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskUpdateCallback.java +++ b/Habitica/src/com/habitrpg/android/habitica/callbacks/TaskUpdateCallback.java @@ -3,7 +3,7 @@ package com.habitrpg.android.habitica.callbacks; import android.util.Log; import com.crashlytics.android.Crashlytics; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import retrofit.Callback; import retrofit.RetrofitError; @@ -12,14 +12,14 @@ import retrofit.client.Response; /** * Created by magicmicky on 02/04/15. */ -public class TaskUpdateCallback implements Callback { +public class TaskUpdateCallback implements Callback { private OnHabitUpdated callback; public TaskUpdateCallback(OnHabitUpdated cb) { callback = cb; } @Override - public void success(HabitItem habit, Response response) { + public void success(Task habit, Response response) { callback.onTaskUpdated(habit); } @@ -31,7 +31,7 @@ public class TaskUpdateCallback implements Callback { Log.w("HabitUpdate", "Error " + error.getMessage()); } public interface OnHabitUpdated { - void onTaskUpdated(HabitItem habit); + void onTaskUpdated(Task habit); void onTaskUpdateFail(); } } diff --git a/Habitica/src/com/habitrpg/android/habitica/events/HabitScoreEvent.java b/Habitica/src/com/habitrpg/android/habitica/events/HabitScoreEvent.java index a18c8aa55..fb350828c 100644 --- a/Habitica/src/com/habitrpg/android/habitica/events/HabitScoreEvent.java +++ b/Habitica/src/com/habitrpg/android/habitica/events/HabitScoreEvent.java @@ -1,6 +1,6 @@ package com.habitrpg.android.habitica.events; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; /** * Created by Negue on 10.07.2015. @@ -8,5 +8,5 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; public class HabitScoreEvent { public boolean Up = false; - public Habit Habit; + public Task Habit; } diff --git a/Habitica/src/com/habitrpg/android/habitica/events/TaskLongPressedEvent.java b/Habitica/src/com/habitrpg/android/habitica/events/TaskLongPressedEvent.java index c6e56bfc7..9e2dcf1ac 100644 --- a/Habitica/src/com/habitrpg/android/habitica/events/TaskLongPressedEvent.java +++ b/Habitica/src/com/habitrpg/android/habitica/events/TaskLongPressedEvent.java @@ -1,10 +1,8 @@ package com.habitrpg.android.habitica.events; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; - /** * Created by Negue on 10.07.2015. */ public class TaskLongPressedEvent { - public HabitItem Task; + public com.magicmicky.habitrpgwrapper.lib.models.tasks.Task Task; } diff --git a/Habitica/src/com/habitrpg/android/habitica/events/TaskSaveEvent.java b/Habitica/src/com/habitrpg/android/habitica/events/TaskSaveEvent.java index 04490ae44..ecf5f2cb7 100644 --- a/Habitica/src/com/habitrpg/android/habitica/events/TaskSaveEvent.java +++ b/Habitica/src/com/habitrpg/android/habitica/events/TaskSaveEvent.java @@ -1,12 +1,12 @@ package com.habitrpg.android.habitica.events; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; /** * Created by viirus on 03/08/15. */ public class TaskSaveEvent { - public HabitItem task; + public Task task; public boolean created; } diff --git a/Habitica/src/com/habitrpg/android/habitica/events/TaskTappedEvent.java b/Habitica/src/com/habitrpg/android/habitica/events/TaskTappedEvent.java index a4a2eb2a9..edf74903b 100644 --- a/Habitica/src/com/habitrpg/android/habitica/events/TaskTappedEvent.java +++ b/Habitica/src/com/habitrpg/android/habitica/events/TaskTappedEvent.java @@ -1,10 +1,8 @@ package com.habitrpg.android.habitica.events; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; - /** * Created by Negue on 10.07.2015. */ public class TaskTappedEvent { - public HabitItem Task; + public com.magicmicky.habitrpgwrapper.lib.models.tasks.Task Task; } diff --git a/Habitica/src/com/habitrpg/android/habitica/events/TodoCheckedEvent.java b/Habitica/src/com/habitrpg/android/habitica/events/TodoCheckedEvent.java index 2ae097dd9..72e1795f0 100644 --- a/Habitica/src/com/habitrpg/android/habitica/events/TodoCheckedEvent.java +++ b/Habitica/src/com/habitrpg/android/habitica/events/TodoCheckedEvent.java @@ -1,10 +1,10 @@ package com.habitrpg.android.habitica.events; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; /** * Created by Negue on 11.07.2015. */ public class TodoCheckedEvent { - public ToDo ToDo; + public Task ToDo; } diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java index 1b04af87f..99a46064c 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java @@ -31,13 +31,11 @@ import com.habitrpg.android.habitica.events.TaskLongPressedEvent; import com.habitrpg.android.habitica.events.TaskTappedEvent; import com.habitrpg.android.habitica.events.TodoCheckedEvent; import com.habitrpg.android.habitica.ui.helpers.ViewHelper; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; import com.magicmicky.habitrpgwrapper.lib.models.tasks.RewardItem; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; import com.raizlabs.android.dbflow.runtime.FlowContentObserver; +import com.raizlabs.android.dbflow.sql.builder.Condition; import com.raizlabs.android.dbflow.sql.language.Select; import com.raizlabs.android.dbflow.structure.BaseModel; import com.raizlabs.android.dbflow.structure.Model; @@ -50,7 +48,7 @@ import butterknife.ButterKnife; import butterknife.InjectView; import de.greenrobot.event.EventBus; -public class HabitItemRecyclerViewAdapter +public class HabitItemRecyclerViewAdapter extends RecyclerView.Adapter implements FlowContentObserver.OnSpecificModelStateChangedListener { @@ -58,6 +56,7 @@ public class HabitItemRecyclerViewAdapter private Class> viewHolderClass; List contents; Class taskClass; + String taskType; private ObservableArrayList observableContent; FlowContentObserver observer; Context context; @@ -67,13 +66,13 @@ public class HabitItemRecyclerViewAdapter private RecyclerView.Adapter parentAdapter; - public HabitItemRecyclerViewAdapter(Class newTaskClass, int layoutResource, Class> viewHolderClass, Context newContext) { - this(newTaskClass, layoutResource, viewHolderClass, newContext, null); + public HabitItemRecyclerViewAdapter(String taskType, Class newTaskClass, int layoutResource, Class> viewHolderClass, Context newContext) { + this(taskType, newTaskClass, layoutResource, viewHolderClass, newContext, null); } - public HabitItemRecyclerViewAdapter(Class newTaskClass, int layoutResource, Class> viewHolderClass, + public HabitItemRecyclerViewAdapter(String taskType, Class newTaskClass, int layoutResource, Class> viewHolderClass, Context newContext, final ObservableArrayList content) { - + this.taskType = taskType; this.context = newContext; this.taskClass = newTaskClass; observableContent = content; @@ -185,7 +184,7 @@ public class HabitItemRecyclerViewAdapter @Override public void onBindViewHolder(ViewHolder holder, int position) { - HabitItem item = contents.get(position); + Task item = contents.get(position); holder.bindHolder(item, position); } @@ -225,7 +224,7 @@ public class HabitItemRecyclerViewAdapter ViewHelper.SetBackgroundTint(view, view.getResources().getColor(color)); } - public abstract class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { + public abstract class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { @InjectView(R.id.card_view) protected CardView cardView; @@ -279,7 +278,7 @@ public class HabitItemRecyclerViewAdapter } - public class HabitViewHolder extends ViewHolder { + public class HabitViewHolder extends ViewHolder { @InjectView(R.id.btnPlus) Button btnPlus; @@ -318,14 +317,14 @@ public class HabitItemRecyclerViewAdapter } @Override - public void bindHolder(Habit habitItem, int position) { + public void bindHolder(Task habitItem, int position) { super.bindHolder(habitItem, position); binding.setHabit(habitItem); } } - public class DailyViewHolder extends ViewHolder { + public class DailyViewHolder extends ViewHolder { @InjectView(R.id.checkBox) CheckBox checkbox; @@ -339,14 +338,14 @@ public class HabitItemRecyclerViewAdapter @Override - public void bindHolder(Daily habitItem, int position) { + public void bindHolder(Task habitItem, int position) { super.bindHolder(habitItem, position); binding.setDaily(habitItem); } } - public class TodoViewHolder extends ViewHolder implements CompoundButton.OnCheckedChangeListener { + public class TodoViewHolder extends ViewHolder implements CompoundButton.OnCheckedChangeListener { @InjectView(R.id.checkBox) CheckBox checkbox; @@ -362,7 +361,7 @@ public class HabitItemRecyclerViewAdapter } @Override - public void bindHolder(ToDo habitItem, int position) { + public void bindHolder(Task habitItem, int position) { super.bindHolder(habitItem, position); binding.setTodo(habitItem); @@ -458,7 +457,9 @@ public class HabitItemRecyclerViewAdapter public void loadContent() { if(this.observableContent == null) { - this.contents = new Select().from(this.taskClass).queryList(); + this.contents = new Select().from(this.taskClass) + .where(Condition.column("type").eq(this.taskType)) + .queryList(); } else { diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TaskRecyclerViewFragment.java b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TaskRecyclerViewFragment.java index f5a516924..df249c168 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TaskRecyclerViewFragment.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TaskRecyclerViewFragment.java @@ -104,8 +104,6 @@ public class TaskRecyclerViewFragment extends Fragment implements View.OnClickLi fragment.SetInnerAdapter(adapter, classType,showFloatingButton); - Log.d("TaskRecyclerViewFragment", "newInstance"); - return fragment; } diff --git a/Habitica/src/com/habitrpg/android/habitica/widget/UpdateWidgetService.java b/Habitica/src/com/habitrpg/android/habitica/widget/UpdateWidgetService.java index 1ba6bbfc1..b1166ea70 100644 --- a/Habitica/src/com/habitrpg/android/habitica/widget/UpdateWidgetService.java +++ b/Habitica/src/com/habitrpg/android/habitica/widget/UpdateWidgetService.java @@ -150,8 +150,8 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback // @Override public void onPostResult(double v, double v2, double v3, double v4, double v5) {} // @Override public void onPreResult() {} // @Override public void onError(HabitRPGException e) {} -// @Override public void onPostTaskAnswer(HabitItem habitItem) {} -// @Override public void onDeletedTask(HabitItem habitItem) {} -// @Override public void onEditTaskAnswer(HabitItem habitItem) {} +// @Override public void onPostTaskAnswer(Task habitItem) {} +// @Override public void onDeletedTask(Task habitItem) {} +// @Override public void onEditTaskAnswer(Task habitItem) {} // @Override public void onUserConnected(String s, String s2) {} } diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java index bec2ec51b..f8038a981 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java @@ -1,7 +1,5 @@ package com.magicmicky.habitrpgwrapper.lib; -import android.util.Log; - import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; import com.google.gson.Gson; @@ -16,12 +14,8 @@ import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection; import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData; import com.magicmicky.habitrpgwrapper.lib.models.UserAuth; import com.magicmicky.habitrpgwrapper.lib.models.UserAuthResponse; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Tags; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; import com.raizlabs.android.dbflow.structure.ModelAdapter; import java.util.List; @@ -58,7 +52,7 @@ public class HabitRPGInteractor { public boolean shouldSkipClass(Class clazz) { return false; } - }).registerTypeAdapter(Tags.class, new TagsAdapter().nullSafe()).create(); + }).registerTypeAdapter(TagsAdapter.class, new TagsAdapter().nullSafe()).create(); RestAdapter adapter = new RestAdapter.Builder() .setEndpoint(server.toString()) @@ -92,31 +86,12 @@ public class HabitRPGInteractor { * Retrieve a daily from HabitRPG's API * @param dailyId the id of the daily to retrieve * @param dailyCallback the callback called when the daily is retrieved - * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily + * @see Task */ - public void getDaily(String dailyId, Callback dailyCallback) { - this.apiService.getDaily(dailyId,dailyCallback); + public void getTask(String dailyId, Callback dailyCallback) { + this.apiService.getTask(dailyId, dailyCallback); } - /** - * Retrieve a Habit from HabitRPG's API - * @param habitId the id of the habit to retrieve. - * @param habitCallback the callback called when the habit is retrieved. - * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit - */ - public void getHabit(String habitId, Callback habitCallback) { - this.apiService.getHabit(habitId,habitCallback); - } - - /** - * Retrieve a To do from HabitRPG's API - * @param todoId the id of the item to retrieve - * @param todoCallback the callback called when the item is retrieved. - * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo - */ - public void getToDo(String todoId, Callback todoCallback) { - this.apiService.getToDo(todoId,todoCallback); - } /** * Retrieve a Reward form HabitRPG's API @@ -125,7 +100,7 @@ public class HabitRPGInteractor { * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward */ public void getReward(String rewardId, Callback rewardCallback) { - this.apiService.getReward(rewardId,rewardCallback); + this.apiService.getReward(rewardId, rewardCallback); } /** @@ -141,32 +116,12 @@ public class HabitRPGInteractor { /** * Create a daily on HabitRPG - * @param daily the daily to create - * @param dailyCallback the callback called when the daily is created - * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily + * @param task the daily to create + * @param taskCallback the callback called when the daily is created + * @see Task */ - public void createItem(Daily daily, Callback dailyCallback) { - this.apiService.createItem(daily, dailyCallback ); - } - - /** - * Create an Habit - * @param habit the haibt to create - * @param habitCallback the callback called once the habit is created - * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit - */ - public void createItem(Habit habit, Callback habitCallback) { - this.apiService.createItem(habit, habitCallback); - } - - /** - * Create a To do - * @param todoItem the item to create - * @param toDoCallback the callback called once the item is created - * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo - */ - public void createItem(ToDo todoItem, Callback toDoCallback) { - this.apiService.createItem(todoItem, toDoCallback); + public void createItem(Task task, Callback taskCallback) { + this.apiService.createItem(task, taskCallback); } /** @@ -180,32 +135,12 @@ public class HabitRPGInteractor { /** * Update an habit - * @param habitId the id of the habit to update - * @param habit the habit to update, with updated field - * @param habitCallback the callback called once the habit is updated + * @param taskId the id of the habit to update + * @param task the habit to update, with updated field + * @param taskCallback the callback called once the habit is updated */ - public void updateItem(String habitId, Habit habit, Callback habitCallback) { - this.apiService.updateTask(habitId, habit, habitCallback); - } - - /** - * Updates a daily - * @param dailyId the id of the daily to update - * @param daily the new daily item, with updated field - * @param habitCallback the callback called once the daily is updated - */ - public void updateItem(String dailyId, Daily daily, Callback habitCallback) { - this.apiService.updateTask(dailyId, daily, habitCallback); - } - - /** - * Updates a To do item - * @param todoId the id of the item to update - * @param todoItem the item to udpate, with updated field - * @param toDoCallback the callback called once the item is updated - */ - public void updateItem(String todoId, ToDo todoItem, Callback toDoCallback) { - this.apiService.updateTask(todoId, todoItem, toDoCallback); + public void updateItem(String taskId, Task task, Callback taskCallback) { + this.apiService.updateTask(taskId, task, taskCallback); } /** diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java index 086b8c15c..6aa589813 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java @@ -7,11 +7,9 @@ import com.magicmicky.habitrpgwrapper.lib.models.Tag; import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData; import com.magicmicky.habitrpgwrapper.lib.models.UserAuth; import com.magicmicky.habitrpgwrapper.lib.models.UserAuthResponse; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData; import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; import java.util.List; @@ -47,38 +45,26 @@ public interface ApiService { // void revive(Callback habitRPGUserCallback); - @GET("/user/tasks/{id}") - void getHabit(@Path("id") String id, Callback habitItemCallback); - @GET("/user/tasks/{id}") - void getDaily(@Path("id") String id, Callback habitItemCallback); - @GET("/user/tasks/{id}") - void getToDo(@Path("id") String id, Callback habitItemCallback); @GET("/user/tasks/{id}") void getReward(@Path("id") String id, Callback habitItemCallback); + @GET("/user/tasks/{id}") + void getTask(@Path("id") String id, Callback habitItemCallback); @POST("/user/tasks/{id}/{direction}") void postTaskDirection(@Path("id") String id, @Path("direction") String direction, Callback taskDirectionCallback); - @POST("/user/tasks") - void createItem(@Body Habit item, Callback habitItemCallback); - @POST("/user/tasks") - void createItem(@Body Daily item, Callback habitItemCallback); - @POST("/user/tasks") - void createItem(@Body ToDo item, Callback habitItemCallback); @POST("/user/tasks") void createItem(@Body Reward item, Callback habitItemCallback); + @POST("/user/tasks") + void createItem(@Body Task item, Callback habitItemCallback); - @PUT("/user/tasks/{id}") - void updateTask(@Path("id") String id, @Body Habit item, Callback habitItemCallback); - @PUT("/user/tasks/{id}") - void updateTask(@Path("id") String id, @Body Daily item, Callback habitItemCallback); - @PUT("/user/tasks/{id}") - void updateTask(@Path("id") String id, @Body ToDo item, Callback habitItemCallback); @PUT("/user/tasks/{id}") void updateTask(@Path("id") String id, @Body Reward item, Callback habitItemCallback); + @PUT("/user/tasks/{id}") + void updateTask(@Path("id") String id, @Body Task item, Callback habitItemCallback); @DELETE("/user/tasks/{id}") diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java index 07171972a..ebab0a7fe 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java @@ -2,14 +2,7 @@ package com.magicmicky.habitrpgwrapper.lib.api; import android.util.Log; -import com.google.gson.Gson; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Checklist; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import retrofit.Callback; import retrofit.RetrofitError; @@ -17,30 +10,16 @@ import retrofit.client.Response; /** * TODO: Tags - * Simple implementation of a HabitItem callback, supposed to be called when the result is either a single + * Simple implementation of a Task callback, supposed to be called when the result is either a single * to do, daily, habit or reward. * Created by MagicMicky on 10/06/2014. */ -public class HabitItemCallback implements Callback { +public class HabitItemCallback implements Callback { private static final String TAG = "HabitCallback"; @Override public void success(T habitItem, Response response) { - if(habitItem instanceof ToDo) { - Log.d(TAG, "todo"); - } else if(habitItem instanceof Habit){ - Log.d(TAG, "habit"); - } else if(habitItem instanceof Daily) { - Log.d(TAG, "daily"); - ((Daily) habitItem).addItem(new ChecklistItem("OMG")); - } else if(habitItem instanceof Reward) { - Log.d(TAG, "reward"); - } else { - Log.d(TAG, "Unknown"); - } - - Log.d(TAG +"_ans", new Gson().toJson(habitItem)); } diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java index b576828ab..defd6561f 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java @@ -1,14 +1,11 @@ package com.magicmicky.habitrpgwrapper.lib.api.TypeAdapter; -import android.util.Log; - import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Tags; - -import org.json.JSONTokener; +import com.magicmicky.habitrpgwrapper.lib.models.Tag; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag; +import com.raizlabs.android.dbflow.sql.language.Select; import java.io.IOException; import java.util.ArrayList; @@ -17,23 +14,24 @@ import java.util.List; /** * Created by magicmicky on 15/05/15. */ -public class TagsAdapter extends TypeAdapter{ +public class TagsAdapter extends TypeAdapter>{ @Override - public void write(JsonWriter out, Tags value) throws IOException { - List list = value.getTags(); + public void write(JsonWriter out, List value) throws IOException { out.beginObject(); - for(String s : list) { - out.name(s); + for(TaskTag tag : value) { + out.name(tag.getTag().getId()); out.value(true); } out.endObject(); - //Log.d("TagsAdapter", "Finished tagging"); } @Override - public Tags read(JsonReader in) throws IOException { - List tags = new ArrayList<>(); + public List read(JsonReader in) throws IOException { + List tags = new ArrayList<>(); + List allTags = new Select() + .from(Tag.class) + .queryList(); boolean isClosed=false; do { switch(in.peek()) { @@ -41,11 +39,18 @@ public class TagsAdapter extends TypeAdapter{ in.beginObject(); break; case NAME: - String tag = in.nextName(); + String taskId = in.nextName(); + if(in.nextBoolean()) { - tags.add(tag); + TaskTag taskTag = new TaskTag(); + for (Tag tag : allTags) { + if (tag.getId().equals(taskId)) { + taskTag.setTag(tag); + break; + } + } + tags.add(taskTag); } - //Log.d("TagsAdapter", "Added tag " + tag); break; case END_OBJECT: in.endObject(); @@ -62,6 +67,6 @@ public class TagsAdapter extends TypeAdapter{ default: } } while(!isClosed); - return new Tags(tags); + return tags; } } diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java index c9c5b8b09..5419c6f69 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java @@ -1,16 +1,15 @@ package com.magicmicky.habitrpgwrapper.lib.models; import com.habitrpg.android.habitica.HabitDatabase; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task; import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; import com.raizlabs.android.dbflow.annotation.Column; import com.raizlabs.android.dbflow.annotation.ForeignKey; import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; import com.raizlabs.android.dbflow.annotation.OneToMany; import com.raizlabs.android.dbflow.annotation.PrimaryKey; import com.raizlabs.android.dbflow.annotation.Table; +import com.raizlabs.android.dbflow.sql.builder.Condition; import com.raizlabs.android.dbflow.sql.language.Select; import com.raizlabs.android.dbflow.structure.BaseModel; @@ -28,10 +27,10 @@ public class HabitRPGUser extends BaseModel { @PrimaryKey private String id; - List dailys; - List todos; + List dailys; + List todos; List rewards; - List habits; + List habits; List tags; @Column @@ -82,11 +81,11 @@ public class HabitRPGUser extends BaseModel { this.id = id; } - public void setDailys(List dailys) { + public void setDailys(List dailys) { this.dailys = dailys; } - public void setTodos(List todos) { + public void setTodos(List todos) { this.todos = todos; } @@ -94,7 +93,7 @@ public class HabitRPGUser extends BaseModel { this.rewards = rewards; } - public void setHabits(List habits) { + public void setHabits(List habits) { this.habits = habits; } @@ -135,30 +134,33 @@ public class HabitRPGUser extends BaseModel { } @OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "habits") - public List getHabits() { + public List getHabits() { if(habits == null) { habits = new Select() - .from(Habit.class) + .from(Task.class) + .where(Condition.column("type").eq("habit")) .queryList(); } return habits; } @OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "dailys") - public List getDailys() { + public List getDailys() { if(dailys == null) { dailys = new Select() - .from(Daily.class) + .from(Task.class) + .where(Condition.column("type").eq("daily")) .queryList(); } return dailys; } @OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "todos") - public List getTodos() { + public List getTodos() { if(todos == null) { todos = new Select() - .from(ToDo.class) + .from(Task.class) + .where(Condition.column("type").eq("todo")) .queryList(); } return todos; @@ -174,7 +176,7 @@ public class HabitRPGUser extends BaseModel { return rewards; } - @OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "rewards") + @OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "tags") public List getTags() { if(tags == null) { tags = new Select() diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java index bdb57b04c..bb98587e8 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java @@ -1,11 +1,17 @@ package com.magicmicky.habitrpgwrapper.lib.models; import com.habitrpg.android.habitica.HabitDatabase; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag; import com.raizlabs.android.dbflow.annotation.Column; +import com.raizlabs.android.dbflow.annotation.OneToMany; import com.raizlabs.android.dbflow.annotation.PrimaryKey; import com.raizlabs.android.dbflow.annotation.Table; +import com.raizlabs.android.dbflow.sql.builder.Condition; +import com.raizlabs.android.dbflow.sql.language.Select; import com.raizlabs.android.dbflow.structure.BaseModel; +import java.util.List; + /** * Description of a Tag in HabitRPG * Created by MagicMicky on 16/03/14. @@ -16,11 +22,13 @@ public class Tag extends BaseModel{ @Column @PrimaryKey - String id; + public String id; @Column String name; + public List tasks; + public Tag() { this(null,null); } @@ -30,6 +38,14 @@ public class Tag extends BaseModel{ this.setName(name); } + public List getTasks() { + if(tasks == null) { + tasks = new Select() + .from(TaskTag.class) + .queryList(); + } + return tasks; + } public String getName() { return name; diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java deleted file mode 100644 index 0bc898e15..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - -import com.habitrpg.android.habitica.HabitDatabase; -import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.ForeignKey; -import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; -import com.raizlabs.android.dbflow.annotation.OneToMany; -import com.raizlabs.android.dbflow.annotation.PrimaryKey; -import com.raizlabs.android.dbflow.annotation.Table; -import com.raizlabs.android.dbflow.sql.builder.Condition; -import com.raizlabs.android.dbflow.sql.language.Select; -import com.raizlabs.android.dbflow.structure.BaseModel; -import com.raizlabs.android.dbflow.structure.container.ForeignKeyContainer; - -import java.util.ArrayList; -import java.util.List; - -/** - * Description of Checklist on HabitRPG - * Created by MagicMicky - */ -public abstract class Checklist extends HabitItem{ - List checklistItems; - - public Checklist() { - this(null,null,null,null); - } - - public Checklist(String notes, Float priority, String text, Double value) { - super(notes, priority, text, value); - this.checklistItems = new ArrayList(); - } - public Checklist(String notes, Float priority, String text, - double value, Checklist checklistToCopy) { - this(notes, priority, text, value); - for(ChecklistItem item : checklistToCopy.getItems()) { - checklistItems.add(new ChecklistItem(item)); - } - } - - public void addItems(Checklist list){ - for (ChecklistItem l : list.getItems()) - { - this.checklistItems.add(l); - } - } - - public void addItem(ChecklistItem item) { - this.checklistItems.add(item); - } - - - public void toggleItem(String id) { - boolean flag = false; - for(int i=0;i getItems() {return checklistItems;}; - - public List getChecklistItems() { - return checklistItems; - } - - public int getSize() { - return checklistItems.size(); - } - public int getNbCompleted() { - int nbCompleted =0; - for(ChecklistItem it : checklistItems) { - if(it.getCompleted()) nbCompleted++; - } - return nbCompleted; - } - -} \ No newline at end of file diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ChecklistItem.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ChecklistItem.java index f15137b2e..1f1dccf77 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ChecklistItem.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ChecklistItem.java @@ -24,15 +24,15 @@ public class ChecklistItem extends BaseModel { @Column private boolean completed; - - /*@Column +/* + @Column @ForeignKey( - references = {@ForeignKeyReference(columnName = "checklist_id", + references = {@ForeignKeyReference(columnName = "task_id", columnType = String.class, foreignColumnName = "id")}, - saveForeignKeyModel = false)*/ - ForeignKeyContainer queenModelContainer; - + saveForeignKeyModel = false) + ForeignKeyContainer task; +*/ public ChecklistItem() { this(null,null); } diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java deleted file mode 100644 index 20d1e9444..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - - -import com.habitrpg.android.habitica.HabitDatabase; -import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.ForeignKey; -import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; -import com.raizlabs.android.dbflow.annotation.OneToMany; -import com.raizlabs.android.dbflow.annotation.PrimaryKey; -import com.raizlabs.android.dbflow.annotation.Table; -import com.raizlabs.android.dbflow.sql.builder.Condition; -import com.raizlabs.android.dbflow.sql.language.Select; -import com.raizlabs.android.dbflow.structure.BaseModel; - -import java.util.Date; -import java.util.List; - -/** - * A daily item. It contains the item called "Daily" on the website - * @author MagicMicky - */ -@Table(databaseName = HabitDatabase.NAME) -public class Daily extends Checklist{ - private final HabitType type=HabitType.daily; - - @Column - public Boolean completed; - - @Column - private String frequency; - - @Column - private Integer everyX; - - @Column - @ForeignKey(references = {@ForeignKeyReference(columnName = "days_id", - columnType = Long.class, - foreignColumnName = "id")}) - private Days repeat; - //TODO: private String lastCompleted; - - @Column - private Integer streak; - /** - * Construct a daily based on all the information needed - * @param id the id of the daily - * @param notes the notes associated to a daily - * @param priority the priority of the daily - * @param text the text of the daily - * @param value the value (points) of the daily - * @param completed whether or not the daily is completed - * @param repeat when does it repeat? - * @param streak the streak - * @param lastCompleted when was the last time it was completed? - */ - public Daily(String id, String notes, Float priority, String text, - Double value, Boolean completed, Days repeat, Integer streak, String lastCompleted) { - //this(id, notes, priority, text, value,completed,repeat,lastCompleted); - super(notes,priority,text,value); - this.setId(id); - this.setCompleted(completed); - this.setRepeat(repeat); - this.setStreak(streak); - //this.setLastCompleted(lastCompleted); - } - public Daily(String id, String notes, Float priority, String text, - Double value, Boolean completed, Days repeat) { - this(id, notes, priority, text, value, completed, repeat, null, null); - } - - public Daily() { - this(null, null, null, null, null, null, null); - } - - /** - * @return if the daily is completed - */ - public boolean getCompleted() { - return completed; - } - /** - * Set whether or not the daily is completed - * @param completed - */ - public void setCompleted(Boolean 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.
- * This array contains 7 values, one for each days, starting from monday. - */ - public Days getRepeat() { - return repeat; - } - /** - * @param repeat the repeat array to set - */ - public void setRepeat(Days repeat) { - this.repeat = repeat; - } - @Override - public HabitType getType() { - return type; - } - /** - * Formated: - * SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - * @return the lastCompleted - */ -/* public String getLastCompleted() { - return lastCompleted; - } - /** - * @param lastCompleted the lastCompleted to set - */ -/* public void setLastCompleted(String lastCompleted) { - this.lastCompleted = lastCompleted; - } - /** - * @return the streak - */ - public int getStreak() { - return streak; - } - /** - * @param streak the streak to set - */ - public void setStreak(Integer streak) { - this.streak = streak; - } -} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java deleted file mode 100644 index 68253a650..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - - -import com.habitrpg.android.habitica.HabitDatabase; -import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.PrimaryKey; -import com.raizlabs.android.dbflow.annotation.Table; - -/** - * An habit item. It contains the item called "Habits" on the website - * @author MagicMicky - * - */ -@Table(databaseName = HabitDatabase.NAME) -public class Habit extends HabitItem{ - private final HabitType type = HabitType.habit; - - @Column - public Boolean up, down; - /** - * Create a new Habit based on all the information needed - * @param id the id of the habit - * @param notes the notes associated to a habit - * @param priority the priority of the habit - * @param text the text of the habit - * @param value the value (points) of the habit - * @param up whether or not the habit can be "upped" - * @param down whether or not the habit can be "downed" - */ - public Habit(String id, String notes, Float priority, String text, double value - , Boolean up, Boolean down) { - super(notes, priority, text, value); - this.setId(id); - this.setUp(up); - this.setDown(down); - } - public Habit() { - super(); - this.setDown(null); - this.setUp(null); - } - /** - * @return whether or not the habit can be "upped" - */ - public boolean getUp() { - return up; - } - /** - * Set the Up value - * @param up - */ - public void setUp(Boolean up) { - this.up = up; - } - /** - * @return whether or not the habit can be "down" - */ - public boolean getDown() { - return down; - } - /** - * Set the Down value - * @param down - */ - public void setDown(Boolean down) { - this.down = down; - } - @Override - public HabitType getType() { - return type; - } - -} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java deleted file mode 100644 index b97efae8e..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - -import android.graphics.Color; - -import com.habitrpg.android.habitica.HabitDatabase; -import com.habitrpg.android.habitica.R; -import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.PrimaryKey; -import com.raizlabs.android.dbflow.annotation.Table; -import com.raizlabs.android.dbflow.structure.BaseModel; - -import org.json.JSONObject; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - * Custom Item that regroup all the others. - * @author MagicMicky - * - */ -public abstract class HabitItem extends BaseModel implements Serializable { - private String _id; - - @Column - @PrimaryKey - String id; - - @Column - public String notes; - - @Column - public Float priority; - - @Column - public String text; - - @Column - public Double value; - - @Column - public String attribute; - - private Tags tags; - /** - * Create a new HabitItem from what is necessary - * @param notes the notes associated to a habit - * @param priority the priority of the habit - * @param text the text of the habit - * @param value the value (points) of the habit - */ - public HabitItem(String notes, Float priority, String text, Double value) { - this.setNotes(notes); - this.setPriority(priority); - this.setText(text); - this.setValue(value); - this.tags=new Tags(); - - } - public HabitItem() { - this(null,null,null,null); - } - /** - * @return the id - */ - public String getId() { - return id; - } - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - /** - * @return the notes - */ - public String getNotes() { - return notes; - } - /** - * @param notes the notes to set - */ - public void setNotes(String notes) { - this.notes = notes; - } - /** - * @return the priority - */ - public Float getPriority() { - return priority; - } - /** - * @param i the priority to set - */ - public void setPriority(Float i) { - this.priority = i; - } - /** - * @return the text - */ - public String getText() { - return text; - } - /** - * @param text the text to set - */ - public void setText(String text) { - this.text = text; - } - /** - * @return the value - */ - public double getValue() { - return value; - } - /** - * @param value the value to set - */ - public void setValue(Double value) { - this.value = value; - } - - /** - * To be allowed to set int value without problems - * @param value the value to set - */ - public void setValue(double value) { - this.setValue(Double.valueOf(value)); - } - - /** - * @return the tags - */ - public List getTags() { - return tags.getTags(); - } - /** - * @param tags the tagsId to set - */ - public void setTags(List tags) { - this.tags.setTags(tags); - } - - public boolean isTagged(List tags) { - if(this.getTags()==null) { - System.out.println("getTags is null!!!"); - } - return (this.getTags() != null && this.getTags().size() != 0); - - } - /** - * Returns a string of the type of the HabitItem - * @return the string of the Item type - */ - public abstract HabitType getType(); - - /** - * Creates a JSON String for this HabitItem using the basic information.
- * Doesn't have the necessary open and close brackets to create an item. - * @return - */ - protected String getJSONBaseString() { - StringBuilder json = new StringBuilder(); - if(this.getId()!=null) - json.append("\"id\":").append(JSONObject.quote(this.getId())).append(","); - json - .append("\"type\":\"").append(this.getType()).append("\"," ) - .append("\"text\":").append(JSONObject.quote(this.getText())).append("," ); - if(this.getPriority()!=null) - json.append("\"priority\":").append(this.getPriority()).append(","); - if(this.getNotes()!=null && !this.getNotes().contentEquals("")) - json.append("\"notes\":").append(JSONObject.quote(this.getNotes())).append("," ); - json.append("\"value\":").append(this.getValue()).append(","); - if(this.getTags()!=null) { //TODO: && this.getTags().size()!=0 - json.append("\"tags\":{"); - /*for(String tagId : this.getTags()) { - json.append("").append(JSONObject.quote(tagId)).append(":").append("true").append(","); - }*/ - json.deleteCharAt(json.length()-1); - json.append("},"); - } - if(this.getAttribute()!=null) { - json.append("\"attribute\":\"").append(this.getAttribute()).append("\","); - } - return json.toString(); - } - /** - * @return the attribute - */ - public String getAttribute() { - return attribute; - } - /** - * @param attribute the attribute to set - */ - public void setAttribute(String attribute) { - this.attribute = attribute; - } - - public int getLightTaskColor() - { - if (this.value < -20) - return R.color.worst; - if (this.value < -10) - return R.color.worse; - if (this.value < -1) - return R.color.bad; - if (this.value < 5) - return R.color.neutral; - if (this.value < 10) - return R.color.better; - return R.color.best; - } - - /** - * Get the button color resources depending on a certain score - * - * @param d the score - * @return the color resource id - */ - public int getDarkTaskColor() - { - if (this.value < -20) - return R.color.worst_btn; - if (this.value < -10) - return R.color.worse_btn; - if (this.value < -1) - return R.color.bad_btn; - if (this.value < 5) - return R.color.neutral_btn; - if (this.value < 10) - return R.color.better_btn; - - return R.color.best_btn; - } -} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java deleted file mode 100644 index 0a4e43aa3..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - -public enum HabitType { - habit, - reward, - todo, - daily - -} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java index 51c747868..479b6e4c7 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java @@ -2,8 +2,6 @@ package com.magicmicky.habitrpgwrapper.lib.models.tasks; import com.habitrpg.android.habitica.HabitDatabase; -import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.PrimaryKey; import com.raizlabs.android.dbflow.annotation.Table; /** @@ -12,22 +10,7 @@ import com.raizlabs.android.dbflow.annotation.Table; * */ @Table(databaseName = HabitDatabase.NAME, allFields = true) -public class Reward extends HabitItem{ - private final HabitType type = HabitType.reward; - - /** - * Create a new Reward - * @param id the id of the reward - * @param notes the notes associated to a reward - * @param priority the priority of the reward - * @param text the text of the reward - * @param value the value (points) of the reward - */ - public Reward(String id, String notes, Float priority, String text, - double value) { - super(notes, priority, text, value); - this.setId(id); - } +public class Reward extends Task { public Reward() { super(); @@ -45,116 +28,4 @@ public class Reward extends HabitItem{ this.id = id; } - @Override - public HabitType getType() { - return type; - } - - public static class SpecialReward extends Reward { - private static SpecialReward[] weapons= { - new SpecialReward(0, "Training Sword","weapon_0","Training weapon.",0,0), - new SpecialReward(1, "Sword","weapon_1","Increases experience gain by 3%.",3,20), - new SpecialReward(2, "Axe", "weapon_2","Increases experience gain by 6%.",6,30), - new SpecialReward(3, "Morningstar", "weapon_3","Increases experience gain by 9%.",9,45), - new SpecialReward(4, "Blue Sword", "weapon_4","Increases experience gain by 12%.",12,65), - new SpecialReward(5, "Red Sword", "weapon_5","Increases experience gain by 15%.",15,90), - new SpecialReward(6, "Golden Sword", "weapon_6","Increases experience gain by 18%.",18,120), - new SpecialReward(7, "Dark Souls Blade", "weapon_7","Increases experience gain by 21%.",21,150) - }; - private static SpecialReward[] armors={ - new SpecialReward(0, "Cloth Armor","armor_0","Training armor.",0,0), - new SpecialReward(1, "Leather Armor","armor_1","Decreases HP loss by 4%.",4,30), - new SpecialReward(2, "Chain Mail","armor_2","Decreases HP loss by 6%.",6,45), - new SpecialReward(3, "Plate Mail","armor_3","Decreases HP loss by 7%.",7,65), - new SpecialReward(4, "Red Armor","armor_4","Decreases HP loss by 8%.",8,90), - new SpecialReward(5, "Golden Armor","armor_5","Decreases HP loss by 10%.",10,120), - new SpecialReward(6, "Shade Armor","armor_6","Decreases HP loss by 12%.",12,150) - };// - private static SpecialReward[] heads = { - new SpecialReward(0, "No Helm","head_0","Training helm.",0,0), - new SpecialReward(1, "Leather Helm","head_1","Decreases HP loss by 2%.",2,15), - new SpecialReward(2, "Chain Coif","head_2","Decreases HP loss by 3%.",3,25), - new SpecialReward(3, "Plate Helm","head_3","Decreases HP loss by 4%.",4,45), - new SpecialReward(4, "Red Helm","head_4","Decreases HP loss by 5%.",5,60), - new SpecialReward(5, "Golden Helm","head_5","Decreases HP loss by 6%.",6,80), - new SpecialReward(6, "Shade Helm","head_6","Decreases HP loss by 7%.",7,100) - };// - - private static SpecialReward[] shields= { - new SpecialReward(0, "No Shield","shield_0","No Shield.",0,0), - new SpecialReward(1, "Wooden Shield","shield_1","Decreases HP loss by 3%",3,20), - new SpecialReward(2, "Buckler","shield_2","Decreases HP loss by 4%.",4,35), - new SpecialReward(3, "Reinforced Shield","shield_3","Decreases HP loss by 5%.",5,55), - new SpecialReward(4, "Red Shield","shield_4","Decreases HP loss by 7%.",7,70), - new SpecialReward(5, "Golden Shield","shield_5","Decreases HP loss by 8%.",8,90), - new SpecialReward(6, "Tormented Skull","shield_6","Decreases HP loss by 9%.",9,120) - };// - - private String classes; - private int plusValue; - private SpecialReward currentReward; - private String type; - private int level; - private SpecialReward(int id, String text, String classes, String notes, int plusValue, double value) { - this.setId(id+""); - this.setText(text); - this.setNotes(notes); - this.setValue(value); - this.setClasses(classes); - this.setPlusValue(plusValue); - } - private SpecialReward(SpecialReward rew) { - this(Integer.parseInt(rew.getId()),rew.getText(),rew.getClasses(),rew.getNotes(),rew.getPlusValue(),rew.getValue()); - } - public SpecialReward(int level, String type) throws ArrayIndexOutOfBoundsException { - this(getRewardFromLevelAndType(level,type)); - - this.type=type; - this.level = level; - } - private static SpecialReward getRewardFromLevelAndType(int level, - String type) { - if(type.equals("armor")) { - if(level > 7) - level=7; - return armors[level]; - } - else if(type.equals("weapon")) { - if(level > 6) - level=6; - return weapons[level]; - } - else if(type.equals("head")) { - if(level > 6) - level=6; - return heads[level]; - } - else { - if(level > 6) - level=6; - return shields[level]; - } - } - public int getPlusValue() { - return this.plusValue; - } - public void setPlusValue(int plusValue) { - this.plusValue=plusValue; - } - public String getClasses() { - return this.classes; - } - public void setClasses(String classes) { - this.classes=classes; - } - public String getPlusValueType() { - if(type == "weapon") { - return "strength"; - } - return "defense"; - } - public int getLevel() { - return level; - } - } } diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java deleted file mode 100644 index 374454f6f..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by magicmicky on 15/05/15. - */ -public class Tags { - private List tags; - - public Tags() { - this.tags = new ArrayList<>(); - } - public Tags(List tags) { - this.tags = tags; - } - - public List getTags() { - return tags; - } - - public void setTags(List tags) { - this.tags = tags; - } -} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java new file mode 100644 index 000000000..75553f21c --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java @@ -0,0 +1,284 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + +import com.habitrpg.android.habitica.HabitDatabase; +import com.habitrpg.android.habitica.R; +import com.raizlabs.android.dbflow.annotation.Column; +import com.raizlabs.android.dbflow.annotation.ForeignKey; +import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; +import com.raizlabs.android.dbflow.annotation.OneToMany; +import com.raizlabs.android.dbflow.annotation.PrimaryKey; +import com.raizlabs.android.dbflow.annotation.Table; +import com.raizlabs.android.dbflow.sql.language.Select; +import com.raizlabs.android.dbflow.structure.BaseModel; + +import java.util.List; + +/** + * Created by viirus on 10/08/15. + */ +@Table(databaseName = HabitDatabase.NAME) +public class Task extends BaseModel { + + @Column + @PrimaryKey + String id; + @Column + public Float priority; + + @Column + public String text, notes, attribute, type; + + @Column + public Double value; + + + @Column + public Boolean up, down; + + @Column + public Boolean completed; + + @Column + public String frequency; + + @Column + public Integer everyX, streak; + + @Column + @ForeignKey(references = {@ForeignKeyReference(columnName = "days_id", + columnType = Long.class, + foreignColumnName = "id")}) + public Days repeat; + //TODO: private String lastCompleted; + + @Column + public String date; + + /** + * @return the id + */ + public String getId() { + return id; + } + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + /** + * @return the notes + */ + public String getNotes() { + return notes; + } + /** + * @param notes the notes to set + */ + public void setNotes(String notes) { + this.notes = notes; + } + /** + * @return the priority + */ + public Float getPriority() { + return priority; + } + /** + * @param i the priority to set + */ + public void setPriority(Float i) { + this.priority = i; + } + /** + * @return the text + */ + public String getText() { + return text; + } + /** + * @param text the text to set + */ + public void setText(String text) { + this.text = text; + } + /** + * @return the value + */ + public double getValue() { + return value; + } + /** + * @param value the value to set + */ + public void setValue(Double value) { + this.value = value; + } + + /** + * To be allowed to set int value without problems + * @param value the value to set + */ + public void setValue(double value) { + this.setValue(Double.valueOf(value)); + } + + + /** + * Returns a string of the type of the Task + * @return the string of the Item type + */ + public String getType() {return this.type;} + + public void setType(String type) {this.type = type;} + + /** + * @return whether or not the habit can be "upped" + */ + public boolean getUp() { + return up; + } + /** + * Set the Up value + * @param up + */ + public void setUp(Boolean up) { + this.up = up; + } + /** + * @return whether or not the habit can be "down" + */ + public boolean getDown() { + return down; + } + /** + * Set the Down value + * @param down + */ + public void setDown(Boolean down) { + this.down = down; + } + + + public boolean getCompleted() { + return completed; + } + /** + * Set whether or not the daily is completed + * @param completed + */ + public void setCompleted(Boolean 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.
+ * This array contains 7 values, one for each days, starting from monday. + */ + public Days getRepeat() { + return repeat; + } + /** + * @param repeat the repeat array to set + */ + public void setRepeat(Days repeat) { + this.repeat = repeat; + } + /** + * Formated: + * SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + * @return the lastCompleted + */ +/* public String getLastCompleted() { + return lastCompleted; + } + /** + * @param lastCompleted the lastCompleted to set + */ +/* public void setLastCompleted(String lastCompleted) { + this.lastCompleted = lastCompleted; + } + /** + * @return the streak + */ + public int getStreak() { + return streak; + } + /** + * @param streak the streak to set + */ + public void setStreak(Integer streak) { + this.streak = streak; + } + + + /** + * @return the due date + */ + public String getDate() { + return date; + } + + /** + * Set the due date + * @param date the date to set + */ + public void setDate(String date) { + this.date = date; + } + + /** + * @return the attribute + */ + public String getAttribute() { + return attribute; + } + /** + * @param attribute the attribute to set + */ + public void setAttribute(String attribute) { + this.attribute = attribute; + } + + public int getLightTaskColor() + { + if (this.value < -20) + return R.color.worst; + if (this.value < -10) + return R.color.worse; + if (this.value < -1) + return R.color.bad; + if (this.value < 5) + return R.color.neutral; + if (this.value < 10) + return R.color.better; + return R.color.best; + } + + /** + * Get the button color resources depending on a certain score + * + * @return the color resource id + */ + public int getDarkTaskColor() + { + if (this.value < -20) + return R.color.worst_btn; + if (this.value < -10) + return R.color.worse_btn; + if (this.value < -1) + return R.color.bad_btn; + if (this.value < 5) + return R.color.neutral_btn; + if (this.value < 10) + return R.color.better_btn; + + return R.color.best_btn; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/TaskTag.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/TaskTag.java new file mode 100644 index 000000000..b7b813331 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/TaskTag.java @@ -0,0 +1,55 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + +import com.habitrpg.android.habitica.HabitDatabase; +import com.magicmicky.habitrpgwrapper.lib.models.Tag; +import com.raizlabs.android.dbflow.annotation.Column; +import com.raizlabs.android.dbflow.annotation.ForeignKey; +import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; +import com.raizlabs.android.dbflow.annotation.PrimaryKey; +import com.raizlabs.android.dbflow.annotation.Table; +import com.raizlabs.android.dbflow.structure.BaseModel; +import com.raizlabs.android.dbflow.structure.container.ForeignKeyContainer; + + +/** + * Created by viirus on 08/08/15. + */ + +@Table(databaseName = HabitDatabase.NAME) +public class TaskTag extends BaseModel { + + @Column + @PrimaryKey(autoincrement = true) + long id; + + @Column + @ForeignKey(references = {@ForeignKeyReference(columnName = "tag_id", + columnType = String.class, + foreignColumnName = "id")}) + public ForeignKeyContainer tag; + + @Column + @ForeignKey(references = {@ForeignKeyReference(columnName = "task_id", + columnType = String.class, + foreignColumnName = "id")}) + public ForeignKeyContainer task; + + public Tag getTag() { + return tag.toModel(); + } + + public void setTag(Tag tag) { + this.tag = new ForeignKeyContainer<>(Tag.class); + this.tag.setModel(tag); + } + + public Task getTask() { + return task.toModel(); + } + + public void setTask(Task task) { + this.task = new ForeignKeyContainer<>(Task.class); + this.task.setModel(task); + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java deleted file mode 100644 index 00858f17f..000000000 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.magicmicky.habitrpgwrapper.lib.models.tasks; - - -import com.habitrpg.android.habitica.HabitDatabase; -import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.OneToMany; -import com.raizlabs.android.dbflow.annotation.PrimaryKey; -import com.raizlabs.android.dbflow.annotation.Table; -import com.raizlabs.android.dbflow.sql.builder.Condition; -import com.raizlabs.android.dbflow.sql.language.Select; - -import java.util.List; - -/** - * A ToDo task that you can see of the website - * You can set a complete date to a ToDo, and you can complete them using a boolean - * @author MagicMicky - * - */ - -@Table(databaseName = HabitDatabase.NAME) -public class ToDo extends Checklist{ - private final HabitType type=HabitType.todo; - - @Column - public Boolean completed; - - @Column - public String date; - /** - * Construct a daily based on all the information needed - * @param id the id of the daily - * @param notes the notes associated to a daily - * @param priority the priority of the daily - * @param text the text of the daily - * @param value the value (points) of the daily - * @param completed whether or not the daily is completed - * @param date the due date - */ - public ToDo(String id, String notes, Float priority, String text, - double value, boolean completed, String date) { - super(notes, priority, text, value); - this.setId(id); - this.setCompleted(completed); - this.setDate(date); - } - - public ToDo() { - super(); - this.setCompleted(null); - this.setDate(null); - } - /** - * @return if the todo is completed - */ - public boolean getCompleted() { - return completed; - } - - /** - * Set whether or not the todo is completed - * @param completed - */ - public void setCompleted(Boolean completed) { - this.completed = completed; - } - - /** - * @return the due date - */ - public String getDate() { - return date; - } - - /** - * Set the due date - * @param date the date to set - */ - public void setDate(String date) { - this.date = date; - } - - @Override - public HabitType getType() { - return type; - } - -} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java index 30d454d75..18899efe9 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java @@ -1,6 +1,5 @@ package com.magicmicky.habitrpgwrapper.lib.utils; -import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; import com.magicmicky.habitrpgwrapper.lib.models.tasks.Days; /**