Skip to content

Commit

Permalink
Open first instance of newly created task, fixes #862 (#866)
Browse files Browse the repository at this point in the history
The Task Editor used to launch the details view for newly created tasks using the task Uri. In general this works, but it fails when the details view uses the Uri with the notification service (because that currently requires an instance Uri). So to fix this we load the first instance after creating a new task and use that one to show the details view.
  • Loading branch information
dmfs committed Oct 9, 2019
1 parent 32c1f82 commit dedb8f9
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def jems_version = '1.24'
def contentpal_version = '0.5'
def contentpal_version = '0.6'
def androidx_test_runner_version = '1.1.1'

ext.deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.dmfs.provider.tasks.utils;

import org.dmfs.jems.optional.Optional;
import org.dmfs.jems.optional.adapters.SinglePresent;
import org.dmfs.jems.procedure.Procedure;
import org.dmfs.jems.single.Single;

Expand All @@ -30,7 +32,7 @@
@Deprecated
public final class With<T> implements Procedure<Procedure<T>>
{
private final Single<T> mValue;
private final Optional<T> mValue;


public With(T value)
Expand All @@ -40,6 +42,12 @@ public With(T value)


public With(Single<T> value)
{
this(new SinglePresent<>(value));
}


public With(Optional<T> value)
{
mValue = value;
}
Expand All @@ -48,6 +56,9 @@ public With(Single<T> value)
@Override
public void process(Procedure<T> delegate)
{
delegate.process(mValue.value());
if (mValue.isPresent())
{
delegate.process(mValue.value());
}
}
}
33 changes: 30 additions & 3 deletions opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
Expand All @@ -41,10 +42,20 @@
import android.widget.Toast;

