From 0f7745449eb408366b6f3f136ccb775cf916fe98 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Mon, 20 Sep 2021 23:11:36 +0200 Subject: [PATCH] moved to nav_view --- .../lagradost/cloudstream3/MainActivity.kt | 67 ++++++++- .../ui/download/DownloadButtonSetup.kt | 40 ++---- .../ui/download/DownloadChildFragment.kt | 11 +- .../cloudstream3/ui/home/HomeFragment.kt | 13 +- .../cloudstream3/ui/player/PlayerFragment.kt | 45 +++--- .../cloudstream3/ui/result/ResultFragment.kt | 62 ++++---- .../ui/settings/SettingsFragment.kt | 2 +- .../ui/subtitles/SubtitlesFragment.kt | 8 +- .../lagradost/cloudstream3/utils/AppUtils.kt | 6 +- .../lagradost/cloudstream3/utils/UIHelper.kt | 19 ++- .../main/res/navigation/mobile_navigation.xml | 133 +++++++++++++++++- 11 files changed, 302 insertions(+), 104 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 82a2786e..4354d555 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -5,6 +5,7 @@ import android.app.PictureInPictureParams import android.content.ComponentName import android.content.Context import android.content.Intent +import android.content.pm.ActivityInfo import android.content.pm.PackageManager import android.content.res.ColorStateList import android.content.res.Configuration @@ -12,14 +13,23 @@ import android.content.res.Resources import android.os.Build import android.os.Bundle import android.view.* +import android.view.View.GONE +import android.view.View.VISIBLE import android.widget.TextView import android.widget.Toast import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.view.isVisible +import androidx.core.view.marginBottom +import androidx.fragment.app.FragmentActivity import androidx.navigation.NavOptions import androidx.navigation.findNavController import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.setupWithNavController import androidx.preference.PreferenceManager +import androidx.transition.ChangeBounds +import androidx.transition.TransitionManager import com.google.android.gms.cast.framework.CastButtonFactory import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import com.lagradost.cloudstream3.APIHolder.apis @@ -43,6 +53,7 @@ import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.utils.UIHelper.getResourceColor import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission +import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.requestRW import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode import com.lagradost.cloudstream3.utils.UIHelper.toPx @@ -172,7 +183,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } private fun AppCompatActivity.backPressed(): Boolean { - val currentFragment = supportFragmentManager.fragments.last { + /*val currentFragment = supportFragmentManager.fragments.last { it.isVisible } @@ -200,8 +211,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { backEvent.invoke(true) return true } + */ backEvent.invoke(false) - return false } @@ -282,16 +293,60 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { val navController = findNavController(R.id.nav_host_fragment) - navOptions = NavOptions.Builder() + /*navOptions = NavOptions.Builder() .setLaunchSingleTop(true) .setEnterAnim(R.anim.nav_enter_anim) .setExitAnim(R.anim.nav_exit_anim) .setPopEnterAnim(R.anim.nav_pop_enter) .setPopExitAnim(R.anim.nav_pop_exit) .setPopUpTo(navController.graph.startDestination, false) - .build() + .build()*/ + nav_view.setupWithNavController(navController) - nav_view.setOnNavigationItemSelectedListener { item -> + var startUp = true + navController.addOnDestinationChangedListener { _, destination, _ -> + // nav_view.hideKeyboard() + /*if (destination.id != R.id.navigation_player) { + requestedOrientation = if (settingsManager?.getBoolean("force_landscape", false) == true) { + ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + } else { + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } + }*/ + + // Fucks up anime info layout since that has its own layout + cast_mini_controller_holder?.isVisible = destination.id != R.id.navigation_results + + if (listOf( + R.id.navigation_home, + R.id.navigation_search, + R.id.navigation_downloads, + R.id.navigation_settings, + R.id.navigation_download_child + ).contains(destination.id) + ) { + nav_view.visibility = VISIBLE + if (nav_view.marginBottom < 0) { + nav_view.layoutParams = nav_view.layoutParams.apply { + val transition = ChangeBounds() + transition.duration = 100 // DURATION OF ANIMATION IN MS + TransitionManager.beginDelayedTransition(homeRoot, transition) + (this as ConstraintLayout.LayoutParams).setMargins(0, 0, 0, 0) + } + } + } else { + if (startUp) nav_view.visibility = GONE + nav_view.layoutParams = nav_view.layoutParams.apply { + val transition = ChangeBounds() + transition.duration = 100 // DURATION OF ANIMATION IN MS + TransitionManager.beginDelayedTransition(homeRoot, transition) + (this as ConstraintLayout.LayoutParams).setMargins(0, 0, 0, -nav_view.height) + } + } + startUp = false + } + + /*nav_view.setOnNavigationItemSelectedListener { item -> when (item.itemId) { R.id.navigation_home -> { navController.navigate(R.id.navigation_home, null, navOptions) @@ -307,7 +362,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } } true - } + }*/ nav_view.itemRippleColor = ColorStateList.valueOf(getResourceColor(R.attr.colorPrimary, 0.1f)) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index 6ff526e9..9c694e68 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -4,7 +4,6 @@ import android.app.Activity import android.content.DialogInterface import android.widget.Toast import androidx.appcompat.app.AlertDialog -import androidx.fragment.app.FragmentActivity import com.lagradost.cloudstream3.MainActivity import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.ui.player.PlayerFragment @@ -12,6 +11,7 @@ import com.lagradost.cloudstream3.ui.player.UriData import com.lagradost.cloudstream3.utils.AppUtils.getNameFull import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos +import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.cloudstream3.utils.VideoDownloadManager @@ -85,30 +85,20 @@ object DownloadButtonSetup { VideoDownloadManager.KEY_DOWNLOAD_INFO, click.data.id.toString() ) ?: return - (act as FragmentActivity).supportFragmentManager.beginTransaction() - .setCustomAnimations( - R.anim.enter_anim, - R.anim.exit_anim, - R.anim.pop_enter, - R.anim.pop_exit - ) - .add( - R.id.homeRoot, - PlayerFragment.newInstance( - UriData( - info.path.toString(), - keyInfo.relativePath, - keyInfo.displayName, - click.data.parentId, - click.data.id, - headerName ?: "null", - if (click.data.episode <= 0) null else click.data.episode, - click.data.season - ), - act.getViewPos(click.data.id)?.position ?: 0 - ) - ) - .commit() + + act.navigate(R.id.global_to_navigation_player, PlayerFragment.newInstance( + UriData( + info.path.toString(), + keyInfo.relativePath, + keyInfo.displayName, + click.data.parentId, + click.data.id, + headerName ?: "null", + if (click.data.episode <= 0) null else click.data.episode, + click.data.season + ), + act.getViewPos(click.data.id)?.position ?: 0 + )) } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt index 8f972314..c2bb4c9a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt @@ -21,13 +21,12 @@ import kotlinx.coroutines.withContext class DownloadChildFragment : Fragment() { companion object { - fun newInstance(headerName: String, folder: String) = - DownloadChildFragment().apply { - arguments = Bundle().apply { - putString("folder", folder) - putString("name", headerName) - } + fun newInstance(headerName: String, folder: String) : Bundle { + return Bundle().apply { + putString("folder", folder) + putString("name", headerName) } + } } override fun onDestroyView() { 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 265fd961..88f8d664 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 @@ -13,6 +13,7 @@ import android.widget.FrameLayout import android.widget.TextView import androidx.core.view.isVisible import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -92,15 +93,15 @@ class HomeFragment : Fragment() { } } - private lateinit var homeViewModel: HomeViewModel + private val homeViewModel: HomeViewModel by activityViewModels() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - homeViewModel = - ViewModelProvider(this).get(HomeViewModel::class.java) + // homeViewModel = + // ViewModelProvider(activity ?: this).get(HomeViewModel::class.java) return inflater.inflate(R.layout.fragment_home, container, false) } @@ -406,6 +407,10 @@ class HomeFragment : Fragment() { home_master_recycler.layoutManager = GridLayoutManager(context, 1) reloadStored() - homeViewModel.loadAndCancel(context?.getKey(HOMEPAGE_API)) + val apiName = context?.getKey(HOMEPAGE_API) + if(homeViewModel.apiName.value != apiName) { + println("COUGHT HOME : " + homeViewModel.apiName.value + " AT " + apiName) + homeViewModel.loadAndCancel(apiName) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index 7eff9329..47039465 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -169,6 +169,7 @@ class PlayerFragment : Fragment() { // ============ TORRENT ============ //private var torrentStream: TorrentStream? = null private var lastTorrentUrl = "" + //private val isTorrent: Boolean get() = torrentStream != null private fun initTorrentStream(torrentUrl: String) { if (lastTorrentUrl == torrentUrl) return @@ -751,29 +752,27 @@ class PlayerFragment : Fragment() { private var volumeObserver: SettingsContentObserver? = null companion object { - fun newInstance(data: PlayerData, startPos: Long? = null) = - PlayerFragment().apply { - arguments = Bundle().apply { - //println(data) - putString("data", mapper.writeValueAsString(data)) - println("PUT START: " + startPos) - if (startPos != null) { - putLong(STATE_RESUME_POSITION, startPos) - } + fun newInstance(data: PlayerData, startPos: Long? = null): Bundle { + return Bundle().apply { + //println(data) + putString("data", mapper.writeValueAsString(data)) + println("PUT START: " + startPos) + if (startPos != null) { + putLong(STATE_RESUME_POSITION, startPos) } } + } - fun newInstance(uriData: UriData, startPos: Long? = null) = - PlayerFragment().apply { - arguments = Bundle().apply { - //println(data) - putString("uriData", mapper.writeValueAsString(uriData)) + fun newInstance(uriData: UriData, startPos: Long? = null): Bundle { + return Bundle().apply { + //println(data) + putString("uriData", mapper.writeValueAsString(uriData)) - if (startPos != null) { - putLong(STATE_RESUME_POSITION, startPos) - } + if (startPos != null) { + putLong(STATE_RESUME_POSITION, startPos) } } + } } private fun savePos() { @@ -1662,8 +1661,8 @@ class PlayerFragment : Fragment() { savePos() SubtitlesFragment.applyStyleEvent -= ::onSubStyleChanged - // torrentStream?.stopStream() - // torrentStream = null + // torrentStream?.stopStream() + // torrentStream = null super.onDestroy() canEnterPipMode = false @@ -1680,7 +1679,7 @@ class PlayerFragment : Fragment() { override fun onPause() { savePos() super.onPause() - // torrentStream?.currentTorrent?.pause() + // torrentStream?.currentTorrent?.pause() if (Util.SDK_INT <= 23) { if (player_view != null) player_view.onPause() releasePlayer() @@ -1987,12 +1986,12 @@ class PlayerFragment : Fragment() { video_title_rez?.text = if (height == null || width == null) currentUrl?.name ?: "" else - // if (isTorrent) "${width}x${height}" else - if (isDownloadedFile || currentUrl?.name == null) "${width}x${height}" else "${currentUrl.name} - ${width}x${height}" + // if (isTorrent) "${width}x${height}" else + if (isDownloadedFile || currentUrl?.name == null) "${width}x${height}" else "${currentUrl.name} - ${width}x${height}" if (!hasUsedFirstRender) { // DON'T WANT TO SET MULTIPLE MESSAGES //&& !isTorrent - if (!isDownloadedFile && exoPlayer.duration in 5_000..10_000) { + if (!isDownloadedFile && exoPlayer.duration in 5_000..10_000) { // if(getapi apiName ) showToast(activity, R.string.vpn_might_be_needed, LENGTH_SHORT) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index 58465521..d91fafd2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -62,6 +62,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard +import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes @@ -152,15 +153,15 @@ fun ResultEpisode.getWatchProgress(): Float { class ResultFragment : Fragment() { companion object { - fun newInstance(url: String, apiName: String, startAction: Int = 0, startValue: Int = 0) = - ResultFragment().apply { - arguments = Bundle().apply { - putString("url", url) - putString("apiName", apiName) - putInt("startAction", startAction) - putInt("startValue", startValue) - } + fun newInstance(url: String, apiName: String, startAction: Int = 0, startValue: Int = 0): Bundle { + return Bundle().apply { + putString("url", url) + putString("apiName", apiName) + putInt("startAction", startAction) + putInt("startValue", startValue) + putBoolean("restart", true) } + } } private var currentLoadingCount = 0 // THIS IS USED TO PREVENT LATE EVENTS, AFTER DISMISS WAS CLICKED @@ -262,6 +263,11 @@ class ResultFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val restart = arguments?.getBoolean("restart") ?: false + if (restart) { + arguments?.putBoolean("restart", false) + } + activity?.window?.decorView?.clearFocus() hideKeyboard() @@ -284,6 +290,7 @@ class ResultFragment : Fragment() { startAction = arguments?.getInt("startAction") ?: START_ACTION_NORMAL startValue = arguments?.getInt("startValue") ?: START_VALUE_NORMAL + val api = getApiFromName(apiName) if (media_route_button != null) { val chromecastSupport = api.hasChromecastSupport @@ -701,19 +708,12 @@ class ResultFragment : Fragment() { ACTION_PLAY_EPISODE_IN_PLAYER -> { if (buildInPlayer) { - (activity as AppCompatActivity?)?.supportFragmentManager?.beginTransaction() - ?.setCustomAnimations( - R.anim.enter_anim, - R.anim.exit_anim, - R.anim.pop_enter, - R.anim.pop_exit - )?.add( - R.id.homeRoot, - PlayerFragment.newInstance( - PlayerData(index, null, 0), - episodeClick.data.getRealPosition() - ) - )?.commit() + activity.navigate( + R.id.global_to_navigation_player, PlayerFragment.newInstance( + PlayerData(index, null, 0), + episodeClick.data.getRealPosition() + ) + ) } } @@ -827,13 +827,16 @@ class ResultFragment : Fragment() { observe(viewModel.publicEpisodes) { episodes -> when (episodes) { is Resource.Failure -> { - result_episode_loading.isVisible = false + result_episode_loading?.isVisible = false + //result_episodes?.isVisible = false } is Resource.Loading -> { - result_episode_loading.isVisible = true + result_episode_loading?.isVisible = true + // result_episodes?.isVisible = false } is Resource.Success -> { - result_episode_loading.isVisible = false + //result_episodes?.isVisible = true + result_episode_loading?.isVisible = false if (result_episodes == null || result_episodes.adapter == null) return@observe currentEpisodes = episodes.value (result_episodes?.adapter as EpisodeAdapter?)?.cardList = episodes.value @@ -862,8 +865,13 @@ class ResultFragment : Fragment() { } observe(viewModel.publicEpisodesCount) { count -> - result_episodes_text.text = - "$count ${if (count == 1) getString(R.string.episode) else getString(R.string.episodes)}" + if (count < 0) { + result_episodes_text?.isVisible = false + } else { + // result_episodes_text?.isVisible = true + result_episodes_text?.text = + "$count ${if (count == 1) getString(R.string.episode) else getString(R.string.episodes)}" + } } observe(viewModel.id) { @@ -1117,7 +1125,7 @@ class ResultFragment : Fragment() { } } - if (viewModel.resultResponse.value == null) { + if (restart || viewModel.resultResponse.value == null) { viewModel.load(ctx, tempUrl, apiName, showFillers) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 8f1cc06c..5751a70d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -28,7 +28,7 @@ class SettingsFragment : PreferenceFragmentCompat() { // idk, if you find a way of automating this it would be great private val languages = arrayListOf( - Triple("\uD83C\uDDEC\uD83C\uDDE7", "Spanish", "es"), + Triple("\uD83C\uDDEA\uD83C\uDDF8", "Spanish", "es"), Triple("\uD83C\uDDEC\uD83C\uDDE7", "English", "en"), Triple("\uD83C\uDDFB\uD83C\uDDF3", "Viet Nam", "vi"), Triple("\uD83C\uDDF3\uD83C\uDDF1", "Dutch", "nl"), diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt index 691623c6..8b884966 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt @@ -32,6 +32,7 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog import com.lagradost.cloudstream3.utils.SubtitleHelper import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.hideSystemUI +import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage import kotlinx.android.synthetic.main.subtitle_settings.* @@ -67,7 +68,10 @@ class SubtitlesFragment : Fragment() { } fun push(activity: Activity?, hide: Boolean = true) { - (activity as FragmentActivity?)?.supportFragmentManager?.beginTransaction() + activity.navigate(R.id.global_to_navigation_subtitles, Bundle().apply { + putBoolean("hide", hide) + }) + /*(activity as FragmentActivity?)?.supportFragmentManager?.beginTransaction() ?.setCustomAnimations( R.anim.enter_anim, R.anim.exit_anim, @@ -82,7 +86,7 @@ class SubtitlesFragment : Fragment() { } } ) - ?.commit() + ?.commit()*/ } private fun getDefColor(id: Int): Int { 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 a41032d6..03089644 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -21,6 +21,7 @@ import com.google.android.gms.common.wrappers.Wrappers import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.ui.result.ResultFragment +import com.lagradost.cloudstream3.utils.UIHelper.navigate object AppUtils { fun getVideoContentUri(context: Context, videoFilePath: String): Uri? { @@ -77,10 +78,7 @@ object AppUtils { fun AppCompatActivity.loadResult(url: String, apiName: String, startAction: Int = 0, startValue: Int = 0) { this.runOnUiThread { viewModelStore.clear() - this.supportFragmentManager.beginTransaction() - .setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.pop_enter, R.anim.pop_exit) - .add(R.id.homeRoot, ResultFragment.newInstance(url, apiName, startAction, startValue)) - .commit() + this.navigate(R.id.global_to_navigation_results, ResultFragment.newInstance(url, apiName, startAction, startValue)) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt index 48bab7f2..b314f29b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -9,15 +9,14 @@ import android.content.pm.PackageManager import android.content.res.Resources import android.graphics.Color import android.os.Build +import android.os.Bundle import android.view.Gravity import android.view.MenuItem import android.view.View import android.view.WindowManager import android.view.inputmethod.InputMethodManager import android.widget.ImageView -import androidx.annotation.AttrRes -import androidx.annotation.ColorInt -import androidx.annotation.RequiresApi +import androidx.annotation.* import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu @@ -29,6 +28,7 @@ import androidx.core.graphics.green import androidx.core.graphics.red import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity +import androidx.navigation.fragment.NavHostFragment import androidx.preference.PreferenceManager import com.bumptech.glide.Glide import com.bumptech.glide.load.model.GlideUrl @@ -71,6 +71,14 @@ object UIHelper { } } + fun Activity?.navigate(@IdRes navigation : Int, arguments : Bundle? = null) { + if(this is FragmentActivity) { + (supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment?)?.navController?.navigate( + navigation, arguments + ) + } + } + @ColorInt fun Context.getResourceColor(@AttrRes resource: Int, alphaFactor: Float = 1f): Int { val typedArray = obtainStyledAttributes(intArrayOf(resource)) @@ -131,7 +139,8 @@ object UIHelper { } fun FragmentActivity.popCurrentPage() { - val currentFragment = supportFragmentManager.fragments.lastOrNull { + this.onBackPressed() + /*val currentFragment = supportFragmentManager.fragments.lastOrNull { it.isVisible } ?: return @@ -143,7 +152,7 @@ object UIHelper { R.anim.pop_exit ) .remove(currentFragment) - .commitAllowingStateLoss() + .commitAllowingStateLoss()*/ } /* fun FragmentActivity.popCurrentPage(isInPlayer: Boolean, isInExpandedView: Boolean, isInResults: Boolean) { diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 96fb6a82..f3dd961c 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -5,6 +5,109 @@ android:id="@+id/mobile_navigation" app:startDestination="@+id/navigation_home"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tools:layout="@layout/fragment_downloads"> + + + + + + + + + + + + \ No newline at end of file