Skip to content

Commit

Permalink
Crop long param names. #10 #11 Update dialog when receive EVENT param…
Browse files Browse the repository at this point in the history
…. Refactor Param dialog
  • Loading branch information
SrMouraSilva committed Mar 1, 2018
1 parent 9c12e5f commit eceab7f
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 60 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
android:name="io.github.pedalpi.displayview.communication.server.App">
<!--<activity android:naio.github.pedalpi.displayview.activity.MainActivityvity">-->
<activity android:name="io.github.pedalpi.displayview.activity.resume.ResumeActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
><!-- android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden" -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class EffectListItemViewHolder(private val adapter : EffectsListItemAdapter): Ge

override lateinit var dto: EffectsListItemDTO

override var row: View? = null
override var view: View? = null
set(value) {
field = row
name = row?.findViewById(R.id.effectsListItemName) as Button
status = row?.findViewById(R.id.effectsListItemStatus) as ToggleButton
field = view
name = view?.findViewById(R.id.effectsListItemName) as Button
status = view?.findViewById(R.id.effectsListItemStatus) as ToggleButton

name.setOnClickListener { adapter.selectEffectListener(dto) }
status.setOnClickListener { adapter.toggleStatusListener(dto) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.github.pedalpi.displayview.R
import io.github.pedalpi.displayview.util.generateSpinnerDropdownAdapter


class ParamListItemViewHolderCombobox(private val changeable: ParamValueChangeable): ParamListItemViewHolder {
class ParamListItemViewHolderCombobox(private val notifier: ParamValueChangeNotifier): ParamListItemViewHolder {

override val layout: Int = R.layout.param_list_item_combobox

Expand All @@ -21,7 +21,7 @@ class ParamListItemViewHolderCombobox(private val changeable: ParamValueChangeab

override lateinit var dto: ParamListItemDTO

override var row: View? = null
override var view: View? = null
set(row) {
field = row
name = row?.findViewById(R.id.paramsListItemName) as TextView
Expand Down Expand Up @@ -64,7 +64,7 @@ class ParamListItemViewHolderCombobox(private val changeable: ParamValueChangeab

private fun selected(position: Int) {
dto.param.value = position
changeable.onParamValueChange(dto.param)
notifier.onParamValueChange(dto.param)
}

private fun nextValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import io.github.pedalpi.displayview.model.ParamType

class ParamListItemViewHolderFactory {
companion object {
@JvmStatic fun build(changable: ParamValueChangeable, type: ParamType): ParamListItemViewHolder {
@JvmStatic fun build(notifier: ParamValueChangeNotifier, type: ParamType): ParamListItemViewHolder {
return when (type) {
ParamType.COMBOBOX -> ParamListItemViewHolderCombobox(changable)
ParamType.TOGGLE -> ParamListItemViewHolderToggle(changable)
else -> ParamListItemViewHolderSlider(changable)
ParamType.COMBOBOX -> ParamListItemViewHolderCombobox(notifier)
ParamType.TOGGLE -> ParamListItemViewHolderToggle(notifier)
else -> ParamListItemViewHolderSlider(notifier)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.github.pedalpi.displayview.R
/**
* https://github.com/p4x3c0/PedalPi-Display-View/blob/master/app/src/main/java/com/pedalpi/pedalpi/component/ParamSeekbar.java
*/
class ParamListItemViewHolderSlider(private val changeable: ParamValueChangeable) : ParamListItemViewHolder {
class ParamListItemViewHolderSlider(private val notifier: ParamValueChangeNotifier) : ParamListItemViewHolder {

override val layout: Int = R.layout.param_list_item_slider

Expand All @@ -20,7 +20,7 @@ class ParamListItemViewHolderSlider(private val changeable: ParamValueChangeable

override lateinit var dto: ParamListItemDTO

override var row: View? = null
override var view: View? = null
set(row) {
field = row
name = row?.findViewById(R.id.paramsListItemName) as TextView
Expand All @@ -38,7 +38,7 @@ class ParamListItemViewHolderSlider(private val changeable: ParamValueChangeable

value.text = "$progress%"
dto.param.value = dto.param.calculateValueByPercent(progress)
changeable.onParamValueChange(dto.param)
notifier.onParamValueChange(dto.param)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.github.pedalpi.displayview.R
/**
* https://github.com/p4x3c0/PedalPi-Display-View/blob/master/app/src/main/java/com/pedalpi/pedalpi/component/ParamSeekbar.java
*/
class ParamListItemViewHolderToggle(private val changeable: ParamValueChangeable) : ParamListItemViewHolder {
class ParamListItemViewHolderToggle(private val notifier: ParamValueChangeNotifier) : ParamListItemViewHolder {

override val layout: Int = R.layout.param_list_item_toggle

Expand All @@ -18,15 +18,15 @@ class ParamListItemViewHolderToggle(private val changeable: ParamValueChangeable

override lateinit var dto: ParamListItemDTO

override var row: View? = null
override var view: View? = null
set(row) {
field = row
name = row?.findViewById(R.id.paramsListItemName) as TextView
toggle = row?.findViewById(R.id.paramsListItemToggle) as ToggleButton

toggle.setOnClickListener {
dto.param.value = if (toggle.isChecked) 1 else 0
changeable.onParamValueChange(dto.param)
notifier.onParamValueChange(dto.param)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.github.pedalpi.displayview.util.GenericViewHolder

typealias ValueChangedListener = (param: Param) -> Unit

interface ParamValueChangeable {
interface ParamValueChangeNotifier {
var onParamValueChange: ValueChangedListener
}

Expand All @@ -19,7 +19,7 @@ interface ParamListItemViewHolder : GenericViewHolder<ParamListItemDTO> {

class ParamsListItemAdapter(private val context: Context, items: List<ParamListItemDTO>)
: GenericAdapter<ParamListItemDTO, ParamListItemViewHolder>(context, items),
ParamValueChangeable {
ParamValueChangeNotifier {

override var onParamValueChange: ValueChangedListener = { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EffectGridItemViewHolder(private val selectable: EffectSelectable, val res

override lateinit var dto: EffectGridItemDTO

override var row: View? = null
override var view: View? = null
set(row) {
field = row
name = row?.findViewById(R.id.effectsGridItemName) as Button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package io.github.pedalpi.displayview.activity.resume.effectview

import android.content.Context
import android.util.Log
import android.view.View
import android.widget.AdapterView.OnItemClickListener
import android.widget.GridView
import android.widget.TextView
import android.widget.ToggleButton
import io.github.pedalpi.displayview.activity.params.ParamListItemDTO
import io.github.pedalpi.displayview.activity.params.ParamListItemViewHolderFactory
import io.github.pedalpi.displayview.activity.params.ParamValueChangeable
import io.github.pedalpi.displayview.activity.params.ParamValueChangeNotifier
import io.github.pedalpi.displayview.activity.params.ValueChangedListener
import io.github.pedalpi.displayview.model.Effect
import io.github.pedalpi.displayview.model.Pedalboard
import io.github.pedalpi.displayview.util.generateCustomDialog
import io.github.pedalpi.displayview.util.inflate


typealias EffectToggleStatusListener = (effect: Effect) -> Unit

class OnDialogParamValueChange(private val paramsView: EffectView): ParamValueChangeable {
class EffectViewParamValueChangeNotifier(private val paramsView: EffectView): ParamValueChangeNotifier {
override var onParamValueChange: ValueChangedListener
get() = {
paramsView.updateParamView(it.index)
Expand All @@ -38,12 +33,18 @@ class EffectView(
var effect: Effect? = null
private lateinit var adapter: ParamsGridItemAdapter

private val valueChangeNotifier = EffectViewParamValueChangeNotifier(this)

var onParamValueChange: ValueChangedListener = {}
var onEffectToggleStatus: EffectToggleStatusListener = {}
val paramDialog = ParamDialog(context, valueChangeNotifier)

init {
clear()

gridView.onItemClickListener = OnItemClickListener { parent, view, position, id ->
val viewHolder = view.tag as ParamGridItemViewHolder
showDialog(ParamListItemDTO(viewHolder.dto.param))
this.paramDialog.show(viewHolder.dto.param)
}

effectStatus.setOnClickListener {
Expand All @@ -52,11 +53,6 @@ class EffectView(
}
}

private val onValueChangeDialog = OnDialogParamValueChange(this)

var onParamValueChange: ValueChangedListener = {}
var onEffectToggleStatus: EffectToggleStatusListener = {}

/**
* Change the view for the first effect of the pedalboard
* or show none if pedalboard haven't effects
Expand All @@ -81,7 +77,7 @@ class EffectView(
}

private fun populateViews(effect: Effect) {
this.adapter = ParamsGridItemAdapter(context, generateData(effect))
this.adapter = ParamsGridItemAdapter(context, valueChangeNotifier, generateData(effect))

this.gridView.adapter = adapter
this.adapter.notifyDataSetChanged()
Expand All @@ -97,25 +93,12 @@ class EffectView(
this.update(null)
}

private fun showDialog(item: ParamListItemDTO) {
Log.i("PARAM", item.param.name)

val viewHolder = ParamListItemViewHolderFactory.build(onValueChangeDialog, item.param.type)

val view = context.inflate(viewHolder.layout)

viewHolder.row = view
item.viewHolder = viewHolder
viewHolder.update(context, item)

context.generateCustomDialog(view).show()
}

/**
* Update the param view
*/
fun updateParamView(paramIndex: Int) {
adapter.update(paramIndex)
paramDialog.update()
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.pedalpi.displayview.activity.resume.effectview

import android.content.Context
import android.view.ViewGroup
import io.github.pedalpi.displayview.activity.params.ParamListItemDTO
import io.github.pedalpi.displayview.activity.params.ParamListItemViewHolder
import io.github.pedalpi.displayview.activity.params.ParamListItemViewHolderFactory
import io.github.pedalpi.displayview.activity.params.ParamValueChangeNotifier
import io.github.pedalpi.displayview.model.Param
import io.github.pedalpi.displayview.util.generateCustomDialog
import io.github.pedalpi.displayview.util.inflate


class ParamDialog(private val context: Context, private val notifier: ParamValueChangeNotifier) {

private var viewHolder: ParamListItemViewHolder? = null

fun show(param: Param) {
val dto = ParamListItemDTO(param)

val viewHolder = ParamListItemViewHolderFactory.build(notifier, param.type)
this.viewHolder = viewHolder

val view = context.inflate(viewHolder.layout) as ViewGroup

viewHolder.view = view
dto.viewHolder = viewHolder
viewHolder.update(context, dto)

val dialog = context.generateCustomDialog(view)
dialog.setOnCancelListener { this.viewHolder = null }
dialog.show()
}

fun update() {
this.viewHolder?.update(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.view.View
import android.widget.ProgressBar
import android.widget.TextView
import io.github.pedalpi.displayview.R
import io.github.pedalpi.displayview.model.ParamType


class ParamGridItemViewHolderProgress : ParamGridItemViewHolder {
Expand All @@ -16,7 +17,7 @@ class ParamGridItemViewHolderProgress : ParamGridItemViewHolder {

override lateinit var dto: ParamGridItemDTO

override var row: View? = null
override var view: View? = null
set(row) {
field = row
name = row?.findViewById(R.id.paramsGridItemName) as TextView
Expand All @@ -29,7 +30,15 @@ class ParamGridItemViewHolderProgress : ParamGridItemViewHolder {
this.dto = paramDTO

name.text = paramDTO.param.name
value.text = "${paramDTO.param.valueAsPercent}%"
value.text = this.valueText
progress.progress = paramDTO.param.valueAsPercent
}

private val valueText: String
get() {
return when {
dto.param.type == ParamType.COMBOBOX -> dto.param.optionValue
else -> "${dto.param.valueAsPercent}%"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.pedalpi.displayview.activity.resume.effectview

import android.view.View
import android.widget.TextView
import android.widget.ToggleButton
import io.github.pedalpi.displayview.R
import io.github.pedalpi.displayview.activity.params.ParamValueChangeNotifier


class ParamGridItemViewHolderToggle(private val notifier: ParamValueChangeNotifier) : ParamGridItemViewHolder {

override val layout: Int = R.layout.resume_param_grid_item_toggle

private lateinit var name: TextView
private lateinit var toggle: ToggleButton

override lateinit var dto: ParamGridItemDTO

override var view: View? = null
set(row) {
field = row
name = row?.findViewById(R.id.paramsGridItemName) as TextView
toggle = row?.findViewById(R.id.paramGridItemToggle) as ToggleButton

toggle.setOnClickListener {
this.dto.param.value = if (this.dto.param.value == 1) 0 else 1
notifier.onParamValueChange(this.dto.param)
}
}

override fun update(paramDTO: ParamGridItemDTO) {
this.dto = paramDTO

name.text = paramDTO.param.name
toggle.isChecked = paramDTO.param.value.toInt() == 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ package io.github.pedalpi.displayview.activity.resume.effectview

import android.content.Context
import android.view.View
import io.github.pedalpi.displayview.activity.params.ParamValueChangeNotifier
import io.github.pedalpi.displayview.model.ParamType
import io.github.pedalpi.displayview.util.GenericAdapter
import io.github.pedalpi.displayview.util.GenericViewHolder


interface ParamGridItemViewHolder: GenericViewHolder<ParamGridItemDTO> {
override var dto: ParamGridItemDTO
override val layout: Int
override var row: View?
override var view: View?

fun update(paramDTO: ParamGridItemDTO)
}

class ParamsGridItemAdapter(context: Context, items: List<ParamGridItemDTO>)
class ParamsGridItemAdapter(context: Context, private val notifier: ParamValueChangeNotifier, items: List<ParamGridItemDTO>)
: GenericAdapter<ParamGridItemDTO, ParamGridItemViewHolder>(context, items) {

override fun generateViewHolder(dto: ParamGridItemDTO): ParamGridItemViewHolder {
return ParamGridItemViewHolderProgress()
return when {
dto.param.type == ParamType.TOGGLE -> ParamGridItemViewHolderToggle(notifier)
else -> ParamGridItemViewHolderProgress()
}
}

override fun update(item: ParamGridItemDTO, viewHolder: ParamGridItemViewHolder) {
Expand Down
Loading

0 comments on commit eceab7f

Please sign in to comment.