Refactor and fix for list leaving/deleting functionality

pull/14/head
Sam Bosley 13 years ago
parent 18d8acc461
commit ca004a718e

@ -33,7 +33,6 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback; import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
@ -41,9 +40,7 @@ import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService; import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.FilterListFragment; import com.todoroo.astrid.activity.FilterListFragment;
import com.todoroo.astrid.activity.ShortcutActivity; import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.helper.AsyncImageView; import com.todoroo.astrid.helper.AsyncImageView;
@ -73,6 +70,8 @@ public class TagSettingsActivity extends FragmentActivity {
private TagData tagData; private TagData tagData;
private Filter filter; // Used for creating shortcuts, only initialized if necessary private Filter filter; // Used for creating shortcuts, only initialized if necessary
@Autowired TagService tagService;
@Autowired TagDataService tagDataService; @Autowired TagDataService tagDataService;
@Autowired ActFmSyncService actFmSyncService; @Autowired ActFmSyncService actFmSyncService;
@ -527,20 +526,9 @@ public class TagSettingsActivity extends FragmentActivity {
} }
protected boolean deleteTag() { protected boolean deleteTag() {
tagDataService.delete(tagData.getId()); boolean result = tagService.deleteOrLeaveTag(this, tagData.getValue(TagData.NAME), TagService.SHOW_ACTIVE_TASKS);
if(tagData != null) { finish();
tagData.setValue(TagData.DELETION_DATE, DateUtilities.now()); return result;
PluginServices.getTagDataService().save(tagData);
}
Intent tagDeleted = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED);
tagDeleted.putExtra(TagViewFragment.EXTRA_TAG_NAME, tagData.getValue(TagData.NAME));
tagDeleted.putExtra(TagFilterExposer.TAG_SQL, TagFilterExposer.SHOW_ACTIVE_TASKS);
this.finish();
sendBroadcast(tagDeleted);
return true;
} }
} }

@ -27,7 +27,6 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
@ -59,8 +58,6 @@ import com.todoroo.astrid.utility.AstridPreferences;
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$
public static final String SHOW_ACTIVE_TASKS = "show_main_task_view"; //$NON-NLS-1$
@Autowired TagDataService tagDataService; @Autowired TagDataService tagDataService;
@Autowired GtasksPreferenceService gtasksPreferenceService; @Autowired GtasksPreferenceService gtasksPreferenceService;
@ -129,7 +126,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
private static Intent newTagIntent(Context context, Class<? extends Activity> activity, Tag tag, String sql) { 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); ret.putExtra(TagService.TOKEN_TAG_SQL, sql);
return ret; return ret;
} }
@ -207,7 +204,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); sql = getIntent().getStringExtra(TagService.TOKEN_TAG_SQL);
if(tag == null) { if(tag == null) {
finish(); finish();
return; return;
@ -280,22 +277,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
@Override @Override
protected boolean ok() { protected boolean ok() {
int deleted = tagService.delete(tag); return tagService.deleteOrLeaveTag(this, tag, sql);
TagData tagData = PluginServices.getTagDataService().getTag(tag, TagData.ID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
boolean shared = false;
if(tagData != null) {
tagData.setValue(TagData.DELETION_DATE, DateUtilities.now());
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(shared ? R.string.TEA_tags_left : R.string.TEA_tags_deleted, tag, deleted),
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;
} }
} }

@ -7,7 +7,10 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.Toast;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property.CountProperty; import com.todoroo.andlib.data.Property.CountProperty;
@ -23,7 +26,10 @@ import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
@ -47,6 +53,9 @@ import com.todoroo.astrid.utility.Flags;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public final class TagService { public final class TagService {
public static final String TOKEN_TAG_SQL = "tagSql"; //$NON-NLS-1$
public static final String SHOW_ACTIVE_TASKS = "show_main_task_view"; //$NON-NLS-1$
// --- public constants // --- public constants
/** Metadata key for tag data */ /** Metadata key for tag data */
@ -249,6 +258,25 @@ public final class TagService {
return tagBuilder.toString(); return tagBuilder.toString();
} }
public boolean deleteOrLeaveTag(Context context, String tag, String sql) {
int deleted = deleteTagMetadata(tag);
TagData tagData = PluginServices.getTagDataService().getTag(tag, TagData.ID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
boolean shared = false;
if(tagData != null) {
tagData.setValue(TagData.DELETION_DATE, DateUtilities.now());
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(context, context.getString(shared ? R.string.TEA_tags_left : R.string.TEA_tags_deleted, tag, deleted),
Toast.LENGTH_SHORT).show();
Intent tagDeleted = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED);
tagDeleted.putExtra(TagViewFragment.EXTRA_TAG_NAME, tag);
tagDeleted.putExtra(TOKEN_TAG_SQL, sql);
context.sendBroadcast(tagDeleted);
return true;
}
/** /**
* Return all tags (including metadata tags and TagData tags) in an array list * Return all tags (including metadata tags and TagData tags) in an array list
* @return * @return
@ -352,7 +380,7 @@ public final class TagService {
return tagWithCase; return tagWithCase;
} }
public int delete(String tag) { public int deleteTagMetadata(String tag) {
invalidateTaskCache(tag); invalidateTaskCache(tag);
return PluginServices.getMetadataService().deleteWhere(tagEqIgnoreCase(tag, Criterion.all)); return PluginServices.getMetadataService().deleteWhere(tagEqIgnoreCase(tag, Criterion.all));
} }

@ -44,7 +44,7 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.StatisticsConstants; 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.tags.TagFilterExposer; import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.DateChangedAlerts; import com.todoroo.astrid.ui.DateChangedAlerts;
import com.todoroo.astrid.ui.FragmentPopover; import com.todoroo.astrid.ui.FragmentPopover;
import com.todoroo.astrid.ui.MainMenuPopover; import com.todoroo.astrid.ui.MainMenuPopover;
@ -635,9 +635,9 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String deletedTag = intent.getStringExtra(TagViewFragment.EXTRA_TAG_NAME); String deletedTag = intent.getStringExtra(TagViewFragment.EXTRA_TAG_NAME);
String deletedTagSql = intent.getStringExtra(TagFilterExposer.TAG_SQL); String deletedTagSql = intent.getStringExtra(TagService.TOKEN_TAG_SQL);
FilterListFragment fl = getFilterListFragment(); FilterListFragment fl = getFilterListFragment();
if (deletedTagSql.equals(TagFilterExposer.SHOW_ACTIVE_TASKS)) { if (deletedTagSql.equals(TagService.SHOW_ACTIVE_TASKS)) {
fl.switchToActiveTasks(); fl.switchToActiveTasks();
fl.clear(); // Should auto refresh fl.clear(); // Should auto refresh
} }

Loading…
Cancel
Save