Compare commits
341 Commits
0.1-alpha3
...
develop
Author | SHA1 | Date | |
---|---|---|---|
0fd7cc964f
|
|||
b07a6fd407
|
|||
7d661712f7
|
|||
8fcf047e99
|
|||
17dbe945e5
|
|||
5f609d4c33
|
|||
6515f657d0
|
|||
c448b44fc4
|
|||
88ebc378d3
|
|||
1a012cba7d
|
|||
59a457430e
|
|||
0662d656ac
|
|||
3549a3d2a7
|
|||
c89ae54929
|
|||
3aa03783a9
|
|||
4bceacf75c
|
|||
cf02bee7d4
|
|||
01d026cc7f
|
|||
7580093649 | |||
f266731115
|
|||
a6a23c8560
|
|||
2cb05de810
|
|||
5cf4527a92
|
|||
14ad34138c
|
|||
47e1f6bd49
|
|||
fdcb76e26e
|
|||
7004d73b9f
|
|||
a13eb15adf
|
|||
d40ab9519c
|
|||
2e7db26d1d
|
|||
8b7fb3ac5f
|
|||
097383a082
|
|||
9380f98098
|
|||
e0f05169f5
|
|||
e113a9c795
|
|||
8e397e13d2
|
|||
31e7adac03
|
|||
63f5e69094
|
|||
bf6f2d916e
|
|||
81a20e0aa9 | |||
ed8f3fdcda
|
|||
fffbeaeb49
|
|||
21caa8eb1b
|
|||
bbc819551b
|
|||
2004a3f483
|
|||
0a31c2fd88
|
|||
f49b5a2730
|
|||
a95813e91e
|
|||
8bdaa8122b
|
|||
e2ea0a364e
|
|||
777c6e0212
|
|||
71d5c58653
|
|||
6624e71228
|
|||
d33de371d1 | |||
1ecd25bb06
|
|||
fa28eb35ab
|
|||
d3fe81224b
|
|||
34c7f9d081
|
|||
e835715b9c
|
|||
001141337d
|
|||
5cd3d25ebe
|
|||
215e01c53a
|
|||
1751963574
|
|||
9c3548a866
|
|||
ebd96f9849
|
|||
85b17d7a76
|
|||
f128efea0d
|
|||
da94003368
|
|||
3fdc2aff1b | |||
326da147f1
|
|||
f398c82f62
|
|||
821f8b5590
|
|||
0028cb6dd7
|
|||
127bd030b9
|
|||
3cadaa5c7a
|
|||
97966f5ad3
|
|||
4c55bb771f
|
|||
8eb737a831
|
|||
522b893dc8
|
|||
69e0b6bcca
|
|||
c34b95795f
|
|||
9059306e90
|
|||
ed0c0a4c61
|
|||
03a79346b7
|
|||
ad1e3068cd
|
|||
de1f19c2b7
|
|||
12bbc2ef5f
|
|||
0186cef79e
|
|||
bc5509cf93
|
|||
ef9a0f00d0
|
|||
b85d7ae025
|
|||
69c9666d2b
|
|||
7d6c300f7e
|
|||
1ebc1194e6
|
|||
c48328723b
|
|||
95c8a72c94
|
|||
fc04e8e222
|
|||
a898a70653
|
|||
58aab72097
|
|||
35157b78f5
|
|||
c6a00ea061
|
|||
80a7fc4398
|
|||
dd6ca8b90e
|
|||
e80e81af0f
|
|||
f852600dc7
|
|||
aa49169034
|
|||
7abb5cd3e8
|
|||
3a71bdd2c7
|
|||
629c144c5b
|
|||
b2196f11da
|
|||
5b5a74a1de
|
|||
7a860a7270
|
|||
e97ad9a245
|
|||
cf435fdb72
|
|||
42895a6fba
|
|||
eaf1cf78e9
|
|||
1af82f8370
|
|||
d31a19a4f1
|
|||
b27666ee69 | |||
e76cbda04d
|
|||
7fbf639a70
|
|||
ff63b3d7a4
|
|||
7d32cecd89
|
|||
72280f29d8
|
|||
cd4cfb7a0c
|
|||
4a5a6c04ca
|
|||
554c66e11f
|
|||
0aece1d8fa | |||
f820d2aac0 | |||
0ea2e5ee97
|
|||
a092c5b8be
|
|||
ab660d0ae7
|
|||
be1c001942
|
|||
30a5331bbc
|
|||
0797e9fa3d
|
|||
75204e522d
|
|||
2016e03e56
|
|||
4505f95309
|
|||
e8bf63a666
|
|||
a51001ec2e
|
|||
0b5a8e69fb
|
|||
61c96f5ce2
|
|||
9bf0ae2f63
|
|||
f66fca7ebb
|
|||
df4f43c0a2
|
|||
287ef57bdb
|
|||
aa41884db5
|
|||
bec0dc2628
|
|||
4fed3ddb91
|
|||
e652c001d3
|
|||
2f78fbea73
|
|||
a1fe08840f
|
|||
402fb06c9e
|
|||
188d0d9162
|
|||
d5d70e49d2
|
|||
f100b4abf3
|
|||
f2a798d4f7
|
|||
d427691f6e
|
|||
b4daac0814
|
|||
554af530e3
|
|||
27e7f2a249
|
|||
f97d07c2b8
|
|||
ecbbc5db7b
|
|||
4fd6f9ca7e
|
|||
63ce910ec5
|
|||
7dc41da13c
|
|||
236ca9a6c9
|
|||
a46fd4c6d2
|
|||
c4bc3c7ea2
|
|||
844ff41dd3
|
|||
487c0c3c39
|
|||
eafefd9a51
|
|||
3935f37267
|
|||
39e740cd92 | |||
eeb1c33e43
|
|||
8753d4f36f
|
|||
5ea94b7ded
|
|||
062013489d
|
|||
ed9eff433b
|
|||
c2a5f768b8
|
|||
a505315781
|
|||
d76538cf28
|
|||
309a991007
|
|||
0340c83b47
|
|||
9dfd2cf70b
|
|||
26d2da923b
|
|||
c66c725ee3
|
|||
44f99295e9
|
|||
d417181b70
|
|||
9df5be003b
|
|||
cf3b1802d5
|
|||
19552d3950 | |||
4de97ca42e
|
|||
664959641f
|
|||
c1b0b4038c | |||
ba7d82bc2b
|
|||
e0a6485ed7
|
|||
5555269877
|
|||
3fcd1a96b2
|
|||
03e9c3dae5
|
|||
5ccf907ed8 | |||
8afbae1e1a
|
|||
164db8ebd1
|
|||
44d1825095
|
|||
1d071eafdb
|
|||
0decf317d9
|
|||
5e48e724a7
|
|||
46e3d1f1b6
|
|||
a3a89c6b64
|
|||
7ce67f57cd
|
|||
68d462eeee
|
|||
063b5405fc
|
|||
be591a961a
|
|||
8160641b8f
|
|||
86dfd69b4b
|
|||
74e8639435
|
|||
49e0b1ec29 | |||
e8ab11d5ff
|
|||
0bb433b5cb
|
|||
b05ecf64a6
|
|||
7a2f3ad265
|
|||
4f2bd4fd59
|
|||
af66d968cc | |||
06770559ee
|
|||
1a9de4124d
|
|||
6cc59a72fc
|
|||
a07f291098
|
|||
fad64ad385
|
|||
9d3e9c5019
|
|||
542164be9f | |||
09191f6732
|
|||
9d698a974d
|
|||
e762745705
|
|||
f342d1a3f4
|
|||
b02fadaa89
|
|||
f4760d1ba3 | |||
5bb51c9054 | |||
1e9e02c879 | |||
67c1e2bfdc
|
|||
70aafb1a14
|
|||
373f5c56c9
|
|||
4c5d6e6e24
|
|||
c6874d0e54
|
|||
a740ccfee1
|
|||
8a22554846
|
|||
3f45d769d2
|
|||
7dc120ccfe | |||
7a95304ee1
|
|||
8c0f4965e7 | |||
8e8db386a0
|
|||
86e07ba2cf
|
|||
e5037cf9ac
|
|||
a0111d45cf | |||
0efad7e2b7
|
|||
b12daa9d39 | |||
e4ac01605f
|
|||
75ecac6144
|
|||
1efc108bd7
|
|||
31197a5d44
|
|||
489ef02a35
|
|||
9705a752fb
|
|||
7a5f90cb82
|
|||
800c2a144c
|
|||
6bec0512ba
|
|||
b3ce43c614
|
|||
7845770067
|
|||
94da8c6cee
|
|||
8a43567737
|
|||
8f60a30d61
|
|||
8fc2d69eb8 | |||
2a0bccaf5a | |||
9a45d4453c
|
|||
c648acdff0
|
|||
00699aaec7
|
|||
bba642e9e3
|
|||
f4518056db | |||
1edcf29c07 | |||
04893060e4
|
|||
6fc7bb2c1e
|
|||
ab180ddd89
|
|||
98636d326e
|
|||
b73822c945 | |||
6775a4da2e
|
|||
a390bc9686
|
|||
82bf34e4cb
|
|||
e34e5b2bbd
|
|||
77e657d37c
|
|||
20407d9cac
|
|||
dbd4b26a65
|
|||
ac5aee20de
|
|||
32844223fc
|
|||
d01e87bf14
|
|||
bb8c8ca85a
|
|||
3ed55ca3c9
|
|||
dfaf359952
|
|||
78d9f3cfa5
|
|||
db5758edf9
|
|||
2de1419d36
|
|||
7df99ea0cc
|
|||
8d1c3d9a3f
|
|||
c0c5cb9110
|
|||
21b6e358e7
|
|||
0e5c697bce
|
|||
830f7e753b
|
|||
71079ddc92
|
|||
57897077ab
|
|||
dcd6ebccea
|
|||
91c9b6d716
|
|||
256c32aa3c
|
|||
3880b3ab75
|
|||
0f0573e5bd
|
|||
6ce263832b
|
|||
fd099e97e6
|
|||
d4fa726f9c
|
|||
c8d80ddc9f
|
|||
14377c3f18
|
|||
23713fc1e6
|
|||
353ae6937a
|
|||
2e0a114a80
|
|||
0e9500e39d
|
|||
27e8e1c3c2
|
|||
e51fb0b290
|
|||
d3f078c661
|
|||
6526b8868e | |||
1118c8339c
|
|||
1595ef52bc
|
|||
406434809f | |||
1523e0235a
|
|||
a51f4ca490 | |||
4ec5d0fdc4
|
|||
8a516c640d
|
|||
49430e10bf
|
|||
81b041ab61
|
|||
cf6a110455
|
|||
c138ab4587
|
|||
f0ed6aa379
|
|||
a5fffd5d02
|
|||
ff0727da22
|
|||
ce84cb57a8
|
|||
4c274eb062
|
|||
a25ec81f6b
|
43
README.md
43
README.md
@ -1,40 +1,29 @@
|
||||
# teapod
|
||||
# Teapod
|
||||
|
||||
A unoffical App for Anime-on-Demand.
|
||||
Teapod is a unofficial App for Crunchyroll. It allows you to watch all your favourite animes from Crunchyroll on your android device. To use Teapod you need to have a account at Crunchyroll.
|
||||
|
||||
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="75">](https://f-droid.org/de/packages/org.mosad.teapod/)
|
||||
|
||||
## Features
|
||||
* acces all media in the library
|
||||
* search the library
|
||||
* play movies/tv shows via integrated exoplayer
|
||||
* add movies/tv shows to you list, for easier access
|
||||
|
||||
### Missing Features
|
||||
* a alternative/secondary stream is currently not supported (for dub titles the subtitle version is missing)
|
||||
* Watch all animes from Crunchyroll on your Android device
|
||||
* Native Player based on ExoPayer
|
||||
* Prefer the OmU version via the app settings
|
||||
|
||||
## Screenshots
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Library.png" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Library.png)
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Media.png" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Media.png)
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Search.png" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Search.png)
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Home.webp" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Home.webp)
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Library.webp" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Library.webp)
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Media.webp" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Media.webp)
|
||||
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Search.webp" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Search.webp)
|
||||
|
||||
### License
|
||||
This App is licensed under the terms and conditions of GPL 3. This Project is not associated with Anime-on-Demand in any way.
|
||||
Teapod is licensed under the terms and conditions of GPL 3. This Project is not associated with Crunchyroll in any way.
|
||||
|
||||
### Known Issues
|
||||
If a tv show is selected, the first episode will be marked as already watched. This is due to the difficulties of parsing. The Parser is designed to be as easy to maintain and fail safe as possible.
|
||||
### Contributing
|
||||
Currently you need to have an Crunchyroll account to contribute to Teapod. Contributing without one is impossible.If you want to contribute to Teapod and need an account on this gitea instance, please write an email.
|
||||
|
||||
### Used Libraries
|
||||
* AndroidX: https://developer.android.com/jetpack/androidx
|
||||
* Material Components for Android: https://github.com/material-components/material-components-android
|
||||
* ExoPlayer: https://github.com/google/ExoPlayer
|
||||
* Gson: https://github.com/google/gson
|
||||
* Material design icons: https://github.com/google/material-design-icons
|
||||
* Material Dialogs: https://github.com/afollestad/material-dialogs
|
||||
* Jsoup: https://jsoup.org
|
||||
* kotlinx.coroutines: https://github.com/Kotlin/kotlinx.coroutines
|
||||
* Glide: https://github.com/bumptech/glide
|
||||
* Glide Transformations: https://github.com/wasabeef/glide-transformations
|
||||
### [FAQ](https://git.mosad.xyz/Seil0/teapod/wiki#hilfe)
|
||||
|
||||
#### Why is it called Teapod?
|
||||
Teapod is a Acronym for "The ultimate anime app on demand", hence this project is called Teapod and not Teapot.
|
||||
|
||||
Teapod © 2020 [@Seil0](https://git.mosad.xyz/Seil0)
|
||||
Teapod © 2020-2023 [@Seil0](https://git.mosad.xyz/Seil0)
|
||||
|
@ -1,71 +1,89 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version"
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain 17
|
||||
sourceSets.configureEach {
|
||||
languageSettings.optIn("kotlin.RequiresOptIn")
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.2"
|
||||
compileSdk 34
|
||||
buildToolsVersion = '34.0.0'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.mosad.teapod"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "0.1-alpha3"
|
||||
minSdk 23
|
||||
targetSdk 33
|
||||
versionCode 100992 //01.00.000
|
||||
versionName "1.1.0-beta3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
resValue "string", "build_time", buildTime()
|
||||
setProperty("archivesBaseName", "teapod-$versionName")
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
buildConfig true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
namespace 'org.mosad.teapod'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3'
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha02'
|
||||
implementation 'androidx.core:core-ktx:1.13.1'
|
||||
implementation 'androidx.core:core-splashscreen:1.0.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.8.3'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.8.3'
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha06'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.6'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6'
|
||||
implementation "androidx.paging:paging-runtime-ktx:3.3.2"
|
||||
|
||||
implementation 'com.google.android.material:material:1.3.0-alpha03'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.12.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.12.0'
|
||||
implementation 'com.google.android.material:material:1.12.0'
|
||||
implementation "com.google.android.exoplayer:exoplayer-core:$exo_version"
|
||||
implementation "com.google.android.exoplayer:exoplayer-hls:$exo_version"
|
||||
implementation "com.google.android.exoplayer:exoplayer-dash:$exo_version"
|
||||
implementation "com.google.android.exoplayer:exoplayer-ui:$exo_version"
|
||||
implementation "com.google.android.exoplayer:extension-mediasession:$exo_version"
|
||||
|
||||
implementation 'org.jsoup:jsoup:1.13.1'
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
implementation 'com.facebook.shimmer:shimmer:0.5.0'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:4.16.0'
|
||||
implementation 'jp.wasabeef:glide-transformations:4.3.0'
|
||||
implementation 'com.afollestad.material-dialogs:core:3.3.0'
|
||||
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
|
||||
implementation 'de.psdev.licensesdialog:licensesdialog:2.1.0'
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-android:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
|
||||
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
|
||||
}
|
||||
|
||||
static def buildTime() {
|
||||
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
|
||||
}
|
||||
}
|
||||
|
41
app/proguard-rules.pro
vendored
41
app/proguard-rules.pro
vendored
@ -15,7 +15,46 @@
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
-dontobfuscate
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
#-renamesourcefileattribute SourceFile
|
||||
-keep class org.mosad.teapod.util.** { <fields>; }
|
||||
|
||||
-keep class org.json.** { *; }
|
||||
|
||||
# kotlinx.serialization
|
||||
# Keep `Companion` object fields of serializable classes.
|
||||
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
|
||||
-if @kotlinx.serialization.Serializable class **
|
||||
-keepclassmembers class <1> {
|
||||
static <1>$Companion Companion;
|
||||
}
|
||||
|
||||
# Keep `serializer()` on companion objects (both default and named) of serializable classes.
|
||||
-if @kotlinx.serialization.Serializable class ** {
|
||||
static **$* *;
|
||||
}
|
||||
-keepclassmembers class <1>$<3> {
|
||||
kotlinx.serialization.KSerializer serializer(...);
|
||||
}
|
||||
|
||||
# Keep `INSTANCE.serializer()` of serializable objects.
|
||||
-if @kotlinx.serialization.Serializable class ** {
|
||||
public static ** INSTANCE;
|
||||
}
|
||||
-keepclassmembers class <1> {
|
||||
public static <1> INSTANCE;
|
||||
kotlinx.serialization.KSerializer serializer(...);
|
||||
}
|
||||
|
||||
# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
|
||||
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
|
||||
|
||||
# This is generated automatically by the Android Gradle plugin.
|
||||
-dontwarn org.slf4j.impl.StaticLoggerBinder
|
||||
|
||||
#misc
|
||||
-dontwarn java.lang.instrument.ClassFileTransformer
|
||||
-dontwarn java.lang.ClassValue
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.mosad.teapod">
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
@ -12,20 +12,33 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".PlayerActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|screenSize|layoutDirection"
|
||||
android:theme="@style/AppTheme.MaterialComponents.Light.NoActionBar.FullScreen" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
android:exported="true"
|
||||
android:name="org.mosad.teapod.ui.activity.main.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.App.Starting">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:exported="false"
|
||||
android:name="org.mosad.teapod.ui.activity.onboarding.OnboardingActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:launchMode="singleTop"
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
</activity>
|
||||
<activity
|
||||
android:exported="false"
|
||||
android:name="org.mosad.teapod.ui.activity.player.PlayerActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|layoutDirection"
|
||||
android:autoRemoveFromRecents="true"
|
||||
android:launchMode="singleTask"
|
||||
android:parentActivityName="org.mosad.teapod.ui.activity.main.MainActivity"
|
||||
android:supportsPictureInPicture="true"
|
||||
android:taskAffinity=".player.PlayerActivity"
|
||||
android:theme="@style/PlayerTheme"
|
||||
tools:targetApi="n" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
BIN
app/src/main/ic_launcher-playstore.png
Normal file
BIN
app/src/main/ic_launcher-playstore.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
@ -1,180 +0,0 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.commit
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.ui.fragments.MediaFragment
|
||||
import org.mosad.teapod.ui.fragments.AccountFragment
|
||||
import org.mosad.teapod.ui.components.LoginDialog
|
||||
import org.mosad.teapod.ui.fragments.HomeFragment
|
||||
import org.mosad.teapod.ui.fragments.LibraryFragment
|
||||
import org.mosad.teapod.ui.fragments.SearchFragment
|
||||
import org.mosad.teapod.ui.fragments.LoadingFragment
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.util.TMDBApiController
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private var activeBaseFragment: Fragment = HomeFragment() // the currently active fragment, home at the start
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
nav_view.setOnNavigationItemSelectedListener(this)
|
||||
|
||||
load()
|
||||
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.nav_host_fragment, activeBaseFragment, activeBaseFragment.javaClass.simpleName)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (supportFragmentManager.backStackEntryCount > 0) {
|
||||
supportFragmentManager.popBackStack()
|
||||
} else {
|
||||
if (activeBaseFragment !is HomeFragment) {
|
||||
nav_view.selectedItemId = R.id.navigation_home
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNavigationItemSelected(item: MenuItem): Boolean {
|
||||
if (supportFragmentManager.backStackEntryCount > 0) {
|
||||
supportFragmentManager.popBackStack()
|
||||
}
|
||||
|
||||
val ret = when (item.itemId) {
|
||||
R.id.navigation_home -> {
|
||||
activeBaseFragment = HomeFragment()
|
||||
true
|
||||
}
|
||||
R.id.navigation_library -> {
|
||||
activeBaseFragment = LibraryFragment()
|
||||
true
|
||||
}
|
||||
R.id.navigation_search -> {
|
||||
activeBaseFragment = SearchFragment()
|
||||
true
|
||||
}
|
||||
R.id.navigation_account -> {
|
||||
activeBaseFragment = AccountFragment()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.nav_host_fragment, activeBaseFragment, activeBaseFragment.javaClass.simpleName)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun load() {
|
||||
// running login and list in parallel does not bring any speed improvements
|
||||
val time = measureTimeMillis {
|
||||
// make sure credentials are set
|
||||
EncryptedPreferences.readCredentials(this)
|
||||
if (EncryptedPreferences.password.isEmpty()) {
|
||||
showLoginDialog(true)
|
||||
} else {
|
||||
// try to login in, as most sites can only bee loaded once loged in
|
||||
if (!AoDParser().login()) showLoginDialog(false)
|
||||
}
|
||||
|
||||
StorageController.load(this)
|
||||
|
||||
// initially load all media
|
||||
AoDParser().listAnimes()
|
||||
|
||||
// TODO load home screen, can be parallel to listAnimes
|
||||
}
|
||||
Log.i(javaClass.name, "login and list in $time ms")
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the media fragment for the selected media.
|
||||
* While loading show the loading fragment.
|
||||
* The loading and media fragment are not stored in activeBaseFragment,
|
||||
* as the don't replace a fragment but are added on top of one.
|
||||
*/
|
||||
fun showMediaFragment(mediaId: Int) = GlobalScope.launch {
|
||||
val loadingFragment = LoadingFragment()
|
||||
supportFragmentManager.commit {
|
||||
add(R.id.nav_host_fragment, loadingFragment, "MediaFragment")
|
||||
show(loadingFragment)
|
||||
}
|
||||
|
||||
// load the streams for the selected media
|
||||
val media = AoDParser().getMediaById(mediaId)
|
||||
val tmdb = TMDBApiController().search(media.info.title, media.type)
|
||||
|
||||
val mediaFragment = MediaFragment(media, tmdb)
|
||||
supportFragmentManager.commit {
|
||||
add(R.id.nav_host_fragment, mediaFragment, "MediaFragment")
|
||||
addToBackStack(null)
|
||||
show(mediaFragment)
|
||||
}
|
||||
|
||||
supportFragmentManager.commit {
|
||||
remove(loadingFragment)
|
||||
}
|
||||
}
|
||||
|
||||
fun startPlayer(streamUrl: String) {
|
||||
val intent = Intent(this, PlayerActivity::class.java).apply {
|
||||
putExtra(getString(R.string.intent_stream_url), streamUrl)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun showLoginDialog(firstTry: Boolean) {
|
||||
LoginDialog(this, firstTry).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
|
||||
if (!AoDParser().login()) {
|
||||
showLoginDialog(false)
|
||||
Log.w(javaClass.name, "Login failed, please try again.")
|
||||
}
|
||||
}.negativeButton {
|
||||
Log.i(javaClass.name, "Login canceled, exiting.")
|
||||
finish()
|
||||
}.show()
|
||||
}
|
||||
}
|
@ -1,153 +0,0 @@
|
||||
package org.mosad.teapod
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowInsetsController
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||
import com.google.android.exoplayer2.source.hls.HlsMediaSource
|
||||
import com.google.android.exoplayer2.upstream.DataSource
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
|
||||
import com.google.android.exoplayer2.util.Util
|
||||
import kotlinx.android.synthetic.main.activity_player.*
|
||||
|
||||
|
||||
class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var player: SimpleExoPlayer
|
||||
private lateinit var dataSourceFactory: DataSource.Factory
|
||||
|
||||
private var streamUrl = ""
|
||||
|
||||
private var playWhenReady = true
|
||||
private var currentWindow = 0
|
||||
private var playbackPosition: Long = 0
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_player)
|
||||
hideBars() // Initial hide the bars
|
||||
|
||||
savedInstanceState?.let {
|
||||
currentWindow = it.getInt(getString(R.string.state_resume_window))
|
||||
playbackPosition = it.getLong(getString(R.string.state_resume_position))
|
||||
playWhenReady = it.getBoolean(getString(R.string.state_is_playing))
|
||||
}
|
||||
|
||||
streamUrl = intent.getStringExtra(getString(R.string.intent_stream_url)).toString()
|
||||
}
|
||||
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (Util.SDK_INT > 23) {
|
||||
initPlayer()
|
||||
if (video_view != null) video_view.onResume()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (Util.SDK_INT <= 23) {
|
||||
initPlayer()
|
||||
if (video_view != null) video_view.onResume()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (Util.SDK_INT <= 23) {
|
||||
if (video_view != null) video_view.onPause()
|
||||
releasePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (Util.SDK_INT > 23) {
|
||||
if (video_view != null) video_view.onPause()
|
||||
releasePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
outState.putInt(getString(R.string.state_resume_window), currentWindow)
|
||||
outState.putLong(getString(R.string.state_resume_position), playbackPosition)
|
||||
outState.putBoolean(getString(R.string.state_is_playing), playWhenReady)
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
private fun initPlayer() {
|
||||
if (streamUrl.isEmpty()) {
|
||||
Log.e(javaClass.name, "No stream url was set.")
|
||||
return
|
||||
}
|
||||
|
||||
player = SimpleExoPlayer.Builder(this).build()
|
||||
dataSourceFactory = DefaultDataSourceFactory(this, Util.getUserAgent(this, "Teapod"))
|
||||
|
||||
val mediaSource = HlsMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(MediaItem.fromUri(Uri.parse(streamUrl)))
|
||||
|
||||
player.playWhenReady = playWhenReady
|
||||
player.setMediaSource(mediaSource)
|
||||
player.seekTo(playbackPosition)
|
||||
player.prepare()
|
||||
|
||||
|
||||
player.addListener(object : Player.EventListener {
|
||||
override fun onPlaybackStateChanged(state: Int) {
|
||||
super.onPlaybackStateChanged(state)
|
||||
|
||||
loading.visibility = when (state) {
|
||||
ExoPlayer.STATE_READY -> View.GONE
|
||||
ExoPlayer.STATE_BUFFERING -> View.VISIBLE
|
||||
else -> View.GONE
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// when the player controls get hidden, hide the bars too
|
||||
video_view.setControllerVisibilityListener {
|
||||
if (it == View.GONE) hideBars()
|
||||
}
|
||||
|
||||
video_view.player = player
|
||||
}
|
||||
|
||||
private fun releasePlayer(){
|
||||
playbackPosition = player.currentPosition
|
||||
currentWindow = player.currentWindowIndex
|
||||
playWhenReady = player.playWhenReady
|
||||
player.release()
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the status and navigation bar
|
||||
*/
|
||||
private fun hideBars() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
window.setDecorFitsSystemWindows(false)
|
||||
window.insetsController?.apply {
|
||||
hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
|
||||
systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE
|
||||
}
|
||||
} else {
|
||||
@Suppress("deprecation")
|
||||
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,284 +0,0 @@
|
||||
package org.mosad.teapod.parser
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.JsonParser
|
||||
import kotlinx.coroutines.*
|
||||
import org.jsoup.Connection
|
||||
import org.jsoup.Jsoup
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import org.mosad.teapod.util.Media
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* maybe AoDParser as object would be useful
|
||||
*/
|
||||
class AoDParser {
|
||||
|
||||
private val baseUrl = "https://www.anime-on-demand.de"
|
||||
private val loginPath = "/users/sign_in"
|
||||
private val libraryPath = "/animes"
|
||||
|
||||
private val userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"
|
||||
|
||||
companion object {
|
||||
private var csrfToken: String = ""
|
||||
private var sessionCookies = mutableMapOf<String, String>()
|
||||
private var loginSuccess = false
|
||||
|
||||
val mediaList = arrayListOf<Media>()
|
||||
val itemMediaList = arrayListOf<ItemMedia>()
|
||||
}
|
||||
|
||||
fun login(): Boolean = runBlocking {
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
// get the authenticity token
|
||||
val resAuth = Jsoup.connect(baseUrl + loginPath)
|
||||
.header("User-Agent", userAgent)
|
||||
.execute()
|
||||
|
||||
val authenticityToken = resAuth.parse().select("meta[name=csrf-token]").attr("content")
|
||||
val authCookies = resAuth.cookies()
|
||||
|
||||
//Log.d(javaClass.name, "Received authenticity token: $authenticityToken")
|
||||
//Log.d(javaClass.name, "Received authenticity cookies: $authCookies")
|
||||
|
||||
val data = mapOf(
|
||||
Pair("user[login]", EncryptedPreferences.login),
|
||||
Pair("user[password]", EncryptedPreferences.password),
|
||||
Pair("user[remember_me]", "1"),
|
||||
Pair("commit", "Einloggen"),
|
||||
Pair("authenticity_token", authenticityToken)
|
||||
)
|
||||
|
||||
val resLogin = Jsoup.connect(baseUrl + loginPath)
|
||||
.method(Connection.Method.POST)
|
||||
.data(data)
|
||||
.postDataCharset("UTF-8")
|
||||
.cookies(authCookies)
|
||||
.execute()
|
||||
|
||||
//println(resLogin.body())
|
||||
|
||||
sessionCookies = resLogin.cookies()
|
||||
loginSuccess = resLogin.body().contains("Hallo, du bist jetzt angemeldet.")
|
||||
Log.i(javaClass.name, "Status: ${resLogin.statusCode()} (${resLogin.statusMessage()}), login successful: $loginSuccess")
|
||||
|
||||
loginSuccess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list all animes from the website
|
||||
*/
|
||||
fun listAnimes(): ArrayList<Media> = runBlocking {
|
||||
if (sessionCookies.isEmpty()) login()
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
val resAnimes = Jsoup.connect(baseUrl + libraryPath)
|
||||
.cookies(sessionCookies)
|
||||
.get()
|
||||
|
||||
//println(resAnimes)
|
||||
|
||||
mediaList.clear()
|
||||
resAnimes.select("div.animebox").forEach {
|
||||
val type = if (it.select("p.animebox-link").select("a").text().toLowerCase(Locale.ROOT) == "zur serie") {
|
||||
MediaType.TVSHOW
|
||||
} else {
|
||||
MediaType.MOVIE
|
||||
}
|
||||
val mediaTitle = it.select("h3.animebox-title").text()
|
||||
val mediaLink = it.select("p.animebox-link").select("a").attr("href")
|
||||
val mediaImage = it.select("p.animebox-image").select("img").attr("src")
|
||||
val mediaShortText = it.select("p.animebox-shorttext").text()
|
||||
val mediaId = mediaLink.substringAfterLast("/").toInt()
|
||||
|
||||
itemMediaList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
mediaList.add(Media(mediaId, mediaLink, type).apply {
|
||||
info.title = mediaTitle
|
||||
info.posterUrl = mediaImage
|
||||
info.shortDesc = mediaShortText
|
||||
})
|
||||
}
|
||||
|
||||
Log.i(javaClass.name, "Total library size is: ${mediaList.size}")
|
||||
|
||||
return@withContext mediaList
|
||||
}
|
||||
}
|
||||
|
||||
fun getMediaById(mediaId: Int): Media {
|
||||
val media = mediaList.first { it.id == mediaId }
|
||||
|
||||
if (media.episodes.isEmpty()) {
|
||||
loadStreams(media)
|
||||
}
|
||||
|
||||
return media
|
||||
}
|
||||
|
||||
/**
|
||||
* load streams for the media path, movies have one episode
|
||||
* @param media is used as call ba reference
|
||||
*/
|
||||
private fun loadStreams(media: Media) = runBlocking {
|
||||
if (sessionCookies.isEmpty()) login()
|
||||
|
||||
if (!loginSuccess) {
|
||||
Log.w(javaClass.name, "Login, was not successful.")
|
||||
return@runBlocking
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
|
||||
val res = Jsoup.connect(baseUrl + media.link)
|
||||
.cookies(sessionCookies)
|
||||
.get()
|
||||
|
||||
//println(res)
|
||||
|
||||
// parse additional info from the media page
|
||||
res.select("table.vertical-table").select("tr").forEach { row ->
|
||||
when (row.select("th").text().toLowerCase(Locale.ROOT)) {
|
||||
"produktionsjahr" -> media.info.year = row.select("td").text().toInt()
|
||||
"fsk" -> media.info.age = row.select("td").text().toInt()
|
||||
"episodenanzahl" -> {
|
||||
media.info.episodesCount = row.select("td").text()
|
||||
.substringBefore("/")
|
||||
.filter{ it.isDigit() }
|
||||
.toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parse additional information for tv shows
|
||||
media.episodes = when (media.type) {
|
||||
MediaType.MOVIE -> listOf(Episode())
|
||||
MediaType.TVSHOW -> {
|
||||
res.select("div.three-box-container > div.episodebox").map { episodebox ->
|
||||
val episodeId = episodebox.select("div.flip-front").attr("id").substringAfter("-").toInt()
|
||||
val episodeShortDesc = episodebox.select("p.episodebox-shorttext").text()
|
||||
val episodeWatched = episodebox.select("div.episodebox-icons > div").hasClass("status-icon-orange")
|
||||
val episodeWatchedCallback = episodebox.select("input.streamstarter_html5").eachAttr("data-playlist").first()
|
||||
|
||||
Episode(
|
||||
id = episodeId,
|
||||
shortDesc = episodeShortDesc,
|
||||
watched = episodeWatched,
|
||||
watchedCallback = episodeWatchedCallback
|
||||
)
|
||||
}
|
||||
}
|
||||
MediaType.OTHER -> listOf()
|
||||
}
|
||||
|
||||
if (csrfToken.isEmpty()) {
|
||||
csrfToken = res.select("meta[name=csrf-token]").attr("content")
|
||||
//Log.i(javaClass.name, "New csrf token is $csrfToken")
|
||||
}
|
||||
|
||||
// TODO has attr data-lag (ger or jap)
|
||||
val playlists = res.select("input.streamstarter_html5").eachAttr("data-playlist")
|
||||
|
||||
if (playlists.size > 0) {
|
||||
loadPlaylist(playlists.first(), csrfToken, media.type, media.episodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load the playlist path and parse it, read the stream info from json
|
||||
* @param episodes is used as call ba reference
|
||||
*/
|
||||
private fun loadPlaylist(playlistPath: String, csrfToken: String, type: MediaType, episodes: List<Episode>) = runBlocking {
|
||||
withContext(Dispatchers.Default) {
|
||||
val headers = mutableMapOf(
|
||||
Pair("Accept", "application/json, text/javascript, */*; q=0.01"),
|
||||
Pair("Accept-Language", "de,en-US;q=0.7,en;q=0.3"),
|
||||
Pair("Accept-Encoding", "gzip, deflate, br"),
|
||||
Pair("X-CSRF-Token", csrfToken),
|
||||
Pair("X-Requested-With", "XMLHttpRequest"),
|
||||
)
|
||||
|
||||
//println("loading streaminfo with cstf: $csrfToken")
|
||||
|
||||
val res = Jsoup.connect(baseUrl + playlistPath)
|
||||
.ignoreContentType(true)
|
||||
.cookies(sessionCookies)
|
||||
.headers(headers)
|
||||
.execute()
|
||||
|
||||
//println(res.body())
|
||||
|
||||
when (type) {
|
||||
MediaType.MOVIE -> {
|
||||
val movie = JsonParser.parseString(res.body()).asJsonObject
|
||||
.get("playlist").asJsonArray
|
||||
.first().asJsonObject
|
||||
|
||||
movie.get("sources").asJsonArray.first().apply {
|
||||
episodes.first().streamUrl = this.asJsonObject.get("file").asString
|
||||
}
|
||||
}
|
||||
|
||||
MediaType.TVSHOW -> {
|
||||
val episodesJson = JsonParser.parseString(res.body()).asJsonObject
|
||||
.get("playlist").asJsonArray
|
||||
|
||||
episodesJson.forEach { jsonElement ->
|
||||
val episodeId = jsonElement.asJsonObject.get("mediaid")
|
||||
val episodeStream = jsonElement.asJsonObject.get("sources").asJsonArray
|
||||
.first().asJsonObject
|
||||
.get("file").asString
|
||||
val episodeTitle = jsonElement.asJsonObject.get("title").asString
|
||||
val episodePoster = jsonElement.asJsonObject.get("image").asString
|
||||
val episodeDescription = jsonElement.asJsonObject.get("description").asString
|
||||
val episodeNumber = episodeTitle.substringAfter(", Ep. ").toInt()
|
||||
|
||||
episodes.first { it.id == episodeId.asInt }.apply {
|
||||
this.title = episodeTitle
|
||||
this.posterUrl = episodePoster
|
||||
this.streamUrl = episodeStream
|
||||
this.description = episodeDescription
|
||||
this.number = episodeNumber
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log.e(javaClass.name, "Wrong Type, please report this issue.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun sendCallback(callbackPath: String) = GlobalScope.launch {
|
||||
val headers = mutableMapOf(
|
||||
Pair("Accept", "application/json, text/javascript, */*; q=0.01"),
|
||||
Pair("Accept-Language", "de,en-US;q=0.7,en;q=0.3"),
|
||||
Pair("Accept-Encoding", "gzip, deflate, br"),
|
||||
Pair("X-CSRF-Token", csrfToken),
|
||||
Pair("X-Requested-With", "XMLHttpRequest"),
|
||||
)
|
||||
|
||||
try {
|
||||
withContext(Dispatchers.IO) {
|
||||
Jsoup.connect(baseUrl + callbackPath)
|
||||
.ignoreContentType(true)
|
||||
.cookies(sessionCookies)
|
||||
.headers(headers)
|
||||
.execute()
|
||||
}
|
||||
} catch (ex: IOException) {
|
||||
Log.e(javaClass.name, "Callback for $callbackPath failed.", ex)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,778 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.parser.crunchyroll
|
||||
|
||||
import android.util.Log
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.put
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
|
||||
object Crunchyroll {
|
||||
private val TAG = javaClass.name
|
||||
|
||||
private val client = HttpClient {
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
ignoreUnknownKeys = true
|
||||
})
|
||||
}
|
||||
}
|
||||
private const val baseUrl = "https://beta-api.crunchyroll.com"
|
||||
private const val staticUrl = "https://static.crunchyroll.com"
|
||||
private const val basicApiTokenUrl = "https://gitlab.com/-/snippets/2274956/raw/main/snippetfile1.txt"
|
||||
private var basicApiToken: String = ""
|
||||
|
||||
private lateinit var token: Token
|
||||
private var tokenValidUntil: Long = 0
|
||||
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
|
||||
private val tokenRefreshContext = newSingleThreadContext("TokenRefreshContext")
|
||||
|
||||
private var accountID = ""
|
||||
private var externalID = ""
|
||||
|
||||
private val browsingCache = hashMapOf<String, BrowseResult>()
|
||||
|
||||
/**
|
||||
* Load the pai token, see:
|
||||
* https://git.mosad.xyz/mosad/NonePublicIssues/issues/1
|
||||
*
|
||||
* TODO handle empty file
|
||||
*/
|
||||
fun initBasicApiToken() = runBlocking {
|
||||
withContext(Dispatchers.IO) {
|
||||
basicApiToken = client.get { url(basicApiTokenUrl) }.bodyAsText()
|
||||
Log.i(TAG, "basic auth token: $basicApiToken")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login to the crunchyroll API.
|
||||
*
|
||||
* @param username The Username/Email of the user to log in
|
||||
* @param password The Accounts Password
|
||||
*
|
||||
* @return Boolean: True if login was successful, else false
|
||||
*/
|
||||
fun login(username: String, password: String): Boolean = runBlocking {
|
||||
val tokenEndpoint = "/auth/v1/token"
|
||||
val formData = Parameters.build {
|
||||
append("username", username)
|
||||
append("password", password)
|
||||
append("grant_type", "password")
|
||||
append("scope", "offline_access")
|
||||
}
|
||||
|
||||
var success = false// is false
|
||||
withContext(Dispatchers.IO) {
|
||||
Log.i(TAG, "getting token ...")
|
||||
|
||||
val status = try {
|
||||
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
|
||||
header("Authorization", "Basic $basicApiToken")
|
||||
}
|
||||
token = response.body()
|
||||
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
|
||||
response.status
|
||||
} catch (ex: ClientRequestException) {
|
||||
val status = ex.response.status
|
||||
if (status == HttpStatusCode.Unauthorized) {
|
||||
Log.e(TAG, "Could not complete login: " +
|
||||
"${status.value} ${status.description}. " +
|
||||
"Probably wrong username or password")
|
||||
}
|
||||
|
||||
status
|
||||
}
|
||||
Log.i(TAG, "Login complete with code $status")
|
||||
success = (status == HttpStatusCode.OK)
|
||||
}
|
||||
|
||||
return@runBlocking success
|
||||
}
|
||||
|
||||
private fun refreshToken() {
|
||||
login(EncryptedPreferences.login, EncryptedPreferences.password)
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests: get, post, delete
|
||||
*/
|
||||
|
||||
private suspend inline fun <reified T> request(
|
||||
url: String,
|
||||
httpMethod: HttpMethod,
|
||||
params: List<Pair<String, Any?>> = listOf(),
|
||||
bodyObject: Any = Any()
|
||||
): T = coroutineScope {
|
||||
withContext(tokenRefreshContext) {
|
||||
if (System.currentTimeMillis() > tokenValidUntil) refreshToken()
|
||||
}
|
||||
|
||||
return@coroutineScope (Dispatchers.IO) {
|
||||
val response = client.request(url) {
|
||||
method = httpMethod
|
||||
header("Authorization", "${token.tokenType} ${token.accessToken}")
|
||||
params.forEach {
|
||||
parameter(it.first, it.second)
|
||||
}
|
||||
|
||||
// for json set body and content type
|
||||
if (bodyObject is JsonObject) {
|
||||
setBody(bodyObject)
|
||||
contentType(ContentType.Application.Json)
|
||||
}
|
||||
}
|
||||
|
||||
response.body<T>()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HTTP GET request with [params] to the [endpoint] at [url], if url is empty use baseUrl
|
||||
*/
|
||||
private suspend inline fun <reified T> requestGet(
|
||||
endpoint: String,
|
||||
params: List<Pair<String, Any?>> = listOf(),
|
||||
url: String = ""
|
||||
): T {
|
||||
val path = url.ifEmpty { baseUrl }.plus(endpoint)
|
||||
|
||||
return request(path, HttpMethod.Get, params)
|
||||
}
|
||||
|
||||
private suspend fun requestPost(
|
||||
endpoint: String,
|
||||
params: List<Pair<String, Any?>> = listOf(),
|
||||
bodyObject: JsonObject
|
||||
) {
|
||||
val path = "$baseUrl$endpoint"
|
||||
|
||||
val response: HttpResponse = request(path, HttpMethod.Post, params, bodyObject)
|
||||
Log.i(TAG, "Response: $response")
|
||||
}
|
||||
|
||||
private suspend fun requestPatch(
|
||||
endpoint: String,
|
||||
params: List<Pair<String, Any?>> = listOf(),
|
||||
bodyObject: JsonObject
|
||||
) {
|
||||
val path = "$baseUrl$endpoint"
|
||||
|
||||
val response: HttpResponse = request(path, HttpMethod.Patch, params, bodyObject)
|
||||
Log.i(TAG, "Response: $response")
|
||||
}
|
||||
|
||||
private suspend fun requestDelete(
|
||||
endpoint: String,
|
||||
params: List<Pair<String, Any?>> = listOf(),
|
||||
url: String = ""
|
||||
) = coroutineScope {
|
||||
val path = url.ifEmpty { "$baseUrl$endpoint" }
|
||||
|
||||
val response: HttpResponse = request(path, HttpMethod.Delete, params)
|
||||
Log.i(TAG, "Response: $response")
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic functions: account
|
||||
* Needed for other functions to work properly!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve the account id and set the corresponding global var.
|
||||
* The account id is needed for other calls.
|
||||
*
|
||||
* This must be execute on every start for teapod to work properly!
|
||||
*/
|
||||
suspend fun account() {
|
||||
val indexEndpoint = "/accounts/v1/me"
|
||||
|
||||
val account: Account = try {
|
||||
requestGet(indexEndpoint)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "SerializationException in account(). This is bad!", ex)
|
||||
NoneAccount
|
||||
}
|
||||
|
||||
accountID = account.accountId
|
||||
externalID = account.externalId
|
||||
}
|
||||
|
||||
/**
|
||||
* General element/media functions: browse, search, objects, season_list
|
||||
*/
|
||||
|
||||
/**
|
||||
* Browse the media available on crunchyroll.
|
||||
*
|
||||
* @param start start of the item list, used for pagination, default = 0
|
||||
* @param n number of items to return, default = 10
|
||||
* @param sortBy the sort order, see **[SortBy]**
|
||||
* @param ratings add user rating to the objects, default = false
|
||||
* @param seasonTag filter by season tag, if present
|
||||
* @param categories filter by category, if present
|
||||
* @return A **[BrowseResult]** object is returned.
|
||||
*/
|
||||
suspend fun browse(
|
||||
start: Int = 0,
|
||||
n: Int = 10,
|
||||
sortBy: SortBy = SortBy.ALPHABETICAL,
|
||||
ratings: Boolean = false,
|
||||
seasonTag: String = "",
|
||||
categories: List<Categories> = emptyList()
|
||||
): BrowseResult {
|
||||
val browseEndpoint = "/content/v2/discover/browse"
|
||||
val parameters = mutableListOf(
|
||||
"start" to start,
|
||||
"n" to n,
|
||||
"sort_by" to sortBy.str,
|
||||
"ratings" to ratings,
|
||||
"preferred_audio_language" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
)
|
||||
|
||||
// if a season tag is present add it to the parameters
|
||||
if (seasonTag.isNotEmpty()) {
|
||||
parameters.add("season_tag" to seasonTag)
|
||||
}
|
||||
|
||||
// if a season tag is present add it to the parameters
|
||||
if (categories.isNotEmpty()) {
|
||||
parameters.add("categories" to categories.joinToString(",") { it.str })
|
||||
}
|
||||
|
||||
// fetch result if not already cached
|
||||
if (browsingCache.contains(parameters.toString())) {
|
||||
Log.d(TAG, "browse result cached: $parameters")
|
||||
} else {
|
||||
Log.d(TAG, "browse result not cached, fetching: $parameters")
|
||||
val browseResult: BrowseResult = try {
|
||||
requestGet(browseEndpoint, parameters)
|
||||
}catch (ex: Exception) {
|
||||
Log.e(TAG, "SerializationException in browse().", ex)
|
||||
NoneBrowseResult
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if the cache has more than 10 entries clear it, so it doesn't become a memory problem
|
||||
// Note: this value is totally guessed and should be replaced by a properly researched value
|
||||
if (browsingCache.size > 10) {
|
||||
browsingCache.clear()
|
||||
}
|
||||
|
||||
// add results to cache
|
||||
browsingCache[parameters.toString()] = browseResult
|
||||
}
|
||||
|
||||
return browsingCache[parameters.toString()] ?: NoneBrowseResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Search fo a query term.
|
||||
* Note: currently this function only supports series/tv shows.
|
||||
*
|
||||
* @param query The query term as String
|
||||
* @param n The maximum number of results to return, default = 10
|
||||
* @param ratings add user rating to the objects, default = false
|
||||
* @return A **[SearchResult]** object
|
||||
*/
|
||||
suspend fun search(query: String, n: Int = 10, ratings: Boolean = false): SearchResult {
|
||||
val searchEndpoint = "/content/v2/discover/search"
|
||||
val parameters = listOf(
|
||||
"q" to query,
|
||||
"n" to n,
|
||||
"type" to "series",
|
||||
"ratings" to ratings,
|
||||
"preferred_audio_language" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
// TODO episodes have thumbnails as image, and not poster_tall/poster_tall,
|
||||
// to work around this, for now only tv shows are supported
|
||||
|
||||
return try {
|
||||
requestGet(searchEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in search(), with query = \"$query\".", ex)
|
||||
NoneSearchResult
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of series objects.
|
||||
* Note: episode objects are currently not supported
|
||||
*
|
||||
* @param objects The object IDs as list of Strings
|
||||
* @param ratings add user rating to the objects
|
||||
* @return A **[Collection]** of Panels
|
||||
*/
|
||||
suspend fun objects(objects: List<String>, ratings: Boolean = false): CollectionV2<Item> {
|
||||
val episodesEndpoint = "/content/v2/cms/objects/${objects.joinToString(",")}"
|
||||
val parameters = listOf(
|
||||
"ratings" to ratings,
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(episodesEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in objects().", ex)
|
||||
NoneCollectionV2
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main media functions: series, season, episodes, playback
|
||||
*/
|
||||
|
||||
/**
|
||||
* series id == crunchyroll id?
|
||||
*/
|
||||
suspend fun series(seriesId: String): Series {
|
||||
val seriesEndpoint = "/content/v2/cms/series/$seriesId"
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(seriesEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in series() for id $seriesId.", ex)
|
||||
NoneSeries
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next episode for a series.
|
||||
*
|
||||
* FIXME up_next returns no content if the is no next episode
|
||||
*
|
||||
* @param seriesId The series id for which to call up next
|
||||
* @return A **[UpNextSeriesItem]** with a Panel representing the up next episode
|
||||
*/
|
||||
suspend fun upNextSeries(seriesId: String): UpNextSeriesList {
|
||||
val upNextSeriesEndpoint = "/content/v2/discover/up_next/$seriesId"
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(upNextSeriesEndpoint, parameters)
|
||||
} catch (ex: NoTransformationFoundException) {
|
||||
// should be 204 No Content
|
||||
NoneUpNextSeriesList
|
||||
} catch (ex: JsonConvertException) {
|
||||
Log.e(TAG, "JsonConvertException in upNextSeries() with seriesId=$seriesId", ex)
|
||||
NoneUpNextSeriesList
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in upNextSeries() for seriesId $seriesId.", ex)
|
||||
NoneUpNextSeriesList
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available seasons for a series.
|
||||
*
|
||||
* @param seriesId The series id for which to get the seasons
|
||||
* @return A **[Seasons]** object with a list of **[Season]**
|
||||
*/
|
||||
suspend fun seasons(seriesId: String): Seasons {
|
||||
val seasonsEndpoint = "/content/v2/cms/series/$seriesId/seasons"
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(seasonsEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in seasons() for seriesId $seriesId.", ex)
|
||||
NoneSeasons
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available episodes for a season.
|
||||
*
|
||||
* @param seasonId The season id for which to get the episodes
|
||||
* @return A **[Episodes]** object with a list of **[Episode]**
|
||||
*/
|
||||
suspend fun episodes(seasonId: String): Episodes {
|
||||
val episodesEndpoint = "/content/v2/cms/seasons/$seasonId/episodes"
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(episodesEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in episodes() for seasonId $seasonId.", ex)
|
||||
NoneEpisodes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available subtitles and streams of a episode.
|
||||
*
|
||||
* @param url The streams url of a episode
|
||||
* @return A **[Streams]** object
|
||||
*/
|
||||
suspend fun streams(url: String): Streams {
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(url, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in streams() with url $url.", ex)
|
||||
NoneStreams
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun streamsFromMediaGUID(mediaGUID: String): Streams {
|
||||
val streamsEndpoint = "/content/v2/cms/videos/$mediaGUID/streams"
|
||||
return streams(streamsEndpoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional media functions: watchlist (series), playhead, similar to
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if a media is in the user's watchlist.
|
||||
*
|
||||
* @param seriesId The crunchyroll series id of the media to check
|
||||
* @return **[Boolean]**: ture if it was found, else false
|
||||
*/
|
||||
suspend fun isWatchlist(seriesId: String): Boolean {
|
||||
val watchlistSeriesEndpoint = "/content/v2/$accountID/watchlist"
|
||||
val parameters = listOf(
|
||||
"content_ids" to seriesId,
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
(requestGet(watchlistSeriesEndpoint, parameters) as CollectionV2<IsWatchlistItem>)
|
||||
.total == 1
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in isWatchlist() with seriesId $seriesId", ex)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a media to the user's watchlist.
|
||||
*
|
||||
* @param seriesId The crunchyroll series id of the media to check
|
||||
*/
|
||||
suspend fun postWatchlist(seriesId: String) {
|
||||
val watchlistPostEndpoint = "/content/v2/$accountID/watchlist"
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
val json = buildJsonObject {
|
||||
put("content_id", seriesId)
|
||||
}
|
||||
|
||||
try {
|
||||
requestPost(watchlistPostEndpoint, parameters, json)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in postWatchlist() with seriesId $seriesId", ex)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a media from the user's watchlist.
|
||||
*
|
||||
* @param seriesId The crunchyroll series id of the media to check
|
||||
*/
|
||||
suspend fun deleteWatchlist(seriesId: String) {
|
||||
val watchlistDeleteEndpoint = "/content/v2/$accountID/watchlist/$seriesId"
|
||||
val parameters = listOf(
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
try {
|
||||
requestDelete(watchlistDeleteEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in deleteWatchlist() with seriesId $seriesId", ex)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get playhead information for all episodes in episodeIDs.
|
||||
* The Information returned contains the playhead position, watched state
|
||||
* and last modified date.
|
||||
*
|
||||
* @param episodeIDs A **[List]** of episodes IDs as strings.
|
||||
* @return A **[Map]**<String, **[PlayheadObject]**> containing playback info.
|
||||
*/
|
||||
suspend fun playheads(episodeIDs: List<String>): Playheads {
|
||||
val playheadsEndpoint = "/content/v2/$accountID/playheads"
|
||||
val parameters = listOf(
|
||||
"content_ids" to episodeIDs.joinToString(","),
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(playheadsEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in playheads().", ex.cause)
|
||||
NonePlayheads
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post the playhead to crunchy (playhead position,watched state)
|
||||
*
|
||||
* @param episodeId A episode ID as strings.
|
||||
* @param playhead The episodes playhead in seconds.
|
||||
*/
|
||||
suspend fun postPlayheads(episodeId: String, playhead: Int) {
|
||||
val playheadsEndpoint = "/content/v1/playheads/$accountID"
|
||||
val parameters = listOf("locale" to Preferences.preferredSubtitleLocale.toLanguageTag())
|
||||
|
||||
val json = buildJsonObject {
|
||||
put("content_id", episodeId)
|
||||
put("playhead", playhead)
|
||||
}
|
||||
|
||||
try {
|
||||
requestPost(playheadsEndpoint, parameters, json)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in postPlayheads()", ex.cause)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the intro meta data including start, end and duration of the intro.
|
||||
*
|
||||
* @param episodeId A episode ID as strings.
|
||||
*/
|
||||
suspend fun datalabIntro(episodeId: String): DatalabIntro {
|
||||
val datalabIntroEndpoint = "/datalab-intro-v2/$episodeId.json"
|
||||
|
||||
/*
|
||||
* wtf crunchyroll, why do you return an xml error message when some data is missing,
|
||||
* this is a json endpoint. For fucks sake, return at least a valid json message.
|
||||
*/
|
||||
return try {
|
||||
val response: HttpResponse = requestGet(datalabIntroEndpoint, url = staticUrl)
|
||||
Json.decodeFromString(response.bodyAsText())
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in datalabIntro(). EpisodeId=$episodeId", ex)
|
||||
NoneDatalabIntro
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get similar media for a show/movie.
|
||||
*
|
||||
* @param seriesId The crunchyroll series id of the media
|
||||
* @param n The maximum number of results to return, default = 10
|
||||
* @param ratings add user rating to the objects
|
||||
* @return A **[SimilarToResult]** object
|
||||
*/
|
||||
suspend fun similarTo(seriesId: String, n: Int = 10, ratings: Boolean = false): SimilarToResult {
|
||||
val similarToEndpoint = "/content/v2/discover/$accountID/similar_to/$seriesId"
|
||||
val parameters = listOf(
|
||||
"n" to n,
|
||||
"ratings" to ratings,
|
||||
"preferred_audio_language" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(similarToEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in similarTo().", ex)
|
||||
NoneSimilarToResult
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listing functions: watchlist (list), up_next_account
|
||||
*/
|
||||
|
||||
/**
|
||||
* List items present in the watchlist.
|
||||
*
|
||||
* @param n Number of items to return, defaults to 20.
|
||||
* @return A **[Collection]** containing up to n **[Item]**.
|
||||
*/
|
||||
suspend fun watchlist(n: Int = 20): CollectionV2<Item> {
|
||||
val watchlistEndpoint = "/content/v2/discover/$accountID/watchlist"
|
||||
val parameters = listOf(
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"n" to n,
|
||||
"preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag()
|
||||
)
|
||||
|
||||
val list: Watchlist = try {
|
||||
requestGet(watchlistEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in watchlist().", ex)
|
||||
NoneWatchlist
|
||||
}
|
||||
|
||||
val objects = list.data.map{ it.panel.episodeMetadata.seriesId }
|
||||
return objects(objects)
|
||||
}
|
||||
|
||||
/**
|
||||
* List the next up episodes for the logged in account.
|
||||
*
|
||||
* @param n Number of items to return, default = 20
|
||||
* @return A **[HistoryList]** containing up to n **[UpNextAccountItem]**.
|
||||
*/
|
||||
suspend fun upNextAccount(n: Int = 10): HistoryList {
|
||||
val watchlistEndpoint = "/content/v2/discover/$accountID/history"
|
||||
val parameters = listOf(
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
"n" to n
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(watchlistEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in upNextAccount().", ex)
|
||||
NoneHistoryList
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of recommendations for the currently logged in account.
|
||||
*
|
||||
* @param start start of the item list, used for pagination, default = 0
|
||||
* @param n number of items to return, default = 10
|
||||
* @param ratings add user rating to the objects, default = false
|
||||
* @return A **[RecommendationsList]** containing up to n **[Item]**.
|
||||
*/
|
||||
suspend fun recommendations(start: Int = 0, n: Int = 10, ratings: Boolean = false): RecommendationsList {
|
||||
val recommendationsEndpoint = "/content/v2/discover/$accountID/recommendations"
|
||||
val parameters = listOf(
|
||||
"start" to start,
|
||||
"n" to n,
|
||||
"ratings" to ratings,
|
||||
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag(),
|
||||
)
|
||||
|
||||
return try {
|
||||
requestGet(recommendationsEndpoint, parameters)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in recommendations().", ex)
|
||||
NoneRecommendationsList
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Account/Profile functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get profile information for the currently logged in account.
|
||||
*
|
||||
* @return A **[Profile]** object
|
||||
*/
|
||||
suspend fun profile(): Profile {
|
||||
val profileEndpoint = "/accounts/v1/me/profile"
|
||||
|
||||
return try {
|
||||
requestGet(profileEndpoint)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in profile().", ex)
|
||||
NoneProfile
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post the preferred content subtitle language.
|
||||
*
|
||||
* @param languageTag the preferred language as language tag
|
||||
*/
|
||||
suspend fun setPreferredSubtitleLanguage(languageTag: String) {
|
||||
val profileEndpoint = "/accounts/v1/me/profile"
|
||||
val json = buildJsonObject {
|
||||
put("preferred_content_subtitle_language", languageTag)
|
||||
}
|
||||
|
||||
requestPatch(profileEndpoint, bodyObject = json)
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch the preferred content audio language.
|
||||
*
|
||||
* @param languageTag the preferred language as language tag
|
||||
*/
|
||||
suspend fun setPreferredAudioLanguage(languageTag: String) {
|
||||
val profileEndpoint = "/accounts/v1/me/profile"
|
||||
val json = buildJsonObject {
|
||||
put("preferred_content_audio_language", languageTag)
|
||||
}
|
||||
|
||||
requestPatch(profileEndpoint, bodyObject = json)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional profile (benefits) information for the currently logged in account.
|
||||
*
|
||||
* * @return A **[Profile]** object
|
||||
*/
|
||||
suspend fun benefits(): Benefits {
|
||||
val profileEndpoint = "/subs/v1/subscriptions/$externalID/benefits"
|
||||
|
||||
return try {
|
||||
requestGet(profileEndpoint)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(TAG, "Exception in benefits().", ex)
|
||||
NoneBenefits
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,497 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.parser.crunchyroll
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.Locale
|
||||
|
||||
val supportedAudioLocals = listOf(
|
||||
Locale.forLanguageTag("ar-SA"),
|
||||
Locale.forLanguageTag("ca-ES"),
|
||||
Locale.forLanguageTag("de-DE"),
|
||||
Locale.forLanguageTag("en-US"),
|
||||
Locale.forLanguageTag("en-IN"),
|
||||
Locale.forLanguageTag("es-419"),
|
||||
Locale.forLanguageTag("es-ES"),
|
||||
Locale.forLanguageTag("fr-FR"),
|
||||
Locale.forLanguageTag("hi-IN"),
|
||||
Locale.forLanguageTag("it-IT"),
|
||||
Locale.forLanguageTag("ko-KR"),
|
||||
Locale.forLanguageTag("pl-PL"),
|
||||
Locale.forLanguageTag("pt-BR"),
|
||||
Locale.forLanguageTag("pt-PT"),
|
||||
Locale.forLanguageTag("ru-RU"),
|
||||
Locale.forLanguageTag("ta-IN"),
|
||||
Locale.forLanguageTag("th-TH"),
|
||||
Locale.forLanguageTag("zh-CN"),
|
||||
Locale.forLanguageTag("zh-TW"),
|
||||
Locale.ROOT
|
||||
)
|
||||
|
||||
val supportedSubtitleLocals = listOf(
|
||||
Locale.forLanguageTag("ar-SA"),
|
||||
Locale.forLanguageTag("ca-ES"),
|
||||
Locale.forLanguageTag("de-DE"),
|
||||
Locale.forLanguageTag("en-US"),
|
||||
Locale.forLanguageTag("es-419"),
|
||||
Locale.forLanguageTag("es-ES"),
|
||||
Locale.forLanguageTag("fr-FR"),
|
||||
Locale.forLanguageTag("hi-IN"),
|
||||
Locale.forLanguageTag("it-IT"),
|
||||
Locale.forLanguageTag("ms-MY"),
|
||||
Locale.forLanguageTag("pl-PL"),
|
||||
Locale.forLanguageTag("pt-BR"),
|
||||
Locale.forLanguageTag("pt-PT"),
|
||||
Locale.forLanguageTag("ru-RU"),
|
||||
Locale.forLanguageTag("tr-TR"),
|
||||
Locale.ROOT
|
||||
)
|
||||
|
||||
/**
|
||||
* data classes for browse
|
||||
* TODO make class names more clear/possibly overlapping for now
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enum of all supported sorting orders.
|
||||
*/
|
||||
enum class SortBy(val str: String) {
|
||||
ALPHABETICAL("alphabetical"),
|
||||
NEWLY_ADDED("newly_added"),
|
||||
POPULARITY("popularity")
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
enum class Categories(val str: String) {
|
||||
ACTION("action"),
|
||||
ADVENTURE("adventure"),
|
||||
COMEDY("comedy"),
|
||||
DRAMA("drama"),
|
||||
FANTASY("fantasy"),
|
||||
MUSIC("music"),
|
||||
ROMANCE("romance"),
|
||||
SCI_FI("sci-fi"),
|
||||
SEINEN("seinen"),
|
||||
SHOJO("shojo"),
|
||||
SHONEN("shonen"),
|
||||
SLICE_OF_LIFE("slice+of+life"),
|
||||
SPORTS("sports"),
|
||||
SUPERNATURAL("supernatural"),
|
||||
THRILLER("thriller")
|
||||
}
|
||||
|
||||
/**
|
||||
* token, index, account. This must pe present for the app to work!
|
||||
*/
|
||||
@Serializable
|
||||
data class Token(
|
||||
@SerialName("access_token") val accessToken: String,
|
||||
@SerialName("refresh_token") val refreshToken: String,
|
||||
@SerialName("expires_in") val expiresIn: Int,
|
||||
@SerialName("token_type") val tokenType: String,
|
||||
@SerialName("scope") val scope: String,
|
||||
@SerialName("country") val country: String,
|
||||
@SerialName("account_id") val accountId: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Index(
|
||||
@SerialName("cms") val cms: CMS,
|
||||
@SerialName("service_available") val serviceAvailable: Boolean,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class CMS(
|
||||
@SerialName("bucket") val bucket: String,
|
||||
@SerialName("policy") val policy: String,
|
||||
@SerialName("signature") val signature: String,
|
||||
@SerialName("key_pair_id") val keyPairId: String,
|
||||
@SerialName("expires") val expires: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Account(
|
||||
@SerialName("account_id") val accountId: String,
|
||||
@SerialName("external_id") val externalId: String,
|
||||
@SerialName("email_verified") val emailVerified: Boolean,
|
||||
@SerialName("created") val created: String,
|
||||
)
|
||||
val NoneAccount = Account("", "", false, "")
|
||||
|
||||
/**
|
||||
* search, browse, DiscSeasonList, Watchlist, ContinueWatchingList data types all use Collection
|
||||
*/
|
||||
|
||||
@Serializable
|
||||
data class CollectionV1<T>(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("items") val items: List<T>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class CollectionV2<T>(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("data") val data: List<T>
|
||||
)
|
||||
|
||||
typealias SearchResult = CollectionV2<SearchTypedList<Item>>
|
||||
typealias BrowseResult = CollectionV2<Item>
|
||||
typealias SimilarToResult = CollectionV2<Item>
|
||||
typealias RecommendationsList = CollectionV2<Item>
|
||||
typealias Benefits = CollectionV1<Benefit>
|
||||
|
||||
/**
|
||||
* panel data classes
|
||||
*/
|
||||
|
||||
// the data class Item is used in browse, search, watchlist and similar to
|
||||
// TODO rename to MediaPanel
|
||||
@Serializable
|
||||
data class Item(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val type: String,
|
||||
val channel_id: String,
|
||||
val description: String,
|
||||
val images: Images
|
||||
// TODO series_metadata etc.
|
||||
// TODO add slug_title if present in search, browse, similar to
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Images(val poster_tall: List<List<Poster>>, val poster_wide: List<List<Poster>>)
|
||||
// crunchyroll why?
|
||||
|
||||
@Serializable
|
||||
data class Poster(val height: Int, val width: Int, val source: String, val type: String)
|
||||
|
||||
/**
|
||||
* up next & watchlist data classes
|
||||
*/
|
||||
|
||||
typealias Watchlist = CollectionV2<WatchlistItem>
|
||||
typealias HistoryList = CollectionV2<UpNextAccountItem>
|
||||
typealias UpNextSeriesList = CollectionV2<UpNextSeriesItem>
|
||||
|
||||
@Serializable
|
||||
data class WatchlistItem(
|
||||
@SerialName("panel") val panel: EpisodePanel,
|
||||
@SerialName("new") val new: Boolean,
|
||||
@SerialName("playhead") val playhead: Int,
|
||||
@SerialName("fully_watched") val fullyWatched: Boolean = false,
|
||||
@SerialName("never_watched") val neverWatched: Boolean = false,
|
||||
@SerialName("is_favorite") val isFavorite: Boolean,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class IsWatchlistItem(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("is_favorite") val isFavorite: Boolean,
|
||||
@SerialName("date_added") val dateAdded: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class UpNextAccountItem(
|
||||
@SerialName("panel") val panel: EpisodePanel,
|
||||
@SerialName("new") val new: Boolean,
|
||||
@SerialName("playhead") val playhead: Int,
|
||||
@SerialName("fully_watched") val fullyWatched: Boolean = false,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class UpNextSeriesItem(
|
||||
@SerialName("panel") val panel: EpisodePanel,
|
||||
@SerialName("playhead") val playhead: Int,
|
||||
@SerialName("fully_watched") val fullyWatched: Boolean,
|
||||
@SerialName("never_watched") val neverWatched: Boolean,
|
||||
|
||||
)
|
||||
|
||||
// EpisodePanel is used in ContinueWatchingItem and UpNextSeriesItem
|
||||
@Serializable
|
||||
data class EpisodePanel(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("type") val type: String,
|
||||
@SerialName("channel_id") val channelId: String,
|
||||
@SerialName("description") val description: String,
|
||||
@SerialName("episode_metadata") val episodeMetadata: EpisodeMetadata,
|
||||
@SerialName("images") val images: Thumbnail,
|
||||
// @SerialName("streams_link") val streamsLink: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EpisodeMetadata(
|
||||
@SerialName("duration_ms") val durationMs: Int,
|
||||
@SerialName("episode_number") val episodeNumber: Int? = null, // default/nullable value since optional
|
||||
@SerialName("season_id") val seasonId: String,
|
||||
@SerialName("season_number") val seasonNumber: Int,
|
||||
@SerialName("season_title") val seasonTitle: String,
|
||||
@SerialName("series_id") val seriesId: String,
|
||||
@SerialName("series_title") val seriesTitle: String,
|
||||
)
|
||||
|
||||
val NoneCollectionV2 = CollectionV2<Item>(0, emptyList())
|
||||
val NoneSearchResult = SearchResult(0, emptyList())
|
||||
val NoneBrowseResult = BrowseResult(0, emptyList())
|
||||
val NoneSimilarToResult = SimilarToResult(0, emptyList())
|
||||
val NoneWatchlist = Watchlist(0, emptyList())
|
||||
val NoneHistoryList = HistoryList(0, emptyList())
|
||||
val NoneUpNextSeriesList = UpNextSeriesList(0, emptyList())
|
||||
val NoneRecommendationsList = RecommendationsList(0, emptyList())
|
||||
val NoneBenefits = Benefits(0, emptyList())
|
||||
|
||||
/**
|
||||
* series data class
|
||||
*/
|
||||
|
||||
typealias Series = CollectionV2<SeriesItem>
|
||||
|
||||
@Serializable
|
||||
data class SeriesItem(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("description") val description: String,
|
||||
@SerialName("images") val images: Images,
|
||||
@SerialName("is_simulcast") val isSimulcast: Boolean,
|
||||
@SerialName("maturity_ratings") val maturityRatings: List<String>,
|
||||
@SerialName("audio_locales") val audioLocales: List<String>,
|
||||
@SerialName("episode_count") val episodeCount: Int
|
||||
)
|
||||
|
||||
val NoneSeriesItem = SeriesItem("", "", "", Images(emptyList(), emptyList()), false, emptyList(), emptyList(), 0)
|
||||
val NoneSeries = Series(1, listOf(NoneSeriesItem))
|
||||
|
||||
/**
|
||||
* Seasons data classes
|
||||
*/
|
||||
@Serializable
|
||||
data class Seasons(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("data") val data: List<Season>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Season(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("slug_title") val slugTitle: String,
|
||||
@SerialName("series_id") val seriesId: String,
|
||||
@SerialName("season_number") val seasonNumber: Int,
|
||||
@SerialName("is_subbed") val isSubbed: Boolean,
|
||||
@SerialName("is_dubbed") val isDubbed: Boolean,
|
||||
)
|
||||
|
||||
val NoneSeasons = Seasons(0, emptyList())
|
||||
val NoneSeason = Season("", "", "", "", 0, isSubbed = false, isDubbed = false)
|
||||
|
||||
|
||||
/**
|
||||
* Episodes data classes
|
||||
*/
|
||||
@Serializable
|
||||
data class Episodes(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("data") val data: List<Episode>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Episode(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("series_id") val seriesId: String,
|
||||
@SerialName("season_title") val seasonTitle: String,
|
||||
@SerialName("season_id") val seasonId: String,
|
||||
@SerialName("season_number") val seasonNumber: Int,
|
||||
@SerialName("episode") val episode: String,
|
||||
@SerialName("episode_number") val episodeNumber: Int? = null,
|
||||
@SerialName("description") val description: String,
|
||||
@SerialName("next_episode_id") val nextEpisodeId: String? = null, // default/nullable value since optional
|
||||
@SerialName("next_episode_title") val nextEpisodeTitle: String? = null, // default/nullable value since optional
|
||||
@SerialName("is_subbed") val isSubbed: Boolean,
|
||||
@SerialName("is_dubbed") val isDubbed: Boolean,
|
||||
@SerialName("images") val images: Thumbnail,
|
||||
@SerialName("duration_ms") val durationMs: Int,
|
||||
@SerialName("versions") val versions: List<Version>? = null,
|
||||
@SerialName("streams_link") val streamsLink: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Thumbnail(
|
||||
@SerialName("thumbnail") val thumbnail: List<List<Poster>>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Version(
|
||||
@SerialName("audio_locale") val audioLocale: String,
|
||||
@SerialName("guid") val guid: String,
|
||||
@SerialName("is_premium_only") val isPremiumOnly: Boolean,
|
||||
@SerialName("media_guid") val mediaGUID: String,
|
||||
@SerialName("original") val original: Boolean,
|
||||
@SerialName("season_guid") val seasonGUID: String,
|
||||
@SerialName("variant") val variant: String,
|
||||
)
|
||||
|
||||
val NoneEpisodes = Episodes(0, listOf())
|
||||
val NoneEpisode = Episode(
|
||||
id = "",
|
||||
title = "",
|
||||
seriesId = "",
|
||||
seasonId = "",
|
||||
seasonTitle = "",
|
||||
seasonNumber = 0,
|
||||
episode = "",
|
||||
episodeNumber = 0,
|
||||
description = "",
|
||||
nextEpisodeId = "",
|
||||
nextEpisodeTitle = "",
|
||||
isSubbed = false,
|
||||
isDubbed = false,
|
||||
images = Thumbnail(listOf()),
|
||||
durationMs = 0,
|
||||
versions = emptyList(),
|
||||
streamsLink = ""
|
||||
)
|
||||
|
||||
val NoneVersion = Version(
|
||||
audioLocale = "",
|
||||
guid = "",
|
||||
isPremiumOnly = false,
|
||||
mediaGUID = "",
|
||||
original = true,
|
||||
seasonGUID = "",
|
||||
variant = ""
|
||||
)
|
||||
|
||||
typealias Playheads = CollectionV2<PlayheadObject>
|
||||
|
||||
@Serializable
|
||||
data class PlayheadObject(
|
||||
@SerialName("playhead") val playhead: Int,
|
||||
@SerialName("content_id") val contentId: String,
|
||||
@SerialName("fully_watched") val fullyWatched: Boolean,
|
||||
@SerialName("last_modified") val lastModified: String,
|
||||
)
|
||||
|
||||
val NonePlayheads = Playheads(0, emptyList())
|
||||
|
||||
/**
|
||||
* Meta data for a episode intro. All time values are in seconds.
|
||||
*/
|
||||
@Serializable
|
||||
data class DatalabIntro(
|
||||
@SerialName("media_id") val mediaId: String,
|
||||
@SerialName("startTime") val startTime: Float,
|
||||
@SerialName("endTime") val endTime: Float,
|
||||
@SerialName("duration") val duration: Float,
|
||||
@SerialName("comparedWith") val comparedWith: String,
|
||||
@SerialName("ordering") val ordering: String,
|
||||
@SerialName("last_updated") val lastUpdated: String,
|
||||
)
|
||||
|
||||
val NoneDatalabIntro = DatalabIntro("", 0f, 0f, 0f, "", "", "")
|
||||
|
||||
/**
|
||||
* playback/stream data classes
|
||||
*/
|
||||
@Serializable
|
||||
data class Streams(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("data") val data: List<StreamList>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class StreamList(
|
||||
@SerialName("adaptive_dash") val adaptive_dash: Map<String, Stream>,
|
||||
@SerialName("adaptive_hls") val adaptive_hls: Map<String, Stream>,
|
||||
@SerialName("download_dash") val downloadDash: Map<String, Stream>,
|
||||
@SerialName("download_hls") val download_hls: Map<String, Stream>,
|
||||
// @SerialName("drm_adaptive_dash") val drmAdaptiveDash: Map<String, Stream>,
|
||||
// @SerialName("drm_adaptive_hls") val drmAdaptiveHls: Map<String, Stream>,
|
||||
// @SerialName("drm_download_dash") val drmDownloadDash: Map<String, Stream>,
|
||||
// @SerialName("drm_download_hls") val drmDownloadHls: Map<String, Stream>,
|
||||
// @SerialName("vo_adaptive_dash") val vo_adaptive_dash: Map<String, Stream>,
|
||||
// @SerialName("vo_adaptive_hls") val vo_adaptive_hls: Map<String, Stream>,
|
||||
// @SerialName("vo_drm_adaptive_dash") val vo_drm_adaptive_dash: Map<String, Stream>,
|
||||
// @SerialName("vo_drm_adaptive_hls") val vo_drm_adaptive_hls: Map<String, Stream>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Stream(
|
||||
@SerialName("hardsub_locale") val hardsubLocale: String = "", // default/nullable value since might be optional
|
||||
@SerialName("url") val url: String = "", // default/nullable value since optional
|
||||
@SerialName("vcodec") val vcodec: String = "", // default/nullable value since optional
|
||||
)
|
||||
|
||||
val NoneStreams = Streams(
|
||||
0,
|
||||
arrayListOf(StreamList(
|
||||
mapOf(), mapOf(), mapOf(), mapOf()
|
||||
))
|
||||
)
|
||||
|
||||
/**
|
||||
* profile data class
|
||||
*/
|
||||
@Serializable
|
||||
data class Profile(
|
||||
@SerialName("avatar") val avatar: String,
|
||||
@SerialName("email") val email: String,
|
||||
@SerialName("maturity_rating") val maturityRating: String,
|
||||
@SerialName("preferred_content_audio_language") val preferredContentAudioLanguage: String,
|
||||
@SerialName("preferred_content_subtitle_language") val preferredContentSubtitleLanguage: String,
|
||||
@SerialName("username") val username: String,
|
||||
)
|
||||
val NoneProfile = Profile(
|
||||
avatar = "",
|
||||
email = "",
|
||||
maturityRating = "",
|
||||
preferredContentAudioLanguage = "",
|
||||
preferredContentSubtitleLanguage = "",
|
||||
username = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* benefit data class
|
||||
*/
|
||||
@Serializable
|
||||
data class Benefit(
|
||||
@SerialName("benefit") val benefit: String,
|
||||
@SerialName("source") val source: String,
|
||||
)
|
||||
@Suppress("unused")
|
||||
val NoneBenefit = Benefit(
|
||||
benefit = "",
|
||||
source = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* search result typed list data class
|
||||
*/
|
||||
@Serializable
|
||||
data class SearchTypedList<T>(
|
||||
@SerialName("type") val type: String,
|
||||
@SerialName("count") val count: Int,
|
||||
@SerialName("items") val items: List<T>
|
||||
)
|
@ -1,22 +1,122 @@
|
||||
package org.mosad.teapod.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import java.util.*
|
||||
|
||||
object Preferences {
|
||||
|
||||
var login = ""
|
||||
var preferredAudioLocale: Locale = Locale.forLanguageTag("en-US")
|
||||
internal set
|
||||
var password = ""
|
||||
var preferredSubtitleLocale: Locale = Locale.forLanguageTag("en-US")
|
||||
internal set
|
||||
var autoplay = true
|
||||
internal set
|
||||
var devSettings = false
|
||||
internal set
|
||||
var theme = DataTypes.Theme.SYSTEM
|
||||
internal set
|
||||
|
||||
// dev settings
|
||||
var updatePlayhead = true
|
||||
internal set
|
||||
|
||||
fun saveCredentials(login: String, password: String) {
|
||||
this.login = login
|
||||
this.password = password
|
||||
|
||||
// TODO save
|
||||
private fun getSharedPref(context: Context): SharedPreferences {
|
||||
return context.getSharedPreferences(
|
||||
context.getString(R.string.preference_file_key),
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
}
|
||||
|
||||
fun load() {
|
||||
// TODO
|
||||
fun savePreferredAudioLocal(context: Context, preferredLocale: Locale) {
|
||||
with(getSharedPref(context).edit()) {
|
||||
putString(context.getString(R.string.save_key_preferred_local), preferredLocale.toLanguageTag())
|
||||
apply()
|
||||
}
|
||||
|
||||
this.preferredAudioLocale = preferredLocale
|
||||
}
|
||||
|
||||
fun savePreferredSubtitleLocal(context: Context, preferredLocale: Locale) {
|
||||
with(getSharedPref(context).edit()) {
|
||||
putString(context.getString(R.string.save_key_preferred_local), preferredLocale.toLanguageTag())
|
||||
apply()
|
||||
}
|
||||
|
||||
this.preferredSubtitleLocale = preferredLocale
|
||||
}
|
||||
|
||||
fun saveAutoplay(context: Context, autoplay: Boolean) {
|
||||
with(getSharedPref(context).edit()) {
|
||||
putBoolean(context.getString(R.string.save_key_autoplay), autoplay)
|
||||
apply()
|
||||
}
|
||||
|
||||
this.autoplay = autoplay
|
||||
}
|
||||
|
||||
fun saveDevSettings(context: Context, devSettings: Boolean) {
|
||||
with(getSharedPref(context).edit()) {
|
||||
putBoolean(context.getString(R.string.save_key_dev_settings), devSettings)
|
||||
apply()
|
||||
}
|
||||
|
||||
this.devSettings = devSettings
|
||||
}
|
||||
|
||||
fun saveTheme(context: Context, theme: DataTypes.Theme) {
|
||||
with(getSharedPref(context).edit()) {
|
||||
putString(context.getString(R.string.save_key_theme), theme.toString())
|
||||
apply()
|
||||
}
|
||||
|
||||
this.theme = theme
|
||||
}
|
||||
|
||||
fun saveUpdatePlayhead(context: Context, updatePlayhead: Boolean) {
|
||||
with(getSharedPref(context).edit()) {
|
||||
putBoolean(context.getString(R.string.save_key_update_playhead), updatePlayhead)
|
||||
apply()
|
||||
}
|
||||
|
||||
this.updatePlayhead = updatePlayhead
|
||||
}
|
||||
|
||||
/**
|
||||
* initially load the stored values
|
||||
*/
|
||||
fun load(context: Context) {
|
||||
val sharedPref = getSharedPref(context)
|
||||
|
||||
preferredAudioLocale = Locale.forLanguageTag(
|
||||
sharedPref.getString(
|
||||
context.getString(R.string.save_key_preferred_audio_local), "en-US"
|
||||
) ?: "en-US"
|
||||
)
|
||||
preferredSubtitleLocale = Locale.forLanguageTag(
|
||||
sharedPref.getString(
|
||||
context.getString(R.string.save_key_preferred_local), "en-US"
|
||||
) ?: "en-US"
|
||||
)
|
||||
autoplay = sharedPref.getBoolean(
|
||||
context.getString(R.string.save_key_autoplay), true
|
||||
)
|
||||
devSettings = sharedPref.getBoolean(
|
||||
context.getString(R.string.save_key_dev_settings), false
|
||||
)
|
||||
theme = DataTypes.Theme.valueOf(
|
||||
sharedPref.getString(
|
||||
context.getString(R.string.save_key_theme), DataTypes.Theme.SYSTEM.toString()
|
||||
) ?: DataTypes.Theme.SYSTEM.toString()
|
||||
)
|
||||
|
||||
// dev settings
|
||||
updatePlayhead = sharedPref.getBoolean(
|
||||
context.getString(R.string.save_key_update_playhead), true
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.activity.main
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.commit
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ActivityMainBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.ui.activity.main.fragments.AccountFragment
|
||||
import org.mosad.teapod.ui.activity.main.fragments.HomeFragment
|
||||
import org.mosad.teapod.ui.activity.main.fragments.MyListsFragment
|
||||
import org.mosad.teapod.ui.activity.main.fragments.LibraryFragment
|
||||
import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.metadb.MetaDBController
|
||||
import java.util.*
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListener {
|
||||
private val classTag = javaClass.name
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private var activeBaseFragment: Fragment = HomeFragment() // the currently active fragment, home at the start
|
||||
|
||||
companion object {
|
||||
lateinit var instance: MainActivity
|
||||
}
|
||||
|
||||
init {
|
||||
instance = this
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// Handle the splash screen transition.
|
||||
installSplashScreen()
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
load() // start the initial loading
|
||||
|
||||
// theming
|
||||
val mode = when (Preferences.theme) {
|
||||
DataTypes.Theme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
DataTypes.Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
AppCompatDelegate.setDefaultNightMode(mode)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
binding.navView.setOnItemSelectedListener(this)
|
||||
setContentView(binding.root)
|
||||
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.nav_host_fragment, activeBaseFragment, activeBaseFragment.javaClass.simpleName)
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback {
|
||||
if (supportFragmentManager.backStackEntryCount > 0) {
|
||||
supportFragmentManager.popBackStack()
|
||||
} else {
|
||||
if (activeBaseFragment !is HomeFragment) {
|
||||
binding.navView.selectedItemId = R.id.navigation_home
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNavigationItemSelected(item: MenuItem): Boolean {
|
||||
if (supportFragmentManager.backStackEntryCount > 0) {
|
||||
supportFragmentManager.popBackStack()
|
||||
}
|
||||
|
||||
val ret = when (item.itemId) {
|
||||
R.id.navigation_home -> {
|
||||
activeBaseFragment = HomeFragment()
|
||||
true
|
||||
}
|
||||
R.id.navigation_my_lists -> {
|
||||
activeBaseFragment = MyListsFragment()
|
||||
true
|
||||
}
|
||||
R.id.navigation_library -> {
|
||||
activeBaseFragment = LibraryFragment()
|
||||
true
|
||||
}
|
||||
R.id.navigation_account -> {
|
||||
activeBaseFragment = AccountFragment()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.nav_host_fragment, activeBaseFragment, activeBaseFragment.javaClass.simpleName)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// private fun getThemeResource(): Int {
|
||||
// return when (Preferences.theme) {
|
||||
// DataTypes.Theme.LIGHT -> R.style.AppTheme_Light
|
||||
// else -> R.style.AppTheme_Dark
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* initial loading and login are run in parallel, as initial loading doesn't require
|
||||
* any login cookies
|
||||
*/
|
||||
private fun load() {
|
||||
val time = measureTimeMillis {
|
||||
// load all saved stuff here
|
||||
Preferences.load(this)
|
||||
EncryptedPreferences.readCredentials(this)
|
||||
|
||||
// load meta db at the start, it doesn't depend on any third party
|
||||
val metaJob = initMetaDB()
|
||||
|
||||
// always initialize the api token
|
||||
Crunchyroll.initBasicApiToken()
|
||||
|
||||
// show onboarding if no password is set, or login fails
|
||||
if (EncryptedPreferences.password.isEmpty() || !Crunchyroll.login(
|
||||
EncryptedPreferences.login,
|
||||
EncryptedPreferences.password
|
||||
)
|
||||
) {
|
||||
showOnboarding()
|
||||
} else {
|
||||
runBlocking {
|
||||
initCrunchyroll().joinAll()
|
||||
metaJob.join() // meta loading should be done here
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i(classTag, "loading in $time ms")
|
||||
}
|
||||
|
||||
private fun initCrunchyroll(): List<Job> {
|
||||
val scope = CoroutineScope(Dispatchers.IO + CoroutineName("InitialCrunchyLoading"))
|
||||
return listOf(
|
||||
scope.launch { Crunchyroll.account() },
|
||||
scope.launch {
|
||||
// update the local preferred content language, since it may have changed
|
||||
val profile = Crunchyroll.profile()
|
||||
|
||||
val audioLocale = Locale.forLanguageTag(profile.preferredContentAudioLanguage)
|
||||
val subtitleLocale = Locale.forLanguageTag(profile.preferredContentSubtitleLanguage)
|
||||
Preferences.savePreferredAudioLocal(this@MainActivity, audioLocale)
|
||||
Preferences.savePreferredSubtitleLocal(this@MainActivity, subtitleLocale)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun initMetaDB(): Job {
|
||||
val scope = CoroutineScope(Dispatchers.IO + CoroutineName("InitialMetaDBLoading"))
|
||||
return scope.launch { MetaDBController.list() }
|
||||
}
|
||||
|
||||
/**
|
||||
* start the onboarding activity and finish the main activity
|
||||
*/
|
||||
private fun showOnboarding() {
|
||||
startActivity(Intent(this, OnboardingActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
||||
/**
|
||||
* use custom restart instead of recreate(), since it has animations
|
||||
*/
|
||||
fun restart() {
|
||||
val restartIntent = intent
|
||||
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||
finish()
|
||||
startActivity(restartIntent)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RawRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentAboutBinding
|
||||
import org.mosad.teapod.databinding.ItemComponentBinding
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.DataTypes.License
|
||||
import org.mosad.teapod.util.ThirdPartyComponent
|
||||
import java.lang.StringBuilder
|
||||
import java.util.Timer
|
||||
import kotlin.concurrent.schedule
|
||||
|
||||
class AboutFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentAboutBinding
|
||||
|
||||
private val teapodRepoUrl = "https://git.mosad.xyz/Seil0/teapod"
|
||||
private val devClickMax = 5
|
||||
private var devClickCount = 0
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentAboutBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.textVersionDesc.text = getString(R.string.version_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
|
||||
|
||||
getThirdPartyComponents().forEach { thirdParty ->
|
||||
val componentBinding = ItemComponentBinding.inflate(layoutInflater) //(R.layout.item_component, container, false)
|
||||
componentBinding.textComponentTitle.text = thirdParty.name
|
||||
componentBinding.textComponentDesc.text = getString(
|
||||
R.string.third_party_component_desc,
|
||||
thirdParty.year,
|
||||
thirdParty.copyrightOwner,
|
||||
thirdParty.license.short
|
||||
)
|
||||
componentBinding.linearComponent.setOnClickListener {
|
||||
showLicense(thirdParty.license)
|
||||
}
|
||||
|
||||
binding.linearThirdParty.addView(componentBinding.root)
|
||||
}
|
||||
|
||||
initActions()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
binding.imageAppIcon.setOnClickListener {
|
||||
checkDevSettings()
|
||||
}
|
||||
|
||||
binding.linearSource.setOnClickListener {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(teapodRepoUrl)))
|
||||
}
|
||||
|
||||
binding.linearLicense.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(License.GPL3.long)
|
||||
.setMessage(parseLicense(R.raw.gpl_3_full))
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if dev settings shall be enabled
|
||||
*/
|
||||
private fun checkDevSettings() {
|
||||
// if the dev settings are already enabled show a toast
|
||||
if (Preferences.devSettings) {
|
||||
Toast.makeText(context, getString(R.string.dev_settings_already), Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
|
||||
// reset dev settings count after 5 seconds
|
||||
if (devClickCount == 0) {
|
||||
Timer("", false).schedule(5000) {
|
||||
devClickCount = 0
|
||||
}
|
||||
}
|
||||
devClickCount++
|
||||
|
||||
if (devClickCount == devClickMax) {
|
||||
Preferences.saveDevSettings(requireContext(), true)
|
||||
Toast.makeText(context, getString(R.string.dev_settings_enabled), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getThirdPartyComponents(): List<ThirdPartyComponent> {
|
||||
return listOf(
|
||||
ThirdPartyComponent("AndroidX", "", "The Android Open Source Project",
|
||||
"https://developer.android.com/jetpack/androidx", License.APACHE2),
|
||||
ThirdPartyComponent("Material Components for Android", "2020", "The Android Open Source Project",
|
||||
"https://github.com/material-components/material-components-android", License.APACHE2),
|
||||
ThirdPartyComponent("ExoPlayer", "2014 - 2020", "The Android Open Source Project",
|
||||
"https://github.com/google/ExoPlayer", License.APACHE2),
|
||||
ThirdPartyComponent("Material design icons", "2020", "Google Inc.",
|
||||
"https://github.com/google/material-design-icons", License.APACHE2),
|
||||
ThirdPartyComponent("Ktor", "2014-2021", "JetBrains s.r.o and contributors",
|
||||
"https://ktor.io/", License.APACHE2),
|
||||
ThirdPartyComponent("kotlinx.coroutines", "2016-2021", "JetBrains s.r.o",
|
||||
"https://github.com/Kotlin/kotlinx.coroutines", License.APACHE2),
|
||||
ThirdPartyComponent(" kotlinx.serialization", "2017-2021", "JetBrains s.r.o",
|
||||
"https://github.com/Kotlin/kotlinx.serialization", License.APACHE2),
|
||||
ThirdPartyComponent("Glide", "2014", "Google Inc.",
|
||||
"https://github.com/bumptech/glide", License.BSD2),
|
||||
ThirdPartyComponent("Glide Transformations", "2020", "Wasabeef",
|
||||
"https://github.com/wasabeef/glide-transformations", License.APACHE2)
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLicense(license: License) {
|
||||
val licenseText = when(license) {
|
||||
License.APACHE2 -> parseLicense(R.raw.al_20_full)
|
||||
License.BSD2 -> parseLicense(R.raw.bsd_2_full)
|
||||
License.GPL3 -> parseLicense(R.raw.gpl_3_full)
|
||||
License.MIT -> parseLicense(R.raw.mit_full)
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(license.long)
|
||||
.setMessage(licenseText)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun parseLicense(@RawRes id: Int): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
resources.openRawResource(id).bufferedReader().forEachLine {
|
||||
if (it.isEmpty()) {
|
||||
sb.appendLine(" ")
|
||||
} else {
|
||||
sb.append(it.trim() + " ")
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentAccountBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.Benefits
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.parser.crunchyroll.Profile
|
||||
import org.mosad.teapod.parser.crunchyroll.supportedAudioLocals
|
||||
import org.mosad.teapod.parser.crunchyroll.supportedSubtitleLocals
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
||||
import org.mosad.teapod.ui.components.LoginModalBottomSheet
|
||||
import org.mosad.teapod.util.DataTypes.Theme
|
||||
import org.mosad.teapod.util.showFragment
|
||||
import org.mosad.teapod.util.toDisplayString
|
||||
import java.util.*
|
||||
|
||||
class AccountFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentAccountBinding
|
||||
private var profile: Deferred<Profile> = lifecycleScope.async {
|
||||
Crunchyroll.profile()
|
||||
}
|
||||
private var benefits: Deferred<Benefits> = lifecycleScope.async {
|
||||
Crunchyroll.benefits()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentAccountBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.textAccountLogin.text = EncryptedPreferences.login
|
||||
|
||||
// load account status and tier (async) info before anything else
|
||||
lifecycleScope.launch {
|
||||
benefits.await().apply {
|
||||
this.items.firstOrNull { it.benefit == "cr_premium" }?.let {
|
||||
binding.textAccountSubscription.text = getString(R.string.account_premium)
|
||||
}
|
||||
|
||||
this.items.firstOrNull { it.benefit == "cr_fan_pack" }?.let {
|
||||
binding.textAccountSubscriptionDesc.text =
|
||||
getString(R.string.account_tier, getString(R.string.account_tier_mega_fan))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add preferred subtitles
|
||||
lifecycleScope.launch {
|
||||
binding.textSettingsAudioLanguageDesc.text = Locale.forLanguageTag(
|
||||
profile.await().preferredContentAudioLanguage
|
||||
).displayLanguage
|
||||
binding.textSettingsSubtitleLanguageDesc.text = Locale.forLanguageTag(
|
||||
profile.await().preferredContentSubtitleLanguage
|
||||
).displayLanguage
|
||||
}
|
||||
binding.switchAutoplay.isChecked = Preferences.autoplay
|
||||
binding.textThemeSelected.text = when (Preferences.theme) {
|
||||
Theme.SYSTEM -> getString(R.string.theme_system)
|
||||
Theme.LIGHT -> getString(R.string.theme_light)
|
||||
Theme.DARK -> getString(R.string.theme_dark)
|
||||
}
|
||||
|
||||
binding.linearDevSettings.isVisible = Preferences.devSettings
|
||||
binding.switchUpdatePlayhead.isChecked = Preferences.updatePlayhead
|
||||
|
||||
binding.textInfoAboutDesc.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
|
||||
|
||||
initActions()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
binding.linearAccountLogin.setOnClickListener {
|
||||
showLoginDialog()
|
||||
}
|
||||
|
||||
binding.linearSettingsAudioLanguage.setOnClickListener {
|
||||
showAudioLanguageSelection()
|
||||
}
|
||||
|
||||
binding.linearSettingsSubtitleLanguage.setOnClickListener {
|
||||
showSubtitleLanguageSelection()
|
||||
}
|
||||
|
||||
binding.switchAutoplay.setOnClickListener {
|
||||
Preferences.saveAutoplay(requireContext(), binding.switchAutoplay.isChecked)
|
||||
}
|
||||
|
||||
binding.linearTheme.setOnClickListener {
|
||||
showThemeDialog()
|
||||
}
|
||||
|
||||
binding.linearInfo.setOnClickListener {
|
||||
activity?.showFragment(AboutFragment())
|
||||
}
|
||||
|
||||
binding.switchUpdatePlayhead.setOnClickListener {
|
||||
Preferences.saveUpdatePlayhead(requireContext(), binding.switchUpdatePlayhead.isChecked)
|
||||
}
|
||||
|
||||
binding.linearExportData.setOnClickListener {
|
||||
// unused
|
||||
}
|
||||
|
||||
binding.linearImportData.setOnClickListener {
|
||||
// unused
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLoginDialog() {
|
||||
val loginModal = LoginModalBottomSheet().apply {
|
||||
login = EncryptedPreferences.login
|
||||
password = ""
|
||||
positiveAction = {
|
||||
EncryptedPreferences.saveCredentials(login, password, requireContext())
|
||||
|
||||
// TODO only dismiss if login was successful
|
||||
this.dismiss()
|
||||
}
|
||||
negativeAction = {
|
||||
this.dismiss()
|
||||
}
|
||||
}
|
||||
activity?.let { loginModal.show(it.supportFragmentManager, LoginModalBottomSheet.TAG) }
|
||||
}
|
||||
|
||||
private fun showAudioLanguageSelection() {
|
||||
// we should be able to use the index of supportedLocals for language selection, items is GUI only
|
||||
val items = supportedAudioLocals.map {
|
||||
it.toDisplayString(getString(R.string.settings_content_language_none))
|
||||
}.toTypedArray()
|
||||
|
||||
var initialSelection: Int
|
||||
// profile should be completed here, therefore blocking
|
||||
runBlocking {
|
||||
initialSelection = supportedAudioLocals.indexOf(Locale.forLanguageTag(
|
||||
profile.await().preferredContentAudioLanguage))
|
||||
if (initialSelection < 0) initialSelection = supportedAudioLocals.lastIndex
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.settings_audio_language)
|
||||
.setSingleChoiceItems(items, initialSelection){ dialog, which ->
|
||||
updateAudioLanguage(supportedAudioLocals[which])
|
||||
dialog.dismiss()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun showSubtitleLanguageSelection() {
|
||||
// we should be able to use the index of supportedLocals for language selection, items is GUI only
|
||||
val items = supportedSubtitleLocals.map {
|
||||
it.toDisplayString(getString(R.string.settings_content_language_none))
|
||||
}.toTypedArray()
|
||||
|
||||
var initialSelection: Int
|
||||
// profile should be completed here, therefore blocking
|
||||
runBlocking {
|
||||
initialSelection = supportedSubtitleLocals.indexOf(Locale.forLanguageTag(
|
||||
profile.await().preferredContentSubtitleLanguage))
|
||||
if (initialSelection < 0) initialSelection = supportedSubtitleLocals.lastIndex
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.settings_audio_language)
|
||||
.setSingleChoiceItems(items, initialSelection){ dialog, which ->
|
||||
updateSubtitleLanguage(supportedSubtitleLocals[which])
|
||||
dialog.dismiss()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun updateAudioLanguage(preferredLocale: Locale) {
|
||||
lifecycleScope.launch {
|
||||
Crunchyroll.setPreferredAudioLanguage(preferredLocale.toLanguageTag())
|
||||
|
||||
}.invokeOnCompletion {
|
||||
// update the local preferred audio language
|
||||
Preferences.savePreferredAudioLocal(requireContext(), preferredLocale)
|
||||
|
||||
// update profile since the language selection might have changed
|
||||
profile = lifecycleScope.async { Crunchyroll.profile() }
|
||||
profile.invokeOnCompletion {
|
||||
// update language once loading profile is completed
|
||||
binding.textSettingsAudioLanguageDesc.text = Locale.forLanguageTag(
|
||||
profile.getCompleted().preferredContentAudioLanguage
|
||||
).displayLanguage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun updateSubtitleLanguage(preferredLocal: Locale) {
|
||||
lifecycleScope.launch {
|
||||
Crunchyroll.setPreferredSubtitleLanguage(preferredLocal.toLanguageTag())
|
||||
|
||||
}.invokeOnCompletion {
|
||||
// update the local preferred subtitle language
|
||||
Preferences.savePreferredSubtitleLocal(requireContext(), preferredLocal)
|
||||
|
||||
// update profile since the language selection might have changed
|
||||
profile = lifecycleScope.async { Crunchyroll.profile() }
|
||||
profile.invokeOnCompletion {
|
||||
// update language once loading profile is completed
|
||||
binding.textSettingsAudioLanguageDesc.text = Locale.forLanguageTag(
|
||||
profile.getCompleted().preferredContentSubtitleLanguage
|
||||
).displayLanguage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showThemeDialog() {
|
||||
val items = arrayOf(
|
||||
resources.getString(R.string.theme_system),
|
||||
resources.getString(R.string.theme_light),
|
||||
resources.getString(R.string.theme_dark)
|
||||
)
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.theme)
|
||||
.setSingleChoiceItems(items, Preferences.theme.ordinal){ _, which ->
|
||||
when(which) {
|
||||
0 -> Preferences.saveTheme(requireContext(), Theme.SYSTEM)
|
||||
1 -> Preferences.saveTheme(requireContext(), Theme.LIGHT)
|
||||
2 -> Preferences.saveTheme(requireContext(), Theme.DARK)
|
||||
else -> Preferences.saveTheme(requireContext(), Theme.SYSTEM)
|
||||
}
|
||||
|
||||
(activity as MainActivity).restart()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.bumptech.glide.Glide
|
||||
import com.facebook.shimmer.ShimmerFrameLayout
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentHomeBinding
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.HomeViewModel
|
||||
import org.mosad.teapod.util.adapter.MediaEpisodeListAdapter
|
||||
import org.mosad.teapod.util.adapter.MediaItemListAdapter
|
||||
import org.mosad.teapod.util.playerIntent
|
||||
import org.mosad.teapod.util.setDrawableTop
|
||||
import org.mosad.teapod.util.showFragment
|
||||
import org.mosad.teapod.util.toItemMediaList
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private val classTag = javaClass.name
|
||||
private val model: HomeViewModel by viewModels()
|
||||
private lateinit var binding: FragmentHomeBinding
|
||||
|
||||
private val itemOffset = 21
|
||||
|
||||
private val playerResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
model.updateUpNextItems()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.recyclerUpNext.adapter = MediaEpisodeListAdapter(
|
||||
MediaEpisodeListAdapter.OnClickListener {
|
||||
playerResult.launch(playerIntent(it.panel.episodeMetadata.seasonId, it.panel.id))
|
||||
},
|
||||
itemOffset
|
||||
)
|
||||
|
||||
binding.recyclerWatchlist.adapter = MediaItemListAdapter(
|
||||
MediaItemListAdapter.OnClickListener {
|
||||
activity?.showFragment(MediaFragment(it.id))
|
||||
},
|
||||
itemOffset
|
||||
)
|
||||
|
||||
binding.recyclerRecommendations.adapter = MediaItemListAdapter(
|
||||
MediaItemListAdapter.OnClickListener {
|
||||
activity?.showFragment(MediaFragment(it.id))
|
||||
},
|
||||
itemOffset
|
||||
)
|
||||
|
||||
binding.recyclerNewTitles.adapter = MediaItemListAdapter(
|
||||
MediaItemListAdapter.OnClickListener {
|
||||
activity?.showFragment(MediaFragment(it.id))
|
||||
},
|
||||
itemOffset
|
||||
)
|
||||
|
||||
binding.recyclerTopTen.adapter = MediaItemListAdapter(
|
||||
MediaItemListAdapter.OnClickListener {
|
||||
activity?.showFragment(MediaFragment(it.id))
|
||||
},
|
||||
itemOffset
|
||||
)
|
||||
|
||||
binding.textHighlightMyList.setOnClickListener {
|
||||
model.toggleHighlightWatchlist()
|
||||
|
||||
// disable the watchlist button until the result has been loaded
|
||||
binding.textHighlightMyList.isClickable = false
|
||||
// TODO since this might take a few seconds show a loading animation for the watchlist button
|
||||
}
|
||||
|
||||
// set the shimmer items size as it's depending on the screen size
|
||||
setShimmerLayoutItemSize(binding.shimmerLayoutUpNext)
|
||||
setShimmerLayoutItemSize(binding.shimmerLayoutWatchlist)
|
||||
setShimmerLayoutItemSize(binding.shimmerLayoutRecommendations)
|
||||
setShimmerLayoutItemSize(binding.shimmerLayoutNewTitles)
|
||||
setShimmerLayoutItemSize(binding.shimmerLayoutTopTen)
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
model.onUiState(viewLifecycleOwner.lifecycleScope) { uiState ->
|
||||
when (uiState) {
|
||||
is HomeViewModel.UiState.Normal -> bindUiStateNormal(uiState)
|
||||
is HomeViewModel.UiState.Loading -> bindUiStateLoading()
|
||||
is HomeViewModel.UiState.Error -> bindUiStateError(uiState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindUiStateNormal(uiState: HomeViewModel.UiState.Normal) {
|
||||
val adapterUpNext = binding.recyclerUpNext.adapter as MediaEpisodeListAdapter
|
||||
adapterUpNext.submitList(uiState.upNextItems.filter { !it.fullyWatched })
|
||||
|
||||
val adapterWatchlist = binding.recyclerWatchlist.adapter as MediaItemListAdapter
|
||||
adapterWatchlist.submitList(uiState.watchlistItems.toItemMediaList())
|
||||
|
||||
val adapterRecommendations = binding.recyclerRecommendations.adapter as MediaItemListAdapter
|
||||
adapterRecommendations.submitList(uiState.recommendationsItems.toItemMediaList())
|
||||
|
||||
val adapterNewTitles = binding.recyclerNewTitles.adapter as MediaItemListAdapter
|
||||
adapterNewTitles.submitList(uiState.recentlyAddedItems.toItemMediaList())
|
||||
|
||||
val adapterTopTen = binding.recyclerTopTen.adapter as MediaItemListAdapter
|
||||
adapterTopTen.submitList(uiState.topTenItems.toItemMediaList())
|
||||
|
||||
// highlight item
|
||||
binding.textHighlightTitle.text = uiState.highlightItem.title
|
||||
Glide.with(requireContext()).load(uiState.highlightItem.images.poster_wide[0][3].source)
|
||||
.into(binding.imageHighlight)
|
||||
|
||||
val iconHighlightWatchlist = if (uiState.highlightIsWatchlist) {
|
||||
R.drawable.ic_baseline_check_24
|
||||
} else {
|
||||
R.drawable.ic_baseline_add_24
|
||||
}
|
||||
binding.textHighlightMyList.setDrawableTop(iconHighlightWatchlist)
|
||||
binding.textHighlightMyList.isClickable = true
|
||||
|
||||
binding.textHighlightInfo.setOnClickListener {
|
||||
activity?.showFragment(MediaFragment(uiState.highlightItem.id))
|
||||
}
|
||||
|
||||
binding.buttonPlayHighlight.setOnClickListener {
|
||||
val panel = uiState.highlightItemUpNext.panel
|
||||
playerResult.launch(playerIntent(panel.episodeMetadata.seasonId, panel.id))
|
||||
}
|
||||
|
||||
// disable the shimmer effect
|
||||
disableShimmer()
|
||||
|
||||
// make highlights layout visible again
|
||||
binding.linearHighlight.isVisible = true
|
||||
}
|
||||
|
||||
private fun bindUiStateLoading() {
|
||||
// hide highlights layout
|
||||
binding.linearHighlight.isVisible = false
|
||||
|
||||
binding.shimmerLayoutUpNext.startShimmer()
|
||||
binding.shimmerLayoutWatchlist.startShimmer()
|
||||
binding.shimmerLayoutRecommendations.startShimmer()
|
||||
binding.shimmerLayoutNewTitles.startShimmer()
|
||||
binding.shimmerLayoutTopTen.startShimmer()
|
||||
}
|
||||
|
||||
private fun setShimmerLayoutItemSize(shimmerLayout: ShimmerFrameLayout) {
|
||||
(shimmerLayout.children.first() as? LinearLayout)?.children?.forEach { child ->
|
||||
child.layoutParams.apply {
|
||||
width = (resources.displayMetrics.widthPixels / requireContext().resources.getInteger(R.integer.item_media_columns)) - itemOffset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindUiStateError(uiState: HomeViewModel.UiState.Error) {
|
||||
// currently not used
|
||||
Log.e(classTag, "A error occurred while loading a UiState: ${uiState.message}")
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the shimmer effect for all shimmer layouts and hide them.
|
||||
*/
|
||||
private fun disableShimmer() {
|
||||
binding.shimmerLayoutHighlight.apply {
|
||||
stopShimmer()
|
||||
isVisible = false
|
||||
}
|
||||
binding.shimmerLayoutUpNext.apply {
|
||||
stopShimmer()
|
||||
isVisible = false
|
||||
}
|
||||
binding.shimmerLayoutWatchlist.apply {
|
||||
stopShimmer()
|
||||
isVisible = false
|
||||
}
|
||||
binding.shimmerLayoutRecommendations.apply {
|
||||
stopShimmer()
|
||||
isVisible = false
|
||||
}
|
||||
binding.shimmerLayoutNewTitles.apply {
|
||||
stopShimmer()
|
||||
isVisible = false
|
||||
}
|
||||
binding.shimmerLayoutTopTen.apply {
|
||||
stopShimmer()
|
||||
isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.databinding.FragmentLibraryBinding
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.LibraryFragmentViewModel
|
||||
import org.mosad.teapod.util.adapter.MediaItemListAdapter
|
||||
import org.mosad.teapod.util.showFragment
|
||||
|
||||
class LibraryFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentLibraryBinding
|
||||
private lateinit var adapter: MediaItemListAdapter
|
||||
private val model: LibraryFragmentViewModel by viewModels()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentLibraryBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// TODO replace with pagination3
|
||||
// https://medium.com/swlh/paging3-recyclerview-pagination-made-easy-333c7dfa8797
|
||||
binding.recyclerMediaSearch.addOnScrollListener(PaginationScrollListener())
|
||||
|
||||
adapter = MediaItemListAdapter(MediaItemListAdapter.OnClickListener {
|
||||
binding.searchText.clearFocus()
|
||||
activity?.showFragment(MediaFragment(it.id))
|
||||
})
|
||||
binding.recyclerMediaSearch.adapter = adapter
|
||||
|
||||
binding.searchText.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
query?.let { model.search(it) }
|
||||
return false // return false to dismiss the keyboard
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
newText?.let { model.search(it) }
|
||||
return false // return false to dismiss the keyboard
|
||||
}
|
||||
})
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
model.onUiState(viewLifecycleOwner.lifecycleScope) { uiState ->
|
||||
when (uiState) {
|
||||
is LibraryFragmentViewModel.UiState.Browse -> bindUiStateBrowse(uiState)
|
||||
is LibraryFragmentViewModel.UiState.Search -> bindUiStateSearch(uiState)
|
||||
is LibraryFragmentViewModel.UiState.Loading -> bindUiStateLoading()
|
||||
is LibraryFragmentViewModel.UiState.Error -> bindUiStateError(uiState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindUiStateBrowse(uiState: LibraryFragmentViewModel.UiState.Browse) {
|
||||
adapter.submitList(uiState.itemList)
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun bindUiStateSearch(uiState: LibraryFragmentViewModel.UiState.Search) {
|
||||
adapter.submitList(uiState.itemList)
|
||||
adapter.notifyDataSetChanged() // this is needed, else the adapter will not update
|
||||
}
|
||||
|
||||
private fun bindUiStateLoading() {
|
||||
// currently not used
|
||||
}
|
||||
|
||||
private fun bindUiStateError(uiState: LibraryFragmentViewModel.UiState.Error) {
|
||||
// currently not used
|
||||
Log.e(javaClass.name, "A error occurred while loading a UiState: ${uiState.message}")
|
||||
}
|
||||
|
||||
inner class PaginationScrollListener: RecyclerView.OnScrollListener() {
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
|
||||
if (!model.isLazyLoading) {
|
||||
val layoutManager = recyclerView.layoutManager as? GridLayoutManager
|
||||
layoutManager?.let {
|
||||
// adapter.itemCount - 10 to start loading a bit earlier than the actual end
|
||||
if (layoutManager.findLastCompletelyVisibleItemPosition() >= (adapter.itemCount - 10)) {
|
||||
model.onLazyLoad().invokeOnCompletion {
|
||||
adapter.notifyItemRangeInserted(adapter.itemCount, model.PAGESIZE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentMediaBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.NoneUpNextSeriesList
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
|
||||
import org.mosad.teapod.util.playerIntent
|
||||
import org.mosad.teapod.util.tmdb.TMDBApiController
|
||||
import org.mosad.teapod.util.tmdb.TMDBMovie
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVShow
|
||||
import org.mosad.teapod.util.toItemMediaList
|
||||
|
||||
/**
|
||||
* The media detail fragment.
|
||||
* Note: the fragment is created only once, when selecting a similar title etc.
|
||||
* therefore fragments may be not empty and model may be the old one
|
||||
*/
|
||||
class MediaFragment(private val mediaIdStr: String) : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMediaBinding
|
||||
private lateinit var pagerAdapter: FragmentStateAdapter
|
||||
|
||||
private val model: MediaFragmentViewModel by viewModels()
|
||||
|
||||
private val fragments = arrayListOf<Fragment>()
|
||||
private var watchlistJobRunning = false
|
||||
|
||||
private val playerResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
playerFinishedCallback()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentMediaBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.frameLoading.visibility = View.VISIBLE
|
||||
|
||||
// tab layout and pager
|
||||
pagerAdapter = ScreenSlidePagerAdapter(this)
|
||||
// fix material components issue #1878, if more tabs are added increase
|
||||
binding.pagerEpisodesSimilar.offscreenPageLimit = 2
|
||||
binding.pagerEpisodesSimilar.adapter = pagerAdapter
|
||||
// TODO is position 0 always episodes? (and 1 always similar titles)
|
||||
TabLayoutMediator(binding.tabEpisodesSimilar, binding.pagerEpisodesSimilar) { tab, position ->
|
||||
tab.text = when(position) {
|
||||
0 -> getString(R.string.episodes)
|
||||
1 -> getString(R.string.similar_titles)
|
||||
else -> ""
|
||||
}
|
||||
}.attach()
|
||||
|
||||
lifecycleScope.launch {
|
||||
model.loadCrunchy(mediaIdStr)
|
||||
|
||||
updateGUI()
|
||||
initActions()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if tmdb data is present, use it, else use the aod data
|
||||
*/
|
||||
private fun updateGUI() = with(model) {
|
||||
// generic gui
|
||||
val backdropUrl = tmdbResult.backdropPath?.let { TMDBApiController.imageUrl + it }
|
||||
?: seriesCrunchy.images.poster_wide[0][2].source
|
||||
val posterUrl = tmdbResult.posterPath?.let { TMDBApiController.imageUrl + it }
|
||||
?: seriesCrunchy.images.poster_tall[0][2].source
|
||||
|
||||
// load poster and backdrop
|
||||
Glide.with(requireContext()).load(posterUrl)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.into(binding.imagePoster)
|
||||
Glide.with(requireContext()).load(backdropUrl)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3)))
|
||||
.into(binding.imageBackdrop)
|
||||
|
||||
binding.textYear.text = when(tmdbResult) {
|
||||
is TMDBTVShow -> (tmdbResult as TMDBTVShow).firstAirDate?.substring(0, 4)
|
||||
is TMDBMovie -> (tmdbResult as TMDBMovie).releaseDate.substring(0, 4)
|
||||
else -> ""
|
||||
}
|
||||
binding.textAge.text = seriesCrunchy.maturityRatings.firstOrNull()
|
||||
|
||||
binding.textTitle.text = if (upNextSeries != NoneUpNextSeriesList) {
|
||||
upNextSeries.data.first().panel.title
|
||||
} else seriesCrunchy.title
|
||||
binding.textOverview.text = seriesCrunchy.description
|
||||
|
||||
// set "watchlist" indicator
|
||||
val watchlistIcon = if (isWatchlist) R.drawable.ic_baseline_check_24 else R.drawable.ic_baseline_add_24
|
||||
Glide.with(requireContext()).load(watchlistIcon).into(binding.imageMyListAction)
|
||||
|
||||
/**
|
||||
* clear fragments, since it lives in onCreate scope,
|
||||
* don't do this in onPause/onStop -> FragmentManager transaction
|
||||
* (will be called on similar -> new MediaFragment -> onBackPressed)
|
||||
*/
|
||||
val fragmentsSize = fragments.size
|
||||
fragments.clear()
|
||||
pagerAdapter.notifyItemRangeRemoved(0, fragmentsSize)
|
||||
|
||||
MediaFragmentEpisodes().also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
|
||||
// if has similar titles
|
||||
if (model.similarTo.total > 0) {
|
||||
MediaFragmentSimilar(model.similarTo.toItemMediaList()).also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
}
|
||||
|
||||
// disable scrolling on appbar, if no tabs where added
|
||||
if(fragments.isEmpty()) {
|
||||
val params = binding.linearMedia.layoutParams as AppBarLayout.LayoutParams
|
||||
params.scrollFlags = 0 // clear all scroll flags
|
||||
}
|
||||
|
||||
// specific gui (via tmdb)
|
||||
when (tmdbResult) {
|
||||
is TMDBTVShow -> {
|
||||
// episodes count
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_episodes_count,
|
||||
seriesCrunchy.episodeCount,
|
||||
seriesCrunchy.episodeCount
|
||||
)
|
||||
}
|
||||
is TMDBMovie -> {
|
||||
val tmdbMovie = tmdbResult as TMDBMovie
|
||||
|
||||
if (tmdbMovie.runtime != null) {
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_runtime,
|
||||
tmdbMovie.runtime,
|
||||
tmdbMovie.runtime
|
||||
)
|
||||
} else {
|
||||
binding.textEpisodesOrRuntime.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
binding.textEpisodesOrRuntime.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
binding.frameLoading.visibility = View.GONE // hide loading indicator
|
||||
}
|
||||
|
||||
private fun initActions() = with(model) {
|
||||
binding.buttonPlay.setOnClickListener {
|
||||
if (upNextSeries != NoneUpNextSeriesList) {
|
||||
val panel = upNextSeries.data.first().panel
|
||||
playEpisode(panel.episodeMetadata.seasonId, panel.id)
|
||||
}
|
||||
}
|
||||
|
||||
// add or remove media from myList
|
||||
binding.linearMyListAction.setOnClickListener {
|
||||
// don't allow parallel execution
|
||||
if (!watchlistJobRunning) {
|
||||
watchlistJobRunning = true
|
||||
lifecycleScope.launch {
|
||||
setWatchlist()
|
||||
|
||||
// update "watchlist" indicator
|
||||
val watchlistIcon = if (isWatchlist) R.drawable.ic_baseline_check_24 else R.drawable.ic_baseline_add_24
|
||||
Glide.with(requireContext()).load(watchlistIcon).into(binding.imageMyListAction)
|
||||
watchlistJobRunning = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun playerFinishedCallback() = lifecycleScope.launch {
|
||||
model.updateOnResume()
|
||||
|
||||
if (model.upNextSeries != NoneUpNextSeriesList) {
|
||||
binding.textTitle.text = model.upNextSeries.data.first().panel.title
|
||||
}
|
||||
|
||||
// needs to be called after model.updateOnResume()
|
||||
(fragments.elementAtOrNull(0) as? MediaFragmentEpisodes)?.updateWatchedState()
|
||||
|
||||
Log.d(javaClass.name, "Updated model and gui after player closed")
|
||||
}
|
||||
|
||||
/**
|
||||
* play a episode, also runs callback on player result return
|
||||
*/
|
||||
fun playEpisode(seasonId: String, episodeId: String) {
|
||||
playerResult.launch(playerIntent(seasonId, episodeId))
|
||||
Log.d(javaClass.name, "Started Player with episodeId: $episodeId")
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple pager adapter
|
||||
*/
|
||||
private inner class ScreenSlidePagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
override fun getItemCount(): Int = fragments.size
|
||||
|
||||
override fun createFragment(position: Int): Fragment = fragments[position]
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentMediaEpisodesBinding
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
|
||||
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
|
||||
|
||||
class MediaFragmentEpisodes : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMediaEpisodesBinding
|
||||
private lateinit var adapterRecEpisodes: EpisodeItemAdapter
|
||||
|
||||
private val model: MediaFragmentViewModel by viewModels({requireParentFragment()})
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentMediaEpisodesBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
adapterRecEpisodes = EpisodeItemAdapter(
|
||||
model.currentEpisodesCrunchy,
|
||||
model.tmdbTVSeason.episodes,
|
||||
model.currentPlayheads,
|
||||
EpisodeItemAdapter.OnClickListener { episode ->
|
||||
(requireParentFragment() as? MediaFragment)?.playEpisode(episode.seasonId, episode.id)
|
||||
},
|
||||
EpisodeItemAdapter.ViewType.MEDIA_FRAGMENT
|
||||
)
|
||||
binding.recyclerEpisodes.adapter = adapterRecEpisodes
|
||||
|
||||
// don't show season selection if only one season is present
|
||||
if (model.seasonsCrunchy.total < 2) {
|
||||
binding.buttonSeasonSelection.visibility = View.GONE
|
||||
} else {
|
||||
binding.buttonSeasonSelection.text = getString(
|
||||
R.string.season_number_title,
|
||||
model.currentSeasonCrunchy.seasonNumber,
|
||||
model.currentSeasonCrunchy.title
|
||||
)
|
||||
binding.buttonSeasonSelection.setOnClickListener { v ->
|
||||
showSeasonSelection(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateWatchedState() {
|
||||
// model.currentPlayheads is a val mutable map -> notify dataset changed
|
||||
if (this::adapterRecEpisodes.isInitialized) {
|
||||
adapterRecEpisodes.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSeasonSelection(v: View) {
|
||||
// TODO replace with Exposed dropdown menu: https://material.io/components/menus/android#exposed-dropdown-menus
|
||||
val popup = PopupMenu(requireContext(), v)
|
||||
model.seasonsCrunchy.data.forEach { season ->
|
||||
popup.menu.add(getString(
|
||||
R.string.season_number_title,
|
||||
season.seasonNumber,
|
||||
season.title
|
||||
)
|
||||
).also {
|
||||
it.setOnMenuItemClickListener {
|
||||
onSeasonSelected(season.id)
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
popup.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* Call model to load a new season.
|
||||
* Once loaded update buttonSeasonSelection text and adapterRecEpisodes.
|
||||
*
|
||||
* Suppress waring since invalid.
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun onSeasonSelected(seasonId: String) {
|
||||
// load the new season
|
||||
lifecycleScope.launch {
|
||||
model.setCurrentSeason(seasonId)
|
||||
binding.buttonSeasonSelection.text = getString(
|
||||
R.string.season_number_title,
|
||||
model.currentSeasonCrunchy.seasonNumber,
|
||||
model.currentSeasonCrunchy.title
|
||||
)
|
||||
adapterRecEpisodes.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.mosad.teapod.databinding.FragmentMediaSimilarBinding
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import org.mosad.teapod.util.adapter.MediaItemListAdapter
|
||||
import org.mosad.teapod.util.showFragment
|
||||
|
||||
class MediaFragmentSimilar(val items: List<ItemMedia>) : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMediaSimilarBinding
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentMediaSimilarBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.recyclerMediaSimilar.adapter = MediaItemListAdapter(
|
||||
MediaItemListAdapter.OnClickListener {
|
||||
activity?.showFragment(MediaFragment(it.id))
|
||||
}
|
||||
)
|
||||
|
||||
val adapterSimilar = binding.recyclerMediaSimilar.adapter as MediaItemListAdapter
|
||||
adapterSimilar.submitList(items)
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentMyListsBinding
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.MyListsFragmentViewModel
|
||||
import org.mosad.teapod.util.toItemMediaList
|
||||
|
||||
class MyListsFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMyListsBinding
|
||||
private lateinit var pagerAdapter: FragmentStateAdapter
|
||||
|
||||
private val model: MyListsFragmentViewModel by viewModels()
|
||||
|
||||
private val fragments = arrayListOf<Fragment>()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentMyListsBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// tab layout and pager
|
||||
pagerAdapter = ScreenSlidePagerAdapter(this)
|
||||
binding.pagerMyLists.adapter = pagerAdapter
|
||||
|
||||
TabLayoutMediator(binding.tabMyLists, binding.pagerMyLists) { tab, position ->
|
||||
tab.text = when(position) {
|
||||
0 -> getString(R.string.my_list)
|
||||
1 -> getString(R.string.crunchylists)
|
||||
2 -> getString(R.string.downloads)
|
||||
else -> ""
|
||||
}
|
||||
}.attach()
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
model.onUiState(viewLifecycleOwner.lifecycleScope) { uiState ->
|
||||
when (uiState) {
|
||||
is MyListsFragmentViewModel.UiState.Normal -> bindUiStateNormal(uiState)
|
||||
is MyListsFragmentViewModel.UiState.Loading -> bindUiStateLoading()
|
||||
is MyListsFragmentViewModel.UiState.Error -> bindUiStateError(uiState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindUiStateNormal(uiState: MyListsFragmentViewModel.UiState.Normal) {
|
||||
MediaFragmentSimilar(uiState.watchlistItems.toItemMediaList()).also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindUiStateLoading() {
|
||||
// currently not used
|
||||
}
|
||||
|
||||
private fun bindUiStateError(uiState: MyListsFragmentViewModel.UiState.Error) {
|
||||
// currently not used
|
||||
Log.e(javaClass.name, "A error occurred while loading a UiState: ${uiState.message}")
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple pager adapter
|
||||
* TODO also present in MediaFragment
|
||||
*/
|
||||
private inner class ScreenSlidePagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
override fun getItemCount(): Int = fragments.size
|
||||
|
||||
override fun createFragment(position: Int): Fragment = fragments[position]
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.activity.main.viewmodel
|
||||
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.parser.crunchyroll.*
|
||||
import kotlin.random.Random
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
private val WATCHLIST_LENGTH = 50
|
||||
|
||||
private val uiState = MutableStateFlow<UiState>(UiState.Loading)
|
||||
|
||||
sealed class UiState {
|
||||
object Loading : UiState()
|
||||
data class Normal(
|
||||
val upNextItems: List<UpNextAccountItem>,
|
||||
val watchlistItems: List<Item>,
|
||||
val recommendationsItems: List<Item>,
|
||||
val recentlyAddedItems: List<Item>,
|
||||
val topTenItems: List<Item>,
|
||||
val highlightItem: Item,
|
||||
val highlightItemUpNext: UpNextSeriesItem,
|
||||
val highlightIsWatchlist:Boolean
|
||||
) : UiState()
|
||||
data class Error(val message: String?) : UiState()
|
||||
}
|
||||
|
||||
init {
|
||||
load()
|
||||
}
|
||||
|
||||
fun onUiState(scope: LifecycleCoroutineScope, collector: (UiState) -> Unit) {
|
||||
scope.launch { uiState.collect { collector(it) } }
|
||||
}
|
||||
|
||||
fun load() {
|
||||
viewModelScope.launch {
|
||||
uiState.emit(UiState.Loading)
|
||||
try {
|
||||
// run the loading in parallel to speed up the process
|
||||
val upNextJob = viewModelScope.async { Crunchyroll.upNextAccount(n = 20).data }
|
||||
val watchlistJob = viewModelScope.async { Crunchyroll.watchlist(WATCHLIST_LENGTH).data }
|
||||
val recommendationsJob = viewModelScope.async {
|
||||
Crunchyroll.recommendations(n = 20).data
|
||||
}
|
||||
val recentlyAddedJob = viewModelScope.async {
|
||||
Crunchyroll.browse(sortBy = SortBy.NEWLY_ADDED, n = 50).data
|
||||
}
|
||||
val topTenJob = viewModelScope.async {
|
||||
Crunchyroll.browse(sortBy = SortBy.POPULARITY, n = 10).data
|
||||
}
|
||||
|
||||
val recentlyAddedItems = recentlyAddedJob.await()
|
||||
// FIXME crashes on newTitles.items.size == 0
|
||||
val highlightItem = recentlyAddedItems[Random.nextInt(recentlyAddedItems.size)]
|
||||
val highlightItemUpNextJob = viewModelScope.async {
|
||||
Crunchyroll.upNextSeries(highlightItem.id).data.first()
|
||||
}
|
||||
val highlightItemIsWatchlistJob = viewModelScope.async {
|
||||
Crunchyroll.isWatchlist(highlightItem.id)
|
||||
}
|
||||
|
||||
uiState.emit(UiState.Normal(
|
||||
upNextJob.await(), watchlistJob.await(), recommendationsJob.await(),
|
||||
recentlyAddedJob.await(), topTenJob.await(), highlightItem,
|
||||
highlightItemUpNextJob.await(), highlightItemIsWatchlistJob.await()
|
||||
))
|
||||
} catch (e: Exception) {
|
||||
uiState.emit(UiState.Error(e.message))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the watchlist state of the highlight media.
|
||||
*/
|
||||
fun toggleHighlightWatchlist() {
|
||||
viewModelScope.launch {
|
||||
uiState.update { currentUiState ->
|
||||
if (currentUiState is UiState.Normal) {
|
||||
if (currentUiState.highlightIsWatchlist) {
|
||||
Crunchyroll.deleteWatchlist(currentUiState.highlightItem.id)
|
||||
} else {
|
||||
Crunchyroll.postWatchlist(currentUiState.highlightItem.id)
|
||||
}
|
||||
|
||||
// update the watchlist after a item has been added/removed
|
||||
val watchlistItems = Crunchyroll.watchlist(WATCHLIST_LENGTH).data
|
||||
|
||||
currentUiState.copy(
|
||||
watchlistItems = watchlistItems,
|
||||
highlightIsWatchlist = !currentUiState.highlightIsWatchlist)
|
||||
} else {
|
||||
currentUiState
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the up next list. To be used on player result callbacks.
|
||||
*/
|
||||
fun updateUpNextItems() {
|
||||
viewModelScope.launch {
|
||||
uiState.update { currentUiState ->
|
||||
if (currentUiState is UiState.Normal) {
|
||||
val upNextItems = Crunchyroll.upNextAccount(n = 20).data
|
||||
currentUiState.copy(upNextItems = upNextItems)
|
||||
} else {
|
||||
currentUiState
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
package org.mosad.teapod.ui.activity.main.viewmodel
|
||||
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import org.mosad.teapod.util.toItemMediaList
|
||||
|
||||
class LibraryFragmentViewModel : ViewModel() {
|
||||
|
||||
val PAGESIZE = 50
|
||||
|
||||
private val uiState = MutableStateFlow<UiState>(UiState.Loading)
|
||||
private var oldSearchQuery = ""
|
||||
private var searchJob: Job? = null
|
||||
var isLazyLoading = false
|
||||
internal set
|
||||
|
||||
sealed class UiState {
|
||||
object Loading : UiState()
|
||||
data class Browse(
|
||||
val itemList: MutableList<ItemMedia>
|
||||
) : UiState()
|
||||
data class Search(
|
||||
val itemList: List<ItemMedia>
|
||||
) : UiState()
|
||||
data class Error(val message: String?) : UiState()
|
||||
}
|
||||
|
||||
init {
|
||||
load()
|
||||
}
|
||||
|
||||
fun onUiState(scope: LifecycleCoroutineScope, collector: (UiState) -> Unit) {
|
||||
scope.launch { uiState.collect { collector(it) } }
|
||||
}
|
||||
|
||||
/**
|
||||
* initially load the first n browsing items
|
||||
*/
|
||||
private fun load() {
|
||||
viewModelScope.launch {
|
||||
uiState.emit(UiState.Loading)
|
||||
|
||||
try {
|
||||
initBrowse()
|
||||
} catch (ex: Exception) {
|
||||
uiState.emit(UiState.Error(ex.message))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a query string at Crunchyroll and emit the new ui state.
|
||||
*/
|
||||
fun search(query: String) {
|
||||
// return if nothing has changed
|
||||
if (query == oldSearchQuery) return
|
||||
|
||||
// update the old query since it has changed
|
||||
oldSearchQuery = query
|
||||
|
||||
viewModelScope.launch {
|
||||
|
||||
// always cancel a running search job
|
||||
if (searchJob?.isActive == true) searchJob?.cancel()
|
||||
|
||||
// handle state change: browse <-> search
|
||||
if (query.isEmpty()) {
|
||||
// if the query is empty change back to browse state
|
||||
initBrowse()
|
||||
} else {
|
||||
// TODO handle errors
|
||||
|
||||
// if the current ui state is not search, clear the recyclerview
|
||||
if (uiState.value !is UiState.Search) {
|
||||
uiState.emit(UiState.Search(emptyList()))
|
||||
}
|
||||
|
||||
// create a new search job
|
||||
searchJob = viewModelScope.async {
|
||||
// wait for a few ms: if the user is typing the task will get canceled
|
||||
delay(250)
|
||||
|
||||
val results = Crunchyroll.search(query, 50)
|
||||
.data.firstOrNull()?.items?.toItemMediaList()
|
||||
?: listOf()
|
||||
uiState.emit(UiState.Search(results))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onLazyLoad() = viewModelScope.launch {
|
||||
isLazyLoading = true
|
||||
|
||||
try {
|
||||
uiState.update { currentUiState ->
|
||||
if (currentUiState is UiState.Browse) {
|
||||
val newBrowseItems = Crunchyroll.browse(start = currentUiState.itemList.size, n = PAGESIZE)
|
||||
.toItemMediaList()
|
||||
currentUiState.itemList.addAll(newBrowseItems)
|
||||
}
|
||||
currentUiState
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
uiState.emit(UiState.Error(ex.message))
|
||||
}
|
||||
|
||||
isLazyLoading = false
|
||||
}
|
||||
|
||||
private suspend fun initBrowse() {
|
||||
try {
|
||||
val initialBrowseItems = Crunchyroll.browse(n = PAGESIZE)
|
||||
.toItemMediaList()
|
||||
.toMutableList()
|
||||
uiState.emit(UiState.Browse(initialBrowseItems))
|
||||
} catch (ex: Exception) {
|
||||
uiState.emit(UiState.Error(ex.message))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package org.mosad.teapod.ui.activity.main.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.parser.crunchyroll.*
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.tmdb.*
|
||||
import org.mosad.teapod.util.toPlayheadsMap
|
||||
|
||||
/**
|
||||
* handle media, next ep and tmdb
|
||||
* TODO this lives in activity, is this correct?
|
||||
*/
|
||||
class MediaFragmentViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
var seriesCrunchy = NoneSeriesItem // movies are also series
|
||||
internal set
|
||||
var seasonsCrunchy = NoneSeasons
|
||||
internal set
|
||||
var currentSeasonCrunchy = NoneSeason
|
||||
internal set
|
||||
var episodesCrunchy = NoneEpisodes
|
||||
internal set
|
||||
val currentEpisodesCrunchy = arrayListOf<Episode>() // used for EpisodeItemAdapter (easier updates)
|
||||
|
||||
// additional media info, might change during during user interaction
|
||||
// use a map to update the episode adapter values
|
||||
val currentPlayheads: MutableMap<String, PlayheadObject> = mutableMapOf()
|
||||
var isWatchlist = false
|
||||
internal set
|
||||
var upNextSeries = NoneUpNextSeriesList
|
||||
internal set
|
||||
var similarTo = NoneSimilarToResult
|
||||
internal set
|
||||
|
||||
// TMDB stuff
|
||||
var mediaType = MediaType.OTHER
|
||||
internal set
|
||||
var tmdbResult: TMDBResult = NoneTMDB // TODO rename
|
||||
internal set
|
||||
var tmdbTVSeason: TMDBTVSeason = NoneTMDBTVSeason
|
||||
internal set
|
||||
|
||||
/**
|
||||
* @param crunchyId the crunchyroll series id
|
||||
*/
|
||||
|
||||
suspend fun loadCrunchy(crunchyId: String) {
|
||||
// load series and seasons info in parallel
|
||||
listOf(
|
||||
viewModelScope.launch { seriesCrunchy = Crunchyroll.series(crunchyId).data.first() },
|
||||
viewModelScope.launch { seasonsCrunchy = Crunchyroll.seasons(crunchyId) },
|
||||
viewModelScope.launch { isWatchlist = Crunchyroll.isWatchlist(crunchyId) },
|
||||
viewModelScope.launch { upNextSeries = Crunchyroll.upNextSeries(crunchyId) },
|
||||
viewModelScope.launch { similarTo = Crunchyroll.similarTo(crunchyId) }
|
||||
).joinAll()
|
||||
|
||||
// load the preferred season:
|
||||
// next episode > first season
|
||||
currentSeasonCrunchy = if (upNextSeries != NoneUpNextSeriesList) {
|
||||
seasonsCrunchy.data.firstOrNull{ season ->
|
||||
season.id == upNextSeries.data.first().panel.episodeMetadata.seasonId
|
||||
} ?: seasonsCrunchy.data.first()
|
||||
} else {
|
||||
seasonsCrunchy.data.first()
|
||||
}
|
||||
|
||||
// Note: if we need to query metaDB, do it now
|
||||
|
||||
// load episodes and metaDB in parallel (tmdb needs mediaType, which is set via episodes)
|
||||
viewModelScope.launch { episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id) }.join()
|
||||
currentEpisodesCrunchy.clear()
|
||||
currentEpisodesCrunchy.addAll(episodesCrunchy.data)
|
||||
|
||||
// set media type, for movies the episode field is empty
|
||||
mediaType = episodesCrunchy.data.firstOrNull()?.let {
|
||||
if (it.episode.isNotEmpty()) MediaType.TVSHOW else MediaType.MOVIE
|
||||
} ?: MediaType.OTHER
|
||||
|
||||
// load playheads and tmdb in parallel
|
||||
listOf(
|
||||
updatePlayheadsAsync(),
|
||||
viewModelScope.launch { loadTmdbInfo() } // use tmdb search to get media info
|
||||
).joinAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the tmdb info for the selected media.
|
||||
* The TMDB search return a media type, use this to get the details (movie/tv show and season)
|
||||
*/
|
||||
private suspend fun loadTmdbInfo() {
|
||||
val tmdbApiController = TMDBApiController()
|
||||
|
||||
val tmdbSearchResult = when(mediaType) {
|
||||
MediaType.MOVIE -> tmdbApiController.searchMovie(seriesCrunchy.title)
|
||||
MediaType.TVSHOW -> tmdbApiController.searchTVShow(seriesCrunchy.title)
|
||||
else -> NoneTMDBSearch
|
||||
}
|
||||
|
||||
tmdbResult = if (tmdbSearchResult.results.isNotEmpty()) {
|
||||
when (val result = tmdbSearchResult.results.first()) {
|
||||
is TMDBSearchResultMovie -> tmdbApiController.getMovieDetails(result.id)
|
||||
is TMDBSearchResultTVShow -> tmdbApiController.getTVShowDetails(result.id)
|
||||
else -> NoneTMDB
|
||||
}
|
||||
} else NoneTMDB
|
||||
|
||||
// currently not used
|
||||
// tmdbTVSeason = if (tmdbResult is TMDBTVShow) {
|
||||
// tmdbApiController.getTVSeasonDetails(tmdbResult.id, 0)
|
||||
// } else NoneTMDBTVSeason
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current playheads for all episodes
|
||||
*/
|
||||
private fun updatePlayheadsAsync() = viewModelScope.async {
|
||||
currentPlayheads.clear()
|
||||
currentPlayheads.putAll(
|
||||
Crunchyroll.playheads(episodesCrunchy.data.map { it.id }).toPlayheadsMap()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set currentSeasonCrunchy based on the season id. Also set the new seasons episodes.
|
||||
*
|
||||
* @param seasonId the id of the season to set
|
||||
*/
|
||||
suspend fun setCurrentSeason(seasonId: String) {
|
||||
// return if the id hasn't changed (performance)
|
||||
if (currentSeasonCrunchy.id == seasonId) return
|
||||
|
||||
// set currentSeasonCrunchy to the new season with id == seasonId, if the id isn't found,
|
||||
// don't change the current season (this should/can never happen)
|
||||
currentSeasonCrunchy = seasonsCrunchy.data.firstOrNull {
|
||||
it.id == seasonId
|
||||
} ?: currentSeasonCrunchy
|
||||
|
||||
episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id)
|
||||
currentEpisodesCrunchy.clear()
|
||||
currentEpisodesCrunchy.addAll(episodesCrunchy.data)
|
||||
|
||||
// update playheads playheads (including fully watched state)
|
||||
updatePlayheadsAsync().await()
|
||||
}
|
||||
|
||||
suspend fun setWatchlist() {
|
||||
isWatchlist = if (isWatchlist) {
|
||||
Crunchyroll.deleteWatchlist(seriesCrunchy.id)
|
||||
false
|
||||
} else {
|
||||
Crunchyroll.postWatchlist(seriesCrunchy.id)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateOnResume() {
|
||||
joinAll(
|
||||
updatePlayheadsAsync(),
|
||||
viewModelScope.launch { upNextSeries = Crunchyroll.upNextSeries(seriesCrunchy.id) }
|
||||
)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.mosad.teapod.ui.activity.main.viewmodel
|
||||
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.parser.crunchyroll.Item
|
||||
|
||||
class MyListsFragmentViewModel : ViewModel() {
|
||||
|
||||
private val WATCHLIST_LENGTH = 50
|
||||
|
||||
private val uiState = MutableStateFlow<UiState>(UiState.Loading)
|
||||
|
||||
sealed class UiState {
|
||||
object Loading : UiState()
|
||||
data class Normal(
|
||||
val watchlistItems: List<Item>
|
||||
) : UiState()
|
||||
data class Error(val message: String?) : UiState()
|
||||
}
|
||||
|
||||
init {
|
||||
load()
|
||||
}
|
||||
|
||||
fun onUiState(scope: LifecycleCoroutineScope, collector: (UiState) -> Unit) {
|
||||
scope.launch { uiState.collect { collector(it) } }
|
||||
}
|
||||
|
||||
fun load() {
|
||||
viewModelScope.launch {
|
||||
uiState.emit(UiState.Loading)
|
||||
try {
|
||||
// run the loading in parallel to speed up the process
|
||||
val watchlistJob = viewModelScope.async { Crunchyroll.watchlist(WATCHLIST_LENGTH).data }
|
||||
uiState.emit(
|
||||
UiState.Normal(watchlistJob.await())
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
uiState.emit(UiState.Error(e.message))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package org.mosad.teapod.ui.activity.onboarding
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentOnLoginBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
|
||||
class OnLoginFragment: Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentOnLoginBinding
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentOnLoginBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initActions()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
binding.buttonLogin.setOnClickListener {
|
||||
onLogin()
|
||||
}
|
||||
|
||||
binding.editTextPassword.setOnEditorActionListener { _, actionId, _ ->
|
||||
return@setOnEditorActionListener when (actionId) {
|
||||
EditorInfo.IME_ACTION_DONE -> {
|
||||
onLogin()
|
||||
false // false will hide the keyboards
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun onLogin() {
|
||||
// get login credentials from gui
|
||||
val email = binding.editTextLogin.text.toString()
|
||||
val password = binding.editTextPassword.text.toString()
|
||||
|
||||
binding.buttonLogin.isClickable = false
|
||||
// FIXME, this seems to run blocking
|
||||
lifecycleScope.launch {
|
||||
// try login credentials
|
||||
val login = Crunchyroll.login(email, password)
|
||||
|
||||
if (login) {
|
||||
// save the credentials and show the main activity
|
||||
EncryptedPreferences.saveCredentials(email, password, requireContext())
|
||||
if (activity is OnboardingActivity) (activity as OnboardingActivity).launchMainActivity()
|
||||
} else {
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.textLoginDesc.text = getString(R.string.on_login_failed)
|
||||
binding.buttonLogin.isClickable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.mosad.teapod.ui.activity.onboarding
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.mosad.teapod.databinding.FragmentOnWelcomeBinding
|
||||
|
||||
class OnWelcomeFragment: Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentOnWelcomeBinding
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentOnWelcomeBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initActions()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
binding.buttonGetStarted.setOnClickListener {
|
||||
if (activity is OnboardingActivity) {
|
||||
(activity as OnboardingActivity).nextFragment()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package org.mosad.teapod.ui.activity.onboarding
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import org.mosad.teapod.databinding.ActivityOnboardingBinding
|
||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
||||
|
||||
class OnboardingActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityOnboardingBinding
|
||||
private lateinit var pagerAdapter: FragmentStateAdapter
|
||||
|
||||
private val fragments = arrayOf(OnWelcomeFragment(), OnLoginFragment())
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityOnboardingBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
pagerAdapter = ScreenSlidePagerAdapter(this)
|
||||
binding.viewPager.adapter = pagerAdapter
|
||||
TabLayoutMediator(binding.tabLayout, binding.viewPager) { _, _ -> }.attach()
|
||||
|
||||
// we don't use the skip button, instead we use the start button to skip the last fragment
|
||||
binding.buttonSkip.visibility = View.GONE
|
||||
|
||||
// hide tab layout if only one tab is displayed
|
||||
if (fragments.size <= 1) {
|
||||
binding.tabLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback {
|
||||
if (binding.viewPager.currentItem != 0) {
|
||||
binding.viewPager.currentItem = binding.viewPager.currentItem - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun nextFragment() {
|
||||
if (binding.viewPager.currentItem < fragments.size - 1) {
|
||||
binding.viewPager.currentItem++
|
||||
} else {
|
||||
launchMainActivity()
|
||||
}
|
||||
}
|
||||
|
||||
fun btnNextClick(@Suppress("UNUSED_PARAMETER")v: View) {
|
||||
//nextFragment() // currently not used in Teapod
|
||||
}
|
||||
|
||||
fun btnSkipClick(@Suppress("UNUSED_PARAMETER")v: View) {
|
||||
//launchMainActivity() // currently not used in Teapod
|
||||
}
|
||||
|
||||
fun launchMainActivity() {
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple pager adapter
|
||||
*/
|
||||
private inner class ScreenSlidePagerAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {
|
||||
override fun getItemCount(): Int = fragments.size
|
||||
|
||||
override fun createFragment(position: Int): Fragment = fragments[position]
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,564 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.activity.player
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.PictureInPictureParams
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.util.Rational
|
||||
import android.view.GestureDetector
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.GestureDetectorCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.ui.StyledPlayerControlView
|
||||
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||
import com.google.android.exoplayer2.util.Util
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ActivityPlayerBinding
|
||||
import org.mosad.teapod.databinding.PlayerControlsBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.NoneEpisode
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.ui.activity.player.fragment.EpisodeListDialogFragment
|
||||
import org.mosad.teapod.ui.activity.player.fragment.LanguageSettingsDialogFragment
|
||||
import org.mosad.teapod.util.hideBars
|
||||
import org.mosad.teapod.util.isInPiPMode
|
||||
import org.mosad.teapod.util.navToLauncherTask
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.concurrent.scheduleAtFixedRate
|
||||
|
||||
class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
private val model: PlayerViewModel by viewModels()
|
||||
private lateinit var playerBinding: ActivityPlayerBinding
|
||||
private lateinit var controlsBinding: PlayerControlsBinding
|
||||
|
||||
private lateinit var controller: StyledPlayerControlView
|
||||
private lateinit var gestureDetector: GestureDetectorCompat
|
||||
private lateinit var controlsUpdates: TimerTask
|
||||
|
||||
private var wasInPiP = false
|
||||
private var remainingTime: Long = 0
|
||||
|
||||
private val rwdTime: Long = 10000.unaryMinus()
|
||||
private val fwdTime: Long = 10000
|
||||
private val defaultShowTimeoutMs = 5000
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_player)
|
||||
hideBars() // Initial hide the bars
|
||||
|
||||
playerBinding = ActivityPlayerBinding.bind(findViewById(R.id.player_root))
|
||||
controlsBinding = PlayerControlsBinding.bind(findViewById(R.id.player_controls_root))
|
||||
|
||||
model.loadMediaAsync(
|
||||
intent.getStringExtra(getString(R.string.intent_season_id)) ?: "",
|
||||
intent.getStringExtra(getString(R.string.intent_episode_id)) ?: ""
|
||||
)
|
||||
model.currentEpisodeChangedListener.add { onMediaChanged() }
|
||||
gestureDetector = GestureDetectorCompat(this, PlayerGestureListener())
|
||||
|
||||
controller = playerBinding.videoView.findViewById(R.id.exo_controller)
|
||||
controller.isAnimationEnabled = false // disable controls (time-bar) animation
|
||||
|
||||
initExoPlayer() // call in onCreate, exoplayer lives in view model
|
||||
initGUI()
|
||||
initActions()
|
||||
}
|
||||
|
||||
/**
|
||||
* once minimum is android 7.0 this can be simplified
|
||||
* only onStart and onStop should be needed then
|
||||
* see: https://developer.android.com/guide/topics/ui/picture-in-picture#continuing_playback
|
||||
*/
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (Util.SDK_INT > 23) {
|
||||
initPlayer()
|
||||
playerBinding.videoView.onResume()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (isInPiPMode()) { return }
|
||||
|
||||
if (Util.SDK_INT <= 23) {
|
||||
initPlayer()
|
||||
playerBinding.videoView.onResume()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
if (isInPiPMode()) { return }
|
||||
if (Util.SDK_INT <= 23) { onPauseOnStop() }
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
|
||||
if (Util.SDK_INT > 23) { onPauseOnStop() }
|
||||
// if the player was in pip, it's on a different task
|
||||
if (wasInPiP) { navToLauncherTask() }
|
||||
// if the player is in pip, remove the task, else we'll get a zombie
|
||||
if (isInPiPMode()) { finishAndRemoveTask() }
|
||||
}
|
||||
|
||||
/**
|
||||
* used, when the player is in pip and the user selects a new media
|
||||
*/
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
|
||||
// when the intent changed, load the new media and play it
|
||||
intent?.let {
|
||||
model.loadMediaAsync(
|
||||
it.getStringExtra(getString(R.string.intent_season_id)) ?: "",
|
||||
it.getStringExtra(getString(R.string.intent_episode_id)) ?: ""
|
||||
)
|
||||
model.playCurrentMedia()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* previous to android n, don't override
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
override fun onUserLeaveHint() {
|
||||
super.onUserLeaveHint()
|
||||
|
||||
// start pip mode, if supported
|
||||
if (packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
@Suppress("deprecation")
|
||||
enterPictureInPictureMode()
|
||||
} else {
|
||||
val width = model.player.videoFormat?.width ?: 0
|
||||
val height = model.player.videoFormat?.height ?: 0
|
||||
val contentFrame: View = playerBinding.videoView.findViewById(R.id.exo_content_frame)
|
||||
val contentRect = with(contentFrame) {
|
||||
val (x, y) = intArrayOf(0, 0).also(::getLocationInWindow)
|
||||
Rect(x, y, x + width, y + height)
|
||||
}
|
||||
|
||||
val params = PictureInPictureParams.Builder()
|
||||
.setAspectRatio(Rational(width, height))
|
||||
.setSourceRectHint(contentRect)
|
||||
.build()
|
||||
enterPictureInPictureMode(params)
|
||||
}
|
||||
|
||||
wasInPiP = isInPiPMode()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPictureInPictureModeChanged(
|
||||
isInPictureInPictureMode: Boolean,
|
||||
newConfig: Configuration
|
||||
) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
||||
}
|
||||
|
||||
// Hide the full-screen UI (controls, etc.) while in picture-in-picture mode.
|
||||
playerBinding.videoView.useController = !isInPictureInPictureMode
|
||||
|
||||
// TODO also hide language settings/episodes list
|
||||
}
|
||||
|
||||
private fun initPlayer() {
|
||||
initVideoView()
|
||||
initTimeUpdates()
|
||||
|
||||
// if the player is ready or buffering we can simply play the file again, else do nothing
|
||||
val playbackState = model.player.playbackState
|
||||
if ((playbackState == ExoPlayer.STATE_READY || playbackState == ExoPlayer.STATE_BUFFERING)) {
|
||||
model.player.play()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set play when ready and listeners
|
||||
*/
|
||||
private fun initExoPlayer() {
|
||||
model.player.addListener(object : Player.Listener {
|
||||
override fun onPlaybackStateChanged(state: Int) {
|
||||
super.onPlaybackStateChanged(state)
|
||||
|
||||
playerBinding.loading.visibility = when (state) {
|
||||
ExoPlayer.STATE_READY -> View.GONE
|
||||
ExoPlayer.STATE_BUFFERING -> View.VISIBLE
|
||||
else -> View.GONE
|
||||
}
|
||||
|
||||
// don't use isVisible to hide exoPlayPause, as it will set the visibility to GONE
|
||||
controlsBinding.exoPlayPause.visibility = when(playerBinding.loading.isVisible) {
|
||||
true -> View.INVISIBLE
|
||||
false -> View.VISIBLE
|
||||
}
|
||||
|
||||
if (state == ExoPlayer.STATE_ENDED && hasNextEpisode() && Preferences.autoplay) {
|
||||
playNextEpisode()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// revert back to the old behaviour (blocking init) in case there are any issues with async init
|
||||
// start playing the current episode, after all needed player components have been initialized
|
||||
//model.playCurrentMedia(model.currentPlayhead)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun initVideoView() {
|
||||
playerBinding.videoView.player = model.player
|
||||
|
||||
// when the player controls get hidden, hide the bars too
|
||||
playerBinding.videoView.setControllerVisibilityListener(StyledPlayerView.ControllerVisibilityListener {
|
||||
when (it) {
|
||||
View.GONE -> {
|
||||
hideBars()
|
||||
// TODO also hide the skip op button
|
||||
}
|
||||
View.VISIBLE -> updateControls()
|
||||
}
|
||||
})
|
||||
|
||||
playerBinding.videoView.setOnTouchListener { _, event ->
|
||||
gestureDetector.onTouchEvent(event)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
controlsBinding.exoClosePlayer.setOnClickListener {
|
||||
this.finish()
|
||||
}
|
||||
controlsBinding.rwd10.setOnButtonClickListener { rewind() }
|
||||
controlsBinding.ffwd10.setOnButtonClickListener { fastForward() }
|
||||
playerBinding.buttonNextEp.setOnClickListener { playNextEpisode() }
|
||||
playerBinding.buttonSkipOp.setOnClickListener { skipOpening() }
|
||||
controlsBinding.buttonLanguage.setOnClickListener { showLanguageSettings() }
|
||||
controlsBinding.buttonEpisodes.setOnClickListener { showEpisodesList() }
|
||||
controlsBinding.buttonNextEpC.setOnClickListener { playNextEpisode() }
|
||||
}
|
||||
|
||||
private fun initGUI() {
|
||||
// TODO reimplement for cr
|
||||
// if (model.media.type == DataTypes.MediaType.MOVIE) {
|
||||
// button_episodes.visibility = View.GONE
|
||||
// }
|
||||
}
|
||||
|
||||
private fun initTimeUpdates() {
|
||||
if (this::controlsUpdates.isInitialized) {
|
||||
controlsUpdates.cancel()
|
||||
}
|
||||
|
||||
controlsUpdates = Timer().scheduleAtFixedRate(0, 500) {
|
||||
lifecycleScope.launch {
|
||||
val currentPosition = model.player.currentPosition
|
||||
val btnNextEpIsVisible = playerBinding.buttonNextEp.isVisible
|
||||
val controlsVisible = controller.isVisible
|
||||
|
||||
// make sure remaining time is > 0
|
||||
if (model.player.duration > 0) {
|
||||
remainingTime = model.player.duration - currentPosition
|
||||
remainingTime = if (remainingTime < 0) 0 else remainingTime
|
||||
} else {
|
||||
remainingTime = 0
|
||||
}
|
||||
|
||||
// TODO add metaDB ending_start support
|
||||
// if remaining time > 1 and < 20 sec, a next ep is set, autoplay is enabled
|
||||
// and not in pip: show next ep button
|
||||
if (remainingTime in 1000..20000) {
|
||||
if (!btnNextEpIsVisible && hasNextEpisode() && Preferences.autoplay && !isInPiPMode()) {
|
||||
showButtonNextEp()
|
||||
}
|
||||
} else if (btnNextEpIsVisible) {
|
||||
hideButtonNextEp()
|
||||
}
|
||||
|
||||
// into metadata is present and we can show the skip button
|
||||
if (model.currentIntroMetadata.duration >= 10) {
|
||||
val startTime = model.currentIntroMetadata.startTime.toInt() * 1000
|
||||
if (currentPosition in startTime..(startTime + 10000) && !playerBinding.buttonSkipOp.isVisible) {
|
||||
showButtonSkipOp()
|
||||
} else if (playerBinding.buttonSkipOp.isVisible &&
|
||||
currentPosition !in startTime..(startTime + 10000)
|
||||
) {
|
||||
// the button should only be visible if currentEpisodeMeta != null
|
||||
hideButtonSkipOp()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if controls are visible, update them
|
||||
if (controlsVisible) {
|
||||
updateControls()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onPauseOnStop() {
|
||||
playerBinding.videoView.onPause()
|
||||
model.player.pause()
|
||||
controlsUpdates.cancel()
|
||||
}
|
||||
|
||||
/**
|
||||
* update the custom controls
|
||||
*/
|
||||
private fun updateControls() {
|
||||
// update remaining time label
|
||||
val hours = TimeUnit.MILLISECONDS.toHours(remainingTime) % 24
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(remainingTime) % 60
|
||||
val seconds = TimeUnit.MILLISECONDS.toSeconds(remainingTime) % 60
|
||||
|
||||
// if remaining time is below 60 minutes, don't show hours
|
||||
controlsBinding.exoRemaining.text = if (TimeUnit.MILLISECONDS.toMinutes(remainingTime) < 60) {
|
||||
getString(R.string.time_min_sec, minutes, seconds)
|
||||
} else {
|
||||
getString(R.string.time_hour_min_sec, hours, minutes, seconds)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This methode is called, if the current episode has changed.
|
||||
* Update title text and next ep button visibility.
|
||||
* If the currentEpisode changed to NoneEpisode, exit the activity.
|
||||
*/
|
||||
private fun onMediaChanged() {
|
||||
if (model.currentEpisode == NoneEpisode) {
|
||||
Log.e(javaClass.name, "No media was set.")
|
||||
this.finish()
|
||||
}
|
||||
|
||||
controlsBinding.exoTextTitle.text = model.getMediaTitle()
|
||||
|
||||
// hide the next episode button, if there is none
|
||||
controlsBinding.buttonNextEpC.isVisible = hasNextEpisode()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current episode has a next episode.
|
||||
*
|
||||
* @return Boolean: true if there is a next episode, else false.
|
||||
*/
|
||||
private fun hasNextEpisode(): Boolean {
|
||||
return (model.currentEpisode.nextEpisodeId != null && !model.currentEpisodeIsLastEpisode())
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO set position of rewind/fast forward indicators programmatically
|
||||
*/
|
||||
|
||||
private fun rewind() {
|
||||
model.seekToOffset(rwdTime)
|
||||
|
||||
// hide/show needed components
|
||||
playerBinding.exoDoubleTapIndicator.visibility = View.VISIBLE
|
||||
playerBinding.ffwd10Indicator.visibility = View.INVISIBLE
|
||||
controlsBinding.rwd10.visibility = View.INVISIBLE
|
||||
|
||||
playerBinding.rwd10Indicator.onAnimationEndCallback = {
|
||||
playerBinding.exoDoubleTapIndicator.visibility = View.GONE
|
||||
playerBinding.ffwd10Indicator.visibility = View.VISIBLE
|
||||
controlsBinding.rwd10.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
// run animation
|
||||
playerBinding.rwd10Indicator.runOnClickAnimation()
|
||||
}
|
||||
|
||||
private fun fastForward() {
|
||||
model.seekToOffset(fwdTime)
|
||||
|
||||
// hide/show needed components
|
||||
playerBinding.exoDoubleTapIndicator.visibility = View.VISIBLE
|
||||
playerBinding.rwd10Indicator.visibility = View.INVISIBLE
|
||||
controlsBinding.ffwd10.visibility = View.INVISIBLE
|
||||
|
||||
playerBinding.ffwd10Indicator.onAnimationEndCallback = {
|
||||
playerBinding.exoDoubleTapIndicator.visibility = View.GONE
|
||||
playerBinding.rwd10Indicator.visibility = View.VISIBLE
|
||||
controlsBinding.ffwd10.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
// run animation
|
||||
playerBinding.ffwd10Indicator.runOnClickAnimation()
|
||||
}
|
||||
|
||||
private fun playNextEpisode() {
|
||||
// disable the next episode buttons, so a user can't double click it
|
||||
playerBinding.buttonNextEp.isClickable = false
|
||||
controlsBinding.buttonNextEpC.isClickable = false
|
||||
|
||||
hideButtonNextEp()
|
||||
model.playNextEpisode()
|
||||
|
||||
// enable the next episode buttons when playNextEpisode() has returned
|
||||
playerBinding.buttonNextEp.isClickable = true
|
||||
controlsBinding.buttonNextEpC.isClickable = true
|
||||
}
|
||||
|
||||
private fun skipOpening() {
|
||||
// calculate the seek time
|
||||
if (model.currentIntroMetadata.duration > 10) {
|
||||
val endTime = model.currentIntroMetadata.endTime.toInt() * 1000
|
||||
val seekTime = endTime - model.player.currentPosition
|
||||
model.seekToOffset(seekTime)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* show the next episode button
|
||||
* TODO improve the show animation
|
||||
*/
|
||||
private fun showButtonNextEp() {
|
||||
playerBinding.buttonNextEp.isVisible = true
|
||||
playerBinding.buttonNextEp.alpha = 0.0f
|
||||
|
||||
playerBinding.buttonNextEp.animate()
|
||||
.alpha(1.0f)
|
||||
.setListener(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the next episode button
|
||||
* TODO improve the hide animation
|
||||
*/
|
||||
private fun hideButtonNextEp() {
|
||||
playerBinding.buttonNextEp.animate()
|
||||
.alpha(0.0f)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
super.onAnimationEnd(animation)
|
||||
playerBinding.buttonNextEp.isVisible = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showButtonSkipOp() {
|
||||
playerBinding.buttonSkipOp.isVisible = true
|
||||
playerBinding.buttonSkipOp.alpha = 0.0f
|
||||
|
||||
playerBinding.buttonSkipOp.animate()
|
||||
.alpha(1.0f)
|
||||
.setListener(null)
|
||||
}
|
||||
|
||||
private fun hideButtonSkipOp() {
|
||||
playerBinding.buttonSkipOp.animate()
|
||||
.alpha(0.0f)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
super.onAnimationEnd(animation)
|
||||
playerBinding.buttonSkipOp.isVisible = false
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun showEpisodesList() {
|
||||
pauseAndHideControls()
|
||||
EpisodeListDialogFragment().show(supportFragmentManager, EpisodeListDialogFragment.TAG)
|
||||
}
|
||||
|
||||
private fun showLanguageSettings() {
|
||||
pauseAndHideControls()
|
||||
LanguageSettingsDialogFragment().show(supportFragmentManager, LanguageSettingsDialogFragment.TAG)
|
||||
}
|
||||
|
||||
/**
|
||||
* pause playback and hide controls
|
||||
*/
|
||||
private fun pauseAndHideControls() {
|
||||
model.player.pause() // showTimeoutMs is set to 0 when calling pause, but why
|
||||
controller.showTimeoutMs = defaultShowTimeoutMs // fix showTimeoutMs set to 0
|
||||
controller.hide()
|
||||
}
|
||||
|
||||
inner class PlayerGestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||
|
||||
/**
|
||||
* on single tap hide or show the controls
|
||||
*/
|
||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||
if (!isInPiPMode()) {
|
||||
if (controller.isVisible) controller.hide() else controller.show()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* on double tap rewind or forward
|
||||
*/
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
val eventPosX = e.x.toInt()
|
||||
val viewCenterX = playerBinding.videoView.measuredWidth / 2
|
||||
|
||||
// if the event position is on the left side rewind, if it's on the right forward
|
||||
if (eventPosX < viewCenterX) rewind() else fastForward()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* not used
|
||||
*/
|
||||
override fun onDoubleTapEvent(e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* on long press toggle pause/play
|
||||
*/
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
model.togglePausePlay()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,341 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.activity.player
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import android.support.v4.media.session.MediaSessionCompat
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.crunchyroll.*
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.metadb.EpisodeMeta
|
||||
import org.mosad.teapod.util.metadb.Meta
|
||||
import org.mosad.teapod.util.metadb.MetaDBController
|
||||
import org.mosad.teapod.util.metadb.TVShowMeta
|
||||
import org.mosad.teapod.util.toPlayheadsMap
|
||||
import java.util.*
|
||||
import kotlin.concurrent.scheduleAtFixedRate
|
||||
|
||||
/**
|
||||
* PlayerViewModel handles all stuff related to media/episodes.
|
||||
* When currentEpisode is changed the player will start playing it (not initial media),
|
||||
* the next episode will be update and the callback is handled.
|
||||
*/
|
||||
class PlayerViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val classTag = javaClass.name
|
||||
|
||||
val player = ExoPlayer.Builder(application).build()
|
||||
private val mediaSession = MediaSessionCompat(application, "TEAPOD_PLAYER_SESSION")
|
||||
private val playheadAutoUpdate: TimerTask
|
||||
|
||||
val currentEpisodeChangedListener = ArrayList<() -> Unit>()
|
||||
private var currentPlayhead: Long = 0
|
||||
|
||||
// tmdb/meta data
|
||||
var mediaMeta: Meta? = null
|
||||
internal set
|
||||
var currentEpisodeMeta: EpisodeMeta? = null
|
||||
internal set
|
||||
var currentPlayheads = mapOf<String, PlayheadObject>()
|
||||
internal set
|
||||
var currentIntroMetadata: DatalabIntro = NoneDatalabIntro
|
||||
internal set
|
||||
// var tmdbTVSeason: TMDBTVSeason? =null
|
||||
// internal set
|
||||
|
||||
// crunchyroll episodes/playback
|
||||
var episodes = NoneEpisodes
|
||||
internal set
|
||||
var currentEpisode = NoneEpisode
|
||||
internal set
|
||||
var currentVersion = NoneVersion
|
||||
internal set
|
||||
var currentStreams = NoneStreams
|
||||
internal set
|
||||
|
||||
// current playback settings
|
||||
var currentAudioLocale: Locale = Preferences.preferredAudioLocale
|
||||
internal set
|
||||
var currentSubtitleLocale: Locale = Preferences.preferredSubtitleLocale
|
||||
internal set
|
||||
|
||||
init {
|
||||
// disable platform diagnostics since they might be shared with google
|
||||
ExoPlayer.Builder(application).setUsePlatformDiagnostics(false)
|
||||
|
||||
initMediaSession()
|
||||
|
||||
player.addListener(object : Player.Listener {
|
||||
override fun onPlaybackStateChanged(state: Int) {
|
||||
super.onPlaybackStateChanged(state)
|
||||
|
||||
if (state == ExoPlayer.STATE_ENDED) updatePlayhead()
|
||||
}
|
||||
|
||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||
super.onIsPlayingChanged(isPlaying)
|
||||
|
||||
if (!isPlaying) updatePlayhead()
|
||||
}
|
||||
})
|
||||
|
||||
playheadAutoUpdate = Timer().scheduleAtFixedRate(0, 30000) {
|
||||
viewModelScope.launch {
|
||||
if (player.isPlaying){
|
||||
updatePlayhead()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
|
||||
mediaSession.release()
|
||||
player.release()
|
||||
|
||||
Log.d(classTag, "Released player")
|
||||
}
|
||||
|
||||
/**
|
||||
* set the media session to active
|
||||
* create a media session connector to set title and description
|
||||
*/
|
||||
private fun initMediaSession() {
|
||||
val mediaSessionConnector = MediaSessionConnector(mediaSession)
|
||||
mediaSessionConnector.setPlayer(player)
|
||||
|
||||
mediaSession.isActive = true
|
||||
}
|
||||
|
||||
fun loadMediaAsync(seasonId: String, episodeId: String) = viewModelScope.launch {
|
||||
episodes = Crunchyroll.episodes(seasonId)
|
||||
|
||||
listOf(
|
||||
viewModelScope.launch { mediaMeta = loadMediaMeta(episodes.data.first().seriesId) },
|
||||
viewModelScope.launch {
|
||||
val episodeIDs = episodes.data.map { it.id }
|
||||
currentPlayheads = Crunchyroll.playheads(episodeIDs).toPlayheadsMap()
|
||||
}
|
||||
).joinAll()
|
||||
Log.d(classTag, "meta: $mediaMeta")
|
||||
|
||||
setCurrentEpisode(episodeId)
|
||||
playCurrentMedia(currentPlayhead)
|
||||
}
|
||||
|
||||
fun setLanguage(newAudioLocale: Locale, newSubtitleLocale: Locale) {
|
||||
// TODO if the audio locale has changes update the streams, if only the subtitle locale has changed load the new stream
|
||||
if (newAudioLocale != currentAudioLocale) {
|
||||
currentAudioLocale = newAudioLocale
|
||||
|
||||
currentVersion = currentEpisode.versions?.firstOrNull {
|
||||
it.audioLocale == currentAudioLocale.toLanguageTag()
|
||||
} ?: currentEpisode.versions?.first() ?: NoneVersion
|
||||
|
||||
viewModelScope.launch {
|
||||
currentStreams = Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID)
|
||||
Log.d(classTag, currentVersion.toString())
|
||||
|
||||
playCurrentMedia(player.currentPosition)
|
||||
}
|
||||
} else if (newSubtitleLocale != currentSubtitleLocale) {
|
||||
currentSubtitleLocale = newSubtitleLocale
|
||||
playCurrentMedia(player.currentPosition)
|
||||
}
|
||||
|
||||
// else nothing has changed so no need do do anything
|
||||
}
|
||||
|
||||
// player actions
|
||||
|
||||
/**
|
||||
* Seeks to a offset position specified in milliseconds in the current MediaItem.
|
||||
* @param offset The offset position in the current MediaItem.
|
||||
*/
|
||||
fun seekToOffset(offset: Long) {
|
||||
player.seekTo(player.currentPosition + offset)
|
||||
}
|
||||
|
||||
fun togglePausePlay() {
|
||||
if (player.isPlaying) player.pause() else player.play()
|
||||
}
|
||||
|
||||
/**
|
||||
* play the next episode, if nextEpisodeId is not null
|
||||
*/
|
||||
fun playNextEpisode() = currentEpisode.nextEpisodeId?.let { nextEpisodeId ->
|
||||
updatePlayhead() // update playhead before switching to new episode
|
||||
viewModelScope.launch { setCurrentEpisode(nextEpisodeId, startPlayback = true) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Set currentEpisodeCr to the episode of the given ID
|
||||
* @param episodeId The ID of the episode you want to set currentEpisodeCr to
|
||||
*/
|
||||
suspend fun setCurrentEpisode(episodeId: String, startPlayback: Boolean = false) {
|
||||
currentEpisode = episodes.data.find { episode ->
|
||||
episode.id == episodeId
|
||||
} ?: NoneEpisode
|
||||
|
||||
// TODO improve handling of none present seasons/episodes
|
||||
// update current episode meta
|
||||
currentEpisodeMeta = if (mediaMeta is TVShowMeta && currentEpisode.episodeNumber != null) {
|
||||
(mediaMeta as TVShowMeta)
|
||||
.seasons.getOrNull(currentEpisode.seasonNumber - 1)
|
||||
?.episodes?.getOrNull(currentEpisode.episodeNumber!! - 1)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
// update player gui (title, next ep button) after currentEpisode has changed
|
||||
currentEpisodeChangedListener.forEach { it() }
|
||||
|
||||
// needs to be blocking, currentPlayback must be present when calling playCurrentMedia()
|
||||
joinAll(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
currentVersion = currentEpisode.versions?.firstOrNull {
|
||||
it.audioLocale == currentAudioLocale.toLanguageTag()
|
||||
} ?: currentEpisode.versions?.first() ?: NoneVersion
|
||||
|
||||
// get the current streams object, if no version is set, use streamsLink
|
||||
currentStreams = if (currentVersion != NoneVersion) {
|
||||
Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID)
|
||||
} else {
|
||||
Crunchyroll.streams(currentEpisode.streamsLink)
|
||||
}
|
||||
Log.d(classTag, currentVersion.toString())
|
||||
},
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
Crunchyroll.playheads(listOf(currentEpisode.id)).data.firstOrNull {
|
||||
it.contentId == currentEpisode.id
|
||||
}?.let {
|
||||
// if the episode was fully watched, start at the beginning
|
||||
currentPlayhead = if (it.fullyWatched) {
|
||||
0
|
||||
} else {
|
||||
(it.playhead.times(1000)).toLong()
|
||||
}
|
||||
}
|
||||
},
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
currentIntroMetadata = Crunchyroll.datalabIntro(currentEpisode.id)
|
||||
}
|
||||
)
|
||||
Log.d(classTag, "streams: ${currentEpisode.streamsLink}")
|
||||
|
||||
if (startPlayback) {
|
||||
playCurrentMedia()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the current media from currentStreams.
|
||||
*
|
||||
* @param seekPosition The seek position for the media (default = 0).
|
||||
*/
|
||||
fun playCurrentMedia(seekPosition: Long = 0) {
|
||||
// get preferred stream url, set current language if it differs from the preferred one
|
||||
val preferredLocale = currentSubtitleLocale
|
||||
val fallbackLocal = Locale.US
|
||||
val url = when {
|
||||
currentStreams.data[0].adaptive_hls.containsKey(preferredLocale.toLanguageTag()) -> {
|
||||
currentStreams.data[0].adaptive_hls[preferredLocale.toLanguageTag()]?.url
|
||||
}
|
||||
currentStreams.data[0].adaptive_hls.containsKey(fallbackLocal.toLanguageTag()) -> {
|
||||
currentSubtitleLocale = fallbackLocal
|
||||
currentStreams.data[0].adaptive_hls[fallbackLocal.toLanguageTag()]?.url
|
||||
}
|
||||
else -> {
|
||||
// if no language tag is present use the first entry
|
||||
currentSubtitleLocale = Locale.ROOT
|
||||
currentStreams.data[0].adaptive_hls.entries.first().value.url
|
||||
}
|
||||
}
|
||||
Log.i(classTag, "stream url: $url")
|
||||
|
||||
// create the media item
|
||||
val mediaItem = MediaItem.fromUri(Uri.parse(url))
|
||||
player.setMediaItem(mediaItem)
|
||||
player.prepare()
|
||||
|
||||
if (seekPosition > 0) player.seekTo(seekPosition)
|
||||
player.playWhenReady = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current episode title (with episode number, if it's a tv show)
|
||||
*/
|
||||
fun getMediaTitle(): String {
|
||||
// currentEpisode.episodeNumber defines the media type (tv show = none null, movie = null)
|
||||
return if (currentEpisode.episodeNumber != null) {
|
||||
getApplication<Application>().getString(
|
||||
R.string.component_episode_title,
|
||||
currentEpisode.episode,
|
||||
currentEpisode.title
|
||||
)
|
||||
} else {
|
||||
currentEpisode.title
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current episode is the last in the episodes list.
|
||||
*
|
||||
* @return Boolean: true if it is the last, else false.
|
||||
*/
|
||||
fun currentEpisodeIsLastEpisode(): Boolean {
|
||||
return episodes.data.lastOrNull()?.id == currentEpisode.id
|
||||
}
|
||||
|
||||
private suspend fun loadMediaMeta(crSeriesId: String): Meta? {
|
||||
return MetaDBController.getTVShowMetadata(crSeriesId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the playhead of the current episode, if currentPosition > 1000ms.
|
||||
*/
|
||||
private fun updatePlayhead() {
|
||||
val playhead = (player.currentPosition / 1000)
|
||||
|
||||
if (playhead > 0 && Preferences.updatePlayhead) {
|
||||
// don't use viewModelScope here. This task may needs to finish, when ViewModel will be cleared
|
||||
CoroutineScope(Dispatchers.IO).launch { Crunchyroll.postPlayheads(currentEpisode.id, playhead.toInt()) }
|
||||
Log.i(javaClass.name, "Set playhead for episode ${currentEpisode.id} to $playhead sec.")
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
val episodeIDs = episodes.data.map { it.id }
|
||||
currentPlayheads = Crunchyroll.playheads(episodeIDs).toPlayheadsMap()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package org.mosad.teapod.ui.activity.player.fragment
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.PlayerEpisodesListBinding
|
||||
import org.mosad.teapod.ui.activity.player.PlayerViewModel
|
||||
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
|
||||
import org.mosad.teapod.util.hideBars
|
||||
|
||||
class EpisodeListDialogFragment : DialogFragment() {
|
||||
|
||||
private lateinit var model: PlayerViewModel
|
||||
private lateinit var binding: PlayerEpisodesListBinding
|
||||
|
||||
companion object {
|
||||
const val TAG = "LanguageSettingsDialogFragment"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setStyle(STYLE_NO_TITLE, R.style.FullScreenDialogStyle)
|
||||
model = ViewModelProvider(requireActivity())[PlayerViewModel::class.java]
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = PlayerEpisodesListBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.buttonCloseEpisodesList.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
val adapterRecEpisodes = EpisodeItemAdapter(
|
||||
model.episodes.data,
|
||||
null,
|
||||
model.currentPlayheads,
|
||||
EpisodeItemAdapter.OnClickListener { episode ->
|
||||
dismiss()
|
||||
// TODO make this none blocking, if necessary?
|
||||
runBlocking {
|
||||
model.setCurrentEpisode(episode.id, startPlayback = true)
|
||||
}
|
||||
},
|
||||
EpisodeItemAdapter.ViewType.PLAYER
|
||||
)
|
||||
|
||||
// get the position/index of the currently playing episode
|
||||
adapterRecEpisodes.currentSelected = model.episodes.data.indexOfFirst { it.id == model.currentEpisode.id }
|
||||
|
||||
binding.recyclerEpisodesPlayer.adapter = adapterRecEpisodes
|
||||
binding.recyclerEpisodesPlayer.scrollToPosition(adapterRecEpisodes.currentSelected)
|
||||
|
||||
// initially hide the status and navigation bar
|
||||
hideBars(requireDialog().window, binding.root)
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
model.player.play()
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
package org.mosad.teapod.ui.activity.player.fragment
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.children
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.PlayerLanguageSettingsBinding
|
||||
import org.mosad.teapod.ui.activity.player.PlayerViewModel
|
||||
import org.mosad.teapod.util.hideBars
|
||||
import java.util.*
|
||||
|
||||
class LanguageSettingsDialogFragment : DialogFragment() {
|
||||
|
||||
private lateinit var model: PlayerViewModel
|
||||
private lateinit var binding: PlayerLanguageSettingsBinding
|
||||
|
||||
private var selectedSubtitleLocale = Locale.ROOT
|
||||
private var selectedAudioLocale = Locale.ROOT
|
||||
|
||||
companion object {
|
||||
const val TAG = "LanguageSettingsDialogFragment"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setStyle(STYLE_NO_TITLE, R.style.FullScreenDialogStyle)
|
||||
model = ViewModelProvider(requireActivity())[PlayerViewModel::class.java]
|
||||
selectedSubtitleLocale = model.currentSubtitleLocale
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = PlayerLanguageSettingsBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
var selectedSubtitleView: TextView? = null
|
||||
model.currentStreams.data[0].adaptive_hls.keys.forEach { languageTag ->
|
||||
val locale = Locale.forLanguageTag(languageTag)
|
||||
val subtitleView = addLanguage(binding.linearSubtitleLanguages, locale) { v ->
|
||||
selectedSubtitleLocale = locale
|
||||
updateSelectedLanguage(binding.linearSubtitleLanguages, v as TextView)
|
||||
}
|
||||
|
||||
// if the view is the currently selected one, highlight it
|
||||
if (locale == model.currentSubtitleLocale) {
|
||||
selectedSubtitleView = subtitleView
|
||||
updateSelectedLanguage(binding.linearSubtitleLanguages, subtitleView)
|
||||
}
|
||||
}
|
||||
|
||||
val currentAudioLocal = Locale.forLanguageTag(model.currentVersion.audioLocale)
|
||||
var selectedAudioView: TextView? = null
|
||||
model.currentEpisode.versions?.forEach { version ->
|
||||
val locale = Locale.forLanguageTag(version.audioLocale)
|
||||
val audioView = addLanguage(binding.linearAudioLanguages, locale) { v ->
|
||||
selectedAudioLocale = locale
|
||||
updateSelectedLanguage(binding.linearAudioLanguages, v as TextView)
|
||||
}
|
||||
|
||||
// if the view is the currently selected one, highlight it
|
||||
if (locale == currentAudioLocal) {
|
||||
selectedAudioView = audioView
|
||||
updateSelectedLanguage(binding.linearAudioLanguages, audioView)
|
||||
}
|
||||
}
|
||||
|
||||
binding.buttonCloseLanguageSettings.setOnClickListener { dismiss() }
|
||||
binding.buttonCancel.setOnClickListener { dismiss() }
|
||||
binding.buttonSelect.setOnClickListener {
|
||||
lifecycleScope.launch {
|
||||
model.setLanguage(selectedAudioLocale, selectedSubtitleLocale)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
// initially hide the status and navigation bar
|
||||
hideBars(requireDialog().window, binding.root)
|
||||
|
||||
// scroll to the position of the view, if it's the selected language
|
||||
binding.scrollSubtitleLanguages.post {
|
||||
binding.scrollSubtitleLanguages.scrollTo(0, selectedSubtitleView?.top ?: 0)
|
||||
}
|
||||
|
||||
binding.scrollAudioLanguages.post {
|
||||
binding.scrollSubtitleLanguages.scrollTo(0, selectedAudioView?.top ?: 0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
model.player.play()
|
||||
}
|
||||
|
||||
private fun addLanguage(linear: LinearLayout, locale: Locale, onClick: View.OnClickListener): TextView {
|
||||
val text = TextView(context).apply {
|
||||
height = 96
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
text = if (locale == Locale.ROOT) context.getString(R.string.no_subtitles) else locale.displayLanguage
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
setTextColor(context.resources.getColor(R.color.player_text, context.theme))
|
||||
setPadding(75, 0, 0, 0)
|
||||
|
||||
setOnClickListener(onClick)
|
||||
}
|
||||
|
||||
linear.addView(text)
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights the selected audio/subtitle language
|
||||
*
|
||||
* @param languageLayout The audio/subtitle Layout to update
|
||||
* @param selected The newly selected language TextView
|
||||
*/
|
||||
private fun updateSelectedLanguage(languageLayout: LinearLayout, selected: TextView) {
|
||||
// rest all tf to not selected style
|
||||
languageLayout.children.forEach { child ->
|
||||
if (child is TextView) {
|
||||
child.apply {
|
||||
setTextColor(context.resources.getColor(R.color.player_text, context.theme))
|
||||
setTypeface(null, Typeface.NORMAL)
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0)
|
||||
setPadding(75, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set selected to selected style
|
||||
selected.apply {
|
||||
setTextColor(context.resources.getColor(R.color.player_white, context.theme))
|
||||
setTypeface(null, Typeface.BOLD)
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_baseline_check_24, 0, 0, 0)
|
||||
setPadding(0, 0, 0, 0)
|
||||
compoundDrawablesRelative.getOrNull(0)?.setTint(Color.WHITE)
|
||||
compoundDrawablePadding = 12
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.mosad.teapod.ui.components
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.KeyEvent
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.R
|
||||
import androidx.appcompat.widget.SearchView
|
||||
|
||||
// see https://stackoverflow.com/questions/30046201/android-searchview-empty-query-doesnt-work
|
||||
class EmptySubmitSearchView : SearchView {
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||
|
||||
override fun setOnQueryTextListener(listener: OnQueryTextListener?) {
|
||||
super.setOnQueryTextListener(listener)
|
||||
|
||||
findViewById<SearchAutoComplete?>(R.id.search_src_text).setOnEditorActionListener { _: TextView?, _: Int, event: KeyEvent? ->
|
||||
if (event != null && event.keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
listener?.onQueryTextSubmit(query.toString())
|
||||
} else {
|
||||
listener?.onQueryTextSubmit(query.toString())
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package org.mosad.teapod.ui.components
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ButtonFastForwardBinding
|
||||
|
||||
class FastForwardButton(context: Context, attrs: AttributeSet?): FrameLayout(context, attrs) {
|
||||
|
||||
private val binding = ButtonFastForwardBinding.inflate(LayoutInflater.from(context))
|
||||
private val animationDuration: Long = 800
|
||||
private val buttonAnimation: ObjectAnimator
|
||||
private val labelAnimation: ObjectAnimator
|
||||
|
||||
var onAnimationEndCallback: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
addView(binding.root)
|
||||
|
||||
buttonAnimation = ObjectAnimator.ofFloat(binding.imageButton, View.ROTATION, 0f, 50f).apply {
|
||||
duration = animationDuration / 4
|
||||
repeatCount = 1
|
||||
repeatMode = ObjectAnimator.REVERSE
|
||||
addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
binding.imageButton.isEnabled = false // disable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_forward_24)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
labelAnimation = ObjectAnimator.ofFloat(binding.textView, View.TRANSLATION_X, 35f).apply {
|
||||
duration = animationDuration
|
||||
addListener(object : AnimatorListenerAdapter() {
|
||||
// the label animation takes longer then the button animation, reset stuff in here
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
binding.imageButton.isEnabled = true // enable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_forward_10_24)
|
||||
|
||||
binding.textView.visibility = View.GONE
|
||||
binding.textView.animate().translationX(0f)
|
||||
|
||||
onAnimationEndCallback?.invoke()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnButtonClickListener(func: FastForwardButton.() -> Unit) {
|
||||
binding.imageButton.setOnClickListener {
|
||||
func()
|
||||
}
|
||||
}
|
||||
|
||||
fun runOnClickAnimation() {
|
||||
// run button animation
|
||||
buttonAnimation.start()
|
||||
|
||||
// run lbl animation
|
||||
binding.textView.visibility = View.VISIBLE
|
||||
labelAnimation.start()
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/**
|
||||
* ProjectLaogai
|
||||
*
|
||||
* Copyright 2019-2020 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.ui.components
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.EditText
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
import com.afollestad.materialdialogs.bottomsheets.setPeekHeight
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import com.afollestad.materialdialogs.customview.getCustomView
|
||||
import org.mosad.teapod.R
|
||||
|
||||
class LoginDialog(val context: Context, firstTry: Boolean) {
|
||||
|
||||
private val dialog = MaterialDialog(context, BottomSheet())
|
||||
|
||||
private val editTextLogin: EditText
|
||||
private val editTextPassword: EditText
|
||||
|
||||
var login = ""
|
||||
var password = ""
|
||||
|
||||
init {
|
||||
dialog.title(R.string.login)
|
||||
.message(if (firstTry) R.string.login_desc else R.string.login_failed_desc)
|
||||
.customView(R.layout.dialog_login)
|
||||
.positiveButton(R.string.save)
|
||||
.negativeButton(R.string.cancel)
|
||||
.setPeekHeight(900)
|
||||
|
||||
editTextLogin = dialog.getCustomView().findViewById(R.id.edit_text_login)
|
||||
editTextPassword = dialog.getCustomView().findViewById(R.id.edit_text_password)
|
||||
|
||||
// fix not working accent color
|
||||
//dialog.getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.colorAccent)
|
||||
//dialog.getActionButton(WhichButton.NEGATIVE).updateTextColor(Preferences.colorAccent)
|
||||
}
|
||||
|
||||
fun positiveButton(func: LoginDialog.() -> Unit): LoginDialog = apply {
|
||||
dialog.positiveButton {
|
||||
login = editTextLogin.text.toString()
|
||||
password = editTextPassword.text.toString()
|
||||
|
||||
func()
|
||||
}
|
||||
}
|
||||
|
||||
fun negativeButton(func: LoginDialog.() -> Unit): LoginDialog = apply {
|
||||
dialog.negativeButton {
|
||||
func()
|
||||
}
|
||||
}
|
||||
|
||||
fun show() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
fun show(func: LoginDialog.() -> Unit): LoginDialog = apply {
|
||||
func()
|
||||
|
||||
editTextLogin.setText(login)
|
||||
editTextPassword.setText(password)
|
||||
|
||||
show()
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun dismiss() {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package org.mosad.teapod.ui.components
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import org.mosad.teapod.databinding.ModalBottomSheetLoginBinding
|
||||
|
||||
/**
|
||||
* A bottom sheet with login credential input fields.
|
||||
*
|
||||
* To initialize login or password values, use apply.
|
||||
*/
|
||||
class LoginModalBottomSheet : BottomSheetDialogFragment() {
|
||||
|
||||
private lateinit var binding: ModalBottomSheetLoginBinding
|
||||
|
||||
var login = ""
|
||||
var password = ""
|
||||
|
||||
lateinit var positiveAction: LoginModalBottomSheet.() -> Unit
|
||||
lateinit var negativeAction: LoginModalBottomSheet.() -> Unit
|
||||
|
||||
companion object {
|
||||
const val TAG = "LoginModalBottomSheet"
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = ModalBottomSheetLoginBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.editTextLogin.setText(login)
|
||||
binding.editTextPassword.setText(password)
|
||||
|
||||
binding.positiveButton.setOnClickListener {
|
||||
login = binding.editTextLogin.text.toString()
|
||||
password = binding.editTextPassword.text.toString()
|
||||
|
||||
positiveAction.invoke(this)
|
||||
}
|
||||
binding.negativeButton.setOnClickListener {
|
||||
negativeAction.invoke(this)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package org.mosad.teapod.ui.components
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ButtonRewindBinding
|
||||
|
||||
class RewindButton(context: Context, attrs: AttributeSet): FrameLayout(context, attrs) {
|
||||
|
||||
private val binding = ButtonRewindBinding.inflate(LayoutInflater.from(context))
|
||||
private val animationDuration: Long = 800
|
||||
private val buttonAnimation: ObjectAnimator
|
||||
private val labelAnimation: ObjectAnimator
|
||||
|
||||
var onAnimationEndCallback: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
addView(binding.root)
|
||||
|
||||
buttonAnimation = ObjectAnimator.ofFloat(binding.imageButton, View.ROTATION, 0f, -50f).apply {
|
||||
duration = animationDuration / 4
|
||||
repeatCount = 1
|
||||
repeatMode = ObjectAnimator.REVERSE
|
||||
addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
binding.imageButton.isEnabled = false // disable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_rewind_24)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
labelAnimation = ObjectAnimator.ofFloat(binding.textView, View.TRANSLATION_X, -35f).apply {
|
||||
duration = animationDuration
|
||||
addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
binding.imageButton.isEnabled = true // enable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_rewind_10_24)
|
||||
|
||||
binding.textView.visibility = View.GONE
|
||||
binding.textView.animate().translationX(0f)
|
||||
|
||||
onAnimationEndCallback?.invoke()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun setOnButtonClickListener(func: RewindButton.() -> Unit) {
|
||||
binding.imageButton.setOnClickListener {
|
||||
func()
|
||||
}
|
||||
}
|
||||
|
||||
fun runOnClickAnimation() {
|
||||
// run button animation
|
||||
buttonAnimation.start()
|
||||
|
||||
// run lbl animation
|
||||
binding.textView.visibility = View.VISIBLE
|
||||
labelAnimation.start()
|
||||
}
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import de.psdev.licensesdialog.LicensesDialog
|
||||
import kotlinx.android.synthetic.main.fragment_account.*
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.ui.components.LoginDialog
|
||||
|
||||
class AccountFragment : Fragment() {
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_account, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
text_account_login.text = EncryptedPreferences.login
|
||||
text_info_about_desc.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
|
||||
|
||||
initActions()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
linear_account_login.setOnClickListener {
|
||||
showLoginDialog(true)
|
||||
}
|
||||
|
||||
linear_about.setOnClickListener {
|
||||
MaterialDialog(requireContext())
|
||||
.title(R.string.info_about)
|
||||
.message(R.string.info_about_dialog)
|
||||
.show()
|
||||
}
|
||||
|
||||
text_licenses.setOnClickListener {
|
||||
LicensesDialog.Builder(requireContext())
|
||||
.setNotices(R.raw.notices)
|
||||
.setTitle(R.string.licenses)
|
||||
.setIncludeOwnLicense(true)
|
||||
.setThemeResourceId(R.style.AppTheme)
|
||||
.build()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLoginDialog(firstTry: Boolean) {
|
||||
LoginDialog(requireContext(), firstTry).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
|
||||
if (!AoDParser().login()) {
|
||||
showLoginDialog(false)
|
||||
Log.w(javaClass.name, "Login failed, please try again.")
|
||||
}
|
||||
}.show {
|
||||
login = EncryptedPreferences.login
|
||||
password = ""
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mosad.teapod.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.util.adapter.MediaItemAdapter
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: MediaItemAdapter
|
||||
private lateinit var layoutManager: LinearLayoutManager
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_home, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
GlobalScope.launch {
|
||||
if (AoDParser.mediaList.isEmpty()) {
|
||||
AoDParser().listAnimes()
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
context?.let {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
recycler_my_list.layoutManager = layoutManager
|
||||
recycler_my_list.addItemDecoration(MediaItemDecoration(9))
|
||||
|
||||
updateMyListMedia()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO recreating the adapter on list change is not a good solution
|
||||
fun updateMyListMedia() {
|
||||
val myListMedia = StorageController.myList.map { elementId ->
|
||||
AoDParser.itemMediaList.first {
|
||||
elementId == it.id
|
||||
}
|
||||
}
|
||||
|
||||
adapter = MediaItemAdapter(myListMedia)
|
||||
adapter.onItemClick = { mediaId, _ ->
|
||||
(activity as MainActivity).showMediaFragment(mediaId)
|
||||
}
|
||||
|
||||
recycler_my_list.adapter = adapter
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.android.synthetic.main.fragment_library.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
import org.mosad.teapod.util.adapter.MediaItemAdapter
|
||||
|
||||
class LibraryFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: MediaItemAdapter
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_library, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// init async
|
||||
GlobalScope.launch {
|
||||
if (AoDParser.mediaList.isEmpty()) {
|
||||
AoDParser().listAnimes()
|
||||
}
|
||||
|
||||
// create and set the adapter, needs context
|
||||
withContext(Dispatchers.Main) {
|
||||
context?.let {
|
||||
adapter = MediaItemAdapter(AoDParser.itemMediaList)
|
||||
adapter.onItemClick = { mediaId, _ ->
|
||||
(activity as MainActivity).showMediaFragment(mediaId)
|
||||
}
|
||||
|
||||
recycler_media_library.adapter = adapter
|
||||
recycler_media_library.addItemDecoration(MediaItemDecoration(9))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.mosad.teapod.R
|
||||
|
||||
class LoadingFragment : Fragment() {
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false)
|
||||
}
|
||||
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||
import kotlinx.android.synthetic.main.fragment_media.*
|
||||
import org.mosad.teapod.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.Media
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.util.TMDBResponse
|
||||
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
|
||||
|
||||
class MediaFragment(private val media: Media, private val tmdb: TMDBResponse) : Fragment() {
|
||||
|
||||
private lateinit var adapterRecEpisodes: EpisodeItemAdapter
|
||||
private lateinit var viewManager: RecyclerView.LayoutManager
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_media, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
initGUI()
|
||||
initActions()
|
||||
}
|
||||
|
||||
/**
|
||||
* if tmdb data is present, use it, else use the aod data
|
||||
*/
|
||||
private fun initGUI() {
|
||||
// generic gui
|
||||
val backdropUrl = if (tmdb.backdropUrl.isNotEmpty()) tmdb.backdropUrl else media.info.posterUrl
|
||||
val posterUrl = if (tmdb.posterUrl.isNotEmpty()) tmdb.posterUrl else media.info.posterUrl
|
||||
|
||||
Glide.with(requireContext()).load(backdropUrl)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3)))
|
||||
.into(image_backdrop)
|
||||
|
||||
Glide.with(requireContext()).load(posterUrl)
|
||||
.into(image_poster)
|
||||
|
||||
text_title.text = media.info.title
|
||||
text_year.text = media.info.year.toString()
|
||||
text_age.text = media.info.age.toString()
|
||||
text_overview.text = media.info.shortDesc
|
||||
if (StorageController.myList.contains(media.id)) {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(image_my_list_action)
|
||||
} else {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(image_my_list_action)
|
||||
}
|
||||
|
||||
// specific gui
|
||||
if (media.type == MediaType.TVSHOW) {
|
||||
adapterRecEpisodes = EpisodeItemAdapter(media.episodes)
|
||||
viewManager = LinearLayoutManager(context)
|
||||
recycler_episodes.layoutManager = viewManager
|
||||
recycler_episodes.adapter = adapterRecEpisodes
|
||||
|
||||
text_episodes_or_runtime.text = getString(R.string.text_episodes_count, media.info.episodesCount)
|
||||
} else if (media.type == MediaType.MOVIE) {
|
||||
recycler_episodes.visibility = View.GONE
|
||||
|
||||
if (tmdb.runtime > 0) {
|
||||
text_episodes_or_runtime.text = getString(R.string.text_runtime, tmdb.runtime)
|
||||
} else {
|
||||
text_episodes_or_runtime.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
button_play.setOnClickListener {
|
||||
when (media.type) {
|
||||
MediaType.MOVIE -> playStream(media.episodes.first().streamUrl)
|
||||
MediaType.TVSHOW -> playStream(media.episodes.first().streamUrl)
|
||||
else -> Log.e(javaClass.name, "Wrong Type: $media.type")
|
||||
}
|
||||
}
|
||||
|
||||
// add or remove media from myList
|
||||
linear_my_list_action.setOnClickListener {
|
||||
if (StorageController.myList.contains(media.id)) {
|
||||
StorageController.myList.remove(media.id)
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(image_my_list_action)
|
||||
} else {
|
||||
StorageController.myList.add(media.id)
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(image_my_list_action)
|
||||
}
|
||||
StorageController.saveMyList(requireContext())
|
||||
|
||||
// notify home fragment on change
|
||||
parentFragmentManager.findFragmentByTag("HomeFragment")?.let {
|
||||
(it as HomeFragment).updateMyListMedia()
|
||||
}
|
||||
}
|
||||
|
||||
// set onItemClick only in adapter is initialized
|
||||
if (this::adapterRecEpisodes.isInitialized) {
|
||||
adapterRecEpisodes.onImageClick = { _, position ->
|
||||
playStream(media.episodes[position].streamUrl)
|
||||
|
||||
// update watched state
|
||||
AoDParser().sendCallback(media.episodes[position].watchedCallback)
|
||||
adapterRecEpisodes.updateWatchedState(true, position)
|
||||
adapterRecEpisodes.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun playStream(url: String) {
|
||||
Log.d(javaClass.name, "Playing stream: $url")
|
||||
(activity as MainActivity).startPlayer(url)
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package org.mosad.teapod.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.android.synthetic.main.fragment_search.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.mosad.teapod.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
import org.mosad.teapod.util.adapter.MediaItemAdapter
|
||||
|
||||
class SearchFragment : Fragment() {
|
||||
|
||||
private var adapter : MediaItemAdapter? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_search, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
GlobalScope.launch {
|
||||
if (AoDParser.mediaList.isEmpty()) {
|
||||
AoDParser().listAnimes()
|
||||
}
|
||||
|
||||
// create and set the adapter, needs context
|
||||
withContext(Dispatchers.Main) {
|
||||
context?.let {
|
||||
adapter = MediaItemAdapter(AoDParser.itemMediaList)
|
||||
adapter!!.onItemClick = { mediaId, _ ->
|
||||
search_text.clearFocus()
|
||||
(activity as MainActivity).showMediaFragment(mediaId)
|
||||
}
|
||||
|
||||
recycler_media_search.adapter = adapter
|
||||
recycler_media_search.addItemDecoration(MediaItemDecoration(9))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initActions()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
search_text.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
adapter?.filter?.filter(query)
|
||||
adapter?.notifyDataSetChanged()
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
adapter?.filter?.filter(newText)
|
||||
adapter?.notifyDataSetChanged()
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
63
app/src/main/java/org/mosad/teapod/util/ActivityUtils.kt
Normal file
63
app/src/main/java/org/mosad/teapod/util/ActivityUtils.kt
Normal file
@ -0,0 +1,63 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.fragment.app.commit
|
||||
import org.mosad.teapod.R
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* Show a fragment on top of the current fragment.
|
||||
* The current fragment is replaced and the new one is added
|
||||
* to the back stack.
|
||||
*/
|
||||
fun FragmentActivity.showFragment(fragment: Fragment) {
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.nav_host_fragment, fragment, fragment.javaClass.simpleName)
|
||||
addToBackStack(fragment.javaClass.name)
|
||||
show(fragment)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the status and navigation bar
|
||||
*/
|
||||
fun Activity.hideBars() {
|
||||
hideBars(window, window.decorView.rootView)
|
||||
}
|
||||
|
||||
fun Activity.isInPiPMode(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
isInPictureInPictureMode
|
||||
} else {
|
||||
false // pip mode not supported
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring up launcher task to front
|
||||
*/
|
||||
fun Activity.navToLauncherTask() {
|
||||
val activityManager = (getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager)
|
||||
activityManager.appTasks.forEach { task ->
|
||||
val baseIntent = task.taskInfo.baseIntent
|
||||
val categories = baseIntent.categories
|
||||
if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
|
||||
task.moveToFront()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* exit and remove the app from tasks
|
||||
*/
|
||||
fun Activity.exitAndRemoveTask() {
|
||||
finishAndRemoveTask()
|
||||
exitProcess(0)
|
||||
}
|
@ -1,62 +1,138 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
class DataTypes {
|
||||
enum class MediaType {
|
||||
OTHER,
|
||||
MOVIE,
|
||||
TVSHOW
|
||||
enum class MediaType(val str: String) {
|
||||
OTHER("other"),
|
||||
MOVIE("movie"), // TODO
|
||||
TVSHOW("series")
|
||||
}
|
||||
|
||||
enum class Theme(val str: String) {
|
||||
SYSTEM("System"),
|
||||
LIGHT("Light"),
|
||||
DARK("Dark")
|
||||
}
|
||||
|
||||
enum class License(val short: String, val long: String) {
|
||||
APACHE2("AL 2.0", "Apache License Version 2.0"),
|
||||
MIT("MIT", "MIT License"),
|
||||
GPL3("GPL 3", "GNU General Public License Version 3"),
|
||||
BSD2("BSD 2", "BSD 2-Clause License")
|
||||
}
|
||||
}
|
||||
|
||||
data class ThirdPartyComponent(
|
||||
val name: String,
|
||||
val year: String,
|
||||
val copyrightOwner: String,
|
||||
val link: String,
|
||||
val license: DataTypes.License
|
||||
)
|
||||
|
||||
/**
|
||||
* this class is used to represent the item media
|
||||
* it is uses in the ItemMediaAdapter (RecyclerView)
|
||||
*/
|
||||
data class ItemMedia(
|
||||
val id: Int,
|
||||
val id: String,
|
||||
val title: String,
|
||||
val posterUrl: String
|
||||
val posterUrl: String,
|
||||
)
|
||||
|
||||
// TODO replace playlist: List<AoDEpisode> with a map?
|
||||
data class AoDMedia(
|
||||
val aodId: Int,
|
||||
val type: DataTypes.MediaType,
|
||||
val title: String,
|
||||
val shortText: String,
|
||||
val posterURL: String,
|
||||
var year: Int,
|
||||
var age: Int,
|
||||
val similar: List<ItemMedia>,
|
||||
val playlist: List<AoDEpisode>,
|
||||
) {
|
||||
fun getEpisodeById(mediaId: Int) = playlist.firstOrNull { it.mediaId == mediaId }
|
||||
?: AoDEpisodeNone
|
||||
}
|
||||
|
||||
data class AoDEpisode(
|
||||
val mediaId: Int,
|
||||
val title: String,
|
||||
val description: String,
|
||||
val shortDesc: String,
|
||||
val imageURL: String,
|
||||
val numberStr: String,
|
||||
val index: Int,
|
||||
var watched: Boolean,
|
||||
val watchedCallback: String,
|
||||
val streams: MutableList<Stream>,
|
||||
){
|
||||
fun hasDub() = streams.any { it.language == Locale.GERMAN }
|
||||
|
||||
/**
|
||||
* get the preferred stream
|
||||
* @return the preferred stream, if not present use the first stream
|
||||
*/
|
||||
fun getPreferredStream(language: Locale) = streams.firstOrNull { it.language == language }
|
||||
?: Stream("", Locale.ROOT)
|
||||
}
|
||||
|
||||
data class Stream(
|
||||
val url: String,
|
||||
val language : Locale
|
||||
)
|
||||
|
||||
// TODO will be watched info (state and callback) -> remove description and number
|
||||
data class AoDEpisodeInfo(
|
||||
val aodMediaId: Int,
|
||||
val shortDesc: String,
|
||||
var watched: Boolean,
|
||||
val watchedCallback: String,
|
||||
)
|
||||
|
||||
val AoDMediaNone = AoDMedia(
|
||||
-1,
|
||||
DataTypes.MediaType.OTHER,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
-1,
|
||||
listOf(),
|
||||
listOf()
|
||||
)
|
||||
|
||||
val AoDEpisodeNone = AoDEpisode(
|
||||
-1,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
true,
|
||||
"",
|
||||
mutableListOf()
|
||||
)
|
||||
|
||||
/**
|
||||
* TODO the episodes workflow could use a clean up/rework
|
||||
* this class is used to represent the aod json API?
|
||||
*/
|
||||
data class Media(
|
||||
val id: Int,
|
||||
val link: String,
|
||||
val type: DataTypes.MediaType,
|
||||
val info: Info = Info(),
|
||||
var episodes: List<Episode> = listOf()
|
||||
data class AoDPlaylist(
|
||||
val list: List<Playlist>,
|
||||
val language: Locale
|
||||
)
|
||||
|
||||
data class Info(
|
||||
var title: String = "",
|
||||
var posterUrl: String = "",
|
||||
var shortDesc: String = "",
|
||||
var description: String = "",
|
||||
var year: Int = 0,
|
||||
var age: Int = 0,
|
||||
var episodesCount: Int = 0
|
||||
data class Playlist(
|
||||
val sources: List<Source>,
|
||||
val image: String,
|
||||
val title: String,
|
||||
val description: String,
|
||||
val mediaid: Int
|
||||
)
|
||||
|
||||
data class Episode(
|
||||
val id: Int = 0,
|
||||
var title: String = "",
|
||||
var streamUrl: String = "",
|
||||
var posterUrl: String = "",
|
||||
var description: String = "",
|
||||
var shortDesc: String = "",
|
||||
var number: Int = 0,
|
||||
var watched: Boolean = false,
|
||||
var watchedCallback: String = ""
|
||||
)
|
||||
|
||||
data class TMDBResponse(
|
||||
val id: Int = 0,
|
||||
val title: String = "",
|
||||
val overview: String = "",
|
||||
val posterUrl: String = "",
|
||||
val backdropUrl: String = "",
|
||||
var runtime: Int = 0
|
||||
data class Source(
|
||||
val file: String = ""
|
||||
)
|
||||
|
@ -1,38 +0,0 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.content.Context
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* This controller contains the logic for permanently saved data.
|
||||
* On load, it loads the saved files into the variables
|
||||
*/
|
||||
object StorageController {
|
||||
|
||||
private const val fileNameMyList = "my_list.json"
|
||||
|
||||
val myList = ArrayList<Int>() // a list of saved mediaIds
|
||||
|
||||
fun load(context: Context) {
|
||||
val file = File(context.filesDir, fileNameMyList)
|
||||
|
||||
if (!file.exists()) runBlocking { saveMyList(context).join() }
|
||||
|
||||
myList.clear()
|
||||
myList.addAll(
|
||||
GsonBuilder().create().fromJson(file.readText(), ArrayList<Int>().javaClass)
|
||||
)
|
||||
}
|
||||
|
||||
fun saveMyList(context: Context): Job {
|
||||
val file = File(context.filesDir, fileNameMyList)
|
||||
|
||||
return GlobalScope.launch(Dispatchers.IO) {
|
||||
file.writeText(Gson().toJson(myList))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.net.URL
|
||||
import java.net.URLEncoder
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
|
||||
class TMDBApiController {
|
||||
|
||||
private val apiUrl = "https://api.themoviedb.org/3"
|
||||
private val searchMovieUrl = "$apiUrl/search/movie"
|
||||
private val searchTVUrl = "$apiUrl/search/tv"
|
||||
private val getMovieUrl = "$apiUrl/movie"
|
||||
private val apiKey = "de959cf9c07a08b5ca7cb51cda9a40c2"
|
||||
private val language = "de"
|
||||
private val preparedParameters = "?api_key=$apiKey&language=$language"
|
||||
|
||||
private val imageUrl = "https://image.tmdb.org/t/p/w500"
|
||||
|
||||
fun search(title: String, type: MediaType): TMDBResponse {
|
||||
val searchTerm = title.replace("(Sub)", "").trim()
|
||||
|
||||
return when (type) {
|
||||
MediaType.MOVIE -> searchMovie(searchTerm)
|
||||
MediaType.TVSHOW -> searchTVShow(searchTerm)
|
||||
else -> {
|
||||
Log.e(javaClass.name, "Wrong Type: $type")
|
||||
TMDBResponse()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun searchTVShow(title: String) = runBlocking {
|
||||
val url = URL("$searchTVUrl$preparedParameters&query=${URLEncoder.encode(title, "UTF-8")}")
|
||||
|
||||
GlobalScope.async {
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
//println(response)
|
||||
|
||||
return@async if (response.get("total_results").asInt > 0) {
|
||||
response.get("results").asJsonArray.first().asJsonObject.let {
|
||||
val id = getStringNotNull(it,"id").toInt()
|
||||
val overview = getStringNotNull(it,"overview")
|
||||
val posterPath = getStringNotNullPrefix(it, "poster_path", imageUrl)
|
||||
val backdropPath = getStringNotNullPrefix(it, "backdrop_path", imageUrl)
|
||||
|
||||
TMDBResponse(id, "", overview, posterPath, backdropPath)
|
||||
}
|
||||
} else {
|
||||
TMDBResponse()
|
||||
}
|
||||
}.await()
|
||||
|
||||
}
|
||||
|
||||
fun searchMovie(title: String) = runBlocking {
|
||||
val url = URL("$searchMovieUrl$preparedParameters&query=${URLEncoder.encode(title, "UTF-8")}")
|
||||
|
||||
GlobalScope.async {
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
//println(response)
|
||||
|
||||
return@async if (response.get("total_results").asInt > 0) {
|
||||
response.get("results").asJsonArray.first().asJsonObject.let {
|
||||
val id = getStringNotNull(it,"id").toInt()
|
||||
val overview = getStringNotNull(it,"overview")
|
||||
val posterPath = getStringNotNullPrefix(it, "poster_path", imageUrl)
|
||||
val backdropPath = getStringNotNullPrefix(it, "backdrop_path", imageUrl)
|
||||
val runtime = getMovieRuntime(id)
|
||||
|
||||
TMDBResponse(id, "", overview, posterPath, backdropPath, runtime)
|
||||
}
|
||||
} else {
|
||||
TMDBResponse()
|
||||
}
|
||||
|
||||
|
||||
}.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* currently only used for runtime, need a rework
|
||||
*/
|
||||
fun getMovieRuntime(id: Int): Int = runBlocking {
|
||||
val url = URL("$getMovieUrl/$id?api_key=$apiKey&language=$language")
|
||||
|
||||
GlobalScope.async {
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
//println(response)
|
||||
|
||||
val runtime = getStringNotNull(response,"runtime").toInt()
|
||||
println(runtime)
|
||||
|
||||
|
||||
return@async runtime
|
||||
}.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* return memberName as string if it's not JsonNull,
|
||||
* else return an empty string
|
||||
*/
|
||||
private fun getStringNotNull(jsonObject: JsonObject, memberName: String): String {
|
||||
return getStringNotNullPrefix(jsonObject, memberName, "")
|
||||
}
|
||||
|
||||
/**
|
||||
* return memberName as string with a prefix if it's not JsonNull,
|
||||
* else return an empty string
|
||||
*/
|
||||
private fun getStringNotNullPrefix(jsonObject: JsonObject, memberName: String, prefix: String): String {
|
||||
return if (!jsonObject.get(memberName).isJsonNull) {
|
||||
prefix + jsonObject.get(memberName).asString
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
73
app/src/main/java/org/mosad/teapod/util/Utils.kt
Normal file
73
app/src/main/java/org/mosad/teapod/util/Utils.kt
Normal file
@ -0,0 +1,73 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.crunchyroll.CollectionV2
|
||||
import org.mosad.teapod.parser.crunchyroll.Item
|
||||
import org.mosad.teapod.parser.crunchyroll.PlayheadObject
|
||||
import org.mosad.teapod.ui.activity.player.PlayerActivity
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Create a Intent for PlayerActivity with season and episode id.
|
||||
*
|
||||
* @param seasonId The ID of the season the episode to be played is in
|
||||
* @param episodeId The ID of the episode to play
|
||||
*/
|
||||
fun Fragment.playerIntent(seasonId: String, episodeId: String) = Intent(context, PlayerActivity::class.java).apply {
|
||||
putExtra(getString(R.string.intent_season_id), seasonId)
|
||||
putExtra(getString(R.string.intent_episode_id), episodeId)
|
||||
}
|
||||
|
||||
fun TextView.setDrawableTop(drawable: Int) {
|
||||
this.setCompoundDrawablesWithIntrinsicBounds(0, drawable, 0, 0)
|
||||
}
|
||||
|
||||
fun <T> concatenate(vararg lists: List<T>): List<T> {
|
||||
return listOf(*lists).flatten()
|
||||
}
|
||||
|
||||
// TODO move to correct location
|
||||
fun CollectionV2<Item>.toItemMediaList(): List<ItemMedia> {
|
||||
return this.data.map {
|
||||
ItemMedia(it.id, it.title, it.images.poster_wide[0][0].source)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("toItemMediaListItem")
|
||||
fun List<Item>.toItemMediaList(): List<ItemMedia> {
|
||||
return this.map {
|
||||
ItemMedia(it.id, it.title, it.images.poster_wide[0][0].source)
|
||||
}
|
||||
}
|
||||
|
||||
fun Locale.toDisplayString(fallback: String): String {
|
||||
return if (this.displayLanguage.isNotEmpty() && this.displayCountry.isNotEmpty()) {
|
||||
"${this.displayLanguage} (${this.displayCountry})"
|
||||
} else if (this.displayCountry.isNotEmpty()) {
|
||||
this.displayLanguage
|
||||
} else {
|
||||
fallback
|
||||
}
|
||||
}
|
||||
|
||||
fun CollectionV2<PlayheadObject>.toPlayheadsMap(): Map<String, PlayheadObject> {
|
||||
return this.data.associateBy { it.contentId }
|
||||
}
|
||||
|
||||
fun hideBars(window: Window?, root: View) {
|
||||
if (window != null) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
WindowInsetsControllerCompat(window, root).let { controller ->
|
||||
controller.hide(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars())
|
||||
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -8,43 +11,54 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
|
||||
import kotlinx.android.synthetic.main.item_episode.view.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.databinding.ItemEpisodeBinding
|
||||
import org.mosad.teapod.databinding.ItemEpisodePlayerBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.Episode
|
||||
import org.mosad.teapod.parser.crunchyroll.PlayheadObject
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVEpisode
|
||||
|
||||
class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Adapter<EpisodeItemAdapter.MyViewHolder>() {
|
||||
class EpisodeItemAdapter(
|
||||
private val episodes: List<Episode>,
|
||||
private val tmdbEpisodes: List<TMDBTVEpisode>?,
|
||||
private val playheads: Map<String, PlayheadObject>,
|
||||
private val onClickListener: OnClickListener,
|
||||
private val viewType: ViewType
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
var onItemClick: ((String, Int) -> Unit)? = null
|
||||
var onImageClick: ((String, Int) -> Unit)? = null
|
||||
var currentSelected: Int = -1 // -1, since position should never be < 0
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_episode, parent, false)
|
||||
|
||||
return MyViewHolder(view)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return when (viewType) {
|
||||
ViewType.PLAYER.ordinal -> {
|
||||
PlayerEpisodeViewHolder((ItemEpisodePlayerBinding.inflate(LayoutInflater.from(parent.context), parent, false)))
|
||||
}
|
||||
else -> {
|
||||
// media fragment episode list is default
|
||||
EpisodeViewHolder(ItemEpisodeBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
val context = holder.view.context
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
val episode = episodes[position]
|
||||
val playhead = playheads[episode.id]
|
||||
val tmdbEpisode = tmdbEpisodes?.getOrNull(position)
|
||||
|
||||
holder.view.text_episode_title.text = context.getString(
|
||||
R.string.component_episode_title,
|
||||
episodes[position].number,
|
||||
episodes[position].description
|
||||
)
|
||||
holder.view.text_episode_desc.text = episodes[position].shortDesc
|
||||
|
||||
if (episodes[position].posterUrl.isNotEmpty()) {
|
||||
Glide.with(context).load(episodes[position].posterUrl)
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(holder.view.image_episode)
|
||||
when (holder.itemViewType) {
|
||||
ViewType.MEDIA_FRAGMENT.ordinal -> {
|
||||
(holder as EpisodeViewHolder).bind(episode, playhead, tmdbEpisode)
|
||||
}
|
||||
ViewType.PLAYER.ordinal -> {
|
||||
(holder as PlayerEpisodeViewHolder).bind(episode, playhead, currentSelected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (episodes[position].watched) {
|
||||
holder.view.image_watched.setImageDrawable(
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_circle_24)
|
||||
)
|
||||
} else {
|
||||
holder.view.image_watched.setImageDrawable(null)
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (viewType) {
|
||||
ViewType.MEDIA_FRAGMENT -> ViewType.MEDIA_FRAGMENT.ordinal
|
||||
ViewType.PLAYER -> ViewType.PLAYER.ordinal
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,19 +66,113 @@ class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Ada
|
||||
return episodes.size
|
||||
}
|
||||
|
||||
fun updateWatchedState(watched: Boolean, position: Int) {
|
||||
episodes[position].watched = watched
|
||||
}
|
||||
inner class EpisodeViewHolder(val binding: ItemEpisodeBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
inner class MyViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
onItemClick?.invoke(episodes[adapterPosition].title, adapterPosition)
|
||||
fun bind(episode: Episode, playhead: PlayheadObject?, tmdbEpisode: TMDBTVEpisode?) {
|
||||
val context = binding.root.context
|
||||
|
||||
val titleText = if (episode.episodeNumber != null) {
|
||||
// for tv shows add ep prefix and episode number
|
||||
if (episode.isDubbed) {
|
||||
context.getString(R.string.component_episode_title, episode.episode, episode.title)
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, episode.episode, episode.title)
|
||||
}
|
||||
} else {
|
||||
episode.title
|
||||
}
|
||||
|
||||
view.image_episode.setOnClickListener {
|
||||
onImageClick?.invoke(episodes[adapterPosition].title, adapterPosition)
|
||||
binding.textEpisodeTitle.text = titleText
|
||||
binding.textEpisodeDesc.text = episode.description.ifEmpty {
|
||||
tmdbEpisode?.overview ?: ""
|
||||
}
|
||||
|
||||
if (episode.images.thumbnail[0][0].source.isNotEmpty()) {
|
||||
Glide.with(context).load(episode.images.thumbnail[0][0].source)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(binding.imageEpisode)
|
||||
}
|
||||
|
||||
// add watched progress
|
||||
val playheadProgress = playhead?.playhead?.let {
|
||||
((it.toFloat() / (episode.durationMs / 1000)) * 100).toInt()
|
||||
} ?: 0
|
||||
binding.progressPlayhead.setProgressCompat(playheadProgress, false)
|
||||
binding.progressPlayhead.visibility = if (playheadProgress <= 0)
|
||||
View.GONE else View.VISIBLE
|
||||
|
||||
// add watched icon to episode, if the episode id is present in playheads and fullyWatched
|
||||
val watchedImage: Drawable? = if (playhead?.fullyWatched == true) {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_circle_24)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
binding.imageWatched.setImageDrawable(watchedImage)
|
||||
|
||||
binding.imageEpisode.setOnClickListener {
|
||||
onClickListener.onClick(episode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class PlayerEpisodeViewHolder(val binding: ItemEpisodePlayerBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
// -1, since position should never be < 0
|
||||
fun bind(episode: Episode, playhead: PlayheadObject?, currentSelected: Int) {
|
||||
val context = binding.root.context
|
||||
|
||||
val titleText = if (episode.episodeNumber != null) {
|
||||
// for tv shows add ep prefix and episode number
|
||||
if (episode.isDubbed) {
|
||||
context.getString(R.string.component_episode_title, episode.episode, episode.title)
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, episode.episode, episode.title)
|
||||
}
|
||||
} else {
|
||||
episode.title
|
||||
}
|
||||
|
||||
binding.textEpisodeTitle2.text = titleText
|
||||
binding.textEpisodeDesc2.text = episode.description.ifEmpty { "" }
|
||||
|
||||
if (episode.images.thumbnail[0][0].source.isNotEmpty()) {
|
||||
Glide.with(context).load(episode.images.thumbnail[0][0].source)
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(binding.imageEpisode)
|
||||
}
|
||||
|
||||
// add watched progress
|
||||
val playheadProgress = playhead?.playhead?.let {
|
||||
((it.toFloat() / (episode.durationMs / 1000)) * 100).toInt()
|
||||
} ?: 0
|
||||
binding.progressPlayhead.setProgressCompat(playheadProgress, false)
|
||||
binding.progressPlayhead.visibility = if (playheadProgress <= 0)
|
||||
View.GONE else View.VISIBLE
|
||||
|
||||
// hide the play icon, if it's the current episode
|
||||
binding.imageEpisodePlay.visibility = if (currentSelected == bindingAdapterPosition) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
|
||||
if (currentSelected != bindingAdapterPosition) {
|
||||
binding.imageEpisode.setOnClickListener {
|
||||
onClickListener.onClick(episode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OnClickListener(val clickListener: (episode: Episode) -> Unit) {
|
||||
fun onClick(episode: Episode) = clickListener(episode)
|
||||
}
|
||||
|
||||
enum class ViewType {
|
||||
MEDIA_FRAGMENT,
|
||||
PLAYER
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemMediaBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.UpNextAccountItem
|
||||
|
||||
class MediaEpisodeListAdapter(private val onClickListener: OnClickListener, private val itemOffset: Int = 0) : ListAdapter<UpNextAccountItem, MediaEpisodeListAdapter.MediaViewHolder>(DiffCallback) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaViewHolder {
|
||||
val binding = ItemMediaBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
binding.root.layoutParams.apply {
|
||||
width = (parent.measuredWidth / parent.context.resources.getInteger(R.integer.item_media_columns)) - itemOffset
|
||||
}
|
||||
|
||||
return MediaViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MediaViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.binding.root.setOnClickListener {
|
||||
onClickListener.onClick(item)
|
||||
}
|
||||
holder.bind(item)
|
||||
}
|
||||
|
||||
inner class MediaViewHolder(val binding: ItemMediaBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(item: UpNextAccountItem) {
|
||||
val metadata = item.panel.episodeMetadata
|
||||
|
||||
binding.textTitle.text = binding.root.context.getString(R.string.season_episode_title,
|
||||
metadata.seasonNumber, metadata.episodeNumber, metadata.seriesTitle
|
||||
)
|
||||
|
||||
Glide.with(binding.imagePoster)
|
||||
.load(item.panel.images.thumbnail[0][0].source)
|
||||
.into(binding.imagePoster)
|
||||
|
||||
// add watched progress
|
||||
val playheadProgress = ((item.playhead.toFloat() / (metadata.durationMs / 1000)) * 100)
|
||||
.toInt()
|
||||
binding.progressPlayhead.setProgressCompat(playheadProgress, false)
|
||||
binding.progressPlayhead.visibility = if (playheadProgress <= 0)
|
||||
View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
companion object DiffCallback : DiffUtil.ItemCallback<UpNextAccountItem>() {
|
||||
override fun areItemsTheSame(oldItem: UpNextAccountItem, newItem: UpNextAccountItem): Boolean {
|
||||
return oldItem.panel.id == newItem.panel.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: UpNextAccountItem, newItem: UpNextAccountItem): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
|
||||
class OnClickListener(val clickListener: (item: UpNextAccountItem) -> Unit) {
|
||||
fun onClick(item: UpNextAccountItem) = clickListener(item)
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Filter
|
||||
import android.widget.Filterable
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.android.synthetic.main.item_media.view.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import java.util.*
|
||||
|
||||
class MediaItemAdapter(private val media: List<ItemMedia>) : RecyclerView.Adapter<MediaItemAdapter.ViewHolder>(), Filterable {
|
||||
|
||||
var onItemClick: ((Int, Int) -> Unit)? = null
|
||||
private val filter = MediaFilter()
|
||||
private var filteredMedia = media.map { it.copy() }
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaItemAdapter.ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_media, parent, false)
|
||||
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MediaItemAdapter.ViewHolder, position: Int) {
|
||||
holder.view.apply {
|
||||
text_title.text = filteredMedia[position].title
|
||||
Glide.with(context).load(filteredMedia[position].posterUrl).into(image_poster)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return filteredMedia.size
|
||||
}
|
||||
|
||||
override fun getFilter(): Filter {
|
||||
return filter
|
||||
}
|
||||
|
||||
inner class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
onItemClick?.invoke(filteredMedia[adapterPosition].id, adapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class MediaFilter : Filter() {
|
||||
override fun performFiltering(constraint: CharSequence?): FilterResults {
|
||||
val filterTerm = constraint.toString().toLowerCase(Locale.ROOT)
|
||||
val results = FilterResults()
|
||||
|
||||
val filteredList = if (filterTerm.isEmpty()) {
|
||||
media
|
||||
} else {
|
||||
media.filter {
|
||||
it.title.toLowerCase(Locale.ROOT).contains(filterTerm)
|
||||
}
|
||||
}
|
||||
|
||||
results.values = filteredList
|
||||
results.count = filteredList.size
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
@Suppress("unchecked_cast")
|
||||
/**
|
||||
* suppressing unchecked cast is safe, since we only use Media
|
||||
*/
|
||||
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
|
||||
filteredMedia = results?.values as List<ItemMedia>
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemMediaBinding
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
|
||||
class MediaItemListAdapter(private val onClickListener: OnClickListener, private val itemOffset: Int = 0) : ListAdapter<ItemMedia, MediaItemListAdapter.MediaViewHolder>(DiffCallback) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaViewHolder {
|
||||
val binding = ItemMediaBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
binding.root.layoutParams.apply {
|
||||
width = (parent.measuredWidth / parent.context.resources.getInteger(R.integer.item_media_columns)) - itemOffset
|
||||
}
|
||||
|
||||
return MediaViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MediaViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.binding.root.setOnClickListener {
|
||||
onClickListener.onClick(item)
|
||||
}
|
||||
holder.bind(item)
|
||||
}
|
||||
|
||||
inner class MediaViewHolder(val binding: ItemMediaBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(item: ItemMedia) {
|
||||
binding.textTitle.text = item.title
|
||||
|
||||
Glide.with(binding.root.context)
|
||||
.load(item.posterUrl)
|
||||
.into(binding.imagePoster)
|
||||
|
||||
binding.imageEpisodePlay.isVisible = false
|
||||
binding.progressPlayhead.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
companion object DiffCallback : DiffUtil.ItemCallback<ItemMedia>() {
|
||||
override fun areItemsTheSame(oldItem: ItemMedia, newItem: ItemMedia): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: ItemMedia, newItem: ItemMedia): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
|
||||
class OnClickListener(val clickListener: (item: ItemMedia) -> Unit) {
|
||||
fun onClick(item: ItemMedia) = clickListener(item)
|
||||
}
|
||||
}
|
57
app/src/main/java/org/mosad/teapod/util/metadb/DatTypes.kt
Normal file
57
app/src/main/java/org/mosad/teapod/util/metadb/DatTypes.kt
Normal file
@ -0,0 +1,57 @@
|
||||
package org.mosad.teapod.util.metadb
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
// class representing the media list json object
|
||||
@Serializable
|
||||
data class MediaList(
|
||||
@SerialName("media") val media: List<String>
|
||||
)
|
||||
|
||||
// abstract class used for meta data objects (tv, movie)
|
||||
abstract class Meta {
|
||||
abstract val id: Int
|
||||
abstract val tmdbId: Int
|
||||
abstract val crSeriesId: String
|
||||
}
|
||||
|
||||
// class representing the movie json object
|
||||
@Serializable
|
||||
data class MovieMeta(
|
||||
@SerialName("id") override val id: Int,
|
||||
@SerialName("tmdb_id") override val tmdbId: Int,
|
||||
@SerialName("cr_series_id") override val crSeriesId: String,
|
||||
): Meta()
|
||||
|
||||
// class representing the tv show json object
|
||||
@Serializable
|
||||
data class TVShowMeta(
|
||||
@SerialName("id") override val id: Int,
|
||||
@SerialName("tmdb_id") override val tmdbId: Int,
|
||||
@SerialName("cr_series_id") override val crSeriesId: String,
|
||||
@SerialName("seasons") val seasons: List<SeasonMeta>,
|
||||
): Meta()
|
||||
|
||||
// class used in TVShowMeta, part of the tv show json object
|
||||
@Serializable
|
||||
data class SeasonMeta(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("tmdb_season_id") val tmdbSeasonId: Int,
|
||||
@SerialName("tmdb_season_number") val tmdbSeasonNumber: Int,
|
||||
@SerialName("cr_season_ids") val crSeasonIds: List<String>,
|
||||
@SerialName("episodes") val episodes: List<EpisodeMeta>,
|
||||
)
|
||||
|
||||
// class used in TVShowMeta, part of the tv show json object
|
||||
@Serializable
|
||||
data class EpisodeMeta(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("tmdb_episode_id") val tmdbEpisodeId: Int,
|
||||
@SerialName("tmdb_episode_number") val tmdbEpisodeNumber: Int,
|
||||
@SerialName("cr_episode_ids") val crEpisodeIds: List<String>,
|
||||
@SerialName("opening_start") val openingStart: Long,
|
||||
@SerialName("opening_duration") val openingDuration: Long,
|
||||
@SerialName("ending_start") val endingStart: Long,
|
||||
@SerialName("ending_duration") val endingDuration: Long
|
||||
)
|
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.util.metadb
|
||||
|
||||
import android.util.Log
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
object MetaDBController {
|
||||
private val TAG = javaClass.name
|
||||
|
||||
private const val repoUrl = "https://gitlab.com/Seil0/teapodmetadb/-/raw/main/crunchy/"
|
||||
|
||||
private val client = HttpClient {
|
||||
install(ContentNegotiation) {
|
||||
json()
|
||||
}
|
||||
}
|
||||
|
||||
private var mediaList = MediaList(listOf())
|
||||
private var metaCacheList = arrayListOf<Meta>()
|
||||
|
||||
suspend fun list() = withContext(Dispatchers.IO) {
|
||||
val raw: String = client.get("$repoUrl/list.json").body()
|
||||
mediaList = Json.decodeFromString(raw)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta data for a movie from MetaDB
|
||||
* @param crSeriesId The crunchyroll media id
|
||||
* @return A meta object, or null if not found
|
||||
*/
|
||||
suspend fun getTVShowMetadata(crSeriesId: String): TVShowMeta? {
|
||||
return if (mediaList.media.contains(crSeriesId)) {
|
||||
metaCacheList.firstOrNull {
|
||||
it.crSeriesId == crSeriesId
|
||||
} as TVShowMeta? ?: getTVShowMetadataFromDB(crSeriesId)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getTVShowMetadataFromDB(crSeriesId: String): TVShowMeta? = withContext(Dispatchers.IO) {
|
||||
return@withContext try {
|
||||
val raw: String = client.get("$repoUrl/tv/$crSeriesId/media.json").body()
|
||||
val meta: TVShowMeta = Json.decodeFromString(raw)
|
||||
metaCacheList.add(meta)
|
||||
|
||||
meta
|
||||
} catch (ex: ClientRequestException) {
|
||||
when (ex.response.status) {
|
||||
HttpStatusCode.NotFound -> Log.w(TAG, "The requested file was not found. Series ID: $crSeriesId", ex)
|
||||
else -> Log.e(TAG, "Error while requesting meta data. Series ID: $crSeriesId", ex)
|
||||
}
|
||||
|
||||
null // todo return none object
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.util.tmdb
|
||||
|
||||
import android.util.Log
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.invoke
|
||||
import kotlinx.serialization.SerializationException
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.concatenate
|
||||
|
||||
/**
|
||||
* Controller for tmdb api integration.
|
||||
* Data types are in TMDBDataTypes. For the type definitions see:
|
||||
* https://developers.themoviedb.org/3/getting-started/introduction
|
||||
*
|
||||
*/
|
||||
class TMDBApiController {
|
||||
private val classTag = javaClass.name
|
||||
|
||||
private val client = HttpClient {
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
ignoreUnknownKeys = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private val apiUrl = "https://api.themoviedb.org/3"
|
||||
private val apiKey = "de959cf9c07a08b5ca7cb51cda9a40c2"
|
||||
|
||||
companion object{
|
||||
const val imageUrl = "https://image.tmdb.org/t/p/w500"
|
||||
}
|
||||
|
||||
private suspend inline fun <reified T> request(
|
||||
endpoint: String,
|
||||
parameters: List<Pair<String, Any?>> = emptyList()
|
||||
): T = coroutineScope {
|
||||
val path = "$apiUrl$endpoint"
|
||||
val params = concatenate(
|
||||
listOf("api_key" to apiKey, "language" to Preferences.preferredSubtitleLocale.toLanguageTag()),
|
||||
parameters
|
||||
)
|
||||
|
||||
// TODO handle FileNotFoundException
|
||||
return@coroutineScope (Dispatchers.IO) {
|
||||
val response: HttpResponse = client.get(path) {
|
||||
params.forEach {
|
||||
parameter(it.first, it.second)
|
||||
}
|
||||
}
|
||||
|
||||
response.body<T>()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a movie in tmdb
|
||||
* @param query The query text (movie title)
|
||||
* @return A TMDBSearch<TMDBSearchResultMovie> object, or
|
||||
* NoneTMDBSearchMovie if nothing was found
|
||||
*/
|
||||
suspend fun searchMovie(query: String): TMDBSearch<TMDBSearchResultMovie> {
|
||||
val searchEndpoint = "/search/movie"
|
||||
val parameters = listOf("query" to query, "include_adult" to false)
|
||||
|
||||
return try {
|
||||
request(searchEndpoint, parameters)
|
||||
}catch (ex: SerializationException) {
|
||||
Log.e(classTag, "SerializationException in searchMovie(), with query = $query.", ex)
|
||||
NoneTMDBSearchMovie
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a tv show in tmdb
|
||||
* @param query The query text (tv show title)
|
||||
* @return A TMDBSearch<TMDBSearchResultTVShow> object, or
|
||||
* NoneTMDBSearchTVShow if nothing was found
|
||||
*/
|
||||
suspend fun searchTVShow(query: String): TMDBSearch<TMDBSearchResultTVShow> {
|
||||
val searchEndpoint = "/search/tv"
|
||||
val parameters = listOf("query" to query, "include_adult" to false)
|
||||
|
||||
return try {
|
||||
request(searchEndpoint, parameters)
|
||||
}catch (ex: SerializationException) {
|
||||
Log.e(classTag, "SerializationException in searchTVShow(), with query = $query.", ex)
|
||||
NoneTMDBSearchTVShow
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get details for a movie from tmdb
|
||||
* @param movieId The tmdb ID of the movie
|
||||
* @return A TMDBMovie object, or NoneTMDBMovie if not found
|
||||
*/
|
||||
suspend fun getMovieDetails(movieId: Int): TMDBMovie {
|
||||
val movieEndpoint = "/movie/$movieId"
|
||||
|
||||
// TODO is FileNotFoundException handling needed?
|
||||
return try {
|
||||
request(movieEndpoint)
|
||||
}catch (ex: SerializationException) {
|
||||
Log.e(classTag, "SerializationException in getMovieDetails(), with movieId = $movieId.", ex)
|
||||
NoneTMDBMovie
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get details for a tv show from tmdb
|
||||
* @param tvId The tmdb ID of the tv show
|
||||
* @return A TMDBTVShow object, or NoneTMDBTVShow if not found
|
||||
*/
|
||||
suspend fun getTVShowDetails(tvId: Int): TMDBTVShow {
|
||||
val tvShowEndpoint = "/tv/$tvId"
|
||||
|
||||
// TODO is FileNotFoundException handling needed?
|
||||
return try {
|
||||
request(tvShowEndpoint)
|
||||
}catch (ex: SerializationException) {
|
||||
Log.e(classTag, "SerializationException in getTVShowDetails(), with tvId = $tvId.", ex)
|
||||
NoneTMDBTVShow
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
/**
|
||||
* Get details for a tv show season from tmdb
|
||||
* @param tvId The tmdb ID of the tv show
|
||||
* @param seasonNumber The tmdb season number
|
||||
* @return A TMDBTVSeason object, or NoneTMDBTVSeason if not found
|
||||
*/
|
||||
suspend fun getTVSeasonDetails(tvId: Int, seasonNumber: Int): TMDBTVSeason {
|
||||
val tvShowSeasonEndpoint = "/tv/$tvId/season/$seasonNumber"
|
||||
|
||||
// TODO is FileNotFoundException handling needed?
|
||||
return try {
|
||||
request(tvShowSeasonEndpoint)
|
||||
}catch (ex: SerializationException) {
|
||||
Log.e(classTag, "SerializationException in getTVSeasonDetails(), with tvId = $tvId, seasonNumber = $seasonNumber.", ex)
|
||||
NoneTMDBTVSeason
|
||||
}
|
||||
}
|
||||
|
||||
}
|
137
app/src/main/java/org/mosad/teapod/util/tmdb/TMDBDataTypes.kt
Normal file
137
app/src/main/java/org/mosad/teapod/util/tmdb/TMDBDataTypes.kt
Normal file
@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2022 <seil0@mosad.xyz>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mosad.teapod.util.tmdb
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* These data classes represent the tmdb api json objects.
|
||||
* Fields which are nullable in the tmdb api are also nullable here.
|
||||
*/
|
||||
|
||||
interface TMDBResult {
|
||||
val id: Int
|
||||
val name: String? // for movies tmdb return string or null
|
||||
val overview: String? // for movies tmdb return string or null
|
||||
val posterPath: String?
|
||||
val backdropPath: String?
|
||||
}
|
||||
|
||||
data class TMDBBase(
|
||||
override val id: Int,
|
||||
override val name: String?,
|
||||
override val overview: String?,
|
||||
override val posterPath: String?,
|
||||
override val backdropPath: String?
|
||||
) : TMDBResult
|
||||
|
||||
/**
|
||||
* search results for movie and tv show
|
||||
*/
|
||||
|
||||
@Serializable
|
||||
data class TMDBSearch<T>(
|
||||
val page: Int,
|
||||
val results: List<T>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class TMDBSearchResultMovie(
|
||||
@SerialName("id") override val id: Int,
|
||||
@SerialName("title") override val name: String?,
|
||||
@SerialName("overview") override val overview: String?,
|
||||
@SerialName("poster_path") override val posterPath: String?,
|
||||
@SerialName("backdrop_path") override val backdropPath: String?,
|
||||
) : TMDBResult
|
||||
|
||||
@Serializable
|
||||
data class TMDBSearchResultTVShow(
|
||||
@SerialName("id") override val id: Int,
|
||||
@SerialName("name") override val name: String?,
|
||||
@SerialName("overview") override val overview: String?,
|
||||
@SerialName("poster_path") override val posterPath: String?,
|
||||
@SerialName("backdrop_path") override val backdropPath: String?,
|
||||
) : TMDBResult
|
||||
|
||||
val NoneTMDBSearch = TMDBSearch<TMDBBase>(0, emptyList())
|
||||
val NoneTMDBSearchMovie = TMDBSearch<TMDBSearchResultMovie>(0, emptyList())
|
||||
val NoneTMDBSearchTVShow = TMDBSearch<TMDBSearchResultTVShow>(0, emptyList())
|
||||
|
||||
/**
|
||||
* detail return data types
|
||||
*/
|
||||
|
||||
@Serializable
|
||||
data class TMDBMovie(
|
||||
@SerialName("id") override val id: Int,
|
||||
@SerialName("title") override val name: String, // for movies the name is in the field title
|
||||
@SerialName("overview") override val overview: String?,
|
||||
@SerialName("poster_path") override val posterPath: String?,
|
||||
@SerialName("backdrop_path") override val backdropPath: String?,
|
||||
@SerialName("release_date") val releaseDate: String,
|
||||
@SerialName("runtime") val runtime: Int?,
|
||||
@SerialName("status") val status: String,
|
||||
// TODO genres
|
||||
) : TMDBResult
|
||||
|
||||
@Serializable
|
||||
data class TMDBTVShow(
|
||||
@SerialName("id")override val id: Int,
|
||||
@SerialName("name")override val name: String,
|
||||
@SerialName("overview")override val overview: String,
|
||||
@SerialName("poster_path") override val posterPath: String?,
|
||||
@SerialName("backdrop_path") override val backdropPath: String?,
|
||||
@SerialName("first_air_date") val firstAirDate: String?,
|
||||
@SerialName("last_air_date") val lastAirDate: String?,
|
||||
@SerialName("status") val status: String?,
|
||||
// TODO genres
|
||||
) : TMDBResult
|
||||
|
||||
// use null for nullable types, the gui needs to handle/implement a fallback for null values
|
||||
val NoneTMDB = TMDBBase(0, "", "", null, null)
|
||||
val NoneTMDBMovie = TMDBMovie(0, "", "", null, null, "1970-01-01", null, "")
|
||||
val NoneTMDBTVShow = TMDBTVShow(0, "", "", null, null, "1970-01-01", "1970-01-01", "")
|
||||
|
||||
@Serializable
|
||||
data class TMDBTVSeason(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("name") val name: String,
|
||||
@SerialName("overview") val overview: String,
|
||||
@SerialName("poster_path") val posterPath: String?,
|
||||
@SerialName("air_date") val airDate: String,
|
||||
@SerialName("episodes") val episodes: List<TMDBTVEpisode>,
|
||||
@SerialName("season_number") val seasonNumber: Int
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class TMDBTVEpisode(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("name") val name: String,
|
||||
@SerialName("overview") val overview: String,
|
||||
@SerialName("air_date") val airDate: String,
|
||||
@SerialName("episode_number") val episodeNumber: Int
|
||||
)
|
||||
|
||||
// use null for nullable types, the gui needs to handle/implement a fallback for null values
|
||||
val NoneTMDBTVSeason = TMDBTVSeason(0, "", "", null, "", emptyList(), 0)
|
@ -1,30 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
12
app/src/main/res/drawable/dot_default.xml
Normal file
12
app/src/main/res/drawable/dot_default.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape
|
||||
android:innerRadius="0dp"
|
||||
android:shape="ring"
|
||||
android:thickness="4dp"
|
||||
android:useLevel="false">
|
||||
<solid android:color="?colorOutline"/>
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
12
app/src/main/res/drawable/dot_selected.xml
Normal file
12
app/src/main/res/drawable/dot_selected.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape
|
||||
android:innerRadius="0dp"
|
||||
android:shape="ring"
|
||||
android:thickness="4dp"
|
||||
android:useLevel="false">
|
||||
<solid android:color="?colorSecondary" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
6
app/src/main/res/drawable/dot_tab_selector.xml
Normal file
6
app/src/main/res/drawable/dot_tab_selector.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/dot_selected"
|
||||
android:state_selected="true"/>
|
||||
<item android:drawable="@drawable/dot_default"/>
|
||||
</selector>
|
13
app/src/main/res/drawable/ic_baseline_access_time_24.xml
Normal file
13
app/src/main/res/drawable/ic_baseline_access_time_24.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z" />
|
||||
</vector>
|
@ -4,7 +4,7 @@
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
||||
|
10
app/src/main/res/drawable/ic_baseline_arrow_back_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_arrow_back_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
|
||||
</vector>
|
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7,10l5,5 5,-5z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_baseline_audiotrack_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_audiotrack_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,3v9.28c-0.47,-0.17 -0.97,-0.28 -1.5,-0.28C8.01,12 6,14.01 6,16.5S8.01,21 10.5,21c2.31,0 4.2,-1.75 4.45,-4H15V6h4V3h-7z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_baseline_autorenew_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_autorenew_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,6v3l4,-4 -4,-4v3c-4.42,0 -8,3.58 -8,8 0,1.57 0.46,3.03 1.24,4.26L6.7,14.8c-0.45,-0.83 -0.7,-1.79 -0.7,-2.8 0,-3.31 2.69,-6 6,-6zM18.76,7.74L17.3,9.2c0.44,0.84 0.7,1.79 0.7,2.8 0,3.31 -2.69,6 -6,6v-3l-4,4 4,4v-3c4.42,0 8,-3.58 8,-8 0,-1.57 -0.46,-3.03 -1.24,-4.26z" />
|
||||
</vector>
|
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M17,3L7,3c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3L19,5c0,-1.1 -0.9,-2 -2,-2zM17,18l-5,-2.18L7,18L7,5h10v13z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_baseline_code_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_code_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_baseline_description_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_description_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M14,2L6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6zM16,18L8,18v-2h8v2zM16,14L8,14v-2h8v2zM13,9L13,3.5L18.5,9L13,9z"/>
|
||||
</vector>
|
15
app/src/main/res/drawable/ic_baseline_forward_10_24.xml
Normal file
15
app/src/main/res/drawable/ic_baseline_forward_10_24.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,13c0,3.31 -2.69,6 -6,6s-6,-2.69 -6,-6s2.69,-6 6,-6v4l5,-5l-5,-5v4c-4.42,0 -8,3.58 -8,8c0,4.42 3.58,8 8,8s8,-3.58 8,-8H18z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10.86,15.94l0,-4.27l-0.09,0l-1.77,0.63l0,0.69l1.01,-0.31l0,3.26z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12.25,13.44v0.74c0,1.9 1.31,1.82 1.44,1.82c0.14,0 1.44,0.09 1.44,-1.82v-0.74c0,-1.9 -1.31,-1.82 -1.44,-1.82C13.55,11.62 12.25,11.53 12.25,13.44zM14.29,13.32v0.97c0,0.77 -0.21,1.03 -0.59,1.03c-0.38,0 -0.6,-0.26 -0.6,-1.03v-0.97c0,-0.75 0.22,-1.01 0.59,-1.01C14.07,12.3 14.29,12.57 14.29,13.32z"/>
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_baseline_forward_24.xml
Normal file
9
app/src/main/res/drawable/ic_baseline_forward_24.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,13c0,3.31 -2.69,6 -6,6s-6,-2.69 -6,-6s2.69,-6 6,-6v4l5,-5l-5,-5v4c-4.42,0 -8,3.58 -8,8c0,4.42 3.58,8 8,8c4.42,0 8,-3.58 8,-8H18z" />
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_baseline_language_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_language_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/>
|
||||
</vector>
|
8
app/src/main/res/drawable/ic_baseline_people_24.xml
Normal file
8
app/src/main/res/drawable/ic_baseline_people_24.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5L1,19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45L17,19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z"/>
|
||||
</vector>
|
15
app/src/main/res/drawable/ic_baseline_rewind_10_24.xml
Normal file
15
app/src/main/res/drawable/ic_baseline_rewind_10_24.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11.99,5V1l-5,5l5,5V7c3.31,0 6,2.69 6,6s-2.69,6 -6,6s-6,-2.69 -6,-6h-2c0,4.42 3.58,8 8,8s8,-3.58 8,-8S16.41,5 11.99,5z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10.89,16h-0.85v-3.26l-1.01,0.31v-0.69l1.77,-0.63h0.09V16z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.17,14.24c0,0.32 -0.03,0.6 -0.1,0.82s-0.17,0.42 -0.29,0.57s-0.28,0.26 -0.45,0.33s-0.37,0.1 -0.59,0.1s-0.41,-0.03 -0.59,-0.1s-0.33,-0.18 -0.46,-0.33s-0.23,-0.34 -0.3,-0.57s-0.11,-0.5 -0.11,-0.82V13.5c0,-0.32 0.03,-0.6 0.1,-0.82s0.17,-0.42 0.29,-0.57s0.28,-0.26 0.45,-0.33s0.37,-0.1 0.59,-0.1s0.41,0.03 0.59,0.1c0.18,0.07 0.33,0.18 0.46,0.33s0.23,0.34 0.3,0.57s0.11,0.5 0.11,0.82V14.24zM14.32,13.38c0,-0.19 -0.01,-0.35 -0.04,-0.48s-0.07,-0.23 -0.12,-0.31s-0.11,-0.14 -0.19,-0.17s-0.16,-0.05 -0.25,-0.05s-0.18,0.02 -0.25,0.05s-0.14,0.09 -0.19,0.17s-0.09,0.18 -0.12,0.31s-0.04,0.29 -0.04,0.48v0.97c0,0.19 0.01,0.35 0.04,0.48s0.07,0.24 0.12,0.32s0.11,0.14 0.19,0.17s0.16,0.05 0.25,0.05s0.18,-0.02 0.25,-0.05s0.14,-0.09 0.19,-0.17s0.09,-0.19 0.11,-0.32s0.04,-0.29 0.04,-0.48V13.38z"/>
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_baseline_rewind_24.xml
Normal file
5
app/src/main/res/drawable/ic_baseline_rewind_24.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,5V1L7,6l5,5V7c3.31,0 6,2.69 6,6s-2.69,6 -6,6 -6,-2.69 -6,-6H4c0,4.42 3.58,8 8,8s8,-3.58 8,-8 -3.58,-8 -8,-8z"/>
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_baseline_skip_next_24.xml
Normal file
5
app/src/main/res/drawable/ic_baseline_skip_next_24.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z"/>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_baseline_style_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_style_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M2.53,19.65l1.34,0.56v-9.03l-2.43,5.86c-0.41,1.02 0.08,2.19 1.09,2.61zM22.03,15.95L17.07,3.98c-0.31,-0.75 -1.04,-1.21 -1.81,-1.23 -0.26,0 -0.53,0.04 -0.79,0.15L7.1,5.95c-0.75,0.31 -1.21,1.03 -1.23,1.8 -0.01,0.27 0.04,0.54 0.15,0.8l4.96,11.97c0.31,0.76 1.05,1.22 1.83,1.23 0.26,0 0.52,-0.05 0.77,-0.15l7.36,-3.05c1.02,-0.42 1.51,-1.59 1.09,-2.6zM7.88,8.75c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM5.88,19.75c0,1.1 0.9,2 2,2h1.45l-3.45,-8.34v6.34z"/>
|
||||
</vector>
|
@ -6,5 +6,5 @@
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
|
||||
android:pathData="M20,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM4,12h4v2L4,14v-2zM14,18L4,18v-2h10v2zM20,18h-4v-2h4v2zM20,14L10,14v-2h10v2z"/>
|
||||
</vector>
|
@ -1,10 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6zM20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM12,14.5v-9l6,4.5 -6,4.5z"/>
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6zM20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM12,14.5v-9l6,4.5 -6,4.5z"/>
|
||||
</vector>
|
||||
|
20
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
20
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<group
|
||||
android:scaleX="0.051679686"
|
||||
android:scaleY="0.051679686"
|
||||
android:translateX="27.54"
|
||||
android:translateY="38.90954">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="m850.19,372.71c87.88,-11.01 119.04,-84.97 123.1,-99.87 4.06,-14.89 24.91,-80.57 11.92,-129.36 -12.99,-48.79 -34.36,-72.36 -58.62,-77.25 -24.25,-4.9 -50.59,10.51 -65,32.81 -14.41,22.3 -14.68,45.14 -14.78,55.29 -0.11,10.15 0.76,23.2 -3.37,33.29 -4.13,10.09 3.23,25.71 6.04,35.23 2.81,9.52 9.67,82.62 5.78,115.57 -3.89,32.95 -5.07,34.29 -5.07,34.29zM0.4,23.58C55.81,77.29 56.45,120.86 56.08,132.92c-0.36,12.06 4.77,130.59 11.47,150.76 4.42,13.3 12.11,50.16 41.78,74.48 25.51,20.91 58.65,31.38 58.65,31.38 0,0 36.42,78.46 78.83,108.64 31.56,22.46 39.61,23.74 46.5,35.55 6.18,10.6 93.56,62.62 275.1,47.23 127.29,-10.79 138.56,-44.3 138.56,-44.3 0,0 49.41,-21.9 101.15,-80.43 12.87,-14.56 4.41,-13.21 28.57,-17.79 24.16,-4.58 138.01,-45.58 170.66,-154.36C1039.99,175.32 1017.81,96.01 994.52,69.12 971.23,42.22 931.6,24.18 912.25,24.93c-18.47,0.71 -44.78,4.24 -80.21,46.87 -35.43,42.62 -28.94,37.4 -39.36,41.73 -6.82,2.83 -5.68,3.91 -26.75,-11.65 -20.23,-14.93 -28.9,-21.24 -43.38,-27.24 -7.96,-3.3 2.05,-5.55 2.59,-19.48 0.54,-13.93 2.4,-23.51 -17.32,-23.77 -19.72,-0.26 -408.02,0.21 -408.02,0.21 0,0 -18.8,-1.29 -7.79,24.82 4.2,9.94 -1.45,6.43 -33.27,25.85 -31.82,19.42 -55.58,34.4 -72.28,66.09 -8.43,16 -22.91,23.02 -27.97,8.05C153.44,141.43 125.2,48.96 105.17,23.22 85.56,-1.97 77.8,0.26 77.8,0.26Z"
|
||||
android:strokeWidth="0.41878"
|
||||
android:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
</group>
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_outline_download_24.xml
Normal file
10
app/src/main/res/drawable/ic_outline_download_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,15v3H6v-3H4v3c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2v-3H18zM17,11l-1.41,-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5L17,11z" />
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_outline_info_24.xml
Normal file
10
app/src/main/res/drawable/ic_outline_info_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z" />
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_outline_upload_24.xml
Normal file
10
app/src/main/res/drawable/ic_outline_upload_24.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,15v3H6v-3H4v3c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2v-3H18zM7,9l1.41,1.41L11,7.83V16h2V7.83l2.59,2.58L17,9l-5,-5L7,9z" />
|
||||
</vector>
|
19
app/src/main/res/drawable/ic_splash_foreground.xml
Normal file
19
app/src/main/res/drawable/ic_splash_foreground.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<group android:scaleX="0.03158203"
|
||||
android:scaleY="0.03158203"
|
||||
android:translateX="37.83"
|
||||
android:translateY="44.778053">
|
||||
<path
|
||||
android:pathData="m850.19,372.71c87.88,-11.01 119.04,-84.97 123.1,-99.87 4.06,-14.89 24.91,-80.57 11.92,-129.36 -12.99,-48.79 -34.36,-72.36 -58.62,-77.25 -24.25,-4.9 -50.59,10.51 -65,32.81 -14.41,22.3 -14.68,45.14 -14.78,55.29 -0.11,10.15 0.76,23.2 -3.37,33.29 -4.13,10.09 3.23,25.71 6.04,35.23 2.81,9.52 9.67,82.62 5.78,115.57 -3.89,32.95 -5.07,34.29 -5.07,34.29zM0.4,23.58C55.81,77.29 56.45,120.86 56.08,132.92c-0.36,12.06 4.77,130.59 11.47,150.76 4.42,13.3 12.11,50.16 41.78,74.48 25.51,20.91 58.65,31.38 58.65,31.38 0,0 36.42,78.46 78.83,108.64 31.56,22.46 39.61,23.74 46.5,35.55 6.18,10.6 93.56,62.62 275.1,47.23 127.29,-10.79 138.56,-44.3 138.56,-44.3 0,0 49.41,-21.9 101.15,-80.43 12.87,-14.56 4.41,-13.21 28.57,-17.79 24.16,-4.58 138.01,-45.58 170.66,-154.36C1039.99,175.32 1017.81,96.01 994.52,69.12 971.23,42.22 931.6,24.18 912.25,24.93c-18.47,0.71 -44.78,4.24 -80.21,46.87 -35.43,42.62 -28.94,37.4 -39.36,41.73 -6.82,2.83 -5.68,3.91 -26.75,-11.65 -20.23,-14.93 -28.9,-21.24 -43.38,-27.24 -7.96,-3.3 2.05,-5.55 2.59,-19.48 0.54,-13.93 2.4,-23.51 -17.32,-23.77 -19.72,-0.26 -408.02,0.21 -408.02,0.21 0,0 -18.8,-1.29 -7.79,24.82 4.2,9.94 -1.45,6.43 -33.27,25.85 -31.82,19.42 -55.58,34.4 -72.28,66.09 -8.43,16 -22.91,23.02 -27.97,8.05C153.44,141.43 125.2,48.96 105.17,23.22 85.56,-1.97 77.8,0.26 77.8,0.26Z"
|
||||
android:strokeLineJoin="miter"
|
||||
android:strokeWidth="0.41878"
|
||||
android:fillColor="#000000"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"
|
||||
android:strokeLineCap="butt"/>
|
||||
</group>
|
||||
</vector>
|
7
app/src/main/res/drawable/placeholder_image.xml
Normal file
7
app/src/main/res/drawable/placeholder_image.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?colorSurfaceVariant"/>
|
||||
<size
|
||||
android:width="1920px"
|
||||
android:height="1080px"/>
|
||||
</shape>
|
7
app/src/main/res/drawable/placeholder_image_2_3.xml
Normal file
7
app/src/main/res/drawable/placeholder_image_2_3.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?colorSurfaceVariant"/>
|
||||
<size
|
||||
android:width="400px"
|
||||
android:height="600px"/>
|
||||
</shape>
|
3
app/src/main/res/drawable/ripple_background.xml
Normal file
3
app/src/main/res/drawable/ripple_background.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?attr/colorControlHighlight" />
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#B0B0B0"/>
|
||||
<solid android:color="?colorSurfaceVariant"/>
|
||||
<corners android:radius="3dp"/>
|
||||
</shape>
|
@ -9,9 +9,6 @@
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:background="?android:attr/windowBackground"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
|
50
app/src/main/res/layout/activity_onboarding.xml
Normal file
50
app/src/main/res/layout/activity_onboarding.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
</androidx.viewpager2.widget.ViewPager2>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:background="@android:color/transparent"
|
||||
app:tabBackground="@drawable/dot_tab_selector"
|
||||
app:tabGravity="center"
|
||||
app:tabIndicatorHeight="0dp"
|
||||
app:tabPaddingStart="6dp"
|
||||
app:tabPaddingEnd="6dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@null"
|
||||
android:onClick="btnNextClick"
|
||||
android:text="@string/next"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_skip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@null"
|
||||
android:onClick="btnSkipClick"
|
||||
android:text="@string/skip"
|
||||
tools:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,25 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/player_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:keepScreenOn="true"
|
||||
android:background="#000000"
|
||||
tools:context=".PlayerActivity">
|
||||
android:keepScreenOn="true"
|
||||
tools:context=".ui.activity.player.PlayerActivity">
|
||||
|
||||
<com.google.android.exoplayer2.ui.PlayerView
|
||||
<com.google.android.exoplayer2.ui.StyledPlayerView
|
||||
android:id="@+id/video_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center" />
|
||||
<!-- app:controller_layout_id="@layout/player_custom_control"/>-->
|
||||
android:layout_gravity="center"
|
||||
android:animateLayoutChanges="true"
|
||||
android:foreground="@drawable/ripple_background"
|
||||
app:controller_layout_id="@layout/player_controls" />
|
||||
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/loading"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Circular.Indeterminate"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminate="true"
|
||||
app:indicatorColor="@color/player_white"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/exo_double_tap_indicator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone">
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<org.mosad.teapod.ui.components.RewindButton
|
||||
android:id="@+id/rwd_10_indicator"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Space
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="1dp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<org.mosad.teapod.ui.components.FastForwardButton
|
||||
android:id="@+id/ffwd_10_indicator"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_next_ep"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginBottom="72dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/next_episode"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/player_white"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_skip_op"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginBottom="72dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/skip_opening"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/player_white"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
</FrameLayout>
|
24
app/src/main/res/layout/button_fast_forward.xml
Normal file
24
app/src/main/res/layout/button_fast_forward.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imageButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:background="@drawable/ic_baseline_forward_10_24"
|
||||
android:contentDescription="@string/forward_10" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginStart="42dp"
|
||||
android:text="@string/fwd_10_s"
|
||||
android:textColor="@color/player_white"
|
||||
android:visibility="gone" />
|
||||
</RelativeLayout>
|
27
app/src/main/res/layout/button_rewind.xml
Normal file
27
app/src/main/res/layout/button_rewind.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imageButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:background="@drawable/ic_baseline_rewind_10_24"
|
||||
android:contentDescription="@string/rewind_10" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginEnd="42dp"
|
||||
android:text="@string/rwd_10_s"
|
||||
android:textColor="@color/player_white"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/linLayout_login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_text_login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="7dp"
|
||||
android:ems="10"
|
||||
android:hint="@string/login"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_text_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="7dp"
|
||||
android:ems="10"
|
||||
android:hint="@string/password"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
</LinearLayout>
|
262
app/src/main/res/layout/fragment_about.xml
Normal file
262
app/src/main/res/layout/fragment_about.xml
Normal file
@ -0,0 +1,262 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.activity.main.fragments.AboutFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_app_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="17dp"
|
||||
android:contentDescription="@string/app_name"
|
||||
android:src="@mipmap/ic_launcher_round" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_app_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_about_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:text="@string/about_info" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_version"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/version"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_outline_info_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_version"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/version"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_version_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/version_desc" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_authors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_authors"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/authors"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_people_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_authors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/authors"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_authors_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/author_desc" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_source"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_source"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/source"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_code_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_source"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/source"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_source_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/teapod_repo" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_license"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_license"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/account"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_description_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_license"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/license"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_license_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/license_desc" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_third_party"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:text="@string/third_party_heading"
|
||||
android:textSize="17sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_third_party"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="7dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_tmdb_notice"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/tmdb_notice"
|
||||
android:textAlignment="center" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
@ -4,24 +4,26 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f5f5f5"
|
||||
tools:context=".ui.fragments.AccountFragment">
|
||||
tools:context=".ui.activity.main.fragments.AccountFragment">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="12dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_account"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="#ffffff"
|
||||
android:elevation="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@ -31,17 +33,17 @@
|
||||
android:paddingStart="7dp"
|
||||
android:paddingEnd="7dp"
|
||||
android:text="@string/account"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_account_login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="7dp"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
@ -50,10 +52,9 @@
|
||||
android:contentDescription="@string/account"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="5dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_account_box_24"
|
||||
app:srcCompat="@drawable/ic_baseline_account_box_24" />
|
||||
android:src="@drawable/ic_baseline_account_box_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -66,27 +67,436 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/account_login_ex"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp" />
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_account_login_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/account_login_desc"
|
||||
android:textColor="@android:color/secondary_text_light" />
|
||||
android:text="@string/account_login_desc" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_account_subscription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/account"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_access_time_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_account_subscription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/loading"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_account_subscription_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/account_tier" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:elevation="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="7dp"
|
||||
android:paddingEnd="7dp"
|
||||
android:text="@string/settings"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_settings_audio_language"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/settings_audio_language"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_audiotrack_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings_content_language"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_audio_language"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings_audio_language_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_content_language_desc" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_settings_subtitle_language"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/settings_subtitle_language"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_subtitles_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings_subtitle_language"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_subtitle_language"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings_subtitle_language_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_content_language_desc" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_settings_autoplay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_autoplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/settings_autoplay"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:src="@drawable/ic_baseline_autorenew_24" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/switch_autoplay"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings_auoplay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_autoplay"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_settings_auoplay_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_autoplay_desc" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/switch_autoplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:contentDescription="@string/settings_autoplay"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_theme"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_theme"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/account"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_style_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_theme"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/theme"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_theme_selected"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/theme_light" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_dev_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:clipToPadding="false"
|
||||
android:elevation="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_dev_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="7dp"
|
||||
android:paddingEnd="7dp"
|
||||
android:text="@string/dev_settings"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_update_playhead"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/update_playhead"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_baseline_access_time_24" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/switch_update_playhead"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_update_playhead"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/update_playhead"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_update_playhead_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/update_playhead_desc" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/switch_update_playhead"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:contentDescription="@string/update_playhead"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_export_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_export_data"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/info"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
app:srcCompat="@drawable/ic_outline_upload_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_export_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/export_data"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_export_data_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/export_data_desc" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_import_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_import_data"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/info"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
app:srcCompat="@drawable/ic_outline_download_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_import_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/import_data"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_import_data_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/import_data_desc" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="#ffffff"
|
||||
android:clipToPadding="false"
|
||||
android:elevation="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@ -96,17 +506,17 @@
|
||||
android:paddingStart="7dp"
|
||||
android:paddingEnd="7dp"
|
||||
android:text="@string/info"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_about"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="7dp"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
@ -115,9 +525,9 @@
|
||||
android:contentDescription="@string/info"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:padding="5dp"
|
||||
android:padding="9dp"
|
||||
android:scaleType="fitXY"
|
||||
app:srcCompat="@drawable/ic_baseline_info_24" />
|
||||
app:srcCompat="@drawable/ic_outline_info_24" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -130,37 +540,20 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/info_about"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp" />
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_info_about_desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/info_about_desc"
|
||||
android:textColor="@android:color/secondary_text_light" />
|
||||
android:text="@string/info_about_desc" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_licenses"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="7dp"
|
||||
android:paddingStart="48dp"
|
||||
android:paddingEnd="48dp"
|
||||
android:text="Licenses"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
@ -2,27 +2,170 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/ff_test"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f5f5f5"
|
||||
tools:context=".ui.fragments.HomeFragment">
|
||||
tools:context=".ui.activity.main.fragments.HomeFragment">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
android:layout_marginBottom="7dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/shimmer_layout_highlight"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="gone">
|
||||
|
||||
<include layout="@layout/item_highlight_shimmer" />
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_highlight"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_highlight"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/highlight_media"
|
||||
app:layout_constraintDimensionRatio="H,16:9"
|
||||
tools:src="@drawable/ic_launcher_background" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_highlight_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="7dp"
|
||||
android:text="@string/text_title_ex"
|
||||
android:textAlignment="center"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="7dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_highlight_my_list"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/my_list"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/ic_baseline_add_24" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_play_highlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/button_play"
|
||||
android:textAllCaps="false"
|
||||
android:textSize="16sp"
|
||||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_highlight_info"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/info"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/ic_outline_info_24" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_up_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_up_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/up_next"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/shimmer_layout_up_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_up_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/item_media" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_watchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/text_watchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
@ -33,8 +176,170 @@
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/shimmer_layout_watchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_my_list"
|
||||
android:id="@+id/recycler_watchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/item_media" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_recommendations"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="7dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_recommendations"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/recommendations"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/shimmer_layout_recommendations"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_recommendations"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/item_media" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_new_titles"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_new_titles"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/new_titles"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/shimmer_layout_new_titles"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_new_titles"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/item_media" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_top_ten"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_top_ten"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/top_ten"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.facebook.shimmer.ShimmerFrameLayout
|
||||
android:id="@+id/shimmer_layout_top_ten"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
<include layout="@layout/item_media_shimmer" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_top_ten"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
@ -45,17 +350,4 @@
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_home"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -4,22 +4,35 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f5f5f5"
|
||||
tools:context=".ui.fragments.LibraryFragment">
|
||||
tools:context=".ui.activity.main.fragments.LibraryFragment">
|
||||
|
||||
<org.mosad.teapod.ui.components.EmptySubmitSearchView
|
||||
android:id="@+id/search_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:elevation="8dp"
|
||||
android:iconifiedByDefault="false"
|
||||
android:paddingBottom="5dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
</org.mosad.teapod.ui.components.EmptySubmitSearchView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_media_library"
|
||||
android:id="@+id/recycler_media_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:clipToPadding="false"
|
||||
android:padding="3dp"
|
||||
android:orientation="vertical"
|
||||
android:padding="3dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="2"
|
||||
tools:listitem="@layout/item_media" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/search_text"
|
||||
app:spanCount="@integer/item_media_columns"
|
||||
tools:listitem="@layout/item_media">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f5f5f5"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<com.google.android.material.progressindicator.ProgressIndicator
|
||||
android:id="@+id/progressBar2"
|
||||
style="@style/Widget.MaterialComponents.ProgressIndicator.Circular.Indeterminate"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_gravity="center"
|
||||
tools:visibility="visible" />
|
||||
</FrameLayout>
|
@ -1,159 +1,214 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f5f5f5"
|
||||
tools:context=".ui.fragments.MediaFragment">
|
||||
tools:context=".ui.activity.main.fragments.MediaFragment">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<FrameLayout
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_media"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_scrollFlags="scroll">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_backdrop"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="false"
|
||||
android:maxHeight="231dp"
|
||||
android:minHeight="220dp"
|
||||
android:scaleType="centerCrop" />
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/image_poster"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="200dp"
|
||||
android:layout_gravity="center"
|
||||
app:shapeAppearance="@style/ShapeAppearance.Teapod.RoundedPoster"
|
||||
app:srcCompat="@drawable/ic_launcher_background" />
|
||||
<FrameLayout
|
||||
android:id="@+id/frame_image_progress"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintDimensionRatio="H,16:9"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
</FrameLayout>
|
||||
<ImageView
|
||||
android:id="@+id/image_backdrop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/media_poster_backdrop_desc"
|
||||
android:scaleType="fitCenter"
|
||||
tools:srcCompat="@android:color/darker_gray" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_media_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/image_poster"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginBottom="7dp"
|
||||
android:scaleType="fitCenter"
|
||||
app:shapeAppearance="@style/ShapeAppearance.Teapod.RoundedPoster"
|
||||
tools:src="@drawable/placeholder_image_2_3" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_year"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="2dp"
|
||||
android:text="@string/text_year_ex" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_age"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:background="@drawable/shape_rounden_corner"
|
||||
android:paddingStart="3dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="3dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:text="@string/text_age_ex" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_episodes_or_runtime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:padding="2dp"
|
||||
android:text="@string/text_episodes_count" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_play"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/button_play"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@android:color/primary_text_dark"
|
||||
android:textSize="16sp"
|
||||
app:backgroundTint="#4A4141"
|
||||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:text="@string/text_title_ex"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_overview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:text="@string/text_overview_ex" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_actions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:orientation="horizontal">
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_my_list_action"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/linear_media_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_my_list_action"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_baseline_add_24"
|
||||
app:tint="#4A4141" />
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_my_list_action"
|
||||
android:id="@+id/text_year"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/my_list" />
|
||||
android:padding="2dp"
|
||||
android:text="@string/text_year_ex" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_age"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:background="@drawable/shape_rounded_corner"
|
||||
android:paddingStart="3dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="3dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:text="@string/text_age_ex" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_episodes_or_runtime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:padding="2dp"
|
||||
android:text="@string/text_episodes_count" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_play"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/button_play"
|
||||
android:textAllCaps="false"
|
||||
android:textSize="16sp"
|
||||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:text="@string/text_title_ex"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_overview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:text="@string/text_overview_ex" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_actions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_my_list_action"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_my_list_action"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:contentDescription="@string/my_list"
|
||||
android:paddingStart="11dp"
|
||||
android:paddingTop="11dp"
|
||||
android:paddingEnd="11dp"
|
||||
android:paddingBottom="7dp"
|
||||
android:src="@drawable/ic_baseline_add_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_my_list_action"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/my_list"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_episodes_similar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:background="@android:color/transparent"
|
||||
app:tabGravity="start"
|
||||
app:tabMode="scrollable" />
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_episodes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
tools:layout_editor_absoluteY="298dp"
|
||||
tools:listitem="@layout/item_episode" />
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/pager_episodes_similar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_anchor="@id/app_layout"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_gravity="bottom"/>
|
||||
|
||||
</FrameLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/frame_loading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:colorBackground"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/loadingIndicator"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminate="true"
|
||||
app:indicatorColor="?colorPrimary"
|
||||
tools:visibility="visible" />
|
||||
</FrameLayout>
|
||||
|
||||
</RelativeLayout>
|
33
app/src/main/res/layout/fragment_media_episodes.xml
Normal file
33
app/src/main/res/layout/fragment_media_episodes.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/linear_episodes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_season_selection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:singleLine="true"
|
||||
android:text="@string/text_title_ex"
|
||||
app:icon="@drawable/ic_baseline_arrow_drop_down_24"
|
||||
app:iconGravity="end" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_episodes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="7dp"
|
||||
android:paddingEnd="7dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:layout_editor_absoluteY="298dp"
|
||||
tools:listitem="@layout/item_episode" />
|
||||
|
||||
</LinearLayout>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user