... and now detail exposer kicks butt and passes

pull/14/head
Tim Su 14 years ago
parent 67451e623a
commit 53ed873d6d

@ -13,6 +13,7 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.utility.Constants;
/** /**
* Exposes Task Details for Remember the Milk: * Exposes Task Details for Remember the Milk:
@ -31,10 +32,13 @@ public class GtasksDetailExposer extends BroadcastReceiver {
@Autowired private GtasksListService gtasksListService; @Autowired private GtasksListService gtasksListService;
@Autowired private GtasksPreferenceService gtasksPreferenceService; @Autowired private GtasksPreferenceService gtasksPreferenceService;
public GtasksDetailExposer() {
DependencyInjectionService.getInstance().inject(this);
}
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
ContextManager.setContext(context); ContextManager.setContext(context);
DependencyInjectionService.getInstance().inject(this);
// if we aren't logged in, don't expose features // if we aren't logged in, don't expose features
if(!gtasksPreferenceService.isLoggedIn()) if(!gtasksPreferenceService.isLoggedIn())
@ -74,7 +78,7 @@ public class GtasksDetailExposer extends BroadcastReceiver {
builder.append("<img src='silk_folder'/> ").append(listName); //$NON-NLS-1$ builder.append("<img src='silk_folder'/> ").append(listName); //$NON-NLS-1$
if(metadata.getValue(GtasksMetadata.PARENT_TASK) > AbstractModel.NO_ID) { if(metadata.getValue(GtasksMetadata.PARENT_TASK) > AbstractModel.NO_ID && Constants.DEBUG) {
builder.append(DETAIL_SEPARATOR).append("Parent: ").append(metadata.getValue(GtasksMetadata.PARENT_TASK)); builder.append(DETAIL_SEPARATOR).append("Parent: ").append(metadata.getValue(GtasksMetadata.PARENT_TASK));
} }

@ -14,7 +14,6 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.SyncAction; import com.todoroo.astrid.api.SyncAction;
import com.todoroo.gtasks.GoogleTaskListInfo;
/** /**
* Exposes sync action * Exposes sync action
@ -24,33 +23,17 @@ public class GtasksSyncActionExposer extends BroadcastReceiver {
@Autowired private GtasksPreferenceService gtasksPreferenceService; @Autowired private GtasksPreferenceService gtasksPreferenceService;
@Autowired private GtasksListService gtasksListService;
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
ContextManager.setContext(context); ContextManager.setContext(context);
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
if(intent.getBooleanExtra("setup", false)) {
gtasksPreferenceService.setToken("haha");
GoogleTaskListInfo[] newLists = new GoogleTaskListInfo[2];
GoogleTaskListInfo list = new GoogleTaskListInfo("1", "Tim's Tasks");
newLists[0] = list;
list = new GoogleTaskListInfo("2", "Travel");
newLists[1] = list;
gtasksListService.updateLists(newLists);
System.err.println("you've ben set up the bomb.");
return;
}
// if we aren't logged in, don't expose sync action // if we aren't logged in, don't expose sync action
//if(!gtasksPreferenceService.isLoggedIn()) if(!gtasksPreferenceService.isLoggedIn())
// return; return;
Intent syncIntent = new Intent(intent.getAction(), null, Intent syncIntent = new Intent(intent.getAction(), null,
context, GtasksSyncActionExposer.class); context, GtasksSyncActionExposer.class);
syncIntent.putExtra("setup", true);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0);
SyncAction syncAction = new SyncAction(context.getString(R.string.gtasks_GPr_header), SyncAction syncAction = new SyncAction(context.getString(R.string.gtasks_GPr_header),
pendingIntent); pendingIntent);

@ -1,17 +1,23 @@
package com.todoroo.astrid.gtasks; package com.todoroo.astrid.gtasks;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase; import com.todoroo.astrid.test.DatabaseTestCase;
import com.todoroo.astrid.utility.Preferences;
import com.todoroo.gtasks.GoogleTaskListInfo; import com.todoroo.gtasks.GoogleTaskListInfo;
public class GtasksDetailExposerTest extends DatabaseTestCase { public class GtasksDetailExposerTest extends DatabaseTestCase {
@Autowired private GtasksListService gtasksListService; @Autowired private GtasksListService gtasksListService;
private GtasksTestPreferenceService preferences = new GtasksTestPreferenceService(); private GtasksTestPreferenceService preferences = new GtasksTestPreferenceService();
private DetailListener detailListener = new DetailListener();
private Task task; private Task task;
private String detail; private String detail;
@ -104,7 +110,11 @@ public class GtasksDetailExposerTest extends DatabaseTestCase {
} }
private void whenRequestingDetails() { private void whenRequestingDetails() {
detail = new GtasksDetailExposer().getTaskDetails(task.getId(), false); Intent intent = new Intent(AstridApiConstants.BROADCAST_REQUEST_DETAILS);
intent.putExtra(AstridApiConstants.EXTRAS_EXTENDED, false);
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
detail = null;
new GtasksDetailExposer().onReceive(getContext(), intent);
} }
private void givenLoggedInStatus(boolean status) { private void givenLoggedInStatus(boolean status) {
@ -114,9 +124,21 @@ public class GtasksDetailExposerTest extends DatabaseTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
if(!Preferences.isSet(GtasksPreferenceService.PREF_DEFAULT_LIST)) getContext().registerReceiver(detailListener, new IntentFilter(AstridApiConstants.BROADCAST_SEND_DETAILS));
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, "list");
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
getContext().unregisterReceiver(detailListener);
}
private class DetailListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
detail = intent.getExtras().getString(AstridApiConstants.EXTRAS_RESPONSE);
}
} }
} }

Loading…
Cancel
Save