Skip to content

Commit 9ddbdd0

Browse files
author
Gabor Keszthelyi
committed
Extract and re-use details screen starting code. #589
1 parent 62e6af8 commit 9ddbdd0

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.dmfs.tasks.contract.TaskContract;
5555
import org.dmfs.tasks.contract.TaskContract.TaskLists;
5656
import org.dmfs.tasks.contract.TaskContract.Tasks;
57+
import org.dmfs.tasks.detailsscreen.BasicTaskDetailsUi;
5758
import org.dmfs.tasks.model.CheckListItem;
5859
import org.dmfs.tasks.model.ContentSet;
5960
import org.dmfs.tasks.model.Model;
@@ -793,7 +794,7 @@ public void saveAndExit()
793794
activity.finish();
794795
if (isNewTask)
795796
{
796-
activity.startActivity(new Intent("android.intent.action.VIEW", mTaskUri));
797+
new BasicTaskDetailsUi(mTaskUri).show(activity);
797798
}
798799
}
799800
else

opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.dmfs.android.retentionmagic.annotations.Retain;
5353
import org.dmfs.provider.tasks.AuthorityUtil;
5454
import org.dmfs.tasks.contract.TaskContract.Tasks;
55+
import org.dmfs.tasks.detailsscreen.BasicTaskDetailsUi;
5556
import org.dmfs.tasks.groupings.AbstractGroupingFactory;
5657
import org.dmfs.tasks.groupings.ByDueDate;
5758
import org.dmfs.tasks.groupings.ByList;
@@ -203,9 +204,7 @@ protected void onCreate(Bundle savedInstanceState)
203204
{
204205
if (mShouldShowDetails && mShouldSwitchToDetail)
205206
{
206-
Intent viewTaskIntent = new Intent(Intent.ACTION_VIEW);
207-
viewTaskIntent.setData(mSelectedTaskUri);
208-
startActivity(viewTaskIntent);
207+
new BasicTaskDetailsUi(mSelectedTaskUri).show(this);
209208
mSwitchedToDetail = true;
210209
mShouldSwitchToDetail = false;
211210
mTransientState = true;
@@ -430,9 +429,7 @@ else if (forceReload)
430429

431430
// In single-pane mode, simply start the detail activity
432431
// for the selected item ID.
433-
Intent detailIntent = new Intent(Intent.ACTION_VIEW);
434-
detailIntent.setData(uri);
435-
startActivity(detailIntent);
432+
new BasicTaskDetailsUi(uri).show(this);
436433
mSwitchedToDetail = true;
437434
mShouldSwitchToDetail = false;
438435
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2017 dmfs GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.dmfs.tasks.detailsscreen;
18+
19+
import android.content.Context;
20+
import android.content.Intent;
21+
import android.net.Uri;
22+
23+
24+
/**
25+
* Basic implementation of {@link TaskDetailsUi} that starts an Activity with action VIEW and with the task Uri as data.
26+
*
27+
* @author Gabor Keszthelyi
28+
*/
29+
public final class BasicTaskDetailsUi implements TaskDetailsUi
30+
{
31+
private final Uri mTaskUri;
32+
33+
34+
public BasicTaskDetailsUi(Uri taskUri)
35+
{
36+
mTaskUri = taskUri;
37+
}
38+
39+
40+
@Override
41+
public void show(Context context)
42+
{
43+
context.startActivity(new Intent(Intent.ACTION_VIEW, mTaskUri));
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2017 dmfs GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.dmfs.tasks.detailsscreen;
18+
19+
import android.content.Context;
20+
21+
22+
/**
23+
* Represents the task details UI which can be shown.
24+
*
25+
* @author Gabor Keszthelyi
26+
*/
27+
public interface TaskDetailsUi
28+
{
29+
/**
30+
* Shows the task details.
31+
*/
32+
void show(Context context);
33+
}

0 commit comments

Comments
 (0)