diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index 7c7f54b..bc117e3 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -40,6 +40,10 @@ setVolume(id, value) } + init { + refresh() + } + private fun refresh() { // this is to resend the old information to the internal c++ code (when changing the waveform) muted = muted diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index 7c7f54b..bc117e3 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -40,6 +40,10 @@ setVolume(id, value) } + init { + refresh() + } + private fun refresh() { // this is to resend the old information to the internal c++ code (when changing the waveform) muted = muted diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 59e8054..687fd6a 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -12,9 +12,11 @@ import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.ui.fragments.EditInstrumentFragment +import com.lukas.music.util.setupToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, @@ -29,9 +31,6 @@ binding.editInstrumentButton.setOnClickListener { EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } - binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> - instrument?.muted = !newActive - } - binding.activeSwitch.isChecked = !instrument!!.muted + binding.muteButton.setupToggle(instrument!!::muted, R.color.red) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index 7c7f54b..bc117e3 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -40,6 +40,10 @@ setVolume(id, value) } + init { + refresh() + } + private fun refresh() { // this is to resend the old information to the internal c++ code (when changing the waveform) muted = muted diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 59e8054..687fd6a 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -12,9 +12,11 @@ import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.ui.fragments.EditInstrumentFragment +import com.lukas.music.util.setupToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, @@ -29,9 +31,6 @@ binding.editInstrumentButton.setOnClickListener { EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } - binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> - instrument?.muted = !newActive - } - binding.activeSwitch.isChecked = !instrument!!.muted + binding.muteButton.setupToggle(instrument!!::muted, R.color.red) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt index b9fa92b..5bb150a 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -10,7 +10,11 @@ package com.lukas.music.util +import android.widget.Button import android.widget.SeekBar +import androidx.core.content.ContextCompat +import com.lukas.music.R +import kotlin.reflect.KMutableProperty0 fun SeekBar.setup( min: Int, max: Int, initialProgress: Int, callback: (Int) -> Unit @@ -34,3 +38,15 @@ }) this.progress = initialProgress } + +fun Button.setupToggle(target: KMutableProperty0, activeColor: Int) { + setOnClickListener { + target.set(!target.get()) + setBackgroundColor( + ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) + ) + } + setBackgroundColor( + ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index 7c7f54b..bc117e3 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -40,6 +40,10 @@ setVolume(id, value) } + init { + refresh() + } + private fun refresh() { // this is to resend the old information to the internal c++ code (when changing the waveform) muted = muted diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 59e8054..687fd6a 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -12,9 +12,11 @@ import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.ui.fragments.EditInstrumentFragment +import com.lukas.music.util.setupToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, @@ -29,9 +31,6 @@ binding.editInstrumentButton.setOnClickListener { EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } - binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> - instrument?.muted = !newActive - } - binding.activeSwitch.isChecked = !instrument!!.muted + binding.muteButton.setupToggle(instrument!!::muted, R.color.red) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt index b9fa92b..5bb150a 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -10,7 +10,11 @@ package com.lukas.music.util +import android.widget.Button import android.widget.SeekBar +import androidx.core.content.ContextCompat +import com.lukas.music.R +import kotlin.reflect.KMutableProperty0 fun SeekBar.setup( min: Int, max: Int, initialProgress: Int, callback: (Int) -> Unit @@ -34,3 +38,15 @@ }) this.progress = initialProgress } + +fun Button.setupToggle(target: KMutableProperty0, activeColor: Int) { + setOnClickListener { + target.set(!target.get()) + setBackgroundColor( + ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) + ) + } + setBackgroundColor( + ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) + ) +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_instrument.xml b/app/src/main/res/layout/fragment_instrument.xml index e37f479..df3fb5c 100644 --- a/app/src/main/res/layout/fragment_instrument.xml +++ b/app/src/main/res/layout/fragment_instrument.xml @@ -44,21 +44,21 @@ android:cropToPadding="true" android:keepScreenOn="true" android:src="@android:drawable/ic_menu_edit" - app:backgroundTint="#1565C0" + app:backgroundTint="@color/material_dynamic_primary50" app:fabSize="mini" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/instrumentNameText" /> - + app:layout_constraintTop_toTopOf="@+id/editInstrumentButton" /> diff --git a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt index 7c7f54b..bc117e3 100644 --- a/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/InternalInstrument.kt @@ -40,6 +40,10 @@ setVolume(id, value) } + init { + refresh() + } + private fun refresh() { // this is to resend the old information to the internal c++ code (when changing the waveform) muted = muted diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt index 59e8054..687fd6a 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentViewHolder.kt @@ -12,9 +12,11 @@ import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView +import com.lukas.music.R import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.ui.fragments.EditInstrumentFragment +import com.lukas.music.util.setupToggle class InstrumentViewHolder( val binding: FragmentInstrumentBinding, @@ -29,9 +31,6 @@ binding.editInstrumentButton.setOnClickListener { EditInstrumentFragment(instrument!!, this).showNow(childFragmentManager, "") } - binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> - instrument?.muted = !newActive - } - binding.activeSwitch.isChecked = !instrument!!.muted + binding.muteButton.setupToggle(instrument!!::muted, R.color.red) } } \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/util/UIUtil.kt b/app/src/main/java/com/lukas/music/util/UIUtil.kt index b9fa92b..5bb150a 100644 --- a/app/src/main/java/com/lukas/music/util/UIUtil.kt +++ b/app/src/main/java/com/lukas/music/util/UIUtil.kt @@ -10,7 +10,11 @@ package com.lukas.music.util +import android.widget.Button import android.widget.SeekBar +import androidx.core.content.ContextCompat +import com.lukas.music.R +import kotlin.reflect.KMutableProperty0 fun SeekBar.setup( min: Int, max: Int, initialProgress: Int, callback: (Int) -> Unit @@ -34,3 +38,15 @@ }) this.progress = initialProgress } + +fun Button.setupToggle(target: KMutableProperty0, activeColor: Int) { + setOnClickListener { + target.set(!target.get()) + setBackgroundColor( + ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) + ) + } + setBackgroundColor( + ContextCompat.getColor(context, if (target.get()) activeColor else R.color.gray_0x60) + ) +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_instrument.xml b/app/src/main/res/layout/fragment_instrument.xml index e37f479..df3fb5c 100644 --- a/app/src/main/res/layout/fragment_instrument.xml +++ b/app/src/main/res/layout/fragment_instrument.xml @@ -44,21 +44,21 @@ android:cropToPadding="true" android:keepScreenOn="true" android:src="@android:drawable/ic_menu_edit" - app:backgroundTint="#1565C0" + app:backgroundTint="@color/material_dynamic_primary50" app:fabSize="mini" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/instrumentNameText" /> - + app:layout_constraintTop_toTopOf="@+id/editInstrumentButton" /> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 0c9082f..ff56d7a 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -30,4 +30,5 @@ #808080 #909090 #A0A0A0 + #F00000 \ No newline at end of file