mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Merge branch 'libre-tube:master' into master
This commit is contained in:
commit
e24213b90d
@ -8,12 +8,11 @@ import android.view.View
|
|||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.os.bundleOf
|
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.setFragmentResult
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.fragments.Library
|
||||||
import com.github.libretube.obj.Playlists
|
import com.github.libretube.obj.Playlists
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
@ -87,8 +86,13 @@ class CreatePlaylistDialog : DialogFragment() {
|
|||||||
Toast.makeText(context, getString(R.string.unknown_error), Toast.LENGTH_SHORT)
|
Toast.makeText(context, getString(R.string.unknown_error), Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
// tell the Subscription Activity to fetch the playlists again
|
// refresh the playlists in the library
|
||||||
setFragmentResult("fetchPlaylists", bundleOf("" to ""))
|
try {
|
||||||
|
val parent = parentFragment as Library
|
||||||
|
parent.fetchPlaylists()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, e.toString())
|
||||||
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class Library : Fragment() {
|
|||||||
lateinit var token: String
|
lateinit var token: String
|
||||||
private lateinit var playlistRecyclerView: RecyclerView
|
private lateinit var playlistRecyclerView: RecyclerView
|
||||||
private lateinit var refreshLayout: SwipeRefreshLayout
|
private lateinit var refreshLayout: SwipeRefreshLayout
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
@ -52,26 +53,32 @@ class Library : Fragment() {
|
|||||||
if (token != "") {
|
if (token != "") {
|
||||||
view.findViewById<ImageView>(R.id.boogh2).visibility = View.GONE
|
view.findViewById<ImageView>(R.id.boogh2).visibility = View.GONE
|
||||||
view.findViewById<TextView>(R.id.textLike2).visibility = View.GONE
|
view.findViewById<TextView>(R.id.textLike2).visibility = View.GONE
|
||||||
fetchPlaylists(view)
|
fetchPlaylists()
|
||||||
refreshLayout.isEnabled = true
|
refreshLayout.isEnabled = true
|
||||||
refreshLayout.setOnRefreshListener {
|
refreshLayout.setOnRefreshListener {
|
||||||
Log.d(TAG, "hmm")
|
fetchPlaylists()
|
||||||
fetchPlaylists(view)
|
|
||||||
}
|
}
|
||||||
view.findViewById<FloatingActionButton>(R.id.create_playlist).setOnClickListener {
|
val createPlaylistButton = view.findViewById<FloatingActionButton>(R.id.create_playlist)
|
||||||
|
createPlaylistButton.setOnClickListener {
|
||||||
val newFragment = CreatePlaylistDialog()
|
val newFragment = CreatePlaylistDialog()
|
||||||
newFragment.show(childFragmentManager, "Create Playlist")
|
newFragment.show(childFragmentManager, "Create Playlist")
|
||||||
}
|
}
|
||||||
childFragmentManager.setFragmentResultListener("fetchPlaylists", this) { _, _ ->
|
|
||||||
fetchPlaylists(view)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
refreshLayout.isEnabled = false
|
refreshLayout.isEnabled = false
|
||||||
view.findViewById<FloatingActionButton>(R.id.create_playlist).visibility = View.GONE
|
view.findViewById<FloatingActionButton>(R.id.create_playlist).visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchPlaylists(view: View) {
|
override fun onResume() {
|
||||||
|
// optimize CreatePlaylistFab bottom margin if miniPlayer active
|
||||||
|
val createPlaylistButton = view?.findViewById<FloatingActionButton>(R.id.create_playlist)
|
||||||
|
val layoutParams = createPlaylistButton?.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
|
layoutParams.bottomMargin = if (isMiniPlayerVisible) 180 else 64
|
||||||
|
createPlaylistButton?.layoutParams = layoutParams
|
||||||
|
super.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fetchPlaylists() {
|
||||||
fun run() {
|
fun run() {
|
||||||
refreshLayout.isRefreshing = true
|
refreshLayout.isRefreshing = true
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
@ -91,12 +98,8 @@ class Library : Fragment() {
|
|||||||
}
|
}
|
||||||
if (response.isNotEmpty()) {
|
if (response.isNotEmpty()) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
with(view.findViewById<ImageView>(R.id.boogh2)) {
|
view?.findViewById<ImageView>(R.id.boogh2)?.visibility = View.GONE
|
||||||
visibility = View.GONE
|
view?.findViewById<TextView>(R.id.textLike2)?.visibility = View.GONE
|
||||||
}
|
|
||||||
with(view.findViewById<TextView>(R.id.textLike2)) {
|
|
||||||
visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val playlistsAdapter = PlaylistsAdapter(
|
val playlistsAdapter = PlaylistsAdapter(
|
||||||
response.toMutableList(),
|
response.toMutableList(),
|
||||||
@ -105,13 +108,13 @@ class Library : Fragment() {
|
|||||||
playlistRecyclerView.adapter = playlistsAdapter
|
playlistRecyclerView.adapter = playlistsAdapter
|
||||||
} else {
|
} else {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
with(view.findViewById<ImageView>(R.id.boogh2)) {
|
view?.findViewById<ImageView>(R.id.boogh2).apply {
|
||||||
visibility = View.VISIBLE
|
this?.visibility = View.VISIBLE
|
||||||
setImageResource(R.drawable.ic_list)
|
this?.setImageResource(R.drawable.ic_list)
|
||||||
}
|
}
|
||||||
with(view.findViewById<TextView>(R.id.textLike2)) {
|
view?.findViewById<TextView>(R.id.textLike2).apply {
|
||||||
visibility = View.VISIBLE
|
this?.visibility = View.VISIBLE
|
||||||
text = getString(R.string.emptyList)
|
this?.text = getString(R.string.emptyList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.github.libretube.fragments
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
|
import android.app.PictureInPictureParams
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
@ -92,6 +93,7 @@ import java.util.concurrent.Executors
|
|||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
var isFullScreen = false
|
var isFullScreen = false
|
||||||
|
var isMiniPlayerVisible = false
|
||||||
|
|
||||||
class PlayerFragment : Fragment() {
|
class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
@ -197,9 +199,11 @@ class PlayerFragment : Fragment() {
|
|||||||
val mainMotionLayout =
|
val mainMotionLayout =
|
||||||
mainActivity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
mainActivity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
||||||
if (currentId == eId) {
|
if (currentId == eId) {
|
||||||
|
isMiniPlayerVisible = true
|
||||||
exoPlayerView.useController = false
|
exoPlayerView.useController = false
|
||||||
mainMotionLayout.progress = 1F
|
mainMotionLayout.progress = 1F
|
||||||
} else if (currentId == sId) {
|
} else if (currentId == sId) {
|
||||||
|
isMiniPlayerVisible = false
|
||||||
exoPlayerView.useController = true
|
exoPlayerView.useController = true
|
||||||
mainMotionLayout.progress = 0F
|
mainMotionLayout.progress = 0F
|
||||||
}
|
}
|
||||||
@ -218,6 +222,7 @@ class PlayerFragment : Fragment() {
|
|||||||
playerMotionLayout.transitionToStart()
|
playerMotionLayout.transitionToStart()
|
||||||
|
|
||||||
view.findViewById<ImageView>(R.id.close_imageView).setOnClickListener {
|
view.findViewById<ImageView>(R.id.close_imageView).setOnClickListener {
|
||||||
|
isMiniPlayerVisible = false
|
||||||
motionLayout.transitionToEnd()
|
motionLayout.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
|
||||||
@ -226,6 +231,7 @@ class PlayerFragment : Fragment() {
|
|||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
|
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
|
||||||
|
isMiniPlayerVisible = false
|
||||||
motionLayout.transitionToEnd()
|
motionLayout.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
|
||||||
@ -434,17 +440,20 @@ class PlayerFragment : Fragment() {
|
|||||||
createExoPlayer(view)
|
createExoPlayer(view)
|
||||||
prepareExoPlayerView()
|
prepareExoPlayerView()
|
||||||
if (response.chapters != null) initializeChapters(response.chapters)
|
if (response.chapters != null) initializeChapters(response.chapters)
|
||||||
|
// set media sources for the player
|
||||||
setResolutionAndSubtitles(view, response)
|
setResolutionAndSubtitles(view, response)
|
||||||
|
exoPlayer.prepare()
|
||||||
|
initializePlayerView(view, response)
|
||||||
// support for time stamped links
|
// support for time stamped links
|
||||||
if (arguments?.getLong("timeStamp") != null) {
|
if (arguments?.getLong("timeStamp") != null) {
|
||||||
val position = arguments?.getLong("timeStamp")!! * 1000
|
val position = arguments?.getLong("timeStamp")!! * 1000
|
||||||
exoPlayer.seekTo(position)
|
exoPlayer.seekTo(position)
|
||||||
}
|
}
|
||||||
exoPlayer.prepare()
|
|
||||||
exoPlayer.play()
|
exoPlayer.play()
|
||||||
initializePlayerView(view, response)
|
exoPlayerView.useController = true
|
||||||
initializePlayerNotification(requireContext())
|
initializePlayerNotification(requireContext())
|
||||||
fetchSponsorBlockSegments()
|
fetchSponsorBlockSegments()
|
||||||
|
// show comments if related streams disabled
|
||||||
if (!relatedStreamsEnabled) toggleComments()
|
if (!relatedStreamsEnabled) toggleComments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -537,6 +546,7 @@ class PlayerFragment : Fragment() {
|
|||||||
setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
|
setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
|
||||||
// controllerShowTimeoutMs = 1500
|
// controllerShowTimeoutMs = 1500
|
||||||
controllerHideOnTouch = true
|
controllerHideOnTouch = true
|
||||||
|
useController = false
|
||||||
player = exoPlayer
|
player = exoPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1124,7 +1134,11 @@ class PlayerFragment : Fragment() {
|
|||||||
isFullScreen
|
isFullScreen
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
requireActivity().enterPictureInPictureMode()
|
activity?.enterPictureInPictureMode(updatePipParams())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updatePipParams() = PictureInPictureParams.Builder()
|
||||||
|
.setActions(emptyList())
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -55,14 +55,12 @@ object PreferenceHelper {
|
|||||||
|
|
||||||
fun clearPreferences(context: Context) {
|
fun clearPreferences(context: Context) {
|
||||||
val editor = getDefaultSharedPreferencesEditor(context)
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
editor.clear()
|
editor.clear().apply()
|
||||||
editor.commit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removePreference(context: Context, value: String?) {
|
fun removePreference(context: Context, value: String?) {
|
||||||
val editor = getDefaultSharedPreferencesEditor(context)
|
val editor = getDefaultSharedPreferencesEditor(context)
|
||||||
editor.remove(value)
|
editor.remove(value).apply()
|
||||||
editor.commit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getToken(context: Context): String {
|
fun getToken(context: Context): String {
|
||||||
@ -72,7 +70,7 @@ object PreferenceHelper {
|
|||||||
|
|
||||||
fun setToken(context: Context, newValue: String) {
|
fun setToken(context: Context, newValue: String) {
|
||||||
val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit()
|
val editor = context.getSharedPreferences("token", Context.MODE_PRIVATE).edit()
|
||||||
editor.putString("token", newValue)
|
editor.putString("token", newValue).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUsername(context: Context): String {
|
fun getUsername(context: Context): String {
|
||||||
@ -82,7 +80,7 @@ object PreferenceHelper {
|
|||||||
|
|
||||||
fun setUsername(context: Context, newValue: String) {
|
fun setUsername(context: Context, newValue: String) {
|
||||||
val editor = context.getSharedPreferences("username", Context.MODE_PRIVATE).edit()
|
val editor = context.getSharedPreferences("username", Context.MODE_PRIVATE).edit()
|
||||||
editor.putString("username", newValue)
|
editor.putString("username", newValue).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveCustomInstance(context: Context, customInstance: CustomInstance) {
|
fun saveCustomInstance(context: Context, customInstance: CustomInstance) {
|
||||||
@ -93,7 +91,7 @@ object PreferenceHelper {
|
|||||||
customInstancesList += customInstance
|
customInstancesList += customInstance
|
||||||
|
|
||||||
val json = gson.toJson(customInstancesList)
|
val json = gson.toJson(customInstancesList)
|
||||||
editor.putString("customInstances", json).commit()
|
editor.putString("customInstances", json).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCustomInstances(context: Context): ArrayList<CustomInstance> {
|
fun getCustomInstances(context: Context): ArrayList<CustomInstance> {
|
||||||
|
@ -166,27 +166,6 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<HorizontalScrollView
|
|
||||||
android:id="@id/exo_extra_controls_scroll_view"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical|end"
|
|
||||||
android:visibility="invisible">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@id/exo_extra_controls"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layoutDirection="ltr">
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@id/exo_overflow_hide"
|
|
||||||
style="@style/ExoStyledControls.Button.Bottom.OverflowHide" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</HorizontalScrollView>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/progress_bar"
|
android:id="@+id/progress_bar"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
|
Loading…
Reference in New Issue
Block a user