Combine task classes into one

This commit is contained in:
Phillip Thelen 2015-08-10 15:56:52 +02:00
parent efecb79e81
commit ab84bf83d9
40 changed files with 573 additions and 1858 deletions

View file

@ -2,11 +2,11 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily" />
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Task" />
<variable
name="daily"
type="Daily" />
type="Task" />
</data>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"

View file

@ -3,12 +3,12 @@
<data>
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit" />
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Task" />
<import type="android.view.View"/>
<variable
name="habit"
type="Habit" />
type="Task" />
</data>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"

View file

@ -3,11 +3,11 @@
<data>
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem" />
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward" />
<variable
name="reward"
type="HabitItem" />
type="Reward" />
</data>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"

View file

@ -2,11 +2,11 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo" />
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Task" />
<variable
name="todo"
type="ToDo" />
type="Task" />
</data>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"

View file

@ -24,12 +24,8 @@ import com.magicmicky.habitrpgwrapper.lib.api.TypeAdapter.TagsAdapter;
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
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.io.IOException;
@ -76,7 +72,7 @@ public class APIHelper implements ErrorHandler, Profiler {
return false;
}
})
.registerTypeAdapter(Tags.class, new TagsAdapter().nullSafe())
.registerTypeAdapter(TagsAdapter.class, new TagsAdapter().nullSafe())
.registerTypeAdapter(Boolean.class, booleanAsIntAdapter)
.registerTypeAdapter(boolean.class, booleanAsIntAdapter)
.create();
@ -123,29 +119,8 @@ public class APIHelper implements ErrorHandler, Profiler {
};
public void createNewTask(HabitItem item, Callback cb) {
if(item instanceof Habit) {
createNewTask((Habit) item, cb);
} else if(item instanceof Daily) {
createNewTask((Daily) item, cb);
} else if(item instanceof ToDo) {
createNewTask((ToDo) item, cb);
} else if(item instanceof Reward) {
createNewTask((Reward) item, cb);
}
}
public void createNewTask(Habit habit,Callback<Habit> callback) {
this.apiService.createItem(habit, callback);
}
public void createNewTask(ToDo toDo, Callback<ToDo> callback) {
this.apiService.createItem(toDo, callback);
}
public void createNewTask(Daily d,Callback<Daily> callback) {
this.apiService.createItem(d, callback);
}
public void createNewTask(Reward r,Callback<Reward> 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<Daily> cb) {
this.apiService.updateTask(item.getId(), item, cb);
}
public void updateTask(Habit item, Callback<Habit> cb) {
this.apiService.updateTask(item.getId(), item, cb);
}
public void updateTask(ToDo item, Callback<ToDo> cb) {
this.apiService.updateTask(item.getId(), item, cb);
}
public void updateTask(Reward item, Callback<Reward> 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<HabitItem, Void, Void> {
private class ATaskPostTask extends AsyncTask<Task, Void, Void> {
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<HabitItem, Void, Void> {
private class ATaskDeleteTask extends AsyncTask<Task, Void, Void> {
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<HabitItem, Void, Void> {
private class ATaskUpdateTask extends AsyncTask<Task, Void, Void> {
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)

View file

@ -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;
}
}

View file

@ -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<THabitItem extends Checklist> implements DialogInterface.OnClickListener {
private final Context mContext;
private Checklist checklist;
private THabitItem item;
private Callback<THabitItem> 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<ToDo>() {
@Override
public void success(ToDo toDo, Response response) {
}
@Override
public void failure(RetrofitError error) {
}
});
}
if (item instanceof Daily) {
mAPIHelper.updateTask((Daily) item, new Callback<Daily>() {
@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);
}
}

View file

@ -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<Integer, TaskRecyclerViewFragment> ViewFragmentsDictionary = new HashMap<Integer, TaskRecyclerViewFragment>();
List<HabitItem> TaskList = new ArrayList<HabitItem>();
List<Task> TaskList = new ArrayList<Task>();
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();
}

View file

@ -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);
}

View file

@ -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<HabitItem> tasks);
void onChange(List<Task> tasks);
void onTagFilter(List<String> tags);
}

View file

@ -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<CharSequence> 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);

View file

