mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
basic switch implementation
This commit is contained in:
@@ -262,7 +262,8 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
}
|
||||
|
||||
private void handleSwitchAccount() {
|
||||
ArrayList<AccountManager.Account> accounts = AccountManager.getInstance().getAccounts(this);
|
||||
AccountManager accountManager = AccountManager.getInstance();
|
||||
ArrayList<AccountManager.Account> accounts = accountManager.getAccounts(this);
|
||||
|
||||
// build menu
|
||||
ArrayList<String> menu = new ArrayList<>();
|
||||
@@ -284,11 +285,16 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setItems(menu.toArray(new String[menu.size()]), (dialog, which) -> {
|
||||
if (which==addAccount) {
|
||||
;
|
||||
accountManager.prepareToAddAccount(this);
|
||||
Intent intent = new Intent(this, WelcomeActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else if (which==deleteAccount) {
|
||||
;
|
||||
} else { // switch account
|
||||
;
|
||||
accountManager.switchAccount(this, accounts.get(which));
|
||||
finish();
|
||||
startActivity(new Intent(getApplicationContext(), ConversationListActivity.class));
|
||||
}
|
||||
})
|
||||
.show();
|
||||
|
||||
@@ -13,13 +13,6 @@ public class AccountManager {
|
||||
|
||||
private static AccountManager self;
|
||||
|
||||
public static AccountManager getInstance() {
|
||||
if (self == null) {
|
||||
self = new AccountManager();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
public class Account {
|
||||
private String file;
|
||||
private String displayname;
|
||||
@@ -41,7 +34,7 @@ public class AccountManager {
|
||||
}
|
||||
};
|
||||
|
||||
public @Nullable Account maybeGetAccount(File file) {
|
||||
private @Nullable Account maybeGetAccount(File file) {
|
||||
try {
|
||||
if (!file.isDirectory() && file.getName().endsWith(".db")) {
|
||||
DcContext testContext = new DcContext(null);
|
||||
@@ -60,6 +53,29 @@ public class AccountManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private File getUniqueDbName(Context context) {
|
||||
File dir = context.getFilesDir();
|
||||
int index = 1;
|
||||
while (true) {
|
||||
File test = new File(dir, String.format("messenger-%d.db", index));
|
||||
File testBlobdir = new File(dir, String.format("messenger-%d.db-blobs", index));
|
||||
if (!test.exists() && !testBlobdir.exists()) {
|
||||
return test;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public api
|
||||
|
||||
public static AccountManager getInstance() {
|
||||
if (self == null) {
|
||||
self = new AccountManager();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
public ArrayList<Account> getAccounts(Context context) {
|
||||
ArrayList<Account> result = new ArrayList<>();
|
||||
|
||||
@@ -78,4 +94,20 @@ public class AccountManager {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void prepareToAddAccount(Context context) {
|
||||
File newDb = getUniqueDbName(context);
|
||||
}
|
||||
|
||||
public void cancelAccountAdding(Context context) {
|
||||
|
||||
}
|
||||
|
||||
public void switchAccount(Context context, Account account) {
|
||||
|
||||
}
|
||||
|
||||
public File getSelectedAccount(Context context) {
|
||||
return new File(context.getFilesDir(), "messenger.db");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
super("Android "+BuildConfig.VERSION_NAME);
|
||||
this.context = context;
|
||||
|
||||
File dbfile = new File(context.getFilesDir(), "messenger.db");
|
||||
File dbfile = AccountManager.getInstance().getSelectedAccount(context);
|
||||
open(dbfile.getAbsolutePath());
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user