Extract tag activity classes

pull/189/head
Alex Baker 11 years ago
parent 6254d61fd8
commit a49e6e7ffc

@ -340,11 +340,11 @@
android:theme="@style/Tasks.FullTransparent" />
<activity
android:name="com.todoroo.astrid.tags.TagFilterExposer$DeleteTagActivity"
android:name="com.todoroo.astrid.tags.DeleteTagActivity"
android:theme="@style/Tasks.FullTransparent" />
<activity
android:name="com.todoroo.astrid.tags.TagFilterExposer$RenameTagActivity"
android:name="com.todoroo.astrid.tags.RenameTagActivity"
android:theme="@style/Tasks.FullTransparent" />
<!-- alarms -->

@ -39,6 +39,8 @@ import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksListFragment;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.tags.DeleteTagActivity;
import com.todoroo.astrid.tags.RenameTagActivity;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagsPlugin;
@ -509,14 +511,14 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
return true;
case R.id.menu_delete_list:
TagService.Tag deleteTag = new TagService.Tag(tlf.getActiveTagData());
Intent ret = new Intent(this, TagFilterExposer.DeleteTagActivity.class);
Intent ret = new Intent(this, DeleteTagActivity.class);
ret.putExtra("tag", deleteTag.tag);
ret.putExtra(TagViewFragment.EXTRA_TAG_UUID, deleteTag.uuid);
startActivityForResult(ret, FilterListFragment.REQUEST_CUSTOM_INTENT);
return true;
case R.id.menu_rename_list:
TagService.Tag renameTag = new TagService.Tag(tlf.getActiveTagData());
Intent rename = new Intent(this, TagFilterExposer.RenameTagActivity.class);
Intent rename = new Intent(this, RenameTagActivity.class);
rename.putExtra("tag", renameTag.tag);
rename.putExtra(TagViewFragment.EXTRA_TAG_UUID, renameTag.uuid);
startActivityForResult(rename, FilterListFragment.REQUEST_CUSTOM_INTENT);

@ -0,0 +1,60 @@
package com.todoroo.astrid.tags;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.service.TagDataService;
import org.tasks.R;
import javax.inject.Inject;
public class DeleteTagActivity extends TagActivity {
@Inject TagDataDao tagDataDao;
@Inject TagDataService tagDataService;
@Inject MetadataDao metadataDao;
@Override
protected void showDialog() {
DialogUtilities.okCancelDialog(this, getString(R.string.DLG_delete_this_tag_question, tag), getOkListener(), getCancelListener());
}
@Override
protected Intent ok() {
return deleteOrLeaveTag(this, tag, uuid);
}
private Intent deleteOrLeaveTag(Context context, String tag, String uuid) {
int deleted = deleteTagMetadata(uuid);
TagData tagData = tagDataDao.fetch(uuid, TagData.ID, TagData.UUID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
Intent tagDeleted = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED);
if(tagData != null) {
tagData.setDeletionDate(DateUtilities.now());
tagDataService.save(tagData);
tagDeleted.putExtra(TagViewFragment.EXTRA_TAG_UUID, tagData.getUuid());
}
Toast.makeText(context, context.getString(R.string.TEA_tags_deleted, tag, deleted), Toast.LENGTH_SHORT).show();
context.sendBroadcast(tagDeleted);
return tagDeleted;
}
private int deleteTagMetadata(String uuid) {
Metadata deleted = new Metadata();
deleted.setDeletionDate(DateUtilities.now());
return metadataDao.update(Criterion.and(MetadataDao.MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(uuid)), deleted);
}
}

@ -0,0 +1,47 @@
package com.todoroo.astrid.tags;
import android.content.Intent;
import android.widget.EditText;
import android.widget.Toast;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import org.tasks.R;
public class RenameTagActivity extends TagActivity {
private EditText editor;
@Override
protected void showDialog() {
editor = new EditText(this);
DialogUtilities.viewDialog(this, getString(R.string.DLG_rename_this_tag_header, tag), editor, getOkListener(), getCancelListener());
}
@Override
protected Intent ok() {
if(editor == null) {
return null;
}
String text = editor.getText().toString();
if (text == null || text.length() == 0) {
return null;
} else {
int renamed = tagService.rename(uuid, text);
Toast.makeText(this, getString(R.string.TEA_tags_renamed, tag, text, renamed),
Toast.LENGTH_SHORT).show();
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;
}
}
}

@ -0,0 +1,81 @@
package com.todoroo.astrid.tags;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.data.RemoteModel;
import org.tasks.R;
import org.tasks.injection.InjectingActivity;
import javax.inject.Inject;
public abstract class TagActivity extends InjectingActivity {
String tag;
String uuid;
@Inject TagService tagService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tag = getIntent().getStringExtra(TagFilterExposer.TAG);
uuid = getIntent().getStringExtra(TagViewFragment.EXTRA_TAG_UUID);
if(tag == null || RemoteModel.isUuidEmpty(uuid)) {
finish();
return;
}
showDialog();
}
protected DialogInterface.OnClickListener getOkListener() {
return new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Intent result = ok();
if (result != null) {
setResult(RESULT_OK, result);
} else {
toastNoChanges();
setResult(RESULT_CANCELED);
}
} finally {
finish();
}
}
};
}
protected DialogInterface.OnClickListener getCancelListener() {
return new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
toastNoChanges();
} finally {
setResult(RESULT_CANCELED);
finish();
}
}
};
}
private void toastNoChanges() {
Toast.makeText(this, R.string.TEA_no_tags_modified,
Toast.LENGTH_SHORT).show();
}
protected abstract void showDialog();
protected abstract Intent ok();
}

