-
-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathManageAccountViewHolder.java
More file actions
83 lines (71 loc) · 3.43 KB
/
ManageAccountViewHolder.java
File metadata and controls
83 lines (71 loc) · 3.43 KB
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
75
76
77
78
79
80
81
82
83
/*
* Nextcloud Notes - Android Client
*
* SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package it.niedermann.owncloud.notes.manageaccounts;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static it.niedermann.owncloud.notes.shared.util.ApiVersionUtil.getPreferredApiVersion;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
import androidx.recyclerview.widget.RecyclerView;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.share.helper.AvatarLoader;
public class ManageAccountViewHolder extends RecyclerView.ViewHolder {
private final ItemAccountChooseBinding binding;
public ManageAccountViewHolder(@NonNull View itemView) {
super(itemView);
binding = ItemAccountChooseBinding.bind(itemView);
}
public void bind(
@NonNull Account localAccount,
@NonNull IManageAccountsCallback callback,
boolean isCurrentAccount
) {
binding.accountName.setText(localAccount.getUserName());
binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost());
AvatarLoader.INSTANCE.load(itemView.getContext(), binding.accountItemAvatar, localAccount);
itemView.setOnClickListener((v) -> callback.onSelect(localAccount));
binding.accountContextMenu.setVisibility(VISIBLE);
binding.accountContextMenu.setOnClickListener((v) -> {
final var popup = new PopupMenu(itemView.getContext(), v);
popup.inflate(R.menu.menu_account);
final var preferredApiVersion = getPreferredApiVersion(localAccount.getApiVersion());
if (preferredApiVersion == null || !preferredApiVersion.supportsFileSuffixChange()) {
popup.getMenu().removeItem(popup.getMenu().findItem(R.id.file_suffix).getItemId());
}
if (preferredApiVersion == null || !preferredApiVersion.supportsNotesPathChange()) {
popup.getMenu().removeItem(popup.getMenu().findItem(R.id.notes_path).getItemId());
}
popup.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.notes_path) {
callback.onChangeNotesPath(localAccount);
return true;
} else if (item.getItemId() == R.id.file_suffix) {
callback.onChangeFileSuffix(localAccount);
return true;
} else if (item.getItemId() == R.id.delete) {
callback.onDelete(localAccount);
return true;
}
return false;
});
popup.show();
});
if (isCurrentAccount) {
binding.currentAccountIndicator.setVisibility(VISIBLE);
final var util = BrandingUtil.of(localAccount.getColor(), itemView.getContext());
util.notes.colorLayerDrawable((LayerDrawable) binding.currentAccountIndicator.getDrawable(), R.id.area, localAccount.getColor());
} else {
binding.currentAccountIndicator.setVisibility(GONE);
}
}
}