mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Make it possible to amend list of wipers
This commit is contained in:
@@ -38,11 +38,11 @@ public class RemoteWipeSetupActivity extends BriarActivity implements
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_distributed_backup);
|
setContentView(R.layout.activity_distributed_backup);
|
||||||
if (viewModel.remoteWipeIsSetup()) {
|
// if (viewModel.remoteWipeIsSetup()) {
|
||||||
showInitialFragment(new RemoteWipeDisplayFragment());
|
// showInitialFragment(new RemoteWipeDisplayFragment());
|
||||||
} else {
|
// } else {
|
||||||
showInitialFragment(WiperSelectorFragment.newInstance());
|
showInitialFragment(WiperSelectorFragment.newInstance());
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,11 +45,20 @@ public class RemoteWipeSetupViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ContactId> getWiperContactIds() {
|
||||||
|
try {
|
||||||
|
return db.transactionWithResult(true,
|
||||||
|
remoteWipeManager::getWiperContactIds);
|
||||||
|
} catch (DbException ignored) {
|
||||||
|
return new ArrayList<ContactId>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getWiperNames() {
|
public List<String> getWiperNames() {
|
||||||
ArrayList wiperNames = new ArrayList();
|
ArrayList wiperNames = new ArrayList();
|
||||||
try {
|
try {
|
||||||
List<Author> wipers = db.transactionWithResult(true,
|
List<Author> wipers = db.transactionWithResult(true,
|
||||||
txn -> remoteWipeManager.getWipers(txn));
|
remoteWipeManager::getWipers);
|
||||||
for (Author wiper : wipers) {
|
for (Author wiper : wipers) {
|
||||||
wiperNames.add(wiper.getName());
|
wiperNames.add(wiper.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.os.Bundle;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
@@ -14,9 +15,13 @@ import org.briarproject.briar.android.contactselection.ContactSelectorFragment;
|
|||||||
import org.briarproject.briar.android.contactselection.SelectableContactItem;
|
import org.briarproject.briar.android.contactselection.SelectableContactItem;
|
||||||
import org.briarproject.briar.android.socialbackup.creation.CreateBackupController;
|
import org.briarproject.briar.android.socialbackup.creation.CreateBackupController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -24,6 +29,11 @@ public class WiperSelectorFragment extends ContactSelectorFragment {
|
|||||||
|
|
||||||
public static final String TAG = WiperSelectorFragment.class.getName();
|
public static final String TAG = WiperSelectorFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private RemoteWipeSetupViewModel viewModel;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CreateBackupController controller;
|
CreateBackupController controller;
|
||||||
|
|
||||||
@@ -40,12 +50,14 @@ public class WiperSelectorFragment extends ContactSelectorFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(RemoteWipeSetupViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
selectedContacts.addAll(viewModel.getWiperContactIds());
|
||||||
requireActivity().setTitle(R.string.title_select_wipers);
|
requireActivity().setTitle(R.string.title_select_wipers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public interface RemoteWipeManager extends ConversationManager.ConversationClien
|
|||||||
|
|
||||||
List<Author> getWipers(Transaction txn) throws DbException;
|
List<Author> getWipers(Transaction txn) throws DbException;
|
||||||
|
|
||||||
|
List<ContactId> getWiperContactIds(Transaction txn);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Collection<ConversationMessageHeader> getMessageHeaders(
|
Collection<ConversationMessageHeader> getMessageHeaders(
|
||||||
Transaction txn, ContactId contactId) throws DbException;
|
Transaction txn, ContactId contactId) throws DbException;
|
||||||
|
|||||||
@@ -565,4 +565,27 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ContactId> getWiperContactIds(Transaction txn) {
|
||||||
|
ArrayList<ContactId> wiperContactIds = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
List<Author> wipers = getWipers(txn);
|
||||||
|
for (Author wiper : wipers) {
|
||||||
|
wiperContactIds.add(authorToContactId(txn, wiper));
|
||||||
|
}
|
||||||
|
} catch (DbException ignored) {
|
||||||
|
// Will return an empty list
|
||||||
|
}
|
||||||
|
return wiperContactIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContactId authorToContactId(Transaction txn, Author author)
|
||||||
|
throws DbException {
|
||||||
|
ArrayList<Contact> contacts =
|
||||||
|
(ArrayList<Contact>) contactManager.getContacts(txn);
|
||||||
|
for (Contact c : contacts) {
|
||||||
|
if (c.getAuthor().equals(author)) return c.getId();
|
||||||
|
}
|
||||||
|
throw new DbException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user