Check lifecycle state before recreating removable drive tasks.

This commit is contained in:
akwizgran
2022-04-17 12:28:26 +01:00
parent 74a3f54d28
commit a043e8b1cf
4 changed files with 14 additions and 3 deletions

View File

@@ -103,7 +103,8 @@ public class ReceiveFragment extends Fragment {
// to prevent duplicates on the back stack.
getParentFragmentManager().popBackStack();
// Start again (picks up existing task or allows to start a new one)
viewModel.startReceiveData();
// unless the activity was recreated after the app was killed
if (viewModel.isAccountSignedIn()) viewModel.startReceiveData();
}
}

View File

@@ -4,6 +4,7 @@ import android.app.Application;
import android.net.Uri;
import org.briarproject.bramble.api.Consumer;
import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.db.DbException;
@@ -32,6 +33,7 @@ import androidx.lifecycle.MutableLiveData;
import static java.util.Locale.US;
import static java.util.Objects.requireNonNull;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.STARTING_SERVICES;
import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.PROP_URI;
@UiThread
@@ -40,6 +42,7 @@ class RemovableDriveViewModel extends DbViewModel {
enum Action {SEND, RECEIVE}
private final AccountManager accountManager;
private final RemovableDriveManager manager;
private final MutableLiveEvent<Action> action = new MutableLiveEvent<>();
@@ -61,8 +64,10 @@ class RemovableDriveViewModel extends DbViewModel {
LifecycleManager lifecycleManager,
TransactionManager db,
AndroidExecutor androidExecutor,
AccountManager accountManager,
RemovableDriveManager removableDriveManager) {
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
this.accountManager = accountManager;
this.manager = removableDriveManager;
}
@@ -193,4 +198,8 @@ class RemovableDriveViewModel extends DbViewModel {
return state;
}
boolean isAccountSignedIn() {
return accountManager.hasDatabaseKey() &&
lifecycleManager.getLifecycleState().isAfter(STARTING_SERVICES);
}
}

View File

@@ -109,7 +109,8 @@ public class SendFragment extends Fragment {
// to prevent duplicates on the back stack.
getParentFragmentManager().popBackStack();
// Start again (picks up existing task or allows to start a new one)
viewModel.startSendData();
// unless the activity was recreated after the app was killed
if (viewModel.isAccountSignedIn()) viewModel.startSendData();
}
}

View File

@@ -44,7 +44,7 @@ public abstract class DbViewModel extends AndroidViewModel {
@DatabaseExecutor
private final Executor dbExecutor;
private final LifecycleManager lifecycleManager;
protected final LifecycleManager lifecycleManager;
private final TransactionManager db;
protected final AndroidExecutor androidExecutor;