@ -9,14 +9,11 @@ import android.app.Activity;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.Toast;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion;
@ -39,7 +36,6 @@ import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.tags.TagService.Tag;
import org.tasks.R;
import org.tasks.injection.InjectingActivity;
import org.tasks.injection.InjectingBroadcastReceiver;
import org.tasks.injection.Injector;
@ -56,7 +52,7 @@ import javax.inject.Inject;
*/
public class TagFilterExposer extends InjectingBroadcastReceiver implements AstridFilterExposer {
private static final String TAG = "tag"; //$NON-NLS-1$
public static final String TAG = "tag"; //$NON-NLS-1$
@Inject TagService tagService;
@ -175,123 +171,6 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
return filterFromTag(context, tag, TaskCriteria.activeAndVisible());
}
// --- tag manipulation activities
public abstract static class TagActivity extends InjectingActivity {
String tag;
String uuid;
@Inject TagService tagService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tag = getIntent().getStringExtra(TAG);
uuid = getIntent().getStringExtra(TagViewFragment.EXTRA_TAG_UUID);
if(tag == null || RemoteModel.isUuidEmpty(uuid)) {
finish();
return;
}
showDialog();
}
protected DialogInterface.OnClickListener getOkListener() {
return new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Intent result = ok();
if (result != null) {
setResult(RESULT_OK, result);
} else {
toastNoChanges();
setResult(RESULT_CANCELED);
}
} finally {
finish();
}
}
};
}
protected DialogInterface.OnClickListener getCancelListener() {
return new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
toastNoChanges();
} finally {
setResult(RESULT_CANCELED);
finish();
}
}
};
}
private void toastNoChanges() {
Toast.makeText(this, R.string.TEA_no_tags_modified,
Toast.LENGTH_SHORT).show();
}
protected abstract void showDialog();
protected abstract Intent ok();
}
public static class DeleteTagActivity extends TagActivity {
@Override
protected void showDialog() {
DialogUtilities.okCancelDialog(this, getString(R.string.DLG_delete_this_tag_question, tag), getOkListener(), getCancelListener());
}
@Override
protected Intent ok() {
return tagService.deleteOrLeaveTag(this, tag, uuid);
}
}
public static class RenameTagActivity extends TagActivity {
private EditText editor;
@Override
protected void showDialog() {
editor = new EditText(this);
DialogUtilities.viewDialog(this, getString(R.string.DLG_rename_this_tag_header, tag), editor, getOkListener(), getCancelListener());
}
@Override
protected Intent ok() {
if(editor == null) {
return null;
}
String text = editor.getText().toString();
if (text == null || text.length() == 0) {
return null;
} else {
int renamed = tagService.rename(uuid, text);
Toast.makeText(this, getString(R.string.TEA_tags_renamed, tag, text, renamed),
Toast.LENGTH_SHORT).show();
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;
}
}
}
@Override
public FilterListItem[] getFilters(Injector injector) {
if (ContextManager.getContext() == null) {

@ -5,10 +5,7 @@
*/
package com.todoroo.astrid.tags;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.Toast;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.CountProperty;
@ -21,8 +18,6 @@ import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TagDataDao;
@ -265,21 +260,6 @@ public final class TagService {
return tagBuilder.toString();
}
public Intent deleteOrLeaveTag(Context context, String tag, String uuid) {
int deleted = deleteTagMetadata(uuid);
TagData tagData = tagDataDao.fetch(uuid, TagData.ID, TagData.UUID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
Intent tagDeleted = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED);
if(tagData != null) {
tagData.setDeletionDate(DateUtilities.now());
tagDataService.save(tagData);
tagDeleted.putExtra(TagViewFragment.EXTRA_TAG_UUID, tagData.getUuid());
}
Toast.makeText(context, context.getString(R.string.TEA_tags_deleted, tag, deleted), Toast.LENGTH_SHORT).show();
context.sendBroadcast(tagDeleted);
return tagDeleted;
}
/**
* Return all tags (including metadata tags and TagData tags) in an array list
*/
@ -380,13 +360,6 @@ public final class TagService {
return null;
}
public int deleteTagMetadata(String uuid) {
Metadata deleted = new Metadata();
deleted.setDeletionDate(DateUtilities.now());
return metadataDao.update(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(uuid)), deleted);
}
public int rename(String uuid, String newName) {
TagData template = new TagData();
template.setName(newName);

@ -20,6 +20,8 @@ import com.todoroo.astrid.gtasks.GtasksFilterExposer;
import com.todoroo.astrid.gtasks.GtasksListAdder;
import com.todoroo.astrid.gtasks.GtasksPreferences;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import com.todoroo.astrid.tags.DeleteTagActivity;
import com.todoroo.astrid.tags.RenameTagActivity;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.timers.TimerFilterExposer;
import com.todoroo.astrid.widget.WidgetConfigActivity;
@ -52,8 +54,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
CustomFilterExposer.DeleteActivity.class,
CalendarReminderActivity.class,
GtasksListAdder.class,
TagFilterExposer.DeleteTagActivity.class,
TagFilterExposer.RenameTagActivity.class,
DeleteTagActivity.class,
RenameTagActivity.class,
VoiceCommandActivity.class,
GtasksLoginActivity.class,
WidgetConfigActivity.class,

Loading…
Cancel
Save