From c619056b67fa5e682673eda5608a2c0dca40b1ff Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 10:08:47 +0200 Subject: [PATCH 01/17] Codebase built --- .../com/github/libretube/SearchFragment.kt | 18 ++++++ .../libretube/adapters/SearchAdapter.kt | 29 +++++---- app/src/main/res/drawable/ic_filter.xml | 10 +++ app/src/main/res/layout/fragment_search.xml | 64 ++++++++++++------- app/src/main/res/layout/layout_empty.xml | 6 ++ app/src/main/res/menu/filter_menu.xml | 26 ++++++++ 6 files changed, 117 insertions(+), 36 deletions(-) create mode 100644 app/src/main/res/drawable/ic_filter.xml create mode 100644 app/src/main/res/layout/layout_empty.xml create mode 100644 app/src/main/res/menu/filter_menu.xml diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 6d1865770..f44a7274b 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -1,6 +1,7 @@ package com.github.libretube import android.content.Context +import android.content.DialogInterface import android.os.Bundle import android.text.Editable import android.text.TextWatcher @@ -13,7 +14,10 @@ import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.widget.ArrayAdapter import android.widget.AutoCompleteTextView +import android.widget.ImageView import android.widget.TextView.* +import android.widget.Toast +import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager @@ -25,6 +29,7 @@ import com.github.libretube.adapters.SearchHistoryAdapter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import org.chromium.base.ThreadUtils.runOnUiThread import retrofit2.HttpException import java.io.IOException @@ -55,6 +60,19 @@ class SearchFragment : Fragment() { val historyRecycler = view.findViewById(R.id.history_recycler) + val filterImageView = view.findViewById(R.id.filterMenu_imageView) + filterImageView.setOnClickListener { + val options = arrayOf("Alle", "Videos") + var checkItem = 1 + AlertDialog.Builder(view.context) + .setTitle("Choose an Option") + .setSingleChoiceItems(options, checkItem, DialogInterface.OnClickListener { + dialog, id -> Toast.makeText(view.context,id.toString(),Toast.LENGTH_LONG).show() + }) + + .create() + .show() + } //show search history diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index 9f93cecd4..2f334293e 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -16,19 +16,27 @@ import com.github.libretube.R import com.github.libretube.formatShort import com.github.libretube.obj.SearchItem import com.squareup.picasso.Picasso +import kotlinx.coroutines.NonDisposableHandle.parent +private val showVideos = true +private val showChannels = true +private val showPlaylists = true class SearchAdapter(private val searchItems: List): RecyclerView.Adapter() { + override fun getItemCount(): Int { return searchItems.size } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder1 { - val layout = when (viewType) { - 0 -> R.layout.video_search_row - 1 -> R.layout.channel_search_row - 2 -> R.layout.playlist_search_row - else -> throw IllegalArgumentException("Invalid type") + val layout = if (viewType == 0 && showVideos) { + R.layout.video_search_row + } else if (viewType == 1 && showChannels){ + R.layout.channel_search_row + } else if (viewType == 2 && showPlaylists) { + R.layout.playlist_search_row + } else { + R.layout.layout_empty } val layoutInflater = LayoutInflater.from(parent.context) val cell = layoutInflater.inflate(layout,parent,false) @@ -120,12 +128,9 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ } fun bind(searchItem: SearchItem) { - when { - searchItem.url!!.startsWith("/watch",false) -> bindWatch(searchItem) - searchItem.url!!.startsWith("/channel",false) -> bindChannel(searchItem) - searchItem.url!!.startsWith("/playlist",false) -> bindPlaylist(searchItem) - else -> { - } - } + if (searchItem.url!!.startsWith("/watch",false) && showVideos) bindWatch(searchItem) + else if (searchItem.url!!.startsWith("/channel",false) && showChannels) bindChannel(searchItem) + else if (searchItem.url!!.startsWith("/playlist",false) && showPlaylists) bindPlaylist(searchItem) + else {} } } diff --git a/app/src/main/res/drawable/ic_filter.xml b/app/src/main/res/drawable/ic_filter.xml new file mode 100644 index 000000000..e0b21ad93 --- /dev/null +++ b/app/src/main/res/drawable/ic_filter.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 9a2b0e083..047c4fd16 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -6,41 +6,57 @@ android:layout_height="match_parent" tools:context=".SearchFragment"> - - + android:layout_margin="16dp" + app:cardCornerRadius="27dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - + app:hintEnabled="false"> - + - + + + + + @@ -297,7 +313,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/outlinedTextField" + app:layout_constraintTop_toBottomOf="@+id/searchbar_holder" android:visibility="gone"/> \ No newline at end of file diff --git a/app/src/main/res/layout/layout_empty.xml b/app/src/main/res/layout/layout_empty.xml new file mode 100644 index 000000000..006fd4963 --- /dev/null +++ b/app/src/main/res/layout/layout_empty.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/filter_menu.xml b/app/src/main/res/menu/filter_menu.xml new file mode 100644 index 000000000..7ce177e1c --- /dev/null +++ b/app/src/main/res/menu/filter_menu.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file From 0665ecb6222c13095db5f4a26559a901b7fc6bf1 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 10:24:19 +0200 Subject: [PATCH 02/17] Finished dialog and fixed hard coded strings --- .../com/github/libretube/SearchFragment.kt | 18 ++++++++++++------ app/src/main/res/values/strings.xml | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index f44a7274b..37fff32db 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -61,15 +61,21 @@ class SearchFragment : Fragment() { val historyRecycler = view.findViewById(R.id.history_recycler) val filterImageView = view.findViewById(R.id.filterMenu_imageView) + + var checkedItem = 0 + var tempSelectedItem = 0 + filterImageView.setOnClickListener { - val options = arrayOf("Alle", "Videos") - var checkItem = 1 + val options = arrayOf(getString(R.string.all), getString(R.string.videos), getString(R.string.channels), getString(R.string.playlists)) AlertDialog.Builder(view.context) - .setTitle("Choose an Option") - .setSingleChoiceItems(options, checkItem, DialogInterface.OnClickListener { - dialog, id -> Toast.makeText(view.context,id.toString(),Toast.LENGTH_LONG).show() + .setTitle(getString(R.string.choose_filter)) + .setSingleChoiceItems(options, checkedItem, DialogInterface.OnClickListener { + dialog, id -> tempSelectedItem = id }) - + .setPositiveButton("Ok", DialogInterface.OnClickListener { + dialog, id -> checkedItem = tempSelectedItem + }) + .setNegativeButton("Cancel", null) .create() .show() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 51d9d8b8e..ec811d248 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,4 +72,8 @@ No Internet Connection Retry Comments + Choose search filter + Channels + All + Playlists From 671b59664bb8142ed8b003d4889b69cca7ffc008 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 10:30:07 +0200 Subject: [PATCH 03/17] Fixed hardcoded strings --- app/src/main/java/com/github/libretube/SearchFragment.kt | 8 ++++---- app/src/main/res/values/strings.xml | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 37fff32db..7652da99a 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -70,12 +70,12 @@ class SearchFragment : Fragment() { AlertDialog.Builder(view.context) .setTitle(getString(R.string.choose_filter)) .setSingleChoiceItems(options, checkedItem, DialogInterface.OnClickListener { - dialog, id -> tempSelectedItem = id + dialog, id -> tempSelectedItem = id }) - .setPositiveButton("Ok", DialogInterface.OnClickListener { - dialog, id -> checkedItem = tempSelectedItem + .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { + dialog, id -> checkedItem = tempSelectedItem }) - .setNegativeButton("Cancel", null) + .setNegativeButton(getString(R.string.cancel), null) .create() .show() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ec811d248..662bdfa3c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,4 +76,5 @@ Channels All Playlists + Ok From 71f5becc0885355868407aa5830e5d74a2353ef7 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 10:41:04 +0200 Subject: [PATCH 04/17] Added functionality --- .../java/com/github/libretube/SearchFragment.kt | 9 +++++---- .../com/github/libretube/adapters/SearchAdapter.kt | 14 ++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 7652da99a..eb788de6b 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -34,6 +34,8 @@ import retrofit2.HttpException import java.io.IOException +private var selectedFilter = 0 + class SearchFragment : Fragment() { private val TAG = "SearchFragment" override fun onCreate(savedInstanceState: Bundle?) { @@ -62,18 +64,17 @@ class SearchFragment : Fragment() { val filterImageView = view.findViewById(R.id.filterMenu_imageView) - var checkedItem = 0 var tempSelectedItem = 0 filterImageView.setOnClickListener { val options = arrayOf(getString(R.string.all), getString(R.string.videos), getString(R.string.channels), getString(R.string.playlists)) AlertDialog.Builder(view.context) .setTitle(getString(R.string.choose_filter)) - .setSingleChoiceItems(options, checkedItem, DialogInterface.OnClickListener { + .setSingleChoiceItems(options, selectedFilter, DialogInterface.OnClickListener { dialog, id -> tempSelectedItem = id }) .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { - dialog, id -> checkedItem = tempSelectedItem + dialog, id -> selectedFilter = tempSelectedItem }) .setNegativeButton(getString(R.string.cancel), null) .create() @@ -181,7 +182,7 @@ class SearchFragment : Fragment() { } if(response.items!!.isNotEmpty()){ runOnUiThread { - recyclerView.adapter = SearchAdapter(response.items) + recyclerView.adapter = SearchAdapter(response.items, selectedFilter) } } diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index 2f334293e..f49ce4931 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -18,17 +18,23 @@ import com.github.libretube.obj.SearchItem import com.squareup.picasso.Picasso import kotlinx.coroutines.NonDisposableHandle.parent -private val showVideos = true -private val showChannels = true -private val showPlaylists = true +private var showVideos = true +private var showChannels = true +private var showPlaylists = true -class SearchAdapter(private val searchItems: List): RecyclerView.Adapter() { +class SearchAdapter(private val searchItems: List, private val selectedFilter : Int): RecyclerView.Adapter() { override fun getItemCount(): Int { return searchItems.size } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder1 { + when (selectedFilter) { + 0 -> { showChannels = true; showVideos = true; showPlaylists = true } + 1 -> { showChannels = false; showVideos = true; showPlaylists = false } + 2 -> { showChannels = true; showVideos = false; showPlaylists = false } + 3 -> { showChannels = false; showVideos = false; showPlaylists = true } + } val layout = if (viewType == 0 && showVideos) { R.layout.video_search_row } else if (viewType == 1 && showChannels){ From d04b1bb08555a37fadd5ff4e00d36d00a230e106 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 11:07:56 +0200 Subject: [PATCH 05/17] Refresh on Filter Changed --- app/src/main/java/com/github/libretube/SearchFragment.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index eb788de6b..19f96ee23 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -16,7 +16,6 @@ import android.widget.ArrayAdapter import android.widget.AutoCompleteTextView import android.widget.ImageView import android.widget.TextView.* -import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope @@ -29,7 +28,6 @@ import com.github.libretube.adapters.SearchHistoryAdapter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import org.chromium.base.ThreadUtils.runOnUiThread import retrofit2.HttpException import java.io.IOException @@ -71,10 +69,11 @@ class SearchFragment : Fragment() { AlertDialog.Builder(view.context) .setTitle(getString(R.string.choose_filter)) .setSingleChoiceItems(options, selectedFilter, DialogInterface.OnClickListener { - dialog, id -> tempSelectedItem = id + _, id -> tempSelectedItem = id }) .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { - dialog, id -> selectedFilter = tempSelectedItem + _, _ -> selectedFilter = tempSelectedItem + fetchSearch(autoTextView.text.toString(), recyclerView) }) .setNegativeButton(getString(R.string.cancel), null) .create() @@ -117,7 +116,7 @@ class SearchFragment : Fragment() { GlobalScope.launch { fetchSuggestions(s.toString(), autoTextView) - delay(3000) + delay(1000) addtohistory(s.toString()) fetchSearch(s.toString(), recyclerView) } From 71613937316a151997f707c37cb272f389df4dcb Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 11:09:53 +0200 Subject: [PATCH 06/17] Readme Changed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52f485620..29f4320dd 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ WARNING: THIS IS A BETA VERSION, THEREFORE YOU MAY ENCOUNTER BUGS. IF YOU DO, OP | Search Suggestions | ✅ | | Subtitles | ✅ | | Comments | ✅ | -| Search Filters | 🔴 | +| Search Filters | ✅ | ## Contributing From 9b170c8be2bc991482bca84b81aea2ee71acf5c3 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 12:19:04 +0200 Subject: [PATCH 07/17] Removed unneeded file --- app/src/main/res/menu/filter_menu.xml | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 app/src/main/res/menu/filter_menu.xml diff --git a/app/src/main/res/menu/filter_menu.xml b/app/src/main/res/menu/filter_menu.xml deleted file mode 100644 index 7ce177e1c..000000000 --- a/app/src/main/res/menu/filter_menu.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From 4ed137c174137a0dce317272d23ca296934dd734 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 13:12:46 +0200 Subject: [PATCH 08/17] NextPage for Search --- .../java/com/github/libretube/PipedApi.kt | 7 ++ .../com/github/libretube/SearchFragment.kt | 64 +++++++++++++------ .../libretube/adapters/SearchAdapter.kt | 9 ++- .../com/github/libretube/obj/SearchResult.kt | 2 +- 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/github/libretube/PipedApi.kt b/app/src/main/java/com/github/libretube/PipedApi.kt index 94c2a65b5..3442f1d32 100644 --- a/app/src/main/java/com/github/libretube/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/PipedApi.kt @@ -22,6 +22,13 @@ interface PipedApi { @Query("filter") filter: String ): SearchResult + @GET("nextpage/search") + suspend fun getSearchResultsNextPage( + @Query("q") searchQuery: String, + @Query("filter") filter: String, + @Query("nextpage") nextPage: String + ): SearchResult + @GET("suggestions") suspend fun getSuggestions(@Query("query") query: String): List diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 19f96ee23..fc5279753 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -12,11 +12,10 @@ import android.view.ViewGroup import android.view.WindowManager import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager -import android.widget.ArrayAdapter -import android.widget.AutoCompleteTextView -import android.widget.ImageView +import android.widget.* import android.widget.TextView.* import androidx.appcompat.app.AlertDialog +import androidx.core.content.ContentProviderCompat.requireContext import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager @@ -31,11 +30,13 @@ import kotlinx.coroutines.launch import retrofit2.HttpException import java.io.IOException - -private var selectedFilter = 0 - class SearchFragment : Fragment() { private val TAG = "SearchFragment" + private var selectedFilter = 0 + private var nextPage : String? = null + private lateinit var searchRecView : RecyclerView + private var searchAdapter : SearchAdapter? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { @@ -54,7 +55,7 @@ class SearchFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val recyclerView = view.findViewById(R.id.search_recycler) + searchRecView = view.findViewById(R.id.search_recycler) val autoTextView = view.findViewById(R.id.autoCompleteTextView) @@ -73,7 +74,7 @@ class SearchFragment : Fragment() { }) .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { _, _ -> selectedFilter = tempSelectedItem - fetchSearch(autoTextView.text.toString(), recyclerView) + fetchSearch(autoTextView.text.toString()) }) .setNegativeButton(getString(R.string.cancel), null) .create() @@ -82,7 +83,7 @@ class SearchFragment : Fragment() { //show search history - recyclerView.visibility = GONE + searchRecView.visibility = GONE historyRecycler.visibility = VISIBLE historyRecycler.layoutManager = LinearLayoutManager(view.context) @@ -93,7 +94,7 @@ class SearchFragment : Fragment() { SearchHistoryAdapter(requireContext(), historylist, autoTextView) } - recyclerView.layoutManager = GridLayoutManager(view.context, 1) + searchRecView.layoutManager = GridLayoutManager(view.context, 1) autoTextView.requestFocus() val imm = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager @@ -110,24 +111,30 @@ class SearchFragment : Fragment() { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { if (s!! != "") { - recyclerView.visibility = VISIBLE + searchRecView.visibility = VISIBLE historyRecycler.visibility = GONE - recyclerView.adapter = null + searchRecView.adapter = null + + searchRecView.viewTreeObserver + .addOnScrollChangedListener { + if (!searchRecView.canScrollVertically(1)) { + fetchNextSearchItems(autoTextView.text.toString()) + } + + } GlobalScope.launch { fetchSuggestions(s.toString(), autoTextView) delay(1000) addtohistory(s.toString()) - fetchSearch(s.toString(), recyclerView) + fetchSearch(s.toString()) } - - } } override fun afterTextChanged(s: Editable?) { if (s!!.isEmpty()) { - recyclerView.visibility = GONE + searchRecView.visibility = GONE historyRecycler.visibility = VISIBLE var historylist = getHistory() if (historylist.size != 0) { @@ -167,10 +174,10 @@ class SearchFragment : Fragment() { autoTextView.setAdapter(adapter) } } - private fun fetchSearch(query: String, recyclerView: RecyclerView){ + private fun fetchSearch(query: String){ lifecycleScope.launchWhenCreated { val response = try { - RetrofitInstance.api.getSearchResults(query, "all") + RetrofitInstance.api.getSearchResults(query, "videos") } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection $e") @@ -179,15 +186,34 @@ class SearchFragment : Fragment() { Log.e(TAG, "HttpException, unexpected response") return@launchWhenCreated } + nextPage = response.nextpage if(response.items!!.isNotEmpty()){ runOnUiThread { - recyclerView.adapter = SearchAdapter(response.items, selectedFilter) + searchAdapter = SearchAdapter(response.items, selectedFilter) + searchRecView.adapter = searchAdapter } } } } + private fun fetchNextSearchItems(query: String){ + lifecycleScope.launchWhenCreated { + val response = try { + RetrofitInstance.api.getSearchResultsNextPage(query!!, "videos", nextPage!!) + } catch (e: IOException) { + println(e) + Log.e(TAG, "IOException, you might not have internet connection") + return@launchWhenCreated + } catch (e: HttpException) { + Log.e(TAG, "HttpException, unexpected response," + e.response()) + return@launchWhenCreated + } + nextPage = response.nextpage + searchAdapter?.updateItems(response.items!!) + } + } + private fun Fragment?.runOnUiThread(action: () -> Unit) { this ?: return if (!isAdded) return // Fragment not attached to an Activity diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index f49ce4931..bf99aecf9 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -14,6 +14,7 @@ import com.github.libretube.MainActivity import com.github.libretube.PlayerFragment import com.github.libretube.R import com.github.libretube.formatShort +import com.github.libretube.obj.Comment import com.github.libretube.obj.SearchItem import com.squareup.picasso.Picasso import kotlinx.coroutines.NonDisposableHandle.parent @@ -22,7 +23,13 @@ private var showVideos = true private var showChannels = true private var showPlaylists = true -class SearchAdapter(private val searchItems: List, private val selectedFilter : Int): RecyclerView.Adapter() { +class SearchAdapter(private val searchItems: MutableList, private val selectedFilter : Int): RecyclerView.Adapter() { + + fun updateItems(newItems: List){ + var searchItemsSize = searchItems.size + searchItems.addAll(newItems) + notifyItemRangeInserted(searchItemsSize, newItems.size) + } override fun getItemCount(): Int { return searchItems.size diff --git a/app/src/main/java/com/github/libretube/obj/SearchResult.kt b/app/src/main/java/com/github/libretube/obj/SearchResult.kt index 297619799..13172c9a9 100644 --- a/app/src/main/java/com/github/libretube/obj/SearchResult.kt +++ b/app/src/main/java/com/github/libretube/obj/SearchResult.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties @JsonIgnoreProperties(ignoreUnknown = true) data class SearchResult( - val items: List? = listOf(), + val items: MutableList? = arrayListOf(), val nextpage: String? ="", val suggestion: String?="", val corrected: Boolean? = null From 5207486c3619f669cd49eca1e5e2f675606cc2ff Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 13:26:51 +0200 Subject: [PATCH 09/17] Use API Search Filter --- .../com/github/libretube/SearchFragment.kt | 18 ++++++--- .../libretube/adapters/SearchAdapter.kt | 39 +++++++------------ 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index fc5279753..ff35ce9cb 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -33,6 +33,7 @@ import java.io.IOException class SearchFragment : Fragment() { private val TAG = "SearchFragment" private var selectedFilter = 0 + private var apiSearchFilter = "all" private var nextPage : String? = null private lateinit var searchRecView : RecyclerView private var searchAdapter : SearchAdapter? = null @@ -72,8 +73,15 @@ class SearchFragment : Fragment() { .setSingleChoiceItems(options, selectedFilter, DialogInterface.OnClickListener { _, id -> tempSelectedItem = id }) - .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { - _, _ -> selectedFilter = tempSelectedItem + .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { _, _ -> + selectedFilter = tempSelectedItem + apiSearchFilter = when (selectedFilter) { + 0 -> "all" + 1 -> "videos" + 2 -> "channels" + 3 -> "playlists" + else -> "all" + } fetchSearch(autoTextView.text.toString()) }) .setNegativeButton(getString(R.string.cancel), null) @@ -177,7 +185,7 @@ class SearchFragment : Fragment() { private fun fetchSearch(query: String){ lifecycleScope.launchWhenCreated { val response = try { - RetrofitInstance.api.getSearchResults(query, "videos") + RetrofitInstance.api.getSearchResults(query, apiSearchFilter) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection $e") @@ -189,7 +197,7 @@ class SearchFragment : Fragment() { nextPage = response.nextpage if(response.items!!.isNotEmpty()){ runOnUiThread { - searchAdapter = SearchAdapter(response.items, selectedFilter) + searchAdapter = SearchAdapter(response.items) searchRecView.adapter = searchAdapter } } @@ -200,7 +208,7 @@ class SearchFragment : Fragment() { private fun fetchNextSearchItems(query: String){ lifecycleScope.launchWhenCreated { val response = try { - RetrofitInstance.api.getSearchResultsNextPage(query!!, "videos", nextPage!!) + RetrofitInstance.api.getSearchResultsNextPage(query!!, apiSearchFilter, nextPage!!) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index bf99aecf9..077fac1ad 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -14,16 +14,11 @@ import com.github.libretube.MainActivity import com.github.libretube.PlayerFragment import com.github.libretube.R import com.github.libretube.formatShort -import com.github.libretube.obj.Comment import com.github.libretube.obj.SearchItem import com.squareup.picasso.Picasso -import kotlinx.coroutines.NonDisposableHandle.parent -private var showVideos = true -private var showChannels = true -private var showPlaylists = true -class SearchAdapter(private val searchItems: MutableList, private val selectedFilter : Int): RecyclerView.Adapter() { +class SearchAdapter(private val searchItems: MutableList): RecyclerView.Adapter() { fun updateItems(newItems: List){ var searchItemsSize = searchItems.size @@ -36,20 +31,11 @@ class SearchAdapter(private val searchItems: MutableList, private va } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder1 { - when (selectedFilter) { - 0 -> { showChannels = true; showVideos = true; showPlaylists = true } - 1 -> { showChannels = false; showVideos = true; showPlaylists = false } - 2 -> { showChannels = true; showVideos = false; showPlaylists = false } - 3 -> { showChannels = false; showVideos = false; showPlaylists = true } - } - val layout = if (viewType == 0 && showVideos) { - R.layout.video_search_row - } else if (viewType == 1 && showChannels){ - R.layout.channel_search_row - } else if (viewType == 2 && showPlaylists) { - R.layout.playlist_search_row - } else { - R.layout.layout_empty + val layout = when (viewType) { + 0 -> R.layout.video_search_row + 1 -> R.layout.channel_search_row + 2 -> R.layout.playlist_search_row + else -> throw IllegalArgumentException("Invalid type") } val layoutInflater = LayoutInflater.from(parent.context) val cell = layoutInflater.inflate(layout,parent,false) @@ -141,9 +127,12 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ } fun bind(searchItem: SearchItem) { - if (searchItem.url!!.startsWith("/watch",false) && showVideos) bindWatch(searchItem) - else if (searchItem.url!!.startsWith("/channel",false) && showChannels) bindChannel(searchItem) - else if (searchItem.url!!.startsWith("/playlist",false) && showPlaylists) bindPlaylist(searchItem) - else {} + when { + searchItem.url!!.startsWith("/watch",false) -> bindWatch(searchItem) + searchItem.url!!.startsWith("/channel",false) -> bindChannel(searchItem) + searchItem.url!!.startsWith("/playlist",false) -> bindPlaylist(searchItem) + else -> { + } + } } -} +} \ No newline at end of file From ead1999b99250c5115f00b83d7b5de0b6df65937 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 13:47:24 +0200 Subject: [PATCH 10/17] Fixed Search Items repeating lol --- .../main/java/com/github/libretube/SearchFragment.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index ff35ce9cb..2bf76c3ed 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -27,6 +27,7 @@ import com.github.libretube.adapters.SearchHistoryAdapter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import org.chromium.base.ThreadUtils.runOnUiThread import retrofit2.HttpException import java.io.IOException @@ -37,6 +38,7 @@ class SearchFragment : Fragment() { private var nextPage : String? = null private lateinit var searchRecView : RecyclerView private var searchAdapter : SearchAdapter? = null + private var isLoading : Boolean = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -207,8 +209,14 @@ class SearchFragment : Fragment() { private fun fetchNextSearchItems(query: String){ lifecycleScope.launchWhenCreated { + if (!isLoading) { + isLoading = true val response = try { - RetrofitInstance.api.getSearchResultsNextPage(query!!, apiSearchFilter, nextPage!!) + RetrofitInstance.api.getSearchResultsNextPage( + query!!, + apiSearchFilter, + nextPage!! + ) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") @@ -219,8 +227,10 @@ class SearchFragment : Fragment() { } nextPage = response.nextpage searchAdapter?.updateItems(response.items!!) + isLoading = false } } + } private fun Fragment?.runOnUiThread(action: () -> Unit) { this ?: return From 3d8166142d83517065927e050e17808caeec89cf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 13:54:13 +0200 Subject: [PATCH 11/17] Searchbar UI improvements --- app/src/main/res/layout/fragment_search.xml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 047c4fd16..1bb51023f 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" tools:context=".SearchFragment"> - - + @@ -320,10 +325,7 @@ android:id="@+id/search_recycler" android:layout_width="0dp" android:layout_height="0dp" - android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" - android:layout_marginBottom="10dp" - android:layout_marginTop="20dp" + android:layout_margin="10dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" From 41d644f6d4e01eeb25c41137034b3075cf9bfc4c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 14:02:48 +0200 Subject: [PATCH 12/17] Suggestions Size --- app/src/main/res/layout/fragment_search.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 1bb51023f..24d8b703c 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -46,7 +46,8 @@ android:imeOptions="actionSearch" android:inputType="text" android:maxLines="1" - android:padding="12dp" /> + android:padding="12dp" + android:dropDownWidth="match_parent" /> From ab97ccee85641cdcfb74926319b7e34c7da629e5 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 15:56:24 +0200 Subject: [PATCH 13/17] Added Search History Toggle and Clear in Settings --- .../java/com/github/libretube/SearchFragment.kt | 3 ++- .../java/com/github/libretube/SettingsActivity.kt | 8 ++++++++ app/src/main/res/drawable/ic_trash.xml | 10 ++++++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/settings.xml | 15 +++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_trash.xml diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 2bf76c3ed..bc553a4d8 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -136,7 +136,8 @@ class SearchFragment : Fragment() { GlobalScope.launch { fetchSuggestions(s.toString(), autoTextView) delay(1000) - addtohistory(s.toString()) + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + if (sharedPreferences.getBoolean("search_history_toggle", true)) addtohistory(s.toString()) fetchSearch(s.toString()) } } diff --git a/app/src/main/java/com/github/libretube/SettingsActivity.kt b/app/src/main/java/com/github/libretube/SettingsActivity.kt index 0fb13644e..7e1347b6f 100644 --- a/app/src/main/java/com/github/libretube/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/SettingsActivity.kt @@ -9,6 +9,7 @@ import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.os.Bundle +import android.system.Os.remove import android.text.TextUtils import android.util.Log import android.view.View @@ -224,6 +225,13 @@ class SettingsActivity : AppCompatActivity(), true } + val clearHistory = findPreference("clear_history") + clearHistory?.setOnPreferenceClickListener { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) + sharedPreferences.edit().remove("search_history").commit() + true + } + val about = findPreference("about") about?.setOnPreferenceClickListener { val uri = Uri.parse("https://libre-tube.github.io/") diff --git a/app/src/main/res/drawable/ic_trash.xml b/app/src/main/res/drawable/ic_trash.xml new file mode 100644 index 000000000..d52cfe83e --- /dev/null +++ b/app/src/main/res/drawable/ic_trash.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 662bdfa3c..6e7281ea0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,4 +77,7 @@ All Playlists Ok + History + Search History + Clear History diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 56ae14456..6a2755c1c 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -93,6 +93,21 @@ + + + + + + + + Date: Sun, 15 May 2022 16:03:38 +0200 Subject: [PATCH 14/17] Fixed slow Picasso Image Loading --- .../java/com/github/libretube/adapters/SearchAdapter.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index 077fac1ad..be951287d 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -59,11 +59,11 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ private fun bindWatch(item: SearchItem) { val thumbnailImage = v.findViewById(R.id.search_thumbnail) - Picasso.get().load(item.thumbnail).into(thumbnailImage) + Picasso.get().load(item.thumbnail).fit().centerCrop().into(thumbnailImage) val thumbnailDuration = v.findViewById(R.id.search_thumbnail_duration) thumbnailDuration.text = DateUtils.formatElapsedTime(item.duration!!) val channelImage = v.findViewById(R.id.search_channel_image) - Picasso.get().load(item.uploaderAvatar).into(channelImage) + Picasso.get().load(item.uploaderAvatar).fit().centerCrop().into(channelImage) val title = v.findViewById(R.id.search_description) if (item.title!!.length > 60) { title.text = item.title?.substring(0, 60) + "..." @@ -95,7 +95,7 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ } private fun bindChannel(item: SearchItem) { val channelImage = v.findViewById(R.id.search_channel_image) - Picasso.get().load(item.thumbnail).into(channelImage) + Picasso.get().load(item.thumbnail).fit().centerCrop().into(channelImage) val channelName = v.findViewById(R.id.search_channel_name) channelName.text = item.name val channelViews = v.findViewById(R.id.search_views) @@ -109,7 +109,7 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ } private fun bindPlaylist(item: SearchItem) { val playlistImage = v.findViewById(R.id.search_thumbnail) - Picasso.get().load(item.thumbnail).into(playlistImage) + Picasso.get().load(item.thumbnail).fit().centerCrop().into(playlistImage) val playlistNumber = v.findViewById(R.id.search_playlist_number) playlistNumber.text = item.videos.toString() val playlistName = v.findViewById(R.id.search_description) From f21f8dd1336769258b1f41e3f854fb02c3763e7e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 20:43:29 +0200 Subject: [PATCH 15/17] Fixed a small bug --- app/src/main/java/com/github/libretube/SearchFragment.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index bc553a4d8..6163d9faf 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -27,7 +27,6 @@ import com.github.libretube.adapters.SearchHistoryAdapter import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import org.chromium.base.ThreadUtils.runOnUiThread import retrofit2.HttpException import java.io.IOException @@ -38,7 +37,7 @@ class SearchFragment : Fragment() { private var nextPage : String? = null private lateinit var searchRecView : RecyclerView private var searchAdapter : SearchAdapter? = null - private var isLoading : Boolean = false + private var isLoading : Boolean = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -204,7 +203,7 @@ class SearchFragment : Fragment() { searchRecView.adapter = searchAdapter } } - + isLoading = false } } @@ -215,7 +214,7 @@ class SearchFragment : Fragment() { val response = try { RetrofitInstance.api.getSearchResultsNextPage( query!!, - apiSearchFilter, + apiSearchFilter!!, nextPage!! ) } catch (e: IOException) { From af62aa7df2b4a9d06126300fd6c3489f3685b965 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 16 May 2022 19:02:46 +0200 Subject: [PATCH 16/17] Added YT Music Filters --- .../com/github/libretube/SearchFragment.kt | 35 ++++++++++++------- app/src/main/res/values/strings.xml | 4 +++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/SearchFragment.kt b/app/src/main/java/com/github/libretube/SearchFragment.kt index 6163d9faf..e97d7d44d 100644 --- a/app/src/main/java/com/github/libretube/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/SearchFragment.kt @@ -15,7 +15,6 @@ import android.view.inputmethod.InputMethodManager import android.widget.* import android.widget.TextView.* import androidx.appcompat.app.AlertDialog -import androidx.core.content.ContentProviderCompat.requireContext import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceManager @@ -68,10 +67,20 @@ class SearchFragment : Fragment() { var tempSelectedItem = 0 filterImageView.setOnClickListener { - val options = arrayOf(getString(R.string.all), getString(R.string.videos), getString(R.string.channels), getString(R.string.playlists)) + val filterOptions = arrayOf( + getString(R.string.all), + getString(R.string.videos), + getString(R.string.channels), + getString(R.string.playlists), + getString(R.string.music_songs), + getString(R.string.music_videos), + getString(R.string.music_albums), + getString(R.string.music_playlists) + ) + AlertDialog.Builder(view.context) .setTitle(getString(R.string.choose_filter)) - .setSingleChoiceItems(options, selectedFilter, DialogInterface.OnClickListener { + .setSingleChoiceItems(filterOptions, selectedFilter, DialogInterface.OnClickListener { _, id -> tempSelectedItem = id }) .setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { _, _ -> @@ -81,6 +90,10 @@ class SearchFragment : Fragment() { 1 -> "videos" 2 -> "channels" 3 -> "playlists" + 4 -> "music_songs" + 5 -> "music_videos" + 6 -> "music_albums" + 7 -> "music_playlists" else -> "all" } fetchSearch(autoTextView.text.toString()) @@ -98,7 +111,7 @@ class SearchFragment : Fragment() { historyRecycler.layoutManager = LinearLayoutManager(view.context) var historylist = getHistory() - if (historylist.size != 0) { + if (historylist.isNotEmpty()) { historyRecycler.adapter = SearchHistoryAdapter(requireContext(), historylist, autoTextView) } @@ -107,7 +120,7 @@ class SearchFragment : Fragment() { autoTextView.requestFocus() val imm = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - imm!!.showSoftInput(autoTextView, InputMethodManager.SHOW_IMPLICIT) + imm.showSoftInput(autoTextView, InputMethodManager.SHOW_IMPLICIT) autoTextView.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged( s: CharSequence?, @@ -147,7 +160,7 @@ class SearchFragment : Fragment() { searchRecView.visibility = GONE historyRecycler.visibility = VISIBLE var historylist = getHistory() - if (historylist.size != 0) { + if (historylist.isNotEmpty()) { historyRecycler.adapter = SearchHistoryAdapter(requireContext(), historylist, autoTextView) } @@ -157,8 +170,8 @@ class SearchFragment : Fragment() { }) autoTextView.setOnEditorActionListener(OnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH) { - hideKeyboard(); - autoTextView.dismissDropDown(); + hideKeyboard() + autoTextView.dismissDropDown() return@OnEditorActionListener true } false @@ -212,11 +225,7 @@ class SearchFragment : Fragment() { if (!isLoading) { isLoading = true val response = try { - RetrofitInstance.api.getSearchResultsNextPage( - query!!, - apiSearchFilter!!, - nextPage!! - ) + RetrofitInstance.api.getSearchResultsNextPage(query,apiSearchFilter,nextPage!!) } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6e7281ea0..ec277ead3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -80,4 +80,8 @@ History Search History Clear History + Music Songs + Music Videos + Music Albums + Music Playlists From fef55895340d6ea531595ebdac715d77414ae934 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 16 May 2022 20:14:27 +0200 Subject: [PATCH 17/17] Fixed null and -1 strings --- .../github/libretube/adapters/SearchAdapter.kt | 14 ++++++-------- app/src/main/res/layout/playlist_search_row.xml | 15 ++++----------- app/src/main/res/layout/video_channel_row.xml | 2 -- app/src/main/res/layout/video_search_row.xml | 3 --- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index be951287d..71e431041 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -65,13 +65,11 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ val channelImage = v.findViewById(R.id.search_channel_image) Picasso.get().load(item.uploaderAvatar).fit().centerCrop().into(channelImage) val title = v.findViewById(R.id.search_description) - if (item.title!!.length > 60) { - title.text = item.title?.substring(0, 60) + "..." - } else { - title.text = item.title - } + title.text = if (item.title!!.length > 60) item.title?.substring(0, 60) + "..." else item.title val views = v.findViewById(R.id.search_views) - views.text = item.views.formatShort() +" • "+item.uploadedDate + val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else "" + val uploadDate = if (item.uploadedDate != null) item.uploadedDate else "" + views.text = if (viewsString != "" && uploadDate != "") viewsString + " • " + uploadDate else viewsString + uploadDate val channelName = v.findViewById(R.id.search_channel_name) channelName.text = item.uploaderName v.setOnClickListener{ @@ -111,13 +109,13 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){ val playlistImage = v.findViewById(R.id.search_thumbnail) Picasso.get().load(item.thumbnail).fit().centerCrop().into(playlistImage) val playlistNumber = v.findViewById(R.id.search_playlist_number) - playlistNumber.text = item.videos.toString() + if (item.videos?.toInt() != -1) playlistNumber.text = item.videos.toString() val playlistName = v.findViewById(R.id.search_description) playlistName.text = item.name val playlistChannelName = v.findViewById(R.id.search_name) playlistChannelName.text = item.uploaderName val playlistVideosNumber = v.findViewById(R.id.search_playlist_videos) - playlistVideosNumber.text = item.videos.toString()+" videos" + if (item.videos?.toInt() != -1) playlistVideosNumber.text = v.context.getString(R.string.videoCount, item.videos.toString()) v.setOnClickListener { //playlist clicked val activity = v.context as MainActivity diff --git a/app/src/main/res/layout/playlist_search_row.xml b/app/src/main/res/layout/playlist_search_row.xml index a4d451b23..2b3eb1086 100644 --- a/app/src/main/res/layout/playlist_search_row.xml +++ b/app/src/main/res/layout/playlist_search_row.xml @@ -43,21 +43,17 @@ android:id="@+id/search_playlist_number" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="10" - android:textColor="#ECE4E4" + android:layout_centerInParent="true" android:layout_centerVertical="true" - android:layout_centerHorizontal="true" - /> + android:textColor="#ECE4E4" /> + android:layout_centerInParent="true" + app:srcCompat="@drawable/ic_playlist" /> @@ -67,7 +63,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/card_playlist" app:layout_constraintTop_toTopOf="parent" /> @@ -77,7 +72,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/card_playlist" app:layout_constraintTop_toBottomOf="@+id/search_description" /> @@ -86,7 +80,6 @@ android:id="@+id/search_playlist_videos" android:layout_width="0dp" android:layout_height="wrap_content" - android:text="TextView" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="@+id/guideline" diff --git a/app/src/main/res/layout/video_channel_row.xml b/app/src/main/res/layout/video_channel_row.xml index 6835d1997..ad74d023b 100644 --- a/app/src/main/res/layout/video_channel_row.xml +++ b/app/src/main/res/layout/video_channel_row.xml @@ -50,7 +50,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintTop_toTopOf="parent" /> @@ -60,7 +59,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintTop_toBottomOf="@+id/channel_description" /> diff --git a/app/src/main/res/layout/video_search_row.xml b/app/src/main/res/layout/video_search_row.xml index 444473b2e..5d26d04b3 100644 --- a/app/src/main/res/layout/video_search_row.xml +++ b/app/src/main/res/layout/video_search_row.xml @@ -53,7 +53,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintTop_toTopOf="parent" /> @@ -63,7 +62,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintTop_toBottomOf="@+id/search_description" /> @@ -83,7 +81,6 @@ android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="12dp" - android:text="TextView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/search_channel_image" app:layout_constraintTop_toBottomOf="@+id/search_views" />