mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-31 19:20:34 +00:00
improve checklist checkoff
This commit is contained in:
parent
750729c87d
commit
a85bc6e3fc
3 changed files with 24 additions and 21 deletions
|
|
@ -9,6 +9,7 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
|||
import com.habitrpg.android.habitica.models.Tag;
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirection;
|
||||
import com.habitrpg.android.habitica.models.responses.TaskScoringResult;
|
||||
import com.habitrpg.android.habitica.models.tasks.ChecklistItem;
|
||||
import com.habitrpg.android.habitica.models.tasks.RemindersItem;
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
import com.habitrpg.android.habitica.models.tasks.TaskList;
|
||||
|
|
@ -112,13 +113,16 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
|
|||
.flatMap(task -> taskChecked(user, task, up, force));
|
||||
}
|
||||
|
||||
public Observable<Task> scoreChecklistItem(String taskId, String itemId){
|
||||
public Observable<Task> scoreChecklistItem(String taskId, String itemId) {
|
||||
return apiClient.scoreChecklistItem(taskId, itemId)
|
||||
.zipWith(localRepository.getTask(taskId), (newTask, oldTask) -> {
|
||||
newTask.position = oldTask.position;
|
||||
return newTask;
|
||||
})
|
||||
.doOnNext(this.localRepository::saveTask);
|
||||
.flatMap(task -> localRepository.getTask(taskId))
|
||||
.doOnNext(task -> localRepository.executeTransaction(realm -> {
|
||||
for (ChecklistItem item : task.getChecklist()) {
|
||||
if (itemId.equals(item.getId())) {
|
||||
item.setCompleted(!item.getCompleted());
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -910,9 +910,7 @@ public class MainActivity extends BaseActivity implements TutorialView.OnTutoria
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(ChecklistCheckedCommand event) {
|
||||
checklistCheckUseCase.observable(new ChecklistCheckUseCase.RequestValues(event.task.getId(), event.item.getId()))
|
||||
.subscribe(task -> {}, error -> {
|
||||
});
|
||||
checklistCheckUseCase.observable(new ChecklistCheckUseCase.RequestValues(event.task.getId(), event.item.getId())).subscribe(task -> {}, error -> {});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ import butterknife.OnClick;
|
|||
|
||||
public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implements CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
public Boolean displayChecklist;
|
||||
static Integer expandedChecklistRow = null;
|
||||
|
||||
@BindView(R.id.checkBoxHolder)
|
||||
ViewGroup checkboxHolder;
|
||||
@BindView(R.id.checkBox)
|
||||
|
|
@ -50,7 +51,6 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
|
|||
checklistIndicatorWrapper.setClickable(true);
|
||||
checkbox.setOnCheckedChangeListener(this);
|
||||
expandCheckboxTouchArea(checkboxHolder, checkbox);
|
||||
this.displayChecklist = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -71,7 +71,7 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
|
|||
this.checklistAllTextView.setText(String.valueOf(task.getChecklist().size()));
|
||||
|
||||
this.checklistView.removeAllViews();
|
||||
this.setDisplayChecklist(this.displayChecklist);
|
||||
this.updateChecklistDisplay();
|
||||
|
||||
this.checklistIndicatorWrapper.setVisibility(task.checklist.size() == 0 ? View.GONE : View.VISIBLE);
|
||||
if (this.rightBorderView != null) {
|
||||
|
|
@ -87,11 +87,10 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
|
|||
|
||||
abstract public Boolean shouldDisplayAsActive();
|
||||
|
||||
public void setDisplayChecklist(Boolean displayChecklist) {
|
||||
this.displayChecklist = displayChecklist;
|
||||
public void updateChecklistDisplay() {
|
||||
//This needs to be a LinearLayout, as ListViews can not be inside other ListViews.
|
||||
if (this.checklistView != null) {
|
||||
if (this.displayChecklist && this.task.checklist != null) {
|
||||
if (this.shouldDisplayExpandedChecklist() && this.task.checklist != null) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
for (ChecklistItem item : this.task.checklist) {
|
||||
LinearLayout itemView = (LinearLayout) layoutInflater.inflate(R.layout.checklist_item_row, this.checklistView, false);
|
||||
|
|
@ -122,16 +121,18 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
|
|||
|
||||
@OnClick(R.id.checklistIndicatorWrapper)
|
||||
public void onChecklistIndicatorClicked() {
|
||||
if (this.displayChecklist != null) {
|
||||
this.setDisplayChecklist(!this.displayChecklist);
|
||||
} else {
|
||||
this.setDisplayChecklist(true);
|
||||
}
|
||||
if (this.displayChecklist) {
|
||||
expandedChecklistRow = this.shouldDisplayExpandedChecklist() ? null : getAdapterPosition();
|
||||
if (this.shouldDisplayExpandedChecklist()) {
|
||||
RecyclerView recyclerView = (RecyclerView) this.checklistView.getParent().getParent();
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
||||
layoutManager.scrollToPositionWithOffset(this.getAdapterPosition(), 15);
|
||||
}
|
||||
updateChecklistDisplay();
|
||||
|
||||
}
|
||||
|
||||
private boolean shouldDisplayExpandedChecklist() {
|
||||
return expandedChecklistRow != null && getAdapterPosition() == expandedChecklistRow;
|
||||
}
|
||||
|
||||
public void expandCheckboxTouchArea(final View expandedView, final View checkboxView) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue