From c619056b67fa5e682673eda5608a2c0dca40b1ff Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 15 May 2022 10:08:47 +0200 Subject: [PATCH] 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