mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Added YT Music Filters
This commit is contained in:
parent
f21f8dd133
commit
af62aa7df2
@ -15,7 +15,6 @@ import android.view.inputmethod.InputMethodManager
|
|||||||
import android.widget.*
|
import android.widget.*
|
||||||
import android.widget.TextView.*
|
import android.widget.TextView.*
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.ContentProviderCompat.requireContext
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
@ -68,10 +67,20 @@ class SearchFragment : Fragment() {
|
|||||||
var tempSelectedItem = 0
|
var tempSelectedItem = 0
|
||||||
|
|
||||||
filterImageView.setOnClickListener {
|
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)
|
AlertDialog.Builder(view.context)
|
||||||
.setTitle(getString(R.string.choose_filter))
|
.setTitle(getString(R.string.choose_filter))
|
||||||
.setSingleChoiceItems(options, selectedFilter, DialogInterface.OnClickListener {
|
.setSingleChoiceItems(filterOptions, selectedFilter, DialogInterface.OnClickListener {
|
||||||
_, id -> tempSelectedItem = id
|
_, id -> tempSelectedItem = id
|
||||||
})
|
})
|
||||||
.setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { _, _ ->
|
.setPositiveButton(getString(R.string.okay), DialogInterface.OnClickListener { _, _ ->
|
||||||
@ -81,6 +90,10 @@ class SearchFragment : Fragment() {
|
|||||||
1 -> "videos"
|
1 -> "videos"
|
||||||
2 -> "channels"
|
2 -> "channels"
|
||||||
3 -> "playlists"
|
3 -> "playlists"
|
||||||
|
4 -> "music_songs"
|
||||||
|
5 -> "music_videos"
|
||||||
|
6 -> "music_albums"
|
||||||
|
7 -> "music_playlists"
|
||||||
else -> "all"
|
else -> "all"
|
||||||
}
|
}
|
||||||
fetchSearch(autoTextView.text.toString())
|
fetchSearch(autoTextView.text.toString())
|
||||||
@ -98,7 +111,7 @@ class SearchFragment : Fragment() {
|
|||||||
historyRecycler.layoutManager = LinearLayoutManager(view.context)
|
historyRecycler.layoutManager = LinearLayoutManager(view.context)
|
||||||
|
|
||||||
var historylist = getHistory()
|
var historylist = getHistory()
|
||||||
if (historylist.size != 0) {
|
if (historylist.isNotEmpty()) {
|
||||||
historyRecycler.adapter =
|
historyRecycler.adapter =
|
||||||
SearchHistoryAdapter(requireContext(), historylist, autoTextView)
|
SearchHistoryAdapter(requireContext(), historylist, autoTextView)
|
||||||
}
|
}
|
||||||
@ -107,7 +120,7 @@ class SearchFragment : Fragment() {
|
|||||||
autoTextView.requestFocus()
|
autoTextView.requestFocus()
|
||||||
val imm =
|
val imm =
|
||||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm!!.showSoftInput(autoTextView, InputMethodManager.SHOW_IMPLICIT)
|
imm.showSoftInput(autoTextView, InputMethodManager.SHOW_IMPLICIT)
|
||||||
autoTextView.addTextChangedListener(object : TextWatcher {
|
autoTextView.addTextChangedListener(object : TextWatcher {
|
||||||
override fun beforeTextChanged(
|
override fun beforeTextChanged(
|
||||||
s: CharSequence?,
|
s: CharSequence?,
|
||||||
@ -147,7 +160,7 @@ class SearchFragment : Fragment() {
|
|||||||
searchRecView.visibility = GONE
|
searchRecView.visibility = GONE
|
||||||
historyRecycler.visibility = VISIBLE
|
historyRecycler.visibility = VISIBLE
|
||||||
var historylist = getHistory()
|
var historylist = getHistory()
|
||||||
if (historylist.size != 0) {
|
if (historylist.isNotEmpty()) {
|
||||||
historyRecycler.adapter =
|
historyRecycler.adapter =
|
||||||
SearchHistoryAdapter(requireContext(), historylist, autoTextView)
|
SearchHistoryAdapter(requireContext(), historylist, autoTextView)
|
||||||
}
|
}
|
||||||
@ -157,8 +170,8 @@ class SearchFragment : Fragment() {
|
|||||||
})
|
})
|
||||||
autoTextView.setOnEditorActionListener(OnEditorActionListener { _, actionId, _ ->
|
autoTextView.setOnEditorActionListener(OnEditorActionListener { _, actionId, _ ->
|
||||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||||
hideKeyboard();
|
hideKeyboard()
|
||||||
autoTextView.dismissDropDown();
|
autoTextView.dismissDropDown()
|
||||||
return@OnEditorActionListener true
|
return@OnEditorActionListener true
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
@ -212,11 +225,7 @@ class SearchFragment : Fragment() {
|
|||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.api.getSearchResultsNextPage(
|
RetrofitInstance.api.getSearchResultsNextPage(query,apiSearchFilter,nextPage!!)
|
||||||
query!!,
|
|
||||||
apiSearchFilter!!,
|
|
||||||
nextPage!!
|
|
||||||
)
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
Log.e(TAG, "IOException, you might not have internet connection")
|
Log.e(TAG, "IOException, you might not have internet connection")
|
||||||
|
@ -80,4 +80,8 @@
|
|||||||
<string name="history">History</string>
|
<string name="history">History</string>
|
||||||
<string name="search_history">Search History</string>
|
<string name="search_history">Search History</string>
|
||||||
<string name="clear_history">Clear History</string>
|
<string name="clear_history">Clear History</string>
|
||||||
|
<string name="music_songs">Music Songs</string>
|
||||||
|
<string name="music_videos">Music Videos</string>
|
||||||
|
<string name="music_albums">Music Albums</string>
|
||||||
|
<string name="music_playlists">Music Playlists</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user