diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDetailExposer.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDetailExposer.java index 30aba7e66..63ec516e5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDetailExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksDetailExposer.java @@ -13,6 +13,7 @@ import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.data.Metadata; +import com.todoroo.astrid.utility.Constants; /** * Exposes Task Details for Remember the Milk: @@ -31,10 +32,13 @@ public class GtasksDetailExposer extends BroadcastReceiver { @Autowired private GtasksListService gtasksListService; @Autowired private GtasksPreferenceService gtasksPreferenceService; + public GtasksDetailExposer() { + DependencyInjectionService.getInstance().inject(this); + } + @Override public void onReceive(Context context, Intent intent) { ContextManager.setContext(context); - DependencyInjectionService.getInstance().inject(this); // if we aren't logged in, don't expose features if(!gtasksPreferenceService.isLoggedIn()) @@ -74,7 +78,7 @@ public class GtasksDetailExposer extends BroadcastReceiver { builder.append(" ").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)); } diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksSyncActionExposer.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksSyncActionExposer.java index f8d96eb67..46e3cd963 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksSyncActionExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksSyncActionExposer.java @@ -14,7 +14,6 @@ import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.SyncAction; -import com.todoroo.gtasks.GoogleTaskListInfo; /** * Exposes sync action @@ -24,33 +23,17 @@ public class GtasksSyncActionExposer extends BroadcastReceiver { @Autowired private GtasksPreferenceService gtasksPreferenceService; - @Autowired private GtasksListService gtasksListService; - @Override public void onReceive(Context context, Intent intent) { ContextManager.setContext(context); 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(!gtasksPreferenceService.isLoggedIn()) - // return; + if(!gtasksPreferenceService.isLoggedIn()) + return; Intent syncIntent = new Intent(intent.getAction(), null, context, GtasksSyncActionExposer.class); - syncIntent.putExtra("setup", true); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0); SyncAction syncAction = new SyncAction(context.getString(R.string.gtasks_GPr_header), pendingIntent); diff --git a/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java b/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java index 4ecaaf96e..d9c0c80ed 100644 --- a/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java +++ b/tests/src/com/todoroo/astrid/gtasks/GtasksDetailExposerTest.java @@ -1,17 +1,23 @@ 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.astrid.api.AstridApiConstants; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.test.DatabaseTestCase; -import com.todoroo.astrid.utility.Preferences; import com.todoroo.gtasks.GoogleTaskListInfo; public class GtasksDetailExposerTest extends DatabaseTestCase { @Autowired private GtasksListService gtasksListService; private GtasksTestPreferenceService preferences = new GtasksTestPreferenceService(); + private DetailListener detailListener = new DetailListener(); private Task task; private String detail; @@ -104,7 +110,11 @@ public class GtasksDetailExposerTest extends DatabaseTestCase { } 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) { @@ -114,9 +124,21 @@ public class GtasksDetailExposerTest extends DatabaseTestCase { @Override protected void setUp() throws Exception { super.setUp(); - if(!Preferences.isSet(GtasksPreferenceService.PREF_DEFAULT_LIST)) - Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, "list"); + getContext().registerReceiver(detailListener, new IntentFilter(AstridApiConstants.BROADCAST_SEND_DETAILS)); + + } + + @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); + } } }