import org.dmfs.android.bolts.color.elementary.ValueColor;
import org.dmfs.android.contentpal.predicates.AllOf;
import org.dmfs.android.contentpal.predicates.EqArg;
import org.dmfs.android.contentpal.predicates.ReferringTo;
import org.dmfs.android.contentpal.references.RowUriReference;
import org.dmfs.android.contentpal.rowsets.Frozen;
import org.dmfs.android.contentpal.rowsets.QueryRowSet;
import org.dmfs.android.retentionmagic.SupportFragment;
import org.dmfs.android.retentionmagic.annotations.Parameter;
import org.dmfs.android.retentionmagic.annotations.Retain;
import org.dmfs.jems.optional.adapters.First;
import org.dmfs.opentaskspal.readdata.Id;
import org.dmfs.opentaskspal.views.InstancesView;
import org.dmfs.provider.tasks.AuthorityUtil;
import org.dmfs.provider.tasks.utils.With;
import org.dmfs.tasks.contract.TaskContract;
import org.dmfs.tasks.contract.TaskContract.TaskLists;
import org.dmfs.tasks.contract.TaskContract.Tasks;
Expand Down Expand Up @@ -722,9 +733,25 @@ public void saveAndExit()
activity.finish();
if (isNewTask)
{
activity.startActivity(
new Intent(Intent.ACTION_VIEW, mTaskUri)
.putExtra(ViewTaskActivity.EXTRA_COLOR, mListColor));
// When creating a new task we're dealing with a task URI, for now we start the details view with an instance URI though
// so get the first instance of the new task and open it
new With<>(
new First<>(
new Frozen<>(
new QueryRowSet<>(
new InstancesView<>(mAuthority, activity.getContentResolver().acquireContentProviderClient(mAuthority)),
Id.PROJECTION,
new AllOf<>(
new EqArg<>(TaskContract.Instances.DISTANCE_FROM_CURRENT, 0),
new ReferringTo<>(TaskContract.Instances.TASK_ID, new RowUriReference<Tasks>(mTaskUri)))))))
.process(
snapShot ->
activity.startActivity(
new Intent(
Intent.ACTION_VIEW,
ContentUris.withAppendedId(TaskContract.Instances.getContentUri(mAuthority),
new Id(snapShot.values()).value()))
.putExtra(ViewTaskActivity.EXTRA_COLOR, mListColor)));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void onReceive(Context context, Intent intent)
new QueryRowSet<>(
new TaskListsView(authority, context.getContentResolver().acquireContentProviderClient(authority)),
new MultiProjection<>(TaskContract.TaskLists.ACCOUNT_NAME, TaskContract.TaskLists.ACCOUNT_TYPE),
new Not(new AnyOf(
new Not<>(new AnyOf<>(
new Joined<>(new Seq<>(
new EqArg(TaskContract.TaskLists.ACCOUNT_TYPE, TaskContract.LOCAL_ACCOUNT_TYPE)),
new EqArg<>(TaskContract.TaskLists.ACCOUNT_TYPE, TaskContract.LOCAL_ACCOUNT_TYPE)),
new Mapped<>(AccountEq::new, new Seq<>(accountManager.getAccounts()))))))))))
{
context.startActivity(accountRequestIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected void onHandleWork(@NonNull Intent intent)
TaskTitle.PROJECTION,
TaskVersion.PROJECTION,
TaskIsClosed.PROJECTION),
new EqArg(TaskContract.Instances._ID, ContentUris.parseId(instanceUri))))
new EqArg<>(TaskContract.Instances._ID, ContentUris.parseId(instanceUri))))
{
resolveAction(intent.getAction()).execute(this, contentProviderClient, snapshot.values(), instanceUri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ protected void onHandleWork(@NonNull Intent intent)
new InstancesView<>(authority, getContentResolver().acquireContentProviderClient(authority))),
new Composite<>(Id.PROJECTION, TaskVersion.PROJECTION, TaskPin.PROJECTION, TaskIsClosed.PROJECTION,
EffectiveDueDate.PROJECTION, TaskStart.PROJECTION),
new AnyOf(
new AnyOf<>(
// task is either pinned or has a notification
new EqArg(Tasks.PINNED, 1),
new In(Tasks._ID, new Mapped<>(p -> ContentUris.parseId(p.instance()), currentNotifications))))),
new EqArg<>(Tasks.PINNED, 1),
new In<>(Tasks._ID, new Mapped<>(p -> ContentUris.parseId(p.instance()), currentNotifications))))),
(o, o2) -> (int) (ContentUris.parseId(o.instance()) - ContentUris.parseId(o2.instance()))))
{
if (!diff.left().isPresent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
*
* @author Gabor Keszthelyi
*/
public final class IsProperty extends DelegatingPredicate
public final class IsProperty extends DelegatingPredicate<TaskContract.Properties>
{
public IsProperty(String mimeType)
{
super(new EqArg(TaskContract.PropertyColumns.MIMETYPE, mimeType));
super(new EqArg<>(TaskContract.PropertyColumns.MIMETYPE, mimeType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Gabor Keszthelyi
*/
public final class IsRelation extends DelegatingPredicate
public final class IsRelation extends DelegatingPredicate<TaskContract.Properties>
{
public IsRelation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
*
* @author Gabor Keszthelyi
*/
public final class TaskOnList extends DelegatingPredicate
public final class TaskOnList extends DelegatingPredicate<TaskContract.Tasks>
{
public TaskOnList(RowSnapshot<TaskContract.TaskLists> taskListRow, Predicate predicate)
public TaskOnList(RowSnapshot<TaskContract.TaskLists> taskListRow, Predicate<? super TaskContract.Tasks> predicate)
{
super(new AllOf(predicate, new ReferringTo<>(TaskContract.Tasks.LIST_ID, taskListRow)));
super(new AllOf<>(predicate, new ReferringTo<>(TaskContract.Tasks.LIST_ID, taskListRow)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.dmfs.opentaskspal.rowsets;

import androidx.annotation.NonNull;

import org.dmfs.android.contentpal.Projection;
import org.dmfs.android.contentpal.RowReference;
import org.dmfs.android.contentpal.RowSet;
Expand All @@ -27,6 +25,8 @@
import org.dmfs.android.contentpal.rowsets.QueryRowSet;
import org.dmfs.tasks.contract.TaskContract.Tasks;

import androidx.annotation.NonNull;


/**
* {@link RowSet} for the subtasks of a given task.
Expand All @@ -37,7 +37,7 @@ public final class Subtasks extends DelegatingRowSet<Tasks>
{

public Subtasks(@NonNull View<Tasks> view,
@NonNull Projection projection,
@NonNull Projection<? super Tasks> projection,
@NonNull RowReference<Tasks> parentTask)
{
super(new QueryRowSet<>(view, projection, new ReferringTo<>(Tasks.PARENT_ID, parentTask)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.dmfs.opentaskspal.tables;

import android.content.ContentProviderClient;
import androidx.annotation.NonNull;

import org.dmfs.android.contentpal.InsertOperation;
import org.dmfs.android.contentpal.Operation;
Expand All @@ -30,6 +29,8 @@
import org.dmfs.opentaskspal.predicates.TaskOnList;
import org.dmfs.tasks.contract.TaskContract;

import androidx.annotation.NonNull;


/**
* A view onto the {@link TaskContract.Tasks} table which contains only tasks from a specific task list.
Expand Down Expand Up @@ -61,23 +62,23 @@ public InsertOperation<TaskContract.Tasks> insertOperation(@NonNull UriParams ur

@NonNull
@Override
public Operation<TaskContract.Tasks> updateOperation(@NonNull UriParams uriParams, @NonNull Predicate predicate)
public Operation<TaskContract.Tasks> updateOperation(@NonNull UriParams uriParams, @NonNull Predicate<? super TaskContract.Tasks> predicate)
{
return mDelegate.updateOperation(uriParams, new TaskOnList(mTaskListRow, predicate));
}


@NonNull
@Override
public Operation<TaskContract.Tasks> deleteOperation(@NonNull UriParams uriParams, @NonNull Predicate predicate)
public Operation<TaskContract.Tasks> deleteOperation(@NonNull UriParams uriParams, @NonNull Predicate<? super TaskContract.Tasks> predicate)
{
return mDelegate.deleteOperation(uriParams, new TaskOnList(mTaskListRow, predicate));
}


@NonNull
@Override
public Operation<TaskContract.Tasks> assertOperation(@NonNull UriParams uriParams, @NonNull Predicate predicate)
public Operation<TaskContract.Tasks> assertOperation(@NonNull UriParams uriParams, @NonNull Predicate<? super TaskContract.Tasks> predicate)
{
return mDelegate.assertOperation(uriParams, new TaskOnList(mTaskListRow, predicate));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TaskListScoped(@NonNull RowSnapshot<TaskContract.TaskLists> taskListRow,

@NonNull
@Override
public Cursor rows(@NonNull UriParams uriParams, @NonNull Projection<? super TaskContract.Tasks> projection, @NonNull Predicate predicate, @NonNull Optional<String> sorting) throws RemoteException
public Cursor rows(@NonNull UriParams uriParams, @NonNull Projection<? super TaskContract.Tasks> projection, @NonNull Predicate<? super TaskContract.Tasks> predicate, @NonNull Optional<String> sorting) throws RemoteException
{
return mDelegate.rows(uriParams, projection, new TaskOnList(mTaskListRow, predicate), sorting);
}
Expand Down

0 comments on commit dedb8f9

Please sign in to comment.