mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
commit
e37773ed84
@ -17,6 +17,10 @@ android {
|
|||||||
resValue "string", "app_name", "LibreTube"
|
resValue "string", "app_name", "LibreTube"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildFeatures {
|
||||||
|
viewBinding true
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
|
@ -32,6 +32,7 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
|
import com.github.libretube.databinding.ActivityMainBinding
|
||||||
import com.github.libretube.fragments.PlayerFragment
|
import com.github.libretube.fragments.PlayerFragment
|
||||||
import com.github.libretube.fragments.isFullScreen
|
import com.github.libretube.fragments.isFullScreen
|
||||||
import com.github.libretube.services.ClosingService
|
import com.github.libretube.services.ClosingService
|
||||||
@ -46,7 +47,9 @@ import com.google.android.material.color.DynamicColors
|
|||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
val TAG = "MainActivity"
|
val TAG = "MainActivity"
|
||||||
|
|
||||||
lateinit var bottomNavigationView: BottomNavigationView
|
lateinit var binding: ActivityMainBinding
|
||||||
|
|
||||||
|
private lateinit var bottomNavigationView: BottomNavigationView
|
||||||
private lateinit var toolbar: Toolbar
|
private lateinit var toolbar: Toolbar
|
||||||
lateinit var navController: NavController
|
lateinit var navController: NavController
|
||||||
|
|
||||||
@ -76,12 +79,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setContentView(R.layout.activity_main)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
|
|
||||||
bottomNavigationView = findViewById(R.id.bottomNav)
|
|
||||||
navController = findNavController(R.id.fragment)
|
navController = findNavController(R.id.fragment)
|
||||||
bottomNavigationView.setupWithNavController(navController)
|
binding.bottomNav.setupWithNavController(navController)
|
||||||
|
|
||||||
// hide the trending page if enabled
|
// hide the trending page if enabled
|
||||||
val hideTrendingPage = PreferenceHelper.getBoolean(this, "hide_trending_page", false)
|
val hideTrendingPage = PreferenceHelper.getBoolean(this, "hide_trending_page", false)
|
||||||
@ -94,7 +97,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"library" -> navController.navigate(R.id.library)
|
"library" -> navController.navigate(R.id.library)
|
||||||
}
|
}
|
||||||
|
|
||||||
bottomNavigationView.setOnItemSelectedListener {
|
binding.bottomNav.setOnItemSelectedListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.home2 -> {
|
R.id.home2 -> {
|
||||||
navController.backQueue.clear()
|
navController.backQueue.clear()
|
||||||
@ -112,7 +115,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbar = findViewById(R.id.toolbar)
|
|
||||||
val typedValue = TypedValue()
|
val typedValue = TypedValue()
|
||||||
this.theme.resolveAttribute(R.attr.colorPrimary, typedValue, true)
|
this.theme.resolveAttribute(R.attr.colorPrimary, typedValue, true)
|
||||||
val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data))
|
val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data))
|
||||||
@ -120,15 +122,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"Libre<span style='color:$hexColor';>Tube</span>",
|
"Libre<span style='color:$hexColor';>Tube</span>",
|
||||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
HtmlCompat.FROM_HTML_MODE_COMPACT
|
||||||
)
|
)
|
||||||
toolbar.title = appName
|
binding.toolbar.title = appName
|
||||||
|
|
||||||
toolbar.setNavigationOnClickListener {
|
binding.toolbar.setNavigationOnClickListener {
|
||||||
// settings activity stuff
|
// settings activity stuff
|
||||||
val intent = Intent(this, SettingsActivity::class.java)
|
val intent = Intent(this, SettingsActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbar.setOnMenuItemClickListener {
|
binding.toolbar.setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.action_search -> {
|
R.id.action_search -> {
|
||||||
navController.navigate(R.id.searchFragment)
|
navController.navigate(R.id.searchFragment)
|
||||||
@ -267,7 +269,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
try {
|
try {
|
||||||
val mainMotionLayout = findViewById<MotionLayout>(R.id.mainMotionLayout)
|
val mainMotionLayout = binding.mainMotionLayout
|
||||||
if (mainMotionLayout.progress == 0.toFloat()) {
|
if (mainMotionLayout.progress == 0.toFloat()) {
|
||||||
mainMotionLayout.transitionToEnd()
|
mainMotionLayout.transitionToEnd()
|
||||||
findViewById<ConstraintLayout>(R.id.main_container).isClickable = false
|
findViewById<ConstraintLayout>(R.id.main_container).isClickable = false
|
||||||
|
@ -22,14 +22,10 @@ import android.view.ViewGroup
|
|||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.RelativeLayout
|
|
||||||
import android.widget.ScrollView
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
@ -37,12 +33,12 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import com.github.libretube.MainActivity
|
import com.github.libretube.MainActivity
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.adapters.ChaptersAdapter
|
import com.github.libretube.adapters.ChaptersAdapter
|
||||||
import com.github.libretube.adapters.CommentsAdapter
|
import com.github.libretube.adapters.CommentsAdapter
|
||||||
import com.github.libretube.adapters.TrendingAdapter
|
import com.github.libretube.adapters.TrendingAdapter
|
||||||
|
import com.github.libretube.databinding.FragmentPlayerBinding
|
||||||
import com.github.libretube.dialogs.AddtoPlaylistDialog
|
import com.github.libretube.dialogs.AddtoPlaylistDialog
|
||||||
import com.github.libretube.dialogs.DownloadDialog
|
import com.github.libretube.dialogs.DownloadDialog
|
||||||
import com.github.libretube.dialogs.ShareDialog
|
import com.github.libretube.dialogs.ShareDialog
|
||||||
@ -102,6 +98,8 @@ var isMiniPlayerVisible = false
|
|||||||
class PlayerFragment : Fragment() {
|
class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
private val TAG = "PlayerFragment"
|
private val TAG = "PlayerFragment"
|
||||||
|
private lateinit var binding: FragmentPlayerBinding
|
||||||
|
|
||||||
private var videoId: String? = null
|
private var videoId: String? = null
|
||||||
private var playlistId: String? = null
|
private var playlistId: String? = null
|
||||||
private var sId: Int = 0
|
private var sId: Int = 0
|
||||||
@ -114,14 +112,11 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
private var isSubscribed: Boolean = false
|
private var isSubscribed: Boolean = false
|
||||||
|
|
||||||
private lateinit var relatedRecView: RecyclerView
|
|
||||||
private lateinit var commentsRecView: RecyclerView
|
|
||||||
private var commentsAdapter: CommentsAdapter? = null
|
private var commentsAdapter: CommentsAdapter? = null
|
||||||
private var commentsLoaded: Boolean? = false
|
private var commentsLoaded: Boolean? = false
|
||||||
private var nextPage: String? = null
|
private var nextPage: String? = null
|
||||||
private var isLoading = true
|
private var isLoading = true
|
||||||
private lateinit var exoPlayerView: StyledPlayerView
|
private lateinit var exoPlayerView: StyledPlayerView
|
||||||
private lateinit var motionLayout: MotionLayout
|
|
||||||
private lateinit var exoPlayer: ExoPlayer
|
private lateinit var exoPlayer: ExoPlayer
|
||||||
private lateinit var segmentData: Segments
|
private lateinit var segmentData: Segments
|
||||||
private var relatedStreamsEnabled = true
|
private var relatedStreamsEnabled = true
|
||||||
@ -133,8 +128,6 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
private var isPlayerLocked: Boolean = false
|
private var isPlayerLocked: Boolean = false
|
||||||
|
|
||||||
private lateinit var relDownloadVideo: LinearLayout
|
|
||||||
|
|
||||||
private lateinit var mediaSession: MediaSessionCompat
|
private lateinit var mediaSession: MediaSessionCompat
|
||||||
private lateinit var mediaSessionConnector: MediaSessionConnector
|
private lateinit var mediaSessionConnector: MediaSessionConnector
|
||||||
private lateinit var playerNotification: PlayerNotificationManager
|
private lateinit var playerNotification: PlayerNotificationManager
|
||||||
@ -156,9 +149,10 @@ class PlayerFragment : Fragment() {
|
|||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View {
|
||||||
|
binding = FragmentPlayerBinding.inflate(layoutInflater, container, false)
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
return inflater.inflate(R.layout.fragment_player, container, false)
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
@ -172,17 +166,14 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeTransitionLayout(view: View) {
|
private fun initializeTransitionLayout(view: View) {
|
||||||
val playerDescription = view.findViewById<TextView>(R.id.player_description)
|
|
||||||
videoId = videoId!!.replace("/watch?v=", "")
|
videoId = videoId!!.replace("/watch?v=", "")
|
||||||
relDownloadVideo = view.findViewById(R.id.relPlayer_download)
|
|
||||||
val mainActivity = activity as MainActivity
|
|
||||||
mainActivity.findViewById<FrameLayout>(R.id.container).visibility = View.VISIBLE
|
|
||||||
val playerMotionLayout = view.findViewById<MotionLayout>(R.id.playerMotionLayout)
|
|
||||||
motionLayout = playerMotionLayout
|
|
||||||
exoPlayerView = view.findViewById(R.id.player)
|
|
||||||
|
|
||||||
view.findViewById<TextView>(R.id.player_description).text = videoId
|
val mainActivity = activity as MainActivity
|
||||||
playerMotionLayout.addTransitionListener(object : MotionLayout.TransitionListener {
|
mainActivity.binding.container.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
exoPlayerView = binding.player
|
||||||
|
|
||||||
|
binding.playerMotionLayout.addTransitionListener(object : MotionLayout.TransitionListener {
|
||||||
override fun onTransitionStarted(
|
override fun onTransitionStarted(
|
||||||
motionLayout: MotionLayout?,
|
motionLayout: MotionLayout?,
|
||||||
startId: Int,
|
startId: Int,
|
||||||
@ -198,7 +189,7 @@ class PlayerFragment : Fragment() {
|
|||||||
) {
|
) {
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
val mainMotionLayout =
|
val mainMotionLayout =
|
||||||
mainActivity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
mainActivity.binding.mainMotionLayout
|
||||||
mainMotionLayout.progress = abs(progress)
|
mainMotionLayout.progress = abs(progress)
|
||||||
exoPlayerView.hideController()
|
exoPlayerView.hideController()
|
||||||
eId = endId
|
eId = endId
|
||||||
@ -209,7 +200,7 @@ class PlayerFragment : Fragment() {
|
|||||||
println(currentId)
|
println(currentId)
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
val mainMotionLayout =
|
val mainMotionLayout =
|
||||||
mainActivity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
mainActivity.binding.mainMotionLayout
|
||||||
if (currentId == eId) {
|
if (currentId == eId) {
|
||||||
isMiniPlayerVisible = true
|
isMiniPlayerVisible = true
|
||||||
exoPlayerView.useController = false
|
exoPlayerView.useController = false
|
||||||
@ -222,7 +213,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTransitionTrigger(
|
override fun onTransitionTrigger(
|
||||||
motionLayout: MotionLayout?,
|
MotionLayout: MotionLayout?,
|
||||||
triggerId: Int,
|
triggerId: Int,
|
||||||
positive: Boolean,
|
positive: Boolean,
|
||||||
progress: Float
|
progress: Float
|
||||||
@ -230,12 +221,12 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
playerMotionLayout.progress = 1.toFloat()
|
binding.playerMotionLayout.progress = 1.toFloat()
|
||||||
playerMotionLayout.transitionToStart()
|
binding.playerMotionLayout.transitionToStart()
|
||||||
|
|
||||||
view.findViewById<ImageView>(R.id.close_imageView).setOnClickListener {
|
binding.closeImageView.setOnClickListener {
|
||||||
isMiniPlayerVisible = false
|
isMiniPlayerVisible = false
|
||||||
motionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
mainActivity.supportFragmentManager.beginTransaction()
|
mainActivity.supportFragmentManager.beginTransaction()
|
||||||
@ -244,32 +235,30 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
|
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
|
||||||
isMiniPlayerVisible = false
|
isMiniPlayerVisible = false
|
||||||
motionLayout.transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
mainActivity.supportFragmentManager.beginTransaction()
|
mainActivity.supportFragmentManager.beginTransaction()
|
||||||
.remove(this)
|
.remove(this)
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
val playImageView = view.findViewById<ImageView>(R.id.play_imageView)
|
binding.playImageView.setOnClickListener {
|
||||||
playImageView.setOnClickListener {
|
|
||||||
paused = if (paused) {
|
paused = if (paused) {
|
||||||
playImageView.setImageResource(R.drawable.ic_pause)
|
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
||||||
exoPlayer.play()
|
exoPlayer.play()
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
playImageView.setImageResource(R.drawable.ic_play)
|
binding.playImageView.setImageResource(R.drawable.ic_play)
|
||||||
exoPlayer.pause()
|
exoPlayer.pause()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// video description and chapters toggle
|
// video description and chapters toggle
|
||||||
val descLinLayout = view.findViewById<LinearLayout>(R.id.desc_linLayout)
|
binding.playerTitleLayout.setOnClickListener {
|
||||||
view.findViewById<RelativeLayout>(R.id.player_title_layout).setOnClickListener {
|
binding.playerDescriptionArrow.animate().rotationBy(180F).setDuration(250).start()
|
||||||
val arrowImageView = view.findViewById<ImageView>(R.id.player_description_arrow)
|
binding.descLinLayout.visibility =
|
||||||
arrowImageView.animate().rotationBy(180F).setDuration(250).start()
|
if (binding.descLinLayout.isVisible) View.GONE else View.VISIBLE
|
||||||
descLinLayout.visibility = if (descLinLayout.isVisible) View.GONE else View.VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view.findViewById<MaterialCardView>(R.id.comments_toggle)
|
view.findViewById<MaterialCardView>(R.id.comments_toggle)
|
||||||
@ -279,33 +268,31 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
val fullScreenButton = view.findViewById<ImageButton>(R.id.fullscreen)
|
val fullScreenButton = view.findViewById<ImageButton>(R.id.fullscreen)
|
||||||
val exoTitle = view.findViewById<TextView>(R.id.exo_title)
|
val exoTitle = view.findViewById<TextView>(R.id.exo_title)
|
||||||
val mainContainer = view.findViewById<ConstraintLayout>(R.id.main_container)
|
|
||||||
val linLayout = view.findViewById<LinearLayout>(R.id.linLayout)
|
|
||||||
|
|
||||||
// FullScreen button trigger
|
// FullScreen button trigger
|
||||||
fullScreenButton.setOnClickListener {
|
fullScreenButton.setOnClickListener {
|
||||||
exoPlayerView.hideController()
|
exoPlayerView.hideController()
|
||||||
if (!isFullScreen) {
|
if (!isFullScreen) {
|
||||||
with(motionLayout) {
|
with(binding.playerMotionLayout) {
|
||||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
|
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
|
||||||
enableTransition(R.id.yt_transition, false)
|
enableTransition(R.id.yt_transition, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
mainContainer.isClickable = true
|
binding.mainContainer.isClickable = true
|
||||||
linLayout.visibility = View.GONE
|
binding.linLayout.visibility = View.GONE
|
||||||
fullScreenButton.setImageResource(R.drawable.ic_fullscreen_exit)
|
fullScreenButton.setImageResource(R.drawable.ic_fullscreen_exit)
|
||||||
exoTitle.visibility = View.VISIBLE
|
exoTitle.visibility = View.VISIBLE
|
||||||
|
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
} else {
|
} else {
|
||||||
with(motionLayout) {
|
with(binding.playerMotionLayout) {
|
||||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
||||||
enableTransition(R.id.yt_transition, true)
|
enableTransition(R.id.yt_transition, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
mainContainer.isClickable = false
|
binding.mainContainer.isClickable = false
|
||||||
linLayout.visibility = View.VISIBLE
|
binding.linLayout.visibility = View.VISIBLE
|
||||||
fullScreenButton.setImageResource(R.drawable.ic_fullscreen)
|
fullScreenButton.setImageResource(R.drawable.ic_fullscreen)
|
||||||
exoTitle.visibility = View.INVISIBLE
|
exoTitle.visibility = View.INVISIBLE
|
||||||
|
|
||||||
@ -343,32 +330,28 @@ class PlayerFragment : Fragment() {
|
|||||||
isPlayerLocked = !isPlayerLocked
|
isPlayerLocked = !isPlayerLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
val scrollView = view.findViewById<ScrollView>(R.id.player_scrollView)
|
binding.playerScrollView.viewTreeObserver
|
||||||
scrollView.viewTreeObserver
|
|
||||||
.addOnScrollChangedListener {
|
.addOnScrollChangedListener {
|
||||||
if (scrollView.getChildAt(0).bottom
|
if (binding.playerScrollView.getChildAt(0).bottom
|
||||||
== (scrollView.height + scrollView.scrollY) &&
|
== (binding.playerScrollView.height + binding.playerScrollView.scrollY) &&
|
||||||
nextPage != null
|
nextPage != null
|
||||||
) {
|
) {
|
||||||
fetchNextComments()
|
fetchNextComments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commentsRecView = view.findViewById(R.id.comments_recView)
|
binding.commentsRecView.layoutManager = LinearLayoutManager(view.context)
|
||||||
commentsRecView.layoutManager = LinearLayoutManager(view.context)
|
binding.commentsRecView.setItemViewCacheSize(20)
|
||||||
|
|
||||||
commentsRecView.setItemViewCacheSize(20)
|
binding.relatedRecView.layoutManager =
|
||||||
|
|
||||||
relatedRecView = view.findViewById(R.id.player_recView)
|
|
||||||
relatedRecView.layoutManager =
|
|
||||||
GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
|
GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleComments() {
|
private fun toggleComments() {
|
||||||
commentsRecView.visibility =
|
binding.commentsRecView.visibility =
|
||||||
if (commentsRecView.isVisible) View.GONE else View.VISIBLE
|
if (binding.commentsRecView.isVisible) View.GONE else View.VISIBLE
|
||||||
relatedRecView.visibility =
|
binding.relatedRecView.visibility =
|
||||||
if (relatedRecView.isVisible) View.GONE else View.VISIBLE
|
if (binding.relatedRecView.isVisible) View.GONE else View.VISIBLE
|
||||||
if (!commentsLoaded!!) fetchComments()
|
if (!commentsLoaded!!) fetchComments()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,18 +621,17 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializePlayerView(view: View, response: Streams) {
|
private fun initializePlayerView(view: View, response: Streams) {
|
||||||
view.findViewById<TextView>(R.id.player_views_info).text =
|
binding.playerViewsInfo.text =
|
||||||
context?.getString(R.string.views, response.views.formatShort()) +
|
context?.getString(R.string.views, response.views.formatShort()) +
|
||||||
" • " + response.uploadDate
|
" • " + response.uploadDate
|
||||||
view.findViewById<TextView>(R.id.textLike).text = response.likes.formatShort()
|
binding.textLike.text = response.likes.formatShort()
|
||||||
view.findViewById<TextView>(R.id.textDislike).text = response.dislikes.formatShort()
|
binding.textDislike.text = response.dislikes.formatShort()
|
||||||
val channelImage = view.findViewById<ImageView>(R.id.player_channelImage)
|
Picasso.get().load(response.uploaderAvatar).into(binding.playerChannelImage)
|
||||||
Picasso.get().load(response.uploaderAvatar).into(channelImage)
|
binding.playerChannelName.text = response.uploader
|
||||||
view.findViewById<TextView>(R.id.player_channelName).text = response.uploader
|
|
||||||
|
|
||||||
view.findViewById<TextView>(R.id.title_textView).text = response.title
|
binding.titleTextView.text = response.title
|
||||||
view.findViewById<TextView>(R.id.player_title).text = response.title
|
binding.playerTitle.text = response.title
|
||||||
view.findViewById<TextView>(R.id.player_description).text = response.description
|
binding.playerDescription.text = response.description
|
||||||
|
|
||||||
view.findViewById<TextView>(R.id.exo_title).text = response.title
|
view.findViewById<TextView>(R.id.exo_title).text = response.title
|
||||||
|
|
||||||
@ -690,31 +672,28 @@ class PlayerFragment : Fragment() {
|
|||||||
if (playWhenReady && playbackState == Player.STATE_READY) {
|
if (playWhenReady && playbackState == Player.STATE_READY) {
|
||||||
// media actually playing
|
// media actually playing
|
||||||
transitioning = false
|
transitioning = false
|
||||||
view.findViewById<ImageView>(R.id.play_imageView)
|
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
||||||
.setImageResource(R.drawable.ic_pause)
|
|
||||||
} else if (playWhenReady) {
|
} else if (playWhenReady) {
|
||||||
// might be idle (plays after prepare()),
|
// might be idle (plays after prepare()),
|
||||||
// buffering (plays when data available)
|
// buffering (plays when data available)
|
||||||
// or ended (plays when seek away from end)
|
// or ended (plays when seek away from end)
|
||||||
view.findViewById<ImageView>(R.id.play_imageView)
|
binding.playImageView.setImageResource(R.drawable.ic_play)
|
||||||
.setImageResource(R.drawable.ic_play)
|
|
||||||
} else {
|
} else {
|
||||||
// player paused in any state
|
// player paused in any state
|
||||||
view.findViewById<ImageView>(R.id.play_imageView)
|
binding.playImageView.setImageResource(R.drawable.ic_play)
|
||||||
.setImageResource(R.drawable.ic_play)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// share button
|
// share button
|
||||||
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
|
binding.relPlayerShare.setOnClickListener {
|
||||||
val shareDialog = ShareDialog(videoId!!, false)
|
val shareDialog = ShareDialog(videoId!!, false)
|
||||||
shareDialog.show(childFragmentManager, "ShareDialog")
|
shareDialog.show(childFragmentManager, "ShareDialog")
|
||||||
}
|
}
|
||||||
// check if livestream
|
// check if livestream
|
||||||
if (response.duration!! > 0) {
|
if (response.duration!! > 0) {
|
||||||
// download clicked
|
// download clicked
|
||||||
relDownloadVideo.setOnClickListener {
|
binding.relPlayerDownload.setOnClickListener {
|
||||||
if (!IS_DOWNLOAD_RUNNING) {
|
if (!IS_DOWNLOAD_RUNNING) {
|
||||||
val newFragment = DownloadDialog()
|
val newFragment = DownloadDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
@ -732,7 +711,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (response.hls != null) {
|
if (response.hls != null) {
|
||||||
view.findViewById<LinearLayout>(R.id.relPlayer_vlc).setOnClickListener {
|
binding.relPlayerVlc.setOnClickListener {
|
||||||
// start an intent with video as mimetype using the hls stream
|
// start an intent with video as mimetype using the hls stream
|
||||||
val uri: Uri = Uri.parse(response.hls)
|
val uri: Uri = Uri.parse(response.hls)
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
@ -749,14 +728,14 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
if (relatedStreamsEnabled) {
|
if (relatedStreamsEnabled) {
|
||||||
// only show related streams if enabled
|
// only show related streams if enabled
|
||||||
relatedRecView.adapter = TrendingAdapter(
|
binding.relatedRecView.adapter = TrendingAdapter(
|
||||||
response.relatedStreams!!,
|
response.relatedStreams!!,
|
||||||
childFragmentManager
|
childFragmentManager
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// set video description
|
// set video description
|
||||||
val description = response.description!!
|
val description = response.description!!
|
||||||
view.findViewById<TextView>(R.id.player_description).text =
|
binding.playerDescription.text =
|
||||||
// detect whether the description is html formatted
|
// detect whether the description is html formatted
|
||||||
if (description.contains("<") && description.contains(">")) {
|
if (description.contains("<") && description.contains(">")) {
|
||||||
if (SDK_INT >= Build.VERSION_CODES.N) {
|
if (SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
@ -769,19 +748,18 @@ class PlayerFragment : Fragment() {
|
|||||||
description
|
description
|
||||||
}
|
}
|
||||||
|
|
||||||
view.findViewById<RelativeLayout>(R.id.player_channel).setOnClickListener {
|
binding.playerChannel.setOnClickListener {
|
||||||
val activity = view.context as MainActivity
|
val activity = view.context as MainActivity
|
||||||
val bundle = bundleOf("channel_id" to response.uploaderUrl)
|
val bundle = bundleOf("channel_id" to response.uploaderUrl)
|
||||||
activity.navController.navigate(R.id.channel, bundle)
|
activity.navController.navigate(R.id.channel, bundle)
|
||||||
activity.findViewById<MotionLayout>(R.id.mainMotionLayout).transitionToEnd()
|
activity.binding.mainMotionLayout.transitionToEnd()
|
||||||
view.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
|
binding.playerMotionLayout.transitionToEnd()
|
||||||
}
|
}
|
||||||
val token = PreferenceHelper.getToken(requireContext())
|
val token = PreferenceHelper.getToken(requireContext())
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
||||||
val subButton = view.findViewById<MaterialButton>(R.id.player_subscribe)
|
isSubscribed(binding.playerSubscribe, channelId!!)
|
||||||
isSubscribed(subButton, channelId!!)
|
binding.save.setOnClickListener {
|
||||||
view.findViewById<LinearLayout>(R.id.save).setOnClickListener {
|
|
||||||
val newFragment = AddtoPlaylistDialog()
|
val newFragment = AddtoPlaylistDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString("videoId", videoId)
|
bundle.putString("videoId", videoId)
|
||||||
@ -792,13 +770,11 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeChapters(chapters: List<ChapterSegment>) {
|
private fun initializeChapters(chapters: List<ChapterSegment>) {
|
||||||
val chaptersRecView = view?.findViewById<RecyclerView>(R.id.chapters_recView)
|
|
||||||
|
|
||||||
if (chapters.isNotEmpty()) {
|
if (chapters.isNotEmpty()) {
|
||||||
chaptersRecView?.layoutManager =
|
binding.chaptersRecView.layoutManager =
|
||||||
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
|
||||||
chaptersRecView?.adapter = ChaptersAdapter(chapters, exoPlayer)
|
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
|
||||||
chaptersRecView?.visibility = View.VISIBLE
|
binding.chaptersRecView.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1143,7 +1119,7 @@ class PlayerFragment : Fragment() {
|
|||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
commentsAdapter = CommentsAdapter(videoId!!, commentsResponse.comments)
|
commentsAdapter = CommentsAdapter(videoId!!, commentsResponse.comments)
|
||||||
commentsRecView.adapter = commentsAdapter
|
binding.commentsRecView.adapter = commentsAdapter
|
||||||
nextPage = commentsResponse.nextpage
|
nextPage = commentsResponse.nextpage
|
||||||
commentsLoaded = true
|
commentsLoaded = true
|
||||||
isLoading = false
|
isLoading = false
|
||||||
@ -1176,35 +1152,34 @@ class PlayerFragment : Fragment() {
|
|||||||
if (isInPictureInPictureMode) {
|
if (isInPictureInPictureMode) {
|
||||||
exoPlayerView.hideController()
|
exoPlayerView.hideController()
|
||||||
exoPlayerView.useController = false
|
exoPlayerView.useController = false
|
||||||
with(motionLayout) {
|
with(binding.playerMotionLayout) {
|
||||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
|
getConstraintSet(R.id.start).constrainHeight(R.id.player, -1)
|
||||||
enableTransition(R.id.yt_transition, false)
|
enableTransition(R.id.yt_transition, false)
|
||||||
}
|
}
|
||||||
view?.findViewById<ConstraintLayout>(R.id.main_container)?.isClickable = true
|
binding.mainContainer.isClickable = true
|
||||||
view?.findViewById<LinearLayout>(R.id.top_bar)?.visibility = View.GONE
|
view?.findViewById<LinearLayout>(R.id.exo_top_bar)?.visibility = View.GONE
|
||||||
val mainActivity = activity as MainActivity
|
val mainActivity = activity as MainActivity
|
||||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
isFullScreen = false
|
isFullScreen = false
|
||||||
} else {
|
} else {
|
||||||
with(motionLayout) {
|
with(binding.playerMotionLayout) {
|
||||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
||||||
enableTransition(R.id.yt_transition, true)
|
enableTransition(R.id.yt_transition, true)
|
||||||
}
|
}
|
||||||
exoPlayerView.showController()
|
exoPlayerView.showController()
|
||||||
exoPlayerView.useController = true
|
exoPlayerView.useController = true
|
||||||
view?.findViewById<ConstraintLayout>(R.id.main_container)?.isClickable = false
|
binding.mainContainer.isClickable = false
|
||||||
view?.findViewById<LinearLayout>(R.id.top_bar)?.visibility = View.VISIBLE
|
view?.findViewById<LinearLayout>(R.id.exo_top_bar)?.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onUserLeaveHint() {
|
fun onUserLeaveHint() {
|
||||||
val bounds = Rect()
|
val bounds = Rect()
|
||||||
val scrollView = view?.findViewById<ScrollView>(R.id.player_scrollView)
|
binding.playerScrollView.getHitRect(bounds)
|
||||||
scrollView?.getHitRect(bounds)
|
|
||||||
|
|
||||||
if (SDK_INT >= Build.VERSION_CODES.O &&
|
if (SDK_INT >= Build.VERSION_CODES.O &&
|
||||||
exoPlayer.isPlaying && (
|
exoPlayer.isPlaying && (
|
||||||
scrollView?.getLocalVisibleRect(bounds) == true ||
|
binding.playerScrollView.getLocalVisibleRect(bounds) == true ||
|
||||||
isFullScreen
|
isFullScreen
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
android:background="@color/exo_black_opacity_60" />
|
android:background="@color/exo_black_opacity_60" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/top_bar"
|
android:id="@+id/exo_top_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/exo_styled_bottom_bar_height"
|
android:layout_height="@dimen/exo_styled_bottom_bar_height"
|
||||||
android:layout_gravity="top"
|
android:layout_gravity="top"
|
||||||
|
@ -326,7 +326,7 @@
|
|||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/player_recView"
|
android:id="@+id/related_rec_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/comments_recView"
|
android:layout_below="@id/comments_recView"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user