From 980c57a3ddf95288d8125a3857eceae513d56cc2 Mon Sep 17 00:00:00 2001 From: Gabor Keszthelyi Date: Tue, 17 Oct 2017 21:23:08 +0200 Subject: [PATCH] Extract and re-use details screen starting code. #589 --- .idea/dictionaries/dictionary.xml | 1 + .../java/org/dmfs/tasks/EditTaskFragment.java | 3 +- .../java/org/dmfs/tasks/TaskListActivity.java | 9 ++-- .../tasks/detailsscreen/TaskDetailsUi.java | 49 +++++++++++++++++++ .../java/org/dmfs/tasks/utils/Showable.java | 34 +++++++++++++ 5 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 opentasks/src/main/java/org/dmfs/tasks/detailsscreen/TaskDetailsUi.java create mode 100644 opentasks/src/main/java/org/dmfs/tasks/utils/Showable.java diff --git a/.idea/dictionaries/dictionary.xml b/.idea/dictionaries/dictionary.xml index 7db7138b1..f1900c6a3 100644 --- a/.idea/dictionaries/dictionary.xml +++ b/.idea/dictionaries/dictionary.xml @@ -2,6 +2,7 @@ opentasks + showable subtask subtasks diff --git a/opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java b/opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java index 4e0e94bae..b0c41a657 100644 --- a/opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java +++ b/opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java @@ -54,6 +54,7 @@ import org.dmfs.tasks.contract.TaskContract; import org.dmfs.tasks.contract.TaskContract.TaskLists; import org.dmfs.tasks.contract.TaskContract.Tasks; +import org.dmfs.tasks.detailsscreen.TaskDetailsUi; import org.dmfs.tasks.model.CheckListItem; import org.dmfs.tasks.model.ContentSet; import org.dmfs.tasks.model.Model; @@ -793,7 +794,7 @@ public void saveAndExit() activity.finish(); if (isNewTask) { - activity.startActivity(new Intent("android.intent.action.VIEW", mTaskUri)); + new TaskDetailsUi(mTaskUri).show(activity); } } else diff --git a/opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java b/opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java index d00963542..6f25c89f8 100644 --- a/opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java +++ b/opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java @@ -50,6 +50,7 @@ import org.dmfs.android.retentionmagic.annotations.Retain; import org.dmfs.provider.tasks.AuthorityUtil; import org.dmfs.tasks.contract.TaskContract.Tasks; +import org.dmfs.tasks.detailsscreen.TaskDetailsUi; import org.dmfs.tasks.groupings.AbstractGroupingFactory; import org.dmfs.tasks.groupings.ByDueDate; import org.dmfs.tasks.groupings.ByList; @@ -189,9 +190,7 @@ protected void onCreate(Bundle savedInstanceState) { if (mShouldShowDetails && mShouldSwitchToDetail) { - Intent viewTaskIntent = new Intent(Intent.ACTION_VIEW); - viewTaskIntent.setData(mSelectedTaskUri); - startActivity(viewTaskIntent); + new TaskDetailsUi(mSelectedTaskUri).show(this); mShouldSwitchToDetail = false; mTransientState = true; } @@ -396,9 +395,7 @@ else if (forceReload) // In single-pane mode, simply start the detail activity // for the selected item ID. - Intent detailIntent = new Intent(Intent.ACTION_VIEW); - detailIntent.setData(uri); - startActivity(detailIntent); + new TaskDetailsUi(uri).show(this); mShouldSwitchToDetail = false; } } diff --git a/opentasks/src/main/java/org/dmfs/tasks/detailsscreen/TaskDetailsUi.java b/opentasks/src/main/java/org/dmfs/tasks/detailsscreen/TaskDetailsUi.java new file mode 100644 index 000000000..77decc92f --- /dev/null +++ b/opentasks/src/main/java/org/dmfs/tasks/detailsscreen/TaskDetailsUi.java @@ -0,0 +1,49 @@ +/* + * Copyright 2017 dmfs GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dmfs.tasks.detailsscreen; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; + +import org.dmfs.tasks.utils.Showable; + + +/** + * UI for showing the details of a task. + *

+ * On {@link #show(Context)} it starts an Activity with action VIEW and with the task Uri as data. + * + * @author Gabor Keszthelyi + */ +public final class TaskDetailsUi implements Showable +{ + private final Uri mTaskUri; + + + public TaskDetailsUi(Uri taskUri) + { + mTaskUri = taskUri; + } + + + @Override + public void show(Context context) + { + context.startActivity(new Intent(Intent.ACTION_VIEW, mTaskUri)); + } +} diff --git a/opentasks/src/main/java/org/dmfs/tasks/utils/Showable.java b/opentasks/src/main/java/org/dmfs/tasks/utils/Showable.java new file mode 100644 index 000000000..61f3ad6df --- /dev/null +++ b/opentasks/src/main/java/org/dmfs/tasks/utils/Showable.java @@ -0,0 +1,34 @@ +/* + * Copyright 2018 dmfs GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dmfs.tasks.utils; + +import android.content.Context; + + +/** + * Represents a meaningful UI component/part of the app that belongs to a use-case. + * Can be a screen, notification, dialog, toast, etc. + * + * @author Gabor Keszthelyi + */ +public interface Showable +{ + /** + * Show the UI for the use-case this {@link Showable} represents. + */ + void show(C context); +}