|
|
@ -575,195 +575,182 @@ public class FragmentMessages extends FragmentEx {
|
|
|
|
fabMove.setOnClickListener(new View.OnClickListener() {
|
|
|
|
fabMove.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (Helper.isPro(getContext())) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("folder", folder);
|
|
|
|
args.putLong("folder", folder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<List<EntityFolder>>() {
|
|
|
|
new SimpleTask<List<EntityFolder>>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected List<EntityFolder> onLoad(Context context, Bundle args) {
|
|
|
|
protected List<EntityFolder> onLoad(Context context, Bundle args) {
|
|
|
|
long folder = args.getLong("folder");
|
|
|
|
long folder = args.getLong("folder");
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
EntityFolder source = db.folder().getFolder(folder);
|
|
|
|
|
|
|
|
List<EntityFolder> folders = db.folder().getFolders(source.account);
|
|
|
|
|
|
|
|
List<EntityFolder> targets = new ArrayList<>();
|
|
|
|
|
|
|
|
for (EntityFolder f : folders)
|
|
|
|
|
|
|
|
if (!f.id.equals(folder) && !EntityFolder.DRAFTS.equals(f.type))
|
|
|
|
|
|
|
|
targets.add(f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Collator collator = Collator.getInstance(Locale.getDefault());
|
|
|
|
|
|
|
|
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Collections.sort(targets, new Comparator<EntityFolder>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int compare(EntityFolder f1, EntityFolder f2) {
|
|
|
|
|
|
|
|
int s = Integer.compare(
|
|
|
|
|
|
|
|
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
|
|
|
|
|
|
|
|
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
|
|
|
|
|
|
|
|
if (s != 0)
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
return collator.compare(
|
|
|
|
|
|
|
|
f1.name == null ? "" : f1.name,
|
|
|
|
|
|
|
|
f2.name == null ? "" : f2.name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return targets;
|
|
|
|
EntityFolder source = db.folder().getFolder(folder);
|
|
|
|
}
|
|
|
|
List<EntityFolder> folders = db.folder().getFolders(source.account);
|
|
|
|
|
|
|
|
List<EntityFolder> targets = new ArrayList<>();
|
|
|
|
|
|
|
|
for (EntityFolder f : folders)
|
|
|
|
|
|
|
|
if (!f.id.equals(folder) && !EntityFolder.DRAFTS.equals(f.type))
|
|
|
|
|
|
|
|
targets.add(f);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final Collator collator = Collator.getInstance(Locale.getDefault());
|
|
|
|
protected void onLoaded(final Bundle args, List<EntityFolder> folders) {
|
|
|
|
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
|
|
|
PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor);
|
|
|
|
|
|
|
|
|
|
|
|
Collections.sort(targets, new Comparator<EntityFolder>() {
|
|
|
|
int order = 0;
|
|
|
|
@Override
|
|
|
|
for (EntityFolder folder : folders) {
|
|
|
|
public int compare(EntityFolder f1, EntityFolder f2) {
|
|
|
|
String name = (folder.display == null
|
|
|
|
int s = Integer.compare(
|
|
|
|
? Helper.localizeFolderName(getContext(), folder.name)
|
|
|
|
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
|
|
|
|
: folder.display);
|
|
|
|
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name);
|
|
|
|
if (s != 0)
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
return collator.compare(
|
|
|
|
|
|
|
|
f1.name == null ? "" : f1.name,
|
|
|
|
|
|
|
|
f2.name == null ? "" : f2.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
return targets;
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
public boolean onMenuItemClick(final MenuItem target) {
|
|
|
|
|
|
|
|
MutableSelection<Long> selection = new MutableSelection<>();
|
|
|
|
|
|
|
|
selectionTracker.copySelection(selection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long[] ids = new long[selection.size()];
|
|
|
|
@Override
|
|
|
|
int i = 0;
|
|
|
|
protected void onLoaded(final Bundle args, List<EntityFolder> folders) {
|
|
|
|
for (Long id : selection)
|
|
|
|
PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor);
|
|
|
|
ids[i++] = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectionTracker.clearSelection();
|
|
|
|
int order = 0;
|
|
|
|
|
|
|
|
for (EntityFolder folder : folders) {
|
|
|
|
|
|
|
|
String name = (folder.display == null
|
|
|
|
|
|
|
|
? Helper.localizeFolderName(getContext(), folder.name)
|
|
|
|
|
|
|
|
: folder.display);
|
|
|
|
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
args.putLongArray("ids", ids);
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
args.putLong("target", target.getItemId());
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onMenuItemClick(final MenuItem target) {
|
|
|
|
|
|
|
|
MutableSelection<Long> selection = new MutableSelection<>();
|
|
|
|
|
|
|
|
selectionTracker.copySelection(selection);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
long[] ids = new long[selection.size()];
|
|
|
|
@Override
|
|
|
|
int i = 0;
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
for (Long id : selection)
|
|
|
|
long[] ids = args.getLongArray("ids");
|
|
|
|
ids[i++] = id;
|
|
|
|
long target = args.getLong("target");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
selectionTracker.clearSelection();
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (long id : ids) {
|
|
|
|
args.putLongArray("ids", ids);
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
args.putLong("target", target.getItemId());
|
|
|
|
List<EntityMessage> messages =
|
|
|
|
|
|
|
|
db.message().getMessageByThread(message.account, message.thread);
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
for (EntityMessage threaded : messages) {
|
|
|
|
@Override
|
|
|
|
if (threaded.folder.equals(message.folder)) {
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
db.message().setMessageUiHide(threaded.id, true);
|
|
|
|
long[] ids = args.getLongArray("ids");
|
|
|
|
EntityOperation.queue(db, threaded, EntityOperation.MOVE, target);
|
|
|
|
long target = args.getLong("target");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (long id : ids) {
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
List<EntityMessage> messages =
|
|
|
|
|
|
|
|
db.message().getMessageByThread(message.account, message.thread);
|
|
|
|
|
|
|
|
for (EntityMessage threaded : messages) {
|
|
|
|
|
|
|
|
if (threaded.folder.equals(message.folder)) {
|
|
|
|
|
|
|
|
db.message().setMessageUiHide(threaded.id, true);
|
|
|
|
|
|
|
|
EntityOperation.queue(db, threaded, EntityOperation.MOVE, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
return null;
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
EntityOperation.process(context);
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Helper.unexpectedError(getContext(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(FragmentMessages.this, args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
popupMenu.show();
|
|
|
|
@Override
|
|
|
|
}
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Helper.unexpectedError(getContext(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(FragmentMessages.this, args);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
return true;
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
}
|
|
|
|
Helper.unexpectedError(getContext(), ex);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(FragmentMessages.this, args);
|
|
|
|
popupMenu.show();
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
|
|
|
|
@Override
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
}
|
|
|
|
Helper.unexpectedError(getContext(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(FragmentMessages.this, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fabDelete.setOnClickListener(new View.OnClickListener() {
|
|
|
|
fabDelete.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (Helper.isPro(getContext()))
|
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
|
|
|
.setMessage(R.string.title_ask_delete_selected)
|
|
|
|
.setMessage(R.string.title_ask_delete_selected)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
MutableSelection<Long> selection = new MutableSelection<>();
|
|
|
|
MutableSelection<Long> selection = new MutableSelection<>();
|
|
|
|
selectionTracker.copySelection(selection);
|
|
|
|
selectionTracker.copySelection(selection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long[] ids = new long[selection.size()];
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (Long id : selection)
|
|
|
|
|
|
|
|
ids[i++] = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectionTracker.clearSelection();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args.putLongArray("ids", ids);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
|
|
|
|
long[] ids = args.getLongArray("ids");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (long id : ids) {
|
|
|
|
long[] ids = new long[selection.size()];
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
int i = 0;
|
|
|
|
if (message.uid == null && !TextUtils.isEmpty(message.error)) // outbox
|
|
|
|
for (Long id : selection)
|
|
|
|
db.message().deleteMessage(id);
|
|
|
|
ids[i++] = id;
|
|
|
|
else {
|
|
|
|
|
|
|
|
db.message().setMessageUiHide(message.id, true);
|
|
|
|
|
|
|
|
EntityOperation.queue(db, message, EntityOperation.DELETE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
selectionTracker.clearSelection();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
args.putLongArray("ids", ids);
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
|
|
|
|
long[] ids = args.getLongArray("ids");
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
try {
|
|
|
|
Helper.unexpectedError(getContext(), ex);
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (long id : ids) {
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
if (message.uid == null && !TextUtils.isEmpty(message.error)) // outbox
|
|
|
|
|
|
|
|
db.message().deleteMessage(id);
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
db.message().setMessageUiHide(message.id, true);
|
|
|
|
|
|
|
|
EntityOperation.queue(db, message, EntityOperation.DELETE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.load(FragmentMessages.this, args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
|
|
|
|
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Helper.unexpectedError(getContext(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(FragmentMessages.this, args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -1039,15 +1026,9 @@ public class FragmentMessages extends FragmentEx {
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.menu_sort_on_unread:
|
|
|
|
case R.id.menu_sort_on_unread:
|
|
|
|
case R.id.menu_sort_on_starred:
|
|
|
|
case R.id.menu_sort_on_starred:
|
|
|
|
if (Helper.isPro(getContext())) {
|
|
|
|
prefs.edit().putString("sort", item.getItemId() == R.id.menu_sort_on_unread ? "unread" : "starred").apply();
|
|
|
|
prefs.edit().putString("sort", item.getItemId() == R.id.menu_sort_on_unread ? "unread" : "starred").apply();
|
|
|
|
item.setChecked(true);
|
|
|
|
item.setChecked(true);
|
|
|
|
loadMessages();
|
|
|
|
loadMessages();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
|
|
|
|
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.menu_folders:
|
|
|
|
case R.id.menu_folders:
|
|
|
|