mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 09:49:21 +02:00
Merge pull request #1617 from deltachat/fix-relaunch2
fix launch if there is an ongoing process
This commit is contained in:
commit
3ad7822504
5 changed files with 49 additions and 4 deletions
|
@ -482,6 +482,7 @@
|
|||
<string name="pref_background_default_color">Default color</string>
|
||||
<string name="pref_background_custom_image">Custom image</string>
|
||||
<string name="pref_background_custom_color">Custom color</string>
|
||||
<string name="export_aborted">Export aborted.</string>
|
||||
|
||||
<!-- automatically delete message -->
|
||||
<string name="delete_old_messages">Delete old messages</string>
|
||||
|
|
|
@ -3,10 +3,8 @@ package org.thoughtcrime.securesms;
|
|||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* Workaround for Android bug:
|
||||
* https://code.google.com/p/android/issues/detail?id=53313
|
||||
*/
|
||||
// dummy activity that just pushes the app to foreground when fired.
|
||||
// can also be used to work around android bug https://code.google.com/p/android/issues/detail?id=53313
|
||||
public class DummyActivity extends Activity {
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment;
|
|||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.service.GenericForegroundService;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -22,6 +23,15 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
|
|||
Log.w(TAG, "onCreate(" + savedInstanceState + ")");
|
||||
onPreCreate();
|
||||
|
||||
if (GenericForegroundService.isForegroundTaskStarted()) {
|
||||
// this does not prevent intent set by onNewIntent(),
|
||||
// however, at least during onboarding,
|
||||
// this catches a lot of situations with otherwise weird app states.
|
||||
super.onCreate(savedInstanceState);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DcHelper.isConfigured(getApplicationContext())) {
|
||||
Intent intent = new Intent(this, WelcomeActivity.class);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.preferences;
|
|||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.ListPreference;
|
||||
|
@ -37,6 +38,28 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
dcContext.eventCenter.removeObservers(this);
|
||||
|
||||
if (notificationController != null) {
|
||||
// cancel backup when settings-activity is destroyed.
|
||||
//
|
||||
// where possible, we avoid the settings-activity from being destroyed,
|
||||
// however, i did not find a simple way to cancel ConversationListActivity.onNewIntent() -
|
||||
// which one is cleaning up "back stack" due to the singleTask flag.
|
||||
// using a dummy activity and several workarounds all result even in worse side-effects
|
||||
// than cancel-backup when the user relaunches the app.
|
||||
// maybe we could bear the singleTask flag or could decouple
|
||||
// backup completely from ui-flows -
|
||||
// however, all this is some work and probably not maybe the effort just now.
|
||||
//
|
||||
// anyway, normally, the backup is fast enough and the users will just wait.
|
||||
// btw, import does not have this issue (no singleTask in play there)
|
||||
// and also for export, switching to other apps and tapping the notification will work.
|
||||
// so, the current state is not that bad :)
|
||||
notificationController.close();
|
||||
dcContext.stopOngoingProcess();
|
||||
Toast.makeText(getActivity(), R.string.export_aborted, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -83,6 +106,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
|
|||
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), (dialog, which) -> {
|
||||
dcContext.stopOngoingProcess();
|
||||
notificationController.close();
|
||||
notificationController = null;
|
||||
});
|
||||
progressDialog.show();
|
||||
|
||||
|
@ -106,6 +130,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
|
|||
.show();
|
||||
}
|
||||
notificationController.close();
|
||||
notificationController = null;
|
||||
}
|
||||
else if (progress<1000/*progress in permille*/) {
|
||||
int percent = (int)progress / 10;
|
||||
|
@ -118,6 +143,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
|
|||
progressDialog.dismiss();
|
||||
progressDialog = null;
|
||||
notificationController.close();
|
||||
notificationController = null;
|
||||
String msg = "";
|
||||
if (progressWhat==DcContext.DC_IMEX_EXPORT_BACKUP) {
|
||||
msg = getActivity().getString(R.string.pref_backup_written_to_x, imexDir);
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.service;
|
|||
import android.annotation.TargetApi;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -17,6 +18,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.app.NotificationCompat.Builder;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.thoughtcrime.securesms.DummyActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationCenter;
|
||||
|
||||
|
@ -47,6 +49,7 @@ public final class GenericForegroundService extends Service {
|
|||
private static final AtomicInteger NEXT_ID = new AtomicInteger();
|
||||
private static final AtomicBoolean CHANNEL_CREATED = new AtomicBoolean(false);
|
||||
|
||||
private static int startedCounter = 0;
|
||||
|
||||
private final LinkedHashMap<Integer, Entry> allActiveMessages = new LinkedHashMap<>();
|
||||
|
||||
|
@ -114,6 +117,7 @@ public final class GenericForegroundService extends Service {
|
|||
.setTicker(active.contentText)
|
||||
.setContentText(active.contentText)
|
||||
.setProgress(active.progressMax, active.progress, active.indeterminate)
|
||||
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, DummyActivity.class), 0))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -124,6 +128,7 @@ public final class GenericForegroundService extends Service {
|
|||
|
||||
|
||||
public static NotificationController startForegroundTask(@NonNull Context context, @NonNull String task) {
|
||||
startedCounter++;
|
||||
final int id = NEXT_ID.getAndIncrement();
|
||||
|
||||
createFgNotificationChannel(context);
|
||||
|
@ -145,6 +150,11 @@ public final class GenericForegroundService extends Service {
|
|||
intent.putExtra(EXTRA_ID, id);
|
||||
|
||||
ContextCompat.startForegroundService(context, intent);
|
||||
startedCounter = Math.max(startedCounter-1, 0);
|
||||
}
|
||||
|
||||
public static boolean isForegroundTaskStarted() {
|
||||
return startedCounter > 0;
|
||||
}
|
||||
|
||||
synchronized void replaceProgress(int id, int progressMax, int progress, boolean indeterminate, String message) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue