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

Update widgets when task starts or becomes due #925

Merged
merged 4 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2020 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.actions;

import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ContentProviderClient;
import android.content.Context;
import android.net.Uri;

import org.dmfs.android.contentpal.RowDataSnapshot;
import org.dmfs.tasks.contract.TaskContract;
import org.dmfs.tasks.homescreen.TaskListWidgetProvider;
import org.dmfs.tasks.R;


/**
* A {@link TaskAction} that updates the widgets.
*
* @author Trogel
*/
public final class UpdateWidgetsAction implements TaskAction
{
private final static String TAG = "UpdateWidgetsAction";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unused field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that was a relict of some debug logging. Removed.


public UpdateWidgetsAction()
{
}


@Override
public void execute(Context context, ContentProviderClient contentProviderClient, RowDataSnapshot<TaskContract.Instances> rowSnapshot, Uri taskUri)
{
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
final ComponentName componentName = new ComponentName(context, TaskListWidgetProvider.class);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we have two widget providers (mostly for backwards compatibility). Please ensure to update both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, did not see the other. Hope I got it right.

final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(componentName);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.task_list_widget_lv);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public RemoteViews getViewAt(int position)
row.setTextViewText(android.R.id.text1, mDueDateFormatter.format(dueDate, DateFormatContext.WIDGET_VIEW));

// highlight overdue dates & times
if ((!dueDate.allDay && dueDate.before(mNow) || dueDate.allDay
if ((!dueDate.allDay && Time.compare(dueDate, mNow) <= 0 || dueDate.allDay
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated to the issue. Why did you make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While working on this fix I observed some cases where the update was processed right within the second of the due date. I noticed that in those cases the task did not turn red but remained white in the widget. That seemed wrong. The reason was that dueDate was not before but exactly equal to mNow – at least in android.text.format.Time's second precision.

Therefore I changed this comparison essentially from dueDate < mNow to dueDate <= mNow. Sorry, if the commit message was not clear about my intention.

&& (dueDate.year < mNow.year || dueDate.yearDay <= mNow.yearDay && dueDate.year == mNow.year))
&& !items[position].getIsClosed())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.dmfs.tasks.actions.PostUndoAction;
import org.dmfs.tasks.actions.RemoveNotificationAction;
import org.dmfs.tasks.actions.TaskAction;
import org.dmfs.tasks.actions.UpdateWidgetsAction;
import org.dmfs.tasks.actions.WipeNotificationAction;
import org.dmfs.tasks.contract.TaskContract;

Expand Down Expand Up @@ -180,8 +181,10 @@ private TaskAction resolveAction(String action)

case TaskContract.ACTION_BROADCAST_TASK_DUE:
case TaskContract.ACTION_BROADCAST_TASK_STARTING:
// post start and due notification on the due date channel
return new NotifyStickyAction(data -> CHANNEL_DUE_DATES, true);
return new Composite(
// post start and due notification on the due date channel
new NotifyStickyAction(data -> CHANNEL_DUE_DATES, true),
new UpdateWidgetsAction());

case ACTION_UNDO_COMPLETE:
return new Composite(
Expand Down