Wrap main fragments in frame layouts for easier replacement in transactions later, use tags instead of ids

pull/14/head
Sam Bosley 14 years ago
parent 03c7d2eabb
commit 837b491b19

@ -4,26 +4,34 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.FilterListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/filterlist_fragment" android:id="@+id/filterlist_fragment_container"
android:layout_weight="67"> android:layout_weight="67">
<!-- Preview: layout=@layout/filter_list_activity --> <fragment
</fragment> android:name="com.todoroo.astrid.activity.FilterListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="filterlist_fragment">
<!-- Preview: layout=@layout/filter_list_activity -->
</fragment>
</FrameLayout>
<View <View
android:layout_width="1px" android:layout_width="1px"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#000000"/> android:background="#000000"/>
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/tasklist_fragment" android:id="@+id/tasklist_fragment_container"
android:layout_weight="33"> android:layout_weight="33">
<!-- Preview: layout=@layout/task_list_activity --> <fragment
</fragment> android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="tasklist_fragment">
<!-- Preview: layout=@layout/task_list_activity -->
</fragment>
</FrameLayout>
</LinearLayout> </LinearLayout>

@ -4,26 +4,34 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/tasklist_fragment" android:layout_weight="67"
android:layout_weight="67"> android:id="@+id/tasklist_fragment_container">
<!-- Preview: layout=@layout/task_list_activity --> <fragment
</fragment> android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="tasklist_fragment">
<!-- Preview: layout=@layout/task_list_activity -->
</fragment>
</FrameLayout>
<View <View
android:layout_width="1px" android:layout_width="1px"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#000000"/> android:background="#000000"/>
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.TaskEditActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/taskedit_fragment" android:layout_weight="33"
android:layout_weight="33"> android:id="@+id/taskedit_fragment_container">
<!-- Preview: layout=@layout/task_edit_activity --> <fragment
</fragment> android:name="com.todoroo.astrid.activity.TaskEditActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="taskedit_fragment">
<!-- Preview: layout=@layout/task_edit_activity -->
</fragment>
</FrameLayout>
</LinearLayout> </LinearLayout>

@ -4,26 +4,34 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.FilterListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/filterlist_fragment" android:layout_weight="67"
android:layout_weight="67"> android:id="@+id/filterlist_fragment_container">
<!-- Preview: layout=@layout/filter_list_activity --> <fragment
</fragment> android:name="com.todoroo.astrid.activity.FilterListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/filterlist_fragment">
<!-- Preview: layout=@layout/filter_list_activity -->
</fragment>
</FrameLayout>
<View <View
android:layout_width="1px" android:layout_width="1px"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#000000"/> android:background="#000000"/>
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/tasklist_fragment" android:layout_weight="33"
android:layout_weight="33"> android:id="@+id/tasklist_fragment_container">
<!-- Preview: layout=@layout/task_list_activity --> <fragment
</fragment> android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="tasklist_fragment">
<!-- Preview: layout=@layout/task_list_activity -->
</fragment>
</FrameLayout>
</LinearLayout> </LinearLayout>

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.FilterListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/filterlist_fragment"> android:id="@+id/filterlist_fragment">
</fragment> <fragment
android:name="com.todoroo.astrid.activity.FilterListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="filterlist_fragment">
</fragment>
</FrameLayout>

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.TaskEditActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/taskedit_fragment"> android:id="@+id/taskedit_fragment_container">
</fragment> <fragment
android:name="com.todoroo.astrid.activity.TaskEditActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="taskedit_fragment">
</fragment>
</FrameLayout>

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<fragment <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/tasklist_fragment"> android:id="@+id/tasklist_fragment_container">
</fragment> <fragment
android:name="com.todoroo.astrid.activity.TaskListActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="tasklist_fragment">
</fragment>
</FrameLayout>

