fix bottom dialog

This commit is contained in:
ixiumu 2022-11-24 00:11:13 +08:00
parent 789f3db554
commit 379eb2ebe7
4 changed files with 56 additions and 10 deletions

View file

@ -8,6 +8,7 @@ import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -37,6 +38,7 @@ import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
import com.lagradost.cloudstream3.MainActivity.Companion.mainPluginsLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.mainPluginsLoadedEvent
@ -123,6 +125,7 @@ class HomeFragment : Fragment() {
val configEvent = Event<Int>() val configEvent = Event<Int>()
var currentSpan = 1 var currentSpan = 1
val listHomepageItems = mutableListOf<SearchResponse>() val listHomepageItems = mutableListOf<SearchResponse>()
val handler = Handler(android.os.Looper.getMainLooper())
private val errorProfilePics = listOf( private val errorProfilePics = listOf(
R.drawable.monke_benene, R.drawable.monke_benene,
@ -142,8 +145,8 @@ class HomeFragment : Fragment() {
fun Activity.loadHomepageList( fun Activity.loadHomepageList(
item: HomePageList, item: HomePageList,
deleteCallback: (() -> Unit)? = null, deleteCallback: (() -> Unit)? = null,
) { ): BottomSheetDialog? {
loadHomepageList( return loadHomepageList(
expand = HomeViewModel.ExpandableHomepageList(item, 1, false), expand = HomeViewModel.ExpandableHomepageList(item, 1, false),
deleteCallback = deleteCallback, deleteCallback = deleteCallback,
expandCallback = null expandCallback = null
@ -154,10 +157,10 @@ class HomeFragment : Fragment() {
expand: HomeViewModel.ExpandableHomepageList, expand: HomeViewModel.ExpandableHomepageList,
deleteCallback: (() -> Unit)? = null, deleteCallback: (() -> Unit)? = null,
expandCallback: (suspend (String) -> HomeViewModel.ExpandableHomepageList?)? = null expandCallback: (suspend (String) -> HomeViewModel.ExpandableHomepageList?)? = null
) { ): BottomSheetDialog? {
val context = this val context = this
val bottomSheetDialogBuilder = BottomSheetDialog(context) var bottomSheetDialogBuilder: BottomSheetDialog? = BottomSheetDialog(context)
bottomSheetDialogBuilder.setContentView(R.layout.home_episodes_expanded) bottomSheetDialogBuilder!!.setContentView(R.layout.home_episodes_expanded)
val title = bottomSheetDialogBuilder.findViewById<TextView>(R.id.home_expanded_text)!! val title = bottomSheetDialogBuilder.findViewById<TextView>(R.id.home_expanded_text)!!
val item = expand.list val item = expand.list
title.text = item.name title.text = item.name
@ -200,7 +203,7 @@ class HomeFragment : Fragment() {
} }
titleHolder.setOnClickListener { titleHolder.setOnClickListener {
bottomSheetDialogBuilder.dismissSafe(this) bottomSheetDialogBuilder?.dismissSafe(this)
} }
@ -210,7 +213,13 @@ class HomeFragment : Fragment() {
recycle.adapter = SearchAdapter(item.list.toMutableList(), recycle) { callback -> recycle.adapter = SearchAdapter(item.list.toMutableList(), recycle) { callback ->
handleSearchClickCallback(this, callback) handleSearchClickCallback(this, callback)
if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) { if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) {
bottomSheetDialogBuilder.dismissSafe(this) // bottomSheetDialogBuilder.dismissSafe(this)
handler.postDelayed({
bottomSheetDialogBuilder?.let {
it.window?.setWindowAnimations(-1)
it.hide()
}
}, 200)
} }
}.apply { }.apply {
hasNext = expand.hasNext hasNext = expand.hasNext
@ -257,6 +266,17 @@ class HomeFragment : Fragment() {
//(recycle.adapter as SearchAdapter).notifyDataSetChanged() //(recycle.adapter as SearchAdapter).notifyDataSetChanged()
bottomSheetDialogBuilder.show() bottomSheetDialogBuilder.show()
return bottomSheetDialogBuilder
}
fun BottomSheetDialog.onResume(context: Context?) {
// resume dialog
this.window?.setWindowAnimations(-1)
this.show()
handler.postDelayed({
this.window?.setWindowAnimations(R.style.BottomSheetDialog)
}, 400)
} }
fun getPairList( fun getPairList(
@ -427,6 +447,8 @@ class HomeFragment : Fragment() {
private val homeViewModel: HomeViewModel by activityViewModels() private val homeViewModel: HomeViewModel by activityViewModels()
private var bottomSheetDialog: BottomSheetDialog? = null
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
@ -473,6 +495,8 @@ class HomeFragment : Fragment() {
reloadStored() reloadStored()
afterPluginsLoadedEvent += ::firstLoadHomePage afterPluginsLoadedEvent += ::firstLoadHomePage
mainPluginsLoadedEvent += ::firstLoadHomePage mainPluginsLoadedEvent += ::firstLoadHomePage
bottomSheetDialog?.onResume(context)
} }
override fun onStop() { override fun onStop() {
@ -907,7 +931,7 @@ class HomeFragment : Fragment() {
) )
home_bookmarked_child_more_info?.setOnClickListener { home_bookmarked_child_more_info?.setOnClickListener {
activity?.loadHomepageList( bottomSheetDialog = activity?.loadHomepageList(
HomePageList( HomePageList(
getString(R.string.error_bookmarks_text), //home_bookmarked_parent_item_title?.text?.toString() ?: getString(R.string.error_bookmarks_text), getString(R.string.error_bookmarks_text), //home_bookmarked_parent_item_title?.text?.toString() ?: getString(R.string.error_bookmarks_text),
bookmarks bookmarks
@ -916,6 +940,7 @@ class HomeFragment : Fragment() {
deleteAllBookmarkedData() deleteAllBookmarkedData()
homeViewModel.loadStoredData(null) homeViewModel.loadStoredData(null)
} }
bottomSheetDialog?.setOnDismissListener { bottomSheetDialog = null }
} }
} }
@ -932,7 +957,7 @@ class HomeFragment : Fragment() {
//} //}
home_watch_child_more_info?.setOnClickListener { home_watch_child_more_info?.setOnClickListener {
activity?.loadHomepageList( bottomSheetDialog = activity?.loadHomepageList(
HomePageList( HomePageList(
home_watch_parent_item_title?.text?.toString() home_watch_parent_item_title?.text?.toString()
?: getString(R.string.continue_watching), ?: getString(R.string.continue_watching),
@ -942,6 +967,7 @@ class HomeFragment : Fragment() {
deleteAllResumeStateIds() deleteAllResumeStateIds()
homeViewModel.loadResumeWatching() homeViewModel.loadResumeWatching()
} }
bottomSheetDialog?.setOnDismissListener { bottomSheetDialog = null }
} }
} }
@ -1099,9 +1125,10 @@ class HomeFragment : Fragment() {
ParentItemAdapter(mutableListOf(), { callback -> ParentItemAdapter(mutableListOf(), { callback ->
homeHandleSearch(callback) homeHandleSearch(callback)
}, { item -> }, { item ->
activity?.loadHomepageList(item, expandCallback = { bottomSheetDialog = activity?.loadHomepageList(item, expandCallback = {
homeViewModel.expandAndReturn(it) homeViewModel.expandAndReturn(it)
}) })
bottomSheetDialog?.setOnDismissListener { bottomSheetDialog = null }
}, { name -> }, { name ->
homeViewModel.expand(name) homeViewModel.expand(name)
}) })

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="50%p" android:toYDelta="0"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0" android:toYDelta="50%p"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>

View file

@ -727,4 +727,9 @@
@drawable/cast_ic_mini_controller_closed_caption @drawable/cast_ic_mini_controller_closed_caption
</item> </item>
</style> </style>
<style name="BottomSheetDialog">
<item name="android:windowEnterAnimation">@anim/slide_in_down</item>
<item name="android:windowExitAnimation">@anim/slide_out_down</item>
</style>
</resources> </resources>