Buggy, but I can swipe between lists when starting from active tasks

pull/14/head
Sam Bosley 13 years ago
parent 819b1aa792
commit 5faaa1cf18

@ -102,6 +102,8 @@ public class Filter extends FilterListItem {
this.valuesForNewTasks = valuesForNewTasks;
}
/**
* Utility constructor
*
@ -121,6 +123,38 @@ public class Filter extends FilterListItem {
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}
*/

@ -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>

@ -200,11 +200,11 @@ public class AstridActivity extends FragmentActivity
transaction.commit();
}
protected final void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
protected void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, TaskListFragment.class);
}
protected final void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
protected void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
TaskListFragment newFragment = TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customTaskList);
try {
@ -285,8 +285,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) {
System.err.println("creating fragment of type " + cls.getSimpleName()); //$NON-NLS-1$
@ -304,6 +304,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;
}

@ -132,6 +132,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$
@ -288,8 +290,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);

@ -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.MotionEvent;
@ -29,9 +30,12 @@ import com.todoroo.astrid.actfm.ActFmLoginActivity;
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;
@ -43,11 +47,12 @@ 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;
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$
@ -60,6 +65,9 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
private ImageView mainMenu;
private Button commentsButton;
private TaskListFragmentPager tlfPager;
private TaskListFragmentPagerAdapter tlfPagerAdapter;
private FragmentPopover listsPopover;
private FragmentPopover editPopover;
private FragmentPopover commentsPopover;
@ -147,9 +155,24 @@ 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(TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == Constants.SOURCE_NOTIFICATION)
setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, extras, NotificationFragment.class);
else
@ -163,6 +186,24 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
}
}
@Override
protected 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
protected 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);
}
}
/**
*
* @param actionBar
@ -186,13 +227,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));
}
}
@ -280,6 +321,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);
}
@ -343,6 +389,19 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
lists.setText(item.title);
}
@Override
public void onPageSelected(int position) {
if (tlfPagerAdapter != null)
setListsTitle(tlfPagerAdapter.getPageTitle(position).toString());
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {}
@Override
public void onPageScrollStateChanged(int state) {}
public void setCommentsCount(int count) {
TypedValue tv = new TypedValue();

@ -54,6 +54,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;
@ -68,7 +72,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();
@ -92,6 +96,8 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
private int mSelectedIndex;
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
@ -164,10 +170,24 @@ 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;
}
public void setDataSourceChangedListener(FilterDataSourceChangedListener listener) {
this.listener = listener;
}
public void setListView(ListView listView) {
this.listView = listView;
}
/**
* Create or reuse a view
@ -293,10 +313,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);
}
}
@ -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
* application registered to listen for this broadcast. Each application
@ -379,8 +406,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();
}
/**

@ -6,26 +6,42 @@ 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 {
public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter implements FilterDataSourceChangedListener {
private final Filter[] filters;
private final FilterAdapter filterAdapter;
public TaskListFragmentPagerAdapter(FragmentManager fm, Filter[] filters) {
public TaskListFragmentPagerAdapter(FragmentManager fm, FilterAdapter filterAdapter) {
super(fm);
this.filters = filters;
this.filterAdapter = filterAdapter;
filterAdapter.setDataSourceChangedListener(this);
}
@Override
public void filterDataSourceChanged() {
notifyDataSetChanged();
}
@Override
public Fragment getItem(int position) {
return getFragmentForFilter(filters[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);
}
@Override
public int getCount() {
return filters.length;
return filterAdapter.getCount();
}
private Fragment getFragmentForFilter(Filter filter) {
@ -40,7 +56,8 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter {
} else {
extras = new Bundle();
}
extras.putParcelable(TaskListFragment.TOKEN_FILTER, filter);
if (filter != null)
extras.putParcelable(TaskListFragment.TOKEN_FILTER, filter);
return extras;
}

@ -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);
}
}
Loading…
Cancel
Save