@ -48,7 +48,7 @@ public class AstridWrapperActivity extends FragmentActivity
protected TaskListActivity getTaskListFragment() { protected TaskListActivity getTaskListFragment() {
TaskListActivity frag = (TaskListActivity) getSupportFragmentManager() TaskListActivity frag = (TaskListActivity) getSupportFragmentManager()
.findFragmentById(R.id.tasklist_fragment); .findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
if (frag == null || !frag.isInLayout()) if (frag == null || !frag.isInLayout())
return null; return null;
@ -109,7 +109,7 @@ public class AstridWrapperActivity extends FragmentActivity
} else { } else {
// If showing both fragments, directly update the tasklist-fragment // If showing both fragments, directly update the tasklist-fragment
TaskListActivity tasklist = (TaskListActivity) getSupportFragmentManager() TaskListActivity tasklist = (TaskListActivity) getSupportFragmentManager()
.findFragmentById(R.id.tasklist_fragment); .findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
if(item instanceof Filter) { if(item instanceof Filter) {
Filter filter = (Filter)item; Filter filter = (Filter)item;

@ -95,6 +95,8 @@ import com.todoroo.astrid.utility.Constants;
*/ */
public class FilterListActivity extends ExpandableListFragment { public class FilterListActivity extends ExpandableListFragment {
public static final String TAG_FILTERLIST_FRAGMENT = "filterlist_fragment";
// -- extra codes // -- extra codes
//public static final String SHOW_BACK_BUTTON = "show_back"; //$NON-NLS-1$ //public static final String SHOW_BACK_BUTTON = "show_back"; //$NON-NLS-1$
@ -207,7 +209,7 @@ public class FilterListActivity extends ExpandableListFragment {
onNewIntent(getActivity().getIntent()); onNewIntent(getActivity().getIntent());
Fragment tasklistFrame = getFragmentManager().findFragmentById(R.id.tasklist_fragment); Fragment tasklistFrame = getFragmentManager().findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
mDualFragments = (tasklistFrame != null) && tasklistFrame.isInLayout(); mDualFragments = (tasklistFrame != null) && tasklistFrame.isInLayout();
if (mDualFragments) { if (mDualFragments) {
@ -473,7 +475,7 @@ public class FilterListActivity extends ExpandableListFragment {
return true; return true;
} }
default: { default: {
Fragment tasklist = getSupportFragmentManager().findFragmentById(R.id.tasklist_fragment); Fragment tasklist = getSupportFragmentManager().findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
if (tasklist != null && tasklist.isInLayout()) if (tasklist != null && tasklist.isInLayout())
return tasklist.onOptionsItemSelected(item); return tasklist.onOptionsItemSelected(item);
} }

@ -107,6 +107,8 @@ import com.todoroo.astrid.voice.VoiceInputAssistant;
*/ */
public final class TaskEditActivity extends Fragment { public final class TaskEditActivity extends Fragment {
public static final String TAG_TASKEDIT_FRAGMENT = "taskedit_fragment";
// --- bundle tokens // --- bundle tokens
/** /**
@ -290,7 +292,7 @@ public final class TaskEditActivity extends Fragment {
setHasOptionsMenu(true); setHasOptionsMenu(true);
getSupportActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Fragment tasklistFrame = getFragmentManager().findFragmentById(R.id.tasklist_fragment); Fragment tasklistFrame = getFragmentManager().findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
mDualFragments = (tasklistFrame != null) && tasklistFrame.isInLayout(); mDualFragments = (tasklistFrame != null) && tasklistFrame.isInLayout();
setUpUIComponents(); setUpUIComponents();

@ -28,7 +28,7 @@ public class TaskEditWrapperActivity extends AstridWrapperActivity {
super.onResume(); super.onResume();
Fragment frag = (Fragment) getSupportFragmentManager() Fragment frag = (Fragment) getSupportFragmentManager()
.findFragmentById(R.id.tasklist_fragment); .findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
if (frag != null) { if (frag != null) {
mMultipleFragments = true; mMultipleFragments = true;
} else { } else {
@ -39,7 +39,7 @@ public class TaskEditWrapperActivity extends AstridWrapperActivity {
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
TaskEditActivity frag = (TaskEditActivity) getSupportFragmentManager() TaskEditActivity frag = (TaskEditActivity) getSupportFragmentManager()
.findFragmentById(R.id.taskedit_fragment); .findFragmentByTag(TaskEditActivity.TAG_TASKEDIT_FRAGMENT);
if (frag != null && frag.isInLayout()) if (frag != null && frag.isInLayout())
return frag.onKeyDown(keyCode, event); return frag.onKeyDown(keyCode, event);
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
@ -48,7 +48,7 @@ public class TaskEditWrapperActivity extends AstridWrapperActivity {
@Override @Override
public void setTitle(CharSequence title) { public void setTitle(CharSequence title) {
Fragment frag = (Fragment) getSupportFragmentManager() Fragment frag = (Fragment) getSupportFragmentManager()
.findFragmentById(R.id.tasklist_fragment); .findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
if (frag != null && frag.isInLayout()) if (frag != null && frag.isInLayout())
((TextView)frag.getView().findViewById(R.id.listLabel)).setText(title); ((TextView)frag.getView().findViewById(R.id.listLabel)).setText(title);
// update the actionbar-title // update the actionbar-title

@ -128,6 +128,8 @@ import com.todoroo.astrid.widget.TasksWidget;
public class TaskListActivity extends ListFragment implements OnScrollListener, public class TaskListActivity extends ListFragment implements OnScrollListener,
GestureInterface, OnSortSelectedListener { GestureInterface, OnSortSelectedListener {
public static final String TAG_TASKLIST_FRAGMENT = "tasklist_fragment";
// --- activities // --- activities
private static final long BACKGROUND_REFRESH_INTERVAL = 120000L; private static final long BACKGROUND_REFRESH_INTERVAL = 120000L;

Loading…
Cancel
Save