-
Notifications
You must be signed in to change notification settings - Fork 0
/
BmkListDialogAdapter
81 lines (66 loc) · 2.1 KB
/
BmkListDialogAdapter
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
package app.organicmaps.bookmarks;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.R;
import app.organicmaps.bookmarks.data.BookmarkInfo;
import app.organicmaps.bookmarks.data.BookmarkManager;
import java.util.HashMap;
import java.util.List;
public class BookmarkListDialogAdapter extends BaseBookmarkAdapter<BookmarkListDialogAdapter.SingleChoiceHolder>
{
public static final int VIEW_TYPE_CATEGORY = 0;
public static final int VIEW_TYPE_ADD_NEW = 1;
private int mCheckedPosition;
public BookmarkListDialogAdapter(Context context, int pos,
@NonNull HashMap<Long,Boolean> mBookmarkNames)
{
super(context, mBookmarkNames);
mCheckedPosition = pos;
}
@Override
public SingleChoiceHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view;
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.item_bookmark_category_choose, parent, false);
final SingleChoiceHolder holder = new SingleChoiceHolder(view);
return holder;
}
@Override
public void onBindViewHolder(SingleChoiceHolder holder, int position)
{
String bmkName = getBookmarkInfo(position);
holder.name.setText(bmkName);
}
@Override
public int getItemViewType(int position)
{
return position == getItemCount() - 1 ? VIEW_TYPE_ADD_NEW : VIEW_TYPE_CATEGORY;
}
@Override
public int getItemCount()
{
return getItemCount() + 1;
}
public void chooseItem(int position)
{
final int oldPosition = mCheckedPosition;
mCheckedPosition = position;
notifyItemChanged(oldPosition);
notifyItemChanged(mCheckedPosition);
}
static class SingleChoiceHolder extends RecyclerView.ViewHolder
{
TextView name;
public SingleChoiceHolder(View convertView)
{
super(convertView);
name = convertView.findViewById(R.id.tv__set_name);
}
}
}