mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #105 from AbduAmeen/title_description_seperation
Added separation of title, description and views/date
This commit is contained in:
commit
3d822947fe
@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -13,7 +12,6 @@ import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
@ -21,21 +19,12 @@ import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.ViewCompat.getWindowInsetsController
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.Navigation
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.NavigationUI
|
||||
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import java.lang.Exception
|
||||
|
||||
@ -44,10 +33,11 @@ class MainActivity : AppCompatActivity() {
|
||||
lateinit var bottomNavigationView: BottomNavigationView
|
||||
lateinit var toolbar: Toolbar
|
||||
lateinit var navController : NavController
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
RetrofitInstance.url=sharedPreferences.getString("instance", "https://pipedapi.kavin.rocks/")!!
|
||||
RetrofitInstance.url = sharedPreferences.getString("instance", "https://pipedapi.kavin.rocks/")!!
|
||||
DynamicColors.applyToActivitiesIfAvailable(application)
|
||||
setContentView(R.layout.activity_main)
|
||||
when (sharedPreferences.getString("theme_togglee", "A")!!) {
|
||||
|
@ -26,6 +26,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceManager
|
||||
@ -53,7 +54,6 @@ import java.io.IOException
|
||||
import java.net.URLEncoder
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
var isFullScreen = false
|
||||
class PlayerFragment : Fragment() {
|
||||
|
||||
@ -61,12 +61,12 @@ class PlayerFragment : Fragment() {
|
||||
private var videoId: String? = null
|
||||
private var param2: String? = null
|
||||
private var lastProgress: Float = 0.toFloat()
|
||||
private var sId: Int=0
|
||||
private var eId: Int=0
|
||||
private var paused =false
|
||||
private var sId: Int = 0
|
||||
private var eId: Int = 0
|
||||
private var paused = false
|
||||
private var whichQuality = 0
|
||||
|
||||
var isSubscribed: Boolean =false
|
||||
var isSubscribed: Boolean = false
|
||||
|
||||
private lateinit var relatedRecView: RecyclerView
|
||||
private lateinit var exoPlayerView: StyledPlayerView
|
||||
@ -84,7 +84,8 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
@ -94,48 +95,47 @@ class PlayerFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
hideKeyboard()
|
||||
videoId = videoId!!.replace("/watch?v=","")
|
||||
|
||||
val playerDescription = view.findViewById<TextView>(R.id.player_description)
|
||||
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
|
||||
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
|
||||
playerMotionLayout.addTransitionListener(object: MotionLayout.TransitionListener {
|
||||
playerMotionLayout.addTransitionListener(object : MotionLayout.TransitionListener {
|
||||
override fun onTransitionStarted(
|
||||
motionLayout: MotionLayout?,
|
||||
startId: Int,
|
||||
endId: Int
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float) {
|
||||
val mainActivity = activity as MainActivity
|
||||
val mainMotionLayout = mainActivity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
||||
mainMotionLayout.progress = abs(progress)
|
||||
eId=endId
|
||||
sId=startId
|
||||
|
||||
eId = endId
|
||||
sId = startId
|
||||
}
|
||||
|
||||
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
||||
println(currentId)
|
||||
val mainActivity = activity as MainActivity
|
||||
val mainMotionLayout = mainActivity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
||||
if (currentId==eId) {
|
||||
view.findViewById<ImageButton>(R.id.quality_select).visibility =View.GONE
|
||||
view.findViewById<ImageButton>(R.id.close_imageButton).visibility =View.GONE
|
||||
view.findViewById<TextView>(R.id.quality_text).visibility =View.GONE
|
||||
if (currentId == eId) {
|
||||
view.findViewById<ImageButton>(R.id.quality_select).visibility = View.GONE
|
||||
view.findViewById<ImageButton>(R.id.close_imageButton).visibility = View.GONE
|
||||
view.findViewById<TextView>(R.id.quality_text).visibility = View.GONE
|
||||
mainMotionLayout.progress = 1.toFloat()
|
||||
}else if(currentId==sId){
|
||||
view.findViewById<ImageButton>(R.id.quality_select).visibility =View.VISIBLE
|
||||
view.findViewById<ImageButton>(R.id.close_imageButton).visibility =View.VISIBLE
|
||||
view.findViewById<TextView>(R.id.quality_text).visibility =View.VISIBLE
|
||||
} else if (currentId == sId) {
|
||||
view.findViewById<ImageButton>(R.id.quality_select).visibility = View.VISIBLE
|
||||
view.findViewById<ImageButton>(R.id.close_imageButton).visibility = View.VISIBLE
|
||||
view.findViewById<TextView>(R.id.quality_text).visibility = View.VISIBLE
|
||||
mainMotionLayout.progress = 0.toFloat()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onTransitionTrigger(
|
||||
@ -144,23 +144,20 @@ class PlayerFragment : Fragment() {
|
||||
positive: Boolean,
|
||||
progress: Float
|
||||
) {
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
playerMotionLayout.progress=1.toFloat()
|
||||
playerMotionLayout.progress = 1.toFloat()
|
||||
playerMotionLayout.transitionToStart()
|
||||
fetchJson(view)
|
||||
view.findViewById<ImageView>(R.id.close_imageView).setOnClickListener{
|
||||
view.findViewById<ImageView>(R.id.close_imageView).setOnClickListener {
|
||||
motionLayout.transitionToEnd()
|
||||
val mainActivity = activity as MainActivity
|
||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
mainActivity.supportFragmentManager.beginTransaction()
|
||||
.remove(this)
|
||||
.commit()
|
||||
|
||||
}
|
||||
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener{
|
||||
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
|
||||
motionLayout.transitionToEnd()
|
||||
val mainActivity = activity as MainActivity
|
||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
@ -169,51 +166,52 @@ class PlayerFragment : Fragment() {
|
||||
.commit()
|
||||
}
|
||||
val playImageView = view.findViewById<ImageView>(R.id.play_imageView)
|
||||
playImageView.setOnClickListener{
|
||||
paused = if(paused){
|
||||
playImageView.setOnClickListener {
|
||||
paused = if (paused) {
|
||||
playImageView.setImageResource(R.drawable.ic_pause)
|
||||
exoPlayer.play()
|
||||
false
|
||||
}else {
|
||||
} else {
|
||||
playImageView.setImageResource(R.drawable.ic_play)
|
||||
exoPlayer.pause()
|
||||
true
|
||||
}
|
||||
}
|
||||
//FullScreen button trigger
|
||||
view.findViewById<ImageButton>(R.id.fullscreen).setOnClickListener{
|
||||
//remember to hide everything when new thing added
|
||||
if (!isFullScreen){
|
||||
|
||||
view.findViewById<ConstraintLayout>(R.id.player_title_layout).setOnClickListener {
|
||||
var visible = playerDescription.isVisible
|
||||
|
||||
playerDescription.visibility = if (visible) View.GONE else View.VISIBLE
|
||||
}
|
||||
// FullScreen button trigger
|
||||
view.findViewById<ImageButton>(R.id.fullscreen).setOnClickListener {
|
||||
// remember to hide everything when new thing added
|
||||
if (!isFullScreen) {
|
||||
with(motionLayout) {
|
||||
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
|
||||
view.findViewById<LinearLayout>(R.id.linLayout).visibility=View.GONE
|
||||
view.findViewById<ConstraintLayout>(R.id.main_container).isClickable = true
|
||||
view.findViewById<LinearLayout>(R.id.linLayout).visibility = View.GONE
|
||||
val mainActivity = activity as MainActivity
|
||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||
isFullScreen=true
|
||||
|
||||
}else{
|
||||
with(motionLayout) {
|
||||
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
|
||||
enableTransition(R.id.yt_transition,true)
|
||||
enableTransition(R.id.yt_transition, true)
|
||||
}
|
||||
view.findViewById<ConstraintLayout>(R.id.main_container).isClickable =false
|
||||
view.findViewById<LinearLayout>(R.id.linLayout).visibility=View.VISIBLE
|
||||
view.findViewById<ConstraintLayout>(R.id.main_container).isClickable = false
|
||||
view.findViewById<LinearLayout>(R.id.linLayout).visibility = View.VISIBLE
|
||||
val mainActivity = activity as MainActivity
|
||||
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
isFullScreen=false
|
||||
isFullScreen = false
|
||||
}
|
||||
|
||||
}
|
||||
relatedRecView = view.findViewById(R.id.player_recView)
|
||||
relatedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
}
|
||||
@ -222,16 +220,15 @@ class PlayerFragment : Fragment() {
|
||||
super.onDestroy()
|
||||
try {
|
||||
exoPlayer.stop()
|
||||
}catch (e: Exception){}
|
||||
} catch (e: Exception) {}
|
||||
}
|
||||
|
||||
|
||||
private fun fetchJson(view: View) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getStreams(videoId!!)
|
||||
} catch(e: IOException) {
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show()
|
||||
@ -243,17 +240,20 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
var videosNameArray: Array<CharSequence> = arrayOf()
|
||||
videosNameArray += "HLS"
|
||||
for (vid in response.videoStreams!!){
|
||||
val name = vid.quality +" "+ vid.format
|
||||
for (vid in response.videoStreams!!) {
|
||||
val name = vid.quality + " " + vid.format
|
||||
videosNameArray += name
|
||||
}
|
||||
runOnUiThread {
|
||||
var subtitle = mutableListOf<SubtitleConfiguration>()
|
||||
if(response.subtitles!!.isNotEmpty()){
|
||||
subtitle?.add(SubtitleConfiguration.Builder(response.subtitles!![0].url!!.toUri())
|
||||
if (response.subtitles!!.isNotEmpty()) {
|
||||
subtitle?.add(
|
||||
SubtitleConfiguration.Builder(response.subtitles!![0].url!!.toUri())
|
||||
.setMimeType(response.subtitles!![0].mimeType!!) // The correct MIME type (required).
|
||||
.setLanguage(response.subtitles!![0].code) // The subtitle language (optional).
|
||||
.build())}
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
exoPlayer = ExoPlayer.Builder(view.context)
|
||||
.setSeekBackIncrementMs(5000)
|
||||
@ -262,7 +262,7 @@ class PlayerFragment : Fragment() {
|
||||
exoPlayerView.setShowSubtitleButton(true)
|
||||
exoPlayerView.setShowNextButton(false)
|
||||
exoPlayerView.setShowPreviousButton(false)
|
||||
//exoPlayerView.controllerShowTimeoutMs = 1500
|
||||
// exoPlayerView.controllerShowTimeoutMs = 1500
|
||||
exoPlayerView.controllerHideOnTouch = true
|
||||
exoPlayerView.player = exoPlayer
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
@ -284,13 +284,13 @@ class PlayerFragment : Fragment() {
|
||||
.createMediaSource(videoItem)
|
||||
var audioSource: MediaSource = DefaultMediaSourceFactory(dataSourceFactory)
|
||||
.createMediaSource(fromUri(response.audioStreams!![0].url!!))
|
||||
if (response.videoStreams[index].quality=="720p" || response.videoStreams[index].quality=="1080p" || response.videoStreams[index].quality=="480p" ){
|
||||
if (response.videoStreams[index].quality == "720p" || response.videoStreams[index].quality == "1080p" || response.videoStreams[index].quality == "480p") {
|
||||
audioSource = ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(fromUri(response.audioStreams!![getMostBitRate(response.audioStreams)].url!!))
|
||||
}
|
||||
val mergeSource: MediaSource = MergingMediaSource(videoSource,audioSource)
|
||||
val mergeSource: MediaSource = MergingMediaSource(videoSource, audioSource)
|
||||
exoPlayer.setMediaSource(mergeSource)
|
||||
view.findViewById<TextView>(R.id.quality_text).text=videosNameArray[index+1]
|
||||
view.findViewById<TextView>(R.id.quality_text).text = videosNameArray[index + 1]
|
||||
return@lit
|
||||
}else if (index+1 == response.videoStreams.size){
|
||||
val mediaItem: MediaItem = MediaItem.Builder()
|
||||
@ -301,7 +301,6 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
response.hls != null -> {
|
||||
val mediaItem: MediaItem = MediaItem.Builder()
|
||||
@ -321,32 +320,34 @@ class PlayerFragment : Fragment() {
|
||||
.createMediaSource(videoItem)
|
||||
var audioSource: MediaSource = DefaultMediaSourceFactory(dataSourceFactory)
|
||||
.createMediaSource(fromUri(response.audioStreams!![0].url!!))
|
||||
if (response.videoStreams[0].quality=="720p" || response.videoStreams[0].quality=="1080p" || response.videoStreams[0].quality=="480p" ){
|
||||
if (response.videoStreams[0].quality == "720p" || response.videoStreams[0].quality == "1080p" || response.videoStreams[0].quality == "480p") {
|
||||
audioSource = ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(fromUri(response.audioStreams!![getMostBitRate(response.audioStreams)].url!!))
|
||||
}
|
||||
val mergeSource: MediaSource = MergingMediaSource(videoSource,audioSource)
|
||||
val mergeSource: MediaSource = MergingMediaSource(videoSource, audioSource)
|
||||
exoPlayer.setMediaSource(mergeSource)
|
||||
view.findViewById<TextView>(R.id.quality_text).text=videosNameArray[1]
|
||||
view.findViewById<TextView>(R.id.quality_text).text = videosNameArray[1]
|
||||
}
|
||||
}
|
||||
|
||||
///exoPlayer.getMediaItemAt(5)
|
||||
// /exoPlayer.getMediaItemAt(5)
|
||||
exoPlayer.prepare()
|
||||
exoPlayer.play()
|
||||
|
||||
view.findViewById<TextView>(R.id.title_textView).text = response.title
|
||||
view.findViewById<TextView>(R.id.player_title).text = response.title
|
||||
view.findViewById<TextView>(R.id.player_description).text = response.description
|
||||
|
||||
view.findViewById<ImageButton>(R.id.quality_select).setOnClickListener{
|
||||
//Dialog for quality selection
|
||||
view.findViewById<ImageButton>(R.id.quality_select).setOnClickListener {
|
||||
// Dialog for quality selection
|
||||
val builder: AlertDialog.Builder? = activity?.let {
|
||||
AlertDialog.Builder(it)
|
||||
}
|
||||
builder!!.setTitle(R.string.choose_quality_dialog)
|
||||
.setItems(videosNameArray,
|
||||
.setItems(
|
||||
videosNameArray,
|
||||
DialogInterface.OnClickListener { _, which ->
|
||||
whichQuality = which
|
||||
if(response.subtitles!!.isNotEmpty()) {
|
||||
if (response.subtitles!!.isNotEmpty()) {
|
||||
var subtitle =
|
||||
mutableListOf<SubtitleConfiguration>()
|
||||
subtitle?.add(
|
||||
@ -356,41 +357,44 @@ class PlayerFragment : Fragment() {
|
||||
.build()
|
||||
)
|
||||
}
|
||||
if(which==0){
|
||||
if (which == 0) {
|
||||
val mediaItem: MediaItem = MediaItem.Builder()
|
||||
.setUri(response.hls)
|
||||
.setSubtitleConfigurations(subtitle)
|
||||
.build()
|
||||
exoPlayer.setMediaItem(mediaItem)
|
||||
}else{
|
||||
} else {
|
||||
val dataSourceFactory: DataSource.Factory =
|
||||
DefaultHttpDataSource.Factory()
|
||||
val videoItem: MediaItem = MediaItem.Builder()
|
||||
.setUri(response.videoStreams[which-1].url)
|
||||
.setUri(response.videoStreams[which - 1].url)
|
||||
.setSubtitleConfigurations(subtitle)
|
||||
.build()
|
||||
val videoSource: MediaSource = DefaultMediaSourceFactory(dataSourceFactory)
|
||||
.createMediaSource(videoItem)
|
||||
var audioSource: MediaSource = DefaultMediaSourceFactory(dataSourceFactory)
|
||||
.createMediaSource(fromUri(response.audioStreams!![0].url!!))
|
||||
if (response.videoStreams[which-1].quality=="720p" || response.videoStreams[which-1].quality=="1080p" || response.videoStreams[which-1].quality=="480p" ){
|
||||
if (response.videoStreams[which - 1].quality == "720p" || response.videoStreams[which - 1].quality == "1080p" || response.videoStreams[which - 1].quality == "480p") {
|
||||
audioSource = ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(fromUri(response.audioStreams!![getMostBitRate(response.audioStreams)].url!!))
|
||||
}
|
||||
val mergeSource: MediaSource = MergingMediaSource(videoSource,audioSource)
|
||||
val mergeSource: MediaSource = MergingMediaSource(videoSource, audioSource)
|
||||
exoPlayer.setMediaSource(mergeSource)
|
||||
}
|
||||
view.findViewById<TextView>(R.id.quality_text).text=videosNameArray[which]
|
||||
})
|
||||
view.findViewById<TextView>(R.id.quality_text).text = videosNameArray[which]
|
||||
}
|
||||
)
|
||||
val dialog: AlertDialog? = builder?.create()
|
||||
dialog?.show()
|
||||
}
|
||||
//Listener for play and pause icon change
|
||||
// Listener for play and pause icon change
|
||||
exoPlayer!!.addListener(object : com.google.android.exoplayer2.Player.Listener {
|
||||
override fun onPlayerStateChanged(playWhenReady: Boolean,playbackState: Int) {
|
||||
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
|
||||
|
||||
exoPlayerView.keepScreenOn = !(playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED ||
|
||||
!playWhenReady)
|
||||
exoPlayerView.keepScreenOn = !(
|
||||
playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED ||
|
||||
!playWhenReady
|
||||
)
|
||||
|
||||
if (playWhenReady && playbackState == Player.STATE_READY) {
|
||||
// media actually playing
|
||||
@ -412,54 +416,56 @@ class PlayerFragment : Fragment() {
|
||||
} else {
|
||||
Html.fromHtml(response.description)
|
||||
}
|
||||
view.findViewById<TextView>(R.id.player_sub).text = response.views.formatShort() + " views • "+response.uploadDate
|
||||
view.findViewById<TextView>(R.id.player_views_info).text = response.views.formatShort() + " views • " + response.uploadDate
|
||||
view.findViewById<TextView>(R.id.textLike).text = response.likes.formatShort()
|
||||
val channelImage = view.findViewById<ImageView>(R.id.player_channelImage)
|
||||
Picasso.get().load(response.uploaderAvatar).into(channelImage)
|
||||
view.findViewById<TextView>(R.id.player_channelName).text=response.uploader
|
||||
view.findViewById<TextView>(R.id.player_channelName).text = response.uploader
|
||||
view.findViewById<RelativeLayout>(R.id.player_channel).setOnClickListener {
|
||||
|
||||
val activity = view.context as MainActivity
|
||||
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()
|
||||
view.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
|
||||
}
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
if(sharedPref?.getString("token","")!=""){
|
||||
val channelId = response.uploaderUrl?.replace("/channel/","")
|
||||
if (sharedPref?.getString("token", "") != "") {
|
||||
val channelId = response.uploaderUrl?.replace("/channel/", "")
|
||||
val subButton = view.findViewById<MaterialButton>(R.id.player_subscribe)
|
||||
isSubscribed(subButton, channelId!!)
|
||||
}
|
||||
//share button
|
||||
// share button
|
||||
view.findViewById<RelativeLayout>(R.id.relPlayer_share).setOnClickListener {
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val intent= Intent()
|
||||
intent.action=Intent.ACTION_SEND
|
||||
val intent = Intent()
|
||||
intent.action = Intent.ACTION_SEND
|
||||
var url = "https://piped.kavin.rocks/watch?v=$videoId"
|
||||
val instance = sharedPreferences.getString("instance", "https://pipedapi.kavin.rocks")!!
|
||||
if (instance != "https://pipedapi.kavin.rocks")
|
||||
url += "&instance=${URLEncoder.encode(instance, "UTF-8")}"
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url)
|
||||
intent.type="text/plain"
|
||||
startActivity(Intent.createChooser(intent,"Share Url To:"))
|
||||
intent.type = "text/plain"
|
||||
startActivity(Intent.createChooser(intent, "Share Url To:"))
|
||||
}
|
||||
//check if livestream
|
||||
if (response.duration!!>0){
|
||||
//download clicked
|
||||
// check if livestream
|
||||
if (response.duration!!> 0) {
|
||||
// download clicked
|
||||
relDownloadVideo.setOnClickListener {
|
||||
if(!IS_DOWNLOAD_RUNNING){
|
||||
if (!IS_DOWNLOAD_RUNNING) {
|
||||
val mainActivity = activity as MainActivity
|
||||
Log.e(TAG,"download button clicked!")
|
||||
Log.e(TAG, "download button clicked!")
|
||||
if (SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Log.d("myz", "" + SDK_INT)
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
ActivityCompat.requestPermissions(
|
||||
mainActivity, arrayOf(
|
||||
mainActivity,
|
||||
arrayOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.MANAGE_EXTERNAL_STORAGE
|
||||
), 1
|
||||
) //permission request code is just an int
|
||||
),
|
||||
1
|
||||
) // permission request code is just an int
|
||||
}
|
||||
} else {
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
@ -484,8 +490,8 @@ class PlayerFragment : Fragment() {
|
||||
vidName.add("No video")
|
||||
var vidUrl = arrayListOf<String>()
|
||||
vidUrl.add("")
|
||||
for (vid in response.videoStreams!!){
|
||||
val name = vid.quality +" "+ vid.format
|
||||
for (vid in response.videoStreams!!) {
|
||||
val name = vid.quality + " " + vid.format
|
||||
vidName.add(name)
|
||||
vidUrl.add(vid.url!!)
|
||||
}
|
||||
@ -493,33 +499,33 @@ class PlayerFragment : Fragment() {
|
||||
audioName.add("No audio")
|
||||
var audioUrl = arrayListOf<String>()
|
||||
audioUrl.add("")
|
||||
for (audio in response.audioStreams!!){
|
||||
val name = audio.quality +" "+ audio.format
|
||||
for (audio in response.audioStreams!!) {
|
||||
val name = audio.quality + " " + audio.format
|
||||
audioName.add(name)
|
||||
audioUrl.add(audio.url!!)
|
||||
}
|
||||
val newFragment = DownloadDialog()
|
||||
var bundle = Bundle()
|
||||
bundle.putStringArrayList("videoName",vidName)
|
||||
bundle.putStringArrayList("videoUrl",vidUrl)
|
||||
bundle.putStringArrayList("audioName",audioName)
|
||||
bundle.putStringArrayList("audioUrl",audioUrl)
|
||||
bundle.putString("videoId",videoId)
|
||||
bundle.putInt("duration",response.duration)
|
||||
bundle.putStringArrayList("videoName", vidName)
|
||||
bundle.putStringArrayList("videoUrl", vidUrl)
|
||||
bundle.putStringArrayList("audioName", audioName)
|
||||
bundle.putStringArrayList("audioUrl", audioUrl)
|
||||
bundle.putString("videoId", videoId)
|
||||
bundle.putInt("duration", response.duration)
|
||||
newFragment.arguments = bundle
|
||||
newFragment.show(childFragmentManager, "Download")
|
||||
}else{
|
||||
} else {
|
||||
Toast.makeText(context, R.string.dlisinprogress, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Toast.makeText(context,R.string.cannotDownload, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Toast.makeText(context, R.string.cannotDownload, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
if (response.hls!=null){
|
||||
if (response.hls != null) {
|
||||
view.findViewById<RelativeLayout>(R.id.relPlayer_vlc).setOnClickListener {
|
||||
exoPlayer.pause()
|
||||
try{
|
||||
try {
|
||||
val vlcRequestCode = 42
|
||||
val uri: Uri = Uri.parse(response.hls)
|
||||
val vlcIntent = Intent(Intent.ACTION_VIEW)
|
||||
@ -529,27 +535,26 @@ class PlayerFragment : Fragment() {
|
||||
vlcIntent.putExtra("from_start", false)
|
||||
vlcIntent.putExtra("position", exoPlayer.currentPosition)
|
||||
startActivityForResult(vlcIntent, vlcRequestCode)
|
||||
}catch(e: Exception){
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(context, R.string.vlcerror, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
|
||||
}
|
||||
|
||||
private fun isSubscribed(button: MaterialButton, channel_id: String){
|
||||
private fun isSubscribed(button: MaterialButton, channel_id: String) {
|
||||
@SuppressLint("ResourceAsColor")
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
RetrofitInstance.api.isSubscribed(channel_id,sharedPref?.getString("token","")!!)
|
||||
}catch(e: IOException) {
|
||||
RetrofitInstance.api.isSubscribed(channel_id, sharedPref?.getString("token", "")!!)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
@ -561,46 +566,48 @@ class PlayerFragment : Fragment() {
|
||||
(context as Activity).theme.resolveAttribute(
|
||||
android.R.attr.colorPrimary,
|
||||
colorPrimary,
|
||||
true)
|
||||
true
|
||||
)
|
||||
|
||||
val ColorText = TypedValue()
|
||||
(context as Activity).theme.resolveAttribute(
|
||||
R.attr.colorOnSurface,
|
||||
ColorText,
|
||||
true)
|
||||
true
|
||||
)
|
||||
|
||||
runOnUiThread {
|
||||
if (response.subscribed==true){
|
||||
isSubscribed=true
|
||||
button.text=getString(R.string.unsubscribe)
|
||||
if (response.subscribed == true) {
|
||||
isSubscribed = true
|
||||
button.text = getString(R.string.unsubscribe)
|
||||
button.setTextColor(ColorText.data)
|
||||
}
|
||||
if(response.subscribed!=null){
|
||||
if (response.subscribed != null) {
|
||||
button.setOnClickListener {
|
||||
if(isSubscribed){
|
||||
if (isSubscribed) {
|
||||
unsubscribe(channel_id)
|
||||
button.text=getString(R.string.subscribe)
|
||||
button.text = getString(R.string.subscribe)
|
||||
button.setTextColor(colorPrimary.data)
|
||||
|
||||
}else{
|
||||
} else {
|
||||
subscribe(channel_id)
|
||||
button.text=getString(R.string.unsubscribe)
|
||||
button.text = getString(R.string.unsubscribe)
|
||||
button.setTextColor(colorPrimary.data)
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun subscribe(channel_id: String){
|
||||
private fun subscribe(channel_id: String) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
RetrofitInstance.api.subscribe(sharedPref?.getString("token","")!!, Subscribe(channel_id))
|
||||
}catch(e: IOException) {
|
||||
RetrofitInstance.api.subscribe(sharedPref?.getString("token", "")!!, Subscribe(channel_id))
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
@ -608,18 +615,18 @@ class PlayerFragment : Fragment() {
|
||||
Log.e(TAG, "HttpException, unexpected response$e")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
isSubscribed=true
|
||||
isSubscribed = true
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
private fun unsubscribe(channel_id: String){
|
||||
private fun unsubscribe(channel_id: String) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
RetrofitInstance.api.unsubscribe(sharedPref?.getString("token","")!!, Subscribe(channel_id))
|
||||
}catch(e: IOException) {
|
||||
RetrofitInstance.api.unsubscribe(sharedPref?.getString("token", "")!!, Subscribe(channel_id))
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
@ -627,26 +634,25 @@ class PlayerFragment : Fragment() {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
isSubscribed=false
|
||||
isSubscribed = false
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
|
||||
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||
this ?: return
|
||||
if (!isAdded) return // Fragment not attached to an Activity
|
||||
activity?.runOnUiThread(action)
|
||||
}
|
||||
|
||||
private fun getMostBitRate(audios: List<PipedStream>):Int{
|
||||
var bitrate =0
|
||||
private fun getMostBitRate(audios: List<PipedStream>): Int {
|
||||
var bitrate = 0
|
||||
var index = 0
|
||||
for ((i, audio) in audios.withIndex()){
|
||||
val q = audio.quality!!.replace(" kbps","").toInt()
|
||||
if (q>bitrate){
|
||||
bitrate=q
|
||||
for ((i, audio) in audios.withIndex()) {
|
||||
val q = audio.quality!!.replace(" kbps", "").toInt()
|
||||
if (q> bitrate) {
|
||||
bitrate = q
|
||||
index = i
|
||||
}
|
||||
}
|
||||
@ -656,5 +662,4 @@ class PlayerFragment : Fragment() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
}
|
@ -29,24 +29,68 @@
|
||||
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:text=""
|
||||
android:textSize="15sp"
|
||||
android:layout_margin="7dp"
|
||||
android:textStyle="bold" />
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/player_info_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_sub"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/player_title_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:text="" />
|
||||
android:text="Title"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@id/player_description_arrow"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_views_info"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:text="TextView"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintEnd_toStartOf="@id/player_description_arrow"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/player_description_arrow"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:src="@drawable/ic_arrow_down"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/player_title_layout" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user