diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-06-13 17:45:34 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-06-15 21:32:47 +0300 |
commit | 8c116bd987d96be3d76506c3204fb0ed922e9ed4 (patch) | |
tree | 6aba36b09ccf6c8795d1836dbaf84a37feead9c1 /app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher | |
parent | 0d79609c849b47da5d7bd08f94f80a3645a9a188 (diff) |
Remove old Account drawer and make AccountSwitcher functional
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher')
2 files changed, 15 insertions, 20 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java index ee59a54d8..f849f15c3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherDialog.java @@ -5,10 +5,8 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.view.View; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; @@ -59,25 +57,36 @@ public class AccountSwitcherDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { binding = DialogAccountSwitcherBinding.inflate(requireActivity().getLayoutInflater()); - - binding.accountItemLabel.setText(viewModel.getCurrentAccount().getName()); + Glide.with(requireContext()) .load(viewModel.getCurrentAccount().getUrl() + "/index.php/avatar/" + Uri.encode(viewModel.getCurrentAccount().getUserName()) + "/64") .error(R.drawable.ic_person_grey600_24dp) .apply(RequestOptions.circleCropTransform()) .into(binding.currentAccountItemAvatar); + binding.accountLayout.setOnClickListener((v) -> dismiss()); adapter = new AccountSwitcherAdapter((localAccount -> { viewModel.setCurrentAccount(localAccount, localAccount.getServerDeckVersionAsObject().isSupported(requireContext())); dismiss(); })); + + syncManager.readAccounts().observe(requireActivity(), (localAccounts) -> { + for (Account localAccount : localAccounts) { + if (localAccount.getId() == viewModel.getCurrentAccount().getId()) { + localAccounts.remove(localAccount); + break; + } + } + adapter.setLocalAccounts(localAccounts); + }); + binding.accountsList.setAdapter(adapter); binding.addAccount.setOnClickListener((v) -> { try { - AccountImporter.pickNewAccount(this); + AccountImporter.pickNewAccount(requireActivity()); } catch (NextcloudFilesAppNotInstalledException e) { ExceptionUtil.handleNextcloudFilesAppNotInstalledException(requireContext(), e); } catch (AndroidGetAccountsPermissionNotGranted e) { @@ -96,20 +105,6 @@ public class AccountSwitcherDialog extends DialogFragment { .create(); } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - syncManager.readAccounts().observe(getViewLifecycleOwner(), (localAccounts) -> { - for (Account localAccount : localAccounts) { - if (localAccount.getId() == viewModel.getCurrentAccount().getId()) { - localAccounts.remove(localAccount); - break; - } - } - adapter.setLocalAccounts(localAccounts); - }); - } - public static DialogFragment newInstance(long currentAccountId) { DialogFragment dialog = new AccountSwitcherDialog(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherViewHolder.java index b3f6e5117..1aadf87e0 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/accountswitcher/AccountSwitcherViewHolder.java @@ -24,7 +24,7 @@ public class AccountSwitcherViewHolder extends RecyclerView.ViewHolder { } public void bind(@NonNull Account account, @NonNull Consumer<Account> onAccountClick) { - binding.accountItemLabel.setText(account.getUserName()); + binding.accountItemLabel.setText(account.getName()); Glide.with(itemView.getContext()) .load(account.getUrl() + "/index.php/avatar/" + Uri.encode(account.getUserName()) + "/64") .error(R.drawable.ic_person_grey600_24dp) |