From f4086ecbb346a87dbd452b4c3cb58071b5062400 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 8 Sep 2018 19:54:20 +0000 Subject: [PATCH] Undo move to archive/trash Fixes #92 --- .idea/caches/build_file_checksums.ser | Bin 535 -> 535 bytes .idea/misc.xml | 2 +- app/build.gradle | 2 + .../eu/faircode/email/FragmentMessages.java | 76 ++++++++- app/src/main/res/layout/fragment_messages.xml | 153 +++++++++--------- app/src/main/res/values/strings.xml | 1 + 6 files changed, 153 insertions(+), 81 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 1c5fc394ba4890b3c3c3ed779adaf6ddc04af44b..39f786d69d9f28336b019bc404bd930a08b24690 100644 GIT binary patch delta 32 qcmV+*0N?+Y1eXMmnFFR=v$33N0TDY`v+LXQ$;)@MrChvU0D5@yDG#gw delta 32 ocmbQvGM#0@OlCFh!yD&hF$x~g_<6iFr^eLu*EFVSu9i0|0M$PYwg3PC diff --git a/.idea/misc.xml b/.idea/misc.xml index 77d47004..caad359b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -30,7 +30,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 9bc39f78..ca0494be 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -87,6 +87,8 @@ dependencies { implementation "androidx.browser:browser:$androidx_version" implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version" + implementation "androidx.coordinatorlayout:coordinatorlayout:1.0.0-alpha1" + implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index e6c58664..949316b4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -25,6 +25,7 @@ import android.content.SharedPreferences; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.os.Handler; import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.Log; @@ -218,6 +219,7 @@ public class FragmentMessages extends FragmentEx { DB db = DB.getInstance(context); try { db.beginTransaction(); + EntityMessage message = db.message().getMessage(id); EntityFolder folder = db.folder().getFolder(message.folder); @@ -231,24 +233,86 @@ public class FragmentMessages extends FragmentEx { } db.message().setMessageUiHide(message.id, true); - EntityOperation.queue(db, message, EntityOperation.MOVE, target.id); db.setTransactionSuccessful(); } finally { db.endTransaction(); } - EntityOperation.process(context); + Log.i(Helper.TAG, "Move id=" + id + " target=" + target); return target.name; } @Override - protected void onLoaded(Bundle args, String folder) { - Snackbar.make( + protected void onLoaded(final Bundle args, final String target) { + final Snackbar snackbar = Snackbar.make( view, - getString(R.string.title_moving, Helper.localizeFolderName(getContext(), folder)), - Snackbar.LENGTH_SHORT).show(); + getString(R.string.title_moving, Helper.localizeFolderName(getContext(), target)), + Snackbar.LENGTH_INDEFINITE); + snackbar.setAction(R.string.title_undo, new View.OnClickListener() { + @Override + public void onClick(View v) { + snackbar.dismiss(); + + new SimpleTask() { + @Override + 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); + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + super.onException(args, ex); + } + }.load(FragmentMessages.this, args); + } + }); + snackbar.show(); + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (snackbar.isShown()) { + snackbar.dismiss(); + + args.putString("target", target); + new SimpleTask() { + @Override + protected Void onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + String target = args.getString("target"); + Log.i(Helper.TAG, "Moving id=" + id + " target=" + target); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + EntityFolder folder = db.folder().getFolderByName(message.account, target); + EntityOperation.queue(db, message, EntityOperation.MOVE, folder.id); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + EntityOperation.process(context); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + super.onException(args, ex); + } + }.load(FragmentMessages.this, args); + } + } + }, 5000); } @Override diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index 01cd318d..59087f13 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -1,76 +1,93 @@ - - + - + - + - + - + - + + + + + + + + - - - - - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ebff286..04921b3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -221,6 +221,7 @@ Do you have a question or problem? Yes No + Undo This is a pro feature List of pro features