Merge branch 'libre-tube:master' into master

This commit is contained in:
XelXen 2022-06-19 14:00:32 +05:30 committed by GitHub
commit 4a2a22e1fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 160 additions and 87 deletions

View File

@ -34,7 +34,8 @@
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:hardwareAccelerated="true"
android:screenOrientation="userPortrait">
android:screenOrientation="userPortrait"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@ -77,7 +77,8 @@ class BackgroundMode {
DescriptionAdapter(
response?.title!!,
response?.uploader!!,
response?.thumbnailUrl!!
response?.thumbnailUrl!!,
c
)
)
.build()

View File

@ -5,3 +5,4 @@ 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"
const val PIPED_GITHUB_URL = "https://github.com/TeamPiped/Piped"

View File

@ -58,9 +58,9 @@ class MainActivity : AppCompatActivity() {
RetrofitInstance.url =
sharedPreferences.getString("selectInstance", "https://pipedapi.kavin.rocks/")!!
SponsorBlockSettings.sponsorBlockEnabled =
sharedPreferences.getBoolean("sb_enabled_key", false)
sharedPreferences.getBoolean("sb_enabled_key", true)
SponsorBlockSettings.sponsorNotificationsEnabled =
sharedPreferences.getBoolean("sb_notifications_key", false)
sharedPreferences.getBoolean("sb_notifications_key", true)
SponsorBlockSettings.introEnabled =
sharedPreferences.getBoolean("intro_category_key", false)
SponsorBlockSettings.selfPromoEnabled =
@ -68,7 +68,7 @@ class MainActivity : AppCompatActivity() {
SponsorBlockSettings.interactionEnabled =
sharedPreferences.getBoolean("interaction_category_key", false)
SponsorBlockSettings.sponsorsEnabled =
sharedPreferences.getBoolean("sponsors_category_key", false)
sharedPreferences.getBoolean("sponsors_category_key", true)
SponsorBlockSettings.outroEnabled =
sharedPreferences.getBoolean("outro_category_key", false)
SponsorBlockSettings.fillerEnabled =

View File

@ -27,7 +27,6 @@ import android.widget.TextView
import android.widget.Toast
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.net.toUri
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
@ -87,8 +86,6 @@ import com.squareup.picasso.Picasso
import java.io.IOException
import java.util.concurrent.Executors
import kotlin.math.abs
import kotlinx.coroutines.NonCancellable.isActive
import org.chromium.base.ThreadUtils.runOnUiThread
import org.chromium.net.CronetEngine
import retrofit2.HttpException
@ -721,11 +718,11 @@ class PlayerFragment : Fragment() {
}
// create a list of subtitles
val subtitle = mutableListOf<SubtitleConfiguration>()
if (response.subtitles!!.isNotEmpty()) {
response.subtitles!!.forEach {
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).
SubtitleConfiguration.Builder(it.url!!.toUri())
.setMimeType(it.mimeType!!) // The correct MIME type (required).
.setLanguage(it.code) // The subtitle language (optional).
.build()
)
}
@ -867,7 +864,7 @@ class PlayerFragment : Fragment() {
playerNotification = PlayerNotificationManager
.Builder(c, 1, "background_mode")
.setMediaDescriptionAdapter(
DescriptionAdapter(title, uploader, thumbnailUrl)
DescriptionAdapter(title, uploader, thumbnailUrl, requireContext())
)
.build()

View File

@ -12,9 +12,9 @@ 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.PIPED_GITHUB_URL
import com.github.libretube.R
import com.github.libretube.WEBSITE_URL
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -33,9 +33,6 @@ class AboutFragment : Fragment() {
val topBarText = activity?.findViewById<TextView>(R.id.topBar_textView)
topBarText?.text = getString(R.string.about)
val appVersion = view.findViewById<TextView>(R.id.app_version)
appVersion.text = BuildConfig.VERSION_NAME
val website = view.findViewById<LinearLayout>(R.id.website)
website.setOnClickListener {
openLinkFromHref(WEBSITE_URL)
@ -44,6 +41,10 @@ class AboutFragment : Fragment() {
authors.setOnClickListener {
openLinkFromHref(AUTHORS_URL)
}
val piped = view.findViewById<LinearLayout>(R.id.piped)
piped.setOnClickListener {
openLinkFromHref(PIPED_GITHUB_URL)
}
val donate = view.findViewById<LinearLayout>(R.id.donate)
donate.setOnClickListener {
openLinkFromHref(DONATE_URL)

View File

@ -1,8 +1,11 @@
package com.github.libretube.util
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.github.libretube.MainActivity
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerNotificationManager
import java.net.URL
@ -14,32 +17,58 @@ import java.net.URL
class DescriptionAdapter(
private val title: String,
private val channelName: String,
private val thumbnailUrl: String
private val thumbnailUrl: String,
private val context: Context
) :
PlayerNotificationManager.MediaDescriptionAdapter {
/**
* sets the title of the notification
*/
override fun getCurrentContentTitle(player: Player): CharSequence {
// return controller.metadata.description.title.toString()
return title
}
/**
* overrides the action when clicking the notification
*/
override fun createCurrentContentIntent(player: Player): PendingIntent? {
// return controller.sessionActivity
return null
/**
* starts a new MainActivity Intent when the player notification is clicked
* it doesn't start a completely new MainActivity because the MainActivity's launchMode
* is set to "singleTop" in the AndroidManifest (important!!!)
* that's the only way to launch back into the previous activity (e.g. the player view
*/
val intent = Intent(context, MainActivity::class.java)
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
}
/**
* the description of the notification (below the title)
*/
override fun getCurrentContentText(player: Player): CharSequence? {
// return controller.metadata.description.subtitle.toString()
return channelName
}
/**
* return the icon/thumbnail of the video
*/
override fun getCurrentLargeIcon(
player: Player,
callback: PlayerNotificationManager.BitmapCallback
): Bitmap? {
lateinit var bitmap: Bitmap
/**
* running on a new thread to prevent a NetworkMainThreadException
*/
val thread = Thread {
try {
// try to parse the thumbnailUrl to a Bitmap
/**
* try to GET the thumbnail from the URL
*/
val inputStream = URL(thumbnailUrl).openStream()
bitmap = BitmapFactory.decodeStream(inputStream)
} catch (ex: java.lang.Exception) {
@ -48,9 +77,14 @@ class DescriptionAdapter(
}
thread.start()
thread.join()
// return bitmap if initialized
/**
* returns the scaled bitmap if it got fetched successfully
*/
return try {
bitmap
val resizedBitmap = Bitmap.createScaledBitmap(
bitmap, 1080, 1080, false
)
resizedBitmap
} catch (e: Exception) {
null
}

View File

@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M12,2c5.523,0 10,4.477 10,10s-4.477,10 -10,10c-1.702,0 -3.305,-0.425 -4.708,-1.175L2,22l1.176,-5.29C2.426,15.306 2,13.703 2,12 2,6.477 6.477,2 12,2zM13,7h-2v7h6v-2h-4L13,7z"/>
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.25,2.52 0.77,-1.28 -3.52,-2.09L13.5,8z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M12,2c5.523,0 10,4.477 10,10s-4.477,10 -10,10c-1.702,0 -3.305,-0.425 -4.708,-1.175L2,22l1.176,-5.29C2.426,15.306 2,13.703 2,12 2,6.477 6.477,2 12,2zM13,7h-2v7h6v-2h-4L13,7z" />
</vector>

View File

@ -4,11 +4,11 @@
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:pathData="M9,3h8a2,2 0,0 1,2 2v14a2,2 0,0 1,-2 2H9m6,-9 l-4,-4m4,4 l-4,4m4,-4H5"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="@android:color/black"
android:strokeLineCap="round"/>
<path
android:pathData="M9,3h8a2,2 0,0 1,2 2v14a2,2 0,0 1,-2 2H9m6,-9 l-4,-4m4,4 l-4,4m4,-4H5"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="@android:color/black"
android:strokeLineCap="round" />
</vector>

View File

@ -4,7 +4,7 @@
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M10,11H4V3a1,1 0,0 1,1 -1h14a1,1 0,0 1,1 1v18a1,1 0,0 1,-1 1H5a1,1 0,0 1,-1 -1v-8h6v3l5,-4 -5,-4v3z"/>
<path
android:fillColor="#FF000000"
android:pathData="M10,11H4V3a1,1 0,0 1,1 -1h14a1,1 0,0 1,1 1v18a1,1 0,0 1,-1 1H5a1,1 0,0 1,-1 -1v-8h6v3l5,-4 -5,-4v3z" />
</vector>

View File

@ -225,21 +225,21 @@
android:padding="@dimen/exo_styled_controls_padding"
android:clipToPadding="false">
<ImageButton
android:id="@id/exo_prev"
style="@style/ExoStyledControls.Button.Center.Previous" />
<include layout="@layout/exo_styled_player_control_rewind_button" />
<Button
android:id="@id/exo_rew_with_amount"
android:paddingLeft="4dp"
android:paddingRight="4dp"
style="@style/ExoStyledControls.Button.Center.RewWithAmount" />
<ImageButton
android:id="@id/exo_play_pause"
style="@style/ExoStyledControls.Button.Center.PlayPause" />
<include layout="@layout/exo_styled_player_control_ffwd_button" />
<ImageButton
android:id="@id/exo_next"
style="@style/ExoStyledControls.Button.Center.Next" />
<Button
android:id="@id/exo_ffwd_with_amount"
android:paddingLeft="4dp"
android:paddingRight="4dp"
style="@style/ExoStyledControls.Button.Center.FfwdWithAmount" />
</LinearLayout>

View File

@ -21,26 +21,16 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:text="LibreTube"
android:textSize="27sp"
android:textStyle="bold" />
<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="30dp"
android:textSize="18sp" />
<View style="@style/HorizontalLine" />
<LinearLayout
android:id="@+id/website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp">
style="@style/AboutItem">
<TextView
android:layout_width="match_parent"
@ -55,13 +45,11 @@
</LinearLayout>
<View style="@style/HorizontalLine" />
<LinearLayout
android:id="@+id/contributing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp">
style="@style/AboutItem">
<TextView
android:layout_width="match_parent"
@ -76,13 +64,11 @@
</LinearLayout>
<View style="@style/HorizontalLine" />
<LinearLayout
android:id="@+id/authors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp">
style="@style/AboutItem">
<TextView
android:layout_width="match_parent"
@ -97,13 +83,30 @@
</LinearLayout>
<View style="@style/HorizontalLine" />
<LinearLayout
android:id="@+id/piped"
style="@style/AboutItem">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/piped"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/piped_summary" />
</LinearLayout>
<View style="@style/HorizontalLine" />
<LinearLayout
android:id="@+id/donate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp">
style="@style/AboutItem">
<TextView
android:layout_width="match_parent"
@ -118,13 +121,11 @@
</LinearLayout>
<View style="@style/HorizontalLine" />
<LinearLayout
android:id="@+id/license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingVertical="10dp">
style="@style/AboutItem">
<TextView
android:layout_width="match_parent"

View File

@ -149,7 +149,7 @@
<string name="live">Live</string>
<string name="no_replies">This comment has no replies.</string>
<string name="authors">Authors</string>
<string name="authors_summary">Get to know everyone.</string>
<string name="authors_summary">Get to know everyone who is involved in developing and improving the app.</string>
<string name="download_folder">Name</string>
<string name="download_folder_summary">The name of the folder downloaded media is stored in.</string>
<string name="internal_storage">Internal storage</string>
@ -196,4 +196,5 @@
<string name="behavior">Behavior</string>
<string name="player_summary">Quality and player behavior</string>
<string name="seek_increment">Seek increment</string>
<string name="piped_summary">Piped is an open-source alternative web-frontend for YouTube provides the API we use. Without Piped, LibreTube wouldn\'t exist. Huge thanks to their devs!</string>
</resources>

View File

@ -23,4 +23,26 @@
</style>
<style name="AboutItem">
<item name="android:orientation">vertical</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingBottom">10dp</item>
</style>
<style name="HorizontalLine">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0.8dp</item>
<item name="android:background">@android:color/darker_gray</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
</style>
</resources>

View File

@ -35,7 +35,7 @@
<SwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_history"
android:icon="@drawable/ic_history_filled"
app:key="search_history_toggle"
app:title="@string/search_history" />

View File

@ -6,20 +6,23 @@
app:key="sb_enabled_key"
app:title="@string/sponsorblock"
android:summaryOff="@string/disabled"
android:summaryOn="@string/enabled" />
android:summaryOn="@string/enabled"
app:defaultValue="true" />
<SwitchPreferenceCompat
app:key="sb_notifications_key"
app:title="@string/sponsorblock_notifications"
android:summaryOff="@string/disabled"
android:summaryOn="@string/enabled" />
android:summaryOn="@string/enabled"
app:defaultValue="true" />
<PreferenceCategory app:title="@string/category_segments">
<SwitchPreferenceCompat
app:key="sponsors_category_key"
app:title="@string/category_sponsor"
app:summary="@string/category_sponsor_description" />
app:summary="@string/category_sponsor_description"
app:defaultValue="true" />
<SwitchPreferenceCompat
app:key="selfpromo_category_key"