Indent subtasks in share output

pull/996/head
Alex Baker 5 years ago
parent 82307a9d78
commit c57aa4d608

@ -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<Field> {
protected Field(String expression) {
@ -63,4 +66,20 @@ public class Field extends DBObject<Field> {
}
};
}
public <T> Criterion in(List<T> 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);
}
};
}
}

@ -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<Task> tasks) {
private void send(List<TaskContainer> 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");

@ -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<IdListFilter> CREATOR =
new Creator<IdListFilter>() {
/** {@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(List<Long>ids) {
super("", getQueryTemplate(ids));
}
private static QueryTemplate getQueryTemplate(List<Long> ids) {
return new QueryTemplate()
.join(Join.left(Tag.TABLE, Tag.TASK.eq(Task.ID)))
.where(Task.ID.in(ids));
}
}
Loading…
Cancel
Save