Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LabelFilterAdapter.java « filter « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8fed859a57af916c335ddcb8b4d10415dbdc9de2 (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
package it.niedermann.nextcloud.deck.ui.filter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.jetbrains.annotations.NotNull;

import java.util.NoSuchElementException;

import it.niedermann.nextcloud.deck.model.Label;

public class LabelFilterAdapter extends ArrayAdapter<Label> {

    @NonNull
    private final LayoutInflater inflater;

    @SuppressWarnings("WeakerAccess")
    public LabelFilterAdapter(@NonNull Context context) {
        super(context, android.R.layout.simple_list_item_multiple_choice, android.R.id.text1);
        inflater = LayoutInflater.from(context);
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public long getItemId(int position) {
        final Label label = getItem(position);
        if (label == null) {
            throw new NoSuchElementException();
        }
        return label.getLocalId();
    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        return getView(position, convertView, parent);
    }

    @SuppressWarnings("WeakerAccess")
    public int getPosition(long labelId) {
        for (int i = 0; i < getCount(); i++) {
            if (getItemId(i) == labelId) {
                return i;
            }
        }
        throw new NoSuchElementException();
    }

    @NotNull
    @Override
    public View getView(int position, View convertView, @NotNull ViewGroup parent) {
        final View view;
        if (convertView == null) {
            view = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, parent, false);
        } else {
            view = convertView;
        }
        ((TextView) view.findViewById(android.R.id.text1)).setText(getItem(position).getTitle());
        return view;
    }
}