@ -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<HabitItem> {
public class TaskCreationCallback implements Callback<Task> {
private OnHabitCreated callback;
public TaskCreationCallback(OnHabitCreated cb) {
@ -22,7 +22,7 @@ public class TaskCreationCallback implements Callback<HabitItem> {
@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<HabitItem> {
}
public interface OnHabitCreated {
public void onTaskCreated(HabitItem habit);
public void onTaskCreated(Task habit);
public void onTaskCreationFail();
}
}

View file

@ -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<Void> {
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<Void> {
public interface OnTaskDeleted {
public void onTaskDeleted(HabitItem deleted);
public void onTaskDeleted(Task deleted);
public void onTaskDeletionFail();
}}

View file

@ -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<HabitItem> {
public class TaskUpdateCallback implements Callback<Task> {
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<HabitItem> {
Log.w("HabitUpdate", "Error " + error.getMessage());
}
public interface OnHabitUpdated {
void onTaskUpdated(HabitItem habit);
void onTaskUpdated(Task habit);
void onTaskUpdateFail();
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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<THabitItem extends HabitItem>
public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
extends RecyclerView.Adapter<HabitItemRecyclerViewAdapter.ViewHolder>
implements FlowContentObserver.OnSpecificModelStateChangedListener {
@ -58,6 +56,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
private Class<ViewHolder<THabitItem>> viewHolderClass;
List<THabitItem> contents;
Class<THabitItem> taskClass;
String taskType;
private ObservableArrayList<THabitItem> observableContent;
FlowContentObserver observer;
Context context;
@ -67,13 +66,13 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
private RecyclerView.Adapter<ViewHolder> parentAdapter;
public HabitItemRecyclerViewAdapter(Class<THabitItem> newTaskClass, int layoutResource, Class<ViewHolder<THabitItem>> viewHolderClass, Context newContext) {
this(newTaskClass, layoutResource, viewHolderClass, newContext, null);
public HabitItemRecyclerViewAdapter(String taskType, Class<THabitItem> newTaskClass, int layoutResource, Class<ViewHolder<THabitItem>> viewHolderClass, Context newContext) {
this(taskType, newTaskClass, layoutResource, viewHolderClass, newContext, null);
}
public HabitItemRecyclerViewAdapter(Class<THabitItem> newTaskClass, int layoutResource, Class<ViewHolder<THabitItem>> viewHolderClass,
public HabitItemRecyclerViewAdapter(String taskType, Class<THabitItem> newTaskClass, int layoutResource, Class<ViewHolder<THabitItem>> viewHolderClass,
Context newContext, final ObservableArrayList<THabitItem> content) {
this.taskType = taskType;
this.context = newContext;
this.taskClass = newTaskClass;
observableContent = content;
@ -185,7 +184,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
@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<THabitItem extends HabitItem>
ViewHelper.SetBackgroundTint(view, view.getResources().getColor(color));
}
public abstract class ViewHolder<THabitItem extends HabitItem> extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
public abstract class ViewHolder<THabitItem extends Task> extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
@InjectView(R.id.card_view)
protected CardView cardView;
@ -279,7 +278,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
}
public class HabitViewHolder extends ViewHolder<Habit> {
public class HabitViewHolder extends ViewHolder<Task> {
@InjectView(R.id.btnPlus)
Button btnPlus;
@ -318,14 +317,14 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
}
@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<Daily> {
public class DailyViewHolder extends ViewHolder<Task> {
@InjectView(R.id.checkBox)
CheckBox checkbox;
@ -339,14 +338,14 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
@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<ToDo> implements CompoundButton.OnCheckedChangeListener {
public class TodoViewHolder extends ViewHolder<Task> implements CompoundButton.OnCheckedChangeListener {
@InjectView(R.id.checkBox)
CheckBox checkbox;
@ -362,7 +361,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends HabitItem>
}
@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<THabitItem extends HabitItem>
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
{

View file

@ -104,8 +104,6 @@ public class TaskRecyclerViewFragment extends Fragment implements View.OnClickLi
fragment.SetInnerAdapter(adapter, classType,showFloatingButton);
Log.d("TaskRecyclerViewFragment", "newInstance");
return fragment;
}

View file

@ -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) {}
}

View file

@ -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<Daily> dailyCallback) {
this.apiService.getDaily(dailyId,dailyCallback);
public void getTask(String dailyId, Callback<Task> 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<Habit> 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<ToDo> 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<Reward> 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<Daily> 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<Habit> 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<ToDo> toDoCallback) {
this.apiService.createItem(todoItem, toDoCallback);
public void createItem(Task task, Callback<Task> 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<Habit> 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<Daily> 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<ToDo> toDoCallback) {
this.apiService.updateTask(todoId, todoItem, toDoCallback);
public void updateItem(String taskId, Task task, Callback<Task> taskCallback) {
this.apiService.updateTask(taskId, task, taskCallback);
}
/**

View file

@ -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<HabitRPGUser> habitRPGUserCallback);
@GET("/user/tasks/{id}")
void getHabit(@Path("id") String id, Callback<Habit> habitItemCallback);
@GET("/user/tasks/{id}")
void getDaily(@Path("id") String id, Callback<Daily> habitItemCallback);
@GET("/user/tasks/{id}")
void getToDo(@Path("id") String id, Callback<ToDo> habitItemCallback);
@GET("/user/tasks/{id}")
void getReward(@Path("id") String id, Callback<Reward> habitItemCallback);
@GET("/user/tasks/{id}")
void getTask(@Path("id") String id, Callback<Task> habitItemCallback);
@POST("/user/tasks/{id}/{direction}")
void postTaskDirection(@Path("id") String id, @Path("direction") String direction, Callback<TaskDirectionData> taskDirectionCallback);
@POST("/user/tasks")
void createItem(@Body Habit item, Callback<Habit> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body Daily item, Callback<Daily> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body ToDo item, Callback<ToDo> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body Reward item, Callback<Reward> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body Task item, Callback<Task> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Habit item, Callback<Habit> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Daily item, Callback<Daily> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body ToDo item, Callback<ToDo> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Reward item, Callback<Reward> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Task item, Callback<Task> habitItemCallback);
@DELETE("/user/tasks/{id}")

View file

@ -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<T extends HabitItem> implements Callback<T> {
public class HabitItemCallback<T extends Task> implements Callback<T> {
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));
}

View file

@ -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<Tags>{
public class TagsAdapter extends TypeAdapter<List<TaskTag>>{
@Override
public void write(JsonWriter out, Tags value) throws IOException {
List<String> list = value.getTags();
public void write(JsonWriter out, List<TaskTag> 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<String> tags = new ArrayList<>();
public List<TaskTag> read(JsonReader in) throws IOException {
List<TaskTag> tags = new ArrayList<>();
List<Tag> allTags = new Select()
.from(Tag.class)
.queryList();
boolean isClosed=false;
do {
switch(in.peek()) {
@ -41,11 +39,18 @@ public class TagsAdapter extends TypeAdapter<Tags>{
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<Tags>{
default:
}
} while(!isClosed);
return new Tags(tags);
return tags;
}
}

View file

@ -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<Daily> dailys;
List<ToDo> todos;
List<Task> dailys;
List<Task> todos;
List<Reward> rewards;
List<Habit> habits;
List<Task> habits;
List<Tag> tags;
@Column
@ -82,11 +81,11 @@ public class HabitRPGUser extends BaseModel {
this.id = id;
}
public void setDailys(List<Daily> dailys) {
public void setDailys(List<Task> dailys) {
this.dailys = dailys;
}
public void setTodos(List<ToDo> todos) {
public void setTodos(List<Task> todos) {
this.todos = todos;
}
@ -94,7 +93,7 @@ public class HabitRPGUser extends BaseModel {
this.rewards = rewards;
}
public void setHabits(List<Habit> habits) {
public void setHabits(List<Task> 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<Habit> getHabits() {
public List<Task> 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<Daily> getDailys() {
public List<Task> 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<ToDo> getTodos() {
public List<Task> 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<Tag> getTags() {
if(tags == null) {
tags = new Select()

View file

@ -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<TaskTag> tasks;
public Tag() {
this(null,null);
}
@ -30,6 +38,14 @@ public class Tag extends BaseModel{
this.setName(name);
}
public List<TaskTag> getTasks() {
if(tasks == null) {
tasks = new Select()
.from(TaskTag.class)
.queryList();
}
return tasks;
}
public String getName() {
return name;

View file

@ -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<ChecklistItem> 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<ChecklistItem>();
}
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<this.checklistItems.size() && !flag; i++) {
ChecklistItem it = this.checklistItems.get(i);
if(it.getId().equals(id)) {
it.setCompleted(!it.getCompleted());
flag=true;
}
}
}
public List<ChecklistItem> getItems() {return checklistItems;};
public List<ChecklistItem> 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;
}
}

View file

@ -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<Checklist> queenModelContainer;
saveForeignKeyModel = false)
ForeignKeyContainer<Task> task;
*/
public ChecklistItem() {
this(null,null);
}

View file

@ -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.<br/>
* 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;
}
}

View file

@ -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;
}
}

View file

@ -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<String> getTags() {
return tags.getTags();
}
/**
* @param tags the tagsId to set
*/
public void setTags(List<String> tags) {
this.tags.setTags(tags);
}
public boolean isTagged(List<String> 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.<br>
* 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;
}
}

View file

@ -1,9 +0,0 @@
package com.magicmicky.habitrpgwrapper.lib.models.tasks;
public enum HabitType {
habit,
reward,
todo,
daily
}

View file

@ -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;
}
}
}

View file

@ -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<String> tags;
public Tags() {
this.tags = new ArrayList<>();
}
public Tags(List<String> tags) {
this.tags = tags;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
}

View file

@ -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.<br/>
* 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;
}
}

View file

@ -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> tag;
@Column
@ForeignKey(references = {@ForeignKeyReference(columnName = "task_id",
columnType = String.class,
foreignColumnName = "id")})
public ForeignKeyContainer<Task> 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);
}
}

View file

@ -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;
}
}

View file

@ -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;
/**