|
@ -42,6 +42,7 @@ import android.widget.TextView; |
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton; |
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton; |
|
|
import com.google.android.material.snackbar.Snackbar; |
|
|
import com.google.android.material.snackbar.Snackbar; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.concurrent.ExecutorService; |
|
|
import java.util.concurrent.ExecutorService; |
|
@ -234,7 +235,6 @@ public class FragmentMessages extends FragmentEx { |
|
|
TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos); |
|
|
TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos); |
|
|
if (message == null || |
|
|
if (message == null || |
|
|
expanded.contains(message.id) || |
|
|
expanded.contains(message.id) || |
|
|
viewType != AdapterMessage.ViewType.THREAD || |
|
|
|
|
|
EntityFolder.OUTBOX.equals(message.folderType)) |
|
|
EntityFolder.OUTBOX.equals(message.folderType)) |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
@ -299,13 +299,17 @@ public class FragmentMessages extends FragmentEx { |
|
|
|
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
Bundle args = new Bundle(); |
|
|
args.putLong("id", message.id); |
|
|
args.putLong("id", message.id); |
|
|
|
|
|
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD); |
|
|
args.putInt("direction", direction); |
|
|
args.putInt("direction", direction); |
|
|
|
|
|
|
|
|
new SimpleTask<String[]>() { |
|
|
|
|
|
|
|
|
new SimpleTask<MessageTarget>() { |
|
|
@Override |
|
|
@Override |
|
|
protected String[] onLoad(Context context, Bundle args) { |
|
|
|
|
|
|
|
|
protected MessageTarget onLoad(Context context, Bundle args) { |
|
|
long id = args.getLong("id"); |
|
|
long id = args.getLong("id"); |
|
|
|
|
|
boolean thread = args.getBoolean("thread"); |
|
|
int direction = args.getInt("direction"); |
|
|
int direction = args.getInt("direction"); |
|
|
|
|
|
|
|
|
|
|
|
MessageTarget result = new MessageTarget(); |
|
|
EntityFolder target = null; |
|
|
EntityFolder target = null; |
|
|
|
|
|
|
|
|
// Get target folder and hide message |
|
|
// Get target folder and hide message |
|
@ -327,37 +331,56 @@ public class FragmentMessages extends FragmentEx { |
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); |
|
|
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
db.message().setMessageUiHide(message.id, true); |
|
|
|
|
|
|
|
|
result.target = target.name; |
|
|
|
|
|
result.display = (target.display == null ? target.name : target.display); |
|
|
|
|
|
|
|
|
|
|
|
if (thread) { |
|
|
|
|
|
List<EntityMessage> messages = |
|
|
|
|
|
db.message().getMessageByThread(message.account, message.thread); |
|
|
|
|
|
for (EntityMessage threaded : messages) { |
|
|
|
|
|
if (!threaded.ui_hide && threaded.folder.equals(message.folder)) |
|
|
|
|
|
result.ids.add(threaded.id); |
|
|
|
|
|
} |
|
|
|
|
|
} else |
|
|
|
|
|
result.ids.add(message.id); |
|
|
|
|
|
|
|
|
|
|
|
for (long mid : result.ids) { |
|
|
|
|
|
Log.i(Helper.TAG, "Move hide id=" + mid + " target=" + result.target); |
|
|
|
|
|
db.message().setMessageUiHide(mid, true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
db.setTransactionSuccessful(); |
|
|
db.setTransactionSuccessful(); |
|
|
} finally { |
|
|
} finally { |
|
|
db.endTransaction(); |
|
|
db.endTransaction(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Move id=" + id + " target=" + target.name); |
|
|
|
|
|
|
|
|
|
|
|
return new String[]{target.name, target.display == null ? target.name : target.display}; |
|
|
|
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onLoaded(final Bundle args, final String[] target) { |
|
|
|
|
|
|
|
|
protected void onLoaded(final Bundle args, final MessageTarget result) { |
|
|
// Show undo snackbar |
|
|
// Show undo snackbar |
|
|
final Snackbar snackbar = Snackbar.make( |
|
|
final Snackbar snackbar = Snackbar.make( |
|
|
view, |
|
|
view, |
|
|
getString(R.string.title_moving, Helper.localizeFolderName(getContext(), target[1])), |
|
|
|
|
|
|
|
|
getString(R.string.title_moving, Helper.localizeFolderName(getContext(), result.display)), |
|
|
Snackbar.LENGTH_INDEFINITE); |
|
|
Snackbar.LENGTH_INDEFINITE); |
|
|
snackbar.setAction(R.string.title_undo, new View.OnClickListener() { |
|
|
snackbar.setAction(R.string.title_undo, new View.OnClickListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onClick(View v) { |
|
|
public void onClick(View v) { |
|
|
snackbar.dismiss(); |
|
|
snackbar.dismiss(); |
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
|
args.putSerializable("result", result); |
|
|
|
|
|
|
|
|
// Show message again |
|
|
// Show message again |
|
|
new SimpleTask<Void>() { |
|
|
new SimpleTask<Void>() { |
|
|
@Override |
|
|
@Override |
|
|
protected Void onLoad(Context context, Bundle args) { |
|
|
protected Void onLoad(Context context, Bundle args) { |
|
|
long id = args.getLong("id"); |
|
|
|
|
|
Log.i(Helper.TAG, "Undo move id=" + id); |
|
|
|
|
|
DB.getInstance(context).message().setMessageUiHide(id, false); |
|
|
|
|
|
|
|
|
MessageTarget result = (MessageTarget) args.getSerializable("result"); |
|
|
|
|
|
for (long id : result.ids) { |
|
|
|
|
|
Log.i(Helper.TAG, "Move undo id=" + id); |
|
|
|
|
|
DB.getInstance(context).message().setMessageUiHide(id, false); |
|
|
|
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -374,14 +397,14 @@ public class FragmentMessages extends FragmentEx { |
|
|
new Handler().postDelayed(new Runnable() { |
|
|
new Handler().postDelayed(new Runnable() { |
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
|
Log.i(Helper.TAG, "Move timeout shown=" + snackbar.isShown()); |
|
|
|
|
|
|
|
|
Log.i(Helper.TAG, "Move timeout"); |
|
|
|
|
|
|
|
|
// Remove snackbar |
|
|
// Remove snackbar |
|
|
if (snackbar.isShown()) |
|
|
if (snackbar.isShown()) |
|
|
snackbar.dismiss(); |
|
|
snackbar.dismiss(); |
|
|
|
|
|
|
|
|
final Context context = getContext(); |
|
|
|
|
|
args.putString("target", target[0]); |
|
|
|
|
|
|
|
|
final Bundle args = new Bundle(); |
|
|
|
|
|
args.putSerializable("result", result); |
|
|
|
|
|
|
|
|
// Process move in a thread |
|
|
// Process move in a thread |
|
|
// - the fragment could be gone |
|
|
// - the fragment could be gone |
|
@ -389,18 +412,19 @@ public class FragmentMessages extends FragmentEx { |
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
|
try { |
|
|
try { |
|
|
long id = args.getLong("id"); |
|
|
|
|
|
String target = args.getString("target"); |
|
|
|
|
|
|
|
|
MessageTarget result = (MessageTarget) args.getSerializable("result"); |
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context); |
|
|
|
|
|
|
|
|
DB db = DB.getInstance(snackbar.getContext()); |
|
|
try { |
|
|
try { |
|
|
db.beginTransaction(); |
|
|
db.beginTransaction(); |
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(id); |
|
|
|
|
|
if (message != null && message.ui_hide) { |
|
|
|
|
|
Log.i(Helper.TAG, "Moving id=" + id + " target=" + target); |
|
|
|
|
|
EntityFolder folder = db.folder().getFolderByName(message.account, target); |
|
|
|
|
|
EntityOperation.queue(db, message, EntityOperation.MOVE, folder.id); |
|
|
|
|
|
|
|
|
for (long id : result.ids) { |
|
|
|
|
|
EntityMessage message = db.message().getMessage(id); |
|
|
|
|
|
if (message != null && message.ui_hide) { |
|
|
|
|
|
Log.i(Helper.TAG, "Move id=" + id + " target=" + result.target); |
|
|
|
|
|
EntityFolder folder = db.folder().getFolderByName(message.account, result.target); |
|
|
|
|
|
EntityOperation.queue(db, message, EntityOperation.MOVE, folder.id); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
db.setTransactionSuccessful(); |
|
|
db.setTransactionSuccessful(); |
|
@ -408,7 +432,7 @@ public class FragmentMessages extends FragmentEx { |
|
|
db.endTransaction(); |
|
|
db.endTransaction(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
EntityOperation.process(context); |
|
|
|
|
|
|
|
|
EntityOperation.process(snackbar.getContext()); |
|
|
|
|
|
|
|
|
} catch (Throwable ex) { |
|
|
} catch (Throwable ex) { |
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); |
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); |
|
@ -425,6 +449,12 @@ public class FragmentMessages extends FragmentEx { |
|
|
} |
|
|
} |
|
|
}.load(FragmentMessages.this, args); |
|
|
}.load(FragmentMessages.this, args); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MessageTarget implements Serializable { |
|
|
|
|
|
List<Long> ids = new ArrayList<>(); |
|
|
|
|
|
String target; |
|
|
|
|
|
String display; |
|
|
|
|
|
} |
|
|
}).attachToRecyclerView(rvMessage); |
|
|
}).attachToRecyclerView(rvMessage); |
|
|
|
|
|
|
|
|
fab.setOnClickListener(new View.OnClickListener() { |
|
|
fab.setOnClickListener(new View.OnClickListener() { |
|
|