Merge pull request #3276 from Isira-Seneviratne/Improve_count_formatting

Improve count formatting.
This commit is contained in:
Bnyro 2023-03-10 17:11:40 +01:00 committed by GitHub
commit 95bd8b8baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 32 deletions

View File

@ -1,6 +1,5 @@
package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -24,7 +23,6 @@ import com.github.libretube.ui.sheets.ChannelOptionsBottomSheet
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SearchViewHolder
import com.github.libretube.util.TextUtils
class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder {
@ -104,22 +102,21 @@ class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback)
}
}
@SuppressLint("SetTextI18n")
private fun bindChannel(item: ContentItem, binding: ChannelRowBinding) {
binding.apply {
ImageHelper.loadImage(item.thumbnail, searchChannelImage)
searchChannelName.text = item.name
searchViews.text = listOfNotNull(
root.context.getString(
R.string.subscribers,
item.subscribers.formatShort()
).takeIf { item.subscribers >= 0 },
root.context.getString(
R.string.videoCount,
item.videos.toString()
).takeIf { item.videos >= 0 }
).joinToString(TextUtils.SEPARATOR)
val subscribers = item.subscribers.formatShort()
searchViews.text = if (item.subscribers >= 0 && item.videos >= 0) {
root.context.getString(R.string.subscriberAndVideoCounts, subscribers, item.videos)
} else if (item.subscribers >= 0) {
root.context.getString(R.string.subscribers, subscribers)
} else if (item.videos >= 0) {
root.context.getString(R.string.videoCount, item.videos)
} else {
""
}
root.setOnClickListener {
NavigationHelper.navigateChannel(root.context, item.url)

View File

@ -1,6 +1,5 @@
package com.github.libretube.ui.fragments
import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@ -16,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.Playlist
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentPlaylistBinding
@ -31,7 +31,6 @@ import com.github.libretube.ui.adapters.PlaylistAdapter
import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.util.PlayingQueue
import com.github.libretube.util.TextUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@ -100,7 +99,6 @@ class PlaylistFragment : Fragment() {
)
}
@SuppressLint("SetTextI18n")
private fun fetchPlaylist() {
binding.playlistScrollview.visibility = View.GONE
lifecycleScope.launchWhenCreated {
@ -126,9 +124,7 @@ class PlaylistFragment : Fragment() {
if (binding.playlistName.maxLines == 2) Int.MAX_VALUE else 2
}
binding.playlistInfo.text =
(if (response.uploader != null) response.uploader + TextUtils.SEPARATOR else "") +
getString(R.string.videoCount, response.videos.toString())
binding.playlistInfo.text = getChannelAndVideoString(response, response.videos)
// show playlist options
binding.optionsMenu.setOnClickListener {
@ -196,18 +192,8 @@ class PlaylistFragment : Fragment() {
)
}
val info = binding.playlistInfo.text.split(TextUtils.SEPARATOR)
binding.playlistInfo.text = (
if (info.size == 2) {
info[0] + TextUtils.SEPARATOR
} else {
""
}
) + getString(
R.string.videoCount,
playlistAdapter!!.itemCount.toString()
)
super.onItemRangeRemoved(positionStart, itemCount)
binding.playlistInfo.text =
getChannelAndVideoString(response, playlistFeed.size)
}
})
@ -269,6 +255,12 @@ class PlaylistFragment : Fragment() {
}
}
private fun getChannelAndVideoString(playlist: Playlist, count: Int): String {
return playlist.uploader?.let {
getString(R.string.uploaderAndVideoCount, it, count)
} ?: getString(R.string.videoCount, count)
}
private fun fetchNextPage() {
if (nextPage == null || isLoading) return
isLoading = true

View File

@ -68,7 +68,9 @@
<string name="instance">Instance</string>
<string name="customization">Adjustments</string>
<string name="website">Website</string>
<string name="videoCount">%1$s videos</string>
<string name="uploaderAndVideoCount">%1$s • %2$d videos</string>
<string name="subscriberAndVideoCounts">%1$s subscribers • %2$d videos</string>
<string name="videoCount">%1$d videos</string>
<string name="noInternet">Connect to the Internet first.</string>
<string name="retry">Retry</string>
<string name="comments">Comments</string>