When creating social backup, only allow selecting contacts when there are at least 2 contacts in contact list

This commit is contained in:
ameba23
2021-08-27 12:30:10 +02:00
parent c49c1f78d2
commit be8e5c4bf2
2 changed files with 21 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import android.os.Bundle;
import android.widget.Toast;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.R;
@@ -29,6 +30,9 @@ public class DistributedBackupActivity extends BriarActivity implements
@Inject
public SocialBackupManager socialBackupManager;
@Inject
public ContactManager contactManager;
@Inject
public DatabaseComponent db;
@@ -52,6 +56,20 @@ public class DistributedBackupActivity extends BriarActivity implements
showInitialFragment(fragment);
});
} catch (DbException e) {
// Check the number of contacts in the contacts list > 1
try {
if (contactManager.getContacts().size() < 2) {
Toast.makeText(this,
R.string.social_backup_not_enough_contacts,
Toast.LENGTH_LONG).show();
finish();
}
} catch (DbException dbException) {
Toast.makeText(this,
R.string.reading_contacts_error,
Toast.LENGTH_LONG).show();
finish();
}
CustodianSelectorFragment fragment =
CustodianSelectorFragment.newInstance();
showInitialFragment(fragment);

View File

@@ -729,4 +729,7 @@
<string name="activity_name_recovery">Recover Account</string>
<string name="activity_name_custodian_help_recovery">Help recover account</string>
<string name="existing_backup_explain">%d of the following contacts are needed to restore your account:</string>
<string name="social_backup_not_enough_contacts">To make a social backup, you need at least 2 contacts in your contacts list</string>
<string name="reading_contacts_error">There was an error reading your contacts list</string>
</resources>