Translations update from Hosted Weblate (#524)
* weather: introduce display precipitation Introduce a new datatype called DisplayPrecipitation that optimizes the precipitation level for UI display. This is primarily meant to fix improper precipitation displays when values lower than 0.1 in are shown, albiet that may need to change eventually. * Translated using Weblate (Hindi) Currently translated at 100.0% (283 of 283 strings) Translation: Auxio/Strings Translate-URL: https://hosted.weblate.org/projects/auxio/strings/hi/ * Translated using Weblate (Lithuanian) Currently translated at 100.0% (283 of 283 strings) Translation: Auxio/Strings Translate-URL: https://hosted.weblate.org/projects/auxio/strings/lt/ * Translated using Weblate (Punjabi) Currently translated at 100.0% (283 of 283 strings) Translation: Auxio/Strings Translate-URL: https://hosted.weblate.org/projects/auxio/strings/pa/ * Translated using Weblate (Punjabi) Currently translated at 100.0% (36 of 36 strings) Translation: Auxio/Metadata Translate-URL: https://hosted.weblate.org/projects/auxio/metadata/pa/ * Translated using Weblate (Hindi) Currently translated at 100.0% (36 of 36 strings) Translation: Auxio/Metadata Translate-URL: https://hosted.weblate.org/projects/auxio/metadata/hi/ * Translated using Weblate (Spanish) Currently translated at 100.0% (283 of 283 strings) Translation: Auxio/Strings Translate-URL: https://hosted.weblate.org/projects/auxio/strings/es/ * Translated using Weblate (Polish) Currently translated at 100.0% (283 of 283 strings) Translation: Auxio/Strings Translate-URL: https://hosted.weblate.org/projects/auxio/strings/pl/ * Translated using Weblate (Finnish) Currently translated at 93.2% (264 of 283 strings) Translation: Auxio/Strings Translate-URL: https://hosted.weblate.org/projects/auxio/strings/fi/ --------- Co-authored-by: Alexander Capehart <alex@oxycblt.org> Co-authored-by: ShareASmile <aapshergill@gmail.com> Co-authored-by: Vaclovas Intas <vaclovas1999@gmail.com> Co-authored-by: gallegonovato <fran-carro@hotmail.es> Co-authored-by: Eryk Michalak <gnu.ewm@protonmail.com> Co-authored-by: Jiri Grönroos <jiri.gronroos@iki.fi>
This commit is contained in:
co-authored by
Alexander Capehart
ShareASmile
Vaclovas Intas
gallegonovato
Eryk Michalak
Jiri Grönroos
parent
a1947c4102
commit
816ab04252
@@ -192,7 +192,7 @@ class AlbumDetailFragment :
|
||||
override fun onShuffle() {
|
||||
playbackModel.shuffle(unlikelyToBeNull(detailModel.currentAlbum.value))
|
||||
}
|
||||
|
||||
|
||||
override fun onOpenSortMenu() {
|
||||
findNavController().navigateSafe(AlbumDetailFragmentDirections.sort())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* SortAdapter.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.list.sort
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.ItemSortModeBinding
|
||||
import org.oxycblt.auxio.list.Sort
|
||||
import org.oxycblt.auxio.list.adapter.FlexibleListAdapter
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
|
||||
class SortAdapter(var selectedMode: Sort.Mode) :
|
||||
FlexibleListAdapter<Sort.Mode, SortModeViewHolder>(SortModeViewHolder.DIFF_CALLBACK) {
|
||||
var currentlySelected = selectedMode
|
||||
private set
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
SortModeViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: SortModeViewHolder, position: Int) {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SortModeViewHolder, position: Int, payload: List<Any>) {
|
||||
val mode = getItem(position)
|
||||
if (payload.isEmpty()) {
|
||||
holder.bind(mode)
|
||||
}
|
||||
holder.setSelected(mode == currentlySelected)
|
||||
}
|
||||
|
||||
fun setSelected(mode: Sort.Mode) {
|
||||
if (mode == currentlySelected) return
|
||||
val oldMode = currentList.indexOf(currentlySelected)
|
||||
val newMode = currentList.indexOf(mode)
|
||||
currentlySelected = selectedMode
|
||||
notifyItemChanged(oldMode, PAYLOAD_SELECTION_CHANGED)
|
||||
notifyItemChanged(newMode, PAYLOAD_SELECTION_CHANGED)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val PAYLOAD_SELECTION_CHANGED = Any()
|
||||
}
|
||||
}
|
||||
|
||||
class SortModeViewHolder private constructor(private val binding: ItemSortModeBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(mode: Sort.Mode) {
|
||||
// TODO: Add names to sort.mode
|
||||
binding.sortRadio.text = mode.toString()
|
||||
}
|
||||
|
||||
fun setSelected(selected: Boolean) {
|
||||
binding.sortRadio.isChecked = selected
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun from(parent: View) =
|
||||
SortModeViewHolder(ItemSortModeBinding.inflate(parent.context.inflater))
|
||||
|
||||
val DIFF_CALLBACK =
|
||||
object : DiffUtil.ItemCallback<Sort.Mode>() {
|
||||
override fun areItemsTheSame(oldItem: Sort.Mode, newItem: Sort.Mode) =
|
||||
oldItem == newItem
|
||||
|
||||
override fun areContentsTheSame(oldItem: Sort.Mode, newItem: Sort.Mode) =
|
||||
oldItem == newItem
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* SortDialog.kt is part of Auxio.
|
||||
* MenuDialogFragment.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
|
||||
@@ -16,74 +16,126 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.list.sort
|
||||
package org.oxycblt.auxio.list.menu
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.core.view.updatePadding
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.core.view.children
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.DialogSortBinding
|
||||
import org.oxycblt.auxio.databinding.DialogMenuBinding
|
||||
import org.oxycblt.auxio.list.ClickableListListener
|
||||
import org.oxycblt.auxio.list.Sort
|
||||
import org.oxycblt.auxio.list.ListViewModel
|
||||
import org.oxycblt.auxio.list.Menu
|
||||
import org.oxycblt.auxio.list.adapter.UpdateInstructions
|
||||
import org.oxycblt.auxio.ui.ViewBindingBottomSheetDialogFragment
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.logD
|
||||
|
||||
abstract class SortDialog :
|
||||
ViewBindingBottomSheetDialogFragment<DialogSortBinding>(), ClickableListListener<Sort.Mode> {
|
||||
private val modeAdapter = SortModeAdapter(this)
|
||||
/**
|
||||
* A [ViewBindingBottomSheetDialogFragment] that displays basic music information and a series of
|
||||
* options.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*
|
||||
* TODO: Extend the amount of music info shown in the dialog
|
||||
*/
|
||||
abstract class MenuDialogFragment<M : Menu> :
|
||||
ViewBindingBottomSheetDialogFragment<DialogMenuBinding>(), ClickableListListener<MenuItem> {
|
||||
protected abstract val menuModel: MenuViewModel
|
||||
protected abstract val listModel: ListViewModel
|
||||
private val menuAdapter = MenuItemAdapter(@Suppress("LeakingThis") this)
|
||||
|
||||
abstract fun getInitialSort(): Sort
|
||||
abstract val parcel: Menu.Parcel
|
||||
|
||||
abstract fun applyChosenSort(sort: Sort)
|
||||
/**
|
||||
* Get the options to disable in the context of the currently shown [M].
|
||||
*
|
||||
* @param menu The currently-shown menu [M].
|
||||
*/
|
||||
abstract fun getDisabledItemIds(menu: M): Set<Int>
|
||||
|
||||
abstract fun getModeChoices(): List<Sort.Mode>
|
||||
/**
|
||||
* Update the displayed information about the currently shown [M].
|
||||
*
|
||||
* @param binding The [DialogMenuBinding] to bind information to.
|
||||
* @param menu The currently-shown menu [M].
|
||||
*/
|
||||
abstract fun updateMenu(binding: DialogMenuBinding, menu: M)
|
||||
|
||||
override fun onCreateBinding(inflater: LayoutInflater) = DialogSortBinding.inflate(inflater)
|
||||
/**
|
||||
* Forward the clicked [MenuItem] to it's corresponding handler in another module.
|
||||
*
|
||||
* @param item The [MenuItem] that was clicked.
|
||||
* @param menu The currently-shown menu [M].
|
||||
*/
|
||||
abstract fun onClick(item: MenuItem, menu: M)
|
||||
|
||||
override fun onBindingCreated(binding: DialogSortBinding, savedInstanceState: Bundle?) {
|
||||
override fun onCreateBinding(inflater: LayoutInflater) = DialogMenuBinding.inflate(inflater)
|
||||
|
||||
override fun onBindingCreated(binding: DialogMenuBinding, savedInstanceState: Bundle?) {
|
||||
super.onBindingCreated(binding, savedInstanceState)
|
||||
|
||||
// --- UI SETUP ---
|
||||
binding.root.setOnApplyWindowInsetsListener { v, insets ->
|
||||
v.updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
||||
insets
|
||||
binding.menuName.isSelected = true
|
||||
binding.menuInfo.isSelected = true
|
||||
binding.menuOptionRecycler.apply {
|
||||
adapter = menuAdapter
|
||||
itemAnimator = null
|
||||
}
|
||||
|
||||
binding.sortModeRecycler.adapter = modeAdapter
|
||||
// --- VIEWMODEL SETUP ---
|
||||
listModel.menu.consume()
|
||||
menuModel.setMenu(parcel)
|
||||
collectImmediately(menuModel.currentMenu, this::updateMenu)
|
||||
}
|
||||
|
||||
binding.sortCancel.setOnClickListener { dismiss() }
|
||||
override fun onDestroyBinding(binding: DialogMenuBinding) {
|
||||
super.onDestroyBinding(binding)
|
||||
binding.menuName.isSelected = false
|
||||
binding.menuInfo.isSelected = false
|
||||
binding.menuOptionRecycler.adapter = null
|
||||
}
|
||||
|
||||
binding.sortSave.setOnClickListener {
|
||||
val initial = getInitialSort()
|
||||
// FIXME: This won't work for the playlist sort dialog.
|
||||
val mode = modeAdapter.currentMode ?: initial.mode
|
||||
val direction =
|
||||
when (binding.sortDirectionGroup.checkedButtonId) {
|
||||
R.id.sort_direction_asc -> Sort.Direction.ASCENDING
|
||||
R.id.sort_direction_dsc -> Sort.Direction.DESCENDING
|
||||
else -> initial.direction
|
||||
}
|
||||
applyChosenSort(Sort(mode, direction))
|
||||
dismiss()
|
||||
private fun updateMenu(menu: Menu?) {
|
||||
if (menu == null) {
|
||||
logD("No menu to show, navigating away")
|
||||
findNavController().navigateUp()
|
||||
return
|
||||
}
|
||||
|
||||
// --- STATE SETUP ---
|
||||
val initial = getInitialSort()
|
||||
@Suppress("UNCHECKED_CAST") val casted = menu as? M
|
||||
check(casted != null) { "Unexpected menu instance ${menu::class.simpleName}" }
|
||||
|
||||
modeAdapter.update(getModeChoices(), UpdateInstructions.Diff)
|
||||
modeAdapter.setSelected(initial.mode)
|
||||
// We need to inflate the menu on every menu update since it might have changed
|
||||
// what options are available (ex. if an artist with no songs has had new songs added).
|
||||
// Since we don't have (and don't want) a dummy view to inflate this menu, just
|
||||
// depend on the AndroidX Toolbar internal API and hope for the best.
|
||||
@SuppressLint("RestrictedApi") val builder = MenuBuilder(requireContext())
|
||||
MenuInflater(requireContext()).inflate(casted.res, builder)
|
||||
|
||||
val directionId =
|
||||
when (initial.direction) {
|
||||
Sort.Direction.ASCENDING -> R.id.sort_direction_asc
|
||||
Sort.Direction.DESCENDING -> R.id.sort_direction_dsc
|
||||
// Disable any menu options as specified by the impl
|
||||
val disabledIds = getDisabledItemIds(casted)
|
||||
val visible =
|
||||
builder.children.mapTo(mutableListOf()) {
|
||||
it.isEnabled = !disabledIds.contains(it.itemId)
|
||||
it
|
||||
}
|
||||
binding.sortDirectionGroup.check(directionId)
|
||||
menuAdapter.update(visible, UpdateInstructions.Diff)
|
||||
|
||||
// Delegate to impl how to show music
|
||||
updateMenu(requireBinding(), casted)
|
||||
}
|
||||
|
||||
override fun onClick(item: Sort.Mode, viewHolder: RecyclerView.ViewHolder) {
|
||||
modeAdapter.setSelected(item)
|
||||
final override fun onClick(item: MenuItem, viewHolder: RecyclerView.ViewHolder) {
|
||||
// All option selections close the dialog currently.
|
||||
// TODO: This should change if the app is 100% migrated to menu dialogs
|
||||
findNavController().navigateUp()
|
||||
// Delegate to impl on how to handle items
|
||||
@Suppress("UNCHECKED_CAST") onClick(item, menuModel.currentMenu.value as M)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user