mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Check lifecycle state before recreating removable drive tasks.
This commit is contained in:
@@ -103,7 +103,8 @@ public class ReceiveFragment extends Fragment {
|
|||||||
// to prevent duplicates on the back stack.
|
// to prevent duplicates on the back stack.
|
||||||
getParentFragmentManager().popBackStack();
|
getParentFragmentManager().popBackStack();
|
||||||
// Start again (picks up existing task or allows to start a new one)
|
// 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.app.Application;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.Consumer;
|
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.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
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.Locale.US;
|
||||||
import static java.util.Objects.requireNonNull;
|
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;
|
import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.PROP_URI;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -40,6 +42,7 @@ class RemovableDriveViewModel extends DbViewModel {
|
|||||||
|
|
||||||
enum Action {SEND, RECEIVE}
|
enum Action {SEND, RECEIVE}
|
||||||
|
|
||||||
|
private final AccountManager accountManager;
|
||||||
private final RemovableDriveManager manager;
|
private final RemovableDriveManager manager;
|
||||||
|
|
||||||
private final MutableLiveEvent<Action> action = new MutableLiveEvent<>();
|
private final MutableLiveEvent<Action> action = new MutableLiveEvent<>();
|
||||||
@@ -61,8 +64,10 @@ class RemovableDriveViewModel extends DbViewModel {
|
|||||||
LifecycleManager lifecycleManager,
|
LifecycleManager lifecycleManager,
|
||||||
TransactionManager db,
|
TransactionManager db,
|
||||||
AndroidExecutor androidExecutor,
|
AndroidExecutor androidExecutor,
|
||||||
|
AccountManager accountManager,
|
||||||
RemovableDriveManager removableDriveManager) {
|
RemovableDriveManager removableDriveManager) {
|
||||||
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
this.accountManager = accountManager;
|
||||||
this.manager = removableDriveManager;
|
this.manager = removableDriveManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,4 +198,8 @@ class RemovableDriveViewModel extends DbViewModel {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isAccountSignedIn() {
|
||||||
|
return accountManager.hasDatabaseKey() &&
|
||||||
|
lifecycleManager.getLifecycleState().isAfter(STARTING_SERVICES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,8 @@ public class SendFragment extends Fragment {
|
|||||||
// to prevent duplicates on the back stack.
|
// to prevent duplicates on the back stack.
|
||||||
getParentFragmentManager().popBackStack();
|
getParentFragmentManager().popBackStack();
|
||||||
// Start again (picks up existing task or allows to start a new one)
|
// 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public abstract class DbViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
private final Executor dbExecutor;
|
private final Executor dbExecutor;
|
||||||
private final LifecycleManager lifecycleManager;
|
protected final LifecycleManager lifecycleManager;
|
||||||
private final TransactionManager db;
|
private final TransactionManager db;
|
||||||
protected final AndroidExecutor androidExecutor;
|
protected final AndroidExecutor androidExecutor;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user