Send undo improvements

This commit is contained in:
M66B 2021-03-28 09:07:01 +02:00
parent 8324016e7b
commit 4ecb071839
8 changed files with 43 additions and 23 deletions

View File

@ -11,8 +11,10 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="com.android.vending.BILLING" />
<!-- OAuth -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

View File

@ -11,8 +11,10 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="com.android.vending.BILLING" />
<!-- OAuth -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

View File

@ -11,8 +11,10 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="com.android.vending.BILLING" />
<!-- OAuth -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

View File

@ -42,7 +42,6 @@ import java.util.Map;
public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
static final int PI_REPLY = 1;
static final long UNDO_DELAY = 5000; // milliseconds
@Override
protected void onCreate(Bundle savedInstanceState) {

View File

@ -136,8 +136,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
static final String ACTION_EDIT_RULES = BuildConfig.APPLICATION_ID + ".EDIT_RULES";
static final String ACTION_EDIT_RULE = BuildConfig.APPLICATION_ID + ".EDIT_RULE";
static final String ACTION_NEW_MESSAGE = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE";
static final String ACTION_SENT_UNDO = BuildConfig.APPLICATION_ID + ".SENT_UNDO";
static final String ACTION_UNDO_SEND = BuildConfig.APPLICATION_ID + ".UNDO_SEND";
private static final long UNDO_SEND_DELAY = 7000; // milliseconds
private static final int UPDATE_TIMEOUT = 15 * 1000; // milliseconds
private static final long EXIT_DELAY = 2500L; // milliseconds
static final long UPDATE_DAILY = (BuildConfig.BETA_RELEASE ? 4 : 12) * 3600 * 1000L; // milliseconds
@ -159,7 +160,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_NEW_MESSAGE);
iff.addAction(ACTION_SENT_UNDO);
iff.addAction(ACTION_UNDO_SEND);
lbm.registerReceiver(creceiver, iff);
if (savedInstanceState != null)
@ -1301,8 +1302,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
String action = intent.getAction();
if (ACTION_NEW_MESSAGE.equals(action))
onNewMessage(intent);
else if (ACTION_SENT_UNDO.equals(action))
onSentUndo(intent);
else if (ACTION_UNDO_SEND.equals(action))
onUndoSend(intent);
}
};
@ -1325,8 +1326,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
updatedFolders.add(-1L);
}
private void onSentUndo(Intent intent) {
undo(ActivityCompose.UNDO_DELAY, getString(R.string.title_sending), null, new Runnable() {
private void onUndoSend(Intent intent) {
int delayed = intent.getIntExtra("delayed", 0);
long scheduled = intent.getLongExtra("scheduled", 0);
long now = new Date().getTime();
Log.i("Undo send delay=" + UNDO_SEND_DELAY +
" delayed=" + delayed +
" scheduled=" + new Date(scheduled) +
" now=" + new Date(now));
if (delayed * 1000L < UNDO_SEND_DELAY * 2 || scheduled - now < UNDO_SEND_DELAY * 2)
return;
undo(UNDO_SEND_DELAY, getString(R.string.title_sending), null, new Runnable() {
@Override
public void run() {
long id = intent.getLongExtra("id", -1);

View File

@ -463,7 +463,7 @@ public class EntityMessage implements Serializable {
am.cancel(pi);
} else {
Log.i("Set snooze id=" + id + " wakeup=" + new Date(wakeup));
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, wakeup, pi);
AlarmManagerCompat.setExactAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, wakeup, pi);
}
}

View File

@ -4446,8 +4446,13 @@ public class FragmentCompose extends FragmentBase {
boolean dirty = false;
EntityMessage draft;
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean discard_delete = prefs.getBoolean("discard_delete", false);
boolean write_below = prefs.getBoolean("write_below", false);
boolean save_drafts = prefs.getBoolean("save_drafts", true);
int send_delayed = prefs.getInt("send_delayed", 0);
DB db = DB.getInstance(context);
try {
db.beginTransaction();
@ -4463,7 +4468,6 @@ public class FragmentCompose extends FragmentBase {
if (action == R.id.action_delete) {
dirty = true;
boolean discard_delete = prefs.getBoolean("discard_delete", false);
EntityFolder trash = db.folder().getFolderByType(draft.account, EntityFolder.TRASH);
EntityFolder drafts = db.folder().getFolderByType(draft.account, EntityFolder.DRAFTS);
if (empty || trash == null || discard_delete || (drafts != null && drafts.local))
@ -4626,7 +4630,6 @@ public class FragmentCompose extends FragmentBase {
// Get saved body
Document d;
boolean write_below = prefs.getBoolean("write_below", false);
if (extras != null && extras.containsKey("html")) {
// Save current revision
Document c = JsoupEx.parse(body);
@ -4735,7 +4738,6 @@ public class FragmentCompose extends FragmentBase {
action == R.id.action_redo ||
action == R.id.action_check) {
if ((dirty || encrypted) && !needsEncryption) {
boolean save_drafts = prefs.getBoolean("save_drafts", true);
if (save_drafts)
EntityOperation.queue(context, draft, EntityOperation.ADD);
}
@ -4965,7 +4967,6 @@ public class FragmentCompose extends FragmentBase {
db.attachment().setMessage(attachment.id, draft.id);
// Delay sending message
int send_delayed = prefs.getInt("send_delayed", 0);
if (draft.ui_snoozed == null && send_delayed != 0) {
if (extras.getBoolean("now"))
draft.ui_snoozed = null;
@ -5019,13 +5020,13 @@ public class FragmentCompose extends FragmentBase {
Log.i("Delayed send id=" + draft.id + " at " + new Date(draft.ui_snoozed));
EntityMessage.snooze(context, draft.id, draft.ui_snoozed);
if (draft.ui_snoozed - 2 * ActivityCompose.UNDO_DELAY > new Date().getTime()) {
Intent undo = new Intent(ActivityView.ACTION_SENT_UNDO);
undo.putExtra("id", draft.id);
Intent undo = new Intent(ActivityView.ACTION_UNDO_SEND);
undo.putExtra("id", draft.id);
undo.putExtra("delayed", send_delayed);
undo.putExtra("scheduled", draft.ui_snoozed);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(undo);
}
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(undo);
}
return draft;

View File

@ -11,8 +11,10 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="com.android.vending.BILLING" />
<!-- OAuth -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />