wjc
2025-02-07 e57e1c01a52a326343122d458ad3bd330fc9d347
countrypicker/src/main/java/com/sahooz/library/countrypicker/Adapter.java
@@ -5,6 +5,7 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.ViewGroup;
@@ -17,6 +18,7 @@
    private final LayoutInflater inflater;
    private PickCountryCallback callback = null;
    private final Context context;
    public Adapter(Context ctx) {
        inflater = LayoutInflater.from(ctx);
        context = ctx;
@@ -25,6 +27,7 @@
    public void setSelectedCountries(ArrayList<Country> selectedCountries) {
        this.selectedCountries = selectedCountries;
        notifyDataSetChanged();
    }
    public void setCallback(PickCountryCallback callback) {
@@ -38,8 +41,9 @@
    }
    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")
@@ -49,13 +53,13 @@
        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);
        });
    }