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

View File

@ -35,6 +35,8 @@ class OnScreenEditActivity : AppCompatActivity() {
@Inject
lateinit var appSettings : AppSettings
private var currentButtonName = ""
private fun paletteAction() {
DoubleColorPicker(this@OnScreenEditActivity).apply {
setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color))
@ -66,7 +68,7 @@ class OnScreenEditActivity : AppCompatActivity() {
private fun resetAction() {
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)
.setPositiveButton(R.string.confirm) { _, _ -> binding.onScreenControllerView.resetButton() }
.setNegativeButton(R.string.cancel, null)
@ -140,7 +142,7 @@ class OnScreenEditActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
updateActiveButtonDisplayInfo(binding.onScreenControllerView.editButton)
binding.onScreenControllerView.updateEditButtonInfo()
fullScreen()
}
@ -183,7 +185,8 @@ class OnScreenEditActivity : AppCompatActivity() {
*/
private fun updateActiveButtonDisplayInfo(button : ConfigurableButton) {
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.opacitySlider.slider.value = (button.config.alpha - OnScreenConfiguration.MinAlpha) / (OnScreenConfiguration.MaxAlpha - OnScreenConfiguration.MinAlpha).toFloat() * 100f
}