Improve separation between OSCEditActivity and OSCView

The activity shouldn't access the edit button directly, but should only access data available through the public interface.
This commit is contained in:
lynxnb 2023-04-03 00:25:00 +02:00 committed by Billy Laws
parent 7e3d3bd281
commit 69fb15ffc9
2 changed files with 10 additions and 4 deletions

View File

@ -72,7 +72,6 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
} }
internal val editInfo = OnScreenEditInfo() internal val editInfo = OnScreenEditInfo()
val editButton get() = editInfo.editButton
fun setOnEditButtonChangedListener(listener : OnEditButtonChangedListener?) { fun setOnEditButtonChangedListener(listener : OnEditButtonChangedListener?) {
editInfo.onEditButtonChangedListener = listener editInfo.onEditButtonChangedListener = listener
} }
@ -296,6 +295,10 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
setOnTouchListener(playingTouchHandler) setOnTouchListener(playingTouchHandler)
} }
fun updateEditButtonInfo() {
editInfo.onEditButtonChangedListener?.invoke(editInfo.editButton)
}
fun setEditMode(isEdit : Boolean) { fun setEditMode(isEdit : Boolean) {
// Select all buttons when entering edit if we weren't already editing // Select all buttons when entering edit if we weren't already editing
if (!editInfo.isEditing) if (!editInfo.isEditing)

View File

@ -35,6 +35,8 @@ class OnScreenEditActivity : AppCompatActivity() {
@Inject @Inject
lateinit var appSettings : AppSettings lateinit var appSettings : AppSettings
private var currentButtonName = ""
private fun paletteAction() { private fun paletteAction() {
DoubleColorPicker(this@OnScreenEditActivity).apply { DoubleColorPicker(this@OnScreenEditActivity).apply {
setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color)) setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color))
@ -66,7 +68,7 @@ class OnScreenEditActivity : AppCompatActivity() {
private fun resetAction() { private fun resetAction() {
MaterialAlertDialogBuilder(this) MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.osc_reset, binding.onScreenControllerView.editButton.buttonId.short)) .setTitle(getString(R.string.osc_reset, currentButtonName))
.setMessage(R.string.osc_reset_confirm) .setMessage(R.string.osc_reset_confirm)
.setPositiveButton(R.string.confirm) { _, _ -> binding.onScreenControllerView.resetButton() } .setPositiveButton(R.string.confirm) { _, _ -> binding.onScreenControllerView.resetButton() }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
@ -140,7 +142,7 @@ class OnScreenEditActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateActiveButtonDisplayInfo(binding.onScreenControllerView.editButton) binding.onScreenControllerView.updateEditButtonInfo()
fullScreen() fullScreen()
} }
@ -183,7 +185,8 @@ class OnScreenEditActivity : AppCompatActivity() {
*/ */
private fun updateActiveButtonDisplayInfo(button : ConfigurableButton) { private fun updateActiveButtonDisplayInfo(button : ConfigurableButton) {
binding.enabledCheckbox.checkedState = button.config.groupEnabled binding.enabledCheckbox.checkedState = button.config.groupEnabled
binding.currentButton.text = getString(R.string.osc_current_button, button.buttonId.short) currentButtonName = button.buttonId.short ?: ""
binding.currentButton.text = getString(R.string.osc_current_button, currentButtonName)
binding.scaleSlider.slider.value = (button.config.scale - OnScreenConfiguration.MinScale) / (OnScreenConfiguration.MaxScale - OnScreenConfiguration.MinScale) * 100f binding.scaleSlider.slider.value = (button.config.scale - OnScreenConfiguration.MinScale) / (OnScreenConfiguration.MaxScale - OnScreenConfiguration.MinScale) * 100f
binding.opacitySlider.slider.value = (button.config.alpha - OnScreenConfiguration.MinAlpha) / (OnScreenConfiguration.MaxAlpha - OnScreenConfiguration.MinAlpha).toFloat() * 100f binding.opacitySlider.slider.value = (button.config.alpha - OnScreenConfiguration.MinAlpha) / (OnScreenConfiguration.MaxAlpha - OnScreenConfiguration.MinAlpha).toFloat() * 100f
} }