1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.androidx.widget.util; 18 19 import android.annotation.SuppressLint; 20 import android.view.View; 21 import android.widget.CheckBox; 22 import android.widget.CompoundButton; 23 24 import androidx.recyclerview.widget.RecyclerView; 25 26 public class ConfigViewHolder extends RecyclerView.ViewHolder 27 implements CompoundButton.OnCheckedChangeListener { 28 29 private CheckBox mCheckBox; 30 31 private ConfigToggle mConfigToggle; 32 ConfigViewHolder(View itemView)33 public ConfigViewHolder(View itemView) { 34 super(itemView); 35 mCheckBox = (CheckBox) itemView; 36 mCheckBox.setOnCheckedChangeListener(this); 37 } 38 bind(ConfigToggle toggle)39 public void bind(ConfigToggle toggle) { 40 mConfigToggle = toggle; 41 mCheckBox.setText(toggle.getText()); 42 mCheckBox.setChecked(toggle.isChecked()); 43 } 44 45 @Override 46 @SuppressLint("UnknownNullness") onCheckedChanged(CompoundButton buttonView, boolean isChecked)47 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 48 if (mConfigToggle != null) { 49 mConfigToggle.onChange(isChecked); 50 } 51 } 52 } 53