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

pull/14/head
Tim Su 13 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_height="match_parent"
android:orientation="horizontal">
<!-- Filter List -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="67"
android:background="@android:color/white"
android:id="@+id/filterlist_fragment_container">
</FrameLayout>
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">
</FrameLayout>
android:id="@+id/tasklist_fragment_container" />
</LinearLayout>

@ -2,10 +2,11 @@ package com.todoroo.astrid.activity;
import android.app.PendingIntent.CanceledException;
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.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities;
@ -33,11 +34,11 @@ public class AstridWrapperActivity extends FragmentActivity
TaskListActivity.OnTaskListItemClickedListener,
TaskEditActivity.OnTaskEditDetailsClickedListener {
/** This flag shows if the landscape-multipane layouts are active.
* If a multipane-layout with two fragments is active, the callbacks implemented here
* should not start a new activity, but update the target-fragment directly instead.
*/
protected boolean mMultipleFragments = false;
public static final int LAYOUT_SINGLE = 0;
public static final int LAYOUT_DOUBLE = 1;
public static final int LAYOUT_TRIPLE = 2;
protected int fragmentLayout = LAYOUT_SINGLE;
public FilterListActivity getFilterListFragment() {
FilterListActivity frag = (FilterListActivity) getSupportFragmentManager()
@ -60,23 +61,11 @@ public class AstridWrapperActivity extends FragmentActivity
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
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
FilterListActivity frag = getFilterListFragment();
if (frag != null) {
// forwarding for search-requests
frag.onNewIntent(intent);
}
}
@ -109,6 +98,7 @@ public class AstridWrapperActivity extends FragmentActivity
setIntent(intent);
setupTasklistFragmentWithFilter(filter);
// no animation for dualpane-layout
AndroidUtilities.callOverridePendingTransition(this, 0, 0);
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
public void onTaskListItemClicked(long taskId) {
Intent intent = new Intent(this, TaskEditWrapperActivity.class);
intent.putExtra(TaskEditActivity.TOKEN_ID, taskId);
if (getIntent().hasExtra(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();
editActivity.save(true);
editActivity.repopulateFromScratch(intent);
@ -188,7 +156,54 @@ public class AstridWrapperActivity extends FragmentActivity
@Override
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
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Tell the framework to try to keep this fragment around
// during a configuration change.
setRetainInstance(true);
new StartupService().onStartupApplication(getActivity());
@ -545,7 +542,11 @@ public final class TaskEditActivity extends Fragment {
public void run() {
AndroidUtilities.sleepDeep(500L);
getActivity().runOnUiThread(new Runnable() {
Activity activity = getActivity();
if(activity == null)
return;
activity.runOnUiThread(new Runnable() {
public void run() {
onUiThread();
}

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

@ -50,23 +50,41 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
listsNav = actionBar.getCustomView().findViewById(R.id.lists_nav);
lists = (TextView) actionBar.getCustomView().findViewById(R.id.list_title);
View container = findViewById(R.id.filterlist_fragment_container);
if (container != null) {
mMultipleFragments = true;
initializeFragments(actionBar);
}
/**
*
* @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.getCustomView().findViewById(R.id.list_disclosure_arrow).setVisibility(View.GONE);
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 {
mMultipleFragments = false;
fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true);
listsNav.setOnClickListener(popupMenuClickListener);
createPopover();
}
setupFilterlistFragment();
}
}
private void createPopover() {
private void createPopover() {
popover = new ListDropdownPopover(TaskListWrapperActivity.this);
popover.setOnDismissListener(new OnDismissListener() {
@Override
@ -102,19 +120,6 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
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
protected void onPostResume() {
super.onPostResume();
@ -132,11 +137,6 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
popover.dismiss();
}
@Override
protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
}
public void setSelectedItem(Filter item) {
lists.setText(item.title);
}

Loading…
Cancel
Save