If the currently active list is deleted, switch to active tasks

pull/14/head
Sam Bosley 13 years ago
parent c39a466b5e
commit f41a1b3de9

@ -262,4 +262,9 @@ public class AstridApiConstants {
*/ */
public static final String BROADCAST_EVENT_TASK_REPEATED = PACKAGE + ".TASK_REPEATED"; public static final String BROADCAST_EVENT_TASK_REPEATED = PACKAGE + ".TASK_REPEATED";
/**
* Action name for broadcast intent notifying that tag was deleted
*/
public static final String BROADCAST_EVENT_TAG_DELETED = PACKAGE + ".TAG_DELETED";
} }

@ -270,6 +270,10 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
} }
Toast.makeText(this, getString(shared ? R.string.TEA_tags_left : R.string.TEA_tags_deleted, tag, deleted), Toast.makeText(this, getString(shared ? R.string.TEA_tags_left : R.string.TEA_tags_deleted, tag, deleted),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
Intent tagDeleted = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED);
tagDeleted.putExtra(TagViewFragment.EXTRA_TAG_NAME, tag);
sendBroadcast(tagDeleted);
return true; return true;
} }

@ -352,12 +352,21 @@ public class FilterListFragment extends ListFragment {
if (mDualFragments) if (mDualFragments)
getListView().setItemChecked(position, true); getListView().setItemChecked(position, true);
Filter item = adapter.getItem(position); Filter item = adapter.getItem(position);
setFilterItemSelected(item, position);
}
private void setFilterItemSelected(Filter item, int position) {
mSelectedIndex = position; mSelectedIndex = position;
adapter.setLastSelected(mSelectedIndex); adapter.setLastSelected(mSelectedIndex);
getActivity().getIntent().putExtra(TOKEN_LAST_SELECTED, mSelectedIndex); getActivity().getIntent().putExtra(TOKEN_LAST_SELECTED, mSelectedIndex);
mListener.onFilterItemClicked(item); mListener.onFilterItemClicked(item);
} }
public void switchToActiveTasks() {
if (adapter.getCount() > 0)
setFilterItemSelected(adapter.getItem(0), 0);
}
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {

@ -1,7 +1,10 @@
package com.todoroo.astrid.activity; package com.todoroo.astrid.activity;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActionBar; import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -22,6 +25,8 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.ActFmLoginActivity; import com.todoroo.astrid.actfm.ActFmLoginActivity;
import com.todoroo.astrid.actfm.TagSettingsActivity; import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.actfm.TagUpdatesFragment; 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.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.reminders.NotificationFragment; import com.todoroo.astrid.reminders.NotificationFragment;
@ -47,6 +52,8 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
private FragmentPopover commentsPopover; private FragmentPopover commentsPopover;
private MainMenuPopover mainMenuPopover; private MainMenuPopover mainMenuPopover;
private final TagDeletedReceiver tagDeletedReceiver = new TagDeletedReceiver();
private final OnClickListener mainMenuClickListener = new OnClickListener() { private final OnClickListener mainMenuClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -276,6 +283,12 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
lists.setText(title); lists.setText(title);
} }
@Override
protected void onResume() {
super.onResume();
registerReceiver(tagDeletedReceiver, new IntentFilter(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED));
}
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
@ -289,6 +302,13 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
commentsPopover.dismiss(); commentsPopover.dismiss();
} }
@Override
protected void onStop() {
super.onStop();
System.err.println("Unregistering");
unregisterReceiver(tagDeletedReceiver);
}
public void setSelectedItem(Filter item) { public void setSelectedItem(Filter item) {
lists.setText(item.title); lists.setText(item.title);
} }
@ -365,4 +385,19 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
break; break;
} }
} }
private class TagDeletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String deletedTag = intent.getStringExtra(TagViewFragment.EXTRA_TAG_NAME);
String currentlyShowing = getIntent().getStringExtra(TagViewFragment.EXTRA_TAG_NAME);
if (currentlyShowing != null && currentlyShowing.equals(deletedTag)) {
FilterListFragment fl = getFilterListFragment();
if (fl != null) {
fl.switchToActiveTasks();
}
}
}
}
} }

Loading…
Cancel
Save