|
|
@ -199,53 +199,68 @@ public class FragmentDialogJunk extends FragmentDialogBase {
|
|
|
|
btnClear.setOnClickListener(new View.OnClickListener() {
|
|
|
|
btnClear.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
new AlertDialog.Builder(v.getContext())
|
|
|
|
args.putLong("folder", folder);
|
|
|
|
.setTitle(R.string.title_junk_clear)
|
|
|
|
|
|
|
|
.setMessage(R.string.title_junk_clear_hint)
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
long fid = args.getLong("folder");
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
|
|
|
args.putLong("folder", folder);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
EntityFolder folder = db.folder().getFolder(fid);
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
if (folder == null)
|
|
|
|
@Override
|
|
|
|
return null;
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
|
|
|
|
long fid = args.getLong("folder");
|
|
|
|
EntityFolder junk = db.folder().getFolderByType(folder.account, EntityFolder.JUNK);
|
|
|
|
|
|
|
|
if (junk == null)
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
return null;
|
|
|
|
EntityFolder folder = db.folder().getFolder(fid);
|
|
|
|
|
|
|
|
if (folder == null)
|
|
|
|
List<EntityRule> rules = db.rule().getRules(fid);
|
|
|
|
return null;
|
|
|
|
if (rules == null)
|
|
|
|
|
|
|
|
return null;
|
|
|
|
EntityFolder junk = db.folder().getFolderByType(folder.account, EntityFolder.JUNK);
|
|
|
|
|
|
|
|
if (junk == null)
|
|
|
|
for (EntityRule rule : rules) {
|
|
|
|
return null;
|
|
|
|
JSONObject jaction = new JSONObject(rule.action);
|
|
|
|
|
|
|
|
int type = jaction.optInt("type", -1);
|
|
|
|
List<EntityRule> rules = db.rule().getRules(fid);
|
|
|
|
long target = jaction.optLong("target", -1);
|
|
|
|
if (rules == null)
|
|
|
|
if (type == EntityRule.TYPE_MOVE && target == junk.id) {
|
|
|
|
return null;
|
|
|
|
EntityLog.log(context, "Deleting junk rule=" + rule.id);
|
|
|
|
|
|
|
|
db.rule().deleteRule(rule.id);
|
|
|
|
for (EntityRule rule : rules) {
|
|
|
|
|
|
|
|
JSONObject jaction = new JSONObject(rule.action);
|
|
|
|
|
|
|
|
int type = jaction.optInt("type", -1);
|
|
|
|
|
|
|
|
long target = jaction.optLong("target", -1);
|
|
|
|
|
|
|
|
if (type == EntityRule.TYPE_MOVE && target == junk.id) {
|
|
|
|
|
|
|
|
EntityLog.log(context, "Deleting junk rule=" + rule.id);
|
|
|
|
|
|
|
|
db.rule().deleteRule(rule.id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int count = db.contact().deleteContact(account, EntityContact.TYPE_JUNK);
|
|
|
|
|
|
|
|
EntityLog.log(context, "Deleted junk contacts=" + count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
|
|
|
|
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Log.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.execute(FragmentDialogJunk.this, args, "junk:clear");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
int count = db.contact().deleteContact(account, EntityContact.TYPE_JUNK);
|
|
|
|
@Override
|
|
|
|
EntityLog.log(context, "Deleted junk contacts=" + count);
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
// Do nothing
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.show();
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
|
|
|
|
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Log.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.execute(FragmentDialogJunk.this, args, "junk:clear");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|