diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index d7d294e1e..9087f45d9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -95,10 +95,6 @@ public class TagViewFragment extends TaskListFragment { // --- UI initialization - public TagViewFragment(Bundle extras) { - super(extras); - } - @Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java index c23346951..8840cc78b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java @@ -64,10 +64,6 @@ public class GtasksListFragment extends DraggableTaskListFragment { GtasksList.LAST_SYNC }; - public GtasksListFragment(Bundle extras) { - super(extras); - } - @Override public void onActivityCreated(Bundle icicle) { super.onActivityCreated(icicle); diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java index 46af4dff5..57a900f95 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java @@ -71,10 +71,6 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL private long taskId; - public NotificationFragment(Bundle extras) { - super(extras); - } - @Override public void onCreate(Bundle savedInstanceState) { StartupService.bypassInitialization(); diff --git a/astrid/src/com/todoroo/astrid/activity/AstridActivity.java b/astrid/src/com/todoroo/astrid/activity/AstridActivity.java index 5c4f43667..b8daa156d 100644 --- a/astrid/src/com/todoroo/astrid/activity/AstridActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/AstridActivity.java @@ -1,7 +1,5 @@ package com.todoroo.astrid.activity; -import java.lang.reflect.Constructor; - import android.app.PendingIntent.CanceledException; import android.content.BroadcastReceiver; import android.content.Context; @@ -168,7 +166,10 @@ public class AstridActivity extends FragmentActivity setIntent(intent); - setupTasklistFragmentWithFilter(filter, (Bundle) intent.getExtras().clone()); + Bundle extras = intent.getExtras(); + if (extras != null) + extras = (Bundle) extras.clone(); + setupTasklistFragmentWithFilter(filter, extras); // no animation for dualpane-layout AndroidUtilities.callOverridePendingTransition(this, 0, 0); @@ -204,20 +205,11 @@ public class AstridActivity extends FragmentActivity } protected final void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class customTaskList) { - Class component = customTaskList; - if (filter instanceof FilterWithCustomIntent) { - try { - component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName()); - } catch (Exception e) { - // Invalid - } - } - FragmentManager manager = getSupportFragmentManager(); - FragmentTransaction transaction = manager.beginTransaction(); + TaskListFragment newFragment = TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customTaskList); try { - Constructor constructor = component.getConstructor(Bundle.class); - TaskListFragment newFragment = (TaskListFragment) constructor.newInstance(extras); + FragmentManager manager = getSupportFragmentManager(); + FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.tasklist_fragment_container, newFragment, TaskListFragment.TAG_TASKLIST_FRAGMENT); transaction.commit(); diff --git a/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java index c295475e8..51ff0fd00 100644 --- a/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java @@ -31,10 +31,6 @@ public class DraggableTaskListFragment extends TaskListFragment { // --- task list - public DraggableTaskListFragment(Bundle extras) { - super(extras); - } - /** * If database has an indent property for determining how rows are indented, * return it here so we can read it from the cursor and use it diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 436375efa..a94207af2 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -147,7 +147,9 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener commentsButton.setOnClickListener(commentsButtonClickListener); Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); - Bundle extras = (Bundle) getIntent().getExtras().clone(); + Bundle extras = getIntent().getExtras(); + if (extras != null) + extras = (Bundle) extras.clone(); if (getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == Constants.SOURCE_NOTIFICATION) setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, extras, NotificationFragment.class); else diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index ee9a79437..cbd43b493 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -26,6 +26,7 @@ import android.support.v4.app.SupportActivity; import android.support.v4.view.Menu; import android.support.v4.view.MenuItem; import android.text.TextUtils; +import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.KeyEvent; @@ -64,6 +65,7 @@ import com.todoroo.astrid.adapter.TaskAdapter.OnCompletedTaskListener; import com.todoroo.astrid.adapter.TaskAdapter.ViewHolder; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; +import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.TaskContextActionExposer; import com.todoroo.astrid.api.TaskDecoration; import com.todoroo.astrid.core.CoreFilterExposer; @@ -175,7 +177,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, private Timer backgroundTimer; private boolean isFilter; - protected final Bundle extras; + protected Bundle extras; private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader(); @@ -193,12 +195,31 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, AstridDependencyInjector.initialize(); } - private TaskListFragment() { - this(null); + @SuppressWarnings("nls") + public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras, Class customComponent) { + Class component = customComponent; + if (filter instanceof FilterWithCustomIntent) { + try { + component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName()); + } catch (Exception e) { + // Invalid + } + } + TaskListFragment newFragment; + try { + newFragment = (TaskListFragment) component.newInstance(); + } catch (java.lang.InstantiationException e) { + Log.e("tla-instantiate", "tla-instantiate", e); + newFragment = new TaskListFragment(); + } catch (IllegalAccessException e) { + Log.e("tla-instantiate", "tla-instantiate", e); + newFragment = new TaskListFragment(); + } + newFragment.setExtras(extras); + return newFragment; } - public TaskListFragment(Bundle extras) { - super(); + public void setExtras(Bundle extras) { this.extras = extras; } diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java index 00a93d155..106ff514a 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java @@ -1,8 +1,6 @@ package com.todoroo.astrid.adapter; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - +import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; @@ -31,25 +29,19 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter { } private Fragment getFragmentForFilter(Filter filter) { + Bundle extras = getExtrasForFilter(filter); + return TaskListFragment.instantiateWithFilterAndExtras(filter, extras, TaskListFragment.class); + } + + private Bundle getExtrasForFilter(Filter filter) { + Bundle extras; if (filter instanceof FilterWithCustomIntent) { - try { - Class component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName()); - Constructor constructor = component.getConstructor(Boolean.class, Filter.class); - return (Fragment) constructor.newInstance(true, filter); - } catch (NoSuchMethodException e) { - return new TaskListFragment(null); - } catch (InvocationTargetException e) { - return new TaskListFragment(null); - } catch (ClassNotFoundException e) { - return new TaskListFragment(null); - } catch (IllegalAccessException e) { - return new TaskListFragment(null); - } catch (InstantiationException e) { - return new TaskListFragment(null); - } + extras = ((FilterWithCustomIntent) filter).customExtras; } else { - return new TaskListFragment(null); + extras = new Bundle(); } + extras.putParcelable(TaskListFragment.TOKEN_FILTER, filter); + return extras; } }