blob: d8065279f79e0b139548f69e69188090797f714a (
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
|
package it.niedermann.nextcloud.deck.ui.preparecreate;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.databinding.ItemPickStackStackBinding;
import it.niedermann.nextcloud.deck.model.full.FullStack;
public class StackAdapter extends ArrayAdapter<FullStack> {
@NonNull
private final LayoutInflater inflater;
@SuppressWarnings("WeakerAccess")
public StackAdapter(@NonNull Context context) {
super(context, R.layout.item_pick_stack_account);
setDropDownViewResource(R.layout.item_pick_stack_account);
inflater = LayoutInflater.from(context);
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public long getItemId(int position) {
return Objects.requireNonNull(getItem(position)).getLocalId();
}
@NotNull
@Override
public View getView(int position, View convertView, @NotNull ViewGroup parent) {
final ItemPickStackStackBinding binding;
if (convertView == null) {
binding = ItemPickStackStackBinding.inflate(inflater, parent, false);
} else {
binding = ItemPickStackStackBinding.bind(convertView);
}
final FullStack item = getItem(position);
if (item != null) {
binding.stackTitle.setText(item.getStack().getTitle());
} else {
DeckLog.logError(new IllegalArgumentException("No item for position " + position));
}
return binding.getRoot();
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getView(position, convertView, parent);
}
}
|