blob: 123f345eba9bcd1ba1bc28b5f53f6d8ef1322575 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package it.niedermann.owncloud.notes.manageaccounts;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.nextcloud.android.sso.model.SingleSignOnAccount;
import java.util.List;
import it.niedermann.owncloud.notes.android.activity.LockedActivity;
import it.niedermann.owncloud.notes.databinding.ActivityManageAccountsBinding;
import it.niedermann.owncloud.notes.model.LocalAccount;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
public class ManageAccountsActivity extends LockedActivity {
private ActivityManageAccountsBinding binding;
private ManageAccountAdapter adapter;
private NotesDatabase db = null;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityManageAccountsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
db = NotesDatabase.getInstance(this);
List<LocalAccount> localAccounts = db.getAccounts();
adapter = new ManageAccountAdapter((localAccount) -> {
SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccount.getAccountName());
}, (localAccount) -> {
db.deleteAccount(localAccount);
for (LocalAccount temp : localAccounts) {
if (temp.getId() == localAccount.getId()) {
localAccounts.remove(temp);
break;
}
}
if (localAccounts.size() > 0) {
SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccounts.get(0).getAccountName());
adapter.setCurrentLocalAccount(localAccounts.get(0));
} else {
setResult(AppCompatActivity.RESULT_FIRST_USER);
finish();
}
});
adapter.setLocalAccounts(localAccounts);
try {
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this);
if (ssoAccount != null) {
adapter.setCurrentLocalAccount(db.getLocalAccountByAccountName(ssoAccount.name));
}
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
}
binding.accounts.setAdapter(adapter);
}
@Override
public void applyBrand(int mainColor, int textColor) {
applyBrandToPrimaryToolbar(binding.toolbar);
}
}
|