do not show installed accounts in restore view

This commit is contained in:
Daniel Gultsch 2019-01-23 12:45:15 +01:00
parent 18982174ce
commit 2e0db4dcda
3 changed files with 10 additions and 6 deletions

View file

@ -103,6 +103,7 @@ public class ImportBackupService extends Service {
public void loadBackupFiles(OnBackupFilesLoaded onBackupFilesLoaded) {
executor.execute(() -> {
List<Jid> accounts = mDatabaseBackend.getAccountJids(false);
final ArrayList<BackupFile> backupFiles = new ArrayList<>();
final Set<String> apps = new HashSet<>(Arrays.asList("Conversations", "Quicksy", getString(R.string.app_name)));
for (String app : apps) {
@ -114,7 +115,12 @@ public class ImportBackupService extends Service {
for (File file : directory.listFiles()) {
if (file.isFile() && file.getName().endsWith(".ceb")) {
try {
backupFiles.add(BackupFile.read(file));
final BackupFile backupFile = BackupFile.read(file);
if (accounts.contains(backupFile.getHeader().getJid())) {
Log.d(Config.LOGTAG,"skipping backup for "+backupFile.getHeader().getJid());
} else {
backupFiles.add(backupFile);
}
} catch (IOException e) {
Log.d(Config.LOGTAG, "unable to read backup file ", e);
}
@ -153,7 +159,6 @@ public class ImportBackupService extends Service {
BufferedReader reader = new BufferedReader(new InputStreamReader(gzipInputStream, "UTF-8"));
String line;
StringBuilder multiLineQuery = null;
int error = 0;
while ((line = reader.readLine()) != null) {
int count = count(line, '\'');
if (multiLineQuery != null) {
@ -171,7 +176,6 @@ public class ImportBackupService extends Service {
}
}
}
Log.d(Config.LOGTAG, "done reading file");
final Jid jid = backupFileHeader.getJid();
Cursor countCursor = db.rawQuery("select count(messages.uuid) from messages join conversations on conversations.uuid=messages.conversationUuid join accounts on conversations.accountUuid=accounts.uuid where accounts.username=? and accounts.server=?", new String[]{jid.getEscapedLocal(), jid.getDomain()});
countCursor.moveToFirst();

View file

@ -917,11 +917,11 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return getAccounts(db);
}
public List<Jid> getAccountJids() {
public List<Jid> getAccountJids(final boolean enabledOnly) {
SQLiteDatabase db = this.getReadableDatabase();
final List<Jid> jids = new ArrayList<>();
final String[] columns = new String[]{Account.USERNAME, Account.SERVER};
String where = "not options & (1 <<1)";
String where = enabledOnly ? "not options & (1 <<1)" : null;
Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null);
try {
while (cursor.moveToNext()) {

View file

@ -85,7 +85,7 @@ public class UriHandlerActivity extends AppCompatActivity {
private void handleUri(Uri uri, final boolean scanned) {
final Intent intent;
final XmppUri xmppUri = new XmppUri(uri);
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(); //TODO only look at enabled accounts
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(true);
if (accounts.size() == 0) {
if (xmppUri.isJidValid()) {