From 5f8e86d7bd3782411ffa412ee52a60675135a6cd Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 11 Apr 2012 14:34:01 -0700 Subject: [PATCH] Fixed bugs with Notification fragments in swipe between lists --- .../reminders/NotificationFragment.java | 28 +++++++------------ .../astrid/reminders/Notifications.java | 19 +++++++++++-- .../astrid/activity/TaskListActivity.java | 11 ++++---- .../adapter/TaskListFragmentPagerAdapter.java | 4 +++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java index 57a900f95..4e0b42da5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java @@ -37,15 +37,12 @@ import android.widget.Spinner; import android.widget.TimePicker; import com.timsu.astrid.R; -import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.activity.AstridActivity; import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListFragment; -import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.core.PluginServices; -import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.repeats.RepeatControlSet; import com.todoroo.astrid.service.StartupService; @@ -94,25 +91,10 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL @Override protected void onNewIntent(Intent intent) { - populateFilter(intent); displayNotificationPopup(); super.onNewIntent(intent); } - private void populateFilter(Intent intent) { - taskId = intent.getLongExtra(TOKEN_ID, -1); - if(taskId == -1) - return; - - Filter itemFilter = new Filter(getString(R.string.rmd_NoA_filter), - getString(R.string.rmd_NoA_filter), - new QueryTemplate().where(TaskCriteria.byId(taskId)), - null); - intent.putExtra(TaskListFragment.TOKEN_FILTER, itemFilter); - if (getActivity() instanceof TaskListActivity) // Title was already set before this fragment took over; set it again - ((TaskListActivity) getActivity()).setListsTitle(itemFilter.title); - } - /** * Set up the UI for this activity */ @@ -124,6 +106,16 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL new ReminderDialog((AstridActivity) getActivity(), taskId, title).show(); } + @Override + public void onDetach() { + Activity activity = getActivity(); + if (activity instanceof TaskListActivity) { + TaskListActivity tla = (TaskListActivity) activity; + tla.getFragmentPagerAdapter().remove(filter); + } + super.onDetach(); + } + public static class SnoozeDialog extends FrameLayout implements DialogInterface.OnClickListener { LinearLayout snoozePicker; diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java index 4dcb10671..a81eb3642 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java @@ -5,12 +5,14 @@ import java.util.Date; import android.app.Notification; import android.app.PendingIntent; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.Color; import android.media.AudioManager; import android.net.Uri; +import android.os.Bundle; import android.telephony.TelephonyManager; import android.util.Log; @@ -21,12 +23,16 @@ import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.NotificationManager; import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager; +import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; 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; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.utility.Constants; @@ -176,9 +182,18 @@ public class Notifications extends BroadcastReceiver { String text = reminder + " " + taskTitle; //$NON-NLS-1$ Intent notifyIntent = new Intent(context, TaskListActivity.class); + FilterWithCustomIntent itemFilter = new FilterWithCustomIntent(context.getString(R.string.rmd_NoA_filter), + context.getString(R.string.rmd_NoA_filter), + new QueryTemplate().where(TaskCriteria.byId(id)), + null); + Bundle customExtras = new Bundle(); + customExtras.putLong(NotificationFragment.TOKEN_ID, id); + customExtras.putString(EXTRAS_TEXT, text); + itemFilter.customExtras = customExtras; + itemFilter.customTaskList = new ComponentName(context, NotificationFragment.class); + notifyIntent.setAction("NOTIFY" + id); //$NON-NLS-1$ - notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id); - notifyIntent.putExtra(EXTRAS_TEXT, text); + notifyIntent.putExtra(TaskListFragment.TOKEN_FILTER, itemFilter); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index cdc943eea..0d50701b0 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -38,7 +38,6 @@ import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.core.CoreFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.reminders.NotificationFragment; import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.ThemeService; @@ -172,11 +171,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener tlfPager.setOnPageChangeListener(this); } - if (getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == - Constants.SOURCE_NOTIFICATION) - setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, extras, NotificationFragment.class); - else - setupTasklistFragmentWithFilter(savedFilter, extras); + setupTasklistFragmentWithFilter(savedFilter, extras); if (savedFilter != null) setListsTitle(savedFilter.title); @@ -396,6 +391,10 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener lists.setText(item.title); } + public TaskListFragmentPagerAdapter getFragmentPagerAdapter() { + return tlfPagerAdapter; + } + @Override public void onPageSelected(int position) { if (tlfPagerAdapter != null) { diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java index 2d2936b70..5a05af6e8 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java @@ -69,6 +69,10 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl return filterAdapter.addOrLookup(filter); } + public void remove(Filter filter) { + filterAdapter.remove(filter); + } + /** * Get the filter at the specified position * @param position