Rename and delete tags from TagSettingsActivity
@ -1,52 +0,0 @@
|
|||||||
package com.todoroo.astrid.tags;
|
|
||||||
|
|
||||||
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 org.tasks.R;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class DeleteTagActivity extends TagActivity {
|
|
||||||
|
|
||||||
@Inject TagDataDao tagDataDao;
|
|
||||||
@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() {
|
|
||||||
int deleted = deleteTagMetadata(uuid);
|
|
||||||
TagData tagData = tagDataDao.fetch(uuid, TagData.ID, TagData.UUID);
|
|
||||||
Intent tagDeleted = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_DELETED);
|
|
||||||
if (tagData != null) {
|
|
||||||
tagDataDao.delete(tagData.getId());
|
|
||||||
tagDeleted.putExtra(TagViewFragment.EXTRA_TAG_UUID, tagData.getUuid());
|
|
||||||
}
|
|
||||||
Toast.makeText(this, getString(R.string.TEA_tags_deleted, tag, deleted), Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
package com.todoroo.astrid.tags;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.utility.DialogUtilities;
|
|
||||||
import com.todoroo.astrid.actfm.TagViewFragment;
|
|
||||||
import com.todoroo.astrid.api.AstridApiConstants;
|
|
||||||
|
|
||||||
import org.tasks.R;
|
|
||||||
import org.tasks.injection.ForApplication;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class RenameTagActivity extends TagActivity {
|
|
||||||
|
|
||||||
private EditText editor;
|
|
||||||
|
|
||||||
@Inject TagService tagService;
|
|
||||||
@Inject @ForApplication Context context;
|
|
||||||
|
|
||||||
@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 tasksAffected = tagService.rename(uuid, text);
|
|
||||||
Toast.makeText(this, getString(R.string.TEA_tags_renamed, tag, text, tasksAffected),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
Intent intent = new Intent(AstridApiConstants.BROADCAST_EVENT_TAG_RENAMED) {{
|
|
||||||
putExtra(TagViewFragment.EXTRA_TAG_UUID, uuid);
|
|
||||||
}};
|
|
||||||
context.sendBroadcast(intent);
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,77 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
public abstract class TagActivity extends InjectingActivity {
|
|
||||||
|
|
||||||
String tag;
|
|
||||||
String uuid;
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 453 B |
|
After Width: | Height: | Size: 221 B |
|
After Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 464 B |
|
After Width: | Height: | Size: 257 B |
|
After Width: | Height: | Size: 273 B |
|
Before Width: | Height: | Size: 603 B |
|
After Width: | Height: | Size: 347 B |
|
After Width: | Height: | Size: 391 B |
|
Before Width: | Height: | Size: 305 B |
|
After Width: | Height: | Size: 175 B |
|
After Width: | Height: | Size: 168 B |
@ -0,0 +1,4 @@
|
|||||||
|
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/separatorHeight"
|
||||||
|
android:background="?attr/asSeparator" />
|
||||||