mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +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) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_distributed_backup);
|
||||
if (viewModel.remoteWipeIsSetup()) {
|
||||
showInitialFragment(new RemoteWipeDisplayFragment());
|
||||
} else {
|
||||
// if (viewModel.remoteWipeIsSetup()) {
|
||||
// showInitialFragment(new RemoteWipeDisplayFragment());
|
||||
// } else {
|
||||
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() {
|
||||
ArrayList wiperNames = new ArrayList();
|
||||
try {
|
||||
List<Author> wipers = db.transactionWithResult(true,
|
||||
txn -> remoteWipeManager.getWipers(txn));
|
||||
remoteWipeManager::getWipers);
|
||||
for (Author wiper : wipers) {
|
||||
wiperNames.add(wiper.getName());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
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.socialbackup.creation.CreateBackupController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -24,6 +29,11 @@ public class WiperSelectorFragment extends ContactSelectorFragment {
|
||||
|
||||
public static final String TAG = WiperSelectorFragment.class.getName();
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private RemoteWipeSetupViewModel viewModel;
|
||||
|
||||
@Inject
|
||||
CreateBackupController controller;
|
||||
|
||||
@@ -40,12 +50,14 @@ public class WiperSelectorFragment extends ContactSelectorFragment {
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||
.get(RemoteWipeSetupViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
selectedContacts.addAll(viewModel.getWiperContactIds());
|
||||
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<ContactId> getWiperContactIds(Transaction txn);
|
||||
|
||||
@Override
|
||||
Collection<ConversationMessageHeader> getMessageHeaders(
|
||||
Transaction txn, ContactId contactId) throws DbException;
|
||||
|
||||
@@ -565,4 +565,27 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||
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