Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -628,6 +634,16 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
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)
Expand All @@ -649,7 +665,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
}
homeMasterAdapter = HomeParentItemAdapterPreview(
fragment = this@HomeFragment,
homeViewModel, accountViewModel
homeViewModel
)
homeMasterRecycler.setRecycledViewPool(ParentItemAdapter.sharedPool)
homeMasterRecycler.adapter = homeMasterAdapter
Expand All @@ -671,9 +687,47 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
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
Expand Down Expand Up @@ -715,7 +769,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
super.onScrolled(recyclerView, dx, dy)
}
})

}

//Load value for toggling Random button. Hide at startup
Expand All @@ -736,13 +789,27 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
homeChangeApi.text = apiName
homePreviewReloadProvider.isGone = (apiName == noneApi.name)
homePreviewSearchButton.isGone = (apiName == noneApi.name)
homeSearch.isVisible = false
}
}

observe(homeViewModel.page) { data ->
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(
Expand Down Expand Up @@ -773,6 +840,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
}

is Resource.Failure -> {
homeSearch.isVisible = false
homeLoadingShimmer.stopShimmer()
homeReloadConnectionerror.setOnClickListener(apiChangeClickListener)
homeReloadConnectionOpenInBrowser.setOnClickListener { view ->
Expand All @@ -797,6 +865,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -102,7 +94,7 @@ class HomeParentItemAdapterPreview(
)
}

return HeaderViewHolder(binding, viewModel, accountViewModel, fragment)
return HeaderViewHolder(binding, viewModel, fragment)
}

override fun onBindHeader(holder: ViewHolderState<Bundle>) {
Expand All @@ -128,7 +120,6 @@ class HomeParentItemAdapterPreview(
private class HeaderViewHolder(
val binding: ViewBinding,
val viewModel: HomeViewModel,
accountViewModel: AccountViewModel,
fragment: LifecycleOwner,
) :
ViewHolderState<Bundle>(binding) {
Expand Down Expand Up @@ -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? =
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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<Pair<Boolean, List<LoadResponse>>>) {
Expand Down Expand Up @@ -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) {
Expand Down
71 changes: 71 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,75 @@
app:icon="@drawable/ic_baseline_play_arrow_24"
tools:ignore="ContentDescription"
tools:visibility="visible" />
<View
android:id="@+id/topbar_bg"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/black_overlay"
android:orientation="horizontal"
android:scaleY="0"
android:transformPivotY="0dp"
android:layout_marginTop="1.3dp" />
<LinearLayout
android:id="@+id/home_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical|end"
android:paddingHorizontal="0dp"
android:layout_gravity="top"
android:layout_marginTop="1.3dp">
<androidx.appcompat.widget.SearchView
android:id="@+id/home_search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:editTextColor="@color/white"
android:gravity="center_vertical"
android:iconifiedByDefault="true"
android:nextFocusRight="@id/home_head_profile_padding"
android:padding="0dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
app:closeIcon="@drawable/ic_baseline_close_24"
app:iconifiedByDefault="true"
app:queryBackground="@color/transparent"
app:queryHint="@string/search_hint"
app:searchIcon="@drawable/search_icon"
tools:ignore="RtlSymmetry"
android:visibility="gone"/>

<LinearLayout
android:id="@+id/home_head_profile_padding"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="center"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/rounded_select_ripple"
android:nextFocusLeft="@id/home_search">

<androidx.cardview.widget.CardView
android:id="@+id/home_head_profile_card"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="@color/transparent"
app:cardCornerRadius="20dp"
android:foreground="@drawable/outline_drawable_round_20"
android:focusable="true">

<ImageView
android:id="@+id/home_head_profile_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:contentDescription="@string/account"
android:foreground="@drawable/rounded_outline"
tools:src="@drawable/profile_bg_orange" />
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Loading