From 1a5fc93eba7f7aeac05ffb12f12f6f4d4856d398 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Mon, 25 Apr 2022 20:00:25 +0200 Subject: [PATCH] added search to homepage --- app/build.gradle | 4 +- .../cloudstream3/ui/home/HomeFragment.kt | 23 +++++- .../ui/quicksearch/QuickSearchFragment.kt | 8 +- .../cloudstream3/ui/search/SearchFragment.kt | 8 +- .../main/res/drawable/search_background.xml | 2 +- app/src/main/res/layout/fragment_home.xml | 77 ++++++++++++------- app/src/main/res/layout/fragment_search.xml | 2 +- app/src/main/res/layout/quick_search.xml | 2 +- app/src/main/res/values-tr/strings.xml | 1 - 9 files changed, 83 insertions(+), 44 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6bfbf174..74551e17 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,8 @@ android { minSdkVersion 21 targetSdkVersion 30 - versionCode 45 - versionName "2.9.21" + versionCode 46 + versionName "2.9.22" resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}" diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index ed5ed49c..e3cdb12f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -11,6 +11,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.* +import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.core.widget.NestedScrollView import androidx.fragment.app.Fragment @@ -37,6 +38,7 @@ import com.lagradost.cloudstream3.ui.APIRepository.Companion.noneApi import com.lagradost.cloudstream3.ui.APIRepository.Companion.randomApi import com.lagradost.cloudstream3.ui.AutofitRecyclerView import com.lagradost.cloudstream3.ui.WatchType +import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST import com.lagradost.cloudstream3.ui.search.* import com.lagradost.cloudstream3.ui.search.SearchFragment.Companion.filterSearchResponse @@ -65,7 +67,6 @@ import kotlinx.android.synthetic.main.fragment_home.* import kotlinx.android.synthetic.main.fragment_home.home_api_fab import kotlinx.android.synthetic.main.fragment_home.home_bookmarked_child_recyclerview import kotlinx.android.synthetic.main.fragment_home.home_bookmarked_holder -import kotlinx.android.synthetic.main.fragment_home.home_change_api import kotlinx.android.synthetic.main.fragment_home.home_change_api_loading import kotlinx.android.synthetic.main.fragment_home.home_loaded import kotlinx.android.synthetic.main.fragment_home.home_loading @@ -230,7 +231,8 @@ class HomeFragment : Fragment() { }.sortedBy { it.name.lowercase() }.toMutableList() currentValidApis.addAll(0, validAPIs.subList(0, 2)) - val names = currentValidApis.map { if(isMultiLang) "${getFlagFromIso(it.lang)?.plus(" ") ?: ""}${it.name}" else it.name } + val names = + currentValidApis.map { if (isMultiLang) "${getFlagFromIso(it.lang)?.plus(" ") ?: ""}${it.name}" else it.name } val index = currentValidApis.map { it.name }.indexOf(currentApiName) listView?.setItemChecked(index, true) arrayAdapter.addAll(names) @@ -379,7 +381,8 @@ class HomeFragment : Fragment() { //Disable Random button, if its toggled off on settings context?.let { val settingsManager = PreferenceManager.getDefaultSharedPreferences(it) - toggleRandomButton = settingsManager.getBoolean(getString(R.string.random_button_key), false) + toggleRandomButton = + settingsManager.getBoolean(getString(R.string.random_button_key), false) home_random?.isVisible = toggleRandomButton if (!toggleRandomButton) { home_random?.visibility = View.GONE @@ -389,6 +392,7 @@ class HomeFragment : Fragment() { observe(homeViewModel.apiName) { apiName -> currentApiName = apiName setKey(HOMEPAGE_API, apiName) + home_api_fab?.text = apiName home_provider_name?.text = apiName home_provider_meta_info?.isVisible = false @@ -453,6 +457,19 @@ class HomeFragment : Fragment() { } } + home_search?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String): Boolean { + QuickSearchFragment.pushSearch(activity, query) + + return true + } + + override fun onQueryTextChange(newText: String): Boolean { + //searchViewModel.quickSearch(newText) + return true + } + }) + observe(homeViewModel.page) { data -> when (data) { is Resource.Success -> { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt index 3efcc1a1..9dd2e72e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt @@ -113,11 +113,11 @@ class QuickSearchFragment : Fragment() { val searchExitIcon = quick_search?.findViewById(androidx.appcompat.R.id.search_close_btn) - val searchMagIcon = - quick_search?.findViewById(androidx.appcompat.R.id.search_mag_icon) + //val searchMagIcon = + // quick_search?.findViewById(androidx.appcompat.R.id.search_mag_icon) - searchMagIcon?.scaleX = 0.65f - searchMagIcon?.scaleY = 0.65f + //searchMagIcon?.scaleX = 0.65f + //searchMagIcon?.scaleY = 0.65f quick_search?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt index e2d3891f..0c1680b6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt @@ -134,10 +134,10 @@ class SearchFragment : Fragment() { val searchExitIcon = main_search.findViewById(androidx.appcompat.R.id.search_close_btn) - val searchMagIcon = - main_search.findViewById(androidx.appcompat.R.id.search_mag_icon) - searchMagIcon.scaleX = 0.65f - searchMagIcon.scaleY = 0.65f + // val searchMagIcon = + // main_search.findViewById(androidx.appcompat.R.id.search_mag_icon) + //searchMagIcon.scaleX = 0.65f + //searchMagIcon.scaleY = 0.65f context?.let { ctx -> val validAPIs = ctx.filterProviderByPreferredMedia() diff --git a/app/src/main/res/drawable/search_background.xml b/app/src/main/res/drawable/search_background.xml index 5740d5f0..61eb4f3a 100644 --- a/app/src/main/res/drawable/search_background.xml +++ b/app/src/main/res/drawable/search_background.xml @@ -1,5 +1,5 @@ - + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 9e8a302c..e19f64b7 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -179,7 +179,6 @@ android:layout_height="70dp"> + android:layout_width="40dp" + android:layout_height="40dp"> + + + + + + + + android:visibility="gone" + tools:visibility="visible" + android:text="@string/home_random" + android:id="@+id/home_random" + android:layout_gravity="bottom|start" + app:icon="@drawable/ic_baseline_play_arrow_24" + style="@style/ExtendedFloatingActionButton" + android:textColor="?attr/textColor" + tools:ignore="ContentDescription" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index c7d41b7f..62c02f36 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -15,7 +15,7 @@ android:layout_margin="10dp" android:background="@drawable/search_background" android:layout_width="match_parent" - android:layout_height="45dp"> + android:layout_height="40dp"> + android:layout_height="40dp"> search_providers_list app_locale search_type_list - grid_format auto_update prerelease_update manual_check_update