playback: force LTR on timeline controls
Force LTR on timeline controls, as per the Material Design guidelines. The guidelines state that while "directional" UIs should be LTR/RTL depending on locale, "timeline" UIs should always by LTR, as the direction of time is universal. Auxio did not do this, and so the timeline controls would be RTL on other elements. Fix this by forcing LTR on the UI elements that correspond to timelines. Now, this is not the best system. To ensure that the rest of the layout remains sane, much of the directional views have to be wrapped in a redundant layout, which is somewhat in-efficient. However, the impact seems to be at least negligable.
This commit is contained in:
@@ -43,8 +43,6 @@ import org.oxycblt.auxio.util.logD
|
||||
*
|
||||
* TODO: Custom language support
|
||||
*
|
||||
* TODO: Rework padding ethos
|
||||
*
|
||||
* TODO: Add multi-select
|
||||
*
|
||||
* @author OxygenCobalt
|
||||
|
||||
@@ -144,15 +144,15 @@ class AlbumDetailFragment :
|
||||
override fun onShowSortMenu(anchor: View) {
|
||||
menu(anchor, R.menu.menu_album_sort) {
|
||||
val sort = detailModel.albumSort
|
||||
requireNotNull(menu.findItem(sort.mode.itemId)).isChecked = true
|
||||
requireNotNull(menu.findItem(R.id.option_sort_asc)).isChecked = sort.isAscending
|
||||
unlikelyToBeNull(menu.findItem(sort.mode.itemId)).isChecked = true
|
||||
unlikelyToBeNull(menu.findItem(R.id.option_sort_asc)).isChecked = sort.isAscending
|
||||
setOnMenuItemClickListener { item ->
|
||||
item.isChecked = !item.isChecked
|
||||
detailModel.albumSort =
|
||||
if (item.itemId == R.id.option_sort_asc) {
|
||||
sort.withAscending(item.isChecked)
|
||||
} else {
|
||||
sort.withMode(requireNotNull(Sort.Mode.fromItemId(item.itemId)))
|
||||
sort.withMode(unlikelyToBeNull(Sort.Mode.fromItemId(item.itemId)))
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ class ArtistDetailFragment :
|
||||
override fun onShowSortMenu(anchor: View) {
|
||||
menu(anchor, R.menu.menu_artist_sort) {
|
||||
val sort = detailModel.artistSort
|
||||
requireNotNull(menu.findItem(sort.mode.itemId)).isChecked = true
|
||||
requireNotNull(menu.findItem(R.id.option_sort_asc)).isChecked = sort.isAscending
|
||||
unlikelyToBeNull(menu.findItem(sort.mode.itemId)).isChecked = true
|
||||
unlikelyToBeNull(menu.findItem(R.id.option_sort_asc)).isChecked = sort.isAscending
|
||||
setOnMenuItemClickListener { item ->
|
||||
item.isChecked = !item.isChecked
|
||||
|
||||
@@ -148,7 +148,7 @@ class ArtistDetailFragment :
|
||||
if (item.itemId == R.id.option_sort_asc) {
|
||||
sort.withAscending(item.isChecked)
|
||||
} else {
|
||||
sort.withMode(requireNotNull(Sort.Mode.fromItemId(item.itemId)))
|
||||
sort.withMode(unlikelyToBeNull(Sort.Mode.fromItemId(item.itemId)))
|
||||
}
|
||||
|
||||
true
|
||||
|
||||
@@ -140,15 +140,15 @@ class GenreDetailFragment :
|
||||
override fun onShowSortMenu(anchor: View) {
|
||||
menu(anchor, R.menu.menu_genre_sort) {
|
||||
val sort = detailModel.genreSort
|
||||
requireNotNull(menu.findItem(sort.mode.itemId)).isChecked = true
|
||||
requireNotNull(menu.findItem(R.id.option_sort_asc)).isChecked = sort.isAscending
|
||||
unlikelyToBeNull(menu.findItem(sort.mode.itemId)).isChecked = true
|
||||
unlikelyToBeNull(menu.findItem(R.id.option_sort_asc)).isChecked = sort.isAscending
|
||||
setOnMenuItemClickListener { item ->
|
||||
item.isChecked = !item.isChecked
|
||||
detailModel.genreSort =
|
||||
if (item.itemId == R.id.option_sort_asc) {
|
||||
sort.withAscending(item.isChecked)
|
||||
} else {
|
||||
sort.withMode(requireNotNull(Sort.Mode.fromItemId(item.itemId)))
|
||||
sort.withMode(unlikelyToBeNull(Sort.Mode.fromItemId(item.itemId)))
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.oxycblt.auxio.ui.DisplayMode
|
||||
import org.oxycblt.auxio.ui.Item
|
||||
import org.oxycblt.auxio.ui.MenuItemListener
|
||||
import org.oxycblt.auxio.ui.MonoAdapter
|
||||
import org.oxycblt.auxio.ui.Sort
|
||||
import org.oxycblt.auxio.ui.SongViewHolder
|
||||
import org.oxycblt.auxio.ui.Sort
|
||||
import org.oxycblt.auxio.ui.SyncBackingData
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.context
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Auxio Project
|
||||
*
|
||||
* 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 android.view.View
|
||||
import android.widget.FrameLayout
|
||||
|
||||
/**
|
||||
* A class that programmatically overrides the child layout to a left-to-right (LTR) layout
|
||||
* direction.
|
||||
*
|
||||
* The Material Design guidelines state that any components that represent a "Timeline" should
|
||||
* always be LTR. In Auxio, this applies to most of the playback components. This layout in
|
||||
* particular overrides the layout direction in a way that will not disrupt how other views are laid
|
||||
* out.
|
||||
*/
|
||||
open class NoRtlFrameLayout
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0,
|
||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
check(childCount == 1) { "This view should only contain one child" }
|
||||
getChildAt(0).layoutDirection = View.LAYOUT_DIRECTION_LTR
|
||||
}
|
||||
}
|
||||
@@ -73,10 +73,9 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
|
||||
// Load the track color in manually as it's unclear whether the track actually supports
|
||||
// using a ColorStateList in the resources
|
||||
binding.playbackProgressBar.trackColor =
|
||||
requireContext().getColorStateListSafe(R.color.sel_track).defaultColor
|
||||
|
||||
binding.playbackProgressBar.progress = 0
|
||||
binding.playbackProgressBar.apply {
|
||||
trackColor = requireContext().getColorStateListSafe(R.color.sel_track).defaultColor
|
||||
}
|
||||
|
||||
binding.playbackPlayPause.setOnClickListener { playbackModel.invertPlaying() }
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ import org.oxycblt.auxio.util.textSafe
|
||||
* Instantiation is done by the navigation component, **do not instantiate this fragment manually.**
|
||||
* @author OxygenCobalt
|
||||
*
|
||||
* TODO: Handle RTL correctly in the playback buttons
|
||||
*
|
||||
* TODO: Make seek thumb grow when selected
|
||||
*/
|
||||
class PlaybackPanelFragment :
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.FrameLayout
|
||||
import com.google.android.material.slider.Slider
|
||||
import kotlin.math.max
|
||||
import org.oxycblt.auxio.databinding.ViewSeekBarBinding
|
||||
@@ -52,12 +51,14 @@ constructor(
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0,
|
||||
) :
|
||||
FrameLayout(context, attrs, defStyleAttr),
|
||||
NoRtlFrameLayout(context, attrs, defStyleAttr),
|
||||
Slider.OnSliderTouchListener,
|
||||
Slider.OnChangeListener {
|
||||
private val binding = ViewSeekBarBinding.inflate(context.inflater, this)
|
||||
private val binding = ViewSeekBarBinding.inflate(context.inflater, this, true)
|
||||
|
||||
init {
|
||||
// As per the Material Design guidelines, timeline elements like SeekBars and Controls
|
||||
// should always be LTR.
|
||||
binding.seekBarSlider.addOnSliderTouchListener(this)
|
||||
binding.seekBarSlider.addOnChangeListener(this)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.oxycblt.auxio.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import androidx.annotation.LayoutRes
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -114,6 +115,9 @@ private fun RemoteViews.applyPlayPauseControls(
|
||||
R.id.widget_play_pause,
|
||||
context.newBroadcastPendingIntent(PlaybackService.ACTION_PLAY_PAUSE))
|
||||
|
||||
// Controls are timeline elements, override the layout direction to RTL
|
||||
setInt(R.id.widget_controls, "setLayoutDirection", View.LAYOUT_DIRECTION_LTR)
|
||||
|
||||
setImageViewResource(
|
||||
R.id.widget_play_pause,
|
||||
if (state.isPlaying) {
|
||||
|
||||
Reference in New Issue
Block a user