Fixed several bugs with how tag deleting and renaming from long press work

pull/14/head
Sam Bosley 11 years ago
parent b9a768a470
commit 312104dead

@ -588,11 +588,10 @@ public class TagSettingsActivity extends FragmentActivity {
}, null ); }, null );
} }
protected boolean deleteTag() { protected void deleteTag() {
boolean result = tagService.deleteOrLeaveTag(this, tagData.getValue(TagData.NAME), tagData.getUuid()); Intent result = tagService.deleteOrLeaveTag(this, tagData.getValue(TagData.NAME), tagData.getUuid());
setResult(Activity.RESULT_OK); setResult(Activity.RESULT_OK, result);
finish(); finish();
return result;
} }
} }

@ -232,8 +232,9 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
try { try {
if (ok()) { Intent result = ok();
setResult(RESULT_OK); if (result != null) {
setResult(RESULT_OK, result);
} else { } else {
toastNoChanges(); toastNoChanges();
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
@ -267,7 +268,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
protected abstract void showDialog(TagData tagData); protected abstract void showDialog(TagData tagData);
protected abstract boolean ok(); protected abstract Intent ok();
} }
public static class DeleteTagActivity extends TagActivity { public static class DeleteTagActivity extends TagActivity {
@ -287,7 +288,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
} }
@Override @Override
protected boolean ok() { protected Intent ok() {
return tagService.deleteOrLeaveTag(this, tag, uuid); return tagService.deleteOrLeaveTag(this, tag, uuid);
} }
@ -304,18 +305,25 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
} }
@Override @Override
protected boolean ok() { protected Intent ok() {
if(editor == null) if(editor == null)
return false; return null;
String text = editor.getText().toString(); String text = editor.getText().toString();
if (text == null || text.length() == 0) { if (text == null || text.length() == 0) {
return false; return null;
} else { } else {
int renamed = tagService.rename(uuid, text); int renamed = tagService.rename(uuid, text);
Toast.makeText(this, getString(R.string.TEA_tags_renamed, tag, text, renamed), Toast.makeText(this, getString(R.string.TEA_tags_renamed, tag, text, renamed),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
return true;
if (renamed > 0) {
Intent intent = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_RENAMED);
intent.putExtra(TagViewFragment.EXTRA_TAG_UUID, uuid);
ContextManager.getContext().sendBroadcast(intent);
return intent;
}
return null;
} }
} }
} }

