Closed zezung27 closed 2 years ago
package com.matcos.dynamicislandlight.noti;
import android.annotation.SuppressLint; import android.content.Context; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView;
import com.matcos.dynamicislandlight.R;
import java.util.ArrayList;
public class PackageAdapter extends RecyclerView.Adapter { private Context mContext; private ArrayList mList; INotiEnableCheckbox iNotiEnableCheckbox;
public PackageAdapter(Context mContext, ArrayList<PackageModal> mList) { this.mContext = mContext; this.mList = mList; } public void setClickCheckBoxListener(INotiEnableCheckbox clickCB) { this.iNotiEnableCheckbox = clickCB; } @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(mContext); View heroView = inflater.inflate(R.layout.row_enable_noti, parent, false); ViewHolder viewHolder = new ViewHolder(heroView); return viewHolder; } @Override public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) { // final int pos_fix = position; PackageModal packageModal = mList.get(position); holder.mImageHero.setImageDrawable(packageModal.getIcon()); holder.mTextName.setText(packageModal.getName()); holder.mTextPackageName.setText(packageModal.getPackageName()); holder.checkBox.setChecked(packageModal.isCheck()); } public ArrayList<PackageModal> getListUpdate() { return mList; } @Override public int getItemCount() { return mList.size(); } public class ViewHolder extends RecyclerView.ViewHolder { private ImageView mImageHero; private TextView mTextName; private TextView mTextPackageName; private CheckBox checkBox; public ViewHolder(@NonNull View itemView) { super(itemView); mImageHero = itemView.findViewById(R.id.imgIconPackage); mTextName = itemView.findViewById(R.id.nameApp); mTextPackageName = itemView.findViewById(R.id.namePackage); checkBox = itemView.findViewById(R.id.checkBoxNoti); checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean isChecked = ((CheckBox)view).isChecked(); if(isChecked) { mList.get(getAdapterPosition()).setCheck(true); } else { mList.get(getAdapterPosition()).setCheck(false); } notifyDataSetChanged(); } }); } }
}
package com.matcos.dynamicislandlight.noti;
import android.annotation.SuppressLint; import android.content.Context; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView;
import com.matcos.dynamicislandlight.R;
import java.util.ArrayList;
public class PackageAdapter extends RecyclerView.Adapter {
private Context mContext;
private ArrayList mList;
INotiEnableCheckbox iNotiEnableCheckbox;
}