Merge remote-tracking branch 'origin/120203_sb_leave_shared_lists' into 4.0

pull/14/head
Sam Bosley 14 years ago
commit 896f40d9a3

@ -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";
} }

@ -54,6 +54,7 @@ import com.todoroo.astrid.tags.TagService.Tag;
public class TagFilterExposer extends BroadcastReceiver implements AstridFilterExposer { public class TagFilterExposer extends BroadcastReceiver implements AstridFilterExposer {
private static final String TAG = "tag"; //$NON-NLS-1$ private static final String TAG = "tag"; //$NON-NLS-1$
public static final String TAG_SQL = "tagSql"; //$NON-NLS-1$
@Autowired TagDataService tagDataService; @Autowired TagDataService tagDataService;
@Autowired GtasksPreferenceService gtasksPreferenceService; @Autowired GtasksPreferenceService gtasksPreferenceService;
@ -76,13 +77,20 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
filter.color = Color.GRAY; filter.color = Color.GRAY;
} }
TagData tagData = PluginServices.getTagDataService().getTag(tag.tag, TagData.ID, TagData.USER_ID, TagData.MEMBER_COUNT);
int deleteIntentLabel;
if (tagData.getValue(TagData.MEMBER_COUNT) > 0 && tagData.getValue(TagData.USER_ID) != 0)
deleteIntentLabel = R.string.tag_cm_leave;
else
deleteIntentLabel = R.string.tag_cm_delete;
filter.contextMenuLabels = new String[] { filter.contextMenuLabels = new String[] {
context.getString(R.string.tag_cm_rename), context.getString(R.string.tag_cm_rename),
context.getString(R.string.tag_cm_delete) context.getString(deleteIntentLabel)
}; };
filter.contextMenuIntents = new Intent[] { filter.contextMenuIntents = new Intent[] {
newTagIntent(context, RenameTagActivity.class, tag), newTagIntent(context, RenameTagActivity.class, tag, tagTemplate.toString()),
newTagIntent(context, DeleteTagActivity.class, tag) newTagIntent(context, DeleteTagActivity.class, tag, tagTemplate.toString())
}; };
filter.customTaskList = new ComponentName(ContextManager.getContext(), TagViewFragment.class); filter.customTaskList = new ComponentName(ContextManager.getContext(), TagViewFragment.class);
if(tag.image != null) if(tag.image != null)
@ -106,9 +114,10 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
return filterFromTag(context, tag, TaskCriteria.activeAndVisible()); return filterFromTag(context, tag, TaskCriteria.activeAndVisible());
} }
private static Intent newTagIntent(Context context, Class<? extends Activity> activity, Tag tag) { private static Intent newTagIntent(Context context, Class<? extends Activity> activity, Tag tag, String sql) {
Intent ret = new Intent(context, activity); Intent ret = new Intent(context, activity);
ret.putExtra(TAG, tag.tag); ret.putExtra(TAG, tag.tag);
ret.putExtra(TAG_SQL, sql);
return ret; return ret;
} }
@ -168,6 +177,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
public abstract static class TagActivity extends Activity { public abstract static class TagActivity extends Activity {
protected String tag; protected String tag;
protected String sql;
@Autowired public TagService tagService; @Autowired public TagService tagService;
@Autowired public TagDataService tagDataService; @Autowired public TagDataService tagDataService;
@ -181,6 +191,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
tag = getIntent().getStringExtra(TAG); tag = getIntent().getStringExtra(TAG);
sql = getIntent().getStringExtra(TAG_SQL);
if(tag == null) { if(tag == null) {
finish(); finish();
return; return;
@ -188,12 +199,12 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT); TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT, TagData.USER_ID);
if(tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0) { if(tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0 && tagData.getValue(TagData.USER_ID) == 0) {
DialogUtilities.okDialog(this, getString(R.string.actfm_tag_operation_disabled), getCancelListener()); DialogUtilities.okCancelDialog(this, getString(R.string.actfm_tag_operation_owner_delete), getOkListener(), getCancelListener());
return; return;
} }
showDialog(); showDialog(tagData);
} }
protected DialogInterface.OnClickListener getOkListener() { protected DialogInterface.OnClickListener getOkListener() {
@ -234,7 +245,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
protected abstract void showDialog(); protected abstract void showDialog(TagData tagData);
protected abstract boolean ok(); protected abstract boolean ok();
} }
@ -242,20 +253,32 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
public static class DeleteTagActivity extends TagActivity { public static class DeleteTagActivity extends TagActivity {
@Override @Override
protected void showDialog() { protected void showDialog(TagData tagData) {
DialogUtilities.okCancelDialog(this, getString(R.string.DLG_delete_this_tag_question, tag), getOkListener(), getCancelListener()); int string;
if (tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0)
string = R.string.DLG_leave_this_shared_tag_question;
else
string = R.string.DLG_delete_this_tag_question;
DialogUtilities.okCancelDialog(this, getString(string, tag), getOkListener(), getCancelListener());
} }
@Override @Override
protected boolean ok() { protected boolean ok() {
int deleted = tagService.delete(tag); int deleted = tagService.delete(tag);
TagData tagData = PluginServices.getTagDataService().getTag(tag, TagData.ID, TagData.DELETION_DATE); TagData tagData = PluginServices.getTagDataService().getTag(tag, TagData.ID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
boolean shared = false;
if(tagData != null) { if(tagData != null) {
tagData.setValue(TagData.DELETION_DATE, DateUtilities.now()); tagData.setValue(TagData.DELETION_DATE, DateUtilities.now());
PluginServices.getTagDataService().save(tagData); PluginServices.getTagDataService().save(tagData);
shared = tagData.getValue(TagData.MEMBER_COUNT) > 0 && tagData.getValue(TagData.USER_ID) != 0; // Was I a list member and NOT owner?
} }
Toast.makeText(this, getString(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);
tagDeleted.putExtra(TAG_SQL, sql);
sendBroadcast(tagDeleted);
return true; return true;
} }
@ -266,7 +289,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
private EditText editor; private EditText editor;
@Override @Override
protected void showDialog() { protected void showDialog(TagData tagData) {
editor = new EditText(this); editor = new EditText(this);
DialogUtilities.viewDialog(this, getString(R.string.DLG_rename_this_tag_header, tag), editor, getOkListener(), getCancelListener()); DialogUtilities.viewDialog(this, getString(R.string.DLG_rename_this_tag_header, tag), editor, getOkListener(), getCancelListener());
} }

@ -22,6 +22,9 @@
<!-- can't rename or delete shared tag message --> <!-- can't rename or delete shared tag message -->
<string name="actfm_tag_operation_disabled">Sorry, this operation is not yet supported for shared tags.</string> <string name="actfm_tag_operation_disabled">Sorry, this operation is not yet supported for shared tags.</string>
<!-- warning before deleting a list you're the owner of -->
<string name="actfm_tag_operation_owner_delete">You are the owner of this shared list! If you delete it, it will be deleted for all list members. Are you sure you want to continue?</string>
<!-- menu item to take a picture --> <!-- menu item to take a picture -->
<string name="actfm_picture_camera">Take a Picture</string> <string name="actfm_picture_camera">Take a Picture</string>

@ -69,9 +69,15 @@
<!-- context menu option to delete a tag --> <!-- context menu option to delete a tag -->
<string name="tag_cm_delete">Delete List</string> <string name="tag_cm_delete">Delete List</string>
<!-- Dialog to confirm deletion of a tag --> <!-- context menu option to leave a shared list -->
<string name="tag_cm_leave">Leave List</string>
<!-- Dialog to confirm deletion of a tag (%s -> the name of the list to be deleted) -->
<string name="DLG_delete_this_tag_question">Delete this list: %s? (No tasks will be deleted.)</string> <string name="DLG_delete_this_tag_question">Delete this list: %s? (No tasks will be deleted.)</string>
<!-- Dialog to confirm leaving a shared tag (%s -> the name of the shared list to leave) -->
<string name="DLG_leave_this_shared_tag_question">Leave this shared list: %s? (No tasks will be deleted.)</string>
<!-- Dialog to rename tag --> <!-- Dialog to rename tag -->
<string name="DLG_rename_this_tag_header">Rename the list %s to:</string> <string name="DLG_rename_this_tag_header">Rename the list %s to:</string>
@ -81,6 +87,9 @@
<!-- Toast notification that a tag has been deleted --> <!-- Toast notification that a tag has been deleted -->
<string name="TEA_tags_deleted">List %1$s was deleted, affecting %2$d tasks</string> <string name="TEA_tags_deleted">List %1$s was deleted, affecting %2$d tasks</string>
<!-- Toast notification that a shared tag has been left -->
<string name="TEA_tags_left">You left shared list %1$s, affecting %2$d tasks</string>
<!-- Toast notification that a tag has been renamed --> <!-- Toast notification that a tag has been renamed -->
<string name="TEA_tags_renamed">Renamed %1$s with %2$s for %3$d tasks</string> <string name="TEA_tags_renamed">Renamed %1$s with %2$s for %3$d tasks</string>

@ -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,10 +25,13 @@ 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;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.ui.FragmentPopover; import com.todoroo.astrid.ui.FragmentPopover;
import com.todoroo.astrid.ui.MainMenuPopover; import com.todoroo.astrid.ui.MainMenuPopover;
import com.todoroo.astrid.ui.MainMenuPopover.MainMenuListener; import com.todoroo.astrid.ui.MainMenuPopover.MainMenuListener;
@ -47,6 +53,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 +284,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 +303,12 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
commentsPopover.dismiss(); commentsPopover.dismiss();
} }
@Override
protected void onStop() {
super.onStop();
unregisterReceiver(tagDeletedReceiver);
}
public void setSelectedItem(Filter item) { public void setSelectedItem(Filter item) {
lists.setText(item.title); lists.setText(item.title);
} }
@ -365,4 +385,24 @@ 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 deletedTagSql = intent.getStringExtra(TagFilterExposer.TAG_SQL);
FilterListFragment fl = getFilterListFragment();
if (fl != null) {
Filter currentlyShowing = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER);
if (currentlyShowing != null) {
boolean titlesMatch = currentlyShowing.title != null && currentlyShowing.title.equals(deletedTag);
boolean sqlMatches = currentlyShowing.sqlQuery != null && currentlyShowing.sqlQuery.equals(deletedTagSql);
if (titlesMatch && sqlMatches)
fl.switchToActiveTasks();
}
fl.clear(); // Should auto refresh
}
}
}
} }

Loading…
Cancel
Save