mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-02-10 12:10:15 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff78dd108e | ||
|
|
b01ce34b55 | ||
|
|
c34bb67689 | ||
|
|
84e4ce8b46 | ||
|
|
0123b51638 |
@@ -6,13 +6,39 @@
|
|||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*.{kt,kts}]
|
[*.{kt,kts}]
|
||||||
ktlint_code_style = android_studio
|
ktlint_standard_annotation = disabled
|
||||||
# https://pinterest.github.io/ktlint/latest/rules/standard/#function-naming
|
ktlint_standard_argument-list-wrapping = disabled
|
||||||
ktlint_function_naming_ignore_when_annotated_with = Composable
|
ktlint_standard_backing-property-naming = disabled
|
||||||
|
ktlint_standard_blank-line-before-declaration = disabled
|
||||||
|
ktlint_standard_blank-line-between-when-conditions = disabled
|
||||||
|
ktlint_standard_chain-method-continuation = disabled
|
||||||
ktlint_standard_class-signature = disabled
|
ktlint_standard_class-signature = disabled
|
||||||
|
ktlint_standard_comment-wrapping = disabled
|
||||||
|
ktlint_standard_enum-wrapping = disabled
|
||||||
ktlint_standard_function-expression-body = disabled
|
ktlint_standard_function-expression-body = disabled
|
||||||
|
ktlint_standard_function-literal = disabled
|
||||||
|
ktlint_standard_function-signature = disabled
|
||||||
|
ktlint_standard_indent = disabled
|
||||||
|
ktlint_standard_kdoc = disabled
|
||||||
ktlint_standard_max-line-length = disabled
|
ktlint_standard_max-line-length = disabled
|
||||||
ktlint_standard_mixed-condition-operators = disabled
|
ktlint_standard_mixed-condition-operators = disabled
|
||||||
|
ktlint_standard_multiline-expression-wrapping = disabled
|
||||||
|
ktlint_standard_multiline-if-else = disabled
|
||||||
|
ktlint_standard_no-blank-line-in-list = disabled
|
||||||
|
ktlint_standard_no-consecutive-comments = disabled
|
||||||
|
ktlint_standard_no-empty-first-line-in-class-body = disabled
|
||||||
|
ktlint_standard_no-empty-first-line-in-method-block = disabled
|
||||||
|
ktlint_standard_no-line-break-after-else = disabled
|
||||||
|
ktlint_standard_no-semi = disabled
|
||||||
|
ktlint_standard_no-single-line-block-comment = disabled
|
||||||
ktlint_standard_package-name = disabled
|
ktlint_standard_package-name = disabled
|
||||||
|
ktlint_standard_parameter-list-wrapping = disabled
|
||||||
ktlint_standard_property-naming = disabled
|
ktlint_standard_property-naming = disabled
|
||||||
|
ktlint_standard_spacing-between-declarations-with-annotations = disabled
|
||||||
|
ktlint_standard_spacing-between-declarations-with-comments = disabled
|
||||||
|
ktlint_standard_statement-wrapping = disabled
|
||||||
|
ktlint_standard_string-template-indent = disabled
|
||||||
|
ktlint_standard_trailing-comma-on-call-site = disabled
|
||||||
|
ktlint_standard_trailing-comma-on-declaration-site = disabled
|
||||||
|
ktlint_standard_try-catch-finally-spacing = disabled
|
||||||
|
ktlint_standard_when-entry-bracing = disabled
|
||||||
|
|||||||
2
.github/workflows/backport-pr.yml
vendored
2
.github/workflows/backport-pr.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
|||||||
github.event.comment.author_association == 'MEMBER'
|
github.event.comment.author_association == 'MEMBER'
|
||||||
)
|
)
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v4
|
||||||
- name: Get backport metadata
|
- name: Get backport metadata
|
||||||
# the target branch is the first argument after `/backport`
|
# the target branch is the first argument after `/backport`
|
||||||
env:
|
env:
|
||||||
|
|||||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: gradle/actions/wrapper-validation@v5
|
- uses: gradle/actions/wrapper-validation@v4
|
||||||
|
|
||||||
- name: create and checkout branch
|
- name: create and checkout branch
|
||||||
# push events already checked out the branch
|
# push events already checked out the branch
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.android.build.api.dsl.ApplicationExtension
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.jetbrains.kotlin.android)
|
alias(libs.plugins.jetbrains.kotlin.android)
|
||||||
@@ -34,7 +32,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configure<ApplicationExtension> {
|
android {
|
||||||
compileSdk = 36
|
compileSdk = 36
|
||||||
namespace = "org.schabi.newpipe"
|
namespace = "org.schabi.newpipe"
|
||||||
|
|
||||||
@@ -44,9 +42,9 @@ configure<ApplicationExtension> {
|
|||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
|
|
||||||
versionCode = System.getProperty("versionCodeOverride")?.toInt() ?: 1008
|
versionCode = System.getProperty("versionCodeOverride")?.toInt() ?: 1006
|
||||||
|
|
||||||
versionName = "0.28.3"
|
versionName = "0.28.1"
|
||||||
System.getProperty("versionNameSuffix")?.let { versionNameSuffix = it }
|
System.getProperty("versionNameSuffix")?.let { versionNameSuffix = it }
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
@@ -79,16 +77,19 @@ configure<ApplicationExtension> {
|
|||||||
resValue("string", "app_name", "NewPipe $suffix")
|
resValue("string", "app_name", "NewPipe $suffix")
|
||||||
}
|
}
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
isShrinkResources = true
|
isShrinkResources = false // disabled to fix F-Droid"s reproducible build
|
||||||
proguardFiles(
|
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
||||||
"proguard-rules.pro"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lint {
|
lint {
|
||||||
lintConfig = file("lint.xml")
|
checkReleaseBuilds = false
|
||||||
|
// Or, if you prefer, you can continue to check for errors in release builds,
|
||||||
|
// but continue the build even when errors are found:
|
||||||
|
abortOnError = false
|
||||||
|
// suppress false warning ("Resource IDs will be non-final in Android Gradle Plugin version
|
||||||
|
// 5.0, avoid using them in switch case statements"), which affects only library projects
|
||||||
|
disable += "NonConstantResourceId"
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -99,7 +100,7 @@ configure<ApplicationExtension> {
|
|||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
getByName("androidTest") {
|
getByName("androidTest") {
|
||||||
assets.directories += "$projectDir/schemas"
|
assets.srcDir("$projectDir/schemas")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +111,6 @@ configure<ApplicationExtension> {
|
|||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
viewBinding = true
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
resValues = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
packaging {
|
packaging {
|
||||||
@@ -134,13 +134,6 @@ ksp {
|
|||||||
// Custom dependency configuration for ktlint
|
// Custom dependency configuration for ktlint
|
||||||
val ktlint by configurations.creating
|
val ktlint by configurations.creating
|
||||||
|
|
||||||
// https://checkstyle.org/#JRE_and_JDK
|
|
||||||
tasks.withType<Checkstyle>().configureEach {
|
|
||||||
javaLauncher = javaToolchains.launcherFor {
|
|
||||||
languageVersion = JavaLanguageVersion.of(21)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkstyle {
|
checkstyle {
|
||||||
configDirectory = rootProject.file("checkstyle")
|
configDirectory = rootProject.file("checkstyle")
|
||||||
isIgnoreFailures = false
|
isIgnoreFailures = false
|
||||||
|
|||||||
10
app/lint.xml
10
app/lint.xml
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
|
||||||
~ SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
-->
|
|
||||||
<lint>
|
|
||||||
<issue id="MissingTranslation" severity="ignore" />
|
|
||||||
<issue id="MissingQuantity" severity="ignore" />
|
|
||||||
<issue id="ImpliedQuantity" severity="ignore" />
|
|
||||||
</lint>
|
|
||||||
5
app/proguard-rules.pro
vendored
5
app/proguard-rules.pro
vendored
@@ -39,8 +39,3 @@
|
|||||||
|
|
||||||
## For some reason NotificationModeConfigFragment wasn't kept (only referenced in a preference xml)
|
## For some reason NotificationModeConfigFragment wasn't kept (only referenced in a preference xml)
|
||||||
-keep class org.schabi.newpipe.settings.notifications.** { *; }
|
-keep class org.schabi.newpipe.settings.notifications.** { *; }
|
||||||
|
|
||||||
# Prevent R8 from stripping or renaming Protobuf internal fields
|
|
||||||
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
|
|
||||||
<fields>;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -176,32 +176,28 @@ class DatabaseMigrationTest {
|
|||||||
|
|
||||||
databaseInV7.run {
|
databaseInV7.run {
|
||||||
insert(
|
insert(
|
||||||
"search_history",
|
"search_history", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("service_id", serviceId)
|
put("service_id", serviceId)
|
||||||
put("search", defaultSearch1)
|
put("search", defaultSearch1)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
insert(
|
insert(
|
||||||
"search_history",
|
"search_history", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("service_id", serviceId)
|
put("service_id", serviceId)
|
||||||
put("search", defaultSearch2)
|
put("search", defaultSearch2)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
insert(
|
insert(
|
||||||
"search_history",
|
"search_history", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("service_id", otherServiceId)
|
put("service_id", otherServiceId)
|
||||||
put("search", defaultSearch1)
|
put("search", defaultSearch1)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
insert(
|
insert(
|
||||||
"search_history",
|
"search_history", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("service_id", otherServiceId)
|
put("service_id", otherServiceId)
|
||||||
put("search", defaultSearch2)
|
put("search", defaultSearch2)
|
||||||
@@ -211,17 +207,13 @@ class DatabaseMigrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testHelper.runMigrationsAndValidate(
|
testHelper.runMigrationsAndValidate(
|
||||||
AppDatabase.DATABASE_NAME,
|
AppDatabase.DATABASE_NAME, Migrations.DB_VER_8,
|
||||||
Migrations.DB_VER_8,
|
true, Migrations.MIGRATION_7_8
|
||||||
true,
|
|
||||||
Migrations.MIGRATION_7_8
|
|
||||||
)
|
)
|
||||||
|
|
||||||
testHelper.runMigrationsAndValidate(
|
testHelper.runMigrationsAndValidate(
|
||||||
AppDatabase.DATABASE_NAME,
|
AppDatabase.DATABASE_NAME, Migrations.DB_VER_9,
|
||||||
Migrations.DB_VER_9,
|
true, Migrations.MIGRATION_8_9
|
||||||
true,
|
|
||||||
Migrations.MIGRATION_8_9
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val migratedDatabaseV8 = getMigratedDatabase()
|
val migratedDatabaseV8 = getMigratedDatabase()
|
||||||
@@ -243,8 +235,7 @@ class DatabaseMigrationTest {
|
|||||||
val remoteUid2: Long
|
val remoteUid2: Long
|
||||||
databaseInV8.run {
|
databaseInV8.run {
|
||||||
localUid1 = insert(
|
localUid1 = insert(
|
||||||
"playlists",
|
"playlists", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("name", DEFAULT_NAME + "1")
|
put("name", DEFAULT_NAME + "1")
|
||||||
put("is_thumbnail_permanent", false)
|
put("is_thumbnail_permanent", false)
|
||||||
@@ -252,8 +243,7 @@ class DatabaseMigrationTest {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
localUid2 = insert(
|
localUid2 = insert(
|
||||||
"playlists",
|
"playlists", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("name", DEFAULT_NAME + "2")
|
put("name", DEFAULT_NAME + "2")
|
||||||
put("is_thumbnail_permanent", false)
|
put("is_thumbnail_permanent", false)
|
||||||
@@ -261,29 +251,25 @@ class DatabaseMigrationTest {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
delete(
|
delete(
|
||||||
"playlists",
|
"playlists", "uid = ?",
|
||||||
"uid = ?",
|
|
||||||
Array(1) { localUid1 }
|
Array(1) { localUid1 }
|
||||||
)
|
)
|
||||||
remoteUid1 = insert(
|
remoteUid1 = insert(
|
||||||
"remote_playlists",
|
"remote_playlists", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("service_id", DEFAULT_SERVICE_ID)
|
put("service_id", DEFAULT_SERVICE_ID)
|
||||||
put("url", DEFAULT_URL)
|
put("url", DEFAULT_URL)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
remoteUid2 = insert(
|
remoteUid2 = insert(
|
||||||
"remote_playlists",
|
"remote_playlists", SQLiteDatabase.CONFLICT_FAIL,
|
||||||
SQLiteDatabase.CONFLICT_FAIL,
|
|
||||||
ContentValues().apply {
|
ContentValues().apply {
|
||||||
put("service_id", DEFAULT_SECOND_SERVICE_ID)
|
put("service_id", DEFAULT_SECOND_SERVICE_ID)
|
||||||
put("url", DEFAULT_SECOND_URL)
|
put("url", DEFAULT_SECOND_URL)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
delete(
|
delete(
|
||||||
"remote_playlists",
|
"remote_playlists", "uid = ?",
|
||||||
"uid = ?",
|
|
||||||
Array(1) { remoteUid2 }
|
Array(1) { remoteUid2 }
|
||||||
)
|
)
|
||||||
close()
|
close()
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import android.content.Context
|
|||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import java.io.IOException
|
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertNotNull
|
import org.junit.Assert.assertNotNull
|
||||||
@@ -22,6 +20,9 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
|||||||
import org.schabi.newpipe.extractor.ServiceList
|
import org.schabi.newpipe.extractor.ServiceList
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfo
|
import org.schabi.newpipe.extractor.channel.ChannelInfo
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType
|
import org.schabi.newpipe.extractor.stream.StreamType
|
||||||
|
import java.io.IOException
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import kotlin.streams.toList
|
||||||
|
|
||||||
class FeedDAOTest {
|
class FeedDAOTest {
|
||||||
private lateinit var db: AppDatabase
|
private lateinit var db: AppDatabase
|
||||||
@@ -40,21 +41,14 @@ class FeedDAOTest {
|
|||||||
private val stream7 = StreamEntity(7, serviceId, "https://youtube.com/watch?v=7", "stream 7", StreamType.VIDEO_STREAM, 1000, "channel-4", "https://youtube.com/channel/4", "https://i.ytimg.com/vi/1/hqdefault.jpg", 100, "2023-08-10", OffsetDateTime.parse("2023-08-10T00:00:00Z"))
|
private val stream7 = StreamEntity(7, serviceId, "https://youtube.com/watch?v=7", "stream 7", StreamType.VIDEO_STREAM, 1000, "channel-4", "https://youtube.com/channel/4", "https://i.ytimg.com/vi/1/hqdefault.jpg", 100, "2023-08-10", OffsetDateTime.parse("2023-08-10T00:00:00Z"))
|
||||||
|
|
||||||
private val allStreams = listOf(
|
private val allStreams = listOf(
|
||||||
stream1,
|
stream1, stream2, stream3, stream4, stream5, stream6, stream7
|
||||||
stream2,
|
|
||||||
stream3,
|
|
||||||
stream4,
|
|
||||||
stream5,
|
|
||||||
stream6,
|
|
||||||
stream7
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun createDb() {
|
fun createDb() {
|
||||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
db = Room.inMemoryDatabaseBuilder(
|
db = Room.inMemoryDatabaseBuilder(
|
||||||
context,
|
context, AppDatabase::class.java
|
||||||
AppDatabase::class.java
|
|
||||||
).build()
|
).build()
|
||||||
feedDAO = db.feedDAO()
|
feedDAO = db.feedDAO()
|
||||||
streamDAO = db.streamDAO()
|
streamDAO = db.streamDAO()
|
||||||
@@ -71,10 +65,7 @@ class FeedDAOTest {
|
|||||||
fun testUnlinkStreamsOlderThan_KeepOne() {
|
fun testUnlinkStreamsOlderThan_KeepOne() {
|
||||||
setupUnlinkDelete("2023-08-15T00:00:00Z")
|
setupUnlinkDelete("2023-08-15T00:00:00Z")
|
||||||
val streams = feedDAO.getStreams(
|
val streams = feedDAO.getStreams(
|
||||||
FeedGroupEntity.GROUP_ALL_ID,
|
FeedGroupEntity.GROUP_ALL_ID, includePlayed = true, includePartiallyPlayed = true, null
|
||||||
includePlayed = true,
|
|
||||||
includePartiallyPlayed = true,
|
|
||||||
null
|
|
||||||
)
|
)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
val allowedStreams = listOf(stream3, stream5, stream6, stream7)
|
val allowedStreams = listOf(stream3, stream5, stream6, stream7)
|
||||||
@@ -85,10 +76,7 @@ class FeedDAOTest {
|
|||||||
fun testUnlinkStreamsOlderThan_KeepMultiple() {
|
fun testUnlinkStreamsOlderThan_KeepMultiple() {
|
||||||
setupUnlinkDelete("2023-08-01T00:00:00Z")
|
setupUnlinkDelete("2023-08-01T00:00:00Z")
|
||||||
val streams = feedDAO.getStreams(
|
val streams = feedDAO.getStreams(
|
||||||
FeedGroupEntity.GROUP_ALL_ID,
|
FeedGroupEntity.GROUP_ALL_ID, includePlayed = true, includePartiallyPlayed = true, null
|
||||||
includePlayed = true,
|
|
||||||
includePartiallyPlayed = true,
|
|
||||||
null
|
|
||||||
)
|
)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
val allowedStreams = listOf(stream3, stream4, stream5, stream6, stream7)
|
val allowedStreams = listOf(stream3, stream4, stream5, stream6, stream7)
|
||||||
@@ -124,7 +112,7 @@ class FeedDAOTest {
|
|||||||
SubscriptionEntity.from(ChannelInfo(serviceId, "1", "https://youtube.com/channel/1", "https://youtube.com/channel/1", "channel-1")),
|
SubscriptionEntity.from(ChannelInfo(serviceId, "1", "https://youtube.com/channel/1", "https://youtube.com/channel/1", "channel-1")),
|
||||||
SubscriptionEntity.from(ChannelInfo(serviceId, "2", "https://youtube.com/channel/2", "https://youtube.com/channel/2", "channel-2")),
|
SubscriptionEntity.from(ChannelInfo(serviceId, "2", "https://youtube.com/channel/2", "https://youtube.com/channel/2", "channel-2")),
|
||||||
SubscriptionEntity.from(ChannelInfo(serviceId, "3", "https://youtube.com/channel/3", "https://youtube.com/channel/3", "channel-3")),
|
SubscriptionEntity.from(ChannelInfo(serviceId, "3", "https://youtube.com/channel/3", "https://youtube.com/channel/3", "channel-3")),
|
||||||
SubscriptionEntity.from(ChannelInfo(serviceId, "4", "https://youtube.com/channel/4", "https://youtube.com/channel/4", "channel-4"))
|
SubscriptionEntity.from(ChannelInfo(serviceId, "4", "https://youtube.com/channel/4", "https://youtube.com/channel/4", "channel-4")),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
feedDAO.insertAll(
|
feedDAO.insertAll(
|
||||||
@@ -135,7 +123,7 @@ class FeedDAOTest {
|
|||||||
FeedEntity(4, 2),
|
FeedEntity(4, 2),
|
||||||
FeedEntity(5, 2),
|
FeedEntity(5, 2),
|
||||||
FeedEntity(6, 3),
|
FeedEntity(6, 3),
|
||||||
FeedEntity(7, 4)
|
FeedEntity(7, 4),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package org.schabi.newpipe.local.history
|
package org.schabi.newpipe.local.history
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@@ -14,6 +11,9 @@ import org.schabi.newpipe.database.AppDatabase
|
|||||||
import org.schabi.newpipe.database.history.model.SearchHistoryEntry
|
import org.schabi.newpipe.database.history.model.SearchHistoryEntry
|
||||||
import org.schabi.newpipe.testUtil.TestDatabase
|
import org.schabi.newpipe.testUtil.TestDatabase
|
||||||
import org.schabi.newpipe.testUtil.TrampolineSchedulerRule
|
import org.schabi.newpipe.testUtil.TrampolineSchedulerRule
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
|
||||||
class HistoryRecordManagerTest {
|
class HistoryRecordManagerTest {
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class HistoryRecordManagerTest {
|
|||||||
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 0, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 0, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 2, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 2, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 1, search = "B"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 1, search = "B"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 0, search = "B")
|
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 0, search = "B"),
|
||||||
)
|
)
|
||||||
|
|
||||||
// make sure all 4 were inserted
|
// make sure all 4 were inserted
|
||||||
@@ -85,7 +85,7 @@ class HistoryRecordManagerTest {
|
|||||||
val entries = listOf(
|
val entries = listOf(
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 2, search = "B"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 2, search = "B"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 0, search = "C")
|
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 0, search = "C"),
|
||||||
)
|
)
|
||||||
|
|
||||||
// make sure all 3 were inserted
|
// make sure all 3 were inserted
|
||||||
@@ -98,6 +98,7 @@ class HistoryRecordManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun insertShuffledRelatedSearches(relatedSearches: Collection<SearchHistoryEntry>) {
|
private fun insertShuffledRelatedSearches(relatedSearches: Collection<SearchHistoryEntry>) {
|
||||||
|
|
||||||
// shuffle to make sure the order of items returned by queries depends only on
|
// shuffle to make sure the order of items returned by queries depends only on
|
||||||
// SearchHistoryEntry.creationDate, not on the actual insertion time, so that we can
|
// SearchHistoryEntry.creationDate, not on the actual insertion time, so that we can
|
||||||
// verify that the `ORDER BY` clause does its job
|
// verify that the `ORDER BY` clause does its job
|
||||||
@@ -120,7 +121,7 @@ class HistoryRecordManagerTest {
|
|||||||
RELATED_SEARCHES_ENTRIES[6].search, // A (even if in two places)
|
RELATED_SEARCHES_ENTRIES[6].search, // A (even if in two places)
|
||||||
RELATED_SEARCHES_ENTRIES[4].search, // B
|
RELATED_SEARCHES_ENTRIES[4].search, // B
|
||||||
RELATED_SEARCHES_ENTRIES[5].search, // AA
|
RELATED_SEARCHES_ENTRIES[5].search, // AA
|
||||||
RELATED_SEARCHES_ENTRIES[2].search // BA
|
RELATED_SEARCHES_ENTRIES[2].search, // BA
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ class HistoryRecordManagerTest {
|
|||||||
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 3, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 3, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 3, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 3, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 0, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 0, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 2, search = "AA")
|
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 2, search = "AA"),
|
||||||
)
|
)
|
||||||
insertShuffledRelatedSearches(relatedSearches)
|
insertShuffledRelatedSearches(relatedSearches)
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ class HistoryRecordManagerTest {
|
|||||||
assertThat(searches).containsExactly(
|
assertThat(searches).containsExactly(
|
||||||
RELATED_SEARCHES_ENTRIES[6].search, // A (even if in two places)
|
RELATED_SEARCHES_ENTRIES[6].search, // A (even if in two places)
|
||||||
RELATED_SEARCHES_ENTRIES[5].search, // AA
|
RELATED_SEARCHES_ENTRIES[5].search, // AA
|
||||||
RELATED_SEARCHES_ENTRIES[1].search // BA
|
RELATED_SEARCHES_ENTRIES[1].search, // BA
|
||||||
)
|
)
|
||||||
|
|
||||||
// also make sure that the string comparison is case insensitive
|
// also make sure that the string comparison is case insensitive
|
||||||
@@ -170,7 +171,7 @@ class HistoryRecordManagerTest {
|
|||||||
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 3, search = "A"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 3, search = "A"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 0, search = "B"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 0, search = "B"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 2, search = "AA"),
|
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 2, search = "AA"),
|
||||||
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A")
|
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,8 @@ class LocalPlaylistManagerTest {
|
|||||||
fun createPlaylist() {
|
fun createPlaylist() {
|
||||||
val NEWPIPE_URL = "https://newpipe.net/"
|
val NEWPIPE_URL = "https://newpipe.net/"
|
||||||
val stream = StreamEntity(
|
val stream = StreamEntity(
|
||||||
serviceId = 1,
|
serviceId = 1, url = NEWPIPE_URL, title = "title",
|
||||||
url = NEWPIPE_URL,
|
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
|
||||||
title = "title",
|
|
||||||
streamType = StreamType.VIDEO_STREAM,
|
|
||||||
duration = 1,
|
|
||||||
uploader = "uploader",
|
|
||||||
uploaderUrl = NEWPIPE_URL
|
uploaderUrl = NEWPIPE_URL
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,22 +58,14 @@ class LocalPlaylistManagerTest {
|
|||||||
@Test()
|
@Test()
|
||||||
fun createPlaylist_nonExistentStreamsAreUpserted() {
|
fun createPlaylist_nonExistentStreamsAreUpserted() {
|
||||||
val stream = StreamEntity(
|
val stream = StreamEntity(
|
||||||
serviceId = 1,
|
serviceId = 1, url = "https://newpipe.net/", title = "title",
|
||||||
url = "https://newpipe.net/",
|
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
|
||||||
title = "title",
|
|
||||||
streamType = StreamType.VIDEO_STREAM,
|
|
||||||
duration = 1,
|
|
||||||
uploader = "uploader",
|
|
||||||
uploaderUrl = "https://newpipe.net/"
|
uploaderUrl = "https://newpipe.net/"
|
||||||
)
|
)
|
||||||
database.streamDAO().insert(stream)
|
database.streamDAO().insert(stream)
|
||||||
val upserted = StreamEntity(
|
val upserted = StreamEntity(
|
||||||
serviceId = 1,
|
serviceId = 1, url = "https://newpipe.net/2", title = "title2",
|
||||||
url = "https://newpipe.net/2",
|
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
|
||||||
title = "title2",
|
|
||||||
streamType = StreamType.VIDEO_STREAM,
|
|
||||||
duration = 1,
|
|
||||||
uploader = "uploader",
|
|
||||||
uploaderUrl = "https://newpipe.net/"
|
uploaderUrl = "https://newpipe.net/"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,20 +17,21 @@ class TrampolineSchedulerRule : TestRule {
|
|||||||
|
|
||||||
private val scheduler = Schedulers.trampoline()
|
private val scheduler = Schedulers.trampoline()
|
||||||
|
|
||||||
override fun apply(base: Statement, description: Description): Statement = object : Statement() {
|
override fun apply(base: Statement, description: Description): Statement =
|
||||||
override fun evaluate() {
|
object : Statement() {
|
||||||
try {
|
override fun evaluate() {
|
||||||
RxJavaPlugins.setComputationSchedulerHandler { scheduler }
|
try {
|
||||||
RxJavaPlugins.setIoSchedulerHandler { scheduler }
|
RxJavaPlugins.setComputationSchedulerHandler { scheduler }
|
||||||
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler }
|
RxJavaPlugins.setIoSchedulerHandler { scheduler }
|
||||||
RxJavaPlugins.setSingleSchedulerHandler { scheduler }
|
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler }
|
||||||
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler }
|
RxJavaPlugins.setSingleSchedulerHandler { scheduler }
|
||||||
|
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler }
|
||||||
|
|
||||||
base.evaluate()
|
base.evaluate()
|
||||||
} finally {
|
} finally {
|
||||||
RxJavaPlugins.reset()
|
RxJavaPlugins.reset()
|
||||||
RxAndroidPlugins.reset()
|
RxAndroidPlugins.reset()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,51 +156,41 @@ class StreamItemAdapterTest {
|
|||||||
|
|
||||||
helper.assertInvalidResponse(getResponse(mapOf(Pair("content-length", "mp3"))), 0)
|
helper.assertInvalidResponse(getResponse(mapOf(Pair("content-length", "mp3"))), 0)
|
||||||
helper.assertInvalidResponse(
|
helper.assertInvalidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "filename=\"train.png\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "filename=\"train.png\""))), 1
|
||||||
1
|
|
||||||
)
|
)
|
||||||
helper.assertInvalidResponse(
|
helper.assertInvalidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"data.csv\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"data.csv\""))), 2
|
||||||
2
|
|
||||||
)
|
)
|
||||||
helper.assertInvalidResponse(
|
helper.assertInvalidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; filename=\"data.csv\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; filename=\"data.csv\""))), 3
|
||||||
3
|
|
||||||
)
|
)
|
||||||
helper.assertInvalidResponse(
|
helper.assertInvalidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"fieldName\"; filename*=\"filename.jpg\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"fieldName\"; filename*=\"filename.jpg\""))), 4
|
||||||
4
|
|
||||||
)
|
)
|
||||||
|
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "filename=\"train.ogg\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "filename=\"train.ogg\""))),
|
||||||
5,
|
5, MediaFormat.OGG
|
||||||
MediaFormat.OGG
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "some-form-data; filename=\"audio.flac\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "some-form-data; filename=\"audio.flac\""))),
|
||||||
6,
|
6, MediaFormat.FLAC
|
||||||
MediaFormat.FLAC
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"audio.aiff\"; filename=\"audio.aiff\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"audio.aiff\"; filename=\"audio.aiff\""))),
|
||||||
7,
|
7, MediaFormat.AIFF
|
||||||
MediaFormat.AIFF
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"alien?\"; filename*=UTF-8''%CE%B1%CE%BB%CE%B9%CF%B5%CE%BD.m4a"))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"alien?\"; filename*=UTF-8''%CE%B1%CE%BB%CE%B9%CF%B5%CE%BD.m4a"))),
|
||||||
8,
|
8, MediaFormat.M4A
|
||||||
MediaFormat.M4A
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"audio.mp3\"; filename=\"audio.opus\"; filename*=UTF-8''alien.opus"))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"audio.mp3\"; filename=\"audio.opus\"; filename*=UTF-8''alien.opus"))),
|
||||||
9,
|
9, MediaFormat.OPUS
|
||||||
MediaFormat.OPUS
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"audio.mp3\"; filename=\"audio.opus\"; filename*=\"UTF-8''alien.opus\""))),
|
getResponse(mapOf(Pair("Content-Disposition", "form-data; name=\"audio.mp3\"; filename=\"audio.opus\"; filename*=\"UTF-8''alien.opus\""))),
|
||||||
10,
|
10, MediaFormat.OPUS
|
||||||
MediaFormat.OPUS
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,24 +213,16 @@ class StreamItemAdapterTest {
|
|||||||
helper.assertInvalidResponse(getResponse(mapOf()), 7)
|
helper.assertInvalidResponse(getResponse(mapOf()), 7)
|
||||||
|
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Type", "audio/flac"))),
|
getResponse(mapOf(Pair("Content-Type", "audio/flac"))), 8, MediaFormat.FLAC
|
||||||
8,
|
|
||||||
MediaFormat.FLAC
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Type", "audio/wav"))),
|
getResponse(mapOf(Pair("Content-Type", "audio/wav"))), 9, MediaFormat.WAV
|
||||||
9,
|
|
||||||
MediaFormat.WAV
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Type", "audio/opus"))),
|
getResponse(mapOf(Pair("Content-Type", "audio/opus"))), 10, MediaFormat.OPUS
|
||||||
10,
|
|
||||||
MediaFormat.OPUS
|
|
||||||
)
|
)
|
||||||
helper.assertValidResponse(
|
helper.assertValidResponse(
|
||||||
getResponse(mapOf(Pair("Content-Type", "audio/aiff"))),
|
getResponse(mapOf(Pair("Content-Type", "audio/aiff"))), 11, MediaFormat.AIFF
|
||||||
11,
|
|
||||||
MediaFormat.AIFF
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,37 +230,39 @@ class StreamItemAdapterTest {
|
|||||||
* @return a list of video streams, in which their video only property mirrors the provided
|
* @return a list of video streams, in which their video only property mirrors the provided
|
||||||
* [videoOnly] vararg.
|
* [videoOnly] vararg.
|
||||||
*/
|
*/
|
||||||
private fun getVideoStreams(vararg videoOnly: Boolean) = StreamInfoWrapper(
|
private fun getVideoStreams(vararg videoOnly: Boolean) =
|
||||||
videoOnly.map {
|
StreamItemAdapter.StreamInfoWrapper(
|
||||||
VideoStream.Builder()
|
videoOnly.map {
|
||||||
.setId(Stream.ID_UNKNOWN)
|
VideoStream.Builder()
|
||||||
.setContent("https://example.com", true)
|
.setId(Stream.ID_UNKNOWN)
|
||||||
.setMediaFormat(MediaFormat.MPEG_4)
|
.setContent("https://example.com", true)
|
||||||
.setResolution("720p")
|
.setMediaFormat(MediaFormat.MPEG_4)
|
||||||
.setIsVideoOnly(it)
|
.setResolution("720p")
|
||||||
.build()
|
.setIsVideoOnly(it)
|
||||||
},
|
.build()
|
||||||
context
|
},
|
||||||
)
|
context
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a list of audio streams, containing valid and null elements mirroring the provided
|
* @return a list of audio streams, containing valid and null elements mirroring the provided
|
||||||
* [shouldBeValid] vararg.
|
* [shouldBeValid] vararg.
|
||||||
*/
|
*/
|
||||||
private fun getAudioStreams(vararg shouldBeValid: Boolean) = getSecondaryStreamsFromList(
|
private fun getAudioStreams(vararg shouldBeValid: Boolean) =
|
||||||
shouldBeValid.map {
|
getSecondaryStreamsFromList(
|
||||||
if (it) {
|
shouldBeValid.map {
|
||||||
AudioStream.Builder()
|
if (it) {
|
||||||
.setId(Stream.ID_UNKNOWN)
|
AudioStream.Builder()
|
||||||
.setContent("https://example.com", true)
|
.setId(Stream.ID_UNKNOWN)
|
||||||
.setMediaFormat(MediaFormat.OPUS)
|
.setContent("https://example.com", true)
|
||||||
.setAverageBitrate(192)
|
.setMediaFormat(MediaFormat.OPUS)
|
||||||
.build()
|
.setAverageBitrate(192)
|
||||||
} else {
|
.build()
|
||||||
null
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
|
|
||||||
private fun getIncompleteAudioStreams(size: Int): List<AudioStream> {
|
private fun getIncompleteAudioStreams(size: Int): List<AudioStream> {
|
||||||
val list = ArrayList<AudioStream>(size)
|
val list = ArrayList<AudioStream>(size)
|
||||||
@@ -308,7 +292,7 @@ class StreamItemAdapterTest {
|
|||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"normal visibility (pos=[$position]) is not correct",
|
"normal visibility (pos=[$position]) is not correct",
|
||||||
findViewById<View>(R.id.wo_sound_icon).visibility,
|
findViewById<View>(R.id.wo_sound_icon).visibility,
|
||||||
normalVisibility
|
normalVisibility,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
spinner.adapter.getDropDownView(position, null, spinner).run {
|
spinner.adapter.getDropDownView(position, null, spinner).run {
|
||||||
@@ -323,17 +307,18 @@ class StreamItemAdapterTest {
|
|||||||
/**
|
/**
|
||||||
* Helper function that builds a secondary stream list.
|
* Helper function that builds a secondary stream list.
|
||||||
*/
|
*/
|
||||||
private fun <T : Stream> getSecondaryStreamsFromList(streams: List<T?>) = SparseArrayCompat<SecondaryStreamHelper<T>?>(streams.size).apply {
|
private fun <T : Stream> getSecondaryStreamsFromList(streams: List<T?>) =
|
||||||
streams.forEachIndexed { index, stream ->
|
SparseArrayCompat<SecondaryStreamHelper<T>?>(streams.size).apply {
|
||||||
val secondaryStreamHelper: SecondaryStreamHelper<T>? = stream?.let {
|
streams.forEachIndexed { index, stream ->
|
||||||
SecondaryStreamHelper(
|
val secondaryStreamHelper: SecondaryStreamHelper<T>? = stream?.let {
|
||||||
StreamItemAdapter.StreamInfoWrapper(streams, context),
|
SecondaryStreamHelper(
|
||||||
it
|
StreamItemAdapter.StreamInfoWrapper(streams, context),
|
||||||
)
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
put(index, secondaryStreamHelper)
|
||||||
}
|
}
|
||||||
put(index, secondaryStreamHelper)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun getResponse(headers: Map<String, String>): Response {
|
private fun getResponse(headers: Map<String, String>): Response {
|
||||||
val listHeaders = HashMap<String, List<String>>()
|
val listHeaders = HashMap<String, List<String>>()
|
||||||
@@ -360,8 +345,7 @@ class StreamItemAdapterTest {
|
|||||||
index: Int
|
index: Int
|
||||||
) {
|
) {
|
||||||
assertFalse(
|
assertFalse(
|
||||||
"invalid header returns valid value",
|
"invalid header returns valid value", retrieveMediaFormat(streams[index], response)
|
||||||
retrieveMediaFormat(streams[index], response)
|
|
||||||
)
|
)
|
||||||
assertNull("Media format extracted although stated otherwise", wrapper.getFormat(index))
|
assertNull("Media format extracted although stated otherwise", wrapper.getFormat(index))
|
||||||
}
|
}
|
||||||
@@ -375,8 +359,7 @@ class StreamItemAdapterTest {
|
|||||||
format: MediaFormat
|
format: MediaFormat
|
||||||
) {
|
) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"header was not recognized",
|
"header was not recognized", retrieveMediaFormat(streams[index], response)
|
||||||
retrieveMediaFormat(streams[index], response)
|
|
||||||
)
|
)
|
||||||
assertEquals("Wrong media format extracted", format, wrapper.getFormat(index))
|
assertEquals("Wrong media format extracted", format, wrapper.getFormat(index))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,9 @@ public final class DownloaderImpl extends Downloader {
|
|||||||
|
|
||||||
String responseBodyToReturn = null;
|
String responseBodyToReturn = null;
|
||||||
try (ResponseBody body = response.body()) {
|
try (ResponseBody body = response.body()) {
|
||||||
responseBodyToReturn = body.string();
|
if (body != null) {
|
||||||
|
responseBodyToReturn = body.string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String latestUrl = response.request().url().toString();
|
final String latestUrl = response.request().url().toString();
|
||||||
|
|||||||
@@ -309,21 +309,25 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean drawerItemSelected(final MenuItem item) {
|
private boolean drawerItemSelected(final MenuItem item) {
|
||||||
final int groupId = item.getGroupId();
|
switch (item.getGroupId()) {
|
||||||
if (groupId == R.id.menu_services_group) {
|
case R.id.menu_services_group:
|
||||||
changeService(item);
|
changeService(item);
|
||||||
} else if (groupId == R.id.menu_tabs_group) {
|
break;
|
||||||
tabSelected(item);
|
case R.id.menu_tabs_group:
|
||||||
} else if (groupId == R.id.menu_kiosks_group) {
|
tabSelected(item);
|
||||||
try {
|
break;
|
||||||
kioskSelected(item);
|
case R.id.menu_kiosks_group:
|
||||||
} catch (final Exception e) {
|
try {
|
||||||
ErrorUtil.showUiErrorSnackbar(this, "Selecting drawer kiosk", e);
|
kioskSelected(item);
|
||||||
}
|
} catch (final Exception e) {
|
||||||
} else if (groupId == R.id.menu_options_about_group) {
|
ErrorUtil.showUiErrorSnackbar(this, "Selecting drawer kiosk", e);
|
||||||
optionsAboutSelected(item);
|
}
|
||||||
} else {
|
break;
|
||||||
return false;
|
case R.id.menu_options_about_group:
|
||||||
|
optionsAboutSelected(item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mainBinding.getRoot().closeDrawers();
|
mainBinding.getRoot().closeDrawers();
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.schabi.newpipe
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.room.Room.databaseBuilder
|
import androidx.room.Room.databaseBuilder
|
||||||
import kotlin.concurrent.Volatile
|
|
||||||
import org.schabi.newpipe.database.AppDatabase
|
import org.schabi.newpipe.database.AppDatabase
|
||||||
import org.schabi.newpipe.database.Migrations.MIGRATION_1_2
|
import org.schabi.newpipe.database.Migrations.MIGRATION_1_2
|
||||||
import org.schabi.newpipe.database.Migrations.MIGRATION_2_3
|
import org.schabi.newpipe.database.Migrations.MIGRATION_2_3
|
||||||
@@ -18,6 +17,7 @@ import org.schabi.newpipe.database.Migrations.MIGRATION_5_6
|
|||||||
import org.schabi.newpipe.database.Migrations.MIGRATION_6_7
|
import org.schabi.newpipe.database.Migrations.MIGRATION_6_7
|
||||||
import org.schabi.newpipe.database.Migrations.MIGRATION_7_8
|
import org.schabi.newpipe.database.Migrations.MIGRATION_7_8
|
||||||
import org.schabi.newpipe.database.Migrations.MIGRATION_8_9
|
import org.schabi.newpipe.database.Migrations.MIGRATION_8_9
|
||||||
|
import kotlin.concurrent.Volatile
|
||||||
|
|
||||||
object NewPipeDatabase {
|
object NewPipeDatabase {
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ import androidx.work.WorkerParameters
|
|||||||
import androidx.work.workDataOf
|
import androidx.work.workDataOf
|
||||||
import com.grack.nanojson.JsonParser
|
import com.grack.nanojson.JsonParser
|
||||||
import com.grack.nanojson.JsonParserException
|
import com.grack.nanojson.JsonParserException
|
||||||
import java.io.IOException
|
|
||||||
import org.schabi.newpipe.extractor.downloader.Response
|
import org.schabi.newpipe.extractor.downloader.Response
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
|
||||||
import org.schabi.newpipe.util.ReleaseVersionUtil
|
import org.schabi.newpipe.util.ReleaseVersionUtil
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class NewVersionWorker(
|
class NewVersionWorker(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -46,8 +46,7 @@ class NewVersionWorker(
|
|||||||
// Show toast stating that the app is up-to-date if the update check was manual.
|
// Show toast stating that the app is up-to-date if the update check was manual.
|
||||||
ContextCompat.getMainExecutor(applicationContext).execute {
|
ContextCompat.getMainExecutor(applicationContext).execute {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext,
|
applicationContext, R.string.app_update_unavailable_toast,
|
||||||
R.string.app_update_unavailable_toast,
|
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
@@ -59,11 +58,7 @@ class NewVersionWorker(
|
|||||||
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
|
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
val pendingIntent = PendingIntentCompat.getActivity(
|
val pendingIntent = PendingIntentCompat.getActivity(
|
||||||
applicationContext,
|
applicationContext, 0, intent, 0, false
|
||||||
0,
|
|
||||||
intent,
|
|
||||||
0,
|
|
||||||
false
|
|
||||||
)
|
)
|
||||||
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
|
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
|
||||||
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
|
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
|
||||||
@@ -76,15 +71,12 @@ class NewVersionWorker(
|
|||||||
)
|
)
|
||||||
.setContentText(
|
.setContentText(
|
||||||
applicationContext.getString(
|
applicationContext.getString(
|
||||||
R.string.app_update_available_notification_text,
|
R.string.app_update_available_notification_text, versionName
|
||||||
versionName
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val notificationManager = NotificationManagerCompat.from(applicationContext)
|
val notificationManager = NotificationManagerCompat.from(applicationContext)
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
notificationManager.notify(2000, notificationBuilder.build())
|
||||||
notificationManager.notify(2000, notificationBuilder.build())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class, ReCaptchaException::class)
|
@Throws(IOException::class, ReCaptchaException::class)
|
||||||
|
|||||||
@@ -41,50 +41,50 @@ public final class QueueItemMenuUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
popupMenu.setOnMenuItemClickListener(menuItem -> {
|
popupMenu.setOnMenuItemClickListener(menuItem -> {
|
||||||
final int itemId = menuItem.getItemId();
|
switch (menuItem.getItemId()) {
|
||||||
if (itemId == R.id.menu_item_remove) {
|
case R.id.menu_item_remove:
|
||||||
final int index = playQueue.indexOf(item);
|
final int index = playQueue.indexOf(item);
|
||||||
playQueue.remove(index);
|
playQueue.remove(index);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_item_details) {
|
case R.id.menu_item_details:
|
||||||
// playQueue is null since we don't want any queue change
|
// playQueue is null since we don't want any queue change
|
||||||
NavigationHelper.openVideoDetail(context, item.getServiceId(),
|
NavigationHelper.openVideoDetail(context, item.getServiceId(),
|
||||||
item.getUrl(), item.getTitle(), null,
|
item.getUrl(), item.getTitle(), null,
|
||||||
false);
|
false);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_item_append_playlist) {
|
case R.id.menu_item_append_playlist:
|
||||||
PlaylistDialog.createCorrespondingDialog(
|
PlaylistDialog.createCorrespondingDialog(
|
||||||
context,
|
context,
|
||||||
List.of(new StreamEntity(item)),
|
List.of(new StreamEntity(item)),
|
||||||
dialog -> dialog.show(
|
dialog -> dialog.show(
|
||||||
fragmentManager,
|
fragmentManager,
|
||||||
"QueueItemMenuUtil@append_playlist"
|
"QueueItemMenuUtil@append_playlist"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_item_channel_details) {
|
case R.id.menu_item_channel_details:
|
||||||
SparseItemUtil.fetchUploaderUrlIfSparse(context, item.getServiceId(),
|
SparseItemUtil.fetchUploaderUrlIfSparse(context, item.getServiceId(),
|
||||||
item.getUrl(), item.getUploaderUrl(),
|
item.getUrl(), item.getUploaderUrl(),
|
||||||
// An intent must be used here.
|
// An intent must be used here.
|
||||||
// Opening with FragmentManager transactions is not working,
|
// Opening with FragmentManager transactions is not working,
|
||||||
// as PlayQueueActivity doesn't use fragments.
|
// as PlayQueueActivity doesn't use fragments.
|
||||||
uploaderUrl -> NavigationHelper.openChannelFragmentUsingIntent(
|
uploaderUrl -> NavigationHelper.openChannelFragmentUsingIntent(
|
||||||
context, item.getServiceId(), uploaderUrl, item.getUploader()
|
context, item.getServiceId(), uploaderUrl, item.getUploader()
|
||||||
));
|
));
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_item_share) {
|
case R.id.menu_item_share:
|
||||||
shareText(context, item.getTitle(), item.getUrl(),
|
shareText(context, item.getTitle(), item.getUrl(),
|
||||||
item.getThumbnails());
|
item.getThumbnails());
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_item_download) {
|
case R.id.menu_item_download:
|
||||||
fetchStreamInfoAndSaveToDatabase(context, item.getServiceId(), item.getUrl(),
|
fetchStreamInfoAndSaveToDatabase(context, item.getServiceId(), item.getUrl(),
|
||||||
info -> {
|
info -> {
|
||||||
final DownloadDialog downloadDialog = new DownloadDialog(context,
|
final DownloadDialog downloadDialog = new DownloadDialog(context,
|
||||||
info);
|
info);
|
||||||
downloadDialog.show(fragmentManager, "downloadDialog");
|
downloadDialog.show(fragmentManager, "downloadDialog");
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class AboutActivity : AppCompatActivity() {
|
|||||||
return when (position) {
|
return when (position) {
|
||||||
posAbout -> AboutFragment()
|
posAbout -> AboutFragment()
|
||||||
posLicense -> LicenseFragment.newInstance(SOFTWARE_COMPONENTS)
|
posLicense -> LicenseFragment.newInstance(SOFTWARE_COMPONENTS)
|
||||||
else -> error("Unknown position for ViewPager2")
|
else -> throw IllegalArgumentException("Unknown position for ViewPager2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ class AboutActivity : AppCompatActivity() {
|
|||||||
return when (position) {
|
return when (position) {
|
||||||
posAbout -> R.string.tab_about
|
posAbout -> R.string.tab_about
|
||||||
posLicense -> R.string.tab_licenses
|
posLicense -> R.string.tab_licenses
|
||||||
else -> error("Unknown position for ViewPager2")
|
else -> throw IllegalArgumentException("Unknown position for ViewPager2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,145 +116,86 @@ class AboutActivity : AppCompatActivity() {
|
|||||||
*/
|
*/
|
||||||
private val SOFTWARE_COMPONENTS = arrayListOf(
|
private val SOFTWARE_COMPONENTS = arrayListOf(
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"ACRA",
|
"ACRA", "2013", "Kevin Gaudin",
|
||||||
"2013",
|
"https://github.com/ACRA/acra", StandardLicenses.APACHE2
|
||||||
"Kevin Gaudin",
|
|
||||||
"https://github.com/ACRA/acra",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"AndroidX",
|
"AndroidX", "2005 - 2011", "The Android Open Source Project",
|
||||||
"2005 - 2011",
|
"https://developer.android.com/jetpack", StandardLicenses.APACHE2
|
||||||
"The Android Open Source Project",
|
|
||||||
"https://developer.android.com/jetpack",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"ExoPlayer",
|
"ExoPlayer", "2014 - 2020", "Google, Inc.",
|
||||||
"2014 - 2020",
|
"https://github.com/google/ExoPlayer", StandardLicenses.APACHE2
|
||||||
"Google, Inc.",
|
|
||||||
"https://github.com/google/ExoPlayer",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"GigaGet",
|
"GigaGet", "2014 - 2015", "Peter Cai",
|
||||||
"2014 - 2015",
|
"https://github.com/PaperAirplane-Dev-Team/GigaGet", StandardLicenses.GPL3
|
||||||
"Peter Cai",
|
|
||||||
"https://github.com/PaperAirplane-Dev-Team/GigaGet",
|
|
||||||
StandardLicenses.GPL3
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Groupie",
|
"Groupie", "2016", "Lisa Wray",
|
||||||
"2016",
|
"https://github.com/lisawray/groupie", StandardLicenses.MIT
|
||||||
"Lisa Wray",
|
|
||||||
"https://github.com/lisawray/groupie",
|
|
||||||
StandardLicenses.MIT
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Android-State",
|
"Android-State", "2018", "Evernote",
|
||||||
"2018",
|
"https://github.com/Evernote/android-state", StandardLicenses.EPL1
|
||||||
"Evernote",
|
|
||||||
"https://github.com/Evernote/android-state",
|
|
||||||
StandardLicenses.EPL1
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Bridge",
|
"Bridge", "2021", "Livefront",
|
||||||
"2021",
|
"https://github.com/livefront/bridge", StandardLicenses.APACHE2
|
||||||
"Livefront",
|
|
||||||
"https://github.com/livefront/bridge",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Jsoup",
|
"Jsoup", "2009 - 2020", "Jonathan Hedley",
|
||||||
"2009 - 2020",
|
"https://github.com/jhy/jsoup", StandardLicenses.MIT
|
||||||
"Jonathan Hedley",
|
|
||||||
"https://github.com/jhy/jsoup",
|
|
||||||
StandardLicenses.MIT
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Markwon",
|
"Markwon", "2019", "Dimitry Ivanov",
|
||||||
"2019",
|
"https://github.com/noties/Markwon", StandardLicenses.APACHE2
|
||||||
"Dimitry Ivanov",
|
|
||||||
"https://github.com/noties/Markwon",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Material Components for Android",
|
"Material Components for Android", "2016 - 2020", "Google, Inc.",
|
||||||
"2016 - 2020",
|
|
||||||
"Google, Inc.",
|
|
||||||
"https://github.com/material-components/material-components-android",
|
"https://github.com/material-components/material-components-android",
|
||||||
StandardLicenses.APACHE2
|
StandardLicenses.APACHE2
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"NewPipe Extractor",
|
"NewPipe Extractor", "2017 - 2020", "Christian Schabesberger",
|
||||||
"2017 - 2020",
|
"https://github.com/TeamNewPipe/NewPipeExtractor", StandardLicenses.GPL3
|
||||||
"Christian Schabesberger",
|
|
||||||
"https://github.com/TeamNewPipe/NewPipeExtractor",
|
|
||||||
StandardLicenses.GPL3
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"NoNonsense-FilePicker",
|
"NoNonsense-FilePicker", "2016", "Jonas Kalderstam",
|
||||||
"2016",
|
"https://github.com/spacecowboy/NoNonsense-FilePicker", StandardLicenses.MPL2
|
||||||
"Jonas Kalderstam",
|
|
||||||
"https://github.com/spacecowboy/NoNonsense-FilePicker",
|
|
||||||
StandardLicenses.MPL2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"OkHttp",
|
"OkHttp", "2019", "Square, Inc.",
|
||||||
"2019",
|
"https://square.github.io/okhttp/", StandardLicenses.APACHE2
|
||||||
"Square, Inc.",
|
|
||||||
"https://square.github.io/okhttp/",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"Picasso",
|
"Picasso", "2013", "Square, Inc.",
|
||||||
"2013",
|
"https://square.github.io/picasso/", StandardLicenses.APACHE2
|
||||||
"Square, Inc.",
|
|
||||||
"https://square.github.io/picasso/",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"PrettyTime",
|
"PrettyTime", "2012 - 2020", "Lincoln Baxter, III",
|
||||||
"2012 - 2020",
|
"https://github.com/ocpsoft/prettytime", StandardLicenses.APACHE2
|
||||||
"Lincoln Baxter, III",
|
|
||||||
"https://github.com/ocpsoft/prettytime",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"ProcessPhoenix",
|
"ProcessPhoenix", "2015", "Jake Wharton",
|
||||||
"2015",
|
"https://github.com/JakeWharton/ProcessPhoenix", StandardLicenses.APACHE2
|
||||||
"Jake Wharton",
|
|
||||||
"https://github.com/JakeWharton/ProcessPhoenix",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"RxAndroid",
|
"RxAndroid", "2015", "The RxAndroid authors",
|
||||||
"2015",
|
"https://github.com/ReactiveX/RxAndroid", StandardLicenses.APACHE2
|
||||||
"The RxAndroid authors",
|
|
||||||
"https://github.com/ReactiveX/RxAndroid",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"RxBinding",
|
"RxBinding", "2015", "Jake Wharton",
|
||||||
"2015",
|
"https://github.com/JakeWharton/RxBinding", StandardLicenses.APACHE2
|
||||||
"Jake Wharton",
|
|
||||||
"https://github.com/JakeWharton/RxBinding",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"RxJava",
|
"RxJava", "2016 - 2020", "RxJava Contributors",
|
||||||
"2016 - 2020",
|
"https://github.com/ReactiveX/RxJava", StandardLicenses.APACHE2
|
||||||
"RxJava Contributors",
|
|
||||||
"https://github.com/ReactiveX/RxJava",
|
|
||||||
StandardLicenses.APACHE2
|
|
||||||
),
|
),
|
||||||
SoftwareComponent(
|
SoftwareComponent(
|
||||||
"SearchPreference",
|
"SearchPreference", "2018", "ByteHamster",
|
||||||
"2018",
|
"https://github.com/ByteHamster/SearchPreference", StandardLicenses.MIT
|
||||||
"ByteHamster",
|
),
|
||||||
"https://github.com/ByteHamster/SearchPreference",
|
|
||||||
StandardLicenses.MIT
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.schabi.newpipe.about
|
package org.schabi.newpipe.about
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import java.io.Serializable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for storing information about a software license.
|
* Class for storing information about a software license.
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ class LicenseFragment : Fragment() {
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { formattedLicense ->
|
.subscribe { formattedLicense ->
|
||||||
val webViewData = Base64.encodeToString(
|
val webViewData = Base64.encodeToString(
|
||||||
formattedLicense.toByteArray(),
|
formattedLicense.toByteArray(), Base64.NO_PADDING
|
||||||
Base64.NO_PADDING
|
|
||||||
)
|
)
|
||||||
val webView = WebView(context)
|
val webView = WebView(context)
|
||||||
webView.loadData(webViewData, "text/html; charset=UTF-8", "base64")
|
webView.loadData(webViewData, "text/html; charset=UTF-8", "base64")
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package org.schabi.newpipe.about
|
package org.schabi.newpipe.about
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import java.io.IOException
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.util.ThemeHelper
|
import org.schabi.newpipe.util.ThemeHelper
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context the context to use
|
* @param context the context to use
|
||||||
@@ -28,16 +28,13 @@ fun getFormattedLicense(context: Context, license: License): String {
|
|||||||
fun getLicenseStylesheet(context: Context): String {
|
fun getLicenseStylesheet(context: Context): String {
|
||||||
val isLightTheme = ThemeHelper.isLightThemeSelected(context)
|
val isLightTheme = ThemeHelper.isLightThemeSelected(context)
|
||||||
val licenseBackgroundColor = getHexRGBColor(
|
val licenseBackgroundColor = getHexRGBColor(
|
||||||
context,
|
context, if (isLightTheme) R.color.light_license_background_color else R.color.dark_license_background_color
|
||||||
if (isLightTheme) R.color.light_license_background_color else R.color.dark_license_background_color
|
|
||||||
)
|
)
|
||||||
val licenseTextColor = getHexRGBColor(
|
val licenseTextColor = getHexRGBColor(
|
||||||
context,
|
context, if (isLightTheme) R.color.light_license_text_color else R.color.dark_license_text_color
|
||||||
if (isLightTheme) R.color.light_license_text_color else R.color.dark_license_text_color
|
|
||||||
)
|
)
|
||||||
val youtubePrimaryColor = getHexRGBColor(
|
val youtubePrimaryColor = getHexRGBColor(
|
||||||
context,
|
context, if (isLightTheme) R.color.light_youtube_primary_color else R.color.dark_youtube_primary_color
|
||||||
if (isLightTheme) R.color.light_youtube_primary_color else R.color.dark_youtube_primary_color
|
|
||||||
)
|
)
|
||||||
return "body{padding:12px 15px;margin:0;background:#$licenseBackgroundColor;color:#$licenseTextColor}" +
|
return "body{padding:12px 15px;margin:0;background:#$licenseBackgroundColor;color:#$licenseTextColor}" +
|
||||||
"a[href]{color:#$youtubePrimaryColor}pre{white-space:pre-wrap}"
|
"a[href]{color:#$youtubePrimaryColor}pre{white-space:pre-wrap}"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.schabi.newpipe.about
|
package org.schabi.newpipe.about
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import java.io.Serializable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class SoftwareComponent
|
class SoftwareComponent
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package org.schabi.newpipe.database
|
package org.schabi.newpipe.database
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamType
|
||||||
|
import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType
|
|
||||||
import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
|
||||||
|
|
||||||
class Converters {
|
class Converters {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ interface LocalItem {
|
|||||||
PLAYLIST_REMOTE_ITEM,
|
PLAYLIST_REMOTE_ITEM,
|
||||||
|
|
||||||
PLAYLIST_STREAM_ITEM,
|
PLAYLIST_STREAM_ITEM,
|
||||||
STATISTIC_STREAM_ITEM
|
STATISTIC_STREAM_ITEM,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package org.schabi.newpipe.database
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.room.migration.Migration
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
|
|
||||||
object Migrations {
|
object Migrations {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import androidx.room.Transaction
|
|||||||
import androidx.room.Update
|
import androidx.room.Update
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.core.Maybe
|
import io.reactivex.rxjava3.core.Maybe
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.feed.model.FeedEntity
|
import org.schabi.newpipe.database.feed.model.FeedEntity
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity
|
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity
|
||||||
@@ -16,6 +15,7 @@ import org.schabi.newpipe.database.stream.StreamWithState
|
|||||||
import org.schabi.newpipe.database.stream.model.StreamStateEntity
|
import org.schabi.newpipe.database.stream.model.StreamStateEntity
|
||||||
import org.schabi.newpipe.database.subscription.NotificationMode
|
import org.schabi.newpipe.database.subscription.NotificationMode
|
||||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class FeedDAO {
|
abstract class FeedDAO {
|
||||||
|
|||||||
@@ -19,17 +19,13 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
|||||||
entity = StreamEntity::class,
|
entity = StreamEntity::class,
|
||||||
parentColumns = [StreamEntity.STREAM_ID],
|
parentColumns = [StreamEntity.STREAM_ID],
|
||||||
childColumns = [STREAM_ID],
|
childColumns = [STREAM_ID],
|
||||||
onDelete = ForeignKey.CASCADE,
|
onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE, deferred = true
|
||||||
onUpdate = ForeignKey.CASCADE,
|
|
||||||
deferred = true
|
|
||||||
),
|
),
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = SubscriptionEntity::class,
|
entity = SubscriptionEntity::class,
|
||||||
parentColumns = [SubscriptionEntity.SUBSCRIPTION_UID],
|
parentColumns = [SubscriptionEntity.SUBSCRIPTION_UID],
|
||||||
childColumns = [SUBSCRIPTION_ID],
|
childColumns = [SUBSCRIPTION_ID],
|
||||||
onDelete = ForeignKey.CASCADE,
|
onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE, deferred = true
|
||||||
onUpdate = ForeignKey.CASCADE,
|
|
||||||
deferred = true
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,18 +18,14 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
|||||||
entity = FeedGroupEntity::class,
|
entity = FeedGroupEntity::class,
|
||||||
parentColumns = [FeedGroupEntity.ID],
|
parentColumns = [FeedGroupEntity.ID],
|
||||||
childColumns = [GROUP_ID],
|
childColumns = [GROUP_ID],
|
||||||
onDelete = ForeignKey.CASCADE,
|
onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE, deferred = true
|
||||||
onUpdate = ForeignKey.CASCADE,
|
|
||||||
deferred = true
|
|
||||||
),
|
),
|
||||||
|
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = SubscriptionEntity::class,
|
entity = SubscriptionEntity::class,
|
||||||
parentColumns = [SubscriptionEntity.SUBSCRIPTION_UID],
|
parentColumns = [SubscriptionEntity.SUBSCRIPTION_UID],
|
||||||
childColumns = [SUBSCRIPTION_ID],
|
childColumns = [SUBSCRIPTION_ID],
|
||||||
onDelete = ForeignKey.CASCADE,
|
onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE, deferred = true
|
||||||
onUpdate = ForeignKey.CASCADE,
|
|
||||||
deferred = true
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import androidx.room.ColumnInfo
|
|||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity.Companion.FEED_LAST_UPDATED_TABLE
|
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity.Companion.FEED_LAST_UPDATED_TABLE
|
||||||
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity.Companion.SUBSCRIPTION_ID
|
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity.Companion.SUBSCRIPTION_ID
|
||||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = FEED_LAST_UPDATED_TABLE,
|
tableName = FEED_LAST_UPDATED_TABLE,
|
||||||
@@ -16,9 +16,7 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
|||||||
entity = SubscriptionEntity::class,
|
entity = SubscriptionEntity::class,
|
||||||
parentColumns = [SubscriptionEntity.SUBSCRIPTION_UID],
|
parentColumns = [SubscriptionEntity.SUBSCRIPTION_UID],
|
||||||
childColumns = [SUBSCRIPTION_ID],
|
childColumns = [SUBSCRIPTION_ID],
|
||||||
onDelete = ForeignKey.CASCADE,
|
onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE, deferred = true
|
||||||
onUpdate = ForeignKey.CASCADE,
|
|
||||||
deferred = true
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ data class SearchHistoryEntry @JvmOverloads constructor(
|
|||||||
|
|
||||||
@ColumnInfo(name = ID)
|
@ColumnInfo(name = ID)
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
val id: Long = 0
|
val id: Long = 0,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import androidx.room.Entity
|
|||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.ForeignKey.Companion.CASCADE
|
import androidx.room.ForeignKey.Companion.CASCADE
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.history.model.StreamHistoryEntity.Companion.JOIN_STREAM_ID
|
import org.schabi.newpipe.database.history.model.StreamHistoryEntity.Companion.JOIN_STREAM_ID
|
||||||
import org.schabi.newpipe.database.history.model.StreamHistoryEntity.Companion.STREAM_ACCESS_DATE
|
import org.schabi.newpipe.database.history.model.StreamHistoryEntity.Companion.STREAM_ACCESS_DATE
|
||||||
import org.schabi.newpipe.database.history.model.StreamHistoryEntity.Companion.STREAM_HISTORY_TABLE
|
import org.schabi.newpipe.database.history.model.StreamHistoryEntity.Companion.STREAM_HISTORY_TABLE
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity
|
import org.schabi.newpipe.database.stream.model.StreamEntity
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_ID
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_ID
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param streamUid the stream id this history item will refer to
|
* @param streamUid the stream id this history item will refer to
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package org.schabi.newpipe.database.history.model
|
|||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Embedded
|
import androidx.room.Embedded
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity
|
import org.schabi.newpipe.database.stream.model.StreamEntity
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||||
import org.schabi.newpipe.util.image.ImageStrategy
|
import org.schabi.newpipe.util.image.ImageStrategy
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
data class StreamHistoryEntry(
|
data class StreamHistoryEntry(
|
||||||
@Embedded
|
@Embedded
|
||||||
@@ -30,15 +30,16 @@ data class StreamHistoryEntry(
|
|||||||
accessDate.isEqual(other.accessDate)
|
accessDate.isEqual(other.accessDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toStreamInfoItem(): StreamInfoItem = StreamInfoItem(
|
fun toStreamInfoItem(): StreamInfoItem =
|
||||||
streamEntity.serviceId,
|
StreamInfoItem(
|
||||||
streamEntity.url,
|
streamEntity.serviceId,
|
||||||
streamEntity.title,
|
streamEntity.url,
|
||||||
streamEntity.streamType
|
streamEntity.title,
|
||||||
).apply {
|
streamEntity.streamType,
|
||||||
duration = streamEntity.duration
|
).apply {
|
||||||
uploaderName = streamEntity.uploader
|
duration = streamEntity.duration
|
||||||
uploaderUrl = streamEntity.uploaderUrl
|
uploaderName = streamEntity.uploader
|
||||||
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
|
uploaderUrl = streamEntity.uploaderUrl
|
||||||
}
|
thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ data class PlaylistEntity @JvmOverloads constructor(
|
|||||||
name = item.orderingName,
|
name = item.orderingName,
|
||||||
isThumbnailPermanent = item.isThumbnailPermanent!!,
|
isThumbnailPermanent = item.isThumbnailPermanent!!,
|
||||||
thumbnailStreamId = item.thumbnailStreamId!!,
|
thumbnailStreamId = item.thumbnailStreamId!!,
|
||||||
displayIndex = item.displayIndex!!
|
displayIndex = item.displayIndex!!,
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ package org.schabi.newpipe.database.stream
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Embedded
|
import androidx.room.Embedded
|
||||||
import androidx.room.Ignore
|
import androidx.room.Ignore
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.LocalItem
|
import org.schabi.newpipe.database.LocalItem
|
||||||
import org.schabi.newpipe.database.history.model.StreamHistoryEntity
|
import org.schabi.newpipe.database.history.model.StreamHistoryEntity
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity
|
import org.schabi.newpipe.database.stream.model.StreamEntity
|
||||||
import org.schabi.newpipe.database.stream.model.StreamStateEntity.Companion.STREAM_PROGRESS_MILLIS
|
import org.schabi.newpipe.database.stream.model.StreamStateEntity.Companion.STREAM_PROGRESS_MILLIS
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||||
import org.schabi.newpipe.util.image.ImageStrategy
|
import org.schabi.newpipe.util.image.ImageStrategy
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
data class StreamStatisticsEntry(
|
data class StreamStatisticsEntry(
|
||||||
@Embedded
|
@Embedded
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import androidx.room.Query
|
|||||||
import androidx.room.Transaction
|
import androidx.room.Transaction
|
||||||
import io.reactivex.rxjava3.core.Completable
|
import io.reactivex.rxjava3.core.Completable
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.BasicDAO
|
import org.schabi.newpipe.database.BasicDAO
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity
|
import org.schabi.newpipe.database.stream.model.StreamEntity
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_ID
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_ID
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType
|
import org.schabi.newpipe.extractor.stream.StreamType
|
||||||
import org.schabi.newpipe.util.StreamTypeUtil
|
import org.schabi.newpipe.util.StreamTypeUtil
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class StreamDAO : BasicDAO<StreamEntity> {
|
abstract class StreamDAO : BasicDAO<StreamEntity> {
|
||||||
@@ -87,10 +87,11 @@ abstract class StreamDAO : BasicDAO<StreamEntity> {
|
|||||||
|
|
||||||
private fun compareAndUpdateStream(newerStream: StreamEntity) {
|
private fun compareAndUpdateStream(newerStream: StreamEntity) {
|
||||||
val existentMinimalStream = getMinimalStreamForCompare(newerStream.serviceId, newerStream.url)
|
val existentMinimalStream = getMinimalStreamForCompare(newerStream.serviceId, newerStream.url)
|
||||||
?: error("Stream cannot be null just after insertion.")
|
?: throw IllegalStateException("Stream cannot be null just after insertion.")
|
||||||
newerStream.uid = existentMinimalStream.uid
|
newerStream.uid = existentMinimalStream.uid
|
||||||
|
|
||||||
if (!StreamTypeUtil.isLiveStream(newerStream.streamType)) {
|
if (!StreamTypeUtil.isLiveStream(newerStream.streamType)) {
|
||||||
|
|
||||||
// Use the existent upload date if the newer stream does not have a better precision
|
// Use the existent upload date if the newer stream does not have a better precision
|
||||||
// (i.e. is an approximation). This is done to prevent unnecessary changes.
|
// (i.e. is an approximation). This is done to prevent unnecessary changes.
|
||||||
val hasBetterPrecision =
|
val hasBetterPrecision =
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import androidx.room.Entity
|
|||||||
import androidx.room.Ignore
|
import androidx.room.Ignore
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import java.io.Serializable
|
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_SERVICE_ID
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_SERVICE_ID
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_TABLE
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_TABLE
|
||||||
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_URL
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_URL
|
||||||
@@ -16,6 +14,8 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
|||||||
import org.schabi.newpipe.extractor.stream.StreamType
|
import org.schabi.newpipe.extractor.stream.StreamType
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem
|
||||||
import org.schabi.newpipe.util.image.ImageStrategy
|
import org.schabi.newpipe.util.image.ImageStrategy
|
||||||
|
import java.io.Serializable
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = STREAM_TABLE,
|
tableName = STREAM_TABLE,
|
||||||
@@ -86,12 +86,8 @@ data class StreamEntity(
|
|||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
constructor(item: PlayQueueItem) : this(
|
constructor(item: PlayQueueItem) : this(
|
||||||
serviceId = item.serviceId,
|
serviceId = item.serviceId, url = item.url, title = item.title,
|
||||||
url = item.url,
|
streamType = item.streamType, duration = item.duration, uploader = item.uploader,
|
||||||
title = item.title,
|
|
||||||
streamType = item.streamType,
|
|
||||||
duration = item.duration,
|
|
||||||
uploader = item.uploader,
|
|
||||||
uploaderUrl = item.uploaderUrl,
|
uploaderUrl = item.uploaderUrl,
|
||||||
thumbnailUrl = ImageStrategy.imageListToDbUrl(item.thumbnails)
|
thumbnailUrl = ImageStrategy.imageListToDbUrl(item.thumbnails)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ abstract class SubscriptionDAO : BasicDAO<SubscriptionEntity> {
|
|||||||
entity.uid = uidFromInsert
|
entity.uid = uidFromInsert
|
||||||
} else {
|
} else {
|
||||||
val subscriptionIdFromDb = getSubscriptionIdInternal(entity.serviceId, entity.url!!)
|
val subscriptionIdFromDb = getSubscriptionIdInternal(entity.serviceId, entity.url!!)
|
||||||
?: error("Subscription cannot be null just after insertion.")
|
?: throw IllegalStateException("Subscription cannot be null just after insertion.")
|
||||||
entity.uid = subscriptionIdFromDb
|
entity.uid = subscriptionIdFromDb
|
||||||
|
|
||||||
update(entity)
|
update(entity)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import android.os.IBinder;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
@@ -32,6 +31,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.view.menu.ActionMenuItemView;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.collection.SparseArrayCompat;
|
import androidx.collection.SparseArrayCompat;
|
||||||
import androidx.documentfile.provider.DocumentFile;
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
@@ -113,7 +113,7 @@ public class DownloadDialog extends DialogFragment
|
|||||||
private StoredDirectoryHelper mainStorageAudio = null;
|
private StoredDirectoryHelper mainStorageAudio = null;
|
||||||
private StoredDirectoryHelper mainStorageVideo = null;
|
private StoredDirectoryHelper mainStorageVideo = null;
|
||||||
private DownloadManager downloadManager = null;
|
private DownloadManager downloadManager = null;
|
||||||
private MenuItem okButton = null;
|
private ActionMenuItemView okButton = null;
|
||||||
private Context context = null;
|
private Context context = null;
|
||||||
private boolean askForSavePath;
|
private boolean askForSavePath;
|
||||||
|
|
||||||
@@ -558,13 +558,17 @@ public class DownloadDialog extends DialogFragment
|
|||||||
}
|
}
|
||||||
boolean flag = true;
|
boolean flag = true;
|
||||||
|
|
||||||
if (checkedId == R.id.audio_button) {
|
switch (checkedId) {
|
||||||
setupAudioSpinner();
|
case R.id.audio_button:
|
||||||
} else if (checkedId == R.id.video_button) {
|
setupAudioSpinner();
|
||||||
setupVideoSpinner();
|
break;
|
||||||
} else if (checkedId == R.id.subtitle_button) {
|
case R.id.video_button:
|
||||||
setupSubtitleSpinner();
|
setupVideoSpinner();
|
||||||
flag = false;
|
break;
|
||||||
|
case R.id.subtitle_button:
|
||||||
|
setupSubtitleSpinner();
|
||||||
|
flag = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogBinding.threads.setEnabled(flag);
|
dialogBinding.threads.setEnabled(flag);
|
||||||
@@ -581,26 +585,29 @@ public class DownloadDialog extends DialogFragment
|
|||||||
+ "position = [" + position + "], id = [" + id + "]");
|
+ "position = [" + position + "], id = [" + id + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
final int parentId = parent.getId();
|
switch (parent.getId()) {
|
||||||
if (parentId == R.id.quality_spinner) {
|
case R.id.quality_spinner:
|
||||||
final int checkedRadioButtonId = dialogBinding.videoAudioGroup
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
||||||
.getCheckedRadioButtonId();
|
case R.id.video_button:
|
||||||
if (checkedRadioButtonId == R.id.video_button) {
|
selectedVideoIndex = position;
|
||||||
selectedVideoIndex = position;
|
onVideoStreamSelected();
|
||||||
onVideoStreamSelected();
|
break;
|
||||||
} else if (checkedRadioButtonId == R.id.subtitle_button) {
|
case R.id.subtitle_button:
|
||||||
selectedSubtitleIndex = position;
|
selectedSubtitleIndex = position;
|
||||||
}
|
break;
|
||||||
onItemSelectedSetFileName();
|
}
|
||||||
} else if (parentId == R.id.audio_track_spinner) {
|
onItemSelectedSetFileName();
|
||||||
final boolean trackChanged = selectedAudioTrackIndex != position;
|
break;
|
||||||
selectedAudioTrackIndex = position;
|
case R.id.audio_track_spinner:
|
||||||
if (trackChanged) {
|
final boolean trackChanged = selectedAudioTrackIndex != position;
|
||||||
updateSecondaryStreams();
|
selectedAudioTrackIndex = position;
|
||||||
fetchStreamsSize();
|
if (trackChanged) {
|
||||||
}
|
updateSecondaryStreams();
|
||||||
} else if (parentId == R.id.audio_stream_spinner) {
|
fetchStreamsSize();
|
||||||
selectedAudioIndex = position;
|
}
|
||||||
|
break;
|
||||||
|
case R.id.audio_stream_spinner:
|
||||||
|
selectedAudioIndex = position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,20 +622,23 @@ public class DownloadDialog extends DialogFragment
|
|||||||
|| prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) {
|
|| prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) {
|
||||||
// only update the file name field if it was not edited by the user
|
// only update the file name field if it was not edited by the user
|
||||||
|
|
||||||
final int radioButtonId = dialogBinding.videoAudioGroup
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
||||||
.getCheckedRadioButtonId();
|
case R.id.audio_button:
|
||||||
if (radioButtonId == R.id.audio_button || radioButtonId == R.id.video_button) {
|
case R.id.video_button:
|
||||||
if (!prevFileName.equals(fileName)) {
|
if (!prevFileName.equals(fileName)) {
|
||||||
// since the user might have switched between audio and video, the correct
|
// since the user might have switched between audio and video, the correct
|
||||||
// text might already be in place, so avoid resetting the cursor position
|
// text might already be in place, so avoid resetting the cursor position
|
||||||
dialogBinding.fileName.setText(fileName);
|
dialogBinding.fileName.setText(fileName);
|
||||||
}
|
}
|
||||||
} else if (radioButtonId == R.id.subtitle_button) {
|
break;
|
||||||
final String setSubtitleLanguageCode = subtitleStreamsAdapter
|
|
||||||
.getItem(selectedSubtitleIndex).getLanguageTag();
|
case R.id.subtitle_button:
|
||||||
// this will reset the cursor position, which is bad UX, but it can't be avoided
|
final String setSubtitleLanguageCode = subtitleStreamsAdapter
|
||||||
dialogBinding.fileName.setText(getString(
|
.getItem(selectedSubtitleIndex).getLanguageTag();
|
||||||
R.string.caption_file_name, fileName, setSubtitleLanguageCode));
|
// this will reset the cursor position, which is bad UX, but it can't be avoided
|
||||||
|
dialogBinding.fileName.setText(getString(
|
||||||
|
R.string.caption_file_name, fileName, setSubtitleLanguageCode));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -760,44 +770,47 @@ public class DownloadDialog extends DialogFragment
|
|||||||
|
|
||||||
filenameTmp = getNameEditText().concat(".");
|
filenameTmp = getNameEditText().concat(".");
|
||||||
|
|
||||||
final int checkedRadioButtonId = dialogBinding.videoAudioGroup.getCheckedRadioButtonId();
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
||||||
if (checkedRadioButtonId == R.id.audio_button) {
|
case R.id.audio_button:
|
||||||
selectedMediaType = getString(R.string.last_download_type_audio_key);
|
selectedMediaType = getString(R.string.last_download_type_audio_key);
|
||||||
mainStorage = mainStorageAudio;
|
mainStorage = mainStorageAudio;
|
||||||
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
|
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
|
||||||
size = getWrappedAudioStreams().getSizeInBytes(selectedAudioIndex);
|
size = getWrappedAudioStreams().getSizeInBytes(selectedAudioIndex);
|
||||||
if (format == MediaFormat.WEBMA_OPUS) {
|
if (format == MediaFormat.WEBMA_OPUS) {
|
||||||
mimeTmp = "audio/ogg";
|
mimeTmp = "audio/ogg";
|
||||||
filenameTmp += "opus";
|
filenameTmp += "opus";
|
||||||
} else if (format != null) {
|
} else if (format != null) {
|
||||||
mimeTmp = format.mimeType;
|
mimeTmp = format.mimeType;
|
||||||
filenameTmp += format.getSuffix();
|
filenameTmp += format.getSuffix();
|
||||||
}
|
}
|
||||||
} else if (checkedRadioButtonId == R.id.video_button) {
|
break;
|
||||||
selectedMediaType = getString(R.string.last_download_type_video_key);
|
case R.id.video_button:
|
||||||
mainStorage = mainStorageVideo;
|
selectedMediaType = getString(R.string.last_download_type_video_key);
|
||||||
format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat();
|
mainStorage = mainStorageVideo;
|
||||||
size = wrappedVideoStreams.getSizeInBytes(selectedVideoIndex);
|
format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat();
|
||||||
if (format != null) {
|
size = wrappedVideoStreams.getSizeInBytes(selectedVideoIndex);
|
||||||
mimeTmp = format.mimeType;
|
if (format != null) {
|
||||||
filenameTmp += format.getSuffix();
|
mimeTmp = format.mimeType;
|
||||||
}
|
filenameTmp += format.getSuffix();
|
||||||
} else if (checkedRadioButtonId == R.id.subtitle_button) {
|
}
|
||||||
selectedMediaType = getString(R.string.last_download_type_subtitle_key);
|
break;
|
||||||
mainStorage = mainStorageVideo; // subtitle & video files go together
|
case R.id.subtitle_button:
|
||||||
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
|
selectedMediaType = getString(R.string.last_download_type_subtitle_key);
|
||||||
size = wrappedSubtitleStreams.getSizeInBytes(selectedSubtitleIndex);
|
mainStorage = mainStorageVideo; // subtitle & video files go together
|
||||||
if (format != null) {
|
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
|
||||||
mimeTmp = format.mimeType;
|
size = wrappedSubtitleStreams.getSizeInBytes(selectedSubtitleIndex);
|
||||||
}
|
if (format != null) {
|
||||||
|
mimeTmp = format.mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
if (format == MediaFormat.TTML) {
|
if (format == MediaFormat.TTML) {
|
||||||
filenameTmp += MediaFormat.SRT.getSuffix();
|
filenameTmp += MediaFormat.SRT.getSuffix();
|
||||||
} else if (format != null) {
|
} else if (format != null) {
|
||||||
filenameTmp += format.getSuffix();
|
filenameTmp += format.getSuffix();
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
throw new RuntimeException("No stream selected");
|
default:
|
||||||
|
throw new RuntimeException("No stream selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!askForSavePath && (mainStorage == null
|
if (!askForSavePath && (mainStorage == null
|
||||||
@@ -1044,56 +1057,59 @@ public class DownloadDialog extends DialogFragment
|
|||||||
long nearLength = 0;
|
long nearLength = 0;
|
||||||
|
|
||||||
// more download logic: select muxer, subtitle converter, etc.
|
// more download logic: select muxer, subtitle converter, etc.
|
||||||
final int checkedRadioButtonId = dialogBinding.videoAudioGroup.getCheckedRadioButtonId();
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
||||||
if (checkedRadioButtonId == R.id.audio_button) {
|
case R.id.audio_button:
|
||||||
kind = 'a';
|
kind = 'a';
|
||||||
selectedStream = audioStreamsAdapter.getItem(selectedAudioIndex);
|
selectedStream = audioStreamsAdapter.getItem(selectedAudioIndex);
|
||||||
|
|
||||||
if (selectedStream.getFormat() == MediaFormat.M4A) {
|
if (selectedStream.getFormat() == MediaFormat.M4A) {
|
||||||
psName = Postprocessing.ALGORITHM_M4A_NO_DASH;
|
psName = Postprocessing.ALGORITHM_M4A_NO_DASH;
|
||||||
} else if (selectedStream.getFormat() == MediaFormat.WEBMA_OPUS) {
|
} else if (selectedStream.getFormat() == MediaFormat.WEBMA_OPUS) {
|
||||||
psName = Postprocessing.ALGORITHM_OGG_FROM_WEBM_DEMUXER;
|
psName = Postprocessing.ALGORITHM_OGG_FROM_WEBM_DEMUXER;
|
||||||
}
|
|
||||||
} else if (checkedRadioButtonId == R.id.video_button) {
|
|
||||||
kind = 'v';
|
|
||||||
selectedStream = videoStreamsAdapter.getItem(selectedVideoIndex);
|
|
||||||
|
|
||||||
final SecondaryStreamHelper<AudioStream> secondary = videoStreamsAdapter
|
|
||||||
.getAllSecondary()
|
|
||||||
.get(wrappedVideoStreams.getStreamsList().indexOf(selectedStream));
|
|
||||||
|
|
||||||
if (secondary != null) {
|
|
||||||
secondaryStream = secondary.getStream();
|
|
||||||
|
|
||||||
if (selectedStream.getFormat() == MediaFormat.MPEG_4) {
|
|
||||||
psName = Postprocessing.ALGORITHM_MP4_FROM_DASH_MUXER;
|
|
||||||
} else {
|
|
||||||
psName = Postprocessing.ALGORITHM_WEBM_MUXER;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case R.id.video_button:
|
||||||
|
kind = 'v';
|
||||||
|
selectedStream = videoStreamsAdapter.getItem(selectedVideoIndex);
|
||||||
|
|
||||||
final long videoSize = wrappedVideoStreams.getSizeInBytes(
|
final SecondaryStreamHelper<AudioStream> secondary = videoStreamsAdapter
|
||||||
(VideoStream) selectedStream);
|
.getAllSecondary()
|
||||||
|
.get(wrappedVideoStreams.getStreamsList().indexOf(selectedStream));
|
||||||
|
|
||||||
// set nearLength, only, if both sizes are fetched or known. This probably
|
if (secondary != null) {
|
||||||
// does not work on slow networks but is later updated in the downloader
|
secondaryStream = secondary.getStream();
|
||||||
if (secondary.getSizeInBytes() > 0 && videoSize > 0) {
|
|
||||||
nearLength = secondary.getSizeInBytes() + videoSize;
|
if (selectedStream.getFormat() == MediaFormat.MPEG_4) {
|
||||||
|
psName = Postprocessing.ALGORITHM_MP4_FROM_DASH_MUXER;
|
||||||
|
} else {
|
||||||
|
psName = Postprocessing.ALGORITHM_WEBM_MUXER;
|
||||||
|
}
|
||||||
|
|
||||||
|
final long videoSize = wrappedVideoStreams.getSizeInBytes(
|
||||||
|
(VideoStream) selectedStream);
|
||||||
|
|
||||||
|
// set nearLength, only, if both sizes are fetched or known. This probably
|
||||||
|
// does not work on slow networks but is later updated in the downloader
|
||||||
|
if (secondary.getSizeInBytes() > 0 && videoSize > 0) {
|
||||||
|
nearLength = secondary.getSizeInBytes() + videoSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} else if (checkedRadioButtonId == R.id.subtitle_button) {
|
case R.id.subtitle_button:
|
||||||
threads = 1; // use unique thread for subtitles due small file size
|
threads = 1; // use unique thread for subtitles due small file size
|
||||||
kind = 's';
|
kind = 's';
|
||||||
selectedStream = subtitleStreamsAdapter.getItem(selectedSubtitleIndex);
|
selectedStream = subtitleStreamsAdapter.getItem(selectedSubtitleIndex);
|
||||||
|
|
||||||
if (selectedStream.getFormat() == MediaFormat.TTML) {
|
if (selectedStream.getFormat() == MediaFormat.TTML) {
|
||||||
psName = Postprocessing.ALGORITHM_TTML_CONVERTER;
|
psName = Postprocessing.ALGORITHM_TTML_CONVERTER;
|
||||||
psArgs = new String[]{
|
psArgs = new String[] {
|
||||||
selectedStream.getFormat().getSuffix(),
|
selectedStream.getFormat().getSuffix(),
|
||||||
"false" // ignore empty frames
|
"false" // ignore empty frames
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
return;
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondaryStream == null) {
|
if (secondaryStream == null) {
|
||||||
|
|||||||
@@ -133,16 +133,17 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
final int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == android.R.id.home) {
|
case android.R.id.home:
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.menu_item_share_error) {
|
case R.id.menu_item_share_error:
|
||||||
ShareUtils.shareText(getApplicationContext(),
|
ShareUtils.shareText(getApplicationContext(),
|
||||||
getString(R.string.error_report_title), buildJson());
|
getString(R.string.error_report_title), buildJson());
|
||||||
return true;
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openPrivacyPolicyDialog(final Context context, final String action) {
|
private void openPrivacyPolicyDialog(final Context context, final String action) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import androidx.core.content.ContextCompat
|
|||||||
import com.google.android.exoplayer2.ExoPlaybackException
|
import com.google.android.exoplayer2.ExoPlaybackException
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource
|
import com.google.android.exoplayer2.upstream.HttpDataSource
|
||||||
import com.google.android.exoplayer2.upstream.Loader
|
import com.google.android.exoplayer2.upstream.Loader
|
||||||
import java.net.UnknownHostException
|
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.Info
|
import org.schabi.newpipe.extractor.Info
|
||||||
@@ -29,6 +28,7 @@ import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentExcepti
|
|||||||
import org.schabi.newpipe.ktx.isNetworkRelated
|
import org.schabi.newpipe.ktx.isNetworkRelated
|
||||||
import org.schabi.newpipe.player.mediasource.FailedMediaSource
|
import org.schabi.newpipe.player.mediasource.FailedMediaSource
|
||||||
import org.schabi.newpipe.player.resolver.PlaybackResolver
|
import org.schabi.newpipe.player.resolver.PlaybackResolver
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An error has occurred in the app. This class contains plain old parcelable data that can be used
|
* An error has occurred in the app. This class contains plain old parcelable data that can be used
|
||||||
@@ -59,7 +59,7 @@ class ErrorInfo private constructor(
|
|||||||
* If present, this resource can alternatively be opened in browser (useful if NewPipe is
|
* If present, this resource can alternatively be opened in browser (useful if NewPipe is
|
||||||
* badly broken).
|
* badly broken).
|
||||||
*/
|
*/
|
||||||
val openInBrowserUrl: String?
|
val openInBrowserUrl: String?,
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@@ -68,7 +68,7 @@ class ErrorInfo private constructor(
|
|||||||
userAction: UserAction,
|
userAction: UserAction,
|
||||||
request: String,
|
request: String,
|
||||||
serviceId: Int? = null,
|
serviceId: Int? = null,
|
||||||
openInBrowserUrl: String? = null
|
openInBrowserUrl: String? = null,
|
||||||
) : this(
|
) : this(
|
||||||
throwableToStringList(throwable),
|
throwableToStringList(throwable),
|
||||||
userAction,
|
userAction,
|
||||||
@@ -78,7 +78,7 @@ class ErrorInfo private constructor(
|
|||||||
isReportable(throwable),
|
isReportable(throwable),
|
||||||
isRetryable(throwable),
|
isRetryable(throwable),
|
||||||
(throwable as? ReCaptchaException)?.url,
|
(throwable as? ReCaptchaException)?.url,
|
||||||
openInBrowserUrl
|
openInBrowserUrl,
|
||||||
)
|
)
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@@ -87,7 +87,7 @@ class ErrorInfo private constructor(
|
|||||||
userAction: UserAction,
|
userAction: UserAction,
|
||||||
request: String,
|
request: String,
|
||||||
serviceId: Int? = null,
|
serviceId: Int? = null,
|
||||||
openInBrowserUrl: String? = null
|
openInBrowserUrl: String? = null,
|
||||||
) : this(
|
) : this(
|
||||||
throwableListToStringList(throwables),
|
throwableListToStringList(throwables),
|
||||||
userAction,
|
userAction,
|
||||||
@@ -97,7 +97,7 @@ class ErrorInfo private constructor(
|
|||||||
throwables.any(::isReportable),
|
throwables.any(::isReportable),
|
||||||
throwables.isEmpty() || throwables.any(::isRetryable),
|
throwables.isEmpty() || throwables.any(::isRetryable),
|
||||||
throwables.firstNotNullOfOrNull { it as? ReCaptchaException }?.url,
|
throwables.firstNotNullOfOrNull { it as? ReCaptchaException }?.url,
|
||||||
openInBrowserUrl
|
openInBrowserUrl,
|
||||||
)
|
)
|
||||||
|
|
||||||
// constructor to manually build ErrorInfo when no throwable is available
|
// constructor to manually build ErrorInfo when no throwable is available
|
||||||
@@ -118,7 +118,7 @@ class ErrorInfo private constructor(
|
|||||||
throwable: Throwable,
|
throwable: Throwable,
|
||||||
userAction: UserAction,
|
userAction: UserAction,
|
||||||
request: String,
|
request: String,
|
||||||
info: Info?
|
info: Info?,
|
||||||
) :
|
) :
|
||||||
this(throwable, userAction, request, info?.serviceId, info?.url)
|
this(throwable, userAction, request, info?.serviceId, info?.url)
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ class ErrorInfo private constructor(
|
|||||||
throwables: List<Throwable>,
|
throwables: List<Throwable>,
|
||||||
userAction: UserAction,
|
userAction: UserAction,
|
||||||
request: String,
|
request: String,
|
||||||
info: Info?
|
info: Info?,
|
||||||
) :
|
) :
|
||||||
this(throwables, userAction, request, info?.serviceId, info?.url)
|
this(throwables, userAction, request, info?.serviceId, info?.url)
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ class ErrorInfo private constructor(
|
|||||||
class ErrorMessage(
|
class ErrorMessage(
|
||||||
@StringRes
|
@StringRes
|
||||||
private val stringRes: Int,
|
private val stringRes: Int,
|
||||||
private vararg val formatArgs: String
|
private vararg val formatArgs: String,
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
fun getString(context: Context): String {
|
fun getString(context: Context): String {
|
||||||
return if (formatArgs.isEmpty()) {
|
return if (formatArgs.isEmpty()) {
|
||||||
@@ -160,19 +160,21 @@ class ErrorInfo private constructor(
|
|||||||
|
|
||||||
const val SERVICE_NONE = "<unknown_service>"
|
const val SERVICE_NONE = "<unknown_service>"
|
||||||
|
|
||||||
private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we
|
private fun getServiceName(serviceId: Int?) =
|
||||||
|
// not using getNameOfServiceById since we want to accept a nullable serviceId and we
|
||||||
// want to default to SERVICE_NONE
|
// want to default to SERVICE_NONE
|
||||||
ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name
|
ServiceList.all()?.firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name
|
||||||
?: SERVICE_NONE
|
?: SERVICE_NONE
|
||||||
|
|
||||||
fun throwableToStringList(throwable: Throwable) = arrayOf(throwable.stackTraceToString())
|
fun throwableToStringList(throwable: Throwable) = arrayOf(throwable.stackTraceToString())
|
||||||
|
|
||||||
fun throwableListToStringList(throwableList: List<Throwable>) = throwableList.map { it.stackTraceToString() }.toTypedArray()
|
fun throwableListToStringList(throwableList: List<Throwable>) =
|
||||||
|
throwableList.map { it.stackTraceToString() }.toTypedArray()
|
||||||
|
|
||||||
fun getMessage(
|
fun getMessage(
|
||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
action: UserAction?,
|
action: UserAction?,
|
||||||
serviceId: Int?
|
serviceId: Int?,
|
||||||
): ErrorMessage {
|
): ErrorMessage {
|
||||||
return when {
|
return when {
|
||||||
// player exceptions
|
// player exceptions
|
||||||
@@ -191,24 +193,18 @@ class ErrorInfo private constructor(
|
|||||||
ErrorMessage(R.string.player_http_invalid_status, cause.responseCode.toString())
|
ErrorMessage(R.string.player_http_invalid_status, cause.responseCode.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cause is Loader.UnexpectedLoaderException && cause.cause is ExtractionException ->
|
cause is Loader.UnexpectedLoaderException && cause.cause is ExtractionException ->
|
||||||
getMessage(throwable, action, serviceId)
|
getMessage(throwable, action, serviceId)
|
||||||
|
|
||||||
throwable.type == ExoPlaybackException.TYPE_SOURCE ->
|
throwable.type == ExoPlaybackException.TYPE_SOURCE ->
|
||||||
ErrorMessage(R.string.player_stream_failure)
|
ErrorMessage(R.string.player_stream_failure)
|
||||||
|
|
||||||
throwable.type == ExoPlaybackException.TYPE_UNEXPECTED ->
|
throwable.type == ExoPlaybackException.TYPE_UNEXPECTED ->
|
||||||
ErrorMessage(R.string.player_recoverable_failure)
|
ErrorMessage(R.string.player_recoverable_failure)
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
ErrorMessage(R.string.player_unrecoverable_failure)
|
ErrorMessage(R.string.player_unrecoverable_failure)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throwable is FailedMediaSource.FailedMediaSourceException ->
|
throwable is FailedMediaSource.FailedMediaSourceException ->
|
||||||
getMessage(throwable.cause, action, serviceId)
|
getMessage(throwable.cause, action, serviceId)
|
||||||
|
|
||||||
throwable is PlaybackResolver.ResolverException ->
|
throwable is PlaybackResolver.ResolverException ->
|
||||||
ErrorMessage(R.string.player_stream_failure)
|
ErrorMessage(R.string.player_stream_failure)
|
||||||
|
|
||||||
@@ -224,46 +220,34 @@ class ErrorInfo private constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
?: ErrorMessage(R.string.account_terminated)
|
?: ErrorMessage(R.string.account_terminated)
|
||||||
|
|
||||||
throwable is AgeRestrictedContentException ->
|
throwable is AgeRestrictedContentException ->
|
||||||
ErrorMessage(R.string.restricted_video_no_stream)
|
ErrorMessage(R.string.restricted_video_no_stream)
|
||||||
|
|
||||||
throwable is GeographicRestrictionException ->
|
throwable is GeographicRestrictionException ->
|
||||||
ErrorMessage(R.string.georestricted_content)
|
ErrorMessage(R.string.georestricted_content)
|
||||||
|
|
||||||
throwable is PaidContentException ->
|
throwable is PaidContentException ->
|
||||||
ErrorMessage(R.string.paid_content)
|
ErrorMessage(R.string.paid_content)
|
||||||
|
|
||||||
throwable is PrivateContentException ->
|
throwable is PrivateContentException ->
|
||||||
ErrorMessage(R.string.private_content)
|
ErrorMessage(R.string.private_content)
|
||||||
|
|
||||||
throwable is SoundCloudGoPlusContentException ->
|
throwable is SoundCloudGoPlusContentException ->
|
||||||
ErrorMessage(R.string.soundcloud_go_plus_content)
|
ErrorMessage(R.string.soundcloud_go_plus_content)
|
||||||
|
|
||||||
throwable is UnsupportedContentInCountryException ->
|
throwable is UnsupportedContentInCountryException ->
|
||||||
ErrorMessage(R.string.unsupported_content_in_country)
|
ErrorMessage(R.string.unsupported_content_in_country)
|
||||||
|
|
||||||
throwable is YoutubeMusicPremiumContentException ->
|
throwable is YoutubeMusicPremiumContentException ->
|
||||||
ErrorMessage(R.string.youtube_music_premium_content)
|
ErrorMessage(R.string.youtube_music_premium_content)
|
||||||
|
|
||||||
throwable is SignInConfirmNotBotException ->
|
throwable is SignInConfirmNotBotException ->
|
||||||
ErrorMessage(R.string.sign_in_confirm_not_bot_error, getServiceName(serviceId))
|
ErrorMessage(R.string.sign_in_confirm_not_bot_error, getServiceName(serviceId))
|
||||||
|
|
||||||
throwable is ContentNotAvailableException ->
|
throwable is ContentNotAvailableException ->
|
||||||
ErrorMessage(R.string.content_not_available)
|
ErrorMessage(R.string.content_not_available)
|
||||||
|
|
||||||
// other extractor exceptions
|
// other extractor exceptions
|
||||||
throwable is ContentNotSupportedException ->
|
throwable is ContentNotSupportedException ->
|
||||||
ErrorMessage(R.string.content_not_supported)
|
ErrorMessage(R.string.content_not_supported)
|
||||||
|
|
||||||
// ReCaptchas will be handled in a special way anyway
|
// ReCaptchas will be handled in a special way anyway
|
||||||
throwable is ReCaptchaException ->
|
throwable is ReCaptchaException ->
|
||||||
ErrorMessage(R.string.recaptcha_request_toast)
|
ErrorMessage(R.string.recaptcha_request_toast)
|
||||||
|
|
||||||
// test this at the end as many exceptions could be a subclass of IOException
|
// test this at the end as many exceptions could be a subclass of IOException
|
||||||
throwable != null && throwable.isNetworkRelated ->
|
throwable != null && throwable.isNetworkRelated ->
|
||||||
ErrorMessage(R.string.network_error)
|
ErrorMessage(R.string.network_error)
|
||||||
|
|
||||||
// an extraction exception unrelated to the network
|
// an extraction exception unrelated to the network
|
||||||
// is likely an issue with parsing the website
|
// is likely an issue with parsing the website
|
||||||
throwable is ExtractionException ->
|
throwable is ExtractionException ->
|
||||||
@@ -272,22 +256,16 @@ class ErrorInfo private constructor(
|
|||||||
// user actions (in case the exception is null or unrecognizable)
|
// user actions (in case the exception is null or unrecognizable)
|
||||||
action == UserAction.UI_ERROR ->
|
action == UserAction.UI_ERROR ->
|
||||||
ErrorMessage(R.string.app_ui_crash)
|
ErrorMessage(R.string.app_ui_crash)
|
||||||
|
|
||||||
action == UserAction.REQUESTED_COMMENTS ->
|
action == UserAction.REQUESTED_COMMENTS ->
|
||||||
ErrorMessage(R.string.error_unable_to_load_comments)
|
ErrorMessage(R.string.error_unable_to_load_comments)
|
||||||
|
|
||||||
action == UserAction.SUBSCRIPTION_CHANGE ->
|
action == UserAction.SUBSCRIPTION_CHANGE ->
|
||||||
ErrorMessage(R.string.subscription_change_failed)
|
ErrorMessage(R.string.subscription_change_failed)
|
||||||
|
|
||||||
action == UserAction.SUBSCRIPTION_UPDATE ->
|
action == UserAction.SUBSCRIPTION_UPDATE ->
|
||||||
ErrorMessage(R.string.subscription_update_failed)
|
ErrorMessage(R.string.subscription_update_failed)
|
||||||
|
|
||||||
action == UserAction.LOAD_IMAGE ->
|
action == UserAction.LOAD_IMAGE ->
|
||||||
ErrorMessage(R.string.could_not_load_thumbnails)
|
ErrorMessage(R.string.could_not_load_thumbnails)
|
||||||
|
|
||||||
action == UserAction.DOWNLOAD_OPEN_DIALOG ->
|
action == UserAction.DOWNLOAD_OPEN_DIALOG ->
|
||||||
ErrorMessage(R.string.could_not_setup_download_menu)
|
ErrorMessage(R.string.could_not_setup_download_menu)
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
ErrorMessage(R.string.error_snackbar_message)
|
ErrorMessage(R.string.error_snackbar_message)
|
||||||
}
|
}
|
||||||
@@ -298,19 +276,15 @@ class ErrorInfo private constructor(
|
|||||||
// we don't have an exception, so this is a manually built error, which likely
|
// we don't have an exception, so this is a manually built error, which likely
|
||||||
// indicates that it's important and is thus reportable
|
// indicates that it's important and is thus reportable
|
||||||
null -> true
|
null -> true
|
||||||
|
// the service explicitly said that content is not available (e.g. age restrictions,
|
||||||
// if the service explicitly said that content is not available (e.g. age
|
// video deleted, etc.), there is no use in letting users report it
|
||||||
// restrictions, video deleted, etc.), there is no use in letting users report it
|
is ContentNotAvailableException -> false
|
||||||
is ContentNotAvailableException -> !isContentSurelyNotAvailable(throwable)
|
|
||||||
|
|
||||||
// we know the content is not supported, no need to let the user report it
|
// we know the content is not supported, no need to let the user report it
|
||||||
is ContentNotSupportedException -> false
|
is ContentNotSupportedException -> false
|
||||||
|
|
||||||
// happens often when there is no internet connection; we don't use
|
// happens often when there is no internet connection; we don't use
|
||||||
// `throwable.isNetworkRelated` since any `IOException` would make that function
|
// `throwable.isNetworkRelated` since any `IOException` would make that function
|
||||||
// return true, but not all `IOException`s are network related
|
// return true, but not all `IOException`s are network related
|
||||||
is UnknownHostException -> false
|
is UnknownHostException -> false
|
||||||
|
|
||||||
// by default, this is an unexpected exception, which the user could report
|
// by default, this is an unexpected exception, which the user could report
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
@@ -318,39 +292,14 @@ class ErrorInfo private constructor(
|
|||||||
|
|
||||||
fun isRetryable(throwable: Throwable?): Boolean {
|
fun isRetryable(throwable: Throwable?): Boolean {
|
||||||
return when (throwable) {
|
return when (throwable) {
|
||||||
// if we know the content is surely not available, retrying won't help
|
// we know the content is not available, retrying won't help
|
||||||
is ContentNotAvailableException -> !isContentSurelyNotAvailable(throwable)
|
is ContentNotAvailableException -> false
|
||||||
|
|
||||||
// we know the content is not supported, retrying won't help
|
// we know the content is not supported, retrying won't help
|
||||||
is ContentNotSupportedException -> false
|
is ContentNotSupportedException -> false
|
||||||
|
|
||||||
// by default (including if throwable is null), enable retrying (though the retry
|
// by default (including if throwable is null), enable retrying (though the retry
|
||||||
// button will be shown only if a way to perform the retry is implemented)
|
// button will be shown only if a way to perform the retry is implemented)
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unfortunately sometimes [ContentNotAvailableException] may not indicate that the content
|
|
||||||
* is blocked/deleted/paid, but may just indicate that we could not extract it. This is an
|
|
||||||
* inconsistency in the exceptions thrown by the extractor, but until it is fixed, this
|
|
||||||
* function will distinguish between the two types.
|
|
||||||
* @return `true` if the content is not available because of a limitation imposed by the
|
|
||||||
* service or the owner, `false` if the extractor could not extract info about it
|
|
||||||
*/
|
|
||||||
fun isContentSurelyNotAvailable(e: ContentNotAvailableException): Boolean {
|
|
||||||
return when (e) {
|
|
||||||
is AccountTerminatedException,
|
|
||||||
is AgeRestrictedContentException,
|
|
||||||
is GeographicRestrictionException,
|
|
||||||
is PaidContentException,
|
|
||||||
is PrivateContentException,
|
|
||||||
is SoundCloudGoPlusContentException,
|
|
||||||
is UnsupportedContentInCountryException,
|
|
||||||
is YoutubeMusicPremiumContentException -> true
|
|
||||||
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ import androidx.fragment.app.Fragment
|
|||||||
import com.jakewharton.rxbinding4.view.clicks
|
import com.jakewharton.rxbinding4.view.clicks
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.ktx.animate
|
import org.schabi.newpipe.ktx.animate
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils
|
import org.schabi.newpipe.util.external_communication.ShareUtils
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class ErrorPanelHelper(
|
class ErrorPanelHelper(
|
||||||
private val fragment: Fragment,
|
private val fragment: Fragment,
|
||||||
rootView: View,
|
rootView: View,
|
||||||
onRetry: Runnable?
|
onRetry: Runnable?,
|
||||||
) {
|
) {
|
||||||
private val context: Context = rootView.context!!
|
private val context: Context = rootView.context!!
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class ErrorUtil {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun openActivity(context: Context, errorInfo: ErrorInfo) {
|
fun openActivity(context: Context, errorInfo: ErrorInfo) {
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(context)
|
if (PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.getBoolean(MainActivity.KEY_IS_IN_BACKGROUND, true)
|
.getBoolean(MainActivity.KEY_IS_IN_BACKGROUND, true)
|
||||||
) {
|
) {
|
||||||
createNotification(context, errorInfo)
|
createNotification(context, errorInfo)
|
||||||
} else {
|
} else {
|
||||||
@@ -134,11 +134,8 @@ class ErrorUtil {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val notificationManager = NotificationManagerCompat.from(context)
|
NotificationManagerCompat.from(context)
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
|
||||||
notificationManager
|
|
||||||
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
|
|
||||||
}
|
|
||||||
|
|
||||||
ContextCompat.getMainExecutor(context).execute {
|
ContextCompat.getMainExecutor(context).execute {
|
||||||
// since the notification is silent, also show a toast, otherwise the user is confused
|
// since the notification is silent, also show a toast, otherwise the user is confused
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressLint("MissingSuperCall")
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
saveCookiesAndFinish();
|
saveCookiesAndFinish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,5 +40,5 @@ enum class UserAction(val message: String) {
|
|||||||
OPEN_INFO_ITEM_DIALOG("open info item dialog"),
|
OPEN_INFO_ITEM_DIALOG("open info item dialog"),
|
||||||
GETTING_MAIN_SCREEN_TAB("getting main screen tab"),
|
GETTING_MAIN_SCREEN_TAB("getting main screen tab"),
|
||||||
PLAY_ON_POPUP("play on popup"),
|
PLAY_ON_POPUP("play on popup"),
|
||||||
SUBSCRIPTIONS("loading subscriptions")
|
SUBSCRIPTIONS("loading subscriptions");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,6 +206,8 @@ public final class VideoDetailFragment
|
|||||||
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
|
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
|
||||||
@State
|
@State
|
||||||
protected boolean autoPlayEnabled = true;
|
protected boolean autoPlayEnabled = true;
|
||||||
|
@State
|
||||||
|
protected int originalOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private StreamInfo currentInfo = null;
|
private StreamInfo currentInfo = null;
|
||||||
@@ -1422,10 +1424,8 @@ public final class VideoDetailFragment
|
|||||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||||
}
|
}
|
||||||
// Rebound to the service if it was closed via notification or mini player
|
// Rebound to the service if it was closed via notification or mini player
|
||||||
if (!playerHolder.isBound()) {
|
playerHolder.setListener(VideoDetailFragment.this);
|
||||||
playerHolder.startService(
|
playerHolder.tryBindIfNeeded(context);
|
||||||
false, VideoDetailFragment.this);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1908,23 +1908,29 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenRotationButtonClicked() {
|
public void onScreenRotationButtonClicked() {
|
||||||
// On Android TV screen rotation is not supported
|
final Optional<MainPlayerUi> playerUi = player != null
|
||||||
// In tablet user experience will be better if screen will not be rotated
|
? player.UIs().get(MainPlayerUi.class)
|
||||||
// from landscape to portrait every time.
|
: Optional.empty();
|
||||||
// Just turn on fullscreen mode in landscape orientation
|
if (playerUi.isEmpty()) {
|
||||||
// or portrait & unlocked global orientation
|
|
||||||
final boolean isLandscape = DeviceUtils.isLandscape(requireContext());
|
|
||||||
if (DeviceUtils.isTv(activity) || DeviceUtils.isTablet(activity)
|
|
||||||
&& (!globalScreenOrientationLocked(activity) || isLandscape)) {
|
|
||||||
player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int newOrientation = isLandscape
|
// On tablets and TVs, just toggle fullscreen UI without orientation change.
|
||||||
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
if (DeviceUtils.isTablet(activity) || DeviceUtils.isTv(activity)) {
|
||||||
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
playerUi.get().toggleFullscreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
activity.setRequestedOrientation(newOrientation);
|
if (playerUi.get().isFullscreen()) {
|
||||||
|
// EXITING FULLSCREEN
|
||||||
|
playerUi.get().toggleFullscreen();
|
||||||
|
activity.setRequestedOrientation(originalOrientation);
|
||||||
|
} else {
|
||||||
|
// ENTERING FULLSCREEN
|
||||||
|
originalOrientation = activity.getRequestedOrientation();
|
||||||
|
playerUi.get().toggleFullscreen();
|
||||||
|
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -160,29 +160,34 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(@NonNull final MenuItem item) {
|
public boolean onMenuItemSelected(@NonNull final MenuItem item) {
|
||||||
final int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == R.id.menu_item_notify) {
|
case R.id.menu_item_notify:
|
||||||
final boolean value = !item.isChecked();
|
final boolean value = !item.isChecked();
|
||||||
item.setEnabled(false);
|
item.setEnabled(false);
|
||||||
setNotify(value);
|
setNotify(value);
|
||||||
} else if (itemId == R.id.action_settings) {
|
break;
|
||||||
NavigationHelper.openSettings(requireContext());
|
case R.id.action_settings:
|
||||||
} else if (itemId == R.id.menu_item_rss) {
|
NavigationHelper.openSettings(requireContext());
|
||||||
if (currentInfo != null) {
|
break;
|
||||||
ShareUtils.openUrlInApp(requireContext(), currentInfo.getFeedUrl());
|
case R.id.menu_item_rss:
|
||||||
}
|
if (currentInfo != null) {
|
||||||
} else if (itemId == R.id.menu_item_openInBrowser) {
|
ShareUtils.openUrlInApp(requireContext(), currentInfo.getFeedUrl());
|
||||||
if (currentInfo != null) {
|
}
|
||||||
ShareUtils.openUrlInBrowser(requireContext(),
|
break;
|
||||||
currentInfo.getOriginalUrl());
|
case R.id.menu_item_openInBrowser:
|
||||||
}
|
if (currentInfo != null) {
|
||||||
} else if (itemId == R.id.menu_item_share) {
|
ShareUtils.openUrlInBrowser(requireContext(),
|
||||||
if (currentInfo != null) {
|
currentInfo.getOriginalUrl());
|
||||||
ShareUtils.shareText(requireContext(), name,
|
}
|
||||||
currentInfo.getOriginalUrl(), currentInfo.getAvatars());
|
break;
|
||||||
}
|
case R.id.menu_item_share:
|
||||||
} else {
|
if (currentInfo != null) {
|
||||||
return false;
|
ShareUtils.shareText(requireContext(), name,
|
||||||
|
currentInfo.getOriginalUrl(), currentInfo.getAvatars());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,30 +232,35 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
final int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == R.id.action_settings) {
|
case R.id.action_settings:
|
||||||
NavigationHelper.openSettings(requireContext());
|
NavigationHelper.openSettings(requireContext());
|
||||||
} else if (itemId == R.id.menu_item_openInBrowser) {
|
break;
|
||||||
ShareUtils.openUrlInBrowser(requireContext(), url);
|
case R.id.menu_item_openInBrowser:
|
||||||
} else if (itemId == R.id.menu_item_share) {
|
ShareUtils.openUrlInBrowser(requireContext(), url);
|
||||||
ShareUtils.shareText(requireContext(), name, url,
|
break;
|
||||||
currentInfo == null ? List.of() : currentInfo.getThumbnails());
|
case R.id.menu_item_share:
|
||||||
} else if (itemId == R.id.menu_item_bookmark) {
|
ShareUtils.shareText(requireContext(), name, url,
|
||||||
onBookmarkClicked();
|
currentInfo == null ? List.of() : currentInfo.getThumbnails());
|
||||||
} else if (itemId == R.id.menu_item_append_playlist) {
|
break;
|
||||||
if (currentInfo != null) {
|
case R.id.menu_item_bookmark:
|
||||||
disposables.add(PlaylistDialog.createCorrespondingDialog(
|
onBookmarkClicked();
|
||||||
getContext(),
|
break;
|
||||||
getPlayQueue()
|
case R.id.menu_item_append_playlist:
|
||||||
.getStreams()
|
if (currentInfo != null) {
|
||||||
.stream()
|
disposables.add(PlaylistDialog.createCorrespondingDialog(
|
||||||
.map(StreamEntity::new)
|
getContext(),
|
||||||
.collect(Collectors.toList()),
|
getPlayQueue()
|
||||||
dialog -> dialog.show(getFM(), TAG)
|
.getStreams()
|
||||||
));
|
.stream()
|
||||||
}
|
.map(StreamEntity::new)
|
||||||
} else {
|
.collect(Collectors.toList()),
|
||||||
return super.onOptionsItemSelected(item);
|
dialog -> dialog.show(getFM(), TAG)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package org.schabi.newpipe.info_list;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
import org.schabi.newpipe.info_list.holder.ChannelInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.ChannelMiniInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.CommentInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.InfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.PlaylistInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.StreamInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder;
|
||||||
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Created by Christian Schabesberger on 26.09.16.
|
||||||
|
* <p>
|
||||||
|
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
||||||
|
* InfoItemBuilder.java is part of NewPipe.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* NewPipe is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* NewPipe is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class InfoItemBuilder {
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
private OnClickGesture<StreamInfoItem> onStreamSelectedListener;
|
||||||
|
private OnClickGesture<ChannelInfoItem> onChannelSelectedListener;
|
||||||
|
private OnClickGesture<PlaylistInfoItem> onPlaylistSelectedListener;
|
||||||
|
private OnClickGesture<CommentsInfoItem> onCommentsSelectedListener;
|
||||||
|
|
||||||
|
public InfoItemBuilder(final Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View buildView(@NonNull final ViewGroup parent, @NonNull final InfoItem infoItem,
|
||||||
|
final HistoryRecordManager historyRecordManager) {
|
||||||
|
return buildView(parent, infoItem, historyRecordManager, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public View buildView(@NonNull final ViewGroup parent, @NonNull final InfoItem infoItem,
|
||||||
|
final HistoryRecordManager historyRecordManager,
|
||||||
|
final boolean useMiniVariant) {
|
||||||
|
final InfoItemHolder holder =
|
||||||
|
holderFromInfoType(parent, infoItem.getInfoType(), useMiniVariant);
|
||||||
|
holder.updateFromItem(infoItem, historyRecordManager);
|
||||||
|
return holder.itemView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InfoItemHolder holderFromInfoType(@NonNull final ViewGroup parent,
|
||||||
|
@NonNull final InfoItem.InfoType infoType,
|
||||||
|
final boolean useMiniVariant) {
|
||||||
|
switch (infoType) {
|
||||||
|
case STREAM:
|
||||||
|
return useMiniVariant ? new StreamMiniInfoItemHolder(this, parent)
|
||||||
|
: new StreamInfoItemHolder(this, parent);
|
||||||
|
case CHANNEL:
|
||||||
|
return useMiniVariant ? new ChannelMiniInfoItemHolder(this, parent)
|
||||||
|
: new ChannelInfoItemHolder(this, parent);
|
||||||
|
case PLAYLIST:
|
||||||
|
return useMiniVariant ? new PlaylistMiniInfoItemHolder(this, parent)
|
||||||
|
: new PlaylistInfoItemHolder(this, parent);
|
||||||
|
case COMMENT:
|
||||||
|
return new CommentInfoItemHolder(this, parent);
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("InfoType not expected = " + infoType.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Context getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OnClickGesture<StreamInfoItem> getOnStreamSelectedListener() {
|
||||||
|
return onStreamSelectedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnStreamSelectedListener(final OnClickGesture<StreamInfoItem> listener) {
|
||||||
|
this.onStreamSelectedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OnClickGesture<ChannelInfoItem> getOnChannelSelectedListener() {
|
||||||
|
return onChannelSelectedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnChannelSelectedListener(final OnClickGesture<ChannelInfoItem> listener) {
|
||||||
|
this.onChannelSelectedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OnClickGesture<PlaylistInfoItem> getOnPlaylistSelectedListener() {
|
||||||
|
return onPlaylistSelectedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnPlaylistSelectedListener(final OnClickGesture<PlaylistInfoItem> listener) {
|
||||||
|
this.onPlaylistSelectedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OnClickGesture<CommentsInfoItem> getOnCommentsSelectedListener() {
|
||||||
|
return onCommentsSelectedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnCommentsSelectedListener(
|
||||||
|
final OnClickGesture<CommentsInfoItem> onCommentsSelectedListener) {
|
||||||
|
this.onCommentsSelectedListener = onCommentsSelectedListener;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2016-2026 NewPipe contributors <https://newpipe.net>
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.schabi.newpipe.info_list
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
|
||||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
|
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
|
||||||
import org.schabi.newpipe.util.OnClickGesture
|
|
||||||
|
|
||||||
class InfoItemBuilder(val context: Context) {
|
|
||||||
var onStreamSelectedListener: OnClickGesture<StreamInfoItem>? = null
|
|
||||||
var onChannelSelectedListener: OnClickGesture<ChannelInfoItem>? = null
|
|
||||||
var onPlaylistSelectedListener: OnClickGesture<PlaylistInfoItem>? = null
|
|
||||||
var onCommentsSelectedListener: OnClickGesture<CommentsInfoItem>? = null
|
|
||||||
}
|
|
||||||
@@ -13,17 +13,14 @@ enum class ItemViewMode {
|
|||||||
* Default mode.
|
* Default mode.
|
||||||
*/
|
*/
|
||||||
AUTO,
|
AUTO,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full width list item with thumb on the left and two line title & uploader in right.
|
* Full width list item with thumb on the left and two line title & uploader in right.
|
||||||
*/
|
*/
|
||||||
LIST,
|
LIST,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grid mode places two cards per row.
|
* Grid mode places two cards per row.
|
||||||
*/
|
*/
|
||||||
GRID,
|
GRID,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A full width card in phone - portrait.
|
* A full width card in phone - portrait.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package org.schabi.newpipe.info_list
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.xwray.groupie.GroupieAdapter
|
import com.xwray.groupie.GroupieAdapter
|
||||||
import kotlin.math.max
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo
|
import org.schabi.newpipe.extractor.stream.StreamInfo
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom RecyclerView.Adapter/GroupieAdapter for [StreamSegmentItem] for handling selection state.
|
* Custom RecyclerView.Adapter/GroupieAdapter for [StreamSegmentItem] for handling selection state.
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ class StreamSegmentItem(
|
|||||||
viewHolder.root.findViewById<TextView>(R.id.textViewStartSeconds).text =
|
viewHolder.root.findViewById<TextView>(R.id.textViewStartSeconds).text =
|
||||||
Localization.getDurationString(item.startTimeSeconds.toLong())
|
Localization.getDurationString(item.startTimeSeconds.toLong())
|
||||||
viewHolder.root.setOnClickListener { onClick.onItemClick(this, item.startTimeSeconds) }
|
viewHolder.root.setOnClickListener { onClick.onItemClick(this, item.startTimeSeconds) }
|
||||||
viewHolder.root.setOnLongClickListener {
|
viewHolder.root.setOnLongClickListener { onClick.onItemLongClick(this, item.startTimeSeconds); true }
|
||||||
onClick.onItemLongClick(this, item.startTimeSeconds)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
viewHolder.root.isSelected = isSelected
|
viewHolder.root.isSelected = isSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,16 +41,14 @@ fun View.animate(
|
|||||||
execOnEnd: Runnable? = null
|
execOnEnd: Runnable? = null
|
||||||
) {
|
) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
val id = runCatching { resources.getResourceEntryName(id) }.getOrDefault(id.toString())
|
val id = try {
|
||||||
|
resources.getResourceEntryName(id)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
id.toString()
|
||||||
|
}
|
||||||
val msg = String.format(
|
val msg = String.format(
|
||||||
"%8s → [%s:%s] [%s %s:%s] execOnEnd=%s",
|
"%8s → [%s:%s] [%s %s:%s] execOnEnd=%s", enterOrExit,
|
||||||
enterOrExit,
|
javaClass.simpleName, id, animationType, duration, delay, execOnEnd
|
||||||
javaClass.simpleName,
|
|
||||||
id,
|
|
||||||
animationType,
|
|
||||||
duration,
|
|
||||||
delay,
|
|
||||||
execOnEnd
|
|
||||||
)
|
)
|
||||||
Log.d(TAG, "animate(): $msg")
|
Log.d(TAG, "animate(): $msg")
|
||||||
}
|
}
|
||||||
@@ -293,9 +291,5 @@ private class HideAndExecOnEndListener(private val view: View, execOnEnd: Runnab
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class AnimationType {
|
enum class AnimationType {
|
||||||
ALPHA,
|
ALPHA, SCALE_AND_ALPHA, LIGHT_SCALE_AND_ALPHA, SLIDE_AND_ALPHA, LIGHT_SLIDE_AND_ALPHA
|
||||||
SCALE_AND_ALPHA,
|
|
||||||
LIGHT_SCALE_AND_ALPHA,
|
|
||||||
SLIDE_AND_ALPHA,
|
|
||||||
LIGHT_SLIDE_AND_ALPHA
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
|||||||
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
|
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
|
||||||
import static org.schabi.newpipe.util.ThemeHelper.getItemViewMode;
|
import static org.schabi.newpipe.util.ThemeHelper.getItemViewMode;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment is design to be used with persistent data such as
|
* This fragment is design to be used with persistent data such as
|
||||||
* {@link org.schabi.newpipe.database.LocalItem}, and does not cache the data contained
|
* {@link org.schabi.newpipe.database.LocalItem}, and does not cache the data contained
|
||||||
@@ -102,7 +100,7 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected Supplier<View> getListHeaderSupplier() {
|
protected ViewBinding getListHeader() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,9 +131,9 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
itemsList = rootView.findViewById(R.id.items_list);
|
itemsList = rootView.findViewById(R.id.items_list);
|
||||||
refreshItemViewMode();
|
refreshItemViewMode();
|
||||||
|
|
||||||
final Supplier<View> listHeaderSupplier = getListHeaderSupplier();
|
headerRootBinding = getListHeader();
|
||||||
if (listHeaderSupplier != null) {
|
if (headerRootBinding != null) {
|
||||||
itemListAdapter.setHeaderSupplier(listHeaderSupplier);
|
itemListAdapter.setHeader(headerRootBinding.getRoot());
|
||||||
}
|
}
|
||||||
footerRootBinding = getListFooter();
|
footerRootBinding = getListFooter();
|
||||||
itemListAdapter.setFooter(footerRootBinding.getRoot());
|
itemListAdapter.setFooter(footerRootBinding.getRoot());
|
||||||
@@ -212,8 +210,6 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
showListFooter(false);
|
showListFooter(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(since = "Calling this method with `true` may cause crashes, see "
|
|
||||||
+ "https://github.com/TeamNewPipe/NewPipe/pull/12996#pullrequestreview-3713317115")
|
|
||||||
@Override
|
@Override
|
||||||
public void showListFooter(final boolean show) {
|
public void showListFooter(final boolean show) {
|
||||||
if (itemsList == null) {
|
if (itemsList == null) {
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 01.08.16.
|
* Created by Christian Schabesberger on 01.08.16.
|
||||||
@@ -89,7 +88,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
private final DateTimeFormatter dateTimeFormatter;
|
private final DateTimeFormatter dateTimeFormatter;
|
||||||
|
|
||||||
private boolean showFooter = false;
|
private boolean showFooter = false;
|
||||||
private Supplier<View> headerSupplier = null;
|
private View header = null;
|
||||||
private View footer = null;
|
private View footer = null;
|
||||||
private ItemViewMode itemViewMode = ItemViewMode.LIST;
|
private ItemViewMode itemViewMode = ItemViewMode.LIST;
|
||||||
private boolean useItemHandle = false;
|
private boolean useItemHandle = false;
|
||||||
@@ -98,7 +97,6 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
recordManager = new HistoryRecordManager(context);
|
recordManager = new HistoryRecordManager(context);
|
||||||
localItemBuilder = new LocalItemBuilder(context);
|
localItemBuilder = new LocalItemBuilder(context);
|
||||||
localItems = new ArrayList<>();
|
localItems = new ArrayList<>();
|
||||||
|
|
||||||
dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
|
dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
|
||||||
.withLocale(Localization.getPreferredLocale(context));
|
.withLocale(Localization.getPreferredLocale(context));
|
||||||
}
|
}
|
||||||
@@ -126,7 +124,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "addItems() after > offsetStart = " + offsetStart + ", "
|
Log.d(TAG, "addItems() after > offsetStart = " + offsetStart + ", "
|
||||||
+ "localItems.size() = " + localItems.size() + ", "
|
+ "localItems.size() = " + localItems.size() + ", "
|
||||||
+ "header = " + hasHeader() + ", footer = " + footer + ", "
|
+ "header = " + header + ", footer = " + footer + ", "
|
||||||
+ "showFooter = " + showFooter);
|
+ "showFooter = " + showFooter);
|
||||||
}
|
}
|
||||||
notifyItemRangeInserted(offsetStart, data.size());
|
notifyItemRangeInserted(offsetStart, data.size());
|
||||||
@@ -146,7 +144,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
final int index = localItems.indexOf(data);
|
final int index = localItems.indexOf(data);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
localItems.remove(index);
|
localItems.remove(index);
|
||||||
notifyItemRemoved(index + (hasHeader() ? 1 : 0));
|
notifyItemRemoved(index + (header != null ? 1 : 0));
|
||||||
} else {
|
} else {
|
||||||
// this happens when
|
// this happens when
|
||||||
// 1) removeItem is called on infoItemDuplicate as in showStreamItemDialog of
|
// 1) removeItem is called on infoItemDuplicate as in showStreamItemDialog of
|
||||||
@@ -191,9 +189,9 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
this.useItemHandle = useItemHandle;
|
this.useItemHandle = useItemHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeaderSupplier(@Nullable final Supplier<View> headerSupplier) {
|
public void setHeader(final View header) {
|
||||||
final boolean changed = headerSupplier != this.headerSupplier;
|
final boolean changed = header != this.header;
|
||||||
this.headerSupplier = headerSupplier;
|
this.header = header;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
@@ -203,12 +201,6 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
this.footer = view;
|
this.footer = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasHeader() {
|
|
||||||
return this.headerSupplier != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated(since = "Calling this method with `true` may cause crashes, see "
|
|
||||||
+ "https://github.com/TeamNewPipe/NewPipe/pull/12996#pullrequestreview-3713317115")
|
|
||||||
public void showFooter(final boolean show) {
|
public void showFooter(final boolean show) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "showFooter() called with: show = [" + show + "]");
|
Log.d(TAG, "showFooter() called with: show = [" + show + "]");
|
||||||
@@ -219,8 +211,6 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
|
|
||||||
showFooter = show;
|
showFooter = show;
|
||||||
if (show) {
|
if (show) {
|
||||||
Log.w(TAG, "Calling LocalItemListAdapter.showFooter(true) may cause crashes, see https"
|
|
||||||
+ "://github.com/TeamNewPipe/NewPipe/pull/12996#pullrequestreview-3713317115");
|
|
||||||
notifyItemInserted(sizeConsideringHeader());
|
notifyItemInserted(sizeConsideringHeader());
|
||||||
} else {
|
} else {
|
||||||
notifyItemRemoved(sizeConsideringHeader());
|
notifyItemRemoved(sizeConsideringHeader());
|
||||||
@@ -228,11 +218,11 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int adapterOffsetWithoutHeader(final int offset) {
|
private int adapterOffsetWithoutHeader(final int offset) {
|
||||||
return offset - (hasHeader() ? 1 : 0);
|
return offset - (header != null ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int sizeConsideringHeader() {
|
private int sizeConsideringHeader() {
|
||||||
return localItems.size() + (hasHeader() ? 1 : 0);
|
return localItems.size() + (header != null ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<LocalItem> getItemsList() {
|
public ArrayList<LocalItem> getItemsList() {
|
||||||
@@ -242,7 +232,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
int count = localItems.size();
|
int count = localItems.size();
|
||||||
if (hasHeader()) {
|
if (header != null) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (footer != null && showFooter) {
|
if (footer != null && showFooter) {
|
||||||
@@ -252,7 +242,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "getItemCount() called, count = " + count + ", "
|
Log.d(TAG, "getItemCount() called, count = " + count + ", "
|
||||||
+ "localItems.size() = " + localItems.size() + ", "
|
+ "localItems.size() = " + localItems.size() + ", "
|
||||||
+ "header = " + hasHeader() + ", footer = " + footer + ", "
|
+ "header = " + header + ", footer = " + footer + ", "
|
||||||
+ "showFooter = " + showFooter);
|
+ "showFooter = " + showFooter);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
@@ -265,9 +255,9 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
Log.d(TAG, "getItemViewType() called with: position = [" + position + "]");
|
Log.d(TAG, "getItemViewType() called with: position = [" + position + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasHeader() && position == 0) {
|
if (header != null && position == 0) {
|
||||||
return HEADER_TYPE;
|
return HEADER_TYPE;
|
||||||
} else if (hasHeader()) {
|
} else if (header != null) {
|
||||||
position--;
|
position--;
|
||||||
}
|
}
|
||||||
if (footer != null && position == localItems.size() && showFooter) {
|
if (footer != null && position == localItems.size() && showFooter) {
|
||||||
@@ -328,7 +318,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case HEADER_TYPE:
|
case HEADER_TYPE:
|
||||||
return new HeaderFooterHolder(headerSupplier.get());
|
return new HeaderFooterHolder(header);
|
||||||
case FOOTER_TYPE:
|
case FOOTER_TYPE:
|
||||||
return new HeaderFooterHolder(footer);
|
return new HeaderFooterHolder(footer);
|
||||||
case LOCAL_PLAYLIST_HOLDER_TYPE:
|
case LOCAL_PLAYLIST_HOLDER_TYPE:
|
||||||
@@ -376,14 +366,14 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
|
|
||||||
if (holder instanceof LocalItemHolder) {
|
if (holder instanceof LocalItemHolder) {
|
||||||
// If header isn't null, offset the items by -1
|
// If header isn't null, offset the items by -1
|
||||||
if (hasHeader()) {
|
if (header != null) {
|
||||||
position--;
|
position--;
|
||||||
}
|
}
|
||||||
|
|
||||||
((LocalItemHolder) holder)
|
((LocalItemHolder) holder)
|
||||||
.updateFromItem(localItems.get(position), recordManager, dateTimeFormatter);
|
.updateFromItem(localItems.get(position), recordManager, dateTimeFormatter);
|
||||||
} else if (holder instanceof HeaderFooterHolder && position == 0 && hasHeader()) {
|
} else if (holder instanceof HeaderFooterHolder && position == 0 && header != null) {
|
||||||
((HeaderFooterHolder) holder).view = headerSupplier.get();
|
((HeaderFooterHolder) holder).view = header;
|
||||||
} else if (holder instanceof HeaderFooterHolder && position == sizeConsideringHeader()
|
} else if (holder instanceof HeaderFooterHolder && position == sizeConsideringHeader()
|
||||||
&& footer != null && showFooter) {
|
&& footer != null && showFooter) {
|
||||||
((HeaderFooterHolder) holder).view = footer;
|
((HeaderFooterHolder) holder).view = footer;
|
||||||
@@ -397,10 +387,10 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
for (final Object payload : payloads) {
|
for (final Object payload : payloads) {
|
||||||
if (payload instanceof StreamStateEntity) {
|
if (payload instanceof StreamStateEntity) {
|
||||||
((LocalItemHolder) holder).updateState(localItems
|
((LocalItemHolder) holder).updateState(localItems
|
||||||
.get(hasHeader() ? position - 1 : position), recordManager);
|
.get(header == null ? position : position - 1), recordManager);
|
||||||
} else if (payload instanceof Boolean) {
|
} else if (payload instanceof Boolean) {
|
||||||
((LocalItemHolder) holder).updateState(localItems
|
((LocalItemHolder) holder).updateState(localItems
|
||||||
.get(hasHeader() ? position - 1 : position), recordManager);
|
.get(header == null ? position : position - 1), recordManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ import io.reactivex.rxjava3.core.Completable
|
|||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.core.Maybe
|
import io.reactivex.rxjava3.core.Maybe
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.time.LocalDate
|
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
import org.schabi.newpipe.MainActivity.DEBUG
|
import org.schabi.newpipe.MainActivity.DEBUG
|
||||||
import org.schabi.newpipe.NewPipeDatabase
|
import org.schabi.newpipe.NewPipeDatabase
|
||||||
import org.schabi.newpipe.database.feed.model.FeedEntity
|
import org.schabi.newpipe.database.feed.model.FeedEntity
|
||||||
@@ -21,6 +18,9 @@ import org.schabi.newpipe.database.subscription.NotificationMode
|
|||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType
|
import org.schabi.newpipe.extractor.stream.StreamType
|
||||||
import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
|
||||||
class FeedDatabaseManager(context: Context) {
|
class FeedDatabaseManager(context: Context) {
|
||||||
private val database = NewPipeDatabase.getInstance(context)
|
private val database = NewPipeDatabase.getInstance(context)
|
||||||
@@ -85,13 +85,14 @@ class FeedDatabaseManager(context: Context) {
|
|||||||
items: List<StreamInfoItem>,
|
items: List<StreamInfoItem>,
|
||||||
oldestAllowedDate: OffsetDateTime = FEED_OLDEST_ALLOWED_DATE
|
oldestAllowedDate: OffsetDateTime = FEED_OLDEST_ALLOWED_DATE
|
||||||
) {
|
) {
|
||||||
val itemsToInsert = items.mapNotNull { stream ->
|
val itemsToInsert = ArrayList<StreamInfoItem>()
|
||||||
val uploadDate = stream.uploadDate
|
loop@ for (streamItem in items) {
|
||||||
|
val uploadDate = streamItem.uploadDate
|
||||||
|
|
||||||
when {
|
itemsToInsert += when {
|
||||||
uploadDate == null && stream.streamType == StreamType.LIVE_STREAM -> stream
|
uploadDate == null && streamItem.streamType == StreamType.LIVE_STREAM -> streamItem
|
||||||
uploadDate != null && uploadDate.offsetDateTime() >= oldestAllowedDate -> stream
|
uploadDate != null && uploadDate.offsetDateTime() >= oldestAllowedDate -> streamItem
|
||||||
else -> null
|
else -> continue@loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,6 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import java.util.function.Consumer
|
|
||||||
import org.schabi.newpipe.NewPipeDatabase
|
import org.schabi.newpipe.NewPipeDatabase
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
@@ -83,6 +81,8 @@ import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountStreams
|
|||||||
import org.schabi.newpipe.util.ThemeHelper.getItemViewMode
|
import org.schabi.newpipe.util.ThemeHelper.getItemViewMode
|
||||||
import org.schabi.newpipe.util.ThemeHelper.resolveDrawable
|
import org.schabi.newpipe.util.ThemeHelper.resolveDrawable
|
||||||
import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout
|
import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
class FeedFragment : BaseStateFragment<FeedState>() {
|
class FeedFragment : BaseStateFragment<FeedState>() {
|
||||||
private var _feedBinding: FragmentFeedBinding? = null
|
private var _feedBinding: FragmentFeedBinding? = null
|
||||||
@@ -91,10 +91,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
private lateinit var viewModel: FeedViewModel
|
private lateinit var viewModel: FeedViewModel
|
||||||
|
@State @JvmField var listState: Parcelable? = null
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var listState: Parcelable? = null
|
|
||||||
|
|
||||||
private var groupId = FeedGroupEntity.GROUP_ALL_ID
|
private var groupId = FeedGroupEntity.GROUP_ALL_ID
|
||||||
private var groupName = ""
|
private var groupName = ""
|
||||||
@@ -152,6 +149,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
if (newState == RecyclerView.SCROLL_STATE_IDLE &&
|
if (newState == RecyclerView.SCROLL_STATE_IDLE &&
|
||||||
!recyclerView.canScrollVertically(-1)
|
!recyclerView.canScrollVertically(-1)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (tryGetNewItemsLoadedButton()?.isVisible == true) {
|
if (tryGetNewItemsLoadedButton()?.isVisible == true) {
|
||||||
hideNewItemsLoaded(true)
|
hideNewItemsLoaded(true)
|
||||||
}
|
}
|
||||||
@@ -255,7 +253,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
viewModel.getShowFutureItemsFromPreferences()
|
viewModel.getShowFutureItemsFromPreferences()
|
||||||
)
|
)
|
||||||
|
|
||||||
AlertDialog.Builder(requireContext())
|
AlertDialog.Builder(context!!)
|
||||||
.setTitle(R.string.feed_hide_streams_title)
|
.setTitle(R.string.feed_hide_streams_title)
|
||||||
.setMultiChoiceItems(dialogItems, checkedDialogItems) { _, which, isChecked ->
|
.setMultiChoiceItems(dialogItems, checkedDialogItems) { _, which, isChecked ->
|
||||||
checkedDialogItems[which] = isChecked
|
checkedDialogItems[which] = isChecked
|
||||||
@@ -389,13 +387,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
if (item is StreamItem && !isRefreshing) {
|
if (item is StreamItem && !isRefreshing) {
|
||||||
val stream = item.streamWithState.stream
|
val stream = item.streamWithState.stream
|
||||||
NavigationHelper.openVideoDetailFragment(
|
NavigationHelper.openVideoDetailFragment(
|
||||||
requireContext(),
|
requireContext(), fm,
|
||||||
fm,
|
stream.serviceId, stream.url, stream.title, null, false
|
||||||
stream.serviceId,
|
|
||||||
stream.url,
|
|
||||||
stream.title,
|
|
||||||
null,
|
|
||||||
false
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,8 +500,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
) {
|
) {
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
val isFastFeedModeEnabled = sharedPreferences.getBoolean(
|
val isFastFeedModeEnabled = sharedPreferences.getBoolean(
|
||||||
getString(R.string.feed_use_dedicated_fetch_method_key),
|
getString(R.string.feed_use_dedicated_fetch_method_key), false
|
||||||
false
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val builder = AlertDialog.Builder(requireContext())
|
val builder = AlertDialog.Builder(requireContext())
|
||||||
@@ -543,8 +535,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
private fun updateRelativeTimeViews() {
|
private fun updateRelativeTimeViews() {
|
||||||
updateRefreshViewState()
|
updateRefreshViewState()
|
||||||
groupAdapter.notifyItemRangeChanged(
|
groupAdapter.notifyItemRangeChanged(
|
||||||
0,
|
0, groupAdapter.itemCount,
|
||||||
groupAdapter.itemCount,
|
|
||||||
StreamItem.UPDATE_RELATIVE_TIME
|
StreamItem.UPDATE_RELATIVE_TIME
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.schabi.newpipe.local.feed
|
package org.schabi.newpipe.local.feed
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import org.schabi.newpipe.local.feed.item.StreamItem
|
import org.schabi.newpipe.local.feed.item.StreamItem
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
sealed class FeedState {
|
sealed class FeedState {
|
||||||
data class ProgressState(
|
data class ProgressState(
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import io.reactivex.rxjava3.core.Flowable
|
|||||||
import io.reactivex.rxjava3.functions.Function6
|
import io.reactivex.rxjava3.functions.Function6
|
||||||
import io.reactivex.rxjava3.processors.BehaviorProcessor
|
import io.reactivex.rxjava3.processors.BehaviorProcessor
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import org.schabi.newpipe.App
|
import org.schabi.newpipe.App
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
@@ -27,6 +25,8 @@ import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.IdleEvent
|
|||||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.ProgressEvent
|
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.ProgressEvent
|
||||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.SuccessResultEvent
|
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.SuccessResultEvent
|
||||||
import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT
|
import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class FeedViewModel(
|
class FeedViewModel(
|
||||||
private val application: Application,
|
private val application: Application,
|
||||||
@@ -64,14 +64,8 @@ class FeedViewModel(
|
|||||||
feedDatabaseManager.notLoadedCount(groupId),
|
feedDatabaseManager.notLoadedCount(groupId),
|
||||||
feedDatabaseManager.oldestSubscriptionUpdate(groupId),
|
feedDatabaseManager.oldestSubscriptionUpdate(groupId),
|
||||||
|
|
||||||
Function6 {
|
Function6 { t1: FeedEventManager.Event, t2: Boolean, t3: Boolean, t4: Boolean,
|
||||||
t1: FeedEventManager.Event,
|
t5: Long, t6: List<OffsetDateTime?> ->
|
||||||
t2: Boolean,
|
|
||||||
t3: Boolean,
|
|
||||||
t4: Boolean,
|
|
||||||
t5: Long,
|
|
||||||
t6: List<OffsetDateTime?>
|
|
||||||
->
|
|
||||||
return@Function6 CombineResultEventHolder(t1, t2, t3, t4, t5, t6.firstOrNull())
|
return@Function6 CombineResultEventHolder(t1, t2, t3, t4, t5, t6.firstOrNull())
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -79,13 +73,12 @@ class FeedViewModel(
|
|||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.map { (event, showPlayedItems, showPartiallyPlayedItems, showFutureItems, notLoadedCount, oldestUpdate) ->
|
.map { (event, showPlayedItems, showPartiallyPlayedItems, showFutureItems, notLoadedCount, oldestUpdate) ->
|
||||||
val streamItems = if (event is SuccessResultEvent || event is IdleEvent) {
|
val streamItems = if (event is SuccessResultEvent || event is IdleEvent)
|
||||||
feedDatabaseManager
|
feedDatabaseManager
|
||||||
.getStreams(groupId, showPlayedItems, showPartiallyPlayedItems, showFutureItems)
|
.getStreams(groupId, showPlayedItems, showPartiallyPlayedItems, showFutureItems)
|
||||||
.blockingGet(arrayListOf())
|
.blockingGet(arrayListOf())
|
||||||
} else {
|
else
|
||||||
arrayListOf()
|
arrayListOf()
|
||||||
}
|
|
||||||
|
|
||||||
CombineResultDataHolder(event, streamItems, notLoadedCount, oldestUpdate)
|
CombineResultDataHolder(event, streamItems, notLoadedCount, oldestUpdate)
|
||||||
}
|
}
|
||||||
@@ -157,14 +150,17 @@ class FeedViewModel(
|
|||||||
fun getShowFutureItemsFromPreferences() = getShowFutureItemsFromPreferences(application)
|
fun getShowFutureItemsFromPreferences() = getShowFutureItemsFromPreferences(application)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun getShowPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
|
private fun getShowPlayedItemsFromPreferences(context: Context) =
|
||||||
.getBoolean(context.getString(R.string.feed_show_watched_items_key), true)
|
PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getBoolean(context.getString(R.string.feed_show_watched_items_key), true)
|
||||||
|
|
||||||
private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
|
private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) =
|
||||||
.getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true)
|
PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true)
|
||||||
|
|
||||||
private fun getShowFutureItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
|
private fun getShowFutureItemsFromPreferences(context: Context) =
|
||||||
.getBoolean(context.getString(R.string.feed_show_future_items_key), true)
|
PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getBoolean(context.getString(R.string.feed_show_future_items_key), true)
|
||||||
|
|
||||||
fun getFactory(context: Context, groupId: Long) = viewModelFactory {
|
fun getFactory(context: Context, groupId: Long) = viewModelFactory {
|
||||||
initializer {
|
initializer {
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import android.view.View
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.xwray.groupie.viewbinding.BindableItem
|
import com.xwray.groupie.viewbinding.BindableItem
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import java.util.function.Consumer
|
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.stream.StreamWithState
|
import org.schabi.newpipe.database.stream.StreamWithState
|
||||||
@@ -22,6 +20,8 @@ import org.schabi.newpipe.extractor.stream.StreamType.VIDEO_STREAM
|
|||||||
import org.schabi.newpipe.util.Localization
|
import org.schabi.newpipe.util.Localization
|
||||||
import org.schabi.newpipe.util.StreamTypeUtil
|
import org.schabi.newpipe.util.StreamTypeUtil
|
||||||
import org.schabi.newpipe.util.image.PicassoHelper
|
import org.schabi.newpipe.util.image.PicassoHelper
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
data class StreamItem(
|
data class StreamItem(
|
||||||
val streamWithState: StreamWithState,
|
val streamWithState: StreamWithState,
|
||||||
@@ -132,7 +132,6 @@ data class StreamItem(
|
|||||||
viewsAndDate.isEmpty() -> uploadDate!!
|
viewsAndDate.isEmpty() -> uploadDate!!
|
||||||
else -> Localization.concatenateStrings(viewsAndDate, uploadDate)
|
else -> Localization.concatenateStrings(viewsAndDate, uploadDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> viewsAndDate
|
else -> viewsAndDate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import androidx.core.app.NotificationManagerCompat
|
|||||||
import androidx.core.app.PendingIntentCompat
|
import androidx.core.app.PendingIntentCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import com.squareup.picasso.Target
|
import com.squareup.picasso.Target
|
||||||
@@ -42,9 +41,7 @@ class NotificationHelper(val context: Context) {
|
|||||||
fun displayNewStreamsNotifications(data: FeedUpdateInfo) {
|
fun displayNewStreamsNotifications(data: FeedUpdateInfo) {
|
||||||
val newStreams = data.newStreams
|
val newStreams = data.newStreams
|
||||||
val summary = context.resources.getQuantityString(
|
val summary = context.resources.getQuantityString(
|
||||||
R.plurals.new_streams,
|
R.plurals.new_streams, newStreams.size, newStreams.size
|
||||||
newStreams.size,
|
|
||||||
newStreams.size
|
|
||||||
)
|
)
|
||||||
val summaryBuilder = NotificationCompat.Builder(
|
val summaryBuilder = NotificationCompat.Builder(
|
||||||
context,
|
context,
|
||||||
@@ -92,10 +89,8 @@ class NotificationHelper(val context: Context) {
|
|||||||
// Show individual stream notifications, set channel icon only if there is actually
|
// Show individual stream notifications, set channel icon only if there is actually
|
||||||
// one
|
// one
|
||||||
showStreamNotifications(newStreams, data.serviceId, data.url, bitmap)
|
showStreamNotifications(newStreams, data.serviceId, data.url, bitmap)
|
||||||
// Show summary notification if enabled
|
// Show summary notification
|
||||||
if (manager.areNotificationsEnabled()) {
|
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
|
||||||
}
|
|
||||||
|
|
||||||
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
||||||
}
|
}
|
||||||
@@ -103,10 +98,8 @@ class NotificationHelper(val context: Context) {
|
|||||||
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
|
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
|
||||||
// Show individual stream notifications
|
// Show individual stream notifications
|
||||||
showStreamNotifications(newStreams, data.serviceId, data.url, null)
|
showStreamNotifications(newStreams, data.serviceId, data.url, null)
|
||||||
// Show summary notification if enabled
|
// Show summary notification
|
||||||
if (manager.areNotificationsEnabled()) {
|
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
|
||||||
}
|
|
||||||
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,9 +123,7 @@ class NotificationHelper(val context: Context) {
|
|||||||
) {
|
) {
|
||||||
for (stream in newStreams) {
|
for (stream in newStreams) {
|
||||||
val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon)
|
val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon)
|
||||||
if (manager.areNotificationsEnabled()) {
|
manager.notify(stream.url.hashCode(), notification)
|
||||||
manager.notify(stream.url.hashCode(), notification)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +181,8 @@ class NotificationHelper(val context: Context) {
|
|||||||
val manager = context.getSystemService<NotificationManager>()!!
|
val manager = context.getSystemService<NotificationManager>()!!
|
||||||
val enabled = manager.areNotificationsEnabled()
|
val enabled = manager.areNotificationsEnabled()
|
||||||
val channel = manager.getNotificationChannel(channelId)
|
val channel = manager.getNotificationChannel(channelId)
|
||||||
enabled && channel?.importance != NotificationManager.IMPORTANCE_NONE
|
val importance = channel?.importance
|
||||||
|
enabled && channel != null && importance != NotificationManager.IMPORTANCE_NONE
|
||||||
} else {
|
} else {
|
||||||
NotificationManagerCompat.from(context).areNotificationsEnabled()
|
NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||||
}
|
}
|
||||||
@@ -220,7 +212,7 @@ class NotificationHelper(val context: Context) {
|
|||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
} else {
|
} else {
|
||||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
intent.data = "package:${context.packageName}".toUri()
|
intent.data = Uri.parse("package:" + context.packageName)
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import androidx.work.WorkerParameters
|
|||||||
import androidx.work.rxjava3.RxWorker
|
import androidx.work.rxjava3.RxWorker
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import org.schabi.newpipe.App
|
import org.schabi.newpipe.App
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.error.ErrorInfo
|
import org.schabi.newpipe.error.ErrorInfo
|
||||||
@@ -24,6 +23,7 @@ import org.schabi.newpipe.error.ErrorUtil
|
|||||||
import org.schabi.newpipe.error.UserAction
|
import org.schabi.newpipe.error.UserAction
|
||||||
import org.schabi.newpipe.local.feed.service.FeedLoadManager
|
import org.schabi.newpipe.local.feed.service.FeedLoadManager
|
||||||
import org.schabi.newpipe.local.feed.service.FeedLoadService
|
import org.schabi.newpipe.local.feed.service.FeedLoadService
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Worker which checks for new streams of subscribed channels
|
* Worker which checks for new streams of subscribed channels
|
||||||
@@ -31,7 +31,7 @@ import org.schabi.newpipe.local.feed.service.FeedLoadService
|
|||||||
*/
|
*/
|
||||||
class NotificationWorker(
|
class NotificationWorker(
|
||||||
appContext: Context,
|
appContext: Context,
|
||||||
workerParams: WorkerParameters
|
workerParams: WorkerParameters,
|
||||||
) : RxWorker(appContext, workerParams) {
|
) : RxWorker(appContext, workerParams) {
|
||||||
|
|
||||||
private val notificationHelper by lazy {
|
private val notificationHelper by lazy {
|
||||||
@@ -95,8 +95,9 @@ class NotificationWorker(
|
|||||||
private val TAG = NotificationWorker::class.java.simpleName
|
private val TAG = NotificationWorker::class.java.simpleName
|
||||||
private const val WORK_TAG = App.PACKAGE_NAME + "_streams_notifications"
|
private const val WORK_TAG = App.PACKAGE_NAME + "_streams_notifications"
|
||||||
|
|
||||||
private fun areNotificationsEnabled(context: Context) = NotificationHelper.areNewStreamsNotificationsEnabled(context) &&
|
private fun areNotificationsEnabled(context: Context) =
|
||||||
NotificationHelper.areNotificationsEnabledOnDevice(context)
|
NotificationHelper.areNewStreamsNotificationsEnabled(context) &&
|
||||||
|
NotificationHelper.areNotificationsEnabledOnDevice(context)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules a task for the [NotificationWorker]
|
* Schedules a task for the [NotificationWorker]
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package org.schabi.newpipe.local.feed.notifications
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.ktx.getStringSafe
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information for the Scheduler which checks for new streams.
|
* Information for the Scheduler which checks for new streams.
|
||||||
@@ -21,9 +20,11 @@ data class ScheduleOptions(
|
|||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
return ScheduleOptions(
|
return ScheduleOptions(
|
||||||
interval = TimeUnit.SECONDS.toMillis(
|
interval = TimeUnit.SECONDS.toMillis(
|
||||||
preferences.getStringSafe(
|
preferences.getString(
|
||||||
context.getString(R.string.streams_notifications_interval_key),
|
context.getString(R.string.streams_notifications_interval_key),
|
||||||
context.getString(R.string.streams_notifications_interval_default)
|
null
|
||||||
|
)?.toLongOrNull() ?: context.getString(
|
||||||
|
R.string.streams_notifications_interval_default
|
||||||
).toLong()
|
).toLong()
|
||||||
),
|
),
|
||||||
isRequireNonMeteredNetwork = preferences.getString(
|
isRequireNonMeteredNetwork = preferences.getString(
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package org.schabi.newpipe.local.feed.service
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.processors.BehaviorProcessor
|
import io.reactivex.rxjava3.processors.BehaviorProcessor
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
|
||||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.IdleEvent
|
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.IdleEvent
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
object FeedEventManager {
|
object FeedEventManager {
|
||||||
private var processor: BehaviorProcessor<Event> = BehaviorProcessor.create()
|
private var processor: BehaviorProcessor<Event> = BehaviorProcessor.create()
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ import io.reactivex.rxjava3.core.Single
|
|||||||
import io.reactivex.rxjava3.functions.Consumer
|
import io.reactivex.rxjava3.functions.Consumer
|
||||||
import io.reactivex.rxjava3.processors.PublishProcessor
|
import io.reactivex.rxjava3.processors.PublishProcessor
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.database.subscription.NotificationMode
|
import org.schabi.newpipe.database.subscription.NotificationMode
|
||||||
@@ -31,6 +27,10 @@ import org.schabi.newpipe.util.ChannelTabHelper
|
|||||||
import org.schabi.newpipe.util.ExtractorHelper.getChannelInfo
|
import org.schabi.newpipe.util.ExtractorHelper.getChannelInfo
|
||||||
import org.schabi.newpipe.util.ExtractorHelper.getChannelTab
|
import org.schabi.newpipe.util.ExtractorHelper.getChannelTab
|
||||||
import org.schabi.newpipe.util.ExtractorHelper.getMoreChannelTabItems
|
import org.schabi.newpipe.util.ExtractorHelper.getMoreChannelTabItems
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
class FeedLoadManager(private val context: Context) {
|
class FeedLoadManager(private val context: Context) {
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
*/
|
*/
|
||||||
fun startLoading(
|
fun startLoading(
|
||||||
groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
||||||
ignoreOutdatedThreshold: Boolean = false
|
ignoreOutdatedThreshold: Boolean = false,
|
||||||
): Single<List<Notification<FeedUpdateInfo>>> {
|
): Single<List<Notification<FeedUpdateInfo>>> {
|
||||||
val defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val useFeedExtractor = defaultSharedPreferences.getBoolean(
|
val useFeedExtractor = defaultSharedPreferences.getBoolean(
|
||||||
@@ -85,12 +85,9 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(
|
FeedGroupEntity.GROUP_ALL_ID -> feedDatabaseManager.outdatedSubscriptions(
|
||||||
outdatedThreshold
|
outdatedThreshold
|
||||||
)
|
)
|
||||||
|
|
||||||
GROUP_NOTIFICATION_ENABLED -> feedDatabaseManager.outdatedSubscriptionsWithNotificationMode(
|
GROUP_NOTIFICATION_ENABLED -> feedDatabaseManager.outdatedSubscriptionsWithNotificationMode(
|
||||||
outdatedThreshold,
|
outdatedThreshold, NotificationMode.ENABLED
|
||||||
NotificationMode.ENABLED
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> feedDatabaseManager.outdatedSubscriptionsForGroup(groupId, outdatedThreshold)
|
else -> feedDatabaseManager.outdatedSubscriptionsForGroup(groupId, outdatedThreshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +108,7 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
broadcastProgress()
|
broadcastProgress()
|
||||||
}
|
}
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
// Randomize user subscription ordering to attempt to resist fingerprinting
|
.flatMap { Flowable.fromIterable(it) }
|
||||||
.flatMap { Flowable.fromIterable(it.shuffled()) }
|
|
||||||
.takeWhile { !cancelSignal.get() }
|
.takeWhile { !cancelSignal.get() }
|
||||||
.doOnNext { subscriptionEntity ->
|
.doOnNext { subscriptionEntity ->
|
||||||
// throttle YouTube extractions once every BATCH_SIZE to avoid being rate limited
|
// throttle YouTube extractions once every BATCH_SIZE to avoid being rate limited
|
||||||
@@ -190,8 +186,7 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
|
|
||||||
val channelInfo = getChannelInfo(
|
val channelInfo = getChannelInfo(
|
||||||
subscriptionEntity.serviceId,
|
subscriptionEntity.serviceId,
|
||||||
subscriptionEntity.url,
|
subscriptionEntity.url, true
|
||||||
true
|
|
||||||
)
|
)
|
||||||
.onErrorReturn(storeOriginalErrorAndRethrow)
|
.onErrorReturn(storeOriginalErrorAndRethrow)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
@@ -221,8 +216,7 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
) {
|
) {
|
||||||
val infoItemsPage = getMoreChannelTabItems(
|
val infoItemsPage = getMoreChannelTabItems(
|
||||||
subscriptionEntity.serviceId,
|
subscriptionEntity.serviceId,
|
||||||
linkHandler,
|
linkHandler, channelTabInfo.nextPage
|
||||||
channelTabInfo.nextPage
|
|
||||||
)
|
)
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
|
|
||||||
@@ -240,7 +234,7 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
subscriptionEntity,
|
subscriptionEntity,
|
||||||
originalInfo!!,
|
originalInfo!!,
|
||||||
streams!!,
|
streams!!,
|
||||||
errors
|
errors,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@@ -311,7 +305,6 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
feedDatabaseManager.markAsOutdated(info.uid)
|
feedDatabaseManager.markAsOutdated(info.uid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.isOnError -> {
|
notification.isOnError -> {
|
||||||
val error = notification.error
|
val error = notification.error
|
||||||
feedResultsHolder.addError(error!!)
|
feedResultsHolder.addError(error!!)
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import io.reactivex.rxjava3.functions.Function
|
import io.reactivex.rxjava3.functions.Function
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import org.schabi.newpipe.App
|
import org.schabi.newpipe.App
|
||||||
import org.schabi.newpipe.MainActivity.DEBUG
|
import org.schabi.newpipe.MainActivity.DEBUG
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.ErrorResultEvent
|
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.ErrorResultEvent
|
||||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.postEvent
|
import org.schabi.newpipe.local.feed.service.FeedEventManager.postEvent
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class FeedLoadService : Service() {
|
class FeedLoadService : Service() {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -94,8 +94,7 @@ class FeedLoadService : Service() {
|
|||||||
.doOnSubscribe {
|
.doOnSubscribe {
|
||||||
startForeground(NOTIFICATION_ID, notificationBuilder.build())
|
startForeground(NOTIFICATION_ID, notificationBuilder.build())
|
||||||
}
|
}
|
||||||
.subscribe { _, error: Throwable? ->
|
.subscribe { _, error: Throwable? -> // explicitly mark error as nullable
|
||||||
// explicitly mark error as nullable
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
Log.e(TAG, "Error while storing result", error)
|
Log.e(TAG, "Error while storing result", error)
|
||||||
handleError(error)
|
handleError(error)
|
||||||
@@ -185,9 +184,7 @@ class FeedLoadService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package org.schabi.newpipe.local.feed.service
|
|||||||
data class FeedLoadState(
|
data class FeedLoadState(
|
||||||
val updateDescription: String,
|
val updateDescription: String,
|
||||||
val maxProgress: Int,
|
val maxProgress: Int,
|
||||||
val currentProgress: Int
|
val currentProgress: Int,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ data class FeedUpdateInfo(
|
|||||||
val description: String?,
|
val description: String?,
|
||||||
val subscriberCount: Long?,
|
val subscriberCount: Long?,
|
||||||
val streams: List<StreamInfoItem>,
|
val streams: List<StreamInfoItem>,
|
||||||
val errors: List<Throwable>
|
val errors: List<Throwable>,
|
||||||
) {
|
) {
|
||||||
constructor(
|
constructor(
|
||||||
subscription: SubscriptionEntity,
|
subscription: SubscriptionEntity,
|
||||||
info: Info,
|
info: Info,
|
||||||
streams: List<StreamInfoItem>,
|
streams: List<StreamInfoItem>,
|
||||||
errors: List<Throwable>
|
errors: List<Throwable>,
|
||||||
) : this(
|
) : this(
|
||||||
uid = subscription.uid,
|
uid = subscription.uid,
|
||||||
notificationMode = subscription.notificationMode,
|
notificationMode = subscription.notificationMode,
|
||||||
@@ -46,7 +46,7 @@ data class FeedUpdateInfo(
|
|||||||
description = (info as? ChannelInfo)?.description,
|
description = (info as? ChannelInfo)?.description,
|
||||||
subscriberCount = (info as? ChannelInfo)?.subscriberCount,
|
subscriberCount = (info as? ChannelInfo)?.subscriberCount,
|
||||||
streams = streams,
|
streams = streams,
|
||||||
errors = errors
|
errors = errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.viewbinding.ViewBinding;
|
||||||
|
|
||||||
import com.evernote.android.state.State;
|
import com.evernote.android.state.State;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
@@ -44,7 +45,6 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
@@ -126,12 +126,12 @@ public class StatisticsPlaylistFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<View> getListHeaderSupplier() {
|
protected ViewBinding getListHeader() {
|
||||||
headerBinding = StatisticPlaylistControlBinding.inflate(activity.getLayoutInflater(),
|
headerBinding = StatisticPlaylistControlBinding.inflate(activity.getLayoutInflater(),
|
||||||
itemsList, false);
|
itemsList, false);
|
||||||
playlistControlBinding = headerBinding.playlistControl;
|
playlistControlBinding = headerBinding.playlistControl;
|
||||||
|
|
||||||
return headerBinding::getRoot;
|
return headerBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ private fun exportJustUrls(playlist: List<PlaylistStreamEntry>): String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun exportAsYoutubeTempPlaylist(playlist: List<PlaylistStreamEntry>): String {
|
private fun exportAsYoutubeTempPlaylist(playlist: List<PlaylistStreamEntry>): String {
|
||||||
|
|
||||||
val videoIDs = playlist.asReversed().asSequence()
|
val videoIDs = playlist.asReversed().asSequence()
|
||||||
.mapNotNull { getYouTubeId(it.streamEntity.url) }
|
.mapNotNull { getYouTubeId(it.streamEntity.url) }
|
||||||
.take(50) // YouTube limitation: temp playlists can't have more than 50 items
|
.take(50) // YouTube limitation: temp playlists can't have more than 50 items
|
||||||
@@ -63,5 +64,6 @@ private val linkHandler: YoutubeStreamLinkHandlerFactory = YoutubeStreamLinkHand
|
|||||||
* @return the video id
|
* @return the video id
|
||||||
*/
|
*/
|
||||||
private fun getYouTubeId(url: String): String? {
|
private fun getYouTubeId(url: String): String? {
|
||||||
return runCatching { linkHandler.getId(url) }.getOrNull()
|
|
||||||
|
return try { linkHandler.getId(url) } catch (e: ParsingException) { null }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.schabi.newpipe.local.playlist;
|
package org.schabi.newpipe.local.playlist;
|
||||||
|
|
||||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
||||||
import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar;
|
import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar;
|
||||||
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
||||||
import static org.schabi.newpipe.local.playlist.ExportPlaylistKt.export;
|
import static org.schabi.newpipe.local.playlist.ExportPlaylistKt.export;
|
||||||
@@ -24,8 +22,6 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -33,6 +29,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.viewbinding.ViewBinding;
|
||||||
|
|
||||||
import com.evernote.android.state.State;
|
import com.evernote.android.state.State;
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
@@ -58,7 +55,6 @@ import org.schabi.newpipe.local.BaseLocalListFragment;
|
|||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
import org.schabi.newpipe.util.DeviceUtils;
|
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
@@ -71,7 +67,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
@@ -163,14 +158,14 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<View> getListHeaderSupplier() {
|
protected ViewBinding getListHeader() {
|
||||||
headerBinding = LocalPlaylistHeaderBinding.inflate(activity.getLayoutInflater(), itemsList,
|
headerBinding = LocalPlaylistHeaderBinding.inflate(activity.getLayoutInflater(), itemsList,
|
||||||
false);
|
false);
|
||||||
playlistControlBinding = headerBinding.playlistControl;
|
playlistControlBinding = headerBinding.playlistControl;
|
||||||
|
|
||||||
headerBinding.playlistTitleView.setSelected(true);
|
headerBinding.playlistTitleView.setSelected(true);
|
||||||
|
|
||||||
return headerBinding::getRoot;
|
return headerBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -370,7 +365,17 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
createRenameDialog();
|
createRenameDialog();
|
||||||
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
|
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
|
||||||
if (!isRewritingPlaylist) {
|
if (!isRewritingPlaylist) {
|
||||||
openRemoveWatchedConfirmationDialog();
|
new AlertDialog.Builder(requireContext())
|
||||||
|
.setMessage(R.string.remove_watched_popup_warning)
|
||||||
|
.setTitle(R.string.remove_watched_popup_title)
|
||||||
|
.setPositiveButton(R.string.ok, (d, id) ->
|
||||||
|
removeWatchedStreams(false))
|
||||||
|
.setNeutralButton(
|
||||||
|
R.string.remove_watched_popup_yes_and_partially_watched_videos,
|
||||||
|
(d, id) -> removeWatchedStreams(true))
|
||||||
|
.setNegativeButton(R.string.cancel,
|
||||||
|
(d, id) -> d.cancel())
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
} else if (item.getItemId() == R.id.menu_item_remove_duplicates) {
|
} else if (item.getItemId() == R.id.menu_item_remove_duplicates) {
|
||||||
if (!isRewritingPlaylist) {
|
if (!isRewritingPlaylist) {
|
||||||
@@ -442,28 +447,39 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
.getIsPlaylistThumbnailPermanent(playlistId);
|
.getIsPlaylistThumbnailPermanent(playlistId);
|
||||||
boolean thumbnailVideoRemoved = false;
|
boolean thumbnailVideoRemoved = false;
|
||||||
|
|
||||||
final var streamStates = recordManager
|
if (removePartiallyWatched) {
|
||||||
.loadLocalStreamStateBatch(playlist).blockingGet();
|
for (final var playlistItem : playlist) {
|
||||||
|
final int indexInHistory = Collections.binarySearch(historyStreamIds,
|
||||||
|
playlistItem.getStreamId());
|
||||||
|
|
||||||
for (int i = 0; i < playlist.size(); i++) {
|
if (indexInHistory < 0) {
|
||||||
final var playlistItem = playlist.get(i);
|
itemsToKeep.add(playlistItem);
|
||||||
final var streamStateEntity = streamStates.get(i);
|
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved
|
||||||
final int indexInHistory = Collections.binarySearch(historyStreamIds,
|
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
|
||||||
playlistItem.getStreamId());
|
== playlistItem.getStreamEntity().getUid()) {
|
||||||
final long duration = playlistItem.toStreamInfoItem().getDuration();
|
thumbnailVideoRemoved = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final var streamStates = recordManager
|
||||||
|
.loadLocalStreamStateBatch(playlist).blockingGet();
|
||||||
|
|
||||||
if (indexInHistory < 0 // stream is not in history
|
for (int i = 0; i < playlist.size(); i++) {
|
||||||
// stream is in history but the streamStateEntity is null
|
final var playlistItem = playlist.get(i);
|
||||||
// if the stream was played for less than 5 seconds, see
|
final var streamStateEntity = streamStates.get(i);
|
||||||
// StreamStateEntity#PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS
|
|
||||||
|| streamStateEntity == null
|
final int indexInHistory = Collections.binarySearch(historyStreamIds,
|
||||||
|| (!removePartiallyWatched
|
playlistItem.getStreamId());
|
||||||
&& !streamStateEntity.isFinished(duration))) {
|
final long duration = playlistItem.toStreamInfoItem().getDuration();
|
||||||
itemsToKeep.add(playlistItem);
|
|
||||||
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved
|
if (indexInHistory < 0 || (streamStateEntity != null
|
||||||
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
|
&& !streamStateEntity.isFinished(duration))) {
|
||||||
== playlistItem.getStreamEntity().getUid()) {
|
itemsToKeep.add(playlistItem);
|
||||||
thumbnailVideoRemoved = true;
|
} else if (!isThumbnailPermanent && !thumbnailVideoRemoved
|
||||||
|
&& playlistManager.getPlaylistThumbnailStreamId(playlistId)
|
||||||
|
== playlistItem.getStreamEntity().getUid()) {
|
||||||
|
thumbnailVideoRemoved = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,35 +904,6 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a confirmation dialog to remove watched streams from the playlist.
|
|
||||||
* The user can also choose to remove partially watched streams.
|
|
||||||
*/
|
|
||||||
private void openRemoveWatchedConfirmationDialog() {
|
|
||||||
final android.widget.CheckBox removePartiallyWatchedCheckbox =
|
|
||||||
new android.widget.CheckBox(requireContext());
|
|
||||||
removePartiallyWatchedCheckbox.setText(
|
|
||||||
R.string.remove_watched_popup_partially_watched_streams);
|
|
||||||
|
|
||||||
// Wrap the checkbox in a container with dialog-like horizontal padding
|
|
||||||
// so it aligns with the dialog title and message on the start side.
|
|
||||||
final LinearLayout checkboxContainer = new LinearLayout(requireContext());
|
|
||||||
checkboxContainer.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
final int padding = DeviceUtils.dpToPx(20, requireContext());
|
|
||||||
checkboxContainer.setPadding(padding, padding, padding, 0);
|
|
||||||
checkboxContainer.addView(removePartiallyWatchedCheckbox,
|
|
||||||
new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
|
||||||
|
|
||||||
new AlertDialog.Builder(requireContext())
|
|
||||||
.setMessage(R.string.remove_watched_popup_warning)
|
|
||||||
.setTitle(R.string.remove_watched_popup_title)
|
|
||||||
.setView(checkboxContainer)
|
|
||||||
.setPositiveButton(R.string.yes, (d, id) ->
|
|
||||||
removeWatchedStreams(removePartiallyWatchedCheckbox.isChecked()))
|
|
||||||
.setNegativeButton(R.string.cancel, (d, id) -> d.cancel())
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTabsPagerAdapter(
|
public void setTabsPagerAdapter(
|
||||||
@Nullable final MainFragment.SelectedTabsPagerAdapter tabsPagerAdapter) {
|
@Nullable final MainFragment.SelectedTabsPagerAdapter tabsPagerAdapter) {
|
||||||
this.tabsPagerAdapter = tabsPagerAdapter;
|
this.tabsPagerAdapter = tabsPagerAdapter;
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ import com.xwray.groupie.GroupAdapter
|
|||||||
import com.xwray.groupie.Section
|
import com.xwray.groupie.Section
|
||||||
import com.xwray.groupie.viewbinding.GroupieViewHolder
|
import com.xwray.groupie.viewbinding.GroupieViewHolder
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Date
|
|
||||||
import java.util.Locale
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity.Companion.GROUP_ALL_ID
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity.Companion.GROUP_ALL_ID
|
||||||
import org.schabi.newpipe.databinding.DialogTitleBinding
|
import org.schabi.newpipe.databinding.DialogTitleBinding
|
||||||
@@ -65,6 +62,9 @@ import org.schabi.newpipe.util.OnClickGesture
|
|||||||
import org.schabi.newpipe.util.ServiceHelper
|
import org.schabi.newpipe.util.ServiceHelper
|
||||||
import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountChannels
|
import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountChannels
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils
|
import org.schabi.newpipe.util.external_communication.ShareUtils
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
||||||
private var _binding: FragmentSubscriptionBinding? = null
|
private var _binding: FragmentSubscriptionBinding? = null
|
||||||
@@ -276,13 +276,10 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
when (item) {
|
when (item) {
|
||||||
is FeedGroupCardItem ->
|
is FeedGroupCardItem ->
|
||||||
NavigationHelper.openFeedFragment(fm, item.groupId, item.name)
|
NavigationHelper.openFeedFragment(fm, item.groupId, item.name)
|
||||||
|
|
||||||
is FeedGroupCardGridItem ->
|
is FeedGroupCardGridItem ->
|
||||||
NavigationHelper.openFeedFragment(fm, item.groupId, item.name)
|
NavigationHelper.openFeedFragment(fm, item.groupId, item.name)
|
||||||
|
|
||||||
is FeedGroupAddNewItem ->
|
is FeedGroupAddNewItem ->
|
||||||
FeedGroupDialog.newInstance().show(fm, null)
|
FeedGroupDialog.newInstance().show(fm, null)
|
||||||
|
|
||||||
is FeedGroupAddNewGridItem ->
|
is FeedGroupAddNewGridItem ->
|
||||||
FeedGroupDialog.newInstance().show(fm, null)
|
FeedGroupDialog.newInstance().show(fm, null)
|
||||||
}
|
}
|
||||||
@@ -297,7 +294,6 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
when (item) {
|
when (item) {
|
||||||
is FeedGroupCardItem ->
|
is FeedGroupCardItem ->
|
||||||
FeedGroupDialog.newInstance(item.groupId).show(fm, null)
|
FeedGroupDialog.newInstance(item.groupId).show(fm, null)
|
||||||
|
|
||||||
is FeedGroupCardGridItem ->
|
is FeedGroupCardGridItem ->
|
||||||
FeedGroupDialog.newInstance(item.groupId).show(fm, null)
|
FeedGroupDialog.newInstance(item.groupId).show(fm, null)
|
||||||
}
|
}
|
||||||
@@ -313,7 +309,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
title = getString(R.string.feed_groups_header_title),
|
title = getString(R.string.feed_groups_header_title),
|
||||||
onSortClicked = ::openReorderDialog,
|
onSortClicked = ::openReorderDialog,
|
||||||
onToggleListViewModeClicked = ::toggleListViewMode,
|
onToggleListViewModeClicked = ::toggleListViewMode,
|
||||||
listViewMode = viewModel.getListViewMode()
|
listViewMode = viewModel.getListViewMode(),
|
||||||
)
|
)
|
||||||
|
|
||||||
add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel)))
|
add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel)))
|
||||||
@@ -346,14 +342,9 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
val actions = DialogInterface.OnClickListener { _, i ->
|
val actions = DialogInterface.OnClickListener { _, i ->
|
||||||
when (i) {
|
when (i) {
|
||||||
0 -> ShareUtils.shareText(
|
0 -> ShareUtils.shareText(
|
||||||
requireContext(),
|
requireContext(), selectedItem.name, selectedItem.url, selectedItem.thumbnails
|
||||||
selectedItem.name,
|
|
||||||
selectedItem.url,
|
|
||||||
selectedItem.thumbnails
|
|
||||||
)
|
)
|
||||||
|
|
||||||
1 -> ShareUtils.openUrlInBrowser(requireContext(), selectedItem.url)
|
1 -> ShareUtils.openUrlInBrowser(requireContext(), selectedItem.url)
|
||||||
|
|
||||||
2 -> deleteChannel(selectedItem)
|
2 -> deleteChannel(selectedItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,9 +374,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
private val listenerChannelItem = object : OnClickGesture<ChannelInfoItem> {
|
private val listenerChannelItem = object : OnClickGesture<ChannelInfoItem> {
|
||||||
override fun selected(selectedItem: ChannelInfoItem) = NavigationHelper.openChannelFragment(
|
override fun selected(selectedItem: ChannelInfoItem) = NavigationHelper.openChannelFragment(
|
||||||
fm,
|
fm,
|
||||||
selectedItem.serviceId,
|
selectedItem.serviceId, selectedItem.url, selectedItem.name
|
||||||
selectedItem.url,
|
|
||||||
selectedItem.name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun held(selectedItem: ChannelInfoItem) = showLongTapDialog(selectedItem)
|
override fun held(selectedItem: ChannelInfoItem) = showLongTapDialog(selectedItem)
|
||||||
@@ -415,7 +404,6 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
itemsListState = null
|
itemsListState = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is SubscriptionState.ErrorState -> {
|
is SubscriptionState.ErrorState -> {
|
||||||
result.error?.let {
|
result.error?.let {
|
||||||
showError(ErrorInfo(result.error, UserAction.SOMETHING_ELSE, "Subscriptions"))
|
showError(ErrorInfo(result.error, UserAction.SOMETHING_ELSE, "Subscriptions"))
|
||||||
|
|||||||
@@ -37,16 +37,13 @@ class SubscriptionManager(context: Context) {
|
|||||||
filterQuery.isNotEmpty() -> {
|
filterQuery.isNotEmpty() -> {
|
||||||
return if (showOnlyUngrouped) {
|
return if (showOnlyUngrouped) {
|
||||||
subscriptionTable.getSubscriptionsOnlyUngroupedFiltered(
|
subscriptionTable.getSubscriptionsOnlyUngroupedFiltered(
|
||||||
currentGroupId,
|
currentGroupId, filterQuery
|
||||||
filterQuery
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
subscriptionTable.getSubscriptionsFiltered(filterQuery)
|
subscriptionTable.getSubscriptionsFiltered(filterQuery)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showOnlyUngrouped -> subscriptionTable.getSubscriptionsOnlyUngrouped(currentGroupId)
|
showOnlyUngrouped -> subscriptionTable.getSubscriptionsOnlyUngrouped(currentGroupId)
|
||||||
|
|
||||||
else -> subscriptionTable.getAll()
|
else -> subscriptionTable.getAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,18 +67,19 @@ class SubscriptionManager(context: Context) {
|
|||||||
return listEntities
|
return listEntities
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateChannelInfo(info: ChannelInfo): Completable = subscriptionTable.getSubscription(info.serviceId, info.url)
|
fun updateChannelInfo(info: ChannelInfo): Completable =
|
||||||
.flatMapCompletable {
|
subscriptionTable.getSubscription(info.serviceId, info.url)
|
||||||
Completable.fromRunnable {
|
.flatMapCompletable {
|
||||||
it.apply {
|
Completable.fromRunnable {
|
||||||
name = info.name
|
it.apply {
|
||||||
avatarUrl = ImageStrategy.imageListToDbUrl(info.avatars)
|
name = info.name
|
||||||
description = info.description
|
avatarUrl = ImageStrategy.imageListToDbUrl(info.avatars)
|
||||||
subscriberCount = info.subscriberCount
|
description = info.description
|
||||||
|
subscriberCount = info.subscriberCount
|
||||||
|
}
|
||||||
|
subscriptionTable.update(it)
|
||||||
}
|
}
|
||||||
subscriptionTable.update(it)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun updateNotificationMode(serviceId: Int, url: String, @NotificationMode mode: Int): Completable {
|
fun updateNotificationMode(serviceId: Int, url: String, @NotificationMode mode: Int): Completable {
|
||||||
return subscriptionTable().getSubscription(serviceId, url)
|
return subscriptionTable().getSubscription(serviceId, url)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.xwray.groupie.Group
|
|||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.processors.BehaviorProcessor
|
import io.reactivex.rxjava3.processors.BehaviorProcessor
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import org.schabi.newpipe.info_list.ItemViewMode
|
import org.schabi.newpipe.info_list.ItemViewMode
|
||||||
import org.schabi.newpipe.local.feed.FeedDatabaseManager
|
import org.schabi.newpipe.local.feed.FeedDatabaseManager
|
||||||
import org.schabi.newpipe.local.subscription.item.ChannelItem
|
import org.schabi.newpipe.local.subscription.item.ChannelItem
|
||||||
@@ -17,6 +16,7 @@ import org.schabi.newpipe.local.subscription.item.FeedGroupCardGridItem
|
|||||||
import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem
|
import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem
|
||||||
import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT
|
import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT
|
||||||
import org.schabi.newpipe.util.ThemeHelper.getItemViewMode
|
import org.schabi.newpipe.util.ThemeHelper.getItemViewMode
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class SubscriptionViewModel(application: Application) : AndroidViewModel(application) {
|
class SubscriptionViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
private var feedDatabaseManager: FeedDatabaseManager = FeedDatabaseManager(application)
|
private var feedDatabaseManager: FeedDatabaseManager = FeedDatabaseManager(application)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.livefront.bridge.Bridge
|
|||||||
import com.xwray.groupie.GroupieAdapter
|
import com.xwray.groupie.GroupieAdapter
|
||||||
import com.xwray.groupie.OnItemClickListener
|
import com.xwray.groupie.OnItemClickListener
|
||||||
import com.xwray.groupie.Section
|
import com.xwray.groupie.Section
|
||||||
import java.io.Serializable
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.databinding.DialogFeedGroupCreateBinding
|
import org.schabi.newpipe.databinding.DialogFeedGroupCreateBinding
|
||||||
@@ -41,6 +40,7 @@ import org.schabi.newpipe.local.subscription.item.PickerIconItem
|
|||||||
import org.schabi.newpipe.local.subscription.item.PickerSubscriptionItem
|
import org.schabi.newpipe.local.subscription.item.PickerSubscriptionItem
|
||||||
import org.schabi.newpipe.util.DeviceUtils
|
import org.schabi.newpipe.util.DeviceUtils
|
||||||
import org.schabi.newpipe.util.ThemeHelper
|
import org.schabi.newpipe.util.ThemeHelper
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
class FeedGroupDialog : DialogFragment(), BackPressable {
|
class FeedGroupDialog : DialogFragment(), BackPressable {
|
||||||
private var _feedGroupCreateBinding: DialogFeedGroupCreateBinding? = null
|
private var _feedGroupCreateBinding: DialogFeedGroupCreateBinding? = null
|
||||||
@@ -61,41 +61,16 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
|
|||||||
data object DeleteScreen : ScreenState()
|
data object DeleteScreen : ScreenState()
|
||||||
}
|
}
|
||||||
|
|
||||||
@State
|
@State @JvmField var selectedIcon: FeedGroupIcon? = null
|
||||||
@JvmField
|
@State @JvmField var selectedSubscriptions: HashSet<Long> = HashSet()
|
||||||
var selectedIcon: FeedGroupIcon? = null
|
@State @JvmField var wasSubscriptionSelectionChanged: Boolean = false
|
||||||
|
@State @JvmField var currentScreen: ScreenState = InitialScreen
|
||||||
|
|
||||||
@State
|
@State @JvmField var subscriptionsListState: Parcelable? = null
|
||||||
@JvmField
|
@State @JvmField var iconsListState: Parcelable? = null
|
||||||
var selectedSubscriptions: HashSet<Long> = HashSet()
|
@State @JvmField var wasSearchSubscriptionsVisible = false
|
||||||
|
@State @JvmField var subscriptionsCurrentSearchQuery = ""
|
||||||
@State
|
@State @JvmField var subscriptionsShowOnlyUngrouped = false
|
||||||
@JvmField
|
|
||||||
var wasSubscriptionSelectionChanged: Boolean = false
|
|
||||||
|
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var currentScreen: ScreenState = InitialScreen
|
|
||||||
|
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var subscriptionsListState: Parcelable? = null
|
|
||||||
|
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var iconsListState: Parcelable? = null
|
|
||||||
|
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var wasSearchSubscriptionsVisible = false
|
|
||||||
|
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var subscriptionsCurrentSearchQuery = ""
|
|
||||||
|
|
||||||
@State
|
|
||||||
@JvmField
|
|
||||||
var subscriptionsShowOnlyUngrouped = false
|
|
||||||
|
|
||||||
private val subscriptionMainSection = Section()
|
private val subscriptionMainSection = Section()
|
||||||
private val subscriptionEmptyFooter = Section()
|
private val subscriptionEmptyFooter = Section()
|
||||||
@@ -178,10 +153,8 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
|
|||||||
itemAnimator = null
|
itemAnimator = null
|
||||||
adapter = subscriptionGroupAdapter
|
adapter = subscriptionGroupAdapter
|
||||||
layoutManager = GridLayoutManager(
|
layoutManager = GridLayoutManager(
|
||||||
requireContext(),
|
requireContext(), subscriptionGroupAdapter.spanCount,
|
||||||
subscriptionGroupAdapter.spanCount,
|
RecyclerView.VERTICAL, false
|
||||||
RecyclerView.VERTICAL,
|
|
||||||
false
|
|
||||||
).apply {
|
).apply {
|
||||||
spanSizeLookup = subscriptionGroupAdapter.spanSizeLookup
|
spanSizeLookup = subscriptionGroupAdapter.spanSizeLookup
|
||||||
}
|
}
|
||||||
@@ -389,8 +362,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
|
|||||||
val selectedCount = this.selectedSubscriptions.size
|
val selectedCount = this.selectedSubscriptions.size
|
||||||
val selectedCountText = resources.getQuantityString(
|
val selectedCountText = resources.getQuantityString(
|
||||||
R.plurals.feed_group_dialog_selection_count,
|
R.plurals.feed_group_dialog_selection_count,
|
||||||
selectedCount,
|
selectedCount, selectedCount
|
||||||
selectedCount
|
|
||||||
)
|
)
|
||||||
feedGroupCreateBinding.selectedSubscriptionCountView.text = selectedCountText
|
feedGroupCreateBinding.selectedSubscriptionCountView.text = selectedCountText
|
||||||
feedGroupCreateBinding.subscriptionsHeaderInfo.text = selectedCountText
|
feedGroupCreateBinding.subscriptionsHeaderInfo.text = selectedCountText
|
||||||
@@ -506,7 +478,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
|
|||||||
private fun hideKeyboardSearch() {
|
private fun hideKeyboardSearch() {
|
||||||
inputMethodManager.hideSoftInputFromWindow(
|
inputMethodManager.hideSoftInputFromWindow(
|
||||||
searchLayoutBinding.toolbarSearchEditText.windowToken,
|
searchLayoutBinding.toolbarSearchEditText.windowToken,
|
||||||
InputMethodManager.HIDE_NOT_ALWAYS
|
InputMethodManager.RESULT_UNCHANGED_SHOWN
|
||||||
)
|
)
|
||||||
searchLayoutBinding.toolbarSearchEditText.clearFocus()
|
searchLayoutBinding.toolbarSearchEditText.clearFocus()
|
||||||
}
|
}
|
||||||
@@ -523,7 +495,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
|
|||||||
private fun hideKeyboard() {
|
private fun hideKeyboard() {
|
||||||
inputMethodManager.hideSoftInputFromWindow(
|
inputMethodManager.hideSoftInputFromWindow(
|
||||||
feedGroupCreateBinding.groupNameInput.windowToken,
|
feedGroupCreateBinding.groupNameInput.windowToken,
|
||||||
InputMethodManager.HIDE_NOT_ALWAYS
|
InputMethodManager.RESULT_UNCHANGED_SHOWN
|
||||||
)
|
)
|
||||||
feedGroupCreateBinding.groupNameInput.clearFocus()
|
feedGroupCreateBinding.groupNameInput.clearFocus()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ class FeedGroupDialogViewModel(
|
|||||||
|
|
||||||
private var subscriptionsDisposable = Flowable
|
private var subscriptionsDisposable = Flowable
|
||||||
.combineLatest(
|
.combineLatest(
|
||||||
subscriptionsFlowable,
|
subscriptionsFlowable, feedDatabaseManager.subscriptionIdsForGroup(groupId)
|
||||||
feedDatabaseManager.subscriptionIdsForGroup(groupId)
|
|
||||||
) { t1: List<PickerSubscriptionItem>, t2: List<Long> -> t1 to t2.toSet() }
|
) { t1: List<PickerSubscriptionItem>, t2: List<Long> -> t1 to t2.toSet() }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe(mutableSubscriptionsLiveData::postValue)
|
.subscribe(mutableSubscriptionsLiveData::postValue)
|
||||||
@@ -126,10 +125,7 @@ class FeedGroupDialogViewModel(
|
|||||||
) = viewModelFactory {
|
) = viewModelFactory {
|
||||||
initializer {
|
initializer {
|
||||||
FeedGroupDialogViewModel(
|
FeedGroupDialogViewModel(
|
||||||
context.applicationContext,
|
context.applicationContext, groupId, initialQuery, initialShowOnlyUngrouped
|
||||||
groupId,
|
|
||||||
initialQuery,
|
|
||||||
initialShowOnlyUngrouped
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import com.evernote.android.state.State
|
|||||||
import com.livefront.bridge.Bridge
|
import com.livefront.bridge.Bridge
|
||||||
import com.xwray.groupie.GroupieAdapter
|
import com.xwray.groupie.GroupieAdapter
|
||||||
import com.xwray.groupie.TouchCallback
|
import com.xwray.groupie.TouchCallback
|
||||||
import java.util.Collections
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.databinding.DialogFeedGroupReorderBinding
|
import org.schabi.newpipe.databinding.DialogFeedGroupReorderBinding
|
||||||
@@ -23,6 +22,7 @@ import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewMo
|
|||||||
import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewModel.DialogEvent.SuccessEvent
|
import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewModel.DialogEvent.SuccessEvent
|
||||||
import org.schabi.newpipe.local.subscription.item.FeedGroupReorderItem
|
import org.schabi.newpipe.local.subscription.item.FeedGroupReorderItem
|
||||||
import org.schabi.newpipe.util.ThemeHelper
|
import org.schabi.newpipe.util.ThemeHelper
|
||||||
|
import java.util.Collections
|
||||||
|
|
||||||
class FeedGroupReorderDialog : DialogFragment() {
|
class FeedGroupReorderDialog : DialogFragment() {
|
||||||
private var _binding: DialogFeedGroupReorderBinding? = null
|
private var _binding: DialogFeedGroupReorderBinding? = null
|
||||||
|
|||||||
@@ -43,10 +43,7 @@ class ChannelItem(
|
|||||||
|
|
||||||
gesturesListener?.run {
|
gesturesListener?.run {
|
||||||
viewHolder.root.setOnClickListener { selected(infoItem) }
|
viewHolder.root.setOnClickListener { selected(infoItem) }
|
||||||
viewHolder.root.setOnLongClickListener {
|
viewHolder.root.setOnLongClickListener { held(infoItem); true }
|
||||||
held(infoItem)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
|||||||
data class FeedGroupCardGridItem(
|
data class FeedGroupCardGridItem(
|
||||||
val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
||||||
val name: String,
|
val name: String,
|
||||||
val icon: FeedGroupIcon
|
val icon: FeedGroupIcon,
|
||||||
) : BindableItem<FeedGroupCardGridItemBinding>() {
|
) : BindableItem<FeedGroupCardGridItemBinding>() {
|
||||||
constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon)
|
constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon)
|
||||||
|
|
||||||
|
|||||||
@@ -144,9 +144,7 @@ public abstract class BaseImportExportService extends Service {
|
|||||||
notificationBuilder.setContentText(text);
|
notificationBuilder.setContentText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
||||||
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopService() {
|
protected void stopService() {
|
||||||
@@ -176,10 +174,7 @@ public abstract class BaseImportExportService extends Service {
|
|||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
|
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
|
||||||
.setContentText(textOrEmpty);
|
.setContentText(textOrEmpty);
|
||||||
|
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
|
||||||
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NotificationCompat.Builder createNotification() {
|
protected NotificationCompat.Builder createNotification() {
|
||||||
|
|||||||
@@ -127,39 +127,39 @@ public final class PlayQueueActivity extends AppCompatActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
final int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == android.R.id.home) {
|
case android.R.id.home:
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_settings) {
|
case R.id.action_settings:
|
||||||
NavigationHelper.openSettings(this);
|
NavigationHelper.openSettings(this);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_append_playlist) {
|
case R.id.action_append_playlist:
|
||||||
PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager());
|
PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager());
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_playback_speed) {
|
case R.id.action_playback_speed:
|
||||||
openPlaybackParameterDialog();
|
openPlaybackParameterDialog();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_mute) {
|
case R.id.action_mute:
|
||||||
player.toggleMute();
|
player.toggleMute();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_system_audio) {
|
case R.id.action_system_audio:
|
||||||
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
|
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_switch_main) {
|
case R.id.action_switch_main:
|
||||||
this.player.setRecovery();
|
|
||||||
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
|
|
||||||
return true;
|
|
||||||
} else if (itemId == R.id.action_switch_popup) {
|
|
||||||
if (PermissionHelper.isPopupEnabledElseAsk(this)) {
|
|
||||||
this.player.setRecovery();
|
this.player.setRecovery();
|
||||||
NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true);
|
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
|
||||||
}
|
return true;
|
||||||
return true;
|
case R.id.action_switch_popup:
|
||||||
} else if (itemId == R.id.action_switch_background) {
|
if (PermissionHelper.isPopupEnabledElseAsk(this)) {
|
||||||
this.player.setRecovery();
|
this.player.setRecovery();
|
||||||
NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true);
|
NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.action_switch_background:
|
||||||
|
this.player.setRecovery();
|
||||||
|
NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.getGroupId() == MENU_ID_AUDIO_TRACK) {
|
if (item.getGroupId() == MENU_ID_AUDIO_TRACK) {
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
|||||||
import org.schabi.newpipe.player.resolver.AudioPlaybackResolver;
|
import org.schabi.newpipe.player.resolver.AudioPlaybackResolver;
|
||||||
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
||||||
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver.SourceType;
|
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver.SourceType;
|
||||||
import org.schabi.newpipe.player.ui.BackgroundPlayerUi;
|
|
||||||
import org.schabi.newpipe.player.ui.MainPlayerUi;
|
import org.schabi.newpipe.player.ui.MainPlayerUi;
|
||||||
import org.schabi.newpipe.player.ui.PlayerUi;
|
import org.schabi.newpipe.player.ui.PlayerUi;
|
||||||
import org.schabi.newpipe.player.ui.PlayerUiList;
|
import org.schabi.newpipe.player.ui.PlayerUiList;
|
||||||
@@ -272,7 +271,6 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final HistoryRecordManager recordManager;
|
private final HistoryRecordManager recordManager;
|
||||||
|
|
||||||
private boolean screenOn = true;
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -567,12 +565,15 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
if (queueCache == null) {
|
if (queueCache == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return SerializedCache.getInstance().take(queueCache, PlayQueue.class);
|
final PlayQueue newQueue = SerializedCache.getInstance().take(queueCache, PlayQueue.class);
|
||||||
|
if (newQueue == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return newQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initUIsForCurrentPlayerType() {
|
private void initUIsForCurrentPlayerType() {
|
||||||
if ((UIs.get(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
|
if ((UIs.get(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
|
||||||
|| (UIs.get(BackgroundPlayerUi.class).isPresent() && playerType == PlayerType.AUDIO)
|
|
||||||
|| (UIs.get(PopupPlayerUi.class).isPresent() && playerType == PlayerType.POPUP)) {
|
|| (UIs.get(PopupPlayerUi.class).isPresent() && playerType == PlayerType.POPUP)) {
|
||||||
// correct UI already in place
|
// correct UI already in place
|
||||||
return;
|
return;
|
||||||
@@ -591,17 +592,14 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
switch (playerType) {
|
switch (playerType) {
|
||||||
case MAIN:
|
case MAIN:
|
||||||
UIs.destroyAll(PopupPlayerUi.class);
|
UIs.destroyAll(PopupPlayerUi.class);
|
||||||
UIs.destroyAll(BackgroundPlayerUi.class);
|
|
||||||
UIs.addAndPrepare(new MainPlayerUi(this, binding));
|
UIs.addAndPrepare(new MainPlayerUi(this, binding));
|
||||||
break;
|
break;
|
||||||
case POPUP:
|
case POPUP:
|
||||||
UIs.destroyAll(MainPlayerUi.class);
|
UIs.destroyAll(MainPlayerUi.class);
|
||||||
UIs.destroyAll(BackgroundPlayerUi.class);
|
|
||||||
UIs.addAndPrepare(new PopupPlayerUi(this, binding));
|
UIs.addAndPrepare(new PopupPlayerUi(this, binding));
|
||||||
break;
|
break;
|
||||||
case AUDIO:
|
case AUDIO:
|
||||||
UIs.destroyAll(VideoPlayerUi.class); // destroys both MainPlayerUi and PopupPlayerUi
|
UIs.destroyAll(VideoPlayerUi.class);
|
||||||
UIs.addAndPrepare(new BackgroundPlayerUi(this));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -844,12 +842,6 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
case ACTION_SHUFFLE:
|
case ACTION_SHUFFLE:
|
||||||
toggleShuffleModeEnabled();
|
toggleShuffleModeEnabled();
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_SCREEN_OFF:
|
|
||||||
screenOn = false;
|
|
||||||
break;
|
|
||||||
case Intent.ACTION_SCREEN_ON:
|
|
||||||
screenOn = true;
|
|
||||||
break;
|
|
||||||
case Intent.ACTION_CONFIGURATION_CHANGED:
|
case Intent.ACTION_CONFIGURATION_CHANGED:
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "ACTION_CONFIGURATION_CHANGED received");
|
Log.d(TAG, "ACTION_CONFIGURATION_CHANGED received");
|
||||||
@@ -2037,7 +2029,7 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
// resolver was called when the app was in background, the app will only stream audio when
|
// resolver was called when the app was in background, the app will only stream audio when
|
||||||
// the user come back to the app and will never fetch the video stream.
|
// the user come back to the app and will never fetch the video stream.
|
||||||
// Note that the video is not fetched when the app is in background because the video
|
// Note that the video is not fetched when the app is in background because the video
|
||||||
// renderer is fully disabled (see useVideoAndSubtitles method), except for HLS streams
|
// renderer is fully disabled (see useVideoSource method), except for HLS streams
|
||||||
// (see https://github.com/google/ExoPlayer/issues/9282).
|
// (see https://github.com/google/ExoPlayer/issues/9282).
|
||||||
return videoResolver.resolve(info);
|
return videoResolver.resolve(info);
|
||||||
}
|
}
|
||||||
@@ -2203,19 +2195,12 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void useVideoAndSubtitles(final boolean videoAndSubtitlesEnabled) {
|
public void useVideoSource(final boolean videoEnabled) {
|
||||||
if (playQueue == null) {
|
if (playQueue == null || audioPlayerSelected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isAudioOnly = !videoAndSubtitlesEnabled;
|
isAudioOnly = !videoEnabled;
|
||||||
|
|
||||||
final var item = playQueue.getItem();
|
|
||||||
final boolean hasPendingRecovery =
|
|
||||||
item != null && item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET;
|
|
||||||
final boolean hasTimeline =
|
|
||||||
!exoPlayerIsNull() && !simpleExoPlayer.getCurrentTimeline().isEmpty();
|
|
||||||
|
|
||||||
|
|
||||||
getCurrentStreamInfo().ifPresentOrElse(info -> {
|
getCurrentStreamInfo().ifPresentOrElse(info -> {
|
||||||
// In case we don't know the source type, fall back to either video-with-audio, or
|
// In case we don't know the source type, fall back to either video-with-audio, or
|
||||||
@@ -2223,34 +2208,27 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
final SourceType sourceType = videoResolver.getStreamSourceType()
|
final SourceType sourceType = videoResolver.getStreamSourceType()
|
||||||
.orElse(SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
|
.orElse(SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
|
||||||
|
|
||||||
if (hasTimeline || !hasPendingRecovery) {
|
|
||||||
// making sure to save playback position before reloadPlayQueueManager()
|
|
||||||
setRecovery();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
|
if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
|
||||||
reloadPlayQueueManager();
|
reloadPlayQueueManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRecovery();
|
||||||
|
|
||||||
|
// Disable or enable video and subtitles renderers depending of the videoEnabled value
|
||||||
|
trackSelector.setParameters(trackSelector.buildUponParameters()
|
||||||
|
.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, !videoEnabled)
|
||||||
|
.setTrackTypeDisabled(C.TRACK_TYPE_VIDEO, !videoEnabled));
|
||||||
}, () -> {
|
}, () -> {
|
||||||
/*
|
/*
|
||||||
The current metadata may be null sometimes (for e.g. when using an unstable connection
|
The current metadata may be null sometimes (for e.g. when using an unstable connection
|
||||||
in livestreams) so we will be not able to execute the block above
|
in livestreams) so we will be not able to execute the block below
|
||||||
|
|
||||||
Reload the play queue manager in this case, which is the behavior when we don't know the
|
Reload the play queue manager in this case, which is the behavior when we don't know the
|
||||||
index of the video renderer or playQueueManagerReloadingNeeded returns true
|
index of the video renderer or playQueueManagerReloadingNeeded returns true
|
||||||
*/
|
*/
|
||||||
if (hasTimeline || !hasPendingRecovery) {
|
|
||||||
// making sure to save playback position before reloadPlayQueueManager()
|
|
||||||
setRecovery();
|
|
||||||
}
|
|
||||||
reloadPlayQueueManager();
|
reloadPlayQueueManager();
|
||||||
|
setRecovery();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Disable or enable video and subtitles renderers depending of the
|
|
||||||
// videoAndSubtitlesEnabled value
|
|
||||||
trackSelector.setParameters(trackSelector.buildUponParameters()
|
|
||||||
.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, !videoAndSubtitlesEnabled)
|
|
||||||
.setTrackTypeDisabled(C.TRACK_TYPE_VIDEO, !videoAndSubtitlesEnabled));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2483,11 +2461,4 @@ public final class Player implements PlaybackListener, Listener {
|
|||||||
.orElse(RENDERER_UNAVAILABLE);
|
.orElse(RENDERER_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
/**
|
|
||||||
* @return whether the device screen is turned on.
|
|
||||||
*/
|
|
||||||
public boolean isScreenOn() {
|
|
||||||
return screenOn;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
|||||||
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getAndroidUserAgent;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getAndroidUserAgent;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getIosUserAgent;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getIosUserAgent;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTvHtml5UserAgent;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isAndroidStreamingUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isAndroidStreamingUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isIosStreamingUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isIosStreamingUrl;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isTvHtml5StreamingUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebEmbeddedPlayerStreamingUrl;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebEmbeddedPlayerStreamingUrl;
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
@@ -659,7 +661,10 @@ public final class YoutubeHttpDataSource extends BaseDataSource implements HttpD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean isTvHtml5StreamingUrl = isTvHtml5StreamingUrl(requestUrl);
|
||||||
|
|
||||||
if (isWebStreamingUrl(requestUrl)
|
if (isWebStreamingUrl(requestUrl)
|
||||||
|
|| isTvHtml5StreamingUrl
|
||||||
|| isWebEmbeddedPlayerStreamingUrl(requestUrl)) {
|
|| isWebEmbeddedPlayerStreamingUrl(requestUrl)) {
|
||||||
httpURLConnection.setRequestProperty(HttpHeaders.ORIGIN, YOUTUBE_BASE_URL);
|
httpURLConnection.setRequestProperty(HttpHeaders.ORIGIN, YOUTUBE_BASE_URL);
|
||||||
httpURLConnection.setRequestProperty(HttpHeaders.REFERER, YOUTUBE_BASE_URL);
|
httpURLConnection.setRequestProperty(HttpHeaders.REFERER, YOUTUBE_BASE_URL);
|
||||||
@@ -680,6 +685,9 @@ public final class YoutubeHttpDataSource extends BaseDataSource implements HttpD
|
|||||||
} else if (isIosStreamingUrl) {
|
} else if (isIosStreamingUrl) {
|
||||||
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT,
|
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT,
|
||||||
getIosUserAgent(null));
|
getIosUserAgent(null));
|
||||||
|
} else if (isTvHtml5StreamingUrl) {
|
||||||
|
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT,
|
||||||
|
getTvHtml5UserAgent());
|
||||||
} else {
|
} else {
|
||||||
// non-mobile user agent
|
// non-mobile user agent
|
||||||
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT, DownloaderImpl.USER_AGENT);
|
httpURLConnection.setRequestProperty(HttpHeaders.USER_AGENT, DownloaderImpl.USER_AGENT);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import org.schabi.newpipe.player.ui.VideoPlayerUi
|
|||||||
* and provides some abstract methods to make it easier separating the logic from the UI.
|
* and provides some abstract methods to make it easier separating the logic from the UI.
|
||||||
*/
|
*/
|
||||||
abstract class BasePlayerGestureListener(
|
abstract class BasePlayerGestureListener(
|
||||||
private val playerUi: VideoPlayerUi
|
private val playerUi: VideoPlayerUi,
|
||||||
) : GestureDetector.SimpleOnGestureListener(), View.OnTouchListener {
|
) : GestureDetector.SimpleOnGestureListener(), View.OnTouchListener {
|
||||||
|
|
||||||
protected val player: Player = playerUi.player
|
protected val player: Player = playerUi.player
|
||||||
@@ -86,9 +86,8 @@ abstract class BasePlayerGestureListener(
|
|||||||
// ///////////////////////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
override fun onDown(e: MotionEvent): Boolean {
|
override fun onDown(e: MotionEvent): Boolean {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "onDown called with e = [$e]")
|
Log.d(TAG, "onDown called with e = [$e]")
|
||||||
}
|
|
||||||
|
|
||||||
if (isDoubleTapping && isDoubleTapEnabled) {
|
if (isDoubleTapping && isDoubleTapEnabled) {
|
||||||
doubleTapControls?.onDoubleTapProgressDown(getDisplayPortion(e))
|
doubleTapControls?.onDoubleTapProgressDown(getDisplayPortion(e))
|
||||||
@@ -109,9 +108,8 @@ abstract class BasePlayerGestureListener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "onDoubleTap called with e = [$e]")
|
Log.d(TAG, "onDoubleTap called with e = [$e]")
|
||||||
}
|
|
||||||
|
|
||||||
onDoubleTap(e, getDisplayPortion(e))
|
onDoubleTap(e, getDisplayPortion(e))
|
||||||
return true
|
return true
|
||||||
@@ -138,9 +136,8 @@ abstract class BasePlayerGestureListener(
|
|||||||
|
|
||||||
private fun startMultiDoubleTap(e: MotionEvent) {
|
private fun startMultiDoubleTap(e: MotionEvent) {
|
||||||
if (!isDoubleTapping) {
|
if (!isDoubleTapping) {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "startMultiDoubleTap called with e = [$e]")
|
Log.d(TAG, "startMultiDoubleTap called with e = [$e]")
|
||||||
}
|
|
||||||
|
|
||||||
keepInDoubleTapMode()
|
keepInDoubleTapMode()
|
||||||
doubleTapControls?.onDoubleTapStarted(getDisplayPortion(e))
|
doubleTapControls?.onDoubleTapStarted(getDisplayPortion(e))
|
||||||
@@ -148,9 +145,8 @@ abstract class BasePlayerGestureListener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun keepInDoubleTapMode() {
|
fun keepInDoubleTapMode() {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "keepInDoubleTapMode called")
|
Log.d(TAG, "keepInDoubleTapMode called")
|
||||||
}
|
|
||||||
|
|
||||||
isDoubleTapping = true
|
isDoubleTapping = true
|
||||||
doubleTapHandler.removeCallbacksAndMessages(DOUBLE_TAP)
|
doubleTapHandler.removeCallbacksAndMessages(DOUBLE_TAP)
|
||||||
@@ -165,9 +161,8 @@ abstract class BasePlayerGestureListener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun endMultiDoubleTap() {
|
fun endMultiDoubleTap() {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "endMultiDoubleTap called")
|
Log.d(TAG, "endMultiDoubleTap called")
|
||||||
}
|
|
||||||
|
|
||||||
isDoubleTapping = false
|
isDoubleTapping = false
|
||||||
doubleTapHandler.removeCallbacksAndMessages(DOUBLE_TAP)
|
doubleTapHandler.removeCallbacksAndMessages(DOUBLE_TAP)
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package org.schabi.newpipe.player.gesture
|
package org.schabi.newpipe.player.gesture
|
||||||
|
|
||||||
enum class DisplayPortion {
|
enum class DisplayPortion {
|
||||||
LEFT,
|
LEFT, MIDDLE, RIGHT, LEFT_HALF, RIGHT_HALF
|
||||||
MIDDLE,
|
|
||||||
RIGHT,
|
|
||||||
LEFT_HALF,
|
|
||||||
RIGHT_HALF
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.widget.ProgressBar
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import kotlin.math.abs
|
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.ktx.AnimationType
|
import org.schabi.newpipe.ktx.AnimationType
|
||||||
@@ -18,6 +17,7 @@ import org.schabi.newpipe.player.helper.AudioReactor
|
|||||||
import org.schabi.newpipe.player.helper.PlayerHelper
|
import org.schabi.newpipe.player.helper.PlayerHelper
|
||||||
import org.schabi.newpipe.player.ui.MainPlayerUi
|
import org.schabi.newpipe.player.ui.MainPlayerUi
|
||||||
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
|
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GestureListener for the player
|
* GestureListener for the player
|
||||||
@@ -42,29 +42,24 @@ class MainPlayerGestureListener(
|
|||||||
v.parent?.requestDisallowInterceptTouchEvent(playerUi.isFullscreen)
|
v.parent?.requestDisallowInterceptTouchEvent(playerUi.isFullscreen)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
v.parent?.requestDisallowInterceptTouchEvent(false)
|
v.parent?.requestDisallowInterceptTouchEvent(false)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "onSingleTapConfirmed() called with: e = [$e]")
|
Log.d(TAG, "onSingleTapConfirmed() called with: e = [$e]")
|
||||||
}
|
|
||||||
|
|
||||||
if (isDoubleTapping) {
|
if (isDoubleTapping)
|
||||||
return true
|
return true
|
||||||
}
|
|
||||||
super.onSingleTapConfirmed(e)
|
super.onSingleTapConfirmed(e)
|
||||||
|
|
||||||
if (player.currentState != Player.STATE_BLOCKED) {
|
if (player.currentState != Player.STATE_BLOCKED)
|
||||||
onSingleTap()
|
onSingleTap()
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +195,6 @@ class MainPlayerGestureListener(
|
|||||||
when (PlayerHelper.getActionForRightGestureSide(player.context)) {
|
when (PlayerHelper.getActionForRightGestureSide(player.context)) {
|
||||||
player.context.getString(R.string.volume_control_key) ->
|
player.context.getString(R.string.volume_control_key) ->
|
||||||
onScrollVolume(distanceY)
|
onScrollVolume(distanceY)
|
||||||
|
|
||||||
player.context.getString(R.string.brightness_control_key) ->
|
player.context.getString(R.string.brightness_control_key) ->
|
||||||
onScrollBrightness(distanceY)
|
onScrollBrightness(distanceY)
|
||||||
}
|
}
|
||||||
@@ -208,7 +202,6 @@ class MainPlayerGestureListener(
|
|||||||
when (PlayerHelper.getActionForLeftGestureSide(player.context)) {
|
when (PlayerHelper.getActionForLeftGestureSide(player.context)) {
|
||||||
player.context.getString(R.string.volume_control_key) ->
|
player.context.getString(R.string.volume_control_key) ->
|
||||||
onScrollVolume(distanceY)
|
onScrollVolume(distanceY)
|
||||||
|
|
||||||
player.context.getString(R.string.brightness_control_key) ->
|
player.context.getString(R.string.brightness_control_key) ->
|
||||||
onScrollBrightness(distanceY)
|
onScrollBrightness(distanceY)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,17 @@ import android.view.MotionEvent
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import kotlin.math.abs
|
|
||||||
import kotlin.math.hypot
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.ktx.AnimationType
|
import org.schabi.newpipe.ktx.AnimationType
|
||||||
import org.schabi.newpipe.ktx.animate
|
import org.schabi.newpipe.ktx.animate
|
||||||
import org.schabi.newpipe.player.ui.PopupPlayerUi
|
import org.schabi.newpipe.player.ui.PopupPlayerUi
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.hypot
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class PopupPlayerGestureListener(
|
class PopupPlayerGestureListener(
|
||||||
private val playerUi: PopupPlayerUi
|
private val playerUi: PopupPlayerUi,
|
||||||
) : BasePlayerGestureListener(playerUi) {
|
) : BasePlayerGestureListener(playerUi) {
|
||||||
|
|
||||||
private var isMoving = false
|
private var isMoving = false
|
||||||
@@ -205,16 +205,13 @@ class PopupPlayerGestureListener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||||
if (DEBUG) {
|
if (DEBUG)
|
||||||
Log.d(TAG, "onSingleTapConfirmed() called with: e = [$e]")
|
Log.d(TAG, "onSingleTapConfirmed() called with: e = [$e]")
|
||||||
}
|
|
||||||
|
|
||||||
if (isDoubleTapping) {
|
if (isDoubleTapping)
|
||||||
return true
|
return true
|
||||||
}
|
if (player.exoPlayerIsNull())
|
||||||
if (player.exoPlayerIsNull()) {
|
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
|
|
||||||
onSingleTap()
|
onSingleTap()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -129,13 +129,6 @@ public class PlayerDataSource {
|
|||||||
getDefaultDashChunkSourceFactory(cachelessDataSourceFactory),
|
getDefaultDashChunkSourceFactory(cachelessDataSourceFactory),
|
||||||
cachelessDataSourceFactory);
|
cachelessDataSourceFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DashMediaSource.Factory getLiveYoutubeDashMediaSourceFactory() {
|
|
||||||
return new DashMediaSource.Factory(
|
|
||||||
getDefaultDashChunkSourceFactory(cachelessDataSourceFactory),
|
|
||||||
cachelessDataSourceFactory)
|
|
||||||
.setManifestParser(new YoutubeDashLiveManifestParser());
|
|
||||||
}
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
package org.schabi.newpipe.player.helper;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.DashManifest;
|
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.DashManifestParser;
|
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.Period;
|
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.ProgramInformation;
|
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.ServiceDescriptionElement;
|
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.UtcTimingElement;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link DashManifestParser} fixing YouTube DASH manifests to allow starting playback from the
|
|
||||||
* newest period available instead of the earliest one in some cases.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* It changes the {@code availabilityStartTime} passed to a custom value doing the workaround.
|
|
||||||
* A better approach to fix the issue should be investigated and used in the future.
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public class YoutubeDashLiveManifestParser extends DashManifestParser {
|
|
||||||
|
|
||||||
// Result of Util.parseXsDateTime("1970-01-01T00:00:00Z")
|
|
||||||
private static final long AVAILABILITY_START_TIME_TO_USE = 0;
|
|
||||||
|
|
||||||
// There is no computation made with the availabilityStartTime value in the
|
|
||||||
// parseMediaPresentationDescription method itself, so we can just override methods called in
|
|
||||||
// this method using the workaround value
|
|
||||||
// Overriding parsePeriod does not seem to be needed
|
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:ParameterNumber")
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
protected DashManifest buildMediaPresentationDescription(
|
|
||||||
final long availabilityStartTime,
|
|
||||||
final long durationMs,
|
|
||||||
final long minBufferTimeMs,
|
|
||||||
final boolean dynamic,
|
|
||||||
final long minUpdateTimeMs,
|
|
||||||
final long timeShiftBufferDepthMs,
|
|
||||||
final long suggestedPresentationDelayMs,
|
|
||||||
final long publishTimeMs,
|
|
||||||
@Nullable final ProgramInformation programInformation,
|
|
||||||
@Nullable final UtcTimingElement utcTiming,
|
|
||||||
@Nullable final ServiceDescriptionElement serviceDescription,
|
|
||||||
@Nullable final Uri location,
|
|
||||||
@NonNull final List<Period> periods) {
|
|
||||||
return super.buildMediaPresentationDescription(
|
|
||||||
AVAILABILITY_START_TIME_TO_USE,
|
|
||||||
durationMs,
|
|
||||||
minBufferTimeMs,
|
|
||||||
dynamic,
|
|
||||||
minUpdateTimeMs,
|
|
||||||
timeShiftBufferDepthMs,
|
|
||||||
suggestedPresentationDelayMs,
|
|
||||||
publishTimeMs,
|
|
||||||
programInformation,
|
|
||||||
utcTiming,
|
|
||||||
serviceDescription,
|
|
||||||
location,
|
|
||||||
periods);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,7 @@ internal fun infoItemTypeToString(type: InfoType): String {
|
|||||||
InfoType.STREAM -> ID_STREAM
|
InfoType.STREAM -> ID_STREAM
|
||||||
InfoType.PLAYLIST -> ID_PLAYLIST
|
InfoType.PLAYLIST -> ID_PLAYLIST
|
||||||
InfoType.CHANNEL -> ID_CHANNEL
|
InfoType.CHANNEL -> ID_CHANNEL
|
||||||
else -> error("Unexpected value: $type")
|
else -> throw IllegalStateException("Unexpected value: $type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ internal fun infoItemTypeFromString(type: String): InfoType {
|
|||||||
ID_STREAM -> InfoType.STREAM
|
ID_STREAM -> InfoType.STREAM
|
||||||
ID_PLAYLIST -> InfoType.PLAYLIST
|
ID_PLAYLIST -> InfoType.PLAYLIST
|
||||||
ID_CHANNEL -> InfoType.CHANNEL
|
ID_CHANNEL -> InfoType.CHANNEL
|
||||||
else -> error("Unexpected value: $type")
|
else -> throw IllegalStateException("Unexpected value: $type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import io.reactivex.rxjava3.core.Flowable
|
|||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.util.function.Consumer
|
|
||||||
import org.schabi.newpipe.MainActivity.DEBUG
|
import org.schabi.newpipe.MainActivity.DEBUG
|
||||||
import org.schabi.newpipe.NewPipeDatabase
|
import org.schabi.newpipe.NewPipeDatabase
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
@@ -38,6 +37,7 @@ import org.schabi.newpipe.local.playlist.RemotePlaylistManager
|
|||||||
import org.schabi.newpipe.util.ExtractorHelper
|
import org.schabi.newpipe.util.ExtractorHelper
|
||||||
import org.schabi.newpipe.util.ServiceHelper
|
import org.schabi.newpipe.util.ServiceHelper
|
||||||
import org.schabi.newpipe.util.image.ImageStrategy
|
import org.schabi.newpipe.util.image.ImageStrategy
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to cleanly separate the Service implementation (in
|
* This class is used to cleanly separate the Service implementation (in
|
||||||
@@ -47,8 +47,7 @@ import org.schabi.newpipe.util.image.ImageStrategy
|
|||||||
*/
|
*/
|
||||||
class MediaBrowserImpl(
|
class MediaBrowserImpl(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
// parentId
|
notifyChildrenChanged: Consumer<String>, // parentId
|
||||||
notifyChildrenChanged: Consumer<String>
|
|
||||||
) {
|
) {
|
||||||
private val packageValidator = PackageValidator(context)
|
private val packageValidator = PackageValidator(context)
|
||||||
private val database = NewPipeDatabase.getInstance(context)
|
private val database = NewPipeDatabase.getInstance(context)
|
||||||
@@ -90,8 +89,7 @@ class MediaBrowserImpl(
|
|||||||
|
|
||||||
val extras = Bundle()
|
val extras = Bundle()
|
||||||
extras.putBoolean(
|
extras.putBoolean(
|
||||||
MediaConstants.BROWSER_SERVICE_EXTRAS_KEY_SEARCH_SUPPORTED,
|
MediaConstants.BROWSER_SERVICE_EXTRAS_KEY_SEARCH_SUPPORTED, true
|
||||||
true
|
|
||||||
)
|
)
|
||||||
return MediaBrowserServiceCompat.BrowserRoot(ID_ROOT, extras)
|
return MediaBrowserServiceCompat.BrowserRoot(ID_ROOT, extras)
|
||||||
}
|
}
|
||||||
@@ -139,7 +137,7 @@ class MediaBrowserImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (path.removeAt(0)) {
|
when (/*val uriType = */path.removeAt(0)) {
|
||||||
ID_BOOKMARKS -> {
|
ID_BOOKMARKS -> {
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
return populateBookmarks()
|
return populateBookmarks()
|
||||||
@@ -206,12 +204,12 @@ class MediaBrowserImpl(
|
|||||||
val extras = Bundle()
|
val extras = Bundle()
|
||||||
extras.putString(
|
extras.putString(
|
||||||
MediaConstants.DESCRIPTION_EXTRAS_KEY_CONTENT_STYLE_GROUP_TITLE,
|
MediaConstants.DESCRIPTION_EXTRAS_KEY_CONTENT_STYLE_GROUP_TITLE,
|
||||||
context.resources.getString(R.string.tab_bookmarks)
|
context.resources.getString(R.string.tab_bookmarks),
|
||||||
)
|
)
|
||||||
builder.setExtras(extras)
|
builder.setExtras(extras)
|
||||||
return MediaBrowserCompat.MediaItem(
|
return MediaBrowserCompat.MediaItem(
|
||||||
builder.build(),
|
builder.build(),
|
||||||
MediaBrowserCompat.MediaItem.FLAG_BROWSABLE
|
MediaBrowserCompat.MediaItem.FLAG_BROWSABLE,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +266,7 @@ class MediaBrowserImpl(
|
|||||||
private fun createLocalPlaylistStreamMediaItem(
|
private fun createLocalPlaylistStreamMediaItem(
|
||||||
playlistId: Long,
|
playlistId: Long,
|
||||||
item: PlaylistStreamEntry,
|
item: PlaylistStreamEntry,
|
||||||
index: Int
|
index: Int,
|
||||||
): MediaBrowserCompat.MediaItem {
|
): MediaBrowserCompat.MediaItem {
|
||||||
val builder = MediaDescriptionCompat.Builder()
|
val builder = MediaDescriptionCompat.Builder()
|
||||||
builder.setMediaId(createMediaIdForPlaylistIndex(false, playlistId, index))
|
builder.setMediaId(createMediaIdForPlaylistIndex(false, playlistId, index))
|
||||||
@@ -285,7 +283,7 @@ class MediaBrowserImpl(
|
|||||||
private fun createRemotePlaylistStreamMediaItem(
|
private fun createRemotePlaylistStreamMediaItem(
|
||||||
playlistId: Long,
|
playlistId: Long,
|
||||||
item: StreamInfoItem,
|
item: StreamInfoItem,
|
||||||
index: Int
|
index: Int,
|
||||||
): MediaBrowserCompat.MediaItem {
|
): MediaBrowserCompat.MediaItem {
|
||||||
val builder = MediaDescriptionCompat.Builder()
|
val builder = MediaDescriptionCompat.Builder()
|
||||||
builder.setMediaId(createMediaIdForPlaylistIndex(true, playlistId, index))
|
builder.setMediaId(createMediaIdForPlaylistIndex(true, playlistId, index))
|
||||||
@@ -305,7 +303,7 @@ class MediaBrowserImpl(
|
|||||||
private fun createMediaIdForPlaylistIndex(
|
private fun createMediaIdForPlaylistIndex(
|
||||||
isRemote: Boolean,
|
isRemote: Boolean,
|
||||||
playlistId: Long,
|
playlistId: Long,
|
||||||
index: Int
|
index: Int,
|
||||||
): String {
|
): String {
|
||||||
return buildLocalPlaylistItemMediaId(isRemote, playlistId)
|
return buildLocalPlaylistItemMediaId(isRemote, playlistId)
|
||||||
.appendPath(index.toString())
|
.appendPath(index.toString())
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import java.util.function.BiConsumer
|
|
||||||
import java.util.function.Consumer
|
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.NewPipeDatabase
|
import org.schabi.newpipe.NewPipeDatabase
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
@@ -32,6 +30,8 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue
|
|||||||
import org.schabi.newpipe.util.ChannelTabHelper
|
import org.schabi.newpipe.util.ChannelTabHelper
|
||||||
import org.schabi.newpipe.util.ExtractorHelper
|
import org.schabi.newpipe.util.ExtractorHelper
|
||||||
import org.schabi.newpipe.util.NavigationHelper
|
import org.schabi.newpipe.util.NavigationHelper
|
||||||
|
import java.util.function.BiConsumer
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to cleanly separate the Service implementation (in
|
* This class is used to cleanly separate the Service implementation (in
|
||||||
@@ -51,7 +51,7 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val setMediaSessionError: BiConsumer<String, Int>, // error string, error code
|
private val setMediaSessionError: BiConsumer<String, Int>, // error string, error code
|
||||||
private val clearMediaSessionError: Runnable,
|
private val clearMediaSessionError: Runnable,
|
||||||
private val onPrepare: Consumer<Boolean>
|
private val onPrepare: Consumer<Boolean>,
|
||||||
) : PlaybackPreparer {
|
) : PlaybackPreparer {
|
||||||
private val database = NewPipeDatabase.getInstance(context)
|
private val database = NewPipeDatabase.getInstance(context)
|
||||||
private var disposable: Disposable? = null
|
private var disposable: Disposable? = null
|
||||||
@@ -146,7 +146,7 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
throw parseError(mediaId)
|
throw parseError(mediaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (path.removeAt(0)) {
|
return when (/*val uriType = */path.removeAt(0)) {
|
||||||
ID_BOOKMARKS -> extractPlayQueueFromPlaylistMediaId(
|
ID_BOOKMARKS -> extractPlayQueueFromPlaylistMediaId(
|
||||||
mediaId,
|
mediaId,
|
||||||
path,
|
path,
|
||||||
@@ -172,7 +172,7 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
private fun extractPlayQueueFromPlaylistMediaId(
|
private fun extractPlayQueueFromPlaylistMediaId(
|
||||||
mediaId: String,
|
mediaId: String,
|
||||||
path: MutableList<String>,
|
path: MutableList<String>,
|
||||||
url: String?
|
url: String?,
|
||||||
): Single<PlayQueue> {
|
): Single<PlayQueue> {
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
throw parseError(mediaId)
|
throw parseError(mediaId)
|
||||||
@@ -185,11 +185,10 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
}
|
}
|
||||||
val playlistId = path[0].toLong()
|
val playlistId = path[0].toLong()
|
||||||
val index = path[1].toInt()
|
val index = path[1].toInt()
|
||||||
return if (playlistType == ID_LOCAL) {
|
return if (playlistType == ID_LOCAL)
|
||||||
extractLocalPlayQueue(playlistId, index)
|
extractLocalPlayQueue(playlistId, index)
|
||||||
} else {
|
else
|
||||||
extractRemotePlayQueue(playlistId, index)
|
extractRemotePlayQueue(playlistId, index)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ID_URL -> {
|
ID_URL -> {
|
||||||
@@ -209,7 +208,7 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
@Throws(ContentNotAvailableException::class)
|
@Throws(ContentNotAvailableException::class)
|
||||||
private fun extractPlayQueueFromHistoryMediaId(
|
private fun extractPlayQueueFromHistoryMediaId(
|
||||||
mediaId: String,
|
mediaId: String,
|
||||||
path: List<String>
|
path: List<String>,
|
||||||
): Single<PlayQueue> {
|
): Single<PlayQueue> {
|
||||||
if (path.size != 1) {
|
if (path.size != 1) {
|
||||||
throw parseError(mediaId)
|
throw parseError(mediaId)
|
||||||
@@ -230,14 +229,14 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
private fun extractPlayQueueFromInfoItemMediaId(
|
private fun extractPlayQueueFromInfoItemMediaId(
|
||||||
mediaId: String,
|
mediaId: String,
|
||||||
path: List<String>,
|
path: List<String>,
|
||||||
url: String
|
url: String,
|
||||||
): Single<PlayQueue> {
|
): Single<PlayQueue> {
|
||||||
if (path.size != 2) {
|
if (path.size != 2) {
|
||||||
throw parseError(mediaId)
|
throw parseError(mediaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
val serviceId = path[1].toInt()
|
val serviceId = path[1].toInt()
|
||||||
return when (infoItemTypeFromString(path[0])) {
|
return when (/*val infoItemType = */infoItemTypeFromString(path[0])) {
|
||||||
InfoType.STREAM -> ExtractorHelper.getStreamInfo(serviceId, url, false)
|
InfoType.STREAM -> ExtractorHelper.getStreamInfo(serviceId, url, false)
|
||||||
.map { SinglePlayQueue(it) }
|
.map { SinglePlayQueue(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ import android.support.v4.media.session.MediaSessionCompat
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.media.MediaBrowserServiceCompat
|
import androidx.media.MediaBrowserServiceCompat
|
||||||
|
import org.schabi.newpipe.BuildConfig
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.NoSuchAlgorithmException
|
import java.security.NoSuchAlgorithmException
|
||||||
import org.schabi.newpipe.BuildConfig
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates that the calling package is authorized to browse a [MediaBrowserServiceCompat].
|
* Validates that the calling package is authorized to browse a [MediaBrowserServiceCompat].
|
||||||
@@ -82,11 +82,11 @@ internal class PackageValidator(context: Context) {
|
|||||||
|
|
||||||
// Build the caller info for the rest of the checks here.
|
// Build the caller info for the rest of the checks here.
|
||||||
val callerPackageInfo = buildCallerInfo(callingPackage)
|
val callerPackageInfo = buildCallerInfo(callingPackage)
|
||||||
?: error("Caller wasn't found in the system?")
|
?: throw IllegalStateException("Caller wasn't found in the system?")
|
||||||
|
|
||||||
// Verify that things aren't ... broken. (This test should always pass.)
|
// Verify that things aren't ... broken. (This test should always pass.)
|
||||||
check(callerPackageInfo.uid == callingUid) {
|
if (callerPackageInfo.uid != callingUid) {
|
||||||
"Caller's package UID doesn't match caller's actual UID?"
|
throw IllegalStateException("Caller's package UID doesn't match caller's actual UID?")
|
||||||
}
|
}
|
||||||
|
|
||||||
val callerSignature = callerPackageInfo.signature
|
val callerSignature = callerPackageInfo.signature
|
||||||
@@ -94,22 +94,18 @@ internal class PackageValidator(context: Context) {
|
|||||||
val isCallerKnown = when {
|
val isCallerKnown = when {
|
||||||
// If it's our own app making the call, allow it.
|
// If it's our own app making the call, allow it.
|
||||||
callingUid == Process.myUid() -> true
|
callingUid == Process.myUid() -> true
|
||||||
|
|
||||||
// If the system is making the call, allow it.
|
// If the system is making the call, allow it.
|
||||||
callingUid == Process.SYSTEM_UID -> true
|
callingUid == Process.SYSTEM_UID -> true
|
||||||
|
|
||||||
// If the app was signed by the same certificate as the platform itself, also allow it.
|
// If the app was signed by the same certificate as the platform itself, also allow it.
|
||||||
callerSignature == platformSignature -> true
|
callerSignature == platformSignature -> true
|
||||||
|
/**
|
||||||
/*
|
|
||||||
* [MEDIA_CONTENT_CONTROL] permission is only available to system applications, and
|
* [MEDIA_CONTENT_CONTROL] permission is only available to system applications, and
|
||||||
* while it isn't required to allow these apps to connect to a
|
* while it isn't required to allow these apps to connect to a
|
||||||
* [MediaBrowserServiceCompat], allowing this ensures optimal compatability with apps
|
* [MediaBrowserServiceCompat], allowing this ensures optimal compatability with apps
|
||||||
* such as Android TV and the Google Assistant.
|
* such as Android TV and the Google Assistant.
|
||||||
*/
|
*/
|
||||||
callerPackageInfo.permissions.contains(MEDIA_CONTENT_CONTROL) -> true
|
callerPackageInfo.permissions.contains(MEDIA_CONTENT_CONTROL) -> true
|
||||||
|
/**
|
||||||
/*
|
|
||||||
* If the calling app has a notification listener it is able to retrieve notifications
|
* If the calling app has a notification listener it is able to retrieve notifications
|
||||||
* and can connect to an active [MediaSessionCompat].
|
* and can connect to an active [MediaSessionCompat].
|
||||||
*
|
*
|
||||||
@@ -173,10 +169,11 @@ internal class PackageValidator(context: Context) {
|
|||||||
*/
|
*/
|
||||||
@Suppress("deprecation")
|
@Suppress("deprecation")
|
||||||
@SuppressLint("PackageManagerGetSignatures")
|
@SuppressLint("PackageManagerGetSignatures")
|
||||||
private fun getPackageInfo(callingPackage: String): PackageInfo? = packageManager.getPackageInfo(
|
private fun getPackageInfo(callingPackage: String): PackageInfo? =
|
||||||
callingPackage,
|
packageManager.getPackageInfo(
|
||||||
PackageManager.GET_SIGNATURES or PackageManager.GET_PERMISSIONS
|
callingPackage,
|
||||||
)
|
PackageManager.GET_SIGNATURES or PackageManager.GET_PERMISSIONS
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the signature of a given package's [PackageInfo].
|
* Gets the signature of a given package's [PackageInfo].
|
||||||
@@ -188,21 +185,23 @@ internal class PackageValidator(context: Context) {
|
|||||||
* returns `null` as the signature.
|
* returns `null` as the signature.
|
||||||
*/
|
*/
|
||||||
@Suppress("deprecation")
|
@Suppress("deprecation")
|
||||||
private fun getSignature(packageInfo: PackageInfo): String? = if (packageInfo.signatures == null || packageInfo.signatures!!.size != 1) {
|
private fun getSignature(packageInfo: PackageInfo): String? =
|
||||||
// Security best practices dictate that an app should be signed with exactly one (1)
|
if (packageInfo.signatures == null || packageInfo.signatures!!.size != 1) {
|
||||||
// signature. Because of this, if there are multiple signatures, reject it.
|
// Security best practices dictate that an app should be signed with exactly one (1)
|
||||||
null
|
// signature. Because of this, if there are multiple signatures, reject it.
|
||||||
} else {
|
null
|
||||||
val certificate = packageInfo.signatures!![0].toByteArray()
|
} else {
|
||||||
getSignatureSha256(certificate)
|
val certificate = packageInfo.signatures!![0].toByteArray()
|
||||||
}
|
getSignatureSha256(certificate)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the Android platform signing key signature. This key is never null.
|
* Finds the Android platform signing key signature. This key is never null.
|
||||||
*/
|
*/
|
||||||
private fun getSystemSignature(): String = getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo ->
|
private fun getSystemSignature(): String =
|
||||||
getSignature(platformInfo)
|
getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo ->
|
||||||
} ?: error("Platform signature not found")
|
getSignature(platformInfo)
|
||||||
|
} ?: throw IllegalStateException("Platform signature not found")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SHA-256 signature given a certificate byte array.
|
* Creates a SHA-256 signature given a certificate byte array.
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ public final class NotificationUtil {
|
|||||||
notificationBuilder = createNotification();
|
notificationBuilder = createNotification();
|
||||||
}
|
}
|
||||||
updateNotification();
|
updateNotification();
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateThumbnail() {
|
public synchronized void updateThumbnail() {
|
||||||
@@ -86,9 +84,7 @@ public final class NotificationUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLargeIcon(notificationBuilder);
|
setLargeIcon(notificationBuilder);
|
||||||
if (notificationManager.areNotificationsEnabled()) {
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,14 +201,11 @@ public interface PlaybackResolver extends Resolver<StreamInfo, MediaSource> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final StreamInfoTag tag = StreamInfoTag.of(info);
|
final StreamInfoTag tag = StreamInfoTag.of(info);
|
||||||
// Prefer DASH over HLS because of an exoPlayer bug that causes the background player to
|
|
||||||
// also fetch the video stream even if it is supposed to just fetch the audio stream.
|
|
||||||
if (!info.getDashMpdUrl().isEmpty()) {
|
|
||||||
return buildLiveMediaSource(
|
|
||||||
dataSource, info.getDashMpdUrl(), C.CONTENT_TYPE_DASH, tag);
|
|
||||||
}
|
|
||||||
if (!info.getHlsUrl().isEmpty()) {
|
if (!info.getHlsUrl().isEmpty()) {
|
||||||
return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.CONTENT_TYPE_HLS, tag);
|
return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.CONTENT_TYPE_HLS, tag);
|
||||||
|
} else if (!info.getDashMpdUrl().isEmpty()) {
|
||||||
|
return buildLiveMediaSource(
|
||||||
|
dataSource, info.getDashMpdUrl(), C.CONTENT_TYPE_DASH, tag);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Log.w(TAG, "Error when generating live media source, falling back to standard sources",
|
Log.w(TAG, "Error when generating live media source, falling back to standard sources",
|
||||||
@@ -228,11 +225,7 @@ public interface PlaybackResolver extends Resolver<StreamInfo, MediaSource> {
|
|||||||
factory = dataSource.getLiveSsMediaSourceFactory();
|
factory = dataSource.getLiveSsMediaSourceFactory();
|
||||||
break;
|
break;
|
||||||
case C.CONTENT_TYPE_DASH:
|
case C.CONTENT_TYPE_DASH:
|
||||||
if (metadata.getServiceId() == ServiceList.YouTube.getServiceId()) {
|
factory = dataSource.getLiveDashMediaSourceFactory();
|
||||||
factory = dataSource.getLiveYoutubeDashMediaSourceFactory();
|
|
||||||
} else {
|
|
||||||
factory = dataSource.getLiveDashMediaSourceFactory();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case C.CONTENT_TYPE_HLS:
|
case C.CONTENT_TYPE_HLS:
|
||||||
factory = dataSource.getLiveHlsMediaSourceFactory();
|
factory = dataSource.getLiveHlsMediaSourceFactory();
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package org.schabi.newpipe.player.ui;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.player.Player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is not a "graphical" UI for the background player, but it is used to disable fetching video
|
|
||||||
* and text tracks with it.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* This allows reducing data usage for manifest sources with demuxed audio and video,
|
|
||||||
* such as livestreams.
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public class BackgroundPlayerUi extends PlayerUi {
|
|
||||||
|
|
||||||
public BackgroundPlayerUi(@NonNull final Player player) {
|
|
||||||
super(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initPlayback() {
|
|
||||||
super.initPlayback();
|
|
||||||
|
|
||||||
// Make sure to disable video and subtitles track types
|
|
||||||
player.useVideoAndSubtitles(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -216,10 +216,6 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
playQueueAdapter = new PlayQueueAdapter(context,
|
playQueueAdapter = new PlayQueueAdapter(context,
|
||||||
Objects.requireNonNull(player.getPlayQueue()));
|
Objects.requireNonNull(player.getPlayQueue()));
|
||||||
segmentAdapter = new StreamSegmentAdapter(getStreamSegmentListener());
|
segmentAdapter = new StreamSegmentAdapter(getStreamSegmentListener());
|
||||||
|
|
||||||
// Make sure video and text tracks are enabled if the user is in the app, in the case user
|
|
||||||
// switched from background player to main player
|
|
||||||
player.useVideoAndSubtitles(fragmentIsVisible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -335,7 +331,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
} else if (VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED.equals(intent.getAction())) {
|
} else if (VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED.equals(intent.getAction())) {
|
||||||
// Restore video source when user returns to the fragment
|
// Restore video source when user returns to the fragment
|
||||||
fragmentIsVisible = true;
|
fragmentIsVisible = true;
|
||||||
player.useVideoAndSubtitles(true);
|
player.useVideoSource(true);
|
||||||
|
|
||||||
// When a user returns from background, the system UI will always be shown even if
|
// When a user returns from background, the system UI will always be shown even if
|
||||||
// controls are invisible: hide it in that case
|
// controls are invisible: hide it in that case
|
||||||
@@ -374,7 +370,7 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
|
|||||||
if (player.isPlaying() || player.isLoading()) {
|
if (player.isPlaying() || player.isLoading()) {
|
||||||
switch (getMinimizeOnExitAction(context)) {
|
switch (getMinimizeOnExitAction(context)) {
|
||||||
case MINIMIZE_ON_EXIT_MODE_BACKGROUND:
|
case MINIMIZE_ON_EXIT_MODE_BACKGROUND:
|
||||||
player.useVideoAndSubtitles(false);
|
player.useVideoSource(false);
|
||||||
break;
|
break;
|
||||||
case MINIMIZE_ON_EXIT_MODE_POPUP:
|
case MINIMIZE_ON_EXIT_MODE_POPUP:
|
||||||
getParentActivity().ifPresent(activity -> {
|
getParentActivity().ifPresent(activity -> {
|
||||||
|
|||||||
@@ -152,14 +152,6 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
|||||||
windowManager.addView(closeOverlayBinding.getRoot(), closeOverlayLayoutParams);
|
windowManager.addView(closeOverlayBinding.getRoot(), closeOverlayLayoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initPlayback() {
|
|
||||||
super.initPlayback();
|
|
||||||
// Make sure video and text tracks are enabled if the screen is turned on (which should
|
|
||||||
// always be the case), in the case user switched from background player to popup player
|
|
||||||
player.useVideoAndSubtitles(player.isScreenOn());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupElementsVisibility() {
|
protected void setupElementsVisibility() {
|
||||||
binding.fullScreenButton.setVisibility(View.VISIBLE);
|
binding.fullScreenButton.setVisibility(View.VISIBLE);
|
||||||
@@ -227,10 +219,10 @@ public final class PopupPlayerUi extends VideoPlayerUi {
|
|||||||
} else if (player.isPlaying() || player.isLoading()) {
|
} else if (player.isPlaying() || player.isLoading()) {
|
||||||
if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
|
if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
|
||||||
// Use only audio source when screen turns off while popup player is playing
|
// Use only audio source when screen turns off while popup player is playing
|
||||||
player.useVideoAndSubtitles(false);
|
player.useVideoSource(false);
|
||||||
} else if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
|
} else if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
|
||||||
// Restore video source when screen turns on and user was watching video in popup
|
// Restore video source when screen turns on and user was watching video in popup
|
||||||
player.useVideoAndSubtitles(true);
|
player.useVideoSource(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import java.io.File
|
|||||||
class BackupFileLocator(private val homeDir: File) {
|
class BackupFileLocator(private val homeDir: File) {
|
||||||
companion object {
|
companion object {
|
||||||
const val FILE_NAME_DB = "newpipe.db"
|
const val FILE_NAME_DB = "newpipe.db"
|
||||||
|
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"Serializing preferences with Java's ObjectOutputStream is vulnerable to injections",
|
"Serializing preferences with Java's ObjectOutputStream is vulnerable to injections",
|
||||||
replaceWith = ReplaceWith("FILE_NAME_JSON_PREFS")
|
replaceWith = ReplaceWith("FILE_NAME_JSON_PREFS")
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import com.grack.nanojson.JsonArray
|
|||||||
import com.grack.nanojson.JsonParser
|
import com.grack.nanojson.JsonParser
|
||||||
import com.grack.nanojson.JsonParserException
|
import com.grack.nanojson.JsonParserException
|
||||||
import com.grack.nanojson.JsonWriter
|
import com.grack.nanojson.JsonWriter
|
||||||
|
import org.schabi.newpipe.streams.io.SharpOutputStream
|
||||||
|
import org.schabi.newpipe.streams.io.StoredFileHelper
|
||||||
|
import org.schabi.newpipe.util.ZipHelper
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
import org.schabi.newpipe.streams.io.SharpOutputStream
|
|
||||||
import org.schabi.newpipe.streams.io.StoredFileHelper
|
|
||||||
import org.schabi.newpipe.util.ZipHelper
|
|
||||||
|
|
||||||
class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -31,7 +31,7 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
ZipHelper.addFileToZip(
|
ZipHelper.addFileToZip(
|
||||||
outZip,
|
outZip,
|
||||||
BackupFileLocator.FILE_NAME_DB,
|
BackupFileLocator.FILE_NAME_DB,
|
||||||
fileLocator.db.path
|
fileLocator.db.path,
|
||||||
)
|
)
|
||||||
|
|
||||||
// add the legacy vulnerable serialized preferences (will be removed in the future)
|
// add the legacy vulnerable serialized preferences (will be removed in the future)
|
||||||
@@ -78,7 +78,7 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
val success = ZipHelper.extractFileFromZip(
|
val success = ZipHelper.extractFileFromZip(
|
||||||
file,
|
file,
|
||||||
BackupFileLocator.FILE_NAME_DB,
|
BackupFileLocator.FILE_NAME_DB,
|
||||||
fileLocator.db.path
|
fileLocator.db.path,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -122,15 +122,10 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
for ((key, value) in entries) {
|
for ((key, value) in entries) {
|
||||||
when (value) {
|
when (value) {
|
||||||
is Boolean -> editor.putBoolean(key, value)
|
is Boolean -> editor.putBoolean(key, value)
|
||||||
|
|
||||||
is Float -> editor.putFloat(key, value)
|
is Float -> editor.putFloat(key, value)
|
||||||
|
|
||||||
is Int -> editor.putInt(key, value)
|
is Int -> editor.putInt(key, value)
|
||||||
|
|
||||||
is Long -> editor.putLong(key, value)
|
is Long -> editor.putLong(key, value)
|
||||||
|
|
||||||
is String -> editor.putString(key, value)
|
is String -> editor.putString(key, value)
|
||||||
|
|
||||||
is Set<*> -> {
|
is Set<*> -> {
|
||||||
// There are currently only Sets with type String possible
|
// There are currently only Sets with type String possible
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@@ -164,15 +159,10 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
for ((key, value) in jsonObject) {
|
for ((key, value) in jsonObject) {
|
||||||
when (value) {
|
when (value) {
|
||||||
is Boolean -> editor.putBoolean(key, value)
|
is Boolean -> editor.putBoolean(key, value)
|
||||||
|
|
||||||
is Float -> editor.putFloat(key, value)
|
is Float -> editor.putFloat(key, value)
|
||||||
|
|
||||||
is Int -> editor.putInt(key, value)
|
is Int -> editor.putInt(key, value)
|
||||||
|
|
||||||
is Long -> editor.putLong(key, value)
|
is Long -> editor.putLong(key, value)
|
||||||
|
|
||||||
is String -> editor.putString(key, value)
|
is String -> editor.putString(key, value)
|
||||||
|
|
||||||
is JsonArray -> {
|
is JsonArray -> {
|
||||||
editor.putStringSet(key, value.mapNotNull { e -> e as? String }.toSet())
|
editor.putStringSet(key, value.mapNotNull { e -> e as? String }.toSet())
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user