From 44a70cdc0b4e8ef85fa788d1dc063fd5a7b7c136 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 9 Mar 2023 08:54:27 +0530 Subject: [PATCH 1/2] Improve subscriber, playlist uploader and video count formatting. --- .../libretube/ui/adapters/SearchAdapter.kt | 23 +++++++--------- .../ui/fragments/PlaylistFragment.kt | 27 +++++++------------ app/src/main/res/values/strings.xml | 4 ++- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt index 4de28b49bc..b97b4f9358 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt @@ -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(SearchCallback) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder { @@ -104,22 +102,21 @@ class SearchAdapter : ListAdapter(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) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index ff27398ba6..19c018be8a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -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 { @@ -195,17 +191,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() - ) + binding.playlistInfo.text = + getChannelAndVideoString(response, playlistAdapter!!.itemCount) super.onItemRangeRemoved(positionStart, itemCount) } }) @@ -268,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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 04f9768a0d..df0ee17e72 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -68,7 +68,9 @@ Instance Adjustments Website - %1$s videos + %1$s • %2$d videos + %1$s subscribers • %2$d videos + %1$d videos Connect to the Internet first. Retry Comments From d81661202214ecfeb39c5cf8cbebc3efee9db70d Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 10 Mar 2023 07:25:13 +0530 Subject: [PATCH 2/2] Fix item count for private playlists. --- .../java/com/github/libretube/ui/fragments/PlaylistFragment.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 19c018be8a..1e699eb922 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -192,8 +192,7 @@ class PlaylistFragment : Fragment() { } binding.playlistInfo.text = - getChannelAndVideoString(response, playlistAdapter!!.itemCount) - super.onItemRangeRemoved(positionStart, itemCount) + getChannelAndVideoString(response, playlistFeed.size) } })