basic group plan support

This commit is contained in:
Phillip Thelen 2017-02-26 12:07:16 +01:00
parent 18770e0083
commit dc5beef190
13 changed files with 146 additions and 6 deletions

View file

@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.habitrpg.android.habitica"
android:versionCode="156"
android:versionName="0.0.37.1"
android:versionCode="158"
android:versionName="0.0.37.2"
android:screenOrientation="portrait"
android:installLocation="auto" >

View file

@ -0,0 +1 @@
ALTER TABLE Task ADD COLUMN group_id varchar(255);

View file

@ -67,6 +67,14 @@
android:maxLines="3"
tools:text="Notes" />
<TextView
android:id="@+id/approvalRequiredTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Caption4"
android:text="@string/pending_approval"
/>
<LinearLayout
android:id="@+id/taskIconWrapper"
android:layout_width="match_parent"

View file

@ -69,6 +69,14 @@
android:maxLines="3"
tools:text="Notes"/>
<TextView
android:id="@+id/approvalRequiredTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Caption4"
android:text="@string/pending_approval"
/>
<LinearLayout
android:id="@+id/taskIconWrapper"
android:layout_width="match_parent"

View file

@ -47,6 +47,14 @@
android:layout_height="wrap_content"
tools:text="Notes"/>
<TextView
android:id="@+id/approvalRequiredTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Caption4"
android:text="@string/pending_approval"
/>
</LinearLayout>
<Button

View file

@ -67,6 +67,14 @@
android:maxLines="3"
tools:text="Notes" />
<TextView
android:id="@+id/approvalRequiredTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Caption4"
android:text="@string/pending_approval"
/>
<LinearLayout
android:id="@+id/taskIconWrapper"
android:layout_width="match_parent"

View file

@ -7,5 +7,5 @@ public class HabitDatabase {
public static final String NAME = "Habitica";
public static final int VERSION = 32;
public static final int VERSION = 33;
}

View file

@ -421,8 +421,20 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
throwable -> {
}
);
if (task.isGroupTask()) {
new AlertDialog.Builder(this)
.setTitle(R.string.group_tasks_edit_title)
.setMessage(R.string.group_tasks_edit_description)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
finish();
})
.show();
}
}
@Override
protected void injectActivity(AppComponent component) {
component.inject(this);

View file

@ -60,6 +60,9 @@ public abstract class BaseTaskViewHolder extends RecyclerView.ViewHolder impleme
@BindView(R.id.taskIconWrapper)
LinearLayout taskIconWrapper;
@BindView(R.id.approvalRequiredTextField)
TextView approvalRequiredTextView;
boolean disabled;
public BaseTaskViewHolder(View itemView) {
@ -134,8 +137,17 @@ public abstract class BaseTaskViewHolder extends RecyclerView.ViewHolder impleme
if (this.taskIconWrapper != null) {
this.taskIconWrapper.setVisibility(getTaskIconWrapperIsVisible() ? View.VISIBLE : View.GONE);
}
if (task.isPendingApproval()) {
approvalRequiredTextView.setVisibility(View.VISIBLE);
} else {
approvalRequiredTextView.setVisibility(View.GONE);
}
}
protected void configureSpecialTaskTextView(Task task) {
if (this.specialTaskTextView != null) {
this.specialTaskTextView.setVisibility(View.INVISIBLE);

View file

@ -56,8 +56,13 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
@Override
public void bindHolder(Task newTask, int position) {
super.bindHolder(newTask, position);
this.checkbox.setChecked(this.task.completed);
if (this.shouldDisplayAsActive()) {
boolean completed = this.task.completed;
if (task.isPendingApproval()) {
completed = false;
}
this.checkbox.setChecked(completed);
if (this.shouldDisplayAsActive() && !task.isPendingApproval()) {
this.checkboxHolder.setBackgroundResource(this.task.getLightTaskColor());
} else {
this.checkboxHolder.setBackgroundColor(this.taskGray);
@ -77,6 +82,7 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
this.rightBorderView.setBackgroundColor(this.taskGray);
}
}
}
abstract public Boolean shouldDisplayAsActive();

View file

@ -58,6 +58,11 @@ public class Task extends BaseModel {
public Date dateCreated;
@Column
public int position;
@Column
@ForeignKey(references = {@ForeignKeyReference(columnName = "group_id",
columnType = String.class,
foreignColumnName = "task_id")})
public TaskGroupPlan group;
//Habits
@Column
public Boolean up, down;
@ -439,8 +444,13 @@ public class Task extends BaseModel {
checklist = null;
reminders = null;
if (repeat != null)
if (repeat != null) {
repeat.task_id = this.id;
}
if (group != null) {
group.task_id = this.id;
}
super.save();
@ -633,4 +643,22 @@ public class Task extends BaseModel {
EventBus.getDefault().post(event);
super.delete();
}
public boolean isGroupTask() {
if (group != null) {
if (group.approvalRequired) {
return true;
}
}
return false;
}
public boolean isPendingApproval() {
if (group != null) {
if (group.approvalRequired && group.approvalRequested && !group.approvalApproved) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,23 @@
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.ModelContainer;
import com.raizlabs.android.dbflow.annotation.NotNull;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;
@ModelContainer
@Table(databaseName = HabitDatabase.NAME)
public class TaskGroupPlan extends BaseModel {
@Column
@PrimaryKey
@NotNull
String task_id;
@Column
public boolean approvalRequested, approvalApproved, approvalRequired;
}

View file

@ -0,0 +1,26 @@
package com.magicmicky.habitrpgwrapper.lib.utils;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskGroupPlan;
import java.lang.reflect.Type;
public class TaskGroupPlanDeserializer implements JsonDeserializer<TaskGroupPlan> {
@Override
public TaskGroupPlan deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
TaskGroupPlan group = new TaskGroupPlan();
JsonObject object = json.getAsJsonObject();
JsonObject approvalObject = object.getAsJsonObject("approval");
group.approvalRequested = approvalObject.getAsJsonPrimitive("requested").getAsBoolean();
group.approvalApproved = approvalObject.getAsJsonPrimitive("approved").getAsBoolean();
group.approvalRequired = approvalObject.getAsJsonPrimitive("required").getAsBoolean();
return null;
}
}