mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Merge pull request #3276 from Isira-Seneviratne/Improve_count_formatting
Improve count formatting.
This commit is contained in:
commit
95bd8b8baf
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.ui.adapters
|
package com.github.libretube.ui.adapters
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
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.PlaylistOptionsBottomSheet
|
||||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
||||||
import com.github.libretube.ui.viewholders.SearchViewHolder
|
import com.github.libretube.ui.viewholders.SearchViewHolder
|
||||||
import com.github.libretube.util.TextUtils
|
|
||||||
|
|
||||||
class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback) {
|
class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback) {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder {
|
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) {
|
private fun bindChannel(item: ContentItem, binding: ChannelRowBinding) {
|
||||||
binding.apply {
|
binding.apply {
|
||||||
ImageHelper.loadImage(item.thumbnail, searchChannelImage)
|
ImageHelper.loadImage(item.thumbnail, searchChannelImage)
|
||||||
searchChannelName.text = item.name
|
searchChannelName.text = item.name
|
||||||
|
|
||||||
searchViews.text = listOfNotNull(
|
val subscribers = item.subscribers.formatShort()
|
||||||
root.context.getString(
|
searchViews.text = if (item.subscribers >= 0 && item.videos >= 0) {
|
||||||
R.string.subscribers,
|
root.context.getString(R.string.subscriberAndVideoCounts, subscribers, item.videos)
|
||||||
item.subscribers.formatShort()
|
} else if (item.subscribers >= 0) {
|
||||||
).takeIf { item.subscribers >= 0 },
|
root.context.getString(R.string.subscribers, subscribers)
|
||||||
root.context.getString(
|
} else if (item.videos >= 0) {
|
||||||
R.string.videoCount,
|
root.context.getString(R.string.videoCount, item.videos)
|
||||||
item.videos.toString()
|
} else {
|
||||||
).takeIf { item.videos >= 0 }
|
""
|
||||||
).joinToString(TextUtils.SEPARATOR)
|
}
|
||||||
|
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
NavigationHelper.navigateChannel(root.context, item.url)
|
NavigationHelper.navigateChannel(root.context, item.url)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.ui.fragments
|
package com.github.libretube.ui.fragments
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -16,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.PlaylistsHelper
|
import com.github.libretube.api.PlaylistsHelper
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
|
import com.github.libretube.api.obj.Playlist
|
||||||
import com.github.libretube.api.obj.StreamItem
|
import com.github.libretube.api.obj.StreamItem
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
import com.github.libretube.databinding.FragmentPlaylistBinding
|
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.models.PlayerViewModel
|
||||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
||||||
import com.github.libretube.util.PlayingQueue
|
import com.github.libretube.util.PlayingQueue
|
||||||
import com.github.libretube.util.TextUtils
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
@ -100,7 +99,6 @@ class PlaylistFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
private fun fetchPlaylist() {
|
private fun fetchPlaylist() {
|
||||||
binding.playlistScrollview.visibility = View.GONE
|
binding.playlistScrollview.visibility = View.GONE
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
@ -126,9 +124,7 @@ class PlaylistFragment : Fragment() {
|
|||||||
if (binding.playlistName.maxLines == 2) Int.MAX_VALUE else 2
|
if (binding.playlistName.maxLines == 2) Int.MAX_VALUE else 2
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.playlistInfo.text =
|
binding.playlistInfo.text = getChannelAndVideoString(response, response.videos)
|
||||||
(if (response.uploader != null) response.uploader + TextUtils.SEPARATOR else "") +
|
|
||||||
getString(R.string.videoCount, response.videos.toString())
|
|
||||||
|
|
||||||
// show playlist options
|
// show playlist options
|
||||||
binding.optionsMenu.setOnClickListener {
|
binding.optionsMenu.setOnClickListener {
|
||||||
@ -196,18 +192,8 @@ class PlaylistFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val info = binding.playlistInfo.text.split(TextUtils.SEPARATOR)
|
binding.playlistInfo.text =
|
||||||
binding.playlistInfo.text = (
|
getChannelAndVideoString(response, playlistFeed.size)
|
||||||
if (info.size == 2) {
|
|
||||||
info[0] + TextUtils.SEPARATOR
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
) + getString(
|
|
||||||
R.string.videoCount,
|
|
||||||
playlistAdapter!!.itemCount.toString()
|
|
||||||
)
|
|
||||||
super.onItemRangeRemoved(positionStart, itemCount)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -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() {
|
private fun fetchNextPage() {
|
||||||
if (nextPage == null || isLoading) return
|
if (nextPage == null || isLoading) return
|
||||||
isLoading = true
|
isLoading = true
|
||||||
|
@ -68,7 +68,9 @@
|
|||||||
<string name="instance">Instance</string>
|
<string name="instance">Instance</string>
|
||||||
<string name="customization">Adjustments</string>
|
<string name="customization">Adjustments</string>
|
||||||
<string name="website">Website</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="noInternet">Connect to the Internet first.</string>
|
||||||
<string name="retry">Retry</string>
|
<string name="retry">Retry</string>
|
||||||
<string name="comments">Comments</string>
|
<string name="comments">Comments</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user