Move methods to broadcaster

pull/189/head
Alex Baker 11 years ago
parent ec4c92ae2e
commit 362e18f602

@ -377,10 +377,7 @@ public class TaskDao extends RemoteModelDao<Task> {
}
if(values.containsKey(Task.COMPLETION_DATE.name) && task.isCompleted()) {
Intent broadcastIntent;
broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_COMPLETED);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
broadcaster.sendOrderedBroadcast(broadcastIntent);
broadcaster.taskCompleted(task.getId());
}
broadcastTaskChanged();
@ -390,7 +387,7 @@ public class TaskDao extends RemoteModelDao<Task> {
* Send broadcast when task list changes. Widgets should update.
*/
private void broadcastTaskChanged() {
broadcaster.sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_LIST_UPDATED));
broadcaster.taskListUpdated();
}
/**

@ -17,7 +17,6 @@ import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
@ -47,7 +46,6 @@ public class Notifications extends InjectingBroadcastReceiver {
/**
* Action name for broadcast intent notifying that task was created from repeating template
*/
public static final String BROADCAST_IN_APP_NOTIFY = Constants.PACKAGE + ".IN_APP_NOTIFY"; //$NON-NLS-1$
public static final String EXTRAS_CUSTOM_INTENT = "intent"; //$NON-NLS-1$
public static final String EXTRAS_NOTIF_ID = "notifId"; //$NON-NLS-1$
@ -176,19 +174,7 @@ public class Notifications extends InjectingBroadcastReceiver {
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION);
requestNotification((int) id, notifyIntent, type, title, text, ringTimes);
broadcaster.requestNotification((int) id, notifyIntent, type, title, text, ringTimes);
return true;
}
private void requestNotification(long taskId, Intent intent, int type, String title, String text, int ringTimes) {
Intent inAppNotify = new Intent(BROADCAST_IN_APP_NOTIFY);
inAppNotify.putExtra(EXTRAS_NOTIF_ID, (int) taskId);
inAppNotify.putExtra(NotificationFragment.TOKEN_ID, taskId);
inAppNotify.putExtra(EXTRAS_CUSTOM_INTENT, intent);
inAppNotify.putExtra(EXTRAS_TYPE, type);
inAppNotify.putExtra(EXTRAS_TITLE, title);
inAppNotify.putExtra(EXTRAS_TEXT, text);
inAppNotify.putExtra(EXTRAS_RING_TIMES, ringTimes);
broadcaster.sendOrderedBroadcast(inAppNotify, AstridApiConstants.PERMISSION_READ);
}
}

@ -6,7 +6,6 @@
package com.todoroo.astrid.service;
import android.content.ContentValues;
import android.content.Intent;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
@ -15,7 +14,6 @@ import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata;
@ -236,7 +234,7 @@ public class TaskService {
filterCounter.refreshFilterCounts(new Runnable() {
@Override
public void run() {
broadcaster.sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_FILTER_LIST_UPDATED));
broadcaster.filterListUpdated();
}
});
}

@ -3,6 +3,11 @@ package org.tasks;
import android.content.Context;
import android.content.Intent;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.reminders.NotificationFragment;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.utility.Constants;
import org.tasks.injection.ForApplication;
import javax.inject.Inject;
@ -11,6 +16,8 @@ import javax.inject.Singleton;
@Singleton
public class Broadcaster {
public static final String BROADCAST_IN_APP_NOTIFY = Constants.PACKAGE + ".IN_APP_NOTIFY"; //$NON-NLS-1$
private final Context context;
@Inject
@ -18,11 +25,38 @@ public class Broadcaster {
this.context = context;
}
public void sendOrderedBroadcast(Intent intent) {
public void requestNotification(final long taskId, final Intent intent, final int type,
final String title, final String text, final int ringTimes) {
sendOrderedBroadcast(new Intent(BROADCAST_IN_APP_NOTIFY) {{
putExtra(Notifications.EXTRAS_NOTIF_ID, (int) taskId);
putExtra(NotificationFragment.TOKEN_ID, taskId);
putExtra(Notifications.EXTRAS_CUSTOM_INTENT, intent);
putExtra(Notifications.EXTRAS_TYPE, type);
putExtra(Notifications.EXTRAS_TITLE, title);
putExtra(Notifications.EXTRAS_TEXT, text);
putExtra(Notifications.EXTRAS_RING_TIMES, ringTimes);
}}, AstridApiConstants.PERMISSION_READ);
}
public void taskCompleted(final long id) {
sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_COMPLETED) {{
putExtra(AstridApiConstants.EXTRAS_TASK_ID, id);
}});
}
public void taskListUpdated() {
sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_LIST_UPDATED));
}
public void filterListUpdated() {
sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_FILTER_LIST_UPDATED));
}
private void sendOrderedBroadcast(Intent intent) {
sendOrderedBroadcast(intent, null);
}
public void sendOrderedBroadcast(Intent intent, String permissions) {
void sendOrderedBroadcast(Intent intent, String permissions) {
context.sendOrderedBroadcast(intent, permissions);
}
}

@ -3,8 +3,6 @@ package org.tasks.scheduling;
import android.content.Context;
import android.content.Intent;
import com.todoroo.astrid.api.AstridApiConstants;
import org.tasks.Broadcaster;
import org.tasks.injection.InjectingBroadcastReceiver;
@ -18,7 +16,7 @@ public class RefreshBroadcastReceiver extends InjectingBroadcastReceiver {
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
broadcaster.sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_LIST_UPDATED));
broadcaster.sendOrderedBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_FILTER_LIST_UPDATED));
broadcaster.taskListUpdated();
broadcaster.filterListUpdated();
}
}

Loading…
Cancel
Save