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 6c58fac9a8b..070d1d8ce6b 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 @@ -5,10 +5,12 @@ import android.app.Activity import android.content.Context import android.content.DialogInterface import android.content.Intent +import android.content.res.Configuration import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.ViewGroup.MarginLayoutParams import android.widget.AbsListView import android.widget.ArrayAdapter import android.widget.ImageView @@ -75,6 +77,10 @@ import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes import com.lagradost.cloudstream3.utils.UIHelper.toPx +import androidx.appcompat.widget.SearchView +import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountEditDialog +import com.lagradost.cloudstream3.utils.ImageLoader.loadImage +import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarMargin private const val TAG = "HomeFragment" @@ -628,6 +634,16 @@ class HomeFragment : BaseFragment( override fun onBindingCreated(binding: FragmentHomeBinding) { context?.let { HomeChildItemAdapter.updatePosterSize(it) } binding.apply { + fixPaddingStatusbarMargin(homePadding) + val orientation = resources.configuration.orientation + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + topbarBg.layoutParams = topbarBg.layoutParams.apply { + if (this is MarginLayoutParams) { + setMargins(0,0,0,0) + } + } + } + fixPaddingStatusbarMargin(topbarBg) //homeChangeApiLoading.setOnClickListener(apiChangeClickListener) //homeChangeApiLoading.setOnClickListener(apiChangeClickListener) homeApiFab.setOnClickListener(apiChangeClickListener) @@ -649,7 +665,7 @@ class HomeFragment : BaseFragment( } homeMasterAdapter = HomeParentItemAdapterPreview( fragment = this@HomeFragment, - homeViewModel, accountViewModel + homeViewModel ) homeMasterRecycler.setRecycledViewPool(ParentItemAdapter.sharedPool) homeMasterRecycler.adapter = homeMasterAdapter @@ -671,9 +687,47 @@ class HomeFragment : BaseFragment( homeViewModel.queryTextSubmit("") } + homeHeadProfileCard.isGone = isLayout(TV or EMULATOR) + + homeViewModel.currentAccount.observe(viewLifecycleOwner) { currentAccount -> + homeHeadProfilePic.loadImage(currentAccount?.image) + } + + homeHeadProfilePadding.setOnClickListener { + activity?.showAccountSelectLinear() + } + + fun showAccountEditBox(context: Context): Boolean { + val currentAccount = DataStoreHelper.getCurrentAccount() + return if (currentAccount != null) { + showAccountEditDialog( + context = context, + account = currentAccount, + isNewAccount = false, + accountEditCallback = { accountViewModel.handleAccountUpdate(it, context) }, + accountDeleteCallback = { + accountViewModel.handleAccountDelete( + it, + context + ) + } + ) + true + } else false + } + + homeHeadProfilePadding.setOnLongClickListener { + showAccountEditBox(it.context) + } + + val topBarTotalScrollRange = 500 homeMasterRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { if (isLayout(PHONE)) { + //topbar_bg movement + val offset = recyclerView.computeVerticalScrollOffset() + val fraction = (offset.toFloat()/topBarTotalScrollRange).coerceIn(0f,1f) + topbarBg.scaleY =fraction // Fab is only relevant to Phone if (dy > 0) { //check for scroll down homeApiFab.shrink() // hide @@ -715,7 +769,6 @@ class HomeFragment : BaseFragment( super.onScrolled(recyclerView, dx, dy) } }) - } //Load value for toggling Random button. Hide at startup @@ -736,6 +789,7 @@ class HomeFragment : BaseFragment( homeChangeApi.text = apiName homePreviewReloadProvider.isGone = (apiName == noneApi.name) homePreviewSearchButton.isGone = (apiName == noneApi.name) + homeSearch.isVisible = false } } @@ -743,6 +797,19 @@ class HomeFragment : BaseFragment( binding.apply { when (data) { is Resource.Success -> { + homeLoadingShimmer.stopShimmer() + homeSearch.isVisible = homeViewModel.apiName.value != noneApi.name + homeSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String): Boolean { + homeViewModel.queryTextSubmit(query) + return true + } + + override fun onQueryTextChange(newText: String): Boolean { + homeViewModel.queryTextChange(newText) + return true + } + }) val d = data.value (homeMasterRecycler.adapter as? ParentItemAdapter)?.submitList(d.values.map { it.copy( @@ -773,6 +840,7 @@ class HomeFragment : BaseFragment( } is Resource.Failure -> { + homeSearch.isVisible = false homeLoadingShimmer.stopShimmer() homeReloadConnectionerror.setOnClickListener(apiChangeClickListener) homeReloadConnectionOpenInBrowser.setOnClickListener { view -> @@ -797,6 +865,7 @@ class HomeFragment : BaseFragment( homeLoading.isVisible = false homeLoadingError.isVisible = true homeMasterRecycler.isInvisible = true + homeSearch.isVisible = false // Based on https://github.com/recloudstream/cloudstream/pull/1438 val hasNoNetworkConnection = context?.isNetworkAvailable() == false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt index e6b82e47382..2abbaf82796 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt @@ -1,14 +1,11 @@ package com.lagradost.cloudstream3.ui.home -import android.content.Context import android.os.Bundle import android.os.Parcelable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.ImageView import androidx.appcompat.app.AlertDialog -import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat import androidx.core.view.isGone import androidx.core.view.isVisible @@ -35,9 +32,6 @@ import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.ui.ViewHolderState import com.lagradost.cloudstream3.ui.WatchType -import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountEditDialog -import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountSelectLinear -import com.lagradost.cloudstream3.ui.account.AccountViewModel import com.lagradost.cloudstream3.ui.result.FOCUS_SELF import com.lagradost.cloudstream3.ui.result.ResultViewModel2 import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST @@ -52,7 +46,6 @@ import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.utils.AppContextUtils.html import com.lagradost.cloudstream3.utils.AppContextUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.DataStoreHelper -import com.lagradost.cloudstream3.utils.ImageLoader.loadImage import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarMargin @@ -61,8 +54,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.populateChips class HomeParentItemAdapterPreview( val fragment: LifecycleOwner, - private val viewModel: HomeViewModel, - private val accountViewModel: AccountViewModel + private val viewModel: HomeViewModel ) : ParentItemAdapter( id = "HomeParentItemAdapterPreview".hashCode(), clickCallback = { @@ -102,7 +94,7 @@ class HomeParentItemAdapterPreview( ) } - return HeaderViewHolder(binding, viewModel, accountViewModel, fragment) + return HeaderViewHolder(binding, viewModel, fragment) } override fun onBindHeader(holder: ViewHolderState) { @@ -128,7 +120,6 @@ class HomeParentItemAdapterPreview( private class HeaderViewHolder( val binding: ViewBinding, val viewModel: HomeViewModel, - accountViewModel: AccountViewModel, fragment: LifecycleOwner, ) : ViewHolderState(binding) { @@ -319,16 +310,6 @@ class HomeParentItemAdapterPreview( private val bookmarkHolder: View = itemView.findViewById(R.id.home_bookmarked_holder) private val bookmarkRecyclerView: RecyclerView = itemView.findViewById(R.id.home_bookmarked_child_recyclerview) - - private val headProfilePic: ImageView? = itemView.findViewById(R.id.home_head_profile_pic) - private val headProfilePicCard: View? = - itemView.findViewById(R.id.home_head_profile_padding) - - private val alternateHeadProfilePic: ImageView? = - itemView.findViewById(R.id.alternate_home_head_profile_pic) - private val alternateHeadProfilePicCard: View? = - itemView.findViewById(R.id.alternate_home_head_profile_padding) - private val topPadding: View? = itemView.findViewById(R.id.home_padding) private val alternativeAccountPadding: View? = @@ -491,48 +472,6 @@ class HomeParentItemAdapterPreview( } } - headProfilePicCard?.isGone = isLayout(TV or EMULATOR) - alternateHeadProfilePicCard?.isGone = isLayout(TV or EMULATOR) - - fragment.observe(viewModel.currentAccount) { currentAccount -> - headProfilePic?.loadImage(currentAccount?.image) - alternateHeadProfilePic?.loadImage(currentAccount?.image) - } - - headProfilePicCard?.setOnClickListener { - activity?.showAccountSelectLinear() - } - - fun showAccountEditBox(context: Context): Boolean { - val currentAccount = DataStoreHelper.getCurrentAccount() - return if (currentAccount != null) { - showAccountEditDialog( - context = context, - account = currentAccount, - isNewAccount = false, - accountEditCallback = { accountViewModel.handleAccountUpdate(it, context) }, - accountDeleteCallback = { - accountViewModel.handleAccountDelete( - it, - context - ) - } - ) - true - } else false - } - - alternateHeadProfilePicCard?.setOnLongClickListener { - showAccountEditBox(it.context) - } - headProfilePicCard?.setOnLongClickListener { - showAccountEditBox(it.context) - } - - alternateHeadProfilePicCard?.setOnClickListener { - activity?.showAccountSelectLinear() - } - (binding as? FragmentHomeHeadTvBinding)?.apply { /*homePreviewChangeApi.setOnClickListener { view -> view.context.selectHomepage(viewModel.repo?.name) { api -> @@ -587,20 +526,6 @@ class HomeParentItemAdapterPreview( } } } - - (binding as? FragmentHomeHeadBinding)?.apply { - homeSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(query: String): Boolean { - viewModel.queryTextSubmit(query) - return true - } - - override fun onQueryTextChange(newText: String): Boolean { - viewModel.queryTextChange(newText) - return true - } - }) - } } private fun updatePreview(preview: Resource>>) { @@ -727,6 +652,7 @@ class HomeParentItemAdapterPreview( observe(viewModel.apiName) { name -> binding.homePreviewChangeApi.text = name binding.homePreviewReloadProvider.isGone = (name == noneApi.name) + binding.homePreviewChangeApi.requestFocus() } }*/ observe(viewModel.resumeWatching) { diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 77a41b2e294..dba8ecc0a71 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -247,4 +247,75 @@ app:icon="@drawable/ic_baseline_play_arrow_24" tools:ignore="ContentDescription" tools:visibility="visible" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home_head.xml b/app/src/main/res/layout/fragment_home_head.xml index e57990dc490..dc55c2b09e5 100644 --- a/app/src/main/res/layout/fragment_home_head.xml +++ b/app/src/main/res/layout/fragment_home_head.xml @@ -1,5 +1,5 @@ - - + - - - - - - - - - - - - - - #80FFFFFF - #32FFFFFF - + #80FFFFFF#32FFFFFF #66000000 + #80000000 #C0121212 #4D121212 #121212