Merge branch 'libre-tube:master' into master

This commit is contained in:
XelXen 2022-06-15 20:00:44 +05:30 committed by GitHub
commit e12d30fdb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 194 additions and 84 deletions

View File

@ -11,7 +11,6 @@ import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
import com.google.android.exoplayer2.ui.PlayerNotificationManager
import gen._base._base_java__rjava_resources.srcjar.R.id.title
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@ -45,14 +44,16 @@ class BackgroundMode {
*/
private lateinit var playerNotification: PlayerNotificationManager
/**
* The [AudioAttributes] handle the audio focus of the [player]
*/
private lateinit var audioAttributes: AudioAttributes
/**
* Initializes the [player] with the [MediaItem].
*/
private fun initializePlayer(c: Context) {
/**
* The [audioAttributes] handle the audio focus of the [player]
*/
val audioAttributes = AudioAttributes.Builder()
audioAttributes = AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_MUSIC)
.build()
@ -68,12 +69,16 @@ class BackgroundMode {
/**
* Initializes the [playerNotification] attached to the [player] and shows it.
*/
private fun initializePlayerNotification(c: Context, streams: Streams) {
private fun initializePlayerNotification(c: Context) {
playerNotification = PlayerNotificationManager
.Builder(c, 1, "background_mode")
// set the description of the notification
.setMediaDescriptionAdapter(
DescriptionAdapter(streams.title!!, streams.uploader!!, streams.thumbnailUrl!!)
DescriptionAdapter(
response?.title!!,
response?.uploader!!,
response?.thumbnailUrl!!
)
)
.build()
playerNotification.apply {
@ -113,7 +118,7 @@ class BackgroundMode {
job.join()
initializePlayer(c)
initializePlayerNotification(c, response!!)
initializePlayerNotification(c)
player?.apply {
playWhenReady = playWhenReadyPlayer

View File

@ -0,0 +1,7 @@
package com.github.libretube
const val GITHUB_API_URL = "https://api.github.com/repos/libre-tube/LibreTube/releases/latest"
const val WEBSITE_URL = "https://libre-tube.github.io/"
const val AUTHORS_URL = "https://github.com/libre-tube/LibreTube/graphs/contributors"
const val DONATE_URL = "https://libre-tube.github.io/#donate"
const val CONTRIBUTING_URL = "https://github.com/libre-tube/LibreTube#donate"

View File

@ -32,7 +32,7 @@ class ChaptersAdapter(
chapterTitle.text = chapter.title
holder.v.setOnClickListener {
val chapterStart = chapter.start!!.toLong() * 1000 // multiply by thousand for ms -> s
val chapterStart = chapter.start!!.toLong() * 1000 // s -> ms
exoPlayer.seekTo(chapterStart)
}
}

View File

@ -828,6 +828,10 @@ class PlayerFragment : Fragment() {
}
private fun createExoPlayer(view: View) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val playbackSpeed = sharedPreferences.getString("playback_speed", "1F")?.toFloat()
val bufferingGoal = sharedPreferences.getString("buffering_goal", "50")?.toInt()!!
val cronetEngine: CronetEngine = CronetHelper.getCronetEngine()
val cronetDataSourceFactory: CronetDataSource.Factory =
CronetDataSource.Factory(cronetEngine, Executors.newCachedThreadPool())
@ -847,6 +851,12 @@ class PlayerFragment : Fragment() {
val loadControl = DefaultLoadControl.Builder()
// cache the last three minutes
.setBackBuffer(1000 * 60 * 3, true)
.setBufferDurationsMs(
DefaultLoadControl.DEFAULT_MIN_BUFFER_MS,
bufferingGoal * 1000, // buffering goal, s -> ms
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS,
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
)
.build()
exoPlayer = ExoPlayer.Builder(view.context)
@ -858,8 +868,6 @@ class PlayerFragment : Fragment() {
exoPlayer.setAudioAttributes(audioAttributes, true)
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val playbackSpeed = sharedPreferences.getString("playback_speed", "1F")?.toFloat()
exoPlayer.setPlaybackSpeed(playbackSpeed!!)
}

View File

@ -0,0 +1,7 @@
package com.github.libretube.obj
// data class for the update info, required to return the data
data class UpdateInfo(
val updateUrl: String,
val tagName: String
)

View File

@ -11,8 +11,12 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.github.libretube.AUTHORS_URL
import com.github.libretube.BuildConfig
import com.github.libretube.CONTRIBUTING_URL
import com.github.libretube.DONATE_URL
import com.github.libretube.R
import com.github.libretube.WEBSITE_URL
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AboutFragment : Fragment() {
@ -34,19 +38,19 @@ class AboutFragment : Fragment() {
val website = view.findViewById<LinearLayout>(R.id.website)
website.setOnClickListener {
openLinkFromHref("https://libre-tube.github.io/")
openLinkFromHref(WEBSITE_URL)
}
val authors = view.findViewById<LinearLayout>(R.id.authors)
authors.setOnClickListener {
openLinkFromHref("https://github.com/libre-tube/LibreTube/graphs/contributors")
openLinkFromHref(AUTHORS_URL)
}
val donate = view.findViewById<LinearLayout>(R.id.donate)
donate.setOnClickListener {
openLinkFromHref("https://libre-tube.github.io/#donate")
openLinkFromHref(DONATE_URL)
}
val contributing = view.findViewById<LinearLayout>(R.id.contributing)
contributing.setOnClickListener {
openLinkFromHref("https://github.com/libre-tube/LibreTube")
openLinkFromHref(CONTRIBUTING_URL)
}
val license = view.findViewById<LinearLayout>(R.id.license)
license.setOnClickListener {

View File

@ -7,7 +7,10 @@ import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerNotificationManager
import java.net.URL
// used to show title and thumbnail of the video in the notification
/**
* The [DescriptionAdapter] is used to show title, uploaderName and thumbnail of the video in the notification
* Basic example [here](https://github.com/AnthonyMarkD/AudioPlayerSampleTest)
*/
class DescriptionAdapter(
private val title: String,
private val channelName: String,

View File

@ -3,8 +3,10 @@ package com.github.libretube.util
import android.util.Log
import androidx.fragment.app.FragmentManager
import com.github.libretube.BuildConfig
import com.github.libretube.GITHUB_API_URL
import com.github.libretube.dialogs.NoUpdateAvailableDialog
import com.github.libretube.dialogs.UpdateAvailableDialog
import com.github.libretube.obj.UpdateInfo
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
@ -40,7 +42,7 @@ fun checkUpdate(childFragmentManager: FragmentManager) {
}
fun getUpdateInfo(): UpdateInfo? {
val latest = URL("https://api.github.com/repos/libre-tube/LibreTube/releases/latest")
val latest = URL(GITHUB_API_URL)
val json = StringBuilder()
val urlConnection: HttpsURLConnection?
urlConnection = latest.openConnection() as HttpsURLConnection
@ -49,7 +51,7 @@ fun getUpdateInfo(): UpdateInfo? {
var line: String?
while (br.readLine().also { line = it } != null) json.append(line)
// Parse and return json data
// Parse and return the json data
val jsonRoot = JSONObject(json.toString())
if (jsonRoot.has("tag_name") &&
jsonRoot.has("html_url") &&
@ -63,7 +65,7 @@ fun getUpdateInfo(): UpdateInfo? {
val name = jsonAsset.getString("name")
if (name.endsWith(".apk")) {
val tagName = jsonRoot.getString("name")
Log.i("", "Lastest version: $tagName")
Log.i("", "Latest version: $tagName")
return UpdateInfo(updateUrl, tagName)
}
}
@ -71,9 +73,3 @@ fun getUpdateInfo(): UpdateInfo? {
}
return null
}
// data class for the update info, required to return the data
data class UpdateInfo(
val updateUrl: String,
val tagName: String
)

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M16.24,7.76C15.07,6.59 13.54,6 12,6v6l-4.24,4.24c2.34,2.34 6.14,2.34 8.49,0 2.34,-2.34 2.34,-6.14 -0.01,-8.48zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" />
</vector>

View File

@ -2,12 +2,12 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/video_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginBottom="16dp"
android:background="?android:attr/selectableItemBackground"
android:id="@+id/video_search">
android:background="?android:attr/selectableItemBackground">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
@ -18,17 +18,17 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_search_thumbnail"
app:cardCornerRadius="8dp"
android:layout_width="0dp"
android:layout_height="0dp"
app:strokeWidth="0dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintEnd_toStartOf="@+id/guideline">
app:strokeWidth="0dp">
<ImageView
android:id="@+id/playlist_thumbnail"
@ -36,15 +36,27 @@
android:layout_height="match_parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<TextView
android:id="@+id/playlist_duration"
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="5dp"
android:textColor="@color/duration_text_color"
android:background="@color/duration_background_color"
android:padding="0.5dp" />
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/playlist_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:textColor="@color/duration_text_color"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<TextView
@ -71,11 +83,11 @@
android:id="@+id/delete_playlist"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded"
android:src="@drawable/ic_delete"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="?android:attr/selectableItemBackground"
android:padding="8dp"
android:visibility="gone" />
android:src="@drawable/ic_delete"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/roundedImageViewRounded" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="?android:attr/selectableItemBackground"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground">
<androidx.cardview.widget.CardView
android:id="@+id/thumbnailcard"
@ -13,28 +13,41 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:elevation="10dp"
app:cardCornerRadius="8dp"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:cardCornerRadius="8dp"
android:elevation="10dp">
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/thumbnail"
android:src="@mipmap/ic_launcher"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/thumbnail_duration"
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="5dp"
android:textColor="@color/duration_text_color"
android:background="@color/duration_background_color"
android:padding="0.5dp" />
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/thumbnail_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:textColor="@color/duration_text_color"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>
@ -45,24 +58,24 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="2"
android:text="Title"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/thumbnailcard"
app:layout_constraintStart_toEndOf="@+id/channel_image"
app:layout_constraintTop_toBottomOf="@+id/thumbnailcard"
android:ellipsize="end"
android:maxLines="2" />
app:layout_constraintTop_toBottomOf="@+id/thumbnailcard" />
<TextView
android:id="@+id/textView_channel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:text="Channel Name"
app:layout_constraintEnd_toEndOf="@+id/textView_title"
app:layout_constraintStart_toStartOf="@+id/textView_title"
app:layout_constraintTop_toBottomOf="@+id/textView_title"
android:paddingBottom="16dp" />
app:layout_constraintTop_toBottomOf="@+id/textView_title" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/channel_image"

View File

@ -2,11 +2,11 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/video_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="?android:attr/selectableItemBackground"
android:id="@+id/video_search">
android:background="?android:attr/selectableItemBackground">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
@ -17,17 +17,17 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_search_thumbnail"
app:cardCornerRadius="8dp"
android:layout_width="0dp"
android:layout_height="0dp"
app:strokeWidth="0dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintEnd_toStartOf="@+id/guideline">
app:strokeWidth="0dp">
<ImageView
android:id="@+id/channel_thumbnail"
@ -35,15 +35,28 @@
android:layout_height="match_parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<TextView
android:id="@+id/channel_duration"
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="5dp"
android:textColor="@color/duration_text_color"
android:background="@color/duration_background_color"
android:padding="0.5dp" />
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/channel_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:textColor="@color/duration_text_color"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<TextView

View File

@ -2,11 +2,11 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/video_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="?android:attr/selectableItemBackground"
android:id="@+id/video_search">
android:background="?android:attr/selectableItemBackground">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
@ -17,17 +17,17 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_search_thumbnail"
app:cardCornerRadius="8dp"
android:layout_width="0dp"
android:layout_height="0dp"
app:strokeWidth="0dp"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintEnd_toStartOf="@+id/guideline">
app:strokeWidth="0dp">
<ImageView
android:id="@+id/search_thumbnail"
@ -35,17 +35,30 @@
android:layout_height="match_parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<TextView
android:id="@+id/search_thumbnail_duration"
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="3dp"
android:textSize="11dp"
android:textColor="@color/duration_text_color"
android:background="@color/duration_background_color"
android:padding="0.5dp" />
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">
<TextView
android:id="@+id/search_thumbnail_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:textColor="@color/duration_text_color"
android:textSize="11sp"
tools:text="05:36" />
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
<TextView
@ -53,9 +66,9 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
android:maxLines="2"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toTopOf="parent" />
@ -83,9 +96,9 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
android:maxLines="1"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/search_channel_image"
app:layout_constraintTop_toBottomOf="@+id/search_views" />

View File

@ -659,4 +659,12 @@
<item>sdcard</item>
</string-array>
<string-array name="bufferingGoal">
<item>50</item>
<item>100</item>
<item>200</item>
<item>300</item>
<item>450</item>
</string-array>
</resources>

View File

@ -181,4 +181,6 @@
<string name="related_streams_summary">Show related streams to videos.</string>
<string name="show_chapters">Show chapters</string>
<string name="hide_chapters">Hide chapters</string>
<string name="buffering_goal">Buffering goal</string>
<string name="buffering_goal_summary">The amount of seconds videos get preloaded at maximum.</string>
</resources>

View File

@ -22,6 +22,15 @@
app:title="@string/playback_speed"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:icon="@drawable/ic_timelapse"
app:defaultValue="50"
app:entries="@array/bufferingGoal"
app:entryValues="@array/bufferingGoal"
app:key="buffering_goal"
app:title="@string/buffering_goal"
app:summary="@string/buffering_goal_summary" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/downloads">