mirror of
https://github.com/clangen/musikcube.git
synced 2025-04-16 14:42:41 +00:00
More eq ui boilerplate.
This commit is contained in:
parent
87fbf5801d
commit
f974911ded
@ -2,6 +2,9 @@ package io.casey.musikcube.remote.ui.settings.activity
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.SeekBar
|
||||||
|
import android.widget.TableLayout
|
||||||
|
import android.widget.TextView
|
||||||
import io.casey.musikcube.remote.R
|
import io.casey.musikcube.remote.R
|
||||||
import io.casey.musikcube.remote.framework.ViewModel
|
import io.casey.musikcube.remote.framework.ViewModel
|
||||||
import io.casey.musikcube.remote.ui.settings.viewmodel.BaseRemoteViewModel
|
import io.casey.musikcube.remote.ui.settings.viewmodel.BaseRemoteViewModel
|
||||||
@ -17,6 +20,7 @@ class RemoteEqActivity: BaseActivity() {
|
|||||||
private lateinit var data: DataProviderMixin
|
private lateinit var data: DataProviderMixin
|
||||||
private lateinit var viewModel: RemoteEqViewModel
|
private lateinit var viewModel: RemoteEqViewModel
|
||||||
private lateinit var loadingOverlay: View
|
private lateinit var loadingOverlay: View
|
||||||
|
private lateinit var table: TableLayout
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
component.inject(this)
|
component.inject(this)
|
||||||
@ -26,6 +30,7 @@ class RemoteEqActivity: BaseActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_remote_eq)
|
setContentView(R.layout.activity_remote_eq)
|
||||||
this.loadingOverlay = findViewById(R.id.loading_overlay)
|
this.loadingOverlay = findViewById(R.id.loading_overlay)
|
||||||
|
this.table = findViewById(R.id.eq_table)
|
||||||
|
|
||||||
viewModel = createViewModel()!!
|
viewModel = createViewModel()!!
|
||||||
|
|
||||||
@ -49,6 +54,30 @@ class RemoteEqActivity: BaseActivity() {
|
|||||||
|
|
||||||
private fun drawNormal() {
|
private fun drawNormal() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
table.removeAllViews()
|
||||||
|
viewModel.sortedBands.forEach { hz ->
|
||||||
|
val row = layoutInflater.inflate(R.layout.eq_band_row, table, false)
|
||||||
|
val value = (viewModel.bands[hz] ?: 0.0).toInt()
|
||||||
|
val progress = (value + 20.0).toInt()
|
||||||
|
val valueText = row.findViewById<TextView>(R.id.value)
|
||||||
|
row.findViewById<TextView>(R.id.label).text = getString(R.string.remote_settings_eq_label_format, hz)
|
||||||
|
row.findViewById<SeekBar>(R.id.seekbar).apply {
|
||||||
|
this.progress = progress
|
||||||
|
this.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
|
valueText.text = getString(R.string.remote_settings_eq_value_format, progress - 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
valueText.text = getString(R.string.remote_settings_eq_value_format, value)
|
||||||
|
table.addView(row)
|
||||||
|
}
|
||||||
initialized = true
|
initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +94,7 @@ class RemoteEqActivity: BaseActivity() {
|
|||||||
drawNormal()
|
drawNormal()
|
||||||
}
|
}
|
||||||
BaseRemoteViewModel.State.Disconnected,
|
BaseRemoteViewModel.State.Disconnected,
|
||||||
|
BaseRemoteViewModel.State.Error,
|
||||||
BaseRemoteViewModel.State.Loading,
|
BaseRemoteViewModel.State.Loading,
|
||||||
BaseRemoteViewModel.State.Saving -> {
|
BaseRemoteViewModel.State.Saving -> {
|
||||||
drawLoading()
|
drawLoading()
|
||||||
|
@ -6,10 +6,10 @@ import io.reactivex.disposables.CompositeDisposable
|
|||||||
import io.reactivex.rxkotlin.subscribeBy
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
|
|
||||||
abstract class BaseRemoteViewModel: ViewModel<BaseRemoteViewModel.State>() {
|
abstract class BaseRemoteViewModel: ViewModel<BaseRemoteViewModel.State>() {
|
||||||
private var provider: IDataProvider? = null
|
protected var provider: IDataProvider? = null
|
||||||
protected var disposables = CompositeDisposable()
|
protected var disposables = CompositeDisposable()
|
||||||
|
|
||||||
enum class State { Disconnected, Saving, Saved, Loading, Ready }
|
enum class State { Disconnected, Saving, Saved, Loading, Ready, Error }
|
||||||
|
|
||||||
fun attach(provider: IDataProvider) {
|
fun attach(provider: IDataProvider) {
|
||||||
this.provider = provider
|
this.provider = provider
|
||||||
|
@ -1,7 +1,38 @@
|
|||||||
package io.casey.musikcube.remote.ui.settings.viewmodel
|
package io.casey.musikcube.remote.ui.settings.viewmodel
|
||||||
|
|
||||||
class RemoteEqViewModel: BaseRemoteViewModel() {
|
import io.casey.musikcube.remote.service.websocket.model.IEqualizerSettings
|
||||||
override fun onConnected() {
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
|
|
||||||
|
class RemoteEqViewModel: BaseRemoteViewModel() {
|
||||||
|
private var domainModel: IEqualizerSettings? = null
|
||||||
|
|
||||||
|
val sortedBands: List<Int>
|
||||||
|
get() {
|
||||||
|
return domainModel?.bands?.keys?.sorted() ?: listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
val bands: Map<Int, Double>
|
||||||
|
get() {
|
||||||
|
return domainModel?.bands ?: mapOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConnected() {
|
||||||
|
if (domainModel != null) {
|
||||||
|
state = State.Ready
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
provider?.let {
|
||||||
|
state = State.Loading
|
||||||
|
it.getEqualizerSettings().subscribeBy(
|
||||||
|
onNext = { result ->
|
||||||
|
domainModel = result
|
||||||
|
state = State.Ready
|
||||||
|
},
|
||||||
|
onError = {
|
||||||
|
state = State.Error
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,6 @@ import io.reactivex.rxkotlin.subscribeBy
|
|||||||
class RemoteSettingsViewModel: BaseRemoteViewModel() {
|
class RemoteSettingsViewModel: BaseRemoteViewModel() {
|
||||||
private var gain: IGainSettings? = null
|
private var gain: IGainSettings? = null
|
||||||
private var outputs: IOutputs? = null
|
private var outputs: IOutputs? = null
|
||||||
private var provider: IDataProvider? = null
|
|
||||||
|
|
||||||
var transportType: TransportType = TransportType.Gapless
|
var transportType: TransportType = TransportType.Gapless
|
||||||
private set(value) {
|
private set(value) {
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="8dp">
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/label"
|
android:id="@+id/label"
|
||||||
android:layout_column="1"
|
android:layout_column="1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical|right"
|
||||||
android:textSize="12sp"
|
|
||||||
tools:text="22000 hz" />
|
tools:text="22000 hz" />
|
||||||
|
|
||||||
<SeekBar
|
<SeekBar
|
||||||
@ -21,8 +21,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:min="0"
|
android:max="40" />
|
||||||
android:max="4000" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/value"
|
android:id="@+id/value"
|
||||||
@ -30,7 +29,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:textSize="12sp"
|
|
||||||
tools:text="0.0 dB"/>
|
tools:text="0.0 dB"/>
|
||||||
|
|
||||||
</TableRow>
|
</TableRow>
|
@ -133,6 +133,8 @@
|
|||||||
<string name="remote_settings_transport_type">playback transport</string>
|
<string name="remote_settings_transport_type">playback transport</string>
|
||||||
<string name="remote_settings_equalizer">equalizer</string>
|
<string name="remote_settings_equalizer">equalizer</string>
|
||||||
<string name="remote_settings_configure_eq_button">configure</string>
|
<string name="remote_settings_configure_eq_button">configure</string>
|
||||||
|
<string name="remote_settings_eq_label_format">%d hz</string>
|
||||||
|
<string name="remote_settings_eq_value_format">%d dB</string>
|
||||||
<string name="transport_type_gapless">gapless</string>
|
<string name="transport_type_gapless">gapless</string>
|
||||||
<string name="transport_type_crossfade">crossfade</string>
|
<string name="transport_type_crossfade">crossfade</string>
|
||||||
<string name="replaygain_mode_disabled">disabled</string>
|
<string name="replaygain_mode_disabled">disabled</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user