mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
WIP db transaction for DistributedBackupActivity
This commit is contained in:
@@ -6,6 +6,8 @@ import android.widget.Toast;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
@@ -14,6 +16,7 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -23,13 +26,15 @@ public class DistributedBackupActivity extends BriarActivity implements
|
||||
|
||||
private Collection<ContactId> custodians;
|
||||
private SocialBackupManager socialBackupManager;
|
||||
private DatabaseComponent db;
|
||||
|
||||
DistributedBackupActivity() {
|
||||
public DistributedBackupActivity() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
DistributedBackupActivity(SocialBackupManager socialBackupManager) {
|
||||
public DistributedBackupActivity(SocialBackupManager socialBackupManager, DatabaseComponent db) {
|
||||
this.socialBackupManager = socialBackupManager;
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,11 +67,12 @@ public class DistributedBackupActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void thresholdDefined(int threshold) {
|
||||
// TODO this is the place to call
|
||||
//socialBackupManager.createBackup();
|
||||
ShardsSentFragment fragment = new ShardsSentFragment();
|
||||
showNextFragment(fragment);
|
||||
public void thresholdDefined(int threshold) throws DbException {
|
||||
db.transaction(false, txn -> {
|
||||
socialBackupManager.createBackup(txn, (List<ContactId>) custodians, threshold);
|
||||
ShardsSentFragment fragment = new ShardsSentFragment();
|
||||
showNextFragment(fragment);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
public interface ThresholdDefinedListener {
|
||||
|
||||
@UiThread
|
||||
void thresholdDefined(int threshold);
|
||||
void thresholdDefined(int threshold) throws DbException;
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.contactselection.ContactSelectorListener;
|
||||
@@ -110,7 +111,11 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_threshold_defined:
|
||||
listener.thresholdDefined(threshold);
|
||||
try {
|
||||
listener.thresholdDefined(threshold);
|
||||
} catch (DbException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
Reference in New Issue
Block a user