Merge pull request #12152 from JosJuice/android-settings-nullable

Android: Get rid of unnecessary nullability in features.settings
This commit is contained in:
JosJuice 2023-09-03 19:53:30 +02:00 committed by GitHub
commit 32f4f3ae7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 69 additions and 71 deletions

View File

@ -13,7 +13,7 @@ class InputDeviceSetting(
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
private val controller: EmulatedController private val controller: EmulatedController
) : StringSingleChoiceSetting(context, null, titleId, descriptionId, null, null, null) { ) : StringSingleChoiceSetting(context, null, titleId, descriptionId, arrayOf(), arrayOf(), null) {
init { init {
refreshChoicesAndValues() refreshChoicesAndValues()
} }

View File

@ -75,7 +75,7 @@ object NativeConfig {
file: String, file: String,
section: String, section: String,
key: String, key: String,
value: String? value: String
) )
@JvmStatic @JvmStatic

View File

@ -94,7 +94,7 @@ enum class StringSetting(
NativeConfig.setString(settings.writeLayer, file, section, key, newValue) NativeConfig.setString(settings.writeLayer, file, section, key, newValue)
} }
fun setString(layer: Int, newValue: String?) { fun setString(layer: Int, newValue: String) {
NativeConfig.setString(layer, file, section, key, newValue) NativeConfig.setString(layer, file, section, key, newValue)
} }

View File

