Merge pull request #12152 from JosJuice/android-settings-nullable
Android: Get rid of unnecessary nullability in features.settings
This commit is contained in:
commit
32f4f3ae7c
|
@ -13,7 +13,7 @@ class InputDeviceSetting(
|
|||
titleId: Int,
|
||||
descriptionId: Int,
|
||||
private val controller: EmulatedController
|
||||
) : StringSingleChoiceSetting(context, null, titleId, descriptionId, null, null, null) {
|
||||
) : StringSingleChoiceSetting(context, null, titleId, descriptionId, arrayOf(), arrayOf(), null) {
|
||||
init {
|
||||
refreshChoicesAndValues()
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ object NativeConfig {
|
|||
file: String,
|
||||
section: String,
|
||||
key: String,
|
||||
value: String?
|
||||
value: String
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -94,7 +94,7 @@ enum class StringSetting(
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ open class FloatSliderSetting : SliderSetting {
|
|||
descriptionId: Int,
|
||||
min: Float,
|
||||
max: Float,
|
||||
units: String?,
|
||||
units: String,
|
||||
stepSize: Float,
|
||||
showDecimal: Boolean
|
||||
) : super(context, titleId, descriptionId, units, showDecimal) {
|
||||
|
@ -39,10 +39,10 @@ open class FloatSliderSetting : SliderSetting {
|
|||
constructor(
|
||||
setting: AbstractFloatSetting,
|
||||
name: CharSequence,
|
||||
description: CharSequence?,
|
||||
description: CharSequence,
|
||||
min: Float,
|
||||
max: Float,
|
||||
units: String?,
|
||||
units: String,
|
||||
stepSize: Float,
|
||||
showDecimal: Boolean
|
||||
) : super(name, description, units, showDecimal) {
|
||||
|
@ -55,9 +55,9 @@ open class FloatSliderSetting : SliderSetting {
|
|||
open val selectedValue: Float
|
||||
get() = floatSetting.float
|
||||
|
||||
open fun setSelectedValue(settings: Settings?, selection: Float) {
|
||||
open fun setSelectedValue(settings: Settings, selection: Float) {
|
||||
floatSetting.setFloat(
|
||||
settings!!,
|
||||
settings,
|
||||
BigDecimal((selection).toDouble()).round(MathContext(3)).toFloat()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ open class HeaderSetting : SettingsItem {
|
|||
descriptionId: Int
|
||||
) : 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
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class IntSliderSetting(
|
|||
descriptionId: Int,
|
||||
val min: Int,
|
||||
val max: Int,
|
||||
units: String?,
|
||||
units: String,
|
||||
val stepSize: Int
|
||||
) : SliderSetting(context, titleId, descriptionId, units, false) {
|
||||
|
||||
|
@ -24,7 +24,7 @@ class IntSliderSetting(
|
|||
val selectedValue: Int
|
||||
get() = intSetting.int
|
||||
|
||||
fun setSelectedValue(settings: Settings?, selection: Int) {
|
||||
intSetting.setInt(settings!!, selection)
|
||||
fun setSelectedValue(settings: Settings, selection: Int) {
|
||||
intSetting.setInt(settings, selection)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class InvertedSwitchSetting(
|
|||
override val isChecked: Boolean
|
||||
get() = !booleanSetting.boolean
|
||||
|
||||
override fun setChecked(settings: Settings?, checked: Boolean) {
|
||||
booleanSetting.setBoolean(settings!!, !checked)
|
||||
override fun setChecked(settings: Settings, checked: Boolean) {
|
||||
booleanSetting.setBoolean(settings, !checked)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import org.dolphinemu.dolphinemu.features.settings.model.Settings
|
|||
|
||||
class LogSwitchSetting(
|
||||
var key: String,
|
||||
title: CharSequence?,
|
||||
description: CharSequence?
|
||||
title: CharSequence,
|
||||
description: CharSequence
|
||||
) : SwitchSetting(
|
||||
AdHocBooleanSetting(
|
||||
Settings.FILE_LOGGER,
|
||||
|
|
|
@ -15,7 +15,7 @@ class PercentSliderSetting(
|
|||
descriptionId: Int,
|
||||
min: Float,
|
||||
max: Float,
|
||||
units: String?,
|
||||
units: String,
|
||||
stepSize: Float,
|
||||
showDecimal: Boolean
|
||||
) : FloatSliderSetting(
|
||||
|
@ -32,9 +32,9 @@ class PercentSliderSetting(
|
|||
override val selectedValue: Float
|
||||
get() = (floatSetting.float * 100)
|
||||
|
||||
override fun setSelectedValue(settings: Settings?, selection: Float) {
|
||||
override fun setSelectedValue(settings: Settings, selection: Float) {
|
||||
floatSetting.setFloat(
|
||||
settings!!,
|
||||
settings,
|
||||
BigDecimal((selection / 100).toDouble()).round(MathContext(3)).toFloat()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.Settings
|
|||
*/
|
||||
abstract class SettingsItem {
|
||||
val name: CharSequence
|
||||
val description: CharSequence?
|
||||
val description: CharSequence
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
|
@ -22,7 +22,7 @@ abstract class SettingsItem {
|
|||
* @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.
|
||||
*/
|
||||
constructor(name: CharSequence, description: CharSequence?) {
|
||||
constructor(name: CharSequence, description: CharSequence) {
|
||||
this.name = name
|
||||
this.description = description
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class SingleChoiceSetting(
|
|||
val selectedValue: Int
|
||||
get() = intSetting.int
|
||||
|
||||
fun setSelectedValue(settings: Settings?, selection: Int) {
|
||||
intSetting.setInt(settings!!, selection)
|
||||
fun setSelectedValue(settings: Settings, selection: Int) {
|
||||
intSetting.setInt(settings, selection)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ import android.content.Context
|
|||
sealed class SliderSetting : SettingsItem {
|
||||
override val type: Int = TYPE_SLIDER
|
||||
|
||||
val units: String?
|
||||
val units: String
|
||||
val showDecimal: Boolean
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
nameId: Int,
|
||||
descriptionId: Int,
|
||||
units: String?,
|
||||
units: String,
|
||||
showDecimal: Boolean
|
||||
) : super(context, nameId, descriptionId) {
|
||||
this.units = units
|
||||
|
@ -23,8 +23,8 @@ sealed class SliderSetting : SettingsItem {
|
|||
|
||||
constructor(
|
||||
name: CharSequence,
|
||||
description: CharSequence?,
|
||||
units: String?,
|
||||
description: CharSequence,
|
||||
units: String,
|
||||
showDecimal: Boolean
|
||||
) : super(name, description) {
|
||||
this.units = units
|
||||
|
|
|
@ -17,15 +17,15 @@ open class StringSingleChoiceSetting : SettingsItem {
|
|||
override val setting: AbstractSetting?
|
||||
get() = stringSetting
|
||||
|
||||
var choices: Array<String>?
|
||||
var choices: Array<String>
|
||||
protected set
|
||||
var values: Array<String>?
|
||||
var values: Array<String>
|
||||
protected set
|
||||
val menuTag: MenuTag?
|
||||
var noChoicesAvailableString = 0
|
||||
private set
|
||||
|
||||
open val selectedChoice: String?
|
||||
open val selectedChoice: String
|
||||
get() = getChoiceAt(selectedValueIndex)
|
||||
|
||||
open val selectedValue: String
|
||||
|
@ -37,8 +37,8 @@ open class StringSingleChoiceSetting : SettingsItem {
|
|||
setting: AbstractStringSetting?,
|
||||
titleId: Int,
|
||||
descriptionId: Int,
|
||||
choices: Array<String>?,
|
||||
values: Array<String>?,
|
||||
choices: Array<String>,
|
||||
values: Array<String>,
|
||||
menuTag: MenuTag? = null
|
||||
) : super(context, titleId, descriptionId) {
|
||||
stringSetting = setting
|
||||
|
@ -75,27 +75,23 @@ open class StringSingleChoiceSetting : SettingsItem {
|
|||
this.menuTag = menuTag
|
||||
}
|
||||
|
||||
fun getChoiceAt(index: Int): String? {
|
||||
if (choices == null) return null
|
||||
|
||||
return if (index >= 0 && index < choices!!.size) {
|
||||
choices!![index]
|
||||
fun getChoiceAt(index: Int): String {
|
||||
return if (index >= 0 && index < choices.size) {
|
||||
choices[index]
|
||||
} else ""
|
||||
}
|
||||
|
||||
fun getValueAt(index: Int): String? {
|
||||
if (values == null) return null
|
||||
|
||||
return if (index >= 0 && index < values!!.size) {
|
||||
values!![index]
|
||||
fun getValueAt(index: Int): String {
|
||||
return if (index >= 0 && index < values.size) {
|
||||
values[index]
|
||||
} else ""
|
||||
}
|
||||
|
||||
val selectedValueIndex: Int
|
||||
get() {
|
||||
val selectedValue = selectedValue
|
||||
for (i in values!!.indices) {
|
||||
if (values!![i] == selectedValue) {
|
||||
for (i in values.indices) {
|
||||
if (values[i] == selectedValue) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,16 +26,16 @@ open class SwitchSetting : SettingsItem {
|
|||
|
||||
constructor(
|
||||
setting: AbstractBooleanSetting,
|
||||
title: CharSequence?,
|
||||
description: CharSequence?
|
||||
) : super(title!!, description) {
|
||||
title: CharSequence,
|
||||
description: CharSequence
|
||||
) : super(title, description) {
|
||||
booleanSetting = setting
|
||||
}
|
||||
|
||||
open val isChecked: Boolean
|
||||
get() = booleanSetting.boolean
|
||||
|
||||
open fun setChecked(settings: Settings?, checked: Boolean) {
|
||||
booleanSetting.setBoolean(settings!!, checked)
|
||||
open fun setChecked(settings: Settings, checked: Boolean) {
|
||||
booleanSetting.setBoolean(settings, checked)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ class SettingsAdapter(
|
|||
return getItem(position).type
|
||||
}
|
||||
|
||||
fun setSettings(settings: ArrayList<SettingsItem>?) {
|
||||
fun setSettings(settings: ArrayList<SettingsItem>) {
|
||||
settingsList = settings
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class SettingsAdapter(
|
|||
}
|
||||
|
||||
fun onBooleanClick(item: SwitchSetting, checked: Boolean) {
|
||||
item.setChecked(settings, checked)
|
||||
item.setChecked(settings!!, checked)
|
||||
fragmentView.onSettingChanged()
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ class SettingsAdapter(
|
|||
item.refreshChoicesAndValues()
|
||||
val choices = item.choices
|
||||
val noChoicesAvailableString = item.noChoicesAvailableString
|
||||
dialog = if (noChoicesAvailableString != 0 && choices!!.isEmpty()) {
|
||||
dialog = if (noChoicesAvailableString != 0 && choices.isEmpty()) {
|
||||
MaterialAlertDialogBuilder(fragmentView.fragmentActivity)
|
||||
.setTitle(item.name)
|
||||
.setMessage(noChoicesAvailableString)
|
||||
|
@ -355,7 +355,7 @@ class SettingsAdapter(
|
|||
dialog.show()
|
||||
}
|
||||
|
||||
fun onFilePickerDirectoryClick(item: SettingsItem?, position: Int) {
|
||||
fun onFilePickerDirectoryClick(item: SettingsItem, position: Int) {
|
||||
clickedItem = item
|
||||
clickedPosition = position
|
||||
|
||||
|
@ -442,9 +442,9 @@ class SettingsAdapter(
|
|||
}
|
||||
|
||||
fun onFilePickerConfirmation(selectedFile: String) {
|
||||
val filePicker = clickedItem as FilePicker?
|
||||
val filePicker = clickedItem as FilePicker
|
||||
|
||||
if (filePicker!!.getSelectedValue() != selectedFile) {
|
||||
if (filePicker.getSelectedValue() != selectedFile) {
|
||||
notifyItemChanged(clickedPosition)
|
||||
fragmentView.onSettingChanged()
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ class SettingsAdapter(
|
|||
val value = getValueForSingleChoiceSelection(scSetting, which)
|
||||
if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
|
||||
|
||||
scSetting.setSelectedValue(settings, value)
|
||||
scSetting.setSelectedValue(settings!!, value)
|
||||
|
||||
closeDialog()
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ class SettingsAdapter(
|
|||
val value = scSetting.getValueAt(which)
|
||||
if (scSetting.selectedValue != value) fragmentView.onSettingChanged()
|
||||
|
||||
scSetting.setSelectedValue(settings!!, value!!)
|
||||
scSetting.setSelectedValue(settings!!, value)
|
||||
|
||||
closeDialog()
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ class SettingsAdapter(
|
|||
if (sliderSetting.selectedValue != seekbarProgress.toInt()) {
|
||||
fragmentView.onSettingChanged()
|
||||
}
|
||||
sliderSetting.setSelectedValue(settings, seekbarProgress.toInt())
|
||||
sliderSetting.setSelectedValue(settings!!, seekbarProgress.toInt())
|
||||
closeDialog()
|
||||
}
|
||||
is FloatSliderSetting -> {
|
||||
|
@ -507,7 +507,7 @@ class SettingsAdapter(
|
|||
|
||||
if (sliderSetting.selectedValue != seekbarProgress) fragmentView.onSettingChanged()
|
||||
|
||||
sliderSetting.setSelectedValue(settings, seekbarProgress)
|
||||
sliderSetting.setSelectedValue(settings!!, seekbarProgress)
|
||||
|
||||
closeDialog()
|
||||
}
|
||||
|
|
|
@ -90,8 +90,8 @@ class SettingsFragment : Fragment(), SettingsFragmentView {
|
|||
|
||||
setInsets()
|
||||
|
||||
val activity = activity as SettingsActivityView?
|
||||
presenter.onViewCreated(menuTag, activity!!.settings)
|
||||
val activity = requireActivity() as SettingsActivityView
|
||||
presenter.onViewCreated(menuTag, activity.settings)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
|
|
@ -15,8 +15,8 @@ import org.dolphinemu.dolphinemu.utils.FileBrowserHelper
|
|||
|
||||
class FilePickerViewHolder(
|
||||
private val binding: ListItemSettingBinding,
|
||||
adapter: SettingsAdapter?
|
||||
) : SettingViewHolder(binding.getRoot(), adapter!!) {
|
||||
adapter: SettingsAdapter
|
||||
) : SettingViewHolder(binding.getRoot(), adapter) {
|
||||
lateinit var setting: FilePicker
|
||||
|
||||
override val item: SettingsItem
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
|
|||
|
||||
class HeaderHyperLinkViewHolder(
|
||||
private val binding: ListItemHeaderBinding,
|
||||
adapter: SettingsAdapter?
|
||||
adapter: SettingsAdapter
|
||||
) : HeaderViewHolder(binding, adapter) {
|
||||
init {
|
||||
itemView.setOnClickListener(null)
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
|
|||
|
||||
open class HeaderViewHolder(
|
||||
private val binding: ListItemHeaderBinding,
|
||||
adapter: SettingsAdapter?
|
||||
) : SettingViewHolder(binding.root, adapter!!) {
|
||||
adapter: SettingsAdapter
|
||||
) : SettingViewHolder(binding.root, adapter) {
|
||||
override val item: SettingsItem? = null
|
||||
|
||||
init {
|
||||
|
|
|
@ -14,9 +14,10 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem
|
|||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
|
||||
|
||||
class RunRunnableViewHolder(
|
||||
private val mBinding: ListItemSettingBinding, adapter: SettingsAdapter?,
|
||||
private val mBinding: ListItemSettingBinding,
|
||||
adapter: SettingsAdapter,
|
||||
private val mContext: Context
|
||||
) : SettingViewHolder(mBinding.getRoot(), adapter!!) {
|
||||
) : SettingViewHolder(mBinding.getRoot(), adapter) {
|
||||
private lateinit var setting: RunRunnable
|
||||
|
||||
override val item: SettingsItem
|
||||
|
|
|
@ -73,7 +73,7 @@ class SingleChoiceViewHolder(
|
|||
}
|
||||
|
||||
override fun onClick(clicked: View) {
|
||||
if (!item?.isEditable!!) {
|
||||
if (!item!!.isEditable) {
|
||||
showNotRuntimeEditableError()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ import org.dolphinemu.dolphinemu.features.settings.model.view.SliderSetting
|
|||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter
|
||||
|
||||
class SliderViewHolder(
|
||||
private val binding: ListItemSettingBinding, adapter: SettingsAdapter?,
|
||||
private val binding: ListItemSettingBinding,
|
||||
adapter: SettingsAdapter,
|
||||
private val context: Context
|
||||
) : SettingViewHolder(binding.root, adapter!!) {
|
||||
) : SettingViewHolder(binding.root, adapter) {
|
||||
private lateinit var setting: SliderSetting
|
||||
|
||||
override val item: SettingsItem
|
||||
|
|
Loading…
Reference in New Issue