@ -22,7 +22,6 @@ import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.CountProperty; import com.todoroo.andlib.data.Property.CountProperty;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Field;
@ -374,7 +373,7 @@ public final class TagService {
return tagBuilder.toString(); return tagBuilder.toString();
} }
public boolean deleteOrLeaveTag(Context context, String tag, String uuid) { public Intent deleteOrLeaveTag(Context context, String tag, String uuid) {
int deleted = deleteTagMetadata(uuid); int deleted = deleteTagMetadata(uuid);
TagData tagData = tagDataDao.fetch(uuid, TagData.ID, TagData.UUID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID); TagData tagData = tagDataDao.fetch(uuid, TagData.ID, TagData.UUID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
boolean shared = false; boolean shared = false;
@ -389,7 +388,7 @@ public final class TagService {
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
context.sendBroadcast(tagDeleted); context.sendBroadcast(tagDeleted);
return true; return tagDeleted;
} }
/** /**
@ -557,12 +556,6 @@ public final class TagService {
result = metadataDao.update(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(uuid)), metadataTemplate); result = metadataDao.update(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(uuid)), metadataTemplate);
tagRenamed = tagRenamed || result > 0; tagRenamed = tagRenamed || result > 0;
if (tagRenamed) {
Intent intent = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_RENAMED);
intent.putExtra(TagViewFragment.EXTRA_TAG_UUID, uuid);
ContextManager.getContext().sendBroadcast(intent);
}
return result; return result;
} }

@ -82,7 +82,7 @@ public class FilterListFragment extends ListFragment {
private static final int CONTEXT_MENU_SHORTCUT = R.string.FLA_context_shortcut; private static final int CONTEXT_MENU_SHORTCUT = R.string.FLA_context_shortcut;
private static final int CONTEXT_MENU_INTENT = Menu.FIRST + 4; private static final int CONTEXT_MENU_INTENT = Menu.FIRST + 4;
private static final int REQUEST_CUSTOM_INTENT = 1; public static final int REQUEST_CUSTOM_INTENT = 10;
static final int REQUEST_VIEW_TASKS = 2; static final int REQUEST_VIEW_TASKS = 2;
public static final int REQUEST_NEW_BUTTON = 3; public static final int REQUEST_NEW_BUTTON = 3;
public static final int REQUEST_NEW_LIST = 4; public static final int REQUEST_NEW_LIST = 4;
@ -257,7 +257,7 @@ public class FilterListFragment extends ListFragment {
if (which == 0) { if (which == 0) {
showCreateShortcutDialog(getActivity(), ShortcutActivity.createIntent(filter), filter); showCreateShortcutDialog(getActivity(), ShortcutActivity.createIntent(filter), filter);
} else { } else {
startActivityForResult(intents[which - 1], REQUEST_CUSTOM_INTENT); getActivity().startActivityForResult(intents[which - 1], REQUEST_CUSTOM_INTENT);
} }
} }
}); });
@ -391,7 +391,7 @@ public class FilterListFragment extends ListFragment {
} }
case CONTEXT_MENU_INTENT: { case CONTEXT_MENU_INTENT: {
Intent intent = item.getIntent(); Intent intent = item.getIntent();
startActivityForResult(intent, REQUEST_CUSTOM_INTENT); getActivity().startActivityForResult(intent, REQUEST_CUSTOM_INTENT);
return true; return true;
} }
default: { default: {

@ -12,11 +12,9 @@ import org.json.JSONObject;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.app.Activity; import android.app.Activity;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
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;
@ -51,7 +49,9 @@ import com.todoroo.astrid.adapter.TaskListFragmentPagerAdapter;
import com.todoroo.astrid.api.AstridApiConstants; 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.core.CoreFilterExposer;
import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TagMetadataDao; import com.todoroo.astrid.dao.TagMetadataDao;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
@ -62,6 +62,7 @@ import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.abtesting.ABTestEventReportingService; import com.todoroo.astrid.service.abtesting.ABTestEventReportingService;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagsPlugin; import com.todoroo.astrid.tags.TagsPlugin;
import com.todoroo.astrid.tags.reusable.FeaturedListFilterMode; import com.todoroo.astrid.tags.reusable.FeaturedListFilterMode;
import com.todoroo.astrid.ui.DateChangedAlerts; import com.todoroo.astrid.ui.DateChangedAlerts;
@ -82,7 +83,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
/** token for indicating source of TLA launch */ /** token for indicating source of TLA launch */
public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$ public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$
public static final String TOKEN_NEW_LIST_CREATED = "newListCreated"; //$NON-NLS-1$ public static final String TOKEN_SWITCH_TO_FILTER = "newListCreated"; //$NON-NLS-1$
/** For indicating the new list screen should be launched at fragment setup time */ /** For indicating the new list screen should be launched at fragment setup time */
public static final String TOKEN_CREATE_NEW_LIST = "createNewList"; //$NON-NLS-1$ public static final String TOKEN_CREATE_NEW_LIST = "createNewList"; //$NON-NLS-1$
@ -121,9 +122,6 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
private boolean swipeEnabled = false; private boolean swipeEnabled = false;
private final TagDeletedReceiver tagDeletedReceiver = new TagDeletedReceiver();
private final TagRenamedReceiver tagRenamedReceiver = new TagRenamedReceiver();
private final OnClickListener mainMenuClickListener = new OnClickListener() { private final OnClickListener mainMenuClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -465,9 +463,9 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
onBackPressed(); onBackPressed();
} }
if (getIntent().hasExtra(TOKEN_NEW_LIST_CREATED)) { if (getIntent().hasExtra(TOKEN_SWITCH_TO_FILTER)) {
Filter newList = getIntent().getParcelableExtra(TOKEN_NEW_LIST_CREATED); Filter newList = getIntent().getParcelableExtra(TOKEN_SWITCH_TO_FILTER);
getIntent().removeExtra(TOKEN_NEW_LIST_CREATED); getIntent().removeExtra(TOKEN_SWITCH_TO_FILTER);
onFilterItemClicked(newList); onFilterItemClicked(newList);
} }
@ -520,8 +518,6 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
registerReceiver(tagDeletedReceiver, new IntentFilter(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED));
registerReceiver(tagRenamedReceiver, new IntentFilter(AstridApiConstants.BROADCAST_EVENT_TAG_RENAMED));
if (Preferences.getBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, false)) if (Preferences.getBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, false))
SyncUpgradePrompt.showSyncUpgradePrompt(this); SyncUpgradePrompt.showSyncUpgradePrompt(this);
@ -537,8 +533,6 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
AndroidUtilities.tryUnregisterReceiver(this, tagDeletedReceiver);
AndroidUtilities.tryUnregisterReceiver(this, tagRenamedReceiver);
} }
public void setSelectedItem(Filter item) { public void setSelectedItem(Filter item) {
@ -624,7 +618,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
Filter newList = data.getParcelableExtra(TagSettingsActivity.TOKEN_NEW_FILTER); Filter newList = data.getParcelableExtra(TagSettingsActivity.TOKEN_NEW_FILTER);
if (newList != null) { if (newList != null) {
getIntent().putExtra(TOKEN_NEW_LIST_CREATED, newList); // Handle in onPostResume() getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, newList); // Handle in onPostResume()
FilterListFragment fla = getFilterListFragment(); FilterListFragment fla = getFilterListFragment();
if (fla != null && getFragmentLayout() != LAYOUT_SINGLE) if (fla != null && getFragmentLayout() != LAYOUT_SINGLE)
fla.clear(); fla.clear();
@ -649,6 +643,49 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
tlf.refresh(); tlf.refresh();
} }
} else if (requestCode == FilterListFragment.REQUEST_CUSTOM_INTENT && resultCode == RESULT_OK && data != null) {
// Tag renamed or deleted
String action = data.getAction();
String uuid = data.getStringExtra(TagViewFragment.EXTRA_TAG_UUID);
if (AstridApiConstants.BROADCAST_EVENT_TAG_DELETED.equals(action)) {
TaskListFragment tlf = getTaskListFragment();
FilterListFragment fl = getFilterListFragment();
if (tlf != null) {
TagData tagData = tlf.getActiveTagData();
String activeUuid = RemoteModel.NO_UUID;
if (tagData != null)
activeUuid = tagData.getUuid();
if (activeUuid.equals(uuid)) {
getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, CoreFilterExposer.buildInboxFilter(getResources())); // Handle in onPostResume()
fl.clear(); // Should auto refresh
} else {
tlf.refresh();
}
}
if (fl != null)
fl.refresh();
} else if (AstridApiConstants.BROADCAST_EVENT_TAG_RENAMED.equals(action)) {
TaskListFragment tlf = getTaskListFragment();
if (tlf != null) {
TagData td = tlf.getActiveTagData();
if (td != null && td.getUuid().equals(uuid)) {
td = PluginServices.getTagDataDao().fetch(uuid, TagData.PROPERTIES);
if (td != null) {
Filter filter = TagFilterExposer.filterFromTagData(this, td);
getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, filter);
}
} else {
tlf.refresh();
}
}
FilterListFragment flf = getFilterListFragment();
if (flf != null)
flf.refresh();
}
} }
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
@ -921,37 +958,4 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
private class TagRenamedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TaskListFragment tlf = getTaskListFragment();
if (tlf != null)
tlf.refresh();
FilterListFragment flf = getFilterListFragment();
if (flf != null)
flf.refresh();
}
}
private class TagDeletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String uuid = intent.getStringExtra(TagViewFragment.EXTRA_TAG_UUID);
TaskListFragment tlf = getTaskListFragment();
FilterListFragment fl = getFilterListFragment();
if (tlf != null) {
TagData tagData = tlf.getActiveTagData();
String activeUuid = RemoteModel.NO_UUID;
if (tagData != null)
activeUuid = tagData.getUuid();
if (activeUuid.equals(uuid)) {
fl.switchToActiveTasks();
fl.clear(); // Should auto refresh
}
}
}
}
} }

Loading…
Cancel
Save