Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract and re-use details screen starting code. #589 #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/dictionaries/dictionary.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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<Context>
{
private final Uri mTaskUri;


public TaskDetailsUi(Uri taskUri)
{
mTaskUri = taskUri;
}


@Override
public void show(Context context)
{
context.startActivity(new Intent(Intent.ACTION_VIEW, mTaskUri));
}
}
34 changes: 34 additions & 0 deletions opentasks/src/main/java/org/dmfs/tasks/utils/Showable.java
Original file line number Diff line number Diff line change
@@ -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<C extends Context>
{
/**
* Show the UI for the use-case this {@link Showable} represents.
*/
void show(C context);
}