| | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import android.util.TypedValue; |
| | | import android.view.LayoutInflater; |
| | | import android.view.ViewGroup; |
| | |
| | | private final LayoutInflater inflater; |
| | | private PickCountryCallback callback = null; |
| | | private final Context context; |
| | | |
| | | public Adapter(Context ctx) { |
| | | inflater = LayoutInflater.from(ctx); |
| | | context = ctx; |
| | |
| | | public void setSelectedCountries(ArrayList<Country> selectedCountries) { |
| | | this.selectedCountries = selectedCountries; |
| | | notifyDataSetChanged(); |
| | | |
| | | } |
| | | |
| | | public void setCallback(PickCountryCallback callback) { |
| | |
| | | } |
| | | |
| | | private int itemHeight = -1; |
| | | |
| | | public void setItemHeight(float dp) { |
| | | itemHeight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, context.getResources().getDisplayMetrics()); |
| | | itemHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, context.getResources().getDisplayMetrics()); |
| | | } |
| | | |
| | | @SuppressLint("SetTextI18n") |
| | |
| | | holder.ivFlag.setImageResource(country.flag); |
| | | holder.tvName.setText(country.translate); |
| | | holder.tvCode.setText("+" + country.code); |
| | | if(itemHeight != -1) { |
| | | if (itemHeight != -1) { |
| | | ViewGroup.LayoutParams params = holder.itemView.getLayoutParams(); |
| | | params.height = itemHeight; |
| | | holder.itemView.setLayoutParams(params); |
| | | } |
| | | holder.itemView.setOnClickListener(v -> { |
| | | if(callback != null) callback.onPick(country); |
| | | if (callback != null) callback.onPick(country); |
| | | }); |
| | | } |
| | | |