Merge remote-tracking branch 'origin/120221_sb_swipe_between_lists' into 120221_sb_swipe_between_lists

pull/14/head
Sam Bosley 13 years ago
commit ed6984e58d

@ -102,6 +102,8 @@ public class Filter extends FilterListItem {
this.valuesForNewTasks = valuesForNewTasks; this.valuesForNewTasks = valuesForNewTasks;
} }
/** /**
* Utility constructor * Utility constructor
* *
@ -121,6 +123,38 @@ public class Filter extends FilterListItem {
return 0; return 0;
} }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((sqlQuery == null) ? 0 : sqlQuery.hashCode());
result = prime * result + ((title == null) ? 0 : title.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Filter other = (Filter) obj;
if (sqlQuery == null) {
if (other.sqlQuery != null)
return false;
} else if (!sqlQuery.equals(other.sqlQuery))
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

@ -233,7 +233,7 @@ public class C2DMReceiver extends BroadcastReceiver {
} }
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notifyIntent.putExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_C2DM); notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_C2DM);
PendingIntent pendingIntent = PendingIntent.getActivity(context, PendingIntent pendingIntent = PendingIntent.getActivity(context,
notifId, notifyIntent, 0); notifId, notifyIntent, 0);

@ -178,8 +178,8 @@ public class TagViewFragment extends TaskListFragment {
} }
TaskListActivity activity = (TaskListActivity) getActivity(); TaskListActivity activity = (TaskListActivity) getActivity();
String tag = activity.getIntent().getStringExtra(EXTRA_TAG_NAME); String tag = extras.getString(EXTRA_TAG_NAME);
long remoteId = activity.getIntent().getLongExtra(EXTRA_TAG_REMOTE_ID, 0); long remoteId = extras.getLong(EXTRA_TAG_REMOTE_ID, 0);
if(tag == null && remoteId == 0) if(tag == null && remoteId == 0)
return; return;
@ -205,8 +205,8 @@ public class TagViewFragment extends TaskListFragment {
super.onNewIntent(intent); super.onNewIntent(intent);
if (activity.getIntent().getBooleanExtra(TOKEN_START_ACTIVITY, false)) { if (extras.getBoolean(TOKEN_START_ACTIVITY, false)) {
activity.getIntent().removeExtra(TOKEN_START_ACTIVITY); extras.remove(TOKEN_START_ACTIVITY);
activity.showComments(); activity.showComments();
} }
} }
@ -465,6 +465,7 @@ public class TagViewFragment extends TaskListFragment {
tagData = tagDataService.fetchById(tagData.getId(), TagData.PROPERTIES); tagData = tagDataService.fetchById(tagData.getId(), TagData.PROPERTIES);
filter = TagFilterExposer.filterFromTagData(getActivity(), tagData); filter = TagFilterExposer.filterFromTagData(getActivity(), tagData);
getActivity().getIntent().putExtra(TOKEN_FILTER, filter); getActivity().getIntent().putExtra(TOKEN_FILTER, filter);
extras.putParcelable(TOKEN_FILTER, filter);
Activity activity = getActivity(); Activity activity = getActivity();
if (activity instanceof TaskListActivity) { if (activity instanceof TaskListActivity) {
((TaskListActivity) activity).setListsTitle(filter.title); ((TaskListActivity) activity).setListsTitle(filter.title);

@ -22,7 +22,6 @@ import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.AstridFilterExposer; import com.todoroo.astrid.api.AstridFilterExposer;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
@ -72,7 +71,6 @@ public class GtasksFilterExposer extends BroadcastReceiver implements AstridFilt
filter.listingIcon = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.gtasks_icon)).getBitmap(); filter.listingIcon = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.gtasks_icon)).getBitmap();
filter.customTaskList = new ComponentName(ContextManager.getContext(), GtasksListFragment.class); filter.customTaskList = new ComponentName(ContextManager.getContext(), GtasksListFragment.class);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putBoolean(TaskListFragment.TOKEN_OVERRIDE_ANIM, true);
extras.putLong(GtasksListFragment.TOKEN_STORE_ID, list.getId()); extras.putLong(GtasksListFragment.TOKEN_STORE_ID, list.getId());
filter.customExtras = extras; filter.customExtras = extras;

@ -120,7 +120,7 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL
// hide quick add // hide quick add
getView().findViewById(R.id.taskListFooter).setVisibility(View.GONE); getView().findViewById(R.id.taskListFooter).setVisibility(View.GONE);
String title = getActivity().getIntent().getStringExtra(Notifications.EXTRAS_TEXT); String title = extras.getString(Notifications.EXTRAS_TEXT);
new ReminderDialog((AstridActivity) getActivity(), taskId, title).show(); new ReminderDialog((AstridActivity) getActivity(), taskId, title).show();
} }

@ -25,7 +25,6 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -181,7 +180,7 @@ public class Notifications extends BroadcastReceiver {
notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id); notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id);
notifyIntent.putExtra(EXTRAS_TEXT, text); notifyIntent.putExtra(EXTRAS_TEXT, text);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
notifyIntent.putExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION); notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION);
requestNotification((int)id, notifyIntent, type, title, text, ringTimes); requestNotification((int)id, notifyIntent, type, title, text, ringTimes);
return true; return true;

@ -29,7 +29,6 @@ import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.AstridFilterExposer; import com.todoroo.astrid.api.AstridFilterExposer;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
@ -112,7 +111,6 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag); extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag);
extras.putLong(TagViewFragment.EXTRA_TAG_REMOTE_ID, tag.remoteId); extras.putLong(TagViewFragment.EXTRA_TAG_REMOTE_ID, tag.remoteId);
extras.putBoolean(TaskListFragment.TOKEN_OVERRIDE_ANIM, true);
filter.customExtras = extras; filter.customExtras = extras;
return filter; return filter;

@ -5,4 +5,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
style="@style/Content" style="@style/Content"
android:id="@+id/tasklist_fragment_container"> android:id="@+id/tasklist_fragment_container">
<com.todoroo.astrid.ui.TaskListFragmentPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout> </FrameLayout>

@ -161,21 +161,12 @@ public class AstridActivity extends FragmentActivity
if(item instanceof Filter) { if(item instanceof Filter) {
Filter filter = (Filter)item; Filter filter = (Filter)item;
if(filter instanceof FilterWithCustomIntent) {
int lastSelectedList = intent.getIntExtra(FilterListFragment.TOKEN_LAST_SELECTED, 0);
intent = ((FilterWithCustomIntent)filter).getCustomIntent();
intent.putExtra(FilterListFragment.TOKEN_LAST_SELECTED, lastSelectedList);
} else {
intent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
}
setIntent(intent);
Bundle extras = configureIntentAndExtrasWithFilter(intent, filter);
if (fragmentLayout == LAYOUT_TRIPLE && getTaskEditFragment() != null) { if (fragmentLayout == LAYOUT_TRIPLE && getTaskEditFragment() != null) {
onBackPressed(); // remove the task edit fragment when switching between lists onBackPressed(); // remove the task edit fragment when switching between lists
} }
setupTasklistFragmentWithFilter(filter, extras);
setupTasklistFragmentWithFilter(filter);
// no animation for dualpane-layout // no animation for dualpane-layout
AndroidUtilities.callOverridePendingTransition(this, 0, 0); AndroidUtilities.callOverridePendingTransition(this, 0, 0);
@ -192,6 +183,23 @@ public class AstridActivity extends FragmentActivity
} }
} }
protected Bundle configureIntentAndExtrasWithFilter(Intent intent, Filter filter) {
if(filter instanceof FilterWithCustomIntent) {
int lastSelectedList = intent.getIntExtra(FilterListFragment.TOKEN_LAST_SELECTED, 0);
intent = ((FilterWithCustomIntent)filter).getCustomIntent();
intent.putExtra(FilterListFragment.TOKEN_LAST_SELECTED, lastSelectedList);
} else {
intent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
}
setIntent(intent);
Bundle extras = intent.getExtras();
if (extras != null)
extras = (Bundle) extras.clone();
return extras;
}
public void setupActivityFragment(TagData tagData) { public void setupActivityFragment(TagData tagData) {
if (fragmentLayout == LAYOUT_SINGLE) if (fragmentLayout == LAYOUT_SINGLE)
return; return;
@ -206,7 +214,7 @@ public class AstridActivity extends FragmentActivity
transaction.commit(); transaction.commit();
} }
public final void setupTasklistFragmentWithFilter(Filter filter) { public void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
Class<?> customTaskList = TaskListFragment.class; Class<?> customTaskList = TaskListFragment.class;
if(filter == null || CoreFilterExposer.isInbox(filter)) { if(filter == null || CoreFilterExposer.isInbox(filter)) {
@ -216,23 +224,15 @@ public class AstridActivity extends FragmentActivity
customTaskList = SubtasksListFragment.class; customTaskList = SubtasksListFragment.class;
} }
setupTasklistFragmentWithFilterAndCustomTaskList(filter, customTaskList); setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList);
} }
public final void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Class<?> customTaskList) { public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
Class<?> component = customTaskList; TaskListFragment newFragment = TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customTaskList);
if (filter instanceof FilterWithCustomIntent) {
try { try {
component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName());
} catch (Exception e) {
// Invalid
}
}
FragmentManager manager = getSupportFragmentManager(); FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction(); FragmentTransaction transaction = manager.beginTransaction();
try {
TaskListFragment newFragment = (TaskListFragment) component.newInstance();
transaction.replace(R.id.tasklist_fragment_container, newFragment, transaction.replace(R.id.tasklist_fragment_container, newFragment,
TaskListFragment.TAG_TASKLIST_FRAGMENT); TaskListFragment.TAG_TASKLIST_FRAGMENT);
transaction.commit(); transaction.commit();
@ -308,8 +308,8 @@ public class AstridActivity extends FragmentActivity
} }
} }
protected Fragment setupFragment(String tag, int container, Class<? extends Fragment> cls) { protected Fragment setupFragment(String tag, int container, Class<? extends Fragment> cls, boolean createImmediate) {
FragmentManager fm = getSupportFragmentManager(); final FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentByTag(tag); Fragment fragment = fm.findFragmentByTag(tag);
if(fragment == null) { if(fragment == null) {
try { try {
@ -326,6 +326,13 @@ public class AstridActivity extends FragmentActivity
else else
ft.replace(container, fragment, tag); ft.replace(container, fragment, tag);
ft.commit(); ft.commit();
if (createImmediate)
runOnUiThread(new Runnable() {
@Override
public void run() {
fm.executePendingTransactions();
}
});
} }
return fragment; return fragment;
} }

@ -122,6 +122,8 @@ public class FilterListFragment extends ListFragment {
// Check that the container activity has implemented the callback interface // Check that the container activity has implemented the callback interface
try { try {
mListener = (OnFilterItemClickedListener) activity; mListener = (OnFilterItemClickedListener) activity;
adapter = new FilterAdapter(getActivity(), null,
R.layout.filter_adapter_row, false);
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new ClassCastException(activity.toString() throw new ClassCastException(activity.toString()
+ " must implement OnFilterItemClickedListener"); //$NON-NLS-1$ + " must implement OnFilterItemClickedListener"); //$NON-NLS-1$
@ -257,8 +259,7 @@ public class FilterListFragment extends ListFragment {
/** Sets up the coach list adapter */ /** Sets up the coach list adapter */
protected void setUpList() { protected void setUpList() {
adapter = new FilterAdapter(getActivity(), getListView(), adapter.setListView(getListView());
R.layout.filter_adapter_row, false);
setListAdapter(adapter); setListAdapter(adapter);
adapter.setLastSelected(mSelectedIndex); adapter.setLastSelected(mSelectedIndex);

@ -87,8 +87,8 @@ public class ShortcutActivity extends Activity {
Intent taskListIntent = new Intent(this, TaskListActivity.class); Intent taskListIntent = new Intent(this, TaskListActivity.class);
if(extras != null && extras.containsKey(TaskListFragment.TOKEN_SOURCE)) if(extras != null && extras.containsKey(TaskListActivity.TOKEN_SOURCE))
taskListIntent.putExtra(TaskListFragment.TOKEN_SOURCE, extras.getInt(TaskListFragment.TOKEN_SOURCE)); taskListIntent.putExtra(TaskListActivity.TOKEN_SOURCE, extras.getInt(TaskListActivity.TOKEN_SOURCE));
if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) { if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) {
taskListIntent.putExtras(intent.getExtras()); taskListIntent.putExtras(intent.getExtras());

@ -9,6 +9,7 @@ import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActionBar; import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -29,32 +30,44 @@ import com.todoroo.astrid.actfm.ActFmLoginActivity;
import com.todoroo.astrid.actfm.TagSettingsActivity; import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.actfm.TagUpdatesFragment; import com.todoroo.astrid.actfm.TagUpdatesFragment;
import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.adapter.TaskListFragmentPagerAdapter;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment; import com.todoroo.astrid.reminders.NotificationFragment;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.ui.DateChangedAlerts; import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.ui.FragmentPopover; import com.todoroo.astrid.ui.FragmentPopover;
import com.todoroo.astrid.ui.MainMenuPopover; import com.todoroo.astrid.ui.MainMenuPopover;
import com.todoroo.astrid.ui.MainMenuPopover.MainMenuListener; import com.todoroo.astrid.ui.MainMenuPopover.MainMenuListener;
import com.todoroo.astrid.ui.TaskListFragmentPager;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.utility.Flags;
import com.todoroo.astrid.welcome.tutorial.WelcomeWalkthrough; import com.todoroo.astrid.welcome.tutorial.WelcomeWalkthrough;
public class TaskListActivity extends AstridActivity implements MainMenuListener { public class TaskListActivity extends AstridActivity implements MainMenuListener, OnPageChangeListener {
public static final String TOKEN_SELECTED_FILTER = "selectedFilter"; //$NON-NLS-1$ public static final String TOKEN_SELECTED_FILTER = "selectedFilter"; //$NON-NLS-1$
/** token for indicating source of TLA launch */
public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$
private View listsNav; private View listsNav;
private ImageView listsNavDisclosure; private ImageView listsNavDisclosure;
private TextView lists; private TextView lists;
private ImageView mainMenu; private ImageView mainMenu;
private Button commentsButton; private Button commentsButton;
private TaskListFragmentPager tlfPager;
private TaskListFragmentPagerAdapter tlfPagerAdapter;
private FragmentPopover listsPopover; private FragmentPopover listsPopover;
private FragmentPopover editPopover; private FragmentPopover editPopover;
private FragmentPopover commentsPopover; private FragmentPopover commentsPopover;
@ -142,15 +155,54 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
commentsButton.setOnClickListener(commentsButtonClickListener); commentsButton.setOnClickListener(commentsButtonClickListener);
Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER);
if (savedFilter == null)
savedFilter = CoreFilterExposer.buildInboxFilter(getResources());
Bundle extras = getIntent().getExtras();
if (extras != null)
extras = (Bundle) extras.clone();
if (fragmentLayout == LAYOUT_SINGLE) {
FilterListFragment flf = getFilterListFragment();
if (flf == null)
throw new RuntimeException("Filterlist fragment was null, needs to exist to construct the fragment pager"); //$NON-NLS-1$
FilterAdapter adapter = flf.adapter;
tlfPager = (TaskListFragmentPager) findViewById(R.id.pager);
tlfPagerAdapter = new TaskListFragmentPagerAdapter(getSupportFragmentManager(), adapter);
tlfPager.setAdapter(tlfPagerAdapter);
tlfPager.setOnPageChangeListener(this);
}
if (getIntent().getIntExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == if (getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT) ==
Constants.SOURCE_NOTIFICATION) Constants.SOURCE_NOTIFICATION)
setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, NotificationFragment.class); setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, extras, NotificationFragment.class);
else else
setupTasklistFragmentWithFilter(savedFilter); setupTasklistFragmentWithFilter(savedFilter, extras);
if (savedFilter != null) if (savedFilter != null)
setListsTitle(savedFilter.title); setListsTitle(savedFilter.title);
if (getIntent().hasExtra(TOKEN_SOURCE)) {
trackActivitySource();
}
}
@Override
public void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilter(filter); // TODO: make sure we handle the extras and the custom task list
} else {
super.setupTasklistFragmentWithFilter(filter, extras);
}
}
@Override
public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilter(filter); // TODO: make sure we handle the extras and the custom task list
} else {
super.setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList);
}
} }
/** /**
@ -176,13 +228,13 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT,
R.id.filterlist_fragment_container, FilterListFragment.class); R.id.filterlist_fragment_container, FilterListFragment.class, false);
} else { } else {
fragmentLayout = LAYOUT_SINGLE; fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
listsNav.setOnClickListener(popupMenuClickListener); listsNav.setOnClickListener(popupMenuClickListener);
createListsPopover(); createListsPopover();
setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, FilterListFragment.class)); setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, FilterListFragment.class, true));
} }
} }
@ -270,6 +322,11 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
if (listsPopover != null) if (listsPopover != null)
listsPopover.dismiss(); listsPopover.dismiss();
setCommentsCount(0); setCommentsCount(0);
if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilter((Filter) item);
return true;
}
return super.onFilterItemClicked(item); return super.onFilterItemClicked(item);
} }
@ -333,6 +390,21 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
lists.setText(item.title); lists.setText(item.title);
} }
@Override
public void onPageSelected(int position) {
if (tlfPagerAdapter != null) {
configureIntentAndExtrasWithFilter(getIntent(), tlfPagerAdapter.getFilter(position));
setListsTitle(tlfPagerAdapter.getPageTitle(position).toString());
}
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) { /* Nothing */ }
@Override
public void onPageScrollStateChanged(int state) { /* Nothing */ }
public void setCommentsCount(int count) { public void setCommentsCount(int count) {
TypedValue tv = new TypedValue(); TypedValue tv = new TypedValue();
@ -452,6 +524,31 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
} }
/**
* Report who launched this activity
*/
protected void trackActivitySource() {
switch (getIntent().getIntExtra(TOKEN_SOURCE,
Constants.SOURCE_DEFAULT)) {
case Constants.SOURCE_NOTIFICATION:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_NOTIFICATION);
break;
case Constants.SOURCE_OTHER:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_OTHER);
break;
case Constants.SOURCE_PPWIDGET:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_PPW);
break;
case Constants.SOURCE_WIDGET:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_WIDGET);
break;
case Constants.SOURCE_C2DM:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_C2DM);
break;
}
getIntent().putExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT); // Only report source once
}
@Override @Override
public void mainMenuItemSelected(int item) { public void mainMenuItemSelected(int item) {
TaskListFragment tla = getTaskListFragment(); TaskListFragment tla = getTaskListFragment();

@ -26,6 +26,7 @@ import android.support.v4.app.SupportActivity;
import android.support.v4.view.Menu; import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem; import android.support.v4.view.MenuItem;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -65,6 +66,7 @@ import com.todoroo.astrid.adapter.TaskAdapter.OnCompletedTaskListener;
import com.todoroo.astrid.adapter.TaskAdapter.ViewHolder; import com.todoroo.astrid.adapter.TaskAdapter.ViewHolder;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.TaskContextActionExposer; import com.todoroo.astrid.api.TaskContextActionExposer;
import com.todoroo.astrid.api.TaskDecoration; import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.core.CoreFilterExposer; import com.todoroo.astrid.core.CoreFilterExposer;
@ -141,10 +143,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
/** token for passing a {@link Filter} object through extras */ /** token for passing a {@link Filter} object through extras */
public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$ public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$
/** token for indicating source of TLA launch */ private static final String TOKEN_EXTRAS = "extras"; //$NON-NLS-1$
public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$
public static final String TOKEN_OVERRIDE_ANIM = "finishAnim"; //$NON-NLS-1$
// --- instance variables // --- instance variables
@ -179,10 +178,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
protected Filter filter; protected Filter filter;
protected int sortFlags; protected int sortFlags;
protected int sortSort; protected int sortSort;
protected boolean overrideFinishAnim;
protected QuickAddBar quickAddBar; protected QuickAddBar quickAddBar;
private Timer backgroundTimer; private Timer backgroundTimer;
protected Bundle extras;
private boolean isInbox; private boolean isInbox;
private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader(); private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader();
@ -201,6 +200,32 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
@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();
}
Bundle args = new Bundle();
args.putBundle(TOKEN_EXTRAS, extras);
newFragment.setArguments(args);
return newFragment;
}
/** /**
* Container Activity must implement this interface and we ensure that it * Container Activity must implement this interface and we ensure that it
* does during the onAttach() callback * does during the onAttach() callback
@ -237,6 +262,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
extras = getArguments() != null ? getArguments().getBundle(TOKEN_EXTRAS) : null;
} }
/* /*
@ -280,10 +306,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
upgradeService.showChangeLog(getActivity(), upgradeService.showChangeLog(getActivity(),
Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1)); Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
if (getActivity().getIntent().hasExtra(TOKEN_SOURCE)) {
trackActivitySource();
}
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY); Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
@ -291,31 +313,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
}); });
} }
/**
* Report who launched this activity
*/
protected void trackActivitySource() {
switch (getActivity().getIntent().getIntExtra(TOKEN_SOURCE,
Constants.SOURCE_DEFAULT)) {
case Constants.SOURCE_NOTIFICATION:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_NOTIFICATION);
break;
case Constants.SOURCE_OTHER:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_OTHER);
break;
case Constants.SOURCE_PPWIDGET:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_PPW);
break;
case Constants.SOURCE_WIDGET:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_WIDGET);
break;
case Constants.SOURCE_C2DM:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_C2DM);
break;
}
getActivity().getIntent().putExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT); // Only report source once
}
/** /**
* @return the current tag you are viewing, or null if you're not viewing a tag * @return the current tag you are viewing, or null if you're not viewing a tag
*/ */
@ -324,12 +321,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
} }
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
overrideFinishAnim = extras.getBoolean(TOKEN_OVERRIDE_ANIM);
} else {
overrideFinishAnim = false;
}
String intentAction = intent.getAction(); String intentAction = intent.getAction();
if (Intent.ACTION_SEARCH.equals(intentAction)) { if (Intent.ACTION_SEARCH.equals(intentAction)) {
String query = intent.getStringExtra(SearchManager.QUERY).trim(); String query = intent.getStringExtra(SearchManager.QUERY).trim();
@ -339,17 +330,14 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
"%" + //$NON-NLS-1$ "%" + //$NON-NLS-1$
query.toUpperCase() + "%")), //$NON-NLS-1$ query.toUpperCase() + "%")), //$NON-NLS-1$
null); null);
intent = new Intent(getActivity(), TaskListActivity.class); Intent searchIntent = new Intent(getActivity(), TaskListActivity.class);
intent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter); searchIntent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter);
startActivity(intent); startActivity(searchIntent);
getActivity().finish(); getActivity().finish();
if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_right_in, R.anim.slide_right_out);
}
return; return;
} else if (extras != null && extras.containsKey(TOKEN_FILTER)) { } else if (extras != null && extras.containsKey(TOKEN_FILTER)) {
filter = extras.getParcelable(TOKEN_FILTER); filter = extras.getParcelable(TOKEN_FILTER);
extras.remove(TOKEN_FILTER); // Otherwise writing this filter to parcel gives infinite recursion
} else { } else {
filter = CoreFilterExposer.buildInboxFilter(getResources()); filter = CoreFilterExposer.buildInboxFilter(getResources());
} }
@ -659,16 +647,16 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
try { try {
Bundle extras = intent.getExtras(); Bundle receivedExtras = intent.getExtras();
long taskId = extras.getLong(AstridApiConstants.EXTRAS_TASK_ID); long taskId = receivedExtras.getLong(AstridApiConstants.EXTRAS_TASK_ID);
String addOn = extras.getString(AstridApiConstants.EXTRAS_ADDON); String addOn = receivedExtras.getString(AstridApiConstants.EXTRAS_ADDON);
if (AstridApiConstants.BROADCAST_SEND_DECORATIONS.equals(intent.getAction())) { if (AstridApiConstants.BROADCAST_SEND_DECORATIONS.equals(intent.getAction())) {
TaskDecoration deco = extras.getParcelable(AstridApiConstants.EXTRAS_RESPONSE); TaskDecoration deco = receivedExtras.getParcelable(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.decorationManager.addNew(taskId, addOn, deco, taskAdapter.decorationManager.addNew(taskId, addOn, deco,
null); null);
} else if (AstridApiConstants.BROADCAST_SEND_DETAILS.equals(intent.getAction())) { } else if (AstridApiConstants.BROADCAST_SEND_DETAILS.equals(intent.getAction())) {
String detail = extras.getString(AstridApiConstants.EXTRAS_RESPONSE); String detail = receivedExtras.getString(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.addDetails(taskId, detail); taskAdapter.addDetails(taskId, detail);
} }
} catch (Exception e) { } catch (Exception e) {
@ -694,10 +682,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
if (requestCode == ACTIVITY_SETTINGS) { if (requestCode == ACTIVITY_SETTINGS) {
if (resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) { if (resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) {
getActivity().finish(); getActivity().finish();
if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_right_in, R.anim.slide_right_out);
}
getActivity().startActivity(getActivity().getIntent()); getActivity().startActivity(getActivity().getIntent());
} else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) { } else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
Preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login Preferences.setLong(SyncActionHelper.PREF_LAST_AUTO_SYNC, 0); // Forces autosync to occur after login
@ -1176,10 +1160,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
protected void toggleDragDrop(boolean newState) { protected void toggleDragDrop(boolean newState) {
if(newState) if(newState)
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null, ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null,
SubtasksListFragment.class); extras, SubtasksListFragment.class);
else else
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null, ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null,
TaskListFragment.class); extras, TaskListFragment.class);
} }
protected boolean isDraggable() { protected boolean isDraggable() {

@ -54,6 +54,10 @@ import com.todoroo.astrid.tags.TagService;
public class FilterAdapter extends ArrayAdapter<Filter> { public class FilterAdapter extends ArrayAdapter<Filter> {
public static interface FilterDataSourceChangedListener {
public void filterDataSourceChanged();
}
// --- style constants // --- style constants
public int filterStyle = R.style.TextAppearance_FLA_Filter; public int filterStyle = R.style.TextAppearance_FLA_Filter;
@ -68,7 +72,7 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
protected final Activity activity; protected final Activity activity;
/** owner listview */ /** owner listview */
protected final ListView listView; protected ListView listView;
/** display metrics for scaling icons */ /** display metrics for scaling icons */
private final DisplayMetrics metrics = new DisplayMetrics(); private final DisplayMetrics metrics = new DisplayMetrics();
@ -92,6 +96,8 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
private int mSelectedIndex; private int mSelectedIndex;
private FilterDataSourceChangedListener listener;
// Previous solution involved a queue of filters and a filterSizeLoadingThread. The filterSizeLoadingThread had // Previous solution involved a queue of filters and a filterSizeLoadingThread. The filterSizeLoadingThread had
// a few problems: how to make sure that the thread is resumed when the controlling activity is resumed, and // a few problems: how to make sure that the thread is resumed when the controlling activity is resumed, and
// how to make sure that the the filterQueue does not accumulate filters without being processed. I am replacing // how to make sure that the the filterQueue does not accumulate filters without being processed. I am replacing
@ -164,10 +170,24 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
offerFilter(item); offerFilter(item);
} }
public int addOrLookup(Filter filter) {
int index = getPosition(filter);
if (index >= 0) return index;
add(filter);
return getCount() - 1;
}
public void setLastSelected(int lastSelected) { public void setLastSelected(int lastSelected) {
mSelectedIndex = lastSelected; mSelectedIndex = lastSelected;
} }
public void setDataSourceChangedListener(FilterDataSourceChangedListener listener) {
this.listener = listener;
}
public void setListView(ListView listView) {
this.listView = listView;
}
/** /**
* Create or reuse a view * Create or reuse a view
@ -293,10 +313,10 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
if (filter instanceof FilterCategory) { if (filter instanceof FilterCategory) {
Filter[] children = ((FilterCategory) filter).children; Filter[] children = ((FilterCategory) filter).children;
for (Filter f : children) { for (Filter f : children) {
add(f); addOrLookup(f);
} }
} else if (filter instanceof Filter){ } else if (filter instanceof Filter){
add((Filter) filter); addOrLookup((Filter) filter);
} }
} }
@ -351,6 +371,13 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
} }
} }
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
if (listener != null)
listener.filterDataSourceChanged();
}
/** /**
* Broadcast a request for lists. The request is sent to every * Broadcast a request for lists. The request is sent to every
* application registered to listen for this broadcast. Each application * application registered to listen for this broadcast. Each application
@ -379,7 +406,6 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
IntentFilter bladeFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS); IntentFilter bladeFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS);
bladeFilter.setPriority(1); bladeFilter.setPriority(1);
activity.registerReceiver(bladeFilterReceiver, bladeFilter); activity.registerReceiver(bladeFilterReceiver, bladeFilter);
if(getCount() == 0)
getLists(); getLists();
} }

@ -0,0 +1,74 @@
package com.todoroo.astrid.adapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.adapter.FilterAdapter.FilterDataSourceChangedListener;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent;
public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter implements FilterDataSourceChangedListener {
private final FilterAdapter filterAdapter;
public TaskListFragmentPagerAdapter(FragmentManager fm, FilterAdapter filterAdapter) {
super(fm);
this.filterAdapter = filterAdapter;
filterAdapter.setDataSourceChangedListener(this);
}
@Override
public void filterDataSourceChanged() {
notifyDataSetChanged();
}
@Override
public Fragment getItem(int position) {
return getFragmentForFilter(filterAdapter.getItem(position));
}
@Override
public CharSequence getPageTitle(int position) {
return filterAdapter.getItem(position).title;
}
public int addOrLookup(Filter filter) {
return filterAdapter.addOrLookup(filter);
}
public Filter getFilter(int position) {
return filterAdapter.getItem(position);
}
@Override
public int getCount() {
return filterAdapter.getCount();
}
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) {
extras = ((FilterWithCustomIntent) filter).customExtras;
} else {
extras = new Bundle();
}
if (filter != null)
extras.putParcelable(TaskListFragment.TOKEN_FILTER, filter);
return extras;
}
@Override
public Parcelable saveState() {
return null; // Don't save state
}
}

@ -0,0 +1,40 @@
package com.todoroo.astrid.ui;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import com.todoroo.astrid.adapter.TaskListFragmentPagerAdapter;
import com.todoroo.astrid.api.Filter;
public class TaskListFragmentPager extends ViewPager {
public TaskListFragmentPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setAdapter(PagerAdapter adapter) {
if (!(adapter instanceof TaskListFragmentPagerAdapter))
throw new ClassCastException("TaskListFragmentPager requires an adapter of type TaskListFragmentPagerAdapter"); //$NON-NLS-1$
super.setAdapter(adapter);
}
/**
* Show the supplied filter, adding it to the data source if it doesn't exist
* @param f
*/
public void showFilter(Filter f) {
TaskListFragmentPagerAdapter adapter = (TaskListFragmentPagerAdapter) getAdapter();
showFilter(adapter.addOrLookup(f));
}
/**
* Show the filter at the supplied index
* @param index
*/
public void showFilter(int index) {
setCurrentItem(index, true);
}
}

@ -217,7 +217,7 @@ public class TasksWidget extends AppWidgetProvider {
Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras); Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
listIntent.putExtras(extras); listIntent.putExtras(extras);
} }
listIntent.putExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_WIDGET); listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET);
listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
if(filter != null) { if(filter != null) {
listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter); listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);

Loading…
Cancel
Save