Merge swipe between lists branch with changes from master

pull/14/head
Sam Bosley 12 years ago
commit af9345c057

@ -102,6 +102,8 @@ public class Filter extends FilterListItem {
this.valuesForNewTasks = valuesForNewTasks;
}
/**
* Utility constructor
*

@ -235,7 +235,7 @@ public class C2DMReceiver extends BroadcastReceiver {
}
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,
notifId, notifyIntent, 0);

@ -309,7 +309,7 @@ public class TagUpdatesFragment extends ListFragment {
private void refreshActivity(boolean manual) {
if (actFmPreferenceService.isLoggedIn()) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
getActivity(), R.id.comments_progressBar, new Runnable() {
getActivity(), this, R.id.comments_progressBar, new Runnable() {
@Override
public void run() {
refreshUpdatesList();

@ -179,8 +179,8 @@ public class TagViewFragment extends TaskListFragment {
}
TaskListActivity activity = (TaskListActivity) getActivity();
String tag = activity.getIntent().getStringExtra(EXTRA_TAG_NAME);
long remoteId = activity.getIntent().getLongExtra(EXTRA_TAG_REMOTE_ID, 0);
String tag = extras.getString(EXTRA_TAG_NAME);
long remoteId = extras.getLong(EXTRA_TAG_REMOTE_ID, 0);
if(tag == null && remoteId == 0)
return;
@ -206,8 +206,8 @@ public class TagViewFragment extends TaskListFragment {
super.onNewIntent(intent);
if (activity.getIntent().getBooleanExtra(TOKEN_START_ACTIVITY, false)) {
activity.getIntent().removeExtra(TOKEN_START_ACTIVITY);
if (extras.getBoolean(TOKEN_START_ACTIVITY, false)) {
extras.remove(TOKEN_START_ACTIVITY);
activity.showComments();
}
}
@ -238,6 +238,11 @@ public class TagViewFragment extends TaskListFragment {
updateCommentCount();
}
@Override
public void requestCommentCountUpdate() {
updateCommentCount();
}
private void updateCommentCount() {
if (tagData != null) {
long lastViewedComments = Preferences.getLong(TagUpdatesFragment.UPDATES_LAST_VIEWED + tagData.getValue(TagData.REMOTE_ID), 0);
@ -258,7 +263,9 @@ public class TagViewFragment extends TaskListFragment {
@Override
protected void initiateAutomaticSync() {
public void initiateAutomaticSync() {
if (!isCurrentTaskListFragment())
return;
if (tagData != null) {
long lastAutoSync = Preferences.getLong(LAST_FETCH_KEY + tagData.getId(), 0);
if(DateUtilities.now() - lastAutoSync > DateUtilities.ONE_HOUR)
@ -270,7 +277,7 @@ public class TagViewFragment extends TaskListFragment {
private void refreshData(final boolean manual) {
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.DLG_loading);
syncService.synchronizeList(tagData, manual, new ProgressBarSyncResultCallback(getActivity(),
syncService.synchronizeList(tagData, manual, new ProgressBarSyncResultCallback(getActivity(), this,
R.id.progressBar, new Runnable() {
@Override
public void run() {
@ -468,6 +475,7 @@ public class TagViewFragment extends TaskListFragment {
return;
filter = TagFilterExposer.filterFromTagData(getActivity(), tagData);
getActivity().getIntent().putExtra(TOKEN_FILTER, filter);
extras.putParcelable(TOKEN_FILTER, filter);
Activity activity = getActivity();
if (activity instanceof TaskListActivity) {
((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.Order;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.AstridFilterExposer;
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.customTaskList = new ComponentName(ContextManager.getContext(), GtasksListFragment.class);
Bundle extras = new Bundle();
extras.putBoolean(TaskListFragment.TOKEN_OVERRIDE_ANIM, true);
extras.putLong(GtasksListFragment.TOKEN_STORE_ID, list.getId());
filter.customExtras = extras;

@ -70,7 +70,9 @@ public class GtasksListFragment extends SubtasksListFragment {
}
@Override
protected void initiateAutomaticSync() {
public void initiateAutomaticSync() {
if (!isCurrentTaskListFragment())
return;
if (list != null && DateUtilities.now() - list.getValue(GtasksList.LAST_SYNC) > DateUtilities.ONE_HOUR) {
syncService.synchronizeList(list, false, syncActionHelper.syncResultCallback);
}

@ -120,7 +120,7 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL
// hide quick add
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();
}

@ -25,7 +25,6 @@ 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.dao.TaskDao;
import com.todoroo.astrid.data.Task;
@ -181,7 +180,7 @@ public class Notifications extends BroadcastReceiver {
notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id);
notifyIntent.putExtra(EXTRAS_TEXT, text);
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);
return true;

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

@ -5,4 +5,8 @@
android:layout_height="match_parent"
style="@style/Content"
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>

@ -145,21 +145,12 @@ public class AstridActivity extends FragmentActivity
if(item instanceof Filter) {
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) {
onBackPressed(); // remove the task edit fragment when switching between lists
}
setupTasklistFragmentWithFilter(filter);
setupTasklistFragmentWithFilter(filter, extras);
// no animation for dualpane-layout
AndroidUtilities.callOverridePendingTransition(this, 0, 0);
@ -176,6 +167,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) {
if (fragmentLayout == LAYOUT_SINGLE)
return;
@ -190,7 +198,7 @@ public class AstridActivity extends FragmentActivity
transaction.commit();
}
public final void setupTasklistFragmentWithFilter(Filter filter) {
public void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
Class<?> customTaskList = TaskListFragment.class;
if(filter == null || CoreFilterExposer.isInbox(filter)) {
@ -200,27 +208,15 @@ public class AstridActivity extends FragmentActivity
customTaskList = SubtasksListFragment.class;
}
setupTasklistFragmentWithFilterAndCustomTaskList(filter, customTaskList);
setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList);
}
public final void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Class<?> customTaskList) {
Class<?> component = customTaskList;
if (filter == null)
getIntent().removeExtra(TaskListFragment.TOKEN_FILTER);
else
getIntent().putExtra(TaskListFragment.TOKEN_FILTER, filter);
if (filter instanceof FilterWithCustomIntent) {
try {
component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName());
} catch (Exception e) {
// Invalid
}
}
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
TaskListFragment newFragment = TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customTaskList);
try {
TaskListFragment newFragment = (TaskListFragment) component.newInstance();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.tasklist_fragment_container, newFragment,
TaskListFragment.TAG_TASKLIST_FRAGMENT);
transaction.commit();
@ -299,8 +295,8 @@ public class AstridActivity extends FragmentActivity
}
}
protected Fragment setupFragment(String tag, int container, Class<? extends Fragment> cls) {
FragmentManager fm = getSupportFragmentManager();
protected Fragment setupFragment(String tag, int container, Class<? extends Fragment> cls, boolean createImmediate) {
final FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentByTag(tag);
if(fragment == null) {
try {
@ -317,6 +313,13 @@ public class AstridActivity extends FragmentActivity
else
ft.replace(container, fragment, tag);
ft.commit();
if (createImmediate)
runOnUiThread(new Runnable() {
@Override
public void run() {
fm.executePendingTransactions();
}
});
}
return fragment;
}

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

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

@ -9,6 +9,7 @@ import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.KeyEvent;
@ -29,31 +30,43 @@ import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.actfm.TagUpdatesFragment;
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.Filter;
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;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.ui.FragmentPopover;
import com.todoroo.astrid.ui.MainMenuPopover;
import com.todoroo.astrid.ui.MainMenuPopover.MainMenuListener;
import com.todoroo.astrid.ui.TaskListFragmentPager;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Flags;
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$
/** token for indicating source of TLA launch */
public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$
private View listsNav;
private ImageView listsNavDisclosure;
private TextView lists;
private ImageView mainMenu;
private Button commentsButton;
private TaskListFragmentPager tlfPager;
private TaskListFragmentPagerAdapter tlfPagerAdapter;
private FragmentPopover listsPopover;
private FragmentPopover editPopover;
private FragmentPopover commentsPopover;
@ -141,15 +154,63 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
commentsButton.setOnClickListener(commentsButtonClickListener);
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)
setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, NotificationFragment.class);
setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, extras, NotificationFragment.class);
else
setupTasklistFragmentWithFilter(savedFilter);
setupTasklistFragmentWithFilter(savedFilter, extras);
if (savedFilter != null)
setListsTitle(savedFilter.title);
if (getIntent().hasExtra(TOKEN_SOURCE)) {
trackActivitySource();
}
}
@Override
public TaskListFragment getTaskListFragment() {
if (fragmentLayout == LAYOUT_SINGLE) {
return tlfPager.getCurrentFragment();
} else {
return super.getTaskListFragment();
}
}
@Override
public void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilter(filter);
} else {
super.setupTasklistFragmentWithFilter(filter, extras);
}
}
@Override
public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilterWithCustomTaskList(filter, customTaskList);
} else {
super.setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList);
}
}
/**
@ -175,13 +236,13 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
}
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT,
R.id.filterlist_fragment_container, FilterListFragment.class);
R.id.filterlist_fragment_container, FilterListFragment.class, false);
} else {
fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true);
listsNav.setOnClickListener(popupMenuClickListener);
createListsPopover();
setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, FilterListFragment.class));
setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, FilterListFragment.class, true));
}
}
@ -275,6 +336,11 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
if (listsPopover != null)
listsPopover.dismiss();
setCommentsCount(0);
if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilter((Filter) item);
return true;
}
return super.onFilterItemClicked(item);
}
@ -338,6 +404,25 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
lists.setText(item.title);
}
@Override
public void onPageSelected(int position) {
if (tlfPagerAdapter != null) {
configureIntentAndExtrasWithFilter(getIntent(), tlfPagerAdapter.getFilter(position));
setListsTitle(tlfPagerAdapter.getPageTitle(position).toString());
TaskListFragment fragment = getTaskListFragment();
fragment.initiateAutomaticSync();
fragment.requestCommentCountUpdate();
}
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) { /* Nothing */ }
@Override
public void onPageScrollStateChanged(int state) { /* Nothing */ }
public void setCommentsCount(int count) {
TypedValue tv = new TypedValue();
@ -478,6 +563,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
public void mainMenuItemSelected(int item, Intent customIntent) {
TaskListFragment tlf = getTaskListFragment();

@ -28,6 +28,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;
@ -68,6 +69,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;
@ -146,10 +148,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
/** token for passing a {@link Filter} object through extras */
public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$
/** token for indicating source of TLA launch */
public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$
public static final String TOKEN_OVERRIDE_ANIM = "finishAnim"; //$NON-NLS-1$
private static final String TOKEN_EXTRAS = "extras"; //$NON-NLS-1$
// --- instance variables
@ -184,10 +183,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
protected Filter filter;
protected int sortFlags;
protected int sortSort;
protected boolean overrideFinishAnim;
protected QuickAddBar quickAddBar;
private Timer backgroundTimer;
protected Bundle extras;
private boolean isInbox;
private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader();
@ -206,6 +205,57 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
AstridDependencyInjector.initialize();
}
/**
* Instantiates and returns an instance of TaskListFragment (or some subclass). Custom types of
* TaskListFragment can be created, with the following precedence:
*
* --If the filter is of type {@link FilterWithCustomIntent}, the task list type it specifies will be used
* --Otherwise, the specified customComponent will be used
*
* See also: instantiateWithFilterAndExtras(Filter, Bundle) which uses TaskListFragment as the default
* custom component.
* @param filter
* @param extras
* @param customComponent
* @return
*/
@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;
}
/**
* Convenience method for calling instantiateWithFilterAndExtras(Filter, Bundle, Class<?>) with
* TaskListFragment as the default component
* @param filter
* @param extras
* @return
*/
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras) {
return instantiateWithFilterAndExtras(filter, extras, TaskListFragment.class);
}
/**
* Container Activity must implement this interface and we ensure that it
* does during the onAttach() callback
@ -242,6 +292,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
public void onCreate(Bundle savedInstanceState) {
DependencyInjectionService.getInstance().inject(this);
super.onCreate(savedInstanceState);
extras = getArguments() != null ? getArguments().getBundle(TOKEN_EXTRAS) : null;
}
/*
@ -287,10 +338,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
upgradeService.showChangeLog(getActivity(),
Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
if (getActivity().getIntent().hasExtra(TOKEN_SOURCE)) {
trackActivitySource();
}
getActivity().runOnUiThread(new Runnable() {
public void run() {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
@ -313,31 +360,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
*/
@ -346,12 +368,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
}
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();
if (Intent.ACTION_SEARCH.equals(intentAction)) {
String query = intent.getStringExtra(SearchManager.QUERY).trim();
@ -361,17 +377,14 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
"%" + //$NON-NLS-1$
query.toUpperCase() + "%")), //$NON-NLS-1$
null);
intent = new Intent(getActivity(), TaskListActivity.class);
intent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter);
startActivity(intent);
Intent searchIntent = new Intent(getActivity(), TaskListActivity.class);
searchIntent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter);
startActivity(searchIntent);
getActivity().finish();
if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_right_in, R.anim.slide_right_out);
}
return;
} else if (extras != null && extras.containsKey(TOKEN_FILTER)) {
filter = extras.getParcelable(TOKEN_FILTER);
extras.remove(TOKEN_FILTER); // Otherwise writing this filter to parcel gives infinite recursion
} else {
filter = CoreFilterExposer.buildInboxFilter(getResources());
}
@ -421,6 +434,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
Activity activity = getActivity();
if (activity == null)
return;
if (!isCurrentTaskListFragment())
return;
boolean isTablet = AndroidUtilities.isTabletSized(activity);
if (activity instanceof TaskListActivity)
@ -625,8 +640,24 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
initiateAutomaticSync();
}
protected void initiateAutomaticSync() {
syncActionHelper.initiateAutomaticSync(filter);
protected boolean isCurrentTaskListFragment() {
AstridActivity activity = (AstridActivity) getActivity();
if (activity != null) {
return activity.getTaskListFragment() == this;
}
return false;
}
public void initiateAutomaticSync() {
if (isCurrentTaskListFragment())
syncActionHelper.initiateAutomaticSync(filter);
}
// Subclasses should override this
public void requestCommentCountUpdate() {
TaskListActivity activity = (TaskListActivity) getActivity();
if (activity != null)
activity.setCommentsCount(0);
}
@Override
@ -686,16 +717,16 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle extras = intent.getExtras();
long taskId = extras.getLong(AstridApiConstants.EXTRAS_TASK_ID);
String addOn = extras.getString(AstridApiConstants.EXTRAS_ADDON);
Bundle receivedExtras = intent.getExtras();
long taskId = receivedExtras.getLong(AstridApiConstants.EXTRAS_TASK_ID);
String addOn = receivedExtras.getString(AstridApiConstants.EXTRAS_ADDON);
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,
null);
} 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);
}
} catch (Exception e) {
@ -714,10 +745,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
if (requestCode == ACTIVITY_SETTINGS) {
if (resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) {
getActivity().finish();
if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_right_in, R.anim.slide_right_out);
}
getActivity().startActivity(getActivity().getIntent());
TasksWidget.updateWidgets(getActivity());
} else if (resultCode == SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
@ -1215,11 +1242,11 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
protected void toggleDragDrop(boolean newState) {
if(newState)
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null,
SubtasksListFragment.class);
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter,
extras, SubtasksListFragment.class);
else
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null,
TaskListFragment.class);
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter,
extras, TaskListFragment.class);
}
protected boolean isDraggable() {

@ -56,6 +56,10 @@ import com.todoroo.astrid.tags.TagService;
public class FilterAdapter extends ArrayAdapter<Filter> {
public static interface FilterDataSourceChangedListener {
public void filterDataSourceChanged();
}
// --- style constants
public int filterStyle = R.style.TextAppearance_FLA_Filter;
@ -70,7 +74,7 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
protected final Activity activity;
/** owner listview */
protected final ListView listView;
protected ListView listView;
/** display metrics for scaling icons */
private final DisplayMetrics metrics = new DisplayMetrics();
@ -99,6 +103,9 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
private final HashMap<Filter, Integer> filterCounts;
private FilterDataSourceChangedListener listener;
// 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
// how to make sure that the the filterQueue does not accumulate filters without being processed. I am replacing
@ -186,6 +193,13 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
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) {
mSelectedIndex = lastSelected;
}
@ -226,6 +240,14 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
});
}
public void setDataSourceChangedListener(FilterDataSourceChangedListener listener) {
this.listener = listener;
}
public void setListView(ListView listView) {
this.listView = listView;
}
/**
* Create or reuse a view
* @param convertView
@ -347,10 +369,10 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
if (filter instanceof FilterCategory) {
Filter[] children = ((FilterCategory) filter).children;
for (Filter f : children) {
add(f);
addOrLookup(f);
}
} else if (filter instanceof Filter){
add((Filter) filter);
addOrLookup((Filter) filter);
}
}
@ -405,6 +427,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
* application registered to listen for this broadcast. Each application
@ -433,8 +462,7 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
IntentFilter bladeFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS);
bladeFilter.setPriority(1);
activity.registerReceiver(bladeFilterReceiver, bladeFilter);
if(getCount() == 0)
getLists();
getLists();
}
/**

@ -0,0 +1,121 @@
package com.todoroo.astrid.adapter;
import java.util.HashMap;
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 HashMap<Integer, Fragment> positionToFragment;
private final HashMap<Filter, Class<?>> customTaskLists;
private final FilterAdapter filterAdapter; // Shares an adapter instance with the filter list fragment
public TaskListFragmentPagerAdapter(FragmentManager fm, FilterAdapter filterAdapter) {
super(fm);
this.filterAdapter = filterAdapter;
filterAdapter.setDataSourceChangedListener(this);
positionToFragment = new HashMap<Integer, Fragment>();
customTaskLists = new HashMap<Filter, Class<?>>();
}
@Override
public void filterDataSourceChanged() {
notifyDataSetChanged();
}
/**
* Instantiates and returns a fragment for the filter at the specified position.
* Also maps the position to the fragment in a cache for later lookup
*/
@Override
public Fragment getItem(int position) {
Filter filter = filterAdapter.getItem(position);
Fragment fragment = getFragmentForFilter(filter);
positionToFragment.put(position, fragment);
return fragment;
}
/**
* Lookup the fragment for the specified position
* @param position
* @return
*/
public Fragment lookupFragmentForPosition(int position) {
return positionToFragment.get(position);
}
@Override
public CharSequence getPageTitle(int position) {
return filterAdapter.getItem(position).title;
}
/**
* Adds the specified filter to the data source if it doesn't exist,
* returning the position of that filter regardless
* @param filter
* @return
*/
public int addOrLookup(Filter filter) {
return filterAdapter.addOrLookup(filter);
}
/**
* Get the filter at the specified position
* @param position
* @return
*/
public Filter getFilter(int position) {
return filterAdapter.getItem(position);
}
@Override
public int getCount() {
return filterAdapter.getCount();
}
public void setCustomTaskListForFilter(Filter f, Class<?> customTaskList) {
customTaskLists.put(f, customTaskList);
notifyDataSetChanged();
}
public void clearCustomTaskListForFilter(Filter f) {
customTaskLists.remove(f);
}
private Fragment getFragmentForFilter(Filter filter) {
Bundle extras = getExtrasForFilter(filter);
Class<?> customList = customTaskLists.get(filter);
if (customList == null)
customList = TaskListFragment.class;
return TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customList);
}
// Constructs extras corresponding to the specified filter that can be used as arguments to the fragment
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
}
}

@ -3,6 +3,7 @@ package com.todoroo.astrid.helper;
import java.util.concurrent.atomic.AtomicInteger;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.ProgressBar;
@ -18,9 +19,9 @@ public class ProgressBarSyncResultCallback extends SyncResultCallbackAdapter {
private final AtomicInteger providers = new AtomicInteger(0);
public ProgressBarSyncResultCallback(Activity activity,
public ProgressBarSyncResultCallback(Activity activity, Fragment fragment,
int progressBarId, Runnable onFinished) {
this.progressBar = (ProgressBar) activity.findViewById(progressBarId);
this.progressBar = (ProgressBar) fragment.getView().findViewById(progressBarId);
this.activity = activity;
this.onFinished = onFinished;

@ -73,7 +73,7 @@ public class SyncActionHelper {
this.activity = activity;
this.fragment = fragment;
syncResultCallback = new ProgressBarSyncResultCallback(activity,
syncResultCallback = new ProgressBarSyncResultCallback(activity, fragment,
R.id.progressBar, new Runnable() {
@Override
public void run() {

@ -0,0 +1,55 @@
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.activity.TaskListFragment;
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));
}
public void showFilterWithCustomTaskList(Filter f, Class<?> customTaskList) {
TaskListFragmentPagerAdapter adapter = (TaskListFragmentPagerAdapter) getAdapter();
adapter.setCustomTaskListForFilter(f, customTaskList);
showFilter(adapter.addOrLookup(f));
}
/**
* Show the filter at the supplied index, with animation
* @param index
*/
public void showFilter(int index) {
setCurrentItem(index, true);
}
/**
* Returns the currently showing fragment
* @return
*/
public TaskListFragment getCurrentFragment() {
return (TaskListFragment) ((TaskListFragmentPagerAdapter) getAdapter()).lookupFragmentForPosition(getCurrentItem());
}
}

@ -219,7 +219,7 @@ public class TasksWidget extends AppWidgetProvider {
Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
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);
if(filter != null) {
listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);

Loading…
Cancel
Save