blob: 19adee12ac7e956d71d33d77de7c5afbb29dcc77 (
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
75
76
77
78
|
package it.niedermann.owncloud.notes.manageaccounts;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Consumer;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.persistence.entity.Account;
public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountViewHolder> {
@Nullable
private Account currentLocalAccount = null;
@NonNull
private final List<Account> localAccounts = new ArrayList<>();
@NonNull
private final Consumer<Account> onAccountClick;
@NonNull
private final Consumer<Account> onAccountDelete;
@NonNull
Consumer<Account> onChangeNotesPath;
@NonNull
Consumer<Account> onChangeFileSuffix;
public ManageAccountAdapter(@NonNull Consumer<Account> onAccountClick,
@NonNull Consumer<Account> onAccountDelete,
@NonNull Consumer<Account> onChangeNotesPath,
@NonNull Consumer<Account> onChangeFileSuffix) {
this.onAccountClick = onAccountClick;
this.onAccountDelete = onAccountDelete;
this.onChangeNotesPath = onChangeNotesPath;
this.onChangeFileSuffix = onChangeFileSuffix;
setHasStableIds(true);
}
@Override
public long getItemId(int position) {
return localAccounts.get(position).getId();
}
@NonNull
@Override
public ManageAccountViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ManageAccountViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_account_choose, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ManageAccountViewHolder holder, int position) {
final var localAccount = localAccounts.get(position);
holder.bind(localAccount, (localAccountClicked) -> {
setCurrentLocalAccount(localAccountClicked);
onAccountClick.accept(localAccountClicked);
}, onAccountDelete, onChangeNotesPath, onChangeFileSuffix, currentLocalAccount != null && currentLocalAccount.getId() == localAccount.getId());
}
@Override
public int getItemCount() {
return localAccounts.size();
}
public void setLocalAccounts(@NonNull List<Account> localAccounts) {
this.localAccounts.clear();
this.localAccounts.addAll(localAccounts);
notifyDataSetChanged();
}
public void setCurrentLocalAccount(@Nullable Account currentLocalAccount) {
this.currentLocalAccount = currentLocalAccount;
notifyDataSetChanged();
}
}
|