@ -26,7 +26,7 @@ open class FloatSliderSetting : SliderSetting {
descriptionId: Int, descriptionId: Int,
min: Float, min: Float,
max: Float, max: Float,
units: String?, units: String,
stepSize: Float, stepSize: Float,
showDecimal: Boolean showDecimal: Boolean
) : super(context, titleId, descriptionId, units, showDecimal) { ) : super(context, titleId, descriptionId, units, showDecimal) {
@ -39,10 +39,10 @@ open class FloatSliderSetting : SliderSetting {
constructor( constructor(
setting: AbstractFloatSetting, setting: AbstractFloatSetting,
name: CharSequence, name: CharSequence,
description: CharSequence?, description: CharSequence,
min: Float, min: Float,
max: Float, max: Float,
units: String?, units: String,
stepSize: Float, stepSize: Float,
showDecimal: Boolean showDecimal: Boolean
) : super(name, description, units, showDecimal) { ) : super(name, description, units, showDecimal) {
@ -55,9 +55,9 @@ open class FloatSliderSetting : SliderSetting {
open val selectedValue: Float open val selectedValue: Float
get() = floatSetting.float get() = floatSetting.float
open fun setSelectedValue(settings: Settings?, selection: Float) { open fun setSelectedValue(settings: Settings, selection: Float) {
floatSetting.setFloat( floatSetting.setFloat(
settings!!, settings,
BigDecimal((selection).toDouble()).round(MathContext(3)).toFloat() BigDecimal((selection).toDouble()).round(MathContext(3)).toFloat()
) )
} }

View File

@ -14,7 +14,7 @@ open class HeaderSetting : SettingsItem {
descriptionId: Int descriptionId: Int
) : super(context, titleId, descriptionId) ) : super(context, titleId, descriptionId)
constructor(title: CharSequence, description: CharSequence?) : super(title, description) constructor(title: CharSequence, description: CharSequence) : super(title, description)
override val type: Int = TYPE_HEADER override val type: Int = TYPE_HEADER
} }

View File

@ -14,7 +14,7 @@ class IntSliderSetting(
descriptionId: Int, descriptionId: Int,
val min: Int, val min: Int,
val max: Int, val max: Int,
units: String?, units: String,
val stepSize: Int val stepSize: Int
) : SliderSetting(context, titleId, descriptionId, units, false) { ) : SliderSetting(context, titleId, descriptionId, units, false) {
@ -24,7 +24,7 @@ class IntSliderSetting(
val selectedValue: Int val selectedValue: Int
get() = intSetting.int get() = intSetting.int
fun setSelectedValue(settings: Settings?, selection: Int) { fun setSelectedValue(settings: Settings, selection: Int) {
intSetting.setInt(settings!!, selection) intSetting.setInt(settings, selection)
} }
} }

View File

@ -19,7 +19,7 @@ class InvertedSwitchSetting(
override val isChecked: Boolean override val isChecked: Boolean
get() = !booleanSetting.boolean get() = !booleanSetting.boolean
override fun setChecked(settings: Settings?, checked: Boolean) { override fun setChecked(settings: Settings, checked: Boolean) {
booleanSetting.setBoolean(settings!!, !checked) booleanSetting.setBoolean(settings, !checked)
} }
} }

View File

@ -7,8 +7,8 @@ import org.dolphinemu.dolphinemu.features.settings.model.Settings
class LogSwitchSetting( class LogSwitchSetting(
var key: String, var key: String,
title: CharSequence?, title: CharSequence,
description: CharSequence? description: CharSequence
) : SwitchSetting( ) : SwitchSetting(
AdHocBooleanSetting( AdHocBooleanSetting(
Settings.FILE_LOGGER, Settings.FILE_LOGGER,

View File

@ -15,7 +15,7 @@ class PercentSliderSetting(
descriptionId: Int, descriptionId: Int,
min: Float, min: Float,
max: Float, max: Float,
units: String?, units: String,
stepSize: Float, stepSize: Float,
showDecimal: Boolean showDecimal: Boolean
) : FloatSliderSetting( ) : FloatSliderSetting(
@ -32,9 +32,9 @@ class PercentSliderSetting(
override val selectedValue: Float override val selectedValue: Float
get() = (floatSetting.float * 100) get() = (floatSetting.float * 100)
override fun setSelectedValue(settings: Settings?, selection: Float) { override fun setSelectedValue(settings: Settings, selection: Float) {
floatSetting.setFloat( floatSetting.setFloat(
settings!!, settings,
BigDecimal((selection / 100).toDouble()).round(MathContext(3)).toFloat() BigDecimal((selection / 100).toDouble()).round(MathContext(3)).toFloat()
) )
} }

View File

@ -14,7 +14,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.Settings
*/ */
abstract class SettingsItem { abstract class SettingsItem {
val name: CharSequence val name: CharSequence
val description: CharSequence? val description: CharSequence
/** /**
* Base constructor. * Base constructor.
@ -22,7 +22,7 @@ abstract class SettingsItem {
* @param name A text string to be displayed as this Setting's name. * @param name A text string to be displayed as this Setting's name.
* @param description A text string to be displayed as this Setting's description. * @param description A text string to be displayed as this Setting's description.
*/ */
constructor(name: CharSequence, description: CharSequence?) { constructor(name: CharSequence, description: CharSequence) {
this.name = name this.name = name
this.description = description this.description = description
} }

View File

@ -24,7 +24,7 @@ class SingleChoiceSetting(
val selectedValue: Int val selectedValue: Int
get() = intSetting.int get() = intSetting.int
fun setSelectedValue(settings: Settings?, selection: Int) { fun setSelectedValue(settings: Settings, selection: Int) {
intSetting.setInt(settings!!, selection) intSetting.setInt(settings, selection)
} }
} }

View File

@ -7,14 +7,14 @@ import android.content.Context
sealed class SliderSetting : SettingsItem { sealed class SliderSetting : SettingsItem {
override val type: Int = TYPE_SLIDER override val type: Int = TYPE_SLIDER
val units: String? val units: String
val showDecimal: Boolean val showDecimal: Boolean
constructor( constructor(
context: Context, context: Context,
nameId: Int, nameId: Int,
descriptionId: Int, descriptionId: Int,
units: String?, units: String,
showDecimal: Boolean showDecimal: Boolean
) : super(context, nameId, descriptionId) { ) : super(context, nameId, descriptionId) {
this.units = units this.units = units
@ -23,8 +23,8 @@ sealed class SliderSetting : SettingsItem {
constructor( constructor(
name: CharSequence, name: CharSequence,
description: CharSequence?, description: CharSequence,
units: String?, units: String,
showDecimal: Boolean showDecimal: Boolean
) : super(name, description) { ) : super(name, description) {
this.units = units this.units = units

View File

@ -17,15 +17,15 @@ open class StringSingleChoiceSetting : SettingsItem {
override val setting: AbstractSetting? override val setting: AbstractSetting?
get() = stringSetting get() = stringSetting
var choices: Array<String>? var choices: Array<String>
protected set protected set
var values: Array<String>? var values: Array<String>
protected set protected set
val menuTag: MenuTag? val menuTag: MenuTag?
var noChoicesAvailableString = 0 var noChoicesAvailableString = 0
private set private set
open val selectedChoice: String? open val selectedChoice: String
get() = getChoiceAt(selectedValueIndex) get() = getChoiceAt(selectedValueIndex)
open val selectedValue: String open val selectedValue: String
@ -37,8 +37,8 @@ open class StringSingleChoiceSetting : SettingsItem {
setting: AbstractStringSetting?, setting: AbstractStringSetting?,
titleId: Int, titleId: Int,
descriptionId: Int, descriptionId: Int,
choices: Array<String>?, choices: Array<String>,
values: Array<String>?, values: Array<String>,
menuTag: MenuTag? = null menuTag: MenuTag? = null
) : super(context, titleId, descriptionId) { ) : super(context, titleId, descriptionId) {
stringSetting = setting stringSetting = setting
@ -75,27 +75,23 @@ open class StringSingleChoiceSetting : SettingsItem {
this.menuTag = menuTag this.menuTag = menuTag
} }
fun getChoiceAt(index: Int): String? { fun getChoiceAt(index: Int): String {
if (choices == null) return null return if (index >= 0 && index < choices.size) {
choices[index]
return if (index >= 0 && index < choices!!.size) {
choices!![index]
} else "" } else ""
} }
fun getValueAt(index: Int): String? { fun getValueAt(index: Int): String {
if (values == null) return null return if (index >= 0 && index < values.size) {
values[index]
return if (index >= 0 && index < values!!.size) {
values!![index]
} else "" } else ""
} }
val selectedValueIndex: Int val selectedValueIndex: Int
get() { get() {
val selectedValue = selectedValue val selectedValue = selectedValue
for (i in values!!.indices) { for (i in values.indices) {
if (values!![i] == selectedValue) { if (values[i] == selectedValue) {
return i return i
} }
} }

View File

@ -26,16 +26,16 @@ open class SwitchSetting : SettingsItem {
constructor( constructor(
setting: AbstractBooleanSetting, setting: AbstractBooleanSetting,
title: CharSequence?, title: CharSequence,
description: CharSequence? description: CharSequence
) : super(title!!, description) { ) : super(title, description) {
booleanSetting = setting booleanSetting = setting
} }
open val isChecked: Boolean open val isChecked: Boolean
get() = booleanSetting.boolean get() = booleanSetting.boolean
open fun setChecked(settings: Settings?, checked: Boolean) { open fun setChecked(settings: Settings, checked: Boolean) {
booleanSetting.setBoolean(settings!!, checked) booleanSetting.setBoolean(settings, checked)
} }
} }

View File

@ -138,7 +138,7 @@ class SettingsAdapter(
return getItem(position).type return getItem(position).type
} }
fun setSettings(settings: ArrayList<SettingsItem>?) { fun setSettings(settings: ArrayList<SettingsItem>) {
settingsList = settings settingsList = settings
notifyDataSetChanged() notifyDataSetChanged()
} }
@ -154,7 +154,7 @@ class SettingsAdapter(
} }
fun onBooleanClick(item: SwitchSetting, checked: Boolean) { fun onBooleanClick(item: SwitchSetting, checked: Boolean) {
item.setChecked(settings, checked) item.setChecked(settings!!, checked)
fragmentView.onSettingChanged() fragmentView.onSettingChanged()
} }
@ -194,7 +194,7 @@ class SettingsAdapter(
item.refreshChoicesAndValues() item.refreshChoicesAndValues()
val choices = item.choices val choices = item.choices
val noChoicesAvailableString = item.noChoicesAvailableString val noChoicesAvailableString = item.noChoicesAvailableString
dialog = if (noChoicesAvailableString != 0 && choices!!.isEmpty()) { dialog = if (noChoicesAvailableString != 0 && choices.isEmpty()) {
MaterialAlertDialogBuilder(fragmentView.fragmentActivity) MaterialAlertDialogBuilder(fragmentView.fragmentActivity)
.setTitle(item.name) .setTitle(item.name)
.setMessage(noChoicesAvailableString) .setMessage(noChoicesAvailableString)
@ -355,7 +355,7 @@ class SettingsAdapter(
dialog.show() dialog.show()
} }
fun onFilePickerDirectoryClick(item: SettingsItem?, position: Int) { fun onFilePickerDirectoryClick(item: SettingsItem, position: Int) {
clickedItem = item clickedItem = item
clickedPosition = position clickedPosition = position
@ -442,9 +442,9 @@ class SettingsAdapter(
} }
fun onFilePickerConfirmation(selectedFile: String) { fun onFilePickerConfirmation(selectedFile: String) {
val filePicker = clickedItem as FilePicker? val filePicker = clickedItem as FilePicker
if (filePicker!!.getSelectedValue() != selectedFile) { if (filePicker.getSelectedValue() != selectedFile) {
notifyItemChanged(clickedPosition) notifyItemChanged(clickedPosition)
fragmentView.onSettingChanged() fragmentView.onSettingChanged()
} }
@ -470,7 +470,7 @@ class SettingsAdapter(
val value = getValueForSingleChoiceSelection(scSetting, which) val value = getValueForSingleChoiceSelection(scSetting, which)
if (scSetting.selectedValue != value) fragmentView.onSettingChanged() if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
scSetting.setSelectedValue(settings, value) scSetting.setSelectedValue(settings!!, value)
closeDialog() closeDialog()
} }
@ -490,7 +490,7 @@ class SettingsAdapter(
val value = scSetting.getValueAt(which) val value = scSetting.getValueAt(which)
if (scSetting.selectedValue != value) fragmentView.onSettingChanged() if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
scSetting.setSelectedValue(settings!!, value!!) scSetting.setSelectedValue(settings!!, value)
closeDialog() closeDialog()
} }
@ -499,7 +499,7 @@ class SettingsAdapter(
if (sliderSetting.selectedValue != seekbarProgress.toInt()) { if (sliderSetting.selectedValue != seekbarProgress.toInt()) {
fragmentView.onSettingChanged() fragmentView.onSettingChanged()
} }
sliderSetting.setSelectedValue(settings, seekbarProgress.toInt()) sliderSetting.setSelectedValue(settings!!, seekbarProgress.toInt())
closeDialog() closeDialog()
} }
is FloatSliderSetting -> { is FloatSliderSetting -> {
@ -507,7 +507,7 @@ class SettingsAdapter(
if (sliderSetting.selectedValue != seekbarProgress) fragmentView.onSettingChanged() if (sliderSetting.selectedValue != seekbarProgress) fragmentView.onSettingChanged()
sliderSetting.setSelectedValue(settings, seekbarProgress) sliderSetting.setSelectedValue(settings!!, seekbarProgress)
closeDialog() closeDialog()
} }

View File

@ -90,8 +90,8 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
setInsets() setInsets()
val activity = activity as SettingsActivityView? val activity = requireActivity() as SettingsActivityView
presenter.onViewCreated(menuTag, activity!!.settings) presenter.onViewCreated(menuTag, activity.settings)
} }
override fun onDestroyView() { override fun onDestroyView() {

View File

@ -15,8 +15,8 @@ import org.dolphinemu.dolphinemu.utils.FileBrowserHelper
class FilePickerViewHolder( class FilePickerViewHolder(
private val binding: ListItemSettingBinding, private val binding: ListItemSettingBinding,
adapter: SettingsAdapter? adapter: SettingsAdapter
) : SettingViewHolder(binding.getRoot(), adapter!!) { ) : SettingViewHolder(binding.getRoot(), adapter) {
lateinit var setting: FilePicker lateinit var setting: FilePicker
override val item: SettingsItem override val item: SettingsItem

View File

@ -11,7 +11,7 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
class HeaderHyperLinkViewHolder( class HeaderHyperLinkViewHolder(
private val binding: ListItemHeaderBinding, private val binding: ListItemHeaderBinding,
adapter: SettingsAdapter? adapter: SettingsAdapter
) : HeaderViewHolder(binding, adapter) { ) : HeaderViewHolder(binding, adapter) {
init { init {
itemView.setOnClickListener(null) itemView.setOnClickListener(null)

View File

@ -9,8 +9,8 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
open class HeaderViewHolder( open class HeaderViewHolder(
private val binding: ListItemHeaderBinding, private val binding: ListItemHeaderBinding,
adapter: SettingsAdapter? adapter: SettingsAdapter
) : SettingViewHolder(binding.root, adapter!!) { ) : SettingViewHolder(binding.root, adapter) {
override val item: SettingsItem? = null override val item: SettingsItem? = null
init { init {

View File

@ -14,9 +14,10 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
class RunRunnableViewHolder( class RunRunnableViewHolder(
private val mBinding: ListItemSettingBinding, adapter: SettingsAdapter?, private val mBinding: ListItemSettingBinding,
adapter: SettingsAdapter,
private val mContext: Context private val mContext: Context
) : SettingViewHolder(mBinding.getRoot(), adapter!!) { ) : SettingViewHolder(mBinding.getRoot(), adapter) {
private lateinit var setting: RunRunnable private lateinit var setting: RunRunnable
override val item: SettingsItem override val item: SettingsItem

View File

@ -73,7 +73,7 @@ class SingleChoiceViewHolder(
} }
override fun onClick(clicked: View) { override fun onClick(clicked: View) {
if (!item?.isEditable!!) { if (!item!!.isEditable) {
showNotRuntimeEditableError() showNotRuntimeEditableError()
return return
} }

View File

@ -14,9 +14,10 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
class SliderViewHolder( class SliderViewHolder(
private val binding: ListItemSettingBinding, adapter: SettingsAdapter?, private val binding: ListItemSettingBinding,
adapter: SettingsAdapter,
private val context: Context private val context: Context
) : SettingViewHolder(binding.root, adapter!!) { ) : SettingViewHolder(binding.root, adapter) {
private lateinit var setting: SliderSetting private lateinit var setting: SliderSetting
override val item: SettingsItem override val item: SettingsItem