Cleaned up / consolidated fragment logic, implemented three-pane layout

pull/14/head
Tim Su 14 years ago
parent 41b672928d
commit b79c666f22

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- Filter List -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="33"
android:background="@android:color/white"
android:id="@+id/filterlist_fragment_container" />
<View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="#000000"/>
<!-- Task List -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="33"
android:id="@+id/tasklist_fragment_container" />
<View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="#000000"/>
<!-- Task Edit -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="33"
android:id="@+id/taskedit_fragment_container"
android:visibility="invisible" />
</LinearLayout>

@ -4,21 +4,25 @@
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">
<!-- Filter List -->
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="67" android:layout_weight="67"
android:background="@android:color/white" android:background="@android:color/white"
android:id="@+id/filterlist_fragment_container"> android:id="@+id/filterlist_fragment_container" />
</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"/>
<!-- Task List -->
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="33" android:layout_weight="33"
android:id="@+id/tasklist_fragment_container"> android:id="@+id/tasklist_fragment_container" />
</FrameLayout>
</LinearLayout> </LinearLayout>

@ -2,10 +2,11 @@ package com.todoroo.astrid.activity;
import android.app.PendingIntent.CanceledException; import android.app.PendingIntent.CanceledException;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.view.View;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
@ -33,11 +34,11 @@ public class AstridWrapperActivity extends FragmentActivity
TaskListActivity.OnTaskListItemClickedListener, TaskListActivity.OnTaskListItemClickedListener,
TaskEditActivity.OnTaskEditDetailsClickedListener { TaskEditActivity.OnTaskEditDetailsClickedListener {
/** This flag shows if the landscape-multipane layouts are active. public static final int LAYOUT_SINGLE = 0;
* If a multipane-layout with two fragments is active, the callbacks implemented here public static final int LAYOUT_DOUBLE = 1;
* should not start a new activity, but update the target-fragment directly instead. public static final int LAYOUT_TRIPLE = 2;
*/
protected boolean mMultipleFragments = false; protected int fragmentLayout = LAYOUT_SINGLE;
public FilterListActivity getFilterListFragment() { public FilterListActivity getFilterListFragment() {
FilterListActivity frag = (FilterListActivity) getSupportFragmentManager() FilterListActivity frag = (FilterListActivity) getSupportFragmentManager()
@ -60,23 +61,11 @@ public class AstridWrapperActivity extends FragmentActivity
return frag; return frag;
} }
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#onNewIntent(android.content.Intent)
*/
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
FilterListActivity frag = getFilterListFragment(); FilterListActivity frag = getFilterListFragment();
if (frag != null) { if (frag != null) {
// forwarding for search-requests
frag.onNewIntent(intent); frag.onNewIntent(intent);
} }
} }
@ -109,6 +98,7 @@ public class AstridWrapperActivity extends FragmentActivity
setIntent(intent); setIntent(intent);
setupTasklistFragmentWithFilter(filter); setupTasklistFragmentWithFilter(filter);
// no animation for dualpane-layout // no animation for dualpane-layout
AndroidUtilities.callOverridePendingTransition(this, 0, 0); AndroidUtilities.callOverridePendingTransition(this, 0, 0);
StatisticsService.reportEvent(StatisticsConstants.FILTER_LIST); StatisticsService.reportEvent(StatisticsConstants.FILTER_LIST);
@ -146,37 +136,15 @@ public class AstridWrapperActivity extends FragmentActivity
} }
} }
protected void setupFilterlistFragment() {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
FilterListActivity newFragment = new FilterListActivity();
if (findViewById(R.id.filterlist_fragment_container) != null) {
if (getFilterListFragment() != null) {
transaction.remove(getFilterListFragment());
transaction.commit();
transaction = manager.beginTransaction();
}
transaction.replace(R.id.filterlist_fragment_container, newFragment,
FilterListActivity.TAG_FILTERLIST_FRAGMENT);
} else {
if (getFilterListFragment() != null)
return;
transaction.add(newFragment, FilterListActivity.TAG_FILTERLIST_FRAGMENT);
}
transaction.commit();
}
public boolean isMultipleFragments() {
return mMultipleFragments;
}
@Override @Override
public void onTaskListItemClicked(long taskId) { public void onTaskListItemClicked(long taskId) {
Intent intent = new Intent(this, TaskEditWrapperActivity.class); Intent intent = new Intent(this, TaskEditWrapperActivity.class);
intent.putExtra(TaskEditActivity.TOKEN_ID, taskId); intent.putExtra(TaskEditActivity.TOKEN_ID, taskId);
if (getIntent().hasExtra(TaskListActivity.TOKEN_FILTER)) if (getIntent().hasExtra(TaskListActivity.TOKEN_FILTER))
intent.putExtra(TaskListActivity.TOKEN_FILTER, getIntent().getParcelableExtra(TaskListActivity.TOKEN_FILTER)); intent.putExtra(TaskListActivity.TOKEN_FILTER, getIntent().getParcelableExtra(TaskListActivity.TOKEN_FILTER));
if (this instanceof TaskEditWrapperActivity) {
if (this instanceof TaskEditWrapperActivity || fragmentLayout == LAYOUT_TRIPLE) {
findViewById(R.id.taskedit_fragment_container).setVisibility(View.VISIBLE);
TaskEditActivity editActivity = getTaskEditFragment(); TaskEditActivity editActivity = getTaskEditFragment();
editActivity.save(true); editActivity.save(true);
editActivity.repopulateFromScratch(intent); editActivity.repopulateFromScratch(intent);
@ -188,7 +156,54 @@ public class AstridWrapperActivity extends FragmentActivity
@Override @Override
public void onTaskEditDetailsClicked(int category, int position) { public void onTaskEditDetailsClicked(int category, int position) {
// TODO Auto-generated method stub //
}
// --- fragment helpers
protected void removeFragment(String tag) {
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentByTag(tag);
if(fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
}
protected void setupFragment(String tag, int container, Class<? extends Fragment> cls) {
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentByTag(tag);
if(fragment == null) {
System.err.println("creating fragment of type " + cls.getSimpleName()); //$NON-NLS-1$
try {
fragment = cls.newInstance();
} catch (InstantiationException e) {
return;
} catch (IllegalAccessException e) {
return;
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(container, fragment, tag);
ft.commit();
}
} }
/**
* @return LAYOUT_SINGLE, LAYOUT_DOUBLE, or LAYOUT_TRIPLE
*/
public int getFragmentLayout() {
return fragmentLayout;
}
/**
* @deprecated please use the getFragmentLayout method instead
*/
@Deprecated
public boolean isMultipleFragments() {
return fragmentLayout != LAYOUT_SINGLE;
}
} }

@ -253,9 +253,6 @@ public final class TaskEditActivity extends Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Tell the framework to try to keep this fragment around
// during a configuration change.
setRetainInstance(true);
new StartupService().onStartupApplication(getActivity()); new StartupService().onStartupApplication(getActivity());
@ -545,7 +542,11 @@ public final class TaskEditActivity extends Fragment {
public void run() { public void run() {
AndroidUtilities.sleepDeep(500L); AndroidUtilities.sleepDeep(500L);
getActivity().runOnUiThread(new Runnable() { Activity activity = getActivity();
if(activity == null)
return;
activity.runOnUiThread(new Runnable() {
public void run() { public void run() {
onUiThread(); onUiThread();
} }

@ -6,7 +6,6 @@ import android.support.v4.app.Fragment;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.widget.TextView; import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
@ -39,9 +38,9 @@ public class TaskEditWrapperActivity extends AstridWrapperActivity {
Fragment frag = (Fragment) getSupportFragmentManager() Fragment frag = (Fragment) getSupportFragmentManager()
.findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT); .findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
if (frag != null) { if (frag != null) {
mMultipleFragments = true; fragmentLayout = LAYOUT_DOUBLE;
} else { } else {
mMultipleFragments = false; fragmentLayout = LAYOUT_SINGLE;
} }
} }

@ -50,23 +50,41 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
listsNav = actionBar.getCustomView().findViewById(R.id.lists_nav); listsNav = actionBar.getCustomView().findViewById(R.id.lists_nav);
lists = (TextView) actionBar.getCustomView().findViewById(R.id.list_title); lists = (TextView) actionBar.getCustomView().findViewById(R.id.list_title);
View container = findViewById(R.id.filterlist_fragment_container); initializeFragments(actionBar);
if (container != null) { }
mMultipleFragments = true;
/**
*
* @param actionBar
*/
protected void initializeFragments(ActionBar actionBar) {
View filterFragment = findViewById(R.id.filterlist_fragment_container);
View editFragment = findViewById(R.id.taskedit_fragment_container);
if (filterFragment != null) {
actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.getCustomView().findViewById(R.id.list_disclosure_arrow).setVisibility(View.GONE); actionBar.getCustomView().findViewById(R.id.list_disclosure_arrow).setVisibility(View.GONE);
listsNav.setOnClickListener(null); listsNav.setOnClickListener(null);
if(editFragment != null) {
fragmentLayout = LAYOUT_TRIPLE;
setupFragment(TaskEditActivity.TAG_TASKEDIT_FRAGMENT,
R.id.taskedit_fragment_container, TaskEditActivity.class);
} else {
fragmentLayout = LAYOUT_DOUBLE;
}
setupFragment(FilterListActivity.TAG_FILTERLIST_FRAGMENT,
R.id.filterlist_fragment_container, FilterListActivity.class);
} else { } else {
mMultipleFragments = false; fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
listsNav.setOnClickListener(popupMenuClickListener); listsNav.setOnClickListener(popupMenuClickListener);
createPopover(); createPopover();
} }
setupFilterlistFragment(); }
}
private void createPopover() { private void createPopover() {
popover = new ListDropdownPopover(TaskListWrapperActivity.this); popover = new ListDropdownPopover(TaskListWrapperActivity.this);
popover.setOnDismissListener(new OnDismissListener() { popover.setOnDismissListener(new OnDismissListener() {
@Override @Override
@ -102,19 +120,6 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
listsNav.setBackgroundColor(selected ? oldTextColor : android.R.color.transparent); listsNav.setBackgroundColor(selected ? oldTextColor : android.R.color.transparent);
} }
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onResume()
*/
@Override
protected void onResume() {
super.onResume();
FilterListActivity fla = getFilterListFragment();
if (fla != null) {
fla.adapter.clear();
}
}
@Override @Override
protected void onPostResume() { protected void onPostResume() {
super.onPostResume(); super.onPostResume();
@ -132,11 +137,6 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
popover.dismiss(); popover.dismiss();
} }
@Override
protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
}
public void setSelectedItem(Filter item) { public void setSelectedItem(Filter item) {
lists.setText(item.title); lists.setText(item.title);
} }

Loading…
Cancel
Save