style: fix accessibility issues
Fix a plethora of style issues that lead to a worse touch experience. I tried to optimize these solutions so that they didn't reduce the layout density too much. More updates may have to be made in the future.
This commit is contained in:
@@ -185,13 +185,6 @@ fun @receiver:ColorRes Int.resolveStateList(context: Context) =
|
||||
fun @receiver:DrawableRes Int.resolveDrawable(context: Context) =
|
||||
requireNotNull(ContextCompat.getDrawable(context, this))
|
||||
|
||||
/**
|
||||
* Resolve a drawable resource into an [AnimatedVectorDrawable]
|
||||
* @see resolveDrawable
|
||||
*/
|
||||
fun @receiver:DrawableRes Int.resolveAnimDrawable(context: Context) =
|
||||
resolveDrawable(context) as AnimatedVectorDrawable
|
||||
|
||||
/**
|
||||
* Resolve this int into a color as if it was an attribute
|
||||
*/
|
||||
|
||||
@@ -161,8 +161,6 @@ class MainFragment : Fragment() {
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
} else {
|
||||
binding.compactPlayback.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class ExcludedDatabase(context: Context) : SQLiteOpenHelper(context, DB_NAME, nu
|
||||
private var INSTANCE: ExcludedDatabase? = null
|
||||
|
||||
/**
|
||||
* Get/Instantiate the single instance of [PlaybackStateDatabase].
|
||||
* Get/Instantiate the single instance of [ExcludedDatabase].
|
||||
*/
|
||||
fun getInstance(context: Context): ExcludedDatabase {
|
||||
val currentInstance = INSTANCE
|
||||
|
||||
@@ -79,19 +79,11 @@ class CompactPlaybackFragment : Fragment() {
|
||||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) { isPlaying ->
|
||||
binding.playbackPlayPause.setPlaying(isPlaying, playbackModel.canAnimate)
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
binding.playbackPlayPause.isActivated = isPlaying
|
||||
}
|
||||
|
||||
logD("Fragment Created")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Auxio Project
|
||||
* PlayPauseButton.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatImageButton
|
||||
import org.oxycblt.auxio.R
|
||||
|
||||
/**
|
||||
* Custom [AppCompatImageButton] that handles the animated play/pause icons.
|
||||
* @author OxygenCobalt
|
||||
* TODO: Replace this with a material icon that does the path manipulation manually.
|
||||
*/
|
||||
class PlayPauseButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = -1
|
||||
) : AppCompatImageButton(context, attrs, defStyleAttr) {
|
||||
/**
|
||||
* Update the play/pause icon to reflect [isPlaying]
|
||||
* @param animate Whether the icon change should be animated or not.
|
||||
*/
|
||||
fun setPlaying(isPlaying: Boolean, animate: Boolean) {
|
||||
if (isPlaying) {
|
||||
setImageResource(R.drawable.ic_pause)
|
||||
} else {
|
||||
setImageResource(R.drawable.ic_play)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,11 +107,7 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
}
|
||||
|
||||
playbackModel.isShuffling.observe(viewLifecycleOwner) { isShuffling ->
|
||||
binding.playbackShuffle.imageTintList = if (isShuffling) {
|
||||
accentColor
|
||||
} else {
|
||||
controlColor
|
||||
}
|
||||
binding.playbackShuffle.isActivated = isShuffling
|
||||
}
|
||||
|
||||
playbackModel.loopMode.observe(viewLifecycleOwner) { loopMode ->
|
||||
@@ -174,17 +170,7 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) { isPlaying ->
|
||||
binding.playbackPlayPause.apply {
|
||||
if (isPlaying) {
|
||||
backgroundTintList = accentColor
|
||||
setPlaying(true, playbackModel.canAnimate)
|
||||
} else {
|
||||
backgroundTintList = controlColor
|
||||
setPlaying(false, playbackModel.canAnimate)
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
binding.playbackPlayPause.isActivated = isPlaying
|
||||
}
|
||||
|
||||
detailModel.navToItem.observe(viewLifecycleOwner) { item ->
|
||||
@@ -198,12 +184,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
}
|
||||
|
||||
// --- SEEK CALLBACKS ---
|
||||
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
|
||||
@@ -70,7 +70,6 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
// Other
|
||||
private val mIsSeeking = MutableLiveData(false)
|
||||
private var mIntentUri: Uri? = null
|
||||
private var mCanAnimate = false
|
||||
|
||||
/** The current song. */
|
||||
val song: LiveData<Song?> get() = mSong
|
||||
@@ -94,7 +93,6 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
val loopMode: LiveData<LoopMode> get() = mLoopMode
|
||||
|
||||
val isSeeking: LiveData<Boolean> get() = mIsSeeking
|
||||
val canAnimate: Boolean get() = mCanAnimate
|
||||
|
||||
/** The position as a duration string. */
|
||||
val formattedPosition = Transformations.map(mPosition) {
|
||||
@@ -351,8 +349,6 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
* Flip the playing status, e.g from playing to paused
|
||||
*/
|
||||
fun invertPlayingStatus() {
|
||||
enableAnimation()
|
||||
|
||||
playbackManager.setPlaying(!playbackManager.isPlaying)
|
||||
}
|
||||
|
||||
@@ -435,20 +431,6 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
mIsSeeking.value = isSeeking
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable animation on the play/pause button, usually done after the first LiveData fire
|
||||
*/
|
||||
fun enableAnimation() {
|
||||
mCanAnimate = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable animation on play/pause button, usually done after when a UI is created
|
||||
*/
|
||||
fun disableAnimation() {
|
||||
mCanAnimate = false
|
||||
}
|
||||
|
||||
// --- OVERRIDES ---
|
||||
|
||||
override fun onCleared() {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.oxycblt.auxio.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.widget.RemoteViews
|
||||
import androidx.annotation.LayoutRes
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -118,20 +119,20 @@ fun createFullWidget(context: Context, state: WidgetState): RemoteViews {
|
||||
)
|
||||
)
|
||||
|
||||
// The main way the large widget differs from the other widgets is the addition of extra
|
||||
// controls. However, since we can't retrieve the context of our views here, we cant
|
||||
// dynamically set the image view attributes. More duplicate resources it is. This is
|
||||
// getting really tiring.
|
||||
// While it is technically possible to use the setColorFilter to tint these buttons, its
|
||||
// actually less efficent than using duplicate drawables.
|
||||
// And no, we can't control state drawables with RemoteViews. Because of course we can't.
|
||||
|
||||
val shuffleRes = when {
|
||||
state.isShuffled -> R.drawable.ic_shuffle_tinted
|
||||
else -> R.drawable.ic_shuffle
|
||||
}
|
||||
|
||||
|
||||
val loopRes = when (state.loopMode) {
|
||||
LoopMode.NONE -> R.drawable.ic_loop
|
||||
LoopMode.ALL -> R.drawable.ic_loop_all_tinted
|
||||
LoopMode.TRACK -> R.drawable.ic_loop_one_tinted
|
||||
LoopMode.ALL -> R.drawable.ic_loop_tinted
|
||||
LoopMode.TRACK -> R.drawable.ic_loop_one
|
||||
}
|
||||
|
||||
views.setImageViewResource(R.id.widget_shuffle, shuffleRes)
|
||||
|
||||
Reference in New Issue
Block a user