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

SingleItemAdapterStrategy.java « gallery « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 750423b6550b0af44b77c25ac14d06f505343864 (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
package com.mapswithme.maps.gallery;

import android.content.res.Resources;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;

abstract class SingleItemAdapterStrategy<T extends Holders.BaseViewHolder<Items.Item>>
    extends AdapterStrategy<T, Items.Item>
{
  SingleItemAdapterStrategy(@Nullable String url,
                            @Nullable ItemSelectedListener<Items.Item> listener)
  {
    super(listener);
    buildItem(url);
  }

  protected void buildItem(@Nullable String url)
  {
    Resources res = MwmApplication.get().getResources();
    mItems.add(new Items.Item(res.getString(getTitle()), url,
                              res.getString(getSubtitle())));
  }

  @StringRes
  protected abstract int getTitle();

  @StringRes
  protected abstract int getSubtitle();

  @NonNull
  protected abstract View inflateView(@NonNull LayoutInflater inflater,
                                      @NonNull ViewGroup parent);

  @NonNull
  @Override
  protected T createViewHolder(@NonNull ViewGroup parent, int viewType)
  {
    View itemView = inflateView(LayoutInflater.from(parent.getContext()), parent);
    TextView button = (TextView) itemView.findViewById(R.id.button);
    button.setText(getLabelForDetailsView());
    return createViewHolder(itemView);
  }

  protected abstract T createViewHolder(@NonNull View itemView);

  @StringRes
  protected abstract int getLabelForDetailsView();

  @Override
  protected void onBindViewHolder(Holders.BaseViewHolder<Items.Item> holder, int position)
  {
    holder.bind(mItems.get(position));
  }

  @Override
  int getItemViewType(int position)
  {
    return 0;
  }
}