Skip to content
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.

7 changes: 7 additions & 0 deletions opentasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}

dependencies {
implementation project(':opentasks-provider')
implementation project(':opentaskspal')
implementation deps.support_appcompat
implementation deps.support_design
implementation(deps.xml_magic) {
Expand All @@ -81,6 +85,9 @@ dependencies {
implementation deps.datetime
implementation deps.bolts_color
implementation deps.retention_magic
implementation deps.contentpal
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

testImplementation deps.junit
testImplementation deps.robolectric
Expand Down
5 changes: 4 additions & 1 deletion opentasks/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@
java.lang.String TAG;
@org.dmfs.android.retentionmagic.annotations.* <fields>;
private long mId;
}
}

-dontwarn android.databinding.**
-keep class android.databinding.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import org.dmfs.tasks.utils.SafeFragmentUiRunnable;
import org.dmfs.tasks.utils.TasksListCursorSpinnerAdapter;

import java.util.TimeZone;


/**
* A quick add dialog. It allows the user to enter a new task without having to deal with the full blown editor interface. At present it support task with a
Expand All @@ -80,6 +82,7 @@ public class QuickAddDialogFragment extends SupportDialogFragment
private final static int COMPLETION_DELAY_MAX = 1500; // ms

private final static String ARG_LIST_ID = "list_id";
private final static String ARG_PARENT_ID = "parent_id";
private final static String ARG_CONTENT = "content";

public static final String LIST_LOADER_URI = "uri";
Expand Down Expand Up @@ -121,6 +124,9 @@ public interface OnTextInputListener
@Parameter(key = ARG_LIST_ID)
private long mListId = -1;

@Parameter(key = ARG_PARENT_ID)
private long mParentId = -1;

@Parameter(key = ARG_CONTENT)
private ContentSet mInitialContent;

Expand Down Expand Up @@ -160,6 +166,22 @@ public static QuickAddDialogFragment newInstance(long listId)
QuickAddDialogFragment fragment = new QuickAddDialogFragment();
Bundle args = new Bundle();
args.putLong(ARG_LIST_ID, listId);
args.putLong(ARG_PARENT_ID, -1);
fragment.setArguments(args);
return fragment;
}

/**
* Create a {@link QuickAddDialogFragment} with the given title and initial text value.
*
* @return A new {@link QuickAddDialogFragment}.
*/
public static QuickAddDialogFragment newInstance(long listId, long parentId)
{
QuickAddDialogFragment fragment = new QuickAddDialogFragment();
Bundle args = new Bundle();
args.putLong(ARG_LIST_ID, listId);
args.putLong(ARG_PARENT_ID, parentId);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -176,6 +198,7 @@ public static QuickAddDialogFragment newInstance(ContentSet content)
Bundle args = new Bundle();
args.putParcelable(ARG_CONTENT, content);
args.putLong(ARG_LIST_ID, -1);
args.putLong(ARG_PARENT_ID, -1);
fragment.setArguments(args);
return fragment;
}
Expand Down Expand Up @@ -300,7 +323,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (EditorInfo.IME_ACTION_DONE == actionId)
{
notifyUser(true /* close afterwards */);
notifyUser(mParentId == -1 /* close if no parent */);
createTask();
return true;
}
Expand Down Expand Up @@ -375,7 +398,11 @@ private ContentSet buildContentSet()
task = new ContentSet(Tasks.getContentUri(mAuthority));
}
task.put(Tasks.LIST_ID, mListSpinner.getSelectedItemId());
if (mParentId != -1) {
task.put(Tasks.PARENT_ID, mParentId);
}
TaskFieldAdapters.TITLE.set(task, mEditText.getText().toString());
TaskFieldAdapters.TIMEZONE.set(task, TimeZone.getDefault());
return task;
}

Expand Down
30 changes: 30 additions & 0 deletions opentasks/src/main/java/org/dmfs/tasks/ViewTaskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,23 @@

import org.dmfs.android.bolts.color.Color;
import org.dmfs.android.bolts.color.elementary.ValueColor;
import org.dmfs.android.contentpal.RowDataSnapshot;
import org.dmfs.android.retentionmagic.SupportFragment;
import org.dmfs.android.retentionmagic.annotations.Parameter;
import org.dmfs.android.retentionmagic.annotations.Retain;
import org.dmfs.opentaskspal.readdata.Id;
import org.dmfs.tasks.contract.TaskContract.Tasks;
import org.dmfs.tasks.detailsscreen.RowDataSubtaskViewParams;
import org.dmfs.tasks.detailsscreen.RowDataSubtasksViewParams;
import org.dmfs.tasks.detailsscreen.SubtasksSource;
import org.dmfs.tasks.detailsscreen.SubtasksView;
import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.model.Model;
import org.dmfs.tasks.model.OnContentChangeListener;
import org.dmfs.tasks.model.Sources;
import org.dmfs.tasks.model.TaskFieldAdapters;
import org.dmfs.tasks.notification.ActionService;
import org.dmfs.tasks.readdata.TaskContentUri;
import org.dmfs.tasks.share.ShareIntentFactory;
import org.dmfs.tasks.utils.ContentValueMapper;
import org.dmfs.tasks.utils.OnModelLoadedListener;
Expand All @@ -74,6 +81,9 @@
import java.util.HashSet;
import java.util.Set;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;


/**
* A fragment representing a single Task detail screen. This fragment is either contained in a {@link TaskListActivity} in two-pane mode (on tablets) or in a
Expand Down Expand Up @@ -135,6 +145,8 @@ public class ViewTaskFragment extends SupportFragment
*/
private TaskView mDetailView;

private CompositeDisposable mDisposables;

private int mListColor;
private int mOldStatus = -1;
private boolean mPinned = false;
Expand Down Expand Up @@ -252,12 +264,14 @@ public void onDestroyView()
mDetailView.setValues(null);
}

mDisposables.dispose();
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
mDisposables = new CompositeDisposable();
mShowFloatingActionButton = !getResources().getBoolean(R.bool.has_two_panes);

mRootView = inflater.inflate(R.layout.fragment_task_view_detail, container, false);
Expand Down Expand Up @@ -442,6 +456,12 @@ private void updateView()
((TextView) mToolBar.findViewById(R.id.toolbar_title)).setText(TaskFieldAdapters.TITLE.get(mContentSet));
}
}

Long listId = mContentSet.getAsLong(Tasks.LIST_ID);
Long parentId = mContentSet.getAsLong(Tasks._ID);
mDisposables.add(new SubtasksSource(mAppContext, mTaskUri, RowDataSubtaskViewParams.SUBTASK_PROJECTION)
.subscribe(subtasks ->
new SubtasksView(mContent).update(new RowDataSubtasksViewParams(new ValueColor(mListColor), listId, parentId, subtasks))));
}


Expand Down Expand Up @@ -566,6 +586,16 @@ public void onClick(DialogInterface dialog, int which)
if (mContentSet != null)
{
// TODO: remove the task in a background task
// delete subtasks
mDisposables.add(new SubtasksSource(mAppContext, mTaskUri, RowDataSubtaskViewParams.SUBTASK_PROJECTION).subscribe(subtasks ->
{
for (RowDataSnapshot<Tasks> x : subtasks) {
Long subtaskId = new Id(x).value();
ContentSet contentSet = new ContentSet(new TaskContentUri(subtaskId, mAppContext).value());
contentSet.delete(mAppContext);
}
}));

mContentSet.delete(mAppContext);
mCallback.onTaskDeleted(mTaskUri);
mTaskUri = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.detailsscreen;

import org.dmfs.android.bolts.color.Color;
import org.dmfs.android.contentpal.Projection;
import org.dmfs.android.contentpal.RowDataSnapshot;
import org.dmfs.android.contentpal.projections.Composite;
import org.dmfs.jems.optional.Optional;
import org.dmfs.opentaskspal.readdata.EffectiveDueDate;
import org.dmfs.opentaskspal.readdata.EffectiveTaskColor;
import org.dmfs.opentaskspal.readdata.Id;
import org.dmfs.opentaskspal.readdata.PercentComplete;
import org.dmfs.opentaskspal.readdata.TaskCompletionTime;
import org.dmfs.opentaskspal.readdata.TaskTitle;
import org.dmfs.rfc5545.DateTime;
import org.dmfs.tasks.contract.TaskContract;

import java.util.Date;


/**
* {@link SubtasksView.Params} that reads the data from the given {@link RowDataSnapshot}.
*
* @author Gabor Keszthelyi
*/
public final class RowDataSubtaskViewParams implements SubtaskView.Params
{

/**
* The projection required for this adapter to work.
*/
public static final Projection<TaskContract.Tasks> SUBTASK_PROJECTION = new Composite<>(
Id.PROJECTION,
TaskTitle.PROJECTION,
EffectiveDueDate.PROJECTION,
EffectiveTaskColor.PROJECTION,
PercentComplete.PROJECTION
);

private final RowDataSnapshot<TaskContract.Tasks> mRowDataSnapshot;


public RowDataSubtaskViewParams(RowDataSnapshot<TaskContract.Tasks> rowDataSnapshot)
{
mRowDataSnapshot = rowDataSnapshot;
}


@Override
public Long id()
{
return new Id(mRowDataSnapshot).value();
}


@Override
public Optional<CharSequence> title()
{
return new TaskTitle(mRowDataSnapshot);
}


@Override
public Optional<DateTime> due()
{
return new EffectiveDueDate(mRowDataSnapshot);
}


@Override
public Color color()
{
return new EffectiveTaskColor(mRowDataSnapshot);
}


@Override
public Optional<DateTime> completionTime()
{
return new TaskCompletionTime(mRowDataSnapshot);
}


@Override
public Optional<Integer> percentComplete()
{
return new PercentComplete(mRowDataSnapshot);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.detailsscreen;

import org.dmfs.android.bolts.color.Color;
import org.dmfs.android.contentpal.RowDataSnapshot;
import org.dmfs.jems.iterable.decorators.Mapped;
import org.dmfs.tasks.contract.TaskContract;


/**
* {@link SubtasksView.Params} that adapts the given {@link RowDataSnapshot}s (and takes the list color).
*
* @author Gabor Keszthelyi
*/
public final class RowDataSubtasksViewParams implements SubtasksView.Params
{
private final Color mTaskListColor;
private final Long mListId;
private final Long mParentId;
private final Iterable<RowDataSnapshot<TaskContract.Tasks>> mSubtaskRows;


public RowDataSubtasksViewParams(Color taskListColor, Long listId, Long parentId, Iterable<RowDataSnapshot<TaskContract.Tasks>> subtaskRows)
{
mTaskListColor = taskListColor;
mListId = listId;
mParentId = parentId;
mSubtaskRows = subtaskRows;
}


@Override
public Color taskListColor()
{
return mTaskListColor;
}


@Override
public Long listId()
{
return mListId;
}

@Override
public Long parentId()
{
return mParentId;
}


@Override
public Iterable<SubtaskView.Params> subtasks()
{
return new Mapped<>(RowDataSubtaskViewParams::new, mSubtaskRows);
}
}
Loading