moved to nav_view

This commit is contained in:
LagradOst 2021-09-20 23:11:36 +02:00
parent 58b131ec49
commit 0f7745449e
11 changed files with 302 additions and 104 deletions

View file

@ -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))

View file

@ -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,16 +85,8 @@ 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(
act.navigate(R.id.global_to_navigation_player, PlayerFragment.newInstance(
UriData(
info.path.toString(),
keyInfo.relativePath,
@ -106,9 +98,7 @@ object DownloadButtonSetup {
click.data.season
),
act.getViewPos(click.data.id)?.position ?: 0
)
)
.commit()
))
}
}
}

View file

@ -21,9 +21,8 @@ import kotlinx.coroutines.withContext
class DownloadChildFragment : Fragment() {
companion object {
fun newInstance(headerName: String, folder: String) =
DownloadChildFragment().apply {
arguments = Bundle().apply {
fun newInstance(headerName: String, folder: String) : Bundle {
return Bundle().apply {
putString("folder", folder)
putString("name", headerName)
}

View file

@ -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<String>(HOMEPAGE_API))
val apiName = context?.getKey<String>(HOMEPAGE_API)
if(homeViewModel.apiName.value != apiName) {
println("COUGHT HOME : " + homeViewModel.apiName.value + " AT " + apiName)
homeViewModel.loadAndCancel(apiName)
}
}
}

View file

@ -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,9 +752,8 @@ class PlayerFragment : Fragment() {
private var volumeObserver: SettingsContentObserver? = null
companion object {
fun newInstance(data: PlayerData, startPos: Long? = null) =
PlayerFragment().apply {
arguments = Bundle().apply {
fun newInstance(data: PlayerData, startPos: Long? = null): Bundle {
return Bundle().apply {
//println(data)
putString("data", mapper.writeValueAsString(data))
println("PUT START: " + startPos)
@ -763,9 +763,8 @@ class PlayerFragment : Fragment() {
}
}
fun newInstance(uriData: UriData, startPos: Long? = null) =
PlayerFragment().apply {
arguments = Bundle().apply {
fun newInstance(uriData: UriData, startPos: Long? = null): Bundle {
return Bundle().apply {
//println(data)
putString("uriData", mapper.writeValueAsString(uriData))

View file

@ -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,13 +153,13 @@ 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 {
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)
}
}
}
@ -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(
activity.navigate(
R.id.global_to_navigation_player, PlayerFragment.newInstance(
PlayerData(index, null, 0),
episodeClick.data.getRealPosition()
)
)?.commit()
)
}
}
@ -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,9 +865,14 @@ class ResultFragment : Fragment() {
}
observe(viewModel.publicEpisodesCount) { count ->
result_episodes_text.text =
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) {
currentId = it
@ -1117,7 +1125,7 @@ class ResultFragment : Fragment() {
}
}
if (viewModel.resultResponse.value == null) {
if (restart || viewModel.resultResponse.value == null) {
viewModel.load(ctx, tempUrl, apiName, showFillers)
}
}

View file

@ -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"),

View file

@ -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 {

View file

@ -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))
}
}

View file

@ -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) {

View file

@ -5,6 +5,109 @@
android:id="@+id/mobile_navigation"
app:startDestination="@+id/navigation_home">
<action android:id="@+id/global_to_navigation_results"
app:destination="@id/navigation_results"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim"
>
<argument
android:name="url"
app:argType="string"/>
<argument
android:name="apiName"
app:argType="string"
/>
<argument
android:name="startAction"
app:argType="integer"
android:defaultValue="0"
/>
<argument
android:name="startValue"
app:argType="integer"
android:defaultValue="0"
/>
<argument
android:name="restart"
app:argType="boolean"
android:defaultValue="false"
/>
</action>
<action android:id="@+id/global_to_navigation_player"
app:destination="@id/navigation_player"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim"
>
<argument
android:name="data"
app:argType="string"
android:defaultValue="@null"
/>
<argument
android:name="uriData"
app:argType="string"
android:defaultValue="@null"
/>
<argument
android:name="resumePosition"
app:argType="long"
android:defaultValue="0L"
/>
</action>
<action android:id="@+id/global_to_navigation_home"
app:destination="@id/navigation_home"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim"
>
</action>
<action android:id="@+id/global_to_navigation_subtitles"
app:destination="@id/navigation_subtitles"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim">
<argument
android:name="hide"
app:argType="boolean"
android:defaultValue="true"
/>
</action>
<action android:id="@+id/global_to_navigation_settings"
app:destination="@id/navigation_settings"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim"
>
</action>
<action android:id="@+id/global_to_navigation_downloads"
app:destination="@id/navigation_downloads"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim"
>
</action>
<action android:id="@+id/global_to_navigation_search"
app:destination="@id/navigation_search"
app:enterAnim="@anim/enter_anim"
app:exitAnim="@anim/exit_anim"
app:popEnterAnim="@anim/enter_anim"
app:popExitAnim="@anim/exit_anim"
>
</action>
<fragment
android:id="@+id/navigation_home"
android:name="com.lagradost.cloudstream3.ui.home.HomeFragment"
@ -21,16 +124,44 @@
android:id="@+id/navigation_downloads"
android:name="com.lagradost.cloudstream3.ui.download.DownloadFragment"
android:label="@string/title_downloads"
tools:layout="@layout/fragment_downloads"/>
tools:layout="@layout/fragment_downloads">
<action android:id="@+id/action_navigation_downloads_to_navigation_download_child"
app:destination="@id/navigation_download_child">
<argument
android:name="name"
app:argType="string"/>
<argument
android:name="folder"
app:argType="string"
/>
</action>
</fragment>
<fragment
android:id="@+id/navigation_settings"
android:layout_height="match_parent"
android:name="com.lagradost.cloudstream3.ui.settings.SettingsFragment"
android:label="@string/title_settings"/>
<fragment
android:id="@+id/navigation_subtitles"
android:layout_height="match_parent"
android:name="com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment"
android:label="@string/subtitles_settings"/>
<fragment
android:id="@+id/navigation_download_child"
android:layout_height="match_parent"
android:name="com.lagradost.cloudstream3.ui.download.DownloadChildFragment"
android:label="@string/title_settings"/>
<fragment
android:id="@+id/navigation_results"
android:layout_height="match_parent"
android:name="com.lagradost.cloudstream3.ui.result.ResultFragment"/>
<fragment
android:id="@+id/navigation_player"
android:layout_height="match_parent"
android:name="com.lagradost.cloudstream3.ui.player.PlayerFragment"/>
</navigation>