Started refactoring to have fragment instantiation take care of choosing the subtasks fragment to use, mostly working

pull/14/head
Sam Bosley 12 years ago
parent 329503a866
commit 5c669f0b0e

@ -15,7 +15,6 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
@ -38,7 +37,6 @@ import com.todoroo.astrid.api.FilterCategory;
import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.FilterWithUpdate;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
@ -46,9 +44,7 @@ import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.subtasks.SubtasksTagListFragment;
import com.todoroo.astrid.tags.TagService.Tag;
import com.todoroo.astrid.utility.AstridPreferences;
/**
* Exposes filters based on tags
@ -98,12 +94,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
newTagIntent(context, DeleteTagActivity.class, tag, tagTemplate.toString())
};
SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(context);
int sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0);
Class<?> fragmentClass = SortHelper.isManualSort(sortFlags) ?
SubtasksTagListFragment.class : TagViewFragment.class;
filter.customTaskList = new ComponentName(ContextManager.getContext(), fragmentClass);
filter.customTaskList = new ComponentName(ContextManager.getContext(), TagViewFragment.class);
if(tag.image != null)
filter.imageUrl = tag.image;
Bundle extras = new Bundle();

@ -27,6 +27,7 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagUpdatesFragment;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem;
@ -42,6 +43,7 @@ import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.subtasks.SubtasksListFragment;
import com.todoroo.astrid.subtasks.SubtasksTagListFragment;
import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.ui.QuickAddBar;
import com.todoroo.astrid.utility.AstridPreferences;
@ -206,10 +208,10 @@ public class AstridActivity extends FragmentActivity
}
public void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) {
Class<?> customTaskList = TaskListFragment.class;
Class<?> customTaskList = null;
if (shouldUseSubtasksFragmentForFilter(filter))
customTaskList = SubtasksListFragment.class;
customTaskList = subtasksClassForFilter(filter);
setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList);
}
@ -235,9 +237,9 @@ public class AstridActivity extends FragmentActivity
}
}
public boolean shouldUseSubtasksFragmentForFilter(Filter filter) {
if(filter == null || CoreFilterExposer.isInbox(filter)) {
SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(this);
public static boolean shouldUseSubtasksFragmentForFilter(Filter filter) {
if(filter == null || CoreFilterExposer.isInbox(filter) || isTagFilter(filter)) {
SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(ContextManager.getContext());
int sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0);
if(SortHelper.isManualSort(sortFlags))
return true;
@ -245,6 +247,20 @@ public class AstridActivity extends FragmentActivity
return false;
}
public static Class<?> subtasksClassForFilter(Filter filter) {
if (isTagFilter(filter))
return SubtasksTagListFragment.class;
return SubtasksListFragment.class;
}
private static boolean isTagFilter(Filter filter) {
if (filter instanceof FilterWithCustomIntent) {
return ((FilterWithCustomIntent) filter).customTaskList.getClassName().equals(
TagViewFragment.class.getName());
}
return false;
}
@Override
public void onTaskListItemClicked(long taskId) {
Intent intent = new Intent(this, TaskEditActivity.class);

@ -238,13 +238,16 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
@SuppressWarnings("nls")
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras, Class<?> customComponent) {
Class<?> component = customComponent;
if (filter instanceof FilterWithCustomIntent) {
if (filter instanceof FilterWithCustomIntent && component == null) {
try {
component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName());
} catch (Exception e) {
// Invalid
}
}
if (component == null)
component = TaskListFragment.class;
TaskListFragment newFragment;
try {
newFragment = (TaskListFragment) component.newInstance();
@ -269,7 +272,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
* @return
*/
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras) {
return instantiateWithFilterAndExtras(filter, extras, TaskListFragment.class);
return instantiateWithFilterAndExtras(filter, extras, null);
}
/**

@ -13,6 +13,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.adapter.FilterAdapter.FilterDataSourceChangedListener;
import com.todoroo.astrid.api.Filter;
@ -108,8 +109,8 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
private Fragment getFragmentForFilter(Filter filter) {
Bundle extras = getExtrasForFilter(filter);
Class<?> customList = customTaskLists.get(filter);
if (customList == null)
customList = TaskListFragment.class;
if (AstridActivity.shouldUseSubtasksFragmentForFilter(filter))
customList = AstridActivity.subtasksClassForFilter(filter);
return TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customList);
}

Loading…
Cancel
Save