mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Display checklists in task list
This commit is contained in:
parent
7e1a1fa1a3
commit
a72d5f06ce
11 changed files with 179 additions and 161 deletions
|
|
@ -1,47 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:background="@android:color/background_light">
|
||||
<RelativeLayout
|
||||
android:id="@+id/RL_addItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/BT_addItem"
|
||||
android:padding="5dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_menu_send"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<com.rengwuxian.materialedittext.MaterialEditText
|
||||
android:id="@+id/ET_addItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/checklist.item.hint"
|
||||
|
||||
android:layout_toLeftOf="@id/BT_addItem"
|
||||
|
||||
android:layout_centerVertical="true"
|
||||
|
||||
android:ems="10"
|
||||
android:singleLine="true"
|
||||
|
||||
app:met_floatingLabel="normal" />
|
||||
|
||||
</RelativeLayout>
|
||||
<ListView
|
||||
android:id="@+id/LV_checklist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</ListView>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/CardText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/row_size"
|
||||
android:background="@drawable/item_background"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="0dp">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/plus"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/BT_delete"
|
||||
android:layout_width="@dimen/row_size"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@color/transparent"
|
||||
android:src="@drawable/ic_action_delete"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<CheckedTextView
|
||||
android:id="@+id/TV_title"
|
||||
style="@style/CardText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center|left"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_toLeftOf="@id/BT_delete"
|
||||
android:layout_toRightOf="@id/plus"
|
||||
android:gravity="left" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
28
Habitica/res/layout/checklist_item_row.xml
Normal file
28
Habitica/res/layout/checklist_item_row.xml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal" android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:minHeight="@dimen/checklist_item_min_height">
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="fill_parent"
|
||||
android:textColor="@color/days_black"
|
||||
android:gravity="center"/>
|
||||
<TextView
|
||||
android:id="@+id/checkedTextView"
|
||||
style="@style/CardTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:id="@+id/bottomBorderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@color/cell_separator"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -8,6 +8,9 @@
|
|||
<variable
|
||||
name="daily"
|
||||
type="Task" />
|
||||
<variable
|
||||
name="displayChecklist"
|
||||
type="Boolean" />
|
||||
</data>
|
||||
|
||||
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
|
@ -103,5 +106,21 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@color/cell_separator"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/checklistView"
|
||||
android:orientation="vertical"
|
||||
android:visibility="@{displayChecklist != null && displayChecklist ? View.VISIBLE : View.GONE}" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:background="@color/checklist_separator"
|
||||
android:visibility="@{displayChecklist != null && displayChecklist ? View.VISIBLE : View.GONE}" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@color/cell_separator"
|
||||
android:visibility="@{displayChecklist != null && displayChecklist ? View.VISIBLE : View.GONE}" />
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
|
@ -8,6 +8,9 @@
|
|||
<variable
|
||||
name="todo"
|
||||
type="Task" />
|
||||
<variable
|
||||
name="displayChecklist"
|
||||
type="Boolean" />
|
||||
</data>
|
||||
|
||||
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
|
@ -23,7 +26,7 @@
|
|||
android:id="@+id/checkBox"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="fill_parent"
|
||||
android:checked="@{todo.completed}"
|
||||
android:checked="@{todo.getCompleted}"
|
||||
app:backgroundColor="@{todo.getLightTaskColor}"
|
||||
android:gravity="center"/>
|
||||
<RelativeLayout
|
||||
|
|
@ -98,5 +101,21 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@color/cell_separator"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/checklistView"
|
||||
android:orientation="vertical"
|
||||
android:visibility="@{displayChecklist != null && displayChecklist ? View.VISIBLE : View.GONE}" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:background="@color/checklist_separator"
|
||||
android:visibility="@{displayChecklist != null && displayChecklist ? View.VISIBLE : View.GONE}" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@color/cell_separator"
|
||||
android:visibility="@{displayChecklist != null && displayChecklist ? View.VISIBLE : View.GONE}" />
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
|
@ -10,9 +10,9 @@
|
|||
<color name="brand">@color/brand_100</color>
|
||||
|
||||
<!-- HabitRPG task color -->
|
||||
<color name="worst_100">#E6B8AF</color>
|
||||
<color name="worst_50">#c96652</color>
|
||||
<color name="worst_10">#c96652</color>
|
||||
<color name="worst_100">#a13f44</color>
|
||||
<color name="worst_50">#a1334d</color>
|
||||
<color name="worst_10">#a10013</color>
|
||||
|
||||
<color name="worse_100">#FF6165</color>
|
||||
<color name="worse_50">#F74E52</color>
|
||||
|
|
@ -93,4 +93,5 @@
|
|||
<color name="checkbox_tint_color">#ffd8dcdd</color>
|
||||
|
||||
<color name="cell_separator">#c3c2c6</color>
|
||||
<color name="checklist_separator">#ededed</color>
|
||||
</resources>
|
||||
|
|
@ -38,4 +38,5 @@
|
|||
<dimen name="hairline_height">0.5dp</dimen>
|
||||
<dimen name="checklist_divider_width">14dp</dimen>
|
||||
<dimen name="checklist_wrapper_width">36dp</dimen>
|
||||
<dimen name="checklist_item_min_height">50dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
/*
|
||||
* This class is useful for using inside of ListView that needs to have checkable items.
|
||||
*/
|
||||
public class CheckableLinearLayout extends LinearLayout implements Checkable {
|
||||
private CheckedTextView _checkbox;
|
||||
|
||||
public CheckableLinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
// find checked text view
|
||||
|
||||
View v = findViewById(R.id.TV_title);
|
||||
|
||||
if (v instanceof CheckedTextView) {
|
||||
_checkbox = (CheckedTextView) v;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return _checkbox != null ? _checkbox.isChecked() : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {
|
||||
if (_checkbox != null) {
|
||||
_checkbox.setChecked(checked);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggle() {
|
||||
if (_checkbox != null) {
|
||||
|
||||
_checkbox.toggle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ import com.habitrpg.android.habitica.events.HabitScoreEvent;
|
|||
import com.habitrpg.android.habitica.events.TaskLongPressedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskSaveEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskTappedEvent;
|
||||
import com.habitrpg.android.habitica.events.TodoCheckedEvent;
|
||||
import com.habitrpg.android.habitica.events.TaskCheckedEvent;
|
||||
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
|
|
@ -37,7 +37,6 @@ import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
|||
import com.habitrpg.android.habitica.ui.adapter.HabitItemRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.TaskRecyclerViewFragment;
|
||||
import com.instabug.wrapper.support.activity.InstabugAppCompatActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ContentResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
|
||||
|
|
@ -253,8 +252,9 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
showSnackbar("LongPress: " + event.Task.text);
|
||||
}
|
||||
|
||||
public void onEvent(TodoCheckedEvent event) {
|
||||
showSnackbar("ToDo Checked= " + event.ToDo.getText(), true);
|
||||
public void onEvent(TaskCheckedEvent event) {
|
||||
showSnackbar("ToDo Checked= " + event.Task.getText(), true);
|
||||
mAPIHelper.updateTaskDirection(event.Task.getId(), event.Task.getCompleted() ? TaskDirection.down : TaskDirection.up, new TaskScoringCallback(this, event.Task.getId()));
|
||||
}
|
||||
|
||||
public void onEvent(HabitScoreEvent event) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
|||
/**
|
||||
* Created by Negue on 11.07.2015.
|
||||
*/
|
||||
public class TodoCheckedEvent {
|
||||
public Task ToDo;
|
||||
public class TaskCheckedEvent {
|
||||
public Task Task;
|
||||
}
|
||||
|
|
@ -14,9 +14,10 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
|
@ -28,8 +29,9 @@ import com.habitrpg.android.habitica.events.BuyRewardTappedEvent;
|
|||
import com.habitrpg.android.habitica.events.HabitScoreEvent;
|
||||
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.events.TaskCheckedEvent;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
|
|
@ -52,6 +54,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
private Class<ViewHolder<THabitItem>> viewHolderClass;
|
||||
List<THabitItem> contents;
|
||||
Class<THabitItem> taskClass;
|
||||
Integer displayedChecklist = null;
|
||||
String taskType;
|
||||
private ObservableArrayList<THabitItem> observableContent;
|
||||
FlowContentObserver observer;
|
||||
|
|
@ -180,6 +183,11 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
Task item = contents.get(position);
|
||||
|
||||
holder.bindHolder(item, position);
|
||||
|
||||
if (this.displayedChecklist != null && ChecklistedViewHolder.class.isAssignableFrom(holder.getClass())) {
|
||||
ChecklistedViewHolder checklistedHolder = (ChecklistedViewHolder) holder;
|
||||
checklistedHolder.setDisplayChecklist(this.displayedChecklist == position);
|
||||
}
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
|
@ -323,7 +331,68 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
}
|
||||
}
|
||||
|
||||
public class DailyViewHolder extends ViewHolder<Task> {
|
||||
public class ChecklistedViewHolder extends ViewHolder<Task> {
|
||||
|
||||
@InjectView(R.id.checklistView)
|
||||
LinearLayout checklistView;
|
||||
|
||||
@InjectView(R.id.checklistIndicatorWrapper)
|
||||
RelativeLayout checklistIndicatorWrapper;
|
||||
|
||||
public Boolean displayChecklist;
|
||||
|
||||
public ChecklistedViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
checklistIndicatorWrapper.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (v == checklistIndicatorWrapper) {
|
||||
if (this.displayChecklist != null) {
|
||||
this.setDisplayChecklist(!this.displayChecklist);
|
||||
} else {
|
||||
this.setDisplayChecklist(true);
|
||||
}
|
||||
} else {
|
||||
super.onClick(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(Task habitItem, int position) {
|
||||
super.bindHolder(habitItem, position);
|
||||
Boolean isClickable = false;
|
||||
if (habitItem.getChecklist() != null && habitItem.getChecklist().size() > 0) {
|
||||
isClickable = true;
|
||||
}
|
||||
checklistIndicatorWrapper.setClickable(isClickable);
|
||||
}
|
||||
|
||||
public void setDisplayChecklist(Boolean displayChecklist) {
|
||||
this.displayChecklist = displayChecklist;
|
||||
if (this.checklistView != null) {
|
||||
if (this.displayChecklist && this.Item.checklist != null) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
for (ChecklistItem item : this.Item.checklist) {
|
||||
LinearLayout itemView = (LinearLayout)layoutInflater.inflate(R.layout.checklist_item_row, null);
|
||||
CheckBox checkbox = (CheckBox) itemView.findViewById(R.id.checkBox);
|
||||
TextView textView = (TextView) itemView.findViewById(R.id.checkedTextView);
|
||||
// Populate the data into the template view using the data object
|
||||
textView.setText(item.getText());
|
||||
checkbox.setChecked(item.getCompleted());
|
||||
this.checklistView.addView(itemView);
|
||||
}
|
||||
} else {
|
||||
this.checklistView.removeAllViewsInLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DailyViewHolder extends ChecklistedViewHolder implements CompoundButton.OnCheckedChangeListener {
|
||||
@InjectView(R.id.checkBox)
|
||||
CheckBox checkbox;
|
||||
|
||||
|
|
@ -333,6 +402,8 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
super(itemView);
|
||||
|
||||
binding = DataBindingUtil.bind(itemView);
|
||||
|
||||
checkbox.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -342,9 +413,25 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
|
||||
binding.setDaily(habitItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayChecklist(Boolean displayChecklist) {
|
||||
binding.setDisplayChecklist(displayChecklist);
|
||||
super.setDisplayChecklist(displayChecklist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked != Item.getCompleted()) {
|
||||
TaskCheckedEvent event = new TaskCheckedEvent();
|
||||
event.Task = Item;
|
||||
EventBus.getDefault().post(event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TodoViewHolder extends ViewHolder<Task> implements CompoundButton.OnCheckedChangeListener {
|
||||
public class TodoViewHolder extends ChecklistedViewHolder implements CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
@InjectView(R.id.checkBox)
|
||||
CheckBox checkbox;
|
||||
|
|
@ -368,10 +455,17 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
TodoCheckedEvent event = new TodoCheckedEvent();
|
||||
event.ToDo = Item;
|
||||
if (isChecked != Item.getCompleted()) {
|
||||
TaskCheckedEvent event = new TaskCheckedEvent();
|
||||
event.Task = Item;
|
||||
EventBus.getDefault().post(event);
|
||||
}
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(event);
|
||||
@Override
|
||||
public void setDisplayChecklist(Boolean displayChecklist) {
|
||||
binding.setDisplayChecklist(displayChecklist);
|
||||
super.setDisplayChecklist(displayChecklist);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue