mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 20:59:00 +00:00
support checking off checklist items in RYA
This commit is contained in:
parent
bcdd016690
commit
4607e4cc7b
3 changed files with 81 additions and 34 deletions
|
|
@ -6,7 +6,7 @@
|
|||
android:orientation="horizontal" android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:minHeight="@dimen/checklist_item_min_height">
|
||||
<RelativeLayout
|
||||
<FrameLayout
|
||||
android:id="@+id/checkBoxHolder"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="match_parent">
|
||||
|
|
@ -14,11 +14,10 @@
|
|||
android:id="@+id/checkBox"
|
||||
android:layout_width="@dimen/checkbox_size"
|
||||
android:layout_height="@dimen/checkbox_size"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:button="@drawable/checklist_checkbox"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
</RelativeLayout>
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
||||
<net.pherth.android.emoji_library.EmojiTextView
|
||||
android:id="@+id/checkedTextView"
|
||||
style="@style/Body2"
|
||||
|
|
|
|||
|
|
@ -2,33 +2,52 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="60dp"
|
||||
android:gravity="center_vertical"
|
||||
android:elevation="2dp"
|
||||
android:layout_margin="4dp"
|
||||
android:background="@drawable/layout_rounded_bg">
|
||||
<FrameLayout
|
||||
android:id="@+id/checkBoxHolder"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:background="@color/task_border_gray" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="@dimen/checkbox_size"
|
||||
android:layout_height="@dimen/checkbox_size"
|
||||
android:layout_gravity="center"
|
||||
android:button="@drawable/daily_checkbox"
|
||||
android:gravity="center" />
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:id="@+id/text_view"
|
||||
android:background="@drawable/layout_rounded_bg"
|
||||
android:orientation="vertical"
|
||||
android:padding="0dp">
|
||||
<LinearLayout
|
||||
android:id="@+id/taskHolder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="12dp" />
|
||||
android:layout_margin="0dp"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="60dp">
|
||||
<FrameLayout
|
||||
android:id="@+id/checkBoxHolder"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:background="@color/task_border_gray" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="@dimen/checkbox_size"
|
||||
android:layout_height="@dimen/checkbox_size"
|
||||
android:layout_gravity="center"
|
||||
android:button="@drawable/daily_checkbox"
|
||||
android:gravity="center" />
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:id="@+id/text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="12dp" />
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:id="@+id/checklistDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray_500" />
|
||||
<LinearLayout
|
||||
android:id="@id/checklistView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -7,6 +7,7 @@ import android.os.Build;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -15,6 +16,7 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.data.TaskRepository;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.tasks.ChecklistItem;
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -33,6 +35,7 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
static boolean isDisplaying = false;
|
||||
|
||||
private final List<Task> tasks;
|
||||
private final TaskRepository taskRepository;
|
||||
private UserRepository userRepository;
|
||||
|
||||
@BindView(R.id.yesterdailies_list)
|
||||
|
|
@ -41,9 +44,10 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
@BindColor(R.color.task_gray)
|
||||
int taskGray;
|
||||
|
||||
private YesterdailyDialog(@NonNull Context context, UserRepository userRepository, List<Task> tasks) {
|
||||
private YesterdailyDialog(@NonNull Context context, UserRepository userRepository, TaskRepository taskRepository, List<Task> tasks) {
|
||||
super(context);
|
||||
this.userRepository = userRepository;
|
||||
this.taskRepository = taskRepository;
|
||||
this.tasks = tasks;
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
|
@ -77,10 +81,26 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
taskView.setClipToOutline(true);
|
||||
}
|
||||
configureTaskView(taskView, task);
|
||||
taskView.setOnClickListener(v -> {
|
||||
View taskContainer = taskView.findViewById(R.id.taskHolder);
|
||||
taskContainer.setOnClickListener(v -> {
|
||||
task.completed = !task.completed;
|
||||
configureTaskView(taskView, task);
|
||||
});
|
||||
|
||||
if (task.checklist.size() > 0) {
|
||||
View checklistDivider = taskView.findViewById(R.id.checklistDivider);
|
||||
ViewGroup checklistContainer = taskView.findViewById(R.id.checklistView);
|
||||
for (ChecklistItem item : task.checklist) {
|
||||
View checklistView = inflater.inflate(R.layout.checklist_item_row, yesterdailiesList, false);
|
||||
configureChecklistView(checklistView, item);
|
||||
checklistView.setOnClickListener(v -> {
|
||||
item.setCompleted(!item.getCompleted());
|
||||
taskRepository.scoreChecklistItem(task.getId(), item.getId()).subscribe(task1 -> {}, RxErrorHandler.handleEmptyError());
|
||||
configureChecklistView(checklistView, item);
|
||||
});
|
||||
checklistContainer.addView(checklistView);
|
||||
}
|
||||
}
|
||||
CheckBox checkBox = (CheckBox) taskView.findViewById(R.id.checkBox);
|
||||
checkBox.setEnabled(false);
|
||||
checkBox.setClickable(false);
|
||||
|
|
@ -88,6 +108,15 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
}
|
||||
}
|
||||
|
||||
private void configureChecklistView(View checklistView, ChecklistItem item) {
|
||||
CheckBox checkbox = (CheckBox) checklistView.findViewById(R.id.checkBox);
|
||||
checkbox.setChecked(item.getCompleted());
|
||||
View checkboxHolder = checklistView.findViewById(R.id.checkBoxHolder);
|
||||
checkboxHolder.setBackgroundResource(R.color.gray_700);
|
||||
TextView textView = (TextView) checklistView.findViewById(R.id.checkedTextView);
|
||||
textView.setText(item.getText());
|
||||
}
|
||||
|
||||
private void configureTaskView(View taskView, Task task) {
|
||||
boolean completed = !task.isDisplayedActive();
|
||||
CheckBox checkbox = (CheckBox) taskView.findViewById(R.id.checkBox);
|
||||
|
|
@ -129,7 +158,7 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
return;
|
||||
}
|
||||
if (tasks.size() > 0) {
|
||||
showDialog(activity, userRepository, tasks);
|
||||
showDialog(activity, userRepository, taskRepository, tasks);
|
||||
} else {
|
||||
userRepository.runCron();
|
||||
}
|
||||
|
|
@ -137,11 +166,11 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
}
|
||||
}
|
||||
|
||||
private static void showDialog(Activity activity, UserRepository userRepository, List<Task> tasks) {
|
||||
private static void showDialog(Activity activity, UserRepository userRepository, TaskRepository taskRepository, List<Task> tasks) {
|
||||
if (activity.isFinishing()) {
|
||||
return;
|
||||
}
|
||||
YesterdailyDialog dialog = new YesterdailyDialog(activity, userRepository, tasks);
|
||||
YesterdailyDialog dialog = new YesterdailyDialog(activity, userRepository, taskRepository, tasks);
|
||||
dialog.show();
|
||||
isDisplaying = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue