|
|
|
@ -71,6 +71,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|
|
|
|
private final static int action_delete_local = 2;
|
|
|
|
|
private final static int action_empty_trash = 3;
|
|
|
|
|
private final static int action_edit_properties = 4;
|
|
|
|
|
private final static int action_legend = 5;
|
|
|
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
@ -181,98 +182,125 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|
|
|
|
if (folder.account != null)
|
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 4, R.string.title_edit_properties);
|
|
|
|
|
|
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, action_legend, 5, R.string.menu_legend);
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem target) {
|
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
|
switch (target.getItemId()) {
|
|
|
|
|
case action_synchronize_now:
|
|
|
|
|
Log.i(Helper.TAG, folder.name + " requesting sync");
|
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
|
new Intent(ServiceSynchronize.ACTION_SYNCHRONIZE_FOLDER)
|
|
|
|
|
.setType("account/" + (folder.account == null ? "outbox" : Long.toString(folder.account)))
|
|
|
|
|
.putExtra("folder", folder.id));
|
|
|
|
|
onActionSynchronizeNow();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case action_delete_local:
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
|
args.putBoolean("outbox", folder.account == null);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
boolean outbox = args.getBoolean("outbox");
|
|
|
|
|
Log.i(Helper.TAG, "Delete local messages outbox=" + outbox);
|
|
|
|
|
if (outbox)
|
|
|
|
|
DB.getInstance(context).message().deleteSeenMessages(id);
|
|
|
|
|
else
|
|
|
|
|
DB.getInstance(context).message().deleteLocalMessages(id);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
OnActionDeleteLocal();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onException(Bundle args, Throwable ex) {
|
|
|
|
|
Helper.unexpectedError(context, ex);
|
|
|
|
|
}
|
|
|
|
|
}.load(context, owner, args);
|
|
|
|
|
case action_empty_trash:
|
|
|
|
|
onActionEmptyTrash();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case action_edit_properties:
|
|
|
|
|
onActionEditProperties();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case action_empty_trash:
|
|
|
|
|
new DialogBuilderLifecycle(context, owner)
|
|
|
|
|
.setMessage(R.string.title_empty_trash_ask)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
case action_legend:
|
|
|
|
|
onActionLegend();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
|
private void onActionSynchronizeNow() {
|
|
|
|
|
Log.i(Helper.TAG, folder.name + " requesting sync");
|
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
|
new Intent(ServiceSynchronize.ACTION_SYNCHRONIZE_FOLDER)
|
|
|
|
|
.setType("account/" + (folder.account == null ? "outbox" : Long.toString(folder.account)))
|
|
|
|
|
.putExtra("folder", folder.id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
private void OnActionDeleteLocal() {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
|
args.putBoolean("outbox", folder.account == null);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
boolean outbox = args.getBoolean("outbox");
|
|
|
|
|
Log.i(Helper.TAG, "Delete local messages outbox=" + outbox);
|
|
|
|
|
if (outbox)
|
|
|
|
|
DB.getInstance(context).message().deleteSeenMessages(id);
|
|
|
|
|
else
|
|
|
|
|
DB.getInstance(context).message().deleteLocalMessages(id);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onException(Bundle args, Throwable ex) {
|
|
|
|
|
Helper.unexpectedError(context, ex);
|
|
|
|
|
}
|
|
|
|
|
}.load(context, owner, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
private void onActionEmptyTrash() {
|
|
|
|
|
new DialogBuilderLifecycle(context, owner)
|
|
|
|
|
.setMessage(R.string.title_empty_trash_ask)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
|
|
for (Long mid : db.message().getMessageByFolder(id)) {
|
|
|
|
|
EntityMessage message = db.message().getMessage(mid);
|
|
|
|
|
db.message().setMessageUiHide(message.id, true);
|
|
|
|
|
EntityOperation.queue(db, message, EntityOperation.DELETE);
|
|
|
|
|
}
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", folder.id);
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
} finally {
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
for (Long mid : db.message().getMessageByFolder(id)) {
|
|
|
|
|
EntityMessage message = db.message().getMessage(mid);
|
|
|
|
|
db.message().setMessageUiHide(message.id, true);
|
|
|
|
|
EntityOperation.queue(db, message, EntityOperation.DELETE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
Helper.unexpectedError(context, ex);
|
|
|
|
|
}
|
|
|
|
|
}.load(context, owner, args);
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
} finally {
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
.show();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case action_edit_properties:
|
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
|
new Intent(ActivityView.ACTION_EDIT_FOLDER)
|
|
|
|
|
.putExtra("id", folder.id));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
@Override
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
Helper.unexpectedError(context, ex);
|
|
|
|
|
}
|
|
|
|
|
}.load(context, owner, args);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionEditProperties() {
|
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
|
lbm.sendBroadcast(
|
|
|
|
|
new Intent(ActivityView.ACTION_EDIT_FOLDER)
|
|
|
|
|
.putExtra("id", folder.id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionLegend() {
|
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
|
|
|
|
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_LEGEND));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|