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 b03e40cf..3e9f6810 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 @@ -18,6 +18,7 @@ import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels +import androidx.lifecycle.* import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -48,6 +49,8 @@ import com.lagradost.cloudstream3.utils.AppUtils.addProgramsToContinueWatching import com.lagradost.cloudstream3.utils.AppUtils.isRecyclerScrollable import com.lagradost.cloudstream3.utils.AppUtils.loadResult import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult +import com.lagradost.cloudstream3.utils.AppUtils.ownHide +import com.lagradost.cloudstream3.utils.AppUtils.ownShow import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.setKey @@ -104,26 +107,32 @@ class HomeFragment : Fragment() { val errorProfilePic = errorProfilePics.random() - fun Activity.loadHomepageList( - item: HomePageList, - deleteCallback: (() -> Unit)? = null, - ) { - loadHomepageList( - expand = HomeViewModel.ExpandableHomepageList(item, 1, false), - deleteCallback = deleteCallback, - expandCallback = null - ) - } + //fun Activity.loadHomepageList( + // item: HomePageList, + // deleteCallback: (() -> Unit)? = null, + //) { + // loadHomepageList( + // expand = HomeViewModel.ExpandableHomepageList(item, 1, false), + // deleteCallback = deleteCallback, + // expandCallback = null + // ) + //} + // returns a BottomSheetDialog that will be hidden with OwnHidden upon hide, and must be saved to be able call ownShow in onCreateView fun Activity.loadHomepageList( expand: HomeViewModel.ExpandableHomepageList, deleteCallback: (() -> Unit)? = null, - expandCallback: (suspend (String) -> HomeViewModel.ExpandableHomepageList?)? = null - ) { + expandCallback: (suspend (String) -> HomeViewModel.ExpandableHomepageList?)? = null, + dismissCallback : (() -> Unit), + ): BottomSheetDialog { val context = this val bottomSheetDialogBuilder = BottomSheetDialog(context) + bottomSheetDialogBuilder.setContentView(R.layout.home_episodes_expanded) val title = bottomSheetDialogBuilder.findViewById(R.id.home_expanded_text)!! + + //title.findViewTreeLifecycleOwner().lifecycle.addObserver() + val item = expand.list title.text = item.name val recycle = @@ -131,6 +140,23 @@ class HomeFragment : Fragment() { val titleHolder = bottomSheetDialogBuilder.findViewById(R.id.home_expanded_drag_down)!! + // main { + //(bottomSheetDialogBuilder.ownerActivity as androidx.fragment.app.FragmentActivity?)?.supportFragmentManager?.fragments?.lastOrNull()?.viewLifecycleOwner?.apply { + // println("GOT LIFE: lifecycle $this") + // this.lifecycle.addObserver(object : DefaultLifecycleObserver { + // override fun onResume(owner: LifecycleOwner) { + // super.onResume(owner) + // println("onResume!!!!") + // bottomSheetDialogBuilder?.ownShow() + // } + + // override fun onStop(owner: LifecycleOwner) { + // super.onStop(owner) + // bottomSheetDialogBuilder?.ownHide() + // } + // }) + //} + // } val delete = bottomSheetDialogBuilder.home_expanded_delete delete.isGone = deleteCallback == null if (deleteCallback != null) { @@ -175,7 +201,8 @@ class HomeFragment : Fragment() { recycle.adapter = SearchAdapter(item.list.toMutableList(), recycle) { callback -> handleSearchClickCallback(this, callback) if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) { - bottomSheetDialogBuilder.dismissSafe(this) + bottomSheetDialogBuilder.ownHide() // we hide here because we want to resume it later + //bottomSheetDialogBuilder.dismissSafe(this) } }.apply { hasNext = expand.hasNext @@ -216,12 +243,14 @@ class HomeFragment : Fragment() { configEvent += spanListener bottomSheetDialogBuilder.setOnDismissListener { + dismissCallback.invoke() configEvent -= spanListener } //(recycle.adapter as SearchAdapter).notifyDataSetChanged() bottomSheetDialogBuilder.show() + return bottomSheetDialogBuilder } fun getPairList( @@ -399,6 +428,7 @@ class HomeFragment : Fragment() { ): View? { //homeViewModel = // ViewModelProvider(this).get(HomeViewModel::class.java) + bottomSheetDialog?.ownShow() val layout = if (isTvSettings()) R.layout.fragment_home_tv else R.layout.fragment_home return inflater.inflate(layout, container, false) @@ -480,6 +510,8 @@ class HomeFragment : Fragment() { private var currentApiName: String? = null private var toggleRandomButton = false + private var bottomSheetDialog: BottomSheetDialog? = null + @SuppressLint("SetTextI18n") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -626,8 +658,10 @@ class HomeFragment : Fragment() { HomeParentItemAdapterPreview(mutableListOf(), { callback -> homeHandleSearch(callback) }, { item -> - activity?.loadHomepageList(item, expandCallback = { + bottomSheetDialog = activity?.loadHomepageList(item, expandCallback = { homeViewModel.expandAndReturn(it) + }, dismissCallback = { + bottomSheetDialog = null }) }, { name -> homeViewModel.expand(name) 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 62f967d2..ad3d9eb8 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 @@ -15,6 +15,7 @@ import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import com.google.android.material.bottomsheet.BottomSheetDialog import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia import com.lagradost.cloudstream3.APIHolder.filterSearchResultByFilmQuality import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull @@ -30,6 +31,7 @@ import com.lagradost.cloudstream3.ui.search.SearchAdapter import com.lagradost.cloudstream3.ui.search.SearchClickCallback import com.lagradost.cloudstream3.ui.search.SearchHelper import com.lagradost.cloudstream3.ui.search.SearchViewModel +import com.lagradost.cloudstream3.utils.AppUtils.ownShow import com.lagradost.cloudstream3.utils.UIHelper import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount @@ -71,6 +73,8 @@ class QuickSearchFragment : Fragment() { private var providers: Set? = null private lateinit var searchViewModel: SearchViewModel + private var bottomSheetDialog: BottomSheetDialog? = null + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -80,7 +84,7 @@ class QuickSearchFragment : Fragment() { WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE ) searchViewModel = ViewModelProvider(this)[SearchViewModel::class.java] - + bottomSheetDialog?.ownShow() return inflater.inflate(R.layout.quick_search, container, false) } @@ -156,7 +160,9 @@ class QuickSearchFragment : Fragment() { // else -> SearchHelper.handleSearchClickCallback(activity, callback) //} }, { item -> - activity?.loadHomepageList(item) + bottomSheetDialog = activity?.loadHomepageList(item, dismissCallback = { + bottomSheetDialog = null + }) }) quick_search_master_recycler?.layoutManager = GridLayoutManager(context, 1) } 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 9c6b62e8..5c101246 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 @@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.ui.home.HomeFragment.Companion.updateChips import com.lagradost.cloudstream3.ui.home.ParentItemAdapter import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings +import com.lagradost.cloudstream3.utils.AppUtils.ownShow import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.setKey @@ -85,6 +86,7 @@ class SearchFragment : Fragment() { } private val searchViewModel: SearchViewModel by activityViewModels() + private var bottomSheetDialog: BottomSheetDialog? = null override fun onCreateView( inflater: LayoutInflater, @@ -94,6 +96,7 @@ class SearchFragment : Fragment() { activity?.window?.setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE ) + bottomSheetDialog?.ownShow() return inflater.inflate( if (isTvSettings()) R.layout.fragment_search_tv else R.layout.fragment_search, container, @@ -473,7 +476,9 @@ class SearchFragment : Fragment() { ParentItemAdapter(mutableListOf(), { callback -> SearchHelper.handleSearchClickCallback(activity, callback) }, { item -> - activity?.loadHomepageList(item) + bottomSheetDialog = activity?.loadHomepageList(item, dismissCallback = { + bottomSheetDialog = null + }) }) val historyAdapter = SearchHistoryAdaptor(mutableListOf()) { click -> diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt index 847b3328..a3eb7362 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -13,9 +13,7 @@ import android.media.tv.TvContract.Channels.COLUMN_INTERNAL_PROVIDER_ID import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.net.Uri -import android.os.Build -import android.os.Environment -import android.os.ParcelFileDescriptor +import android.os.* import android.provider.MediaStore import android.text.Spanned import android.util.Log @@ -40,6 +38,7 @@ import com.google.android.gms.cast.framework.CastState import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailability import com.google.android.gms.common.wrappers.Wrappers +import com.google.android.material.bottomsheet.BottomSheetDialog import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.MainActivity.Companion.afterRepositoryLoadedEvent @@ -79,6 +78,19 @@ object AppUtils { return if (layoutManager == null || adapter == null) false else layoutManager.findLastCompletelyVisibleItemPosition() < adapter.itemCount - 7 // bit more than 1 to make it more seamless } + fun BottomSheetDialog?.ownHide() { + this?.hide() + } + + fun BottomSheetDialog?.ownShow() { + // the reason for this is because show has a shitty animation we don't want + this?.window?.setWindowAnimations(-1) + this?.show() + Handler(Looper.getMainLooper()).postDelayed({ + this?.window?.setWindowAnimations(R.style.Animation_Design_BottomSheetDialog) + },200) + } + //fun Context.deleteFavorite(data: SearchResponse) { // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return // normalSafeApiCall {