@Provides @VideoSizePercentage Integer provideVideoSizePercentage(@VideoSizePercentage IntPreference pref) { return pref.get(); }
@Override public void onBindViewHolder(ShiftValueViewHolder holder, final int position) { int viewType = getItemViewType(position); final ShiftValue key = mData.get(position); holder.title.setText(key.FEATURE); holder.title.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(mContext, "Author: " + key.AUTHOR, Toast.LENGTH_SHORT).show(); } }); switch (viewType) { case TYPE_BOOLEAN: final BooleanPreference boolPref = (BooleanPreference) mShiftValueToPref.get(key); holder.onOrOff.setOnCheckedChangeListener(null); holder.onOrOff.setChecked(boolPref.getValue()); holder.onOrOff.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { boolPref.setValue(!boolPref.getValue()); ShiftManager.getInstance().notifyShiftListeners(key); } }); break; case TYPE_STRING: final StringPreference stringPref = (StringPreference) mShiftValueToPref.get(key); holder.editString.removeTextChangedListener(holder.textWatcher); holder.editString.setText(stringPref.getValue()); holder.textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void afterTextChanged(Editable editable) { stringPref.setValue(editable.toString()); ShiftManager.getInstance().notifyShiftListeners(key); } }; holder.editString.addTextChangedListener(holder.textWatcher); break; case TYPE_INT: final IntPreference intPref = (IntPreference) mShiftValueToPref.get(key); holder.editInt.removeTextChangedListener(holder.textWatcher); holder.editInt.setText(intPref.getValue() + ""); holder.textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void afterTextChanged(Editable editable) { if (!editable.toString().isEmpty()) { Integer value; try { value = Integer.valueOf(editable.toString()); intPref.setValue(value); ShiftManager.getInstance().notifyShiftListeners(key); } catch (NumberFormatException error) { showNumberOverFlowErrorToast(); } } } }; holder.editInt.addTextChangedListener(holder.textWatcher); break; case TYPE_FLOAT: final FloatPreference floatPref = (FloatPreference) mShiftValueToPref.get(key); holder.editFloat.removeTextChangedListener(holder.textWatcher); holder.editFloat.setText(floatPref.getValue() + ""); holder.textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void afterTextChanged(Editable editable) { if (!editable.toString().isEmpty()) { try { Float value = Float.valueOf(editable.toString()); floatPref.setValue(value); ShiftManager.getInstance().notifyShiftListeners(key); } catch (NumberFormatException error) { showNumberOverFlowErrorToast(); } } } }; holder.editFloat.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL); holder.editFloat.addTextChangedListener(holder.textWatcher); break; case TYPE_STRING_SELECTOR: final StringListSelectorPreference stringSelectorPref = (StringListSelectorPreference) mShiftValueToPref.get(key); List<String> values = stringSelectorPref.getValue().getList(); int selectedIndex = stringSelectorPref.getValue().selectedIndex; ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, values); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); holder.spinnerStringSelector.setAdapter(adapter); holder.spinnerStringSelector.setSelection(selectedIndex); holder.spinnerStringSelector.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { stringSelectorPref.setSelectedIndex(position); ShiftManager.getInstance().notifyShiftListeners(key); } @Override public void onNothingSelected(AdapterView<?> parent) { // Do nothing } }); } }