|
|
@ -549,120 +549,126 @@ public class FragmentMessages extends FragmentEx { |
|
|
|
fabMove.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
Bundle args = new Bundle(); |
|
|
|
args.putLong("folder", folder); |
|
|
|
|
|
|
|
new SimpleTask<List<EntityFolder>>() { |
|
|
|
@Override |
|
|
|
protected List<EntityFolder> onLoad(Context context, Bundle args) { |
|
|
|
long folder = args.getLong("folder"); |
|
|
|
DB db = DB.getInstance(context); |
|
|
|
if (Helper.isPro(getContext())) { |
|
|
|
Bundle args = new Bundle(); |
|
|
|
args.putLong("folder", folder); |
|
|
|
|
|
|
|
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); |
|
|
|
new SimpleTask<List<EntityFolder>>() { |
|
|
|
@Override |
|
|
|
protected List<EntityFolder> onLoad(Context context, Bundle args) { |
|
|
|
long folder = args.getLong("folder"); |
|
|
|
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); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
final Collator collator = Collator.getInstance(Locale.getDefault()); |
|
|
|
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc |
|
|
|
return targets; |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
@Override |
|
|
|
protected void onLoaded(final Bundle args, List<EntityFolder> folders) { |
|
|
|
PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return targets; |
|
|
|
} |
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
|
|
|
@Override |
|
|
|
public boolean onMenuItemClick(final MenuItem target) { |
|
|
|
MutableSelection<Long> selection = new MutableSelection<>(); |
|
|
|
selectionTracker.copySelection(selection); |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onLoaded(final Bundle args, List<EntityFolder> folders) { |
|
|
|
PopupMenu popupMenu = new PopupMenu(getContext(), popupAnchor); |
|
|
|
long[] ids = new long[selection.size()]; |
|
|
|
int i = 0; |
|
|
|
for (Long id : selection) |
|
|
|
ids[i++] = id; |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
|
|
|
@Override |
|
|
|
public boolean onMenuItemClick(final MenuItem target) { |
|
|
|
MutableSelection<Long> selection = new MutableSelection<>(); |
|
|
|
selectionTracker.copySelection(selection); |
|
|
|
|
|
|
|
long[] ids = new long[selection.size()]; |
|
|
|
int i = 0; |
|
|
|
for (Long id : selection) |
|
|
|
ids[i++] = id; |
|
|
|
selectionTracker.clearSelection(); |
|
|
|
|
|
|
|
selectionTracker.clearSelection(); |
|
|
|
args.putLongArray("ids", ids); |
|
|
|
args.putLong("target", target.getItemId()); |
|
|
|
|
|
|
|
args.putLongArray("ids", ids); |
|
|
|
args.putLong("target", target.getItemId()); |
|
|
|
new SimpleTask<Void>() { |
|
|
|
@Override |
|
|
|
protected Void onLoad(Context context, Bundle args) { |
|
|
|
long[] ids = args.getLongArray("ids"); |
|
|
|
long target = args.getLong("target"); |
|
|
|
|
|
|
|
new SimpleTask<Void>() { |
|
|
|
@Override |
|
|
|
protected Void onLoad(Context context, Bundle args) { |
|
|
|
long[] ids = args.getLongArray("ids"); |
|
|
|
long target = args.getLong("target"); |
|
|
|
DB db = DB.getInstance(context); |
|
|
|
try { |
|
|
|
db.beginTransaction(); |
|
|
|
|
|
|
|
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); |
|
|
|
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(); |
|
|
|
} |
|
|
|
db.setTransactionSuccessful(); |
|
|
|
} finally { |
|
|
|
db.endTransaction(); |
|
|
|
} |
|
|
|
|
|
|
|
EntityOperation.process(context); |
|
|
|
EntityOperation.process(context); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onException(Bundle args, Throwable ex) { |
|
|
|
Helper.unexpectedError(getContext(), ex); |
|
|
|
} |
|
|
|
}.load(FragmentMessages.this, args); |
|
|
|
@Override |
|
|
|
protected void onException(Bundle args, Throwable ex) { |
|
|
|
Helper.unexpectedError(getContext(), ex); |
|
|
|
} |
|
|
|
}.load(FragmentMessages.this, args); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
}); |
|
|
|
return true; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
popupMenu.show(); |
|
|
|
} |
|
|
|
popupMenu.show(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onException(Bundle args, Throwable ex) { |
|
|
|
Helper.unexpectedError(getContext(), ex); |
|
|
|
} |
|
|
|
}.load(FragmentMessages.this, args); |
|
|
|
@Override |
|
|
|
protected void onException(Bundle args, Throwable ex) { |
|
|
|
Helper.unexpectedError(getContext(), ex); |
|
|
|
} |
|
|
|
}.load(FragmentMessages.this, args); |
|
|
|
} else { |
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); |
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); |
|
|
|
fragmentTransaction.commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|