From c57aa4d608b9fdba678e9ddfd0ed89ac7d4404e0 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 27 Apr 2020 13:52:15 -0500 Subject: [PATCH] Indent subtasks in share output --- .../java/com/todoroo/andlib/sql/Field.java | 19 +++++++++ .../astrid/activity/TaskListFragment.java | 18 ++++++-- .../com/todoroo/astrid/api/IdListFilter.java | 42 +++++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/todoroo/astrid/api/IdListFilter.java diff --git a/app/src/main/java/com/todoroo/andlib/sql/Field.java b/app/src/main/java/com/todoroo/andlib/sql/Field.java index 2a3a9af06..f03bf09a1 100644 --- a/app/src/main/java/com/todoroo/andlib/sql/Field.java +++ b/app/src/main/java/com/todoroo/andlib/sql/Field.java @@ -10,6 +10,9 @@ import static com.todoroo.andlib.sql.SqlConstants.LEFT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.RIGHT_PARENTHESIS; import static com.todoroo.andlib.sql.SqlConstants.SPACE; +import com.google.common.base.Joiner; +import java.util.List; + public class Field extends DBObject { protected Field(String expression) { @@ -63,4 +66,20 @@ public class Field extends DBObject { } }; } + + public Criterion in(List entries) { + final Field field = this; + return new Criterion(Operator.in) { + @Override + protected void populate(StringBuilder sb) { + sb.append(field) + .append(SPACE) + .append(Operator.in) + .append(SPACE) + .append(LEFT_PARENTHESIS) + .append(Joiner.on(",").join(entries)) + .append(RIGHT_PARENTHESIS); + } + }; + } } diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index 7eb0457db..0c71b3fff 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -7,11 +7,13 @@ package com.todoroo.astrid.activity; import static android.app.Activity.RESULT_OK; +import static com.google.common.base.Strings.padStart; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.transform; import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread; import static org.tasks.activities.RemoteListPicker.newRemoteListSupportPicker; import static org.tasks.caldav.CaldavCalendarSettingsActivity.EXTRA_CALDAV_CALENDAR; +import static org.tasks.db.DbUtils.collect; import android.app.Activity; import android.content.BroadcastReceiver; @@ -58,6 +60,7 @@ import com.todoroo.astrid.adapter.TaskAdapterProvider; import com.todoroo.astrid.api.CaldavFilter; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.GtasksFilter; +import com.todoroo.astrid.api.IdListFilter; import com.todoroo.astrid.api.SearchFilter; import com.todoroo.astrid.api.TagFilter; import com.todoroo.astrid.core.BuiltInFilterExposer; @@ -488,7 +491,7 @@ public final class TaskListFragment extends InjectingFragment ((PlaceFilter) filter).openMap(context); return true; case R.id.menu_share: - send(transform(taskDao.fetchTasks(preferences, filter), TaskContainer::getTask)); + send(taskDao.fetchTasks(preferences, filter)); return true; default: return onOptionsItemSelected(item); @@ -752,7 +755,10 @@ public final class TaskListFragment extends InjectingFragment recyclerAdapter.notifyDataSetChanged(); return true; case R.id.menu_share: - send(taskDao.fetch(taskAdapter.getSelected())); + send( + collect( + taskAdapter.getSelected(), + ids -> taskDao.fetchTasks(preferences, new IdListFilter(ids)))); return true; case R.id.delete: dialogBuilder @@ -775,13 +781,17 @@ public final class TaskListFragment extends InjectingFragment } } - private void send(List tasks) { + private void send(List tasks) { Intent intent = new Intent(Intent.ACTION_SEND); String output = Joiner.on("\n") .join( transform( - tasks, t -> String.format("%s %s", t.isCompleted() ? "☑" : "☐", t.getTitle()))); + tasks, t -> { + String checkbox = t.isCompleted() ? "☑" : "☐"; + checkbox = padStart(checkbox, 1 + t.getIndent() * 3, ' '); + return String.format("%s %s", checkbox, t.getTitle()); + })); intent.putExtra(Intent.EXTRA_SUBJECT, filter.listingTitle); intent.putExtra(Intent.EXTRA_TEXT, output); intent.setType("text/plain"); diff --git a/app/src/main/java/com/todoroo/astrid/api/IdListFilter.java b/app/src/main/java/com/todoroo/astrid/api/IdListFilter.java new file mode 100644 index 000000000..762dcd104 --- /dev/null +++ b/app/src/main/java/com/todoroo/astrid/api/IdListFilter.java @@ -0,0 +1,42 @@ +package com.todoroo.astrid.api; + +import android.os.Parcel; +import com.todoroo.andlib.sql.Join; +import com.todoroo.andlib.sql.QueryTemplate; +import com.todoroo.astrid.data.Task; +import java.util.List; +import org.tasks.data.Tag; + +public class IdListFilter extends Filter { + + /** Parcelable Creator Object */ + public static final Creator CREATOR = + new Creator() { + + /** {@inheritDoc} */ + @Override + public IdListFilter createFromParcel(Parcel source) { + IdListFilter item = new IdListFilter(); + item.readFromParcel(source); + return item; + } + + /** {@inheritDoc} */ + @Override + public IdListFilter[] newArray(int size) { + return new IdListFilter[size]; + } + }; + + private IdListFilter() {} + + public IdListFilter(Listids) { + super("", getQueryTemplate(ids)); + } + + private static QueryTemplate getQueryTemplate(List ids) { + return new QueryTemplate() + .join(Join.left(Tag.TABLE, Tag.TASK.eq(Task.ID))) + .where(Task.ID.in(ids)); + } +}