Compare commits
77 Commits
0.4.0
...
35563eeefe
Author | SHA1 | Date | |
---|---|---|---|
35563eeefe
|
|||
281d4b5625
|
|||
f65497e06a
|
|||
1e54bc7983
|
|||
87cc4c5ec1
|
|||
b79d962b8d
|
|||
a10287f747
|
|||
e98e75456e
|
|||
349a0e451a
|
|||
22d2d777c8
|
|||
04b1ac5a53
|
|||
2fa5a0aacd
|
|||
9062474180
|
|||
450fd259c6
|
|||
6dcc50c12a
|
|||
90069e2518
|
|||
0866ce5917
|
|||
9f47304b55
|
|||
206a00fed5
|
|||
a14db062ed
|
|||
b21e9c7abd
|
|||
51e214d3c1
|
|||
2d2c7b2580
|
|||
6dac929550
|
|||
919bce65e9
|
|||
4f5f111afe
|
|||
e6fd5d6952
|
|||
e7d057bfb8
|
|||
eafefd9a51
|
|||
3935f37267
|
|||
39e740cd92 | |||
eeb1c33e43
|
|||
8753d4f36f
|
|||
5ea94b7ded
|
|||
062013489d
|
|||
ed9eff433b
|
|||
c2a5f768b8
|
|||
a505315781
|
|||
d76538cf28
|
|||
309a991007
|
|||
0340c83b47
|
|||
9dfd2cf70b
|
|||
26d2da923b
|
|||
c66c725ee3
|
|||
44f99295e9
|
|||
d417181b70
|
|||
9df5be003b
|
|||
cf3b1802d5
|
|||
4de97ca42e
|
|||
664959641f
|
|||
c1b0b4038c | |||
ba7d82bc2b
|
|||
e0a6485ed7
|
|||
5555269877
|
|||
3fcd1a96b2
|
|||
03e9c3dae5
|
|||
5ccf907ed8 | |||
8afbae1e1a
|
|||
164db8ebd1
|
|||
44d1825095
|
|||
1d071eafdb
|
|||
0decf317d9
|
|||
5e48e724a7
|
|||
46e3d1f1b6
|
|||
a3a89c6b64
|
|||
7ce67f57cd
|
|||
68d462eeee
|
|||
063b5405fc
|
|||
be591a961a
|
|||
8160641b8f
|
|||
86dfd69b4b
|
|||
74e8639435
|
|||
e8ab11d5ff
|
|||
0bb433b5cb
|
|||
b05ecf64a6
|
|||
7a2f3ad265
|
|||
4f2bd4fd59
|
@ -20,11 +20,11 @@ Teapod is a unofficial App for Anime on Demand (AoD). It allows you to watch all
|
||||
Teapod is licensed under the terms and conditions of GPL 3. This Project is not associated with Anime on Demand in any way. But they allow open source apps for their service.
|
||||
|
||||
### Contributing
|
||||
Currentl you need to have an AoD account to contrtibut to Teapod. Contributing without on is kind of impossible.If you want to contribute to Teapod and need an account on this gitea instance, please write me an email.
|
||||
Currently you need to have an AoD account to contribute to Teapod. Contributing without on is kind of impossible.If you want to contribute to Teapod and need an account on this gitea instance, please write me an email.
|
||||
|
||||
### [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-2021 [@Seil0](https://git.mosad.xyz/Seil0)
|
||||
Teapod © 2020-2022 [@Seil0](https://git.mosad.xyz/Seil0)
|
||||
|
@ -1,6 +1,9 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-android-extensions'
|
||||
id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version"
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
@ -10,8 +13,8 @@ android {
|
||||
applicationId "org.mosad.teapod"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 4000 //00.04.000
|
||||
versionName "0.4.0"
|
||||
versionCode 4200 //00.04.200
|
||||
versionName "1.0.0-alpha3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
resValue "string", "build_time", buildTime()
|
||||
@ -29,6 +32,7 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
@ -40,33 +44,41 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1'
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.3'
|
||||
implementation 'androidx.core:core-ktx:1.6.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
|
||||
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.13.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-hls:2.13.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.13.2'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.2'
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.8'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.15.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-hls:2.15.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.15.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.0'
|
||||
implementation 'com.google.android.exoplayer:extension-mediasession:2.15.0'
|
||||
|
||||
implementation 'org.jsoup:jsoup:1.13.1'
|
||||
implementation 'org.jsoup:jsoup:1.14.2'
|
||||
implementation 'com.github.bumptech.glide:glide:4.12.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'
|
||||
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'com.github.kittinunf.fuel:fuel:2.3.1'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-android:2.3.1'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-json:2.3.1'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
}
|
||||
|
||||
|
30
app/proguard-rules.pro
vendored
@ -22,10 +22,40 @@
|
||||
#-renamesourcefileattribute SourceFile
|
||||
-keep class org.mosad.teapod.util.** { <fields>; }
|
||||
|
||||
-keep class org.json.** { *; }
|
||||
|
||||
#Gson
|
||||
-keepattributes Signature
|
||||
-dontwarn sun.misc.**
|
||||
|
||||
# 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
|
||||
|
||||
#misc
|
||||
-dontwarn java.lang.instrument.ClassFileTransformer
|
||||
-dontwarn java.lang.ClassValue
|
||||
|
@ -1,437 +0,0 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2021 <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
|
||||
|
||||
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.*
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import java.io.IOException
|
||||
import java.lang.NumberFormatException
|
||||
import java.util.*
|
||||
import kotlin.random.Random
|
||||
|
||||
object AoDParser {
|
||||
|
||||
private const val baseUrl = "https://www.anime-on-demand.de"
|
||||
private const val loginPath = "/users/sign_in"
|
||||
private const val libraryPath = "/animes"
|
||||
|
||||
private const val userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0"
|
||||
|
||||
private var sessionCookies = mutableMapOf<String, String>()
|
||||
private var csrfToken: String = ""
|
||||
private var loginSuccess = false
|
||||
|
||||
private val mediaList = arrayListOf<Media>() // actual media (data)
|
||||
val itemMediaList = arrayListOf<ItemMedia>() // gui media
|
||||
val highlightsList = arrayListOf<ItemMedia>()
|
||||
val newEpisodesList = arrayListOf<ItemMedia>()
|
||||
val newSimulcastsList = arrayListOf<ItemMedia>()
|
||||
val newTitlesList = arrayListOf<ItemMedia>()
|
||||
val topTenList = arrayListOf<ItemMedia>()
|
||||
|
||||
fun login(): Boolean = runBlocking {
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
// 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)
|
||||
.timeout(60000) // login can take some time default is 60000 (60 sec)
|
||||
.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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initially load all media and home screen data
|
||||
*/
|
||||
fun initialLoading() = listOf(
|
||||
loadHome(),
|
||||
listAnimes()
|
||||
)
|
||||
|
||||
/**
|
||||
* get a media by it's ID (int)
|
||||
* @return Media
|
||||
*/
|
||||
suspend fun getMediaById(mediaId: Int): Media {
|
||||
val media = mediaList.first { it.id == mediaId }
|
||||
|
||||
if (media.episodes.isEmpty()) {
|
||||
loadStreams(media).join()
|
||||
}
|
||||
|
||||
return media
|
||||
}
|
||||
|
||||
fun markAsWatched(mediaId: Int, episodeId: Int) = GlobalScope.launch {
|
||||
val episode = getMediaById(mediaId).getEpisodeById(episodeId)
|
||||
episode.watched = true
|
||||
sendCallback(episode.watchedCallback)
|
||||
|
||||
Log.d(javaClass.name, "Marked episode ${episode.id} as watched")
|
||||
}
|
||||
|
||||
// TODO don't use jsoup here
|
||||
private fun sendCallback(callbackPath: String) = GlobalScope.launch(Dispatchers.IO) {
|
||||
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 {
|
||||
Jsoup.connect(baseUrl + callbackPath)
|
||||
.ignoreContentType(true)
|
||||
.cookies(sessionCookies)
|
||||
.headers(headers)
|
||||
.execute()
|
||||
} catch (ex: IOException) {
|
||||
Log.e(javaClass.name, "Callback for $callbackPath failed.", ex)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* load all media from aod into itemMediaList and mediaList
|
||||
*/
|
||||
private fun listAnimes() = GlobalScope.launch(Dispatchers.IO) {
|
||||
val resAnimes = Jsoup.connect(baseUrl + libraryPath).get()
|
||||
//println(resAnimes)
|
||||
|
||||
itemMediaList.clear()
|
||||
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}")
|
||||
}
|
||||
|
||||
/**
|
||||
* load new episodes, titles and highlights
|
||||
*/
|
||||
private fun loadHome() = GlobalScope.launch(Dispatchers.IO) {
|
||||
val resHome = Jsoup.connect(baseUrl).get()
|
||||
|
||||
// get highlights from AoD
|
||||
highlightsList.clear()
|
||||
resHome.select("#aod-highlights").select("div.news-item").forEach {
|
||||
val mediaId = it.select("div.news-item-text").select("a.serienlink")
|
||||
.attr("href").substringAfterLast("/").toIntOrNull()
|
||||
val mediaTitle = it.select("div.news-title").select("h2").text()
|
||||
val mediaImage = it.select("img").attr("src")
|
||||
|
||||
if (mediaId != null) {
|
||||
highlightsList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
}
|
||||
}
|
||||
|
||||
// get all new episodes from AoD
|
||||
newEpisodesList.clear()
|
||||
resHome.select("h2:contains(Neue Episoden)").next().select("li").forEach {
|
||||
val mediaId = it.select("a.thumbs").attr("href")
|
||||
.substringAfterLast("/").toIntOrNull()
|
||||
val mediaImage = it.select("a.thumbs > img").attr("src")
|
||||
val mediaTitle = "${it.select("a").text()} - ${it.select("span.neweps").text()}"
|
||||
|
||||
if (mediaId != null) {
|
||||
newEpisodesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
}
|
||||
}
|
||||
|
||||
// get new simulcasts from AoD
|
||||
newSimulcastsList.clear()
|
||||
resHome.select("h2:contains(Neue Simulcasts)").next().select("li").forEach {
|
||||
val mediaId = it.select("a.thumbs").attr("href")
|
||||
.substringAfterLast("/").toIntOrNull()
|
||||
val mediaImage = it.select("a.thumbs > img").attr("src")
|
||||
val mediaTitle = it.select("a").text()
|
||||
|
||||
if (mediaId != null) {
|
||||
newSimulcastsList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
}
|
||||
}
|
||||
|
||||
// get new titles from AoD
|
||||
newTitlesList.clear()
|
||||
resHome.select("h2:contains(Neue Anime-Titel)").next().select("li").forEach {
|
||||
val mediaId = it.select("a.thumbs").attr("href")
|
||||
.substringAfterLast("/").toIntOrNull()
|
||||
val mediaImage = it.select("a.thumbs > img").attr("src")
|
||||
val mediaTitle = it.select("a").text()
|
||||
|
||||
if (mediaId != null) {
|
||||
newTitlesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
}
|
||||
}
|
||||
|
||||
// get top ten from AoD
|
||||
topTenList.clear()
|
||||
resHome.select("h2:contains(Anime Top 10)").next().select("li").forEach {
|
||||
val mediaId = it.select("a.thumbs").attr("href")
|
||||
.substringAfterLast("/").toIntOrNull()
|
||||
val mediaImage = it.select("a.thumbs > img").attr("src")
|
||||
val mediaTitle = it.select("a").text()
|
||||
|
||||
if (mediaId != null) {
|
||||
topTenList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
|
||||
}
|
||||
}
|
||||
|
||||
// if highlights is empty, add a random new title
|
||||
if (highlightsList.isEmpty()) {
|
||||
if (newTitlesList.isNotEmpty()) {
|
||||
highlightsList.add(newTitlesList[Random.nextInt(0, newTitlesList.size)])
|
||||
} else {
|
||||
highlightsList.add(ItemMedia(0,"", ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load streams for the media path, movies have one episode
|
||||
* @param media is used as call ba reference
|
||||
*/
|
||||
private fun loadStreams(media: Media) = GlobalScope.launch(Dispatchers.IO) {
|
||||
if (sessionCookies.isEmpty()) login()
|
||||
|
||||
if (!loginSuccess) {
|
||||
Log.w(javaClass.name, "Login, was not successful.")
|
||||
return@launch
|
||||
}
|
||||
|
||||
// get the media page
|
||||
val res = Jsoup.connect(baseUrl + media.link)
|
||||
.cookies(sessionCookies)
|
||||
.get()
|
||||
|
||||
//println(res)
|
||||
|
||||
if (csrfToken.isEmpty()) {
|
||||
csrfToken = res.select("meta[name=csrf-token]").attr("content")
|
||||
//Log.i(javaClass.name, "New csrf token is $csrfToken")
|
||||
}
|
||||
|
||||
val besides = res.select("div.besides").first()
|
||||
val playlists = besides.select("input.streamstarter_html5").map { streamstarter ->
|
||||
parsePlaylistAsync(
|
||||
streamstarter.attr("data-playlist"),
|
||||
streamstarter.attr("data-lang")
|
||||
)
|
||||
}.awaitAll()
|
||||
|
||||
playlists.forEach { aod ->
|
||||
// TODO improve language handling
|
||||
val locale = when (aod.extLanguage) {
|
||||
"ger" -> Locale.GERMAN
|
||||
"jap" -> Locale.JAPANESE
|
||||
else -> Locale.ROOT
|
||||
}
|
||||
|
||||
aod.playlist.forEach { ep ->
|
||||
try {
|
||||
if (media.hasEpisode(ep.mediaid)) {
|
||||
media.getEpisodeById(ep.mediaid).streams.add(
|
||||
Stream(ep.sources.first().file, locale)
|
||||
)
|
||||
} else {
|
||||
media.episodes.add(Episode(
|
||||
id = ep.mediaid,
|
||||
streams = mutableListOf(Stream(ep.sources.first().file, locale)),
|
||||
posterUrl = ep.image,
|
||||
title = ep.title,
|
||||
description = ep.description,
|
||||
number = getNumberFromTitle(ep.title, media.type)
|
||||
))
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
Log.w(javaClass.name, "Could not parse episode information.", ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i(javaClass.name, "Loaded playlists successfully")
|
||||
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// similar titles from media page
|
||||
media.info.similar = res.select("h2:contains(Ähnliche Animes)").next().select("li").mapNotNull {
|
||||
val mediaId = it.select("a.thumbs").attr("href")
|
||||
.substringAfterLast("/").toIntOrNull()
|
||||
val mediaImage = it.select("a.thumbs > img").attr("src")
|
||||
val mediaTitle = it.select("a").text()
|
||||
|
||||
if (mediaId != null) {
|
||||
ItemMedia(mediaId, mediaTitle, mediaImage)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
// additional information for tv shows the episode title (description) is loaded from the "api"
|
||||
if (media.type == MediaType.TVSHOW) {
|
||||
res.select("div.three-box-container > div.episodebox").forEach { episodebox ->
|
||||
// make sure the episode has a streaming link
|
||||
if (episodebox.select("input.streamstarter_html5").isNotEmpty()) {
|
||||
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()
|
||||
|
||||
media.episodes.firstOrNull { it.id == episodeId }?.apply {
|
||||
shortDesc = episodeShortDesc
|
||||
watched = episodeWatched
|
||||
watchedCallback = episodeWatchedCallback
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i(javaClass.name, "media loaded successfully")
|
||||
}
|
||||
|
||||
/**
|
||||
* don't use Gson().fromJson() as we don't have any control over the api and it may change
|
||||
*/
|
||||
private fun parsePlaylistAsync(playlistPath: String, language: String): Deferred<AoDObject> {
|
||||
if (playlistPath == "[]") {
|
||||
return CompletableDeferred(AoDObject(listOf(), language))
|
||||
}
|
||||
|
||||
return GlobalScope.async(Dispatchers.IO) {
|
||||
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()
|
||||
|
||||
//Gson().fromJson(res.body(), AoDObject::class.java)
|
||||
|
||||
return@async AoDObject(JsonParser.parseString(res.body()).asJsonObject
|
||||
.get("playlist").asJsonArray.map {
|
||||
Playlist(
|
||||
sources = it.asJsonObject.get("sources").asJsonArray.map { source ->
|
||||
Source(source.asJsonObject.get("file").asString)
|
||||
},
|
||||
image = it.asJsonObject.get("image").asString,
|
||||
title = it.asJsonObject.get("title").asString,
|
||||
description = it.asJsonObject.get("description").asString,
|
||||
mediaid = it.asJsonObject.get("mediaid").asInt
|
||||
)
|
||||
},
|
||||
language
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the episode number from the title
|
||||
* @param title the episode title, containing a number after "Ep."
|
||||
* @param type the media type, if not TVSHOW, return 0
|
||||
* @return the episode number, on NumberFormatException return 0
|
||||
*/
|
||||
private fun getNumberFromTitle(title: String, type: MediaType): Int {
|
||||
return if (type == MediaType.TVSHOW) {
|
||||
try {
|
||||
title.substringAfter(", Ep. ").toInt()
|
||||
} catch (nex: NumberFormatException) {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,484 @@
|
||||
package org.mosad.teapod.parser.crunchyroll
|
||||
|
||||
import android.util.Log
|
||||
import com.github.kittinunf.fuel.Fuel
|
||||
import com.github.kittinunf.fuel.core.FuelError
|
||||
import com.github.kittinunf.fuel.core.Parameters
|
||||
import com.github.kittinunf.fuel.core.extensions.jsonBody
|
||||
import com.github.kittinunf.fuel.json.FuelJson
|
||||
import com.github.kittinunf.fuel.json.responseJson
|
||||
import com.github.kittinunf.result.Result
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.put
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.concatenate
|
||||
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
|
||||
object Crunchyroll {
|
||||
|
||||
private const val baseUrl = "https://beta-api.crunchyroll.com"
|
||||
|
||||
private var accessToken = ""
|
||||
private var tokenType = ""
|
||||
private var tokenValidUntil: Long = 0
|
||||
|
||||
private var accountID = ""
|
||||
|
||||
private var policy = ""
|
||||
private var signature = ""
|
||||
private var keyPairID = ""
|
||||
|
||||
// TODO temp helper vary
|
||||
private var locale: String = Preferences.preferredLocal.toLanguageTag()
|
||||
private var country: String = Preferences.preferredLocal.country
|
||||
|
||||
private val browsingCache = arrayListOf<Item>()
|
||||
|
||||
/**
|
||||
* 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 = listOf(
|
||||
"username" to username,
|
||||
"password" to password,
|
||||
"grant_type" to "password",
|
||||
"scope" to "offline_access"
|
||||
)
|
||||
|
||||
var success: Boolean // is false
|
||||
withContext(Dispatchers.IO) {
|
||||
val (request, response, result) = Fuel.post("$baseUrl$tokenEndpoint", parameters = formData)
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.appendHeader(
|
||||
"Authorization",
|
||||
"Basic "
|
||||
)
|
||||
.responseJson()
|
||||
|
||||
// TODO fix JSONException: No value for
|
||||
result.component1()?.obj()?.let {
|
||||
accessToken = it.get("access_token").toString()
|
||||
tokenType = it.get("token_type").toString()
|
||||
|
||||
// token will be invalid 1 sec
|
||||
val expiresIn = (it.get("expires_in").toString().toLong() - 1)
|
||||
tokenValidUntil = System.currentTimeMillis() + (expiresIn * 1000)
|
||||
}
|
||||
|
||||
// println("request: $request")
|
||||
// println("response: $response")
|
||||
// println("response: $result")
|
||||
|
||||
Log.i(javaClass.name, "login complete with code ${response.statusCode}")
|
||||
success = (response.statusCode == 200)
|
||||
}
|
||||
|
||||
return@runBlocking success
|
||||
}
|
||||
|
||||
private fun refreshToken() {
|
||||
login(EncryptedPreferences.login, EncryptedPreferences.password)
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests: get, post, delete
|
||||
*/
|
||||
|
||||
private suspend fun request(
|
||||
endpoint: String,
|
||||
params: Parameters = listOf(),
|
||||
url: String = ""
|
||||
): Result<FuelJson, FuelError> = coroutineScope {
|
||||
val path = url.ifEmpty { "$baseUrl$endpoint" }
|
||||
if (System.currentTimeMillis() > tokenValidUntil) refreshToken()
|
||||
|
||||
return@coroutineScope (Dispatchers.IO) {
|
||||
val (request, response, result) = Fuel.get(path, params)
|
||||
.header("Authorization", "$tokenType $accessToken")
|
||||
.responseJson()
|
||||
|
||||
// println("request request: $request")
|
||||
// println("request response: $response")
|
||||
// println("request result: $result")
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun requestPost(
|
||||
endpoint: String,
|
||||
params: Parameters = listOf(),
|
||||
body: String
|
||||
) = coroutineScope {
|
||||
val path = "$baseUrl$endpoint"
|
||||
if (System.currentTimeMillis() > tokenValidUntil) refreshToken()
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
Fuel.post(path, params)
|
||||
.header("Authorization", "$tokenType $accessToken")
|
||||
.jsonBody(body)
|
||||
.response() // without a response, crunchy doesn't accept the request
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun requestDelete(
|
||||
endpoint: String,
|
||||
params: Parameters = listOf(),
|
||||
url: String = ""
|
||||
) = coroutineScope {
|
||||
val path = url.ifEmpty { "$baseUrl$endpoint" }
|
||||
if (System.currentTimeMillis() > tokenValidUntil) refreshToken()
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
Fuel.delete(path, params)
|
||||
.header("Authorization", "$tokenType $accessToken")
|
||||
.response() // without a response, crunchy doesn't accept the request
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic functions: index, account
|
||||
* Needed for other functions to work properly!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve the identifiers necessary for streaming. If the identifiers are
|
||||
* retrieved, set the corresponding global var. The identifiers are valid for 24h.
|
||||
*/
|
||||
suspend fun index() {
|
||||
val indexEndpoint = "/index/v2"
|
||||
val result = request(indexEndpoint)
|
||||
|
||||
result.component1()?.obj()?.getJSONObject("cms")?.let {
|
||||
policy = it.get("policy").toString()
|
||||
signature = it.get("signature").toString()
|
||||
keyPairID = it.get("key_pair_id").toString()
|
||||
}
|
||||
|
||||
println("policy: $policy")
|
||||
println("signature: $signature")
|
||||
println("keyPairID: $keyPairID")
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 result = request(indexEndpoint)
|
||||
|
||||
result.component1()?.obj()?.let {
|
||||
accountID = it.get("account_id").toString()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* General element/media functions: browse, search, objects, season_list
|
||||
*/
|
||||
|
||||
// TODO locale de-DE, categories
|
||||
/**
|
||||
* Browse the media available on crunchyroll.
|
||||
*
|
||||
* @param sortBy
|
||||
* @param n Number of items to return, defaults to 10
|
||||
*
|
||||
* @return A **[BrowseResult]** object is returned.
|
||||
*/
|
||||
suspend fun browse(
|
||||
sortBy: SortBy = SortBy.ALPHABETICAL,
|
||||
seasonTag: String = "",
|
||||
start: Int = 0,
|
||||
n: Int = 10
|
||||
): BrowseResult {
|
||||
val browseEndpoint = "/content/v1/browse"
|
||||
val noneOptParams = listOf("sort_by" to sortBy.str, "start" to start, "n" to n)
|
||||
|
||||
// if a season tag is present add it to the parameters
|
||||
val parameters = if (seasonTag.isNotEmpty()) {
|
||||
concatenate(noneOptParams, listOf("season_tag" to seasonTag))
|
||||
} else {
|
||||
noneOptParams
|
||||
}
|
||||
|
||||
val result = request(browseEndpoint, parameters)
|
||||
val browseResult = result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneBrowseResult
|
||||
|
||||
// add results to cache TODO improve
|
||||
browsingCache.clear()
|
||||
browsingCache.addAll(browseResult.items)
|
||||
|
||||
return browseResult
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
suspend fun search(query: String, n: Int = 10): SearchResult {
|
||||
val searchEndpoint = "/content/v1/search"
|
||||
val parameters = listOf("q" to query, "n" to n, "locale" to locale, "type" to "series")
|
||||
|
||||
val result = request(searchEndpoint, parameters)
|
||||
// TODO episodes have thumbnails as image, and not poster_tall/poster_tall,
|
||||
// to work around this, for now only tv shows are supported
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneSearchResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of series objects.
|
||||
* Note: episode objects are currently not supported
|
||||
*
|
||||
* @param objects The object IDs as list of Strings
|
||||
* @return A **[Collection]** of Panels
|
||||
*/
|
||||
suspend fun objects(objects: List<String>): Collection<Item> {
|
||||
val episodesEndpoint = "/cms/v2/DE/M3/crunchyroll/objects/${objects.joinToString(",")}"
|
||||
val parameters = listOf(
|
||||
"locale" to locale,
|
||||
"Signature" to signature,
|
||||
"Policy" to policy,
|
||||
"Key-Pair-Id" to keyPairID
|
||||
)
|
||||
|
||||
val result = request(episodesEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneCollection
|
||||
}
|
||||
|
||||
/**
|
||||
* List all available seasons as **[SeasonListItem]**.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
suspend fun seasonList(): DiscSeasonList {
|
||||
val seasonListEndpoint = "/content/v1/season_list"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val result = request(seasonListEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneDiscSeasonList
|
||||
}
|
||||
|
||||
/**
|
||||
* Main media functions: series, season, episodes, playback
|
||||
*/
|
||||
|
||||
/**
|
||||
* series id == crunchyroll id?
|
||||
*/
|
||||
suspend fun series(seriesId: String): Series {
|
||||
val seriesEndpoint = "/cms/v2/$country/M3/crunchyroll/series/$seriesId"
|
||||
val parameters = listOf(
|
||||
"locale" to locale,
|
||||
"Signature" to signature,
|
||||
"Policy" to policy,
|
||||
"Key-Pair-Id" to keyPairID
|
||||
)
|
||||
|
||||
val result = request(seriesEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneSeries
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
suspend fun upNextSeries(seriesId: String): UpNextSeriesItem {
|
||||
val upNextSeriesEndpoint = "/content/v1/up_next_series"
|
||||
val parameters = listOf(
|
||||
"series_id" to seriesId,
|
||||
"locale" to locale
|
||||
)
|
||||
|
||||
val result = request(upNextSeriesEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneUpNextSeriesItem
|
||||
}
|
||||
|
||||
suspend fun seasons(seriesId: String): Seasons {
|
||||
val episodesEndpoint = "/cms/v2/$country/M3/crunchyroll/seasons"
|
||||
val parameters = listOf(
|
||||
"series_id" to seriesId,
|
||||
"locale" to locale,
|
||||
"Signature" to signature,
|
||||
"Policy" to policy,
|
||||
"Key-Pair-Id" to keyPairID
|
||||
)
|
||||
|
||||
val result = request(episodesEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneSeasons
|
||||
}
|
||||
|
||||
suspend fun episodes(seasonId: String): Episodes {
|
||||
val episodesEndpoint = "/cms/v2/$country/M3/crunchyroll/episodes"
|
||||
val parameters = listOf(
|
||||
"season_id" to seasonId,
|
||||
"locale" to locale,
|
||||
"Signature" to signature,
|
||||
"Policy" to policy,
|
||||
"Key-Pair-Id" to keyPairID
|
||||
)
|
||||
|
||||
val result = request(episodesEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneEpisodes
|
||||
}
|
||||
|
||||
suspend fun playback(url: String): Playback {
|
||||
val result = request("", url = url)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NonePlayback
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional media functions: watchlist (series), playhead
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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/v1/watchlist/$accountID/$seriesId"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val result = request(watchlistSeriesEndpoint, parameters)
|
||||
// if needed implement parsing
|
||||
|
||||
return result.component1()?.obj()?.has(seriesId) ?: 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/v1/watchlist/$accountID"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val json = buildJsonObject {
|
||||
put("content_id", seriesId)
|
||||
}
|
||||
|
||||
requestPost(watchlistPostEndpoint, parameters, json.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* 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/v1/watchlist/$accountID/$seriesId"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
requestDelete(watchlistDeleteEndpoint, parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>): PlayheadsMap {
|
||||
val playheadsEndpoint = "/content/v1/playheads/$accountID/${episodeIDs.joinToString(",")}"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val result = request(playheadsEndpoint, parameters)
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: emptyMap()
|
||||
}
|
||||
|
||||
suspend fun postPlayheads(episodeId: String, playhead: Int) {
|
||||
val playheadsEndpoint = "/content/v1/playheads/$accountID"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val json = buildJsonObject {
|
||||
put("content_id", episodeId)
|
||||
put("playhead", playhead)
|
||||
}
|
||||
|
||||
requestPost(playheadsEndpoint, parameters, json.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 **[Watchlist]** containing up to n **[Item]**.
|
||||
*/
|
||||
suspend fun watchlist(n: Int = 20): Watchlist {
|
||||
val watchlistEndpoint = "/content/v1/$accountID/watchlist"
|
||||
val parameters = listOf("locale" to locale, "n" to n)
|
||||
|
||||
val watchlistResult = request(watchlistEndpoint, parameters)
|
||||
val list: ContinueWatchingList = watchlistResult.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneContinueWatchingList
|
||||
|
||||
val objects = list.items.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, defaults to 20.
|
||||
* @return A **[ContinueWatchingList]** containing up to n **[ContinueWatchingItem]**.
|
||||
*/
|
||||
suspend fun upNextAccount(n: Int = 20): ContinueWatchingList {
|
||||
val watchlistEndpoint = "/content/v1/$accountID/up_next_account"
|
||||
val parameters = listOf("locale" to locale, "n" to n)
|
||||
|
||||
val resultUpNextAccount = request(watchlistEndpoint, parameters)
|
||||
return resultUpNextAccount.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneContinueWatchingList
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,297 @@
|
||||
package org.mosad.teapod.parser.crunchyroll
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* data classes for browse
|
||||
* TODO make class names more clear/possibly overlapping for now
|
||||
*/
|
||||
enum class SortBy(val str: String) {
|
||||
ALPHABETICAL("alphabetical"),
|
||||
NEWLY_ADDED("newly_added"),
|
||||
POPULARITY("popularity")
|
||||
}
|
||||
|
||||
/**
|
||||
* search, browse, DiscSeasonList, Watchlist, ContinueWatchingList data types all use Collection
|
||||
*/
|
||||
|
||||
@Serializable
|
||||
data class Collection<T>(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("items") val items: List<T>
|
||||
)
|
||||
|
||||
typealias SearchResult = Collection<SearchCollection>
|
||||
typealias SearchCollection = Collection<Item>
|
||||
typealias BrowseResult = Collection<Item>
|
||||
typealias DiscSeasonList = Collection<SeasonListItem>
|
||||
typealias Watchlist = Collection<Item>
|
||||
typealias ContinueWatchingList = Collection<ContinueWatchingItem>
|
||||
|
||||
@Serializable
|
||||
data class UpNextSeriesItem(
|
||||
val playhead: Int,
|
||||
val fully_watched: Boolean,
|
||||
val never_watched: Boolean,
|
||||
val panel: EpisodePanel,
|
||||
)
|
||||
|
||||
/**
|
||||
* panel data classes
|
||||
*/
|
||||
|
||||
// the data class Item is used in browse and search
|
||||
// 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.
|
||||
)
|
||||
|
||||
@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)
|
||||
|
||||
/**
|
||||
* season list data classes
|
||||
*/
|
||||
@Serializable
|
||||
data class SeasonListItem(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("localization") val localization: SeasonListLocalization
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SeasonListLocalization(
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("description") val description: String,
|
||||
)
|
||||
|
||||
/**
|
||||
* continue_watching_item data classes
|
||||
*/
|
||||
@Serializable
|
||||
data class ContinueWatchingItem(
|
||||
@SerialName("panel") val panel: EpisodePanel,
|
||||
@SerialName("new") val new: Boolean,
|
||||
@SerialName("new_content") val newContent: Boolean,
|
||||
// not present in up_next_account -> continue_watching_item
|
||||
// @SerialName("is_favorite") val isFavorite: Boolean,
|
||||
// @SerialName("never_watched") val neverWatched: Boolean,
|
||||
// @SerialName("completion_status") val completionStatus: Boolean,
|
||||
@SerialName("playhead") val playhead: Int,
|
||||
// not present in watchlist -> continue_watching_item
|
||||
// @SerialName("fully_watched") val fullyWatched: Boolean,
|
||||
)
|
||||
|
||||
// EpisodePanel is used in ContinueWatchingItem
|
||||
@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("playback") val playback: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EpisodeMetadata(
|
||||
@SerialName("duration_ms") val durationMs: Int,
|
||||
@SerialName("season_id") val seasonId: String,
|
||||
@SerialName("series_id") val seriesId: String,
|
||||
@SerialName("series_title") val seriesTitle: String,
|
||||
)
|
||||
|
||||
val NoneItem = Item("", "", "", "", "", Images(emptyList(), emptyList()))
|
||||
val NoneEpisodeMetadata = EpisodeMetadata(0, "", "", "")
|
||||
val NoneEpisodePanel = EpisodePanel("", "", "", "", "", NoneEpisodeMetadata, Thumbnail(listOf()), "")
|
||||
|
||||
val NoneCollection = Collection<Item>(0, emptyList())
|
||||
val NoneSearchResult = SearchResult(0, emptyList())
|
||||
val NoneBrowseResult = BrowseResult(0, emptyList())
|
||||
val NoneDiscSeasonList = DiscSeasonList(0, emptyList())
|
||||
val NoneContinueWatchingList = ContinueWatchingList(0, emptyList())
|
||||
|
||||
val NoneUpNextSeriesItem =UpNextSeriesItem(0, false, false, NoneEpisodePanel)
|
||||
|
||||
/**
|
||||
* Series data type
|
||||
*/
|
||||
@Serializable
|
||||
data class Series(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("description") val description: String,
|
||||
@SerialName("images") val images: Images,
|
||||
@SerialName("maturity_ratings") val maturityRatings: List<String>
|
||||
)
|
||||
val NoneSeries = Series("", "", "", Images(emptyList(), emptyList()), emptyList())
|
||||
|
||||
/**
|
||||
* Seasons data type
|
||||
*/
|
||||
@Serializable
|
||||
data class Seasons(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("items") val items: List<Season>
|
||||
) {
|
||||
fun getPreferredSeason(local: Locale): Season {
|
||||
// try to get the the first seasons which matches the preferred local
|
||||
items.forEach { season ->
|
||||
if (season.title.startsWith("(${local.language})", true)) {
|
||||
return season
|
||||
}
|
||||
}
|
||||
|
||||
// if there is no season with the preferred local, try to find a subbed season
|
||||
items.forEach { season ->
|
||||
if (season.isSubbed) {
|
||||
return season
|
||||
}
|
||||
}
|
||||
|
||||
// if there is no preferred language season and no sub, use the first season
|
||||
return items.first()
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Season(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: 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 type
|
||||
*/
|
||||
@Serializable
|
||||
data class Episodes(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("items") val items: 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("playback") val playback: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Thumbnail(
|
||||
@SerialName("thumbnail") val thumbnail: List<List<Poster>>
|
||||
)
|
||||
|
||||
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,
|
||||
playback = ""
|
||||
)
|
||||
|
||||
typealias PlayheadsMap = Map<String, 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,
|
||||
)
|
||||
|
||||
/**
|
||||
* Playback/stream data type
|
||||
*/
|
||||
@Serializable
|
||||
data class Playback(
|
||||
@SerialName("audio_locale") val audioLocale: String,
|
||||
@SerialName("subtitles") val subtitles: Map<String, Subtitle>,
|
||||
@SerialName("streams") val streams: Streams,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Subtitle(
|
||||
@SerialName("locale") val locale: String,
|
||||
@SerialName("url") val url: String,
|
||||
@SerialName("format") val format: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Streams(
|
||||
@SerialName("adaptive_dash") val adaptive_dash: Map<String, Stream>,
|
||||
@SerialName("adaptive_hls") val adaptive_hls: Map<String, Stream>,
|
||||
@SerialName("download_hls") val download_hls: Map<String, Stream>,
|
||||
@SerialName("drm_adaptive_dash") val drm_adaptive_dash: Map<String, Stream>,
|
||||
@SerialName("drm_adaptive_hls") val drm_adaptive_hls: Map<String, Stream>,
|
||||
@SerialName("drm_download_hls") val drm_download_hls: Map<String, Stream>,
|
||||
@SerialName("trailer_dash") val trailer_dash: Map<String, Stream>,
|
||||
@SerialName("trailer_hls") val trailer_hls: 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,
|
||||
@SerialName("url") val url: String,
|
||||
@SerialName("vcodec") val vcodec: String,
|
||||
)
|
||||
|
||||
val NonePlayback = Playback(
|
||||
"",
|
||||
mapOf(),
|
||||
Streams(
|
||||
mapOf(), mapOf(), mapOf(), mapOf(), mapOf(), mapOf(),
|
||||
mapOf(), mapOf(), mapOf(), mapOf(), mapOf(), mapOf(),
|
||||
)
|
||||
)
|
@ -4,13 +4,18 @@ 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 preferSecondary = false
|
||||
internal set
|
||||
var preferredLocal = Locale.GERMANY
|
||||
internal set
|
||||
var autoplay = true
|
||||
internal set
|
||||
var devSettings = false
|
||||
internal set
|
||||
var theme = DataTypes.Theme.DARK
|
||||
internal set
|
||||
|
||||
@ -39,6 +44,15 @@ object Preferences {
|
||||
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())
|
||||
@ -60,6 +74,9 @@ object Preferences {
|
||||
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.DARK.toString()
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Teapod
|
||||
*
|
||||
* Copyright 2020-2021 <seil0@mosad.xyz>
|
||||
* 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
|
||||
@ -29,36 +29,29 @@ import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.commit
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.runBlocking
|
||||
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.AoDParser
|
||||
import org.mosad.teapod.ui.activity.player.PlayerActivity
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.ui.components.LoginDialog
|
||||
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.LibraryFragment
|
||||
import org.mosad.teapod.ui.activity.main.fragments.SearchFragment
|
||||
import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
|
||||
import org.mosad.teapod.ui.activity.player.PlayerActivity
|
||||
import org.mosad.teapod.ui.components.LoginDialog
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.util.exitAndRemoveTask
|
||||
import java.net.SocketTimeoutException
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListener {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private var activeBaseFragment: Fragment = HomeFragment() // the currently active fragment, home at the start
|
||||
|
||||
companion object {
|
||||
var wasInitialized = false
|
||||
lateinit var instance: MainActivity
|
||||
}
|
||||
|
||||
@ -69,11 +62,11 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
if (!wasInitialized) { load() }
|
||||
load() // start the initial loading
|
||||
theme.applyStyle(getThemeResource(), true)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
binding.navView.setOnNavigationItemSelectedListener(this)
|
||||
binding.navView.setOnItemSelectedListener(this)
|
||||
setContentView(binding.root)
|
||||
|
||||
supportFragmentManager.commit {
|
||||
@ -138,48 +131,43 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
||||
*/
|
||||
private fun load() {
|
||||
val time = measureTimeMillis {
|
||||
val loadingJob = AoDParser.initialLoading() // start the initial loading
|
||||
|
||||
// load all saved stuff here
|
||||
Preferences.load(this)
|
||||
EncryptedPreferences.readCredentials(this)
|
||||
StorageController.load(this)
|
||||
|
||||
// show onbaording
|
||||
if (EncryptedPreferences.password.isEmpty()) {
|
||||
// show onboarding if no password is set, or login fails
|
||||
if (EncryptedPreferences.password.isEmpty() || !Crunchyroll.login(
|
||||
EncryptedPreferences.login,
|
||||
EncryptedPreferences.password
|
||||
)
|
||||
) {
|
||||
showOnboarding()
|
||||
} else {
|
||||
try {
|
||||
if (!AoDParser.login()) {
|
||||
showLoginDialog()
|
||||
}
|
||||
} catch (ex: SocketTimeoutException) {
|
||||
Log.w(javaClass.name, "Timeout during login!")
|
||||
|
||||
// show waring dialog before finishing
|
||||
MaterialDialog(this).show {
|
||||
title(R.string.dialog_timeout_head)
|
||||
message(R.string.dialog_timeout_desc)
|
||||
onDismiss { exitAndRemoveTask() }
|
||||
}
|
||||
}
|
||||
runBlocking { initCrunchyroll().joinAll() }
|
||||
}
|
||||
|
||||
runBlocking { loadingJob.joinAll() } // wait for initial loading to finish
|
||||
}
|
||||
Log.i(javaClass.name, "loading and login in $time ms")
|
||||
Log.i(javaClass.name, "loading in $time ms")
|
||||
}
|
||||
|
||||
wasInitialized = true
|
||||
private fun initCrunchyroll(): List<Job> {
|
||||
println("init")
|
||||
|
||||
val scope = CoroutineScope(Dispatchers.IO + CoroutineName("InitialLoadingScope"))
|
||||
return listOf(
|
||||
scope.launch { Crunchyroll.index() },
|
||||
scope.launch { Crunchyroll.account() }
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLoginDialog() {
|
||||
LoginDialog(this, false).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
|
||||
if (!AoDParser.login()) {
|
||||
showLoginDialog()
|
||||
Log.w(javaClass.name, "Login failed, please try again.")
|
||||
}
|
||||
// TODO
|
||||
// if (!AoDParser.login()) {
|
||||
// showLoginDialog()
|
||||
// Log.w(javaClass.name, "Login failed, please try again.")
|
||||
// }
|
||||
}.negativeButton {
|
||||
Log.i(javaClass.name, "Login canceled, exiting.")
|
||||
finish()
|
||||
@ -197,9 +185,9 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
||||
/**
|
||||
* start the player as new activity
|
||||
*/
|
||||
fun startPlayer(mediaId: Int, episodeId: Int) {
|
||||
fun startPlayer(seasonId: String, episodeId: String) {
|
||||
val intent = Intent(this, PlayerActivity::class.java).apply {
|
||||
putExtra(getString(R.string.intent_media_id), mediaId)
|
||||
putExtra(getString(R.string.intent_season_id), seasonId)
|
||||
putExtra(getString(R.string.intent_episode_id), episodeId)
|
||||
}
|
||||
startActivity(intent)
|
||||
|
@ -6,6 +6,7 @@ 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.afollestad.materialdialogs.MaterialDialog
|
||||
@ -13,15 +14,21 @@ 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 val teapodRepoUrl = "https://git.mosad.xyz/Seil0/teapod"
|
||||
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
|
||||
@ -52,6 +59,10 @@ class AboutFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
binding.imageAppIcon.setOnClickListener {
|
||||
checkDevSettings()
|
||||
}
|
||||
|
||||
binding.linearSource.setOnClickListener {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(teapodRepoUrl)))
|
||||
}
|
||||
@ -64,6 +75,30 @@ class AboutFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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",
|
||||
|
@ -1,20 +1,25 @@
|
||||
package org.mosad.teapod.ui.activity.main.fragments
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentAccountBinding
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
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.LoginDialog
|
||||
import org.mosad.teapod.util.DataTypes.Theme
|
||||
import org.mosad.teapod.util.showFragment
|
||||
@ -23,6 +28,28 @@ class AccountFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentAccountBinding
|
||||
|
||||
private val getUriExport = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
result.data?.data?.also { uri ->
|
||||
//StorageController.exportMyList(requireContext(), uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val getUriImport = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
result.data?.data?.also { uri ->
|
||||
// val success = StorageController.importMyList(requireContext(), uri)
|
||||
// if (success == 0) {
|
||||
// Toast.makeText(
|
||||
// context, getString(R.string.import_data_success),
|
||||
// Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentAccountBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
@ -31,6 +58,16 @@ class AccountFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// TODO reimplement for ct, if possible (maybe account status would be better? (premium))
|
||||
// load subscription (async) info before anything else
|
||||
binding.textAccountSubscription.text = getString(R.string.account_subscription, getString(R.string.loading))
|
||||
lifecycleScope.launch {
|
||||
binding.textAccountSubscription.text = getString(
|
||||
R.string.account_subscription,
|
||||
"TODO"
|
||||
)
|
||||
}
|
||||
|
||||
binding.textAccountLogin.text = EncryptedPreferences.login
|
||||
binding.textInfoAboutDesc.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
|
||||
binding.textThemeSelected.text = when (Preferences.theme) {
|
||||
@ -41,6 +78,8 @@ class AccountFragment : Fragment() {
|
||||
binding.switchSecondary.isChecked = Preferences.preferSecondary
|
||||
binding.switchAutoplay.isChecked = Preferences.autoplay
|
||||
|
||||
binding.linearDevSettings.isVisible = Preferences.devSettings
|
||||
|
||||
initActions()
|
||||
}
|
||||
|
||||
@ -49,6 +88,11 @@ class AccountFragment : Fragment() {
|
||||
showLoginDialog(true)
|
||||
}
|
||||
|
||||
binding.linearAccountSubscription.setOnClickListener {
|
||||
// TODO
|
||||
//startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(AoDParser.getSubscriptionUrl())))
|
||||
}
|
||||
|
||||
binding.linearTheme.setOnClickListener {
|
||||
showThemeDialog()
|
||||
}
|
||||
@ -64,16 +108,34 @@ class AccountFragment : Fragment() {
|
||||
binding.switchAutoplay.setOnClickListener {
|
||||
Preferences.saveAutoplay(requireContext(), binding.switchAutoplay.isChecked)
|
||||
}
|
||||
|
||||
binding.linearExportData.setOnClickListener {
|
||||
val i = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "text/json"
|
||||
putExtra(Intent.EXTRA_TITLE, "my-list.json")
|
||||
}
|
||||
getUriExport.launch(i)
|
||||
}
|
||||
|
||||
binding.linearImportData.setOnClickListener {
|
||||
val i = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "*/*"
|
||||
}
|
||||
getUriImport.launch(i)
|
||||
}
|
||||
}
|
||||
|
||||
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.")
|
||||
}
|
||||
// TODO
|
||||
// if (!AoDParser.login()) {
|
||||
// showLoginDialog(false)
|
||||
// Log.w(javaClass.name, "Login failed, please try again.")
|
||||
// }
|
||||
}.show {
|
||||
login = EncryptedPreferences.login
|
||||
password = ""
|
||||
@ -92,11 +154,12 @@ class AccountFragment : Fragment() {
|
||||
when(index) {
|
||||
0 -> Preferences.saveTheme(context, Theme.LIGHT)
|
||||
1 -> Preferences.saveTheme(context, Theme.DARK)
|
||||
else -> Preferences.saveTheme(context, Theme.LIGHT)
|
||||
else -> Preferences.saveTheme(context, Theme.DARK)
|
||||
}
|
||||
|
||||
(activity as MainActivity).restart()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +1,34 @@
|
||||
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.lifecycle.lifecycleScope
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
||||
import org.mosad.teapod.databinding.FragmentHomeBinding
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import org.mosad.teapod.util.StorageController
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.parser.crunchyroll.Item
|
||||
import org.mosad.teapod.parser.crunchyroll.SortBy
|
||||
import org.mosad.teapod.util.adapter.MediaItemAdapter
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
import org.mosad.teapod.util.setDrawableTop
|
||||
import org.mosad.teapod.util.showFragment
|
||||
import org.mosad.teapod.util.toItemMediaList
|
||||
import kotlin.random.Random
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentHomeBinding
|
||||
private lateinit var adapterMyList: MediaItemAdapter
|
||||
private lateinit var adapterNewEpisodes: MediaItemAdapter
|
||||
private lateinit var adapterNewSimulcasts: MediaItemAdapter
|
||||
private lateinit var adapterUpNext: MediaItemAdapter
|
||||
private lateinit var adapterWatchlist: MediaItemAdapter
|
||||
private lateinit var adapterNewTitles: MediaItemAdapter
|
||||
private lateinit var adapterTopTen: MediaItemAdapter
|
||||
|
||||
private lateinit var highlightMedia: ItemMedia
|
||||
private lateinit var highlightMedia: Item
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
@ -40,7 +38,7 @@ class HomeFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
lifecycleScope.launch {
|
||||
context?.let {
|
||||
initHighlight()
|
||||
initRecyclerViews()
|
||||
@ -50,118 +48,114 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun initHighlight() {
|
||||
if (AoDParser.highlightsList.isNotEmpty()) {
|
||||
highlightMedia = AoDParser.highlightsList[0]
|
||||
lifecycleScope.launch {
|
||||
val newTitles = Crunchyroll.browse(sortBy = SortBy.NEWLY_ADDED, n = 10)
|
||||
// FIXME crashes on newTitles.items.size == 0
|
||||
highlightMedia = newTitles.items[Random.nextInt(newTitles.items.size)]
|
||||
|
||||
// add media item to gui
|
||||
binding.textHighlightTitle.text = highlightMedia.title
|
||||
Glide.with(requireContext()).load(highlightMedia.posterUrl)
|
||||
Glide.with(requireContext()).load(highlightMedia.images.poster_wide[0][3].source)
|
||||
.into(binding.imageHighlight)
|
||||
|
||||
if (StorageController.myList.contains(highlightMedia.id)) {
|
||||
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_check_24)
|
||||
} else {
|
||||
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_add_24)
|
||||
}
|
||||
// TODO watchlist indicator
|
||||
// if (StorageController.myList.contains(0)) {
|
||||
// binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_check_24)
|
||||
// } else {
|
||||
// binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_add_24)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private fun initRecyclerViews() {
|
||||
binding.recyclerMyList.addItemDecoration(MediaItemDecoration(9))
|
||||
/**
|
||||
* Suspend, since adapters need to be initialized before we can initialize the actions.
|
||||
*/
|
||||
private suspend fun initRecyclerViews() {
|
||||
binding.recyclerWatchlist.addItemDecoration(MediaItemDecoration(9))
|
||||
binding.recyclerNewEpisodes.addItemDecoration(MediaItemDecoration(9))
|
||||
binding.recyclerNewSimulcasts.addItemDecoration(MediaItemDecoration(9))
|
||||
binding.recyclerNewTitles.addItemDecoration(MediaItemDecoration(9))
|
||||
binding.recyclerTopTen.addItemDecoration(MediaItemDecoration(9))
|
||||
|
||||
// my list
|
||||
val myListMedia = StorageController.myList.map { elementId ->
|
||||
AoDParser.itemMediaList.first {
|
||||
elementId == it.id
|
||||
}
|
||||
}
|
||||
adapterMyList = MediaItemAdapter(myListMedia)
|
||||
binding.recyclerMyList.adapter = adapterMyList
|
||||
val asyncJobList = arrayListOf<Job>()
|
||||
|
||||
// new episodes
|
||||
adapterNewEpisodes = MediaItemAdapter(AoDParser.newEpisodesList)
|
||||
binding.recyclerNewEpisodes.adapter = adapterNewEpisodes
|
||||
// continue watching
|
||||
val upNextJob = lifecycleScope.launch {
|
||||
// TODO create EpisodeItemAdapter, which will start the playback of the selected episode immediately
|
||||
adapterUpNext = MediaItemAdapter(Crunchyroll.upNextAccount().toItemMediaList())
|
||||
binding.recyclerNewEpisodes.adapter = adapterUpNext
|
||||
}
|
||||
asyncJobList.add(upNextJob)
|
||||
|
||||
// watchlist
|
||||
val watchlistJob = lifecycleScope.launch {
|
||||
adapterWatchlist = MediaItemAdapter(Crunchyroll.watchlist(50).toItemMediaList())
|
||||
binding.recyclerWatchlist.adapter = adapterWatchlist
|
||||
}
|
||||
asyncJobList.add(watchlistJob)
|
||||
|
||||
// new simulcasts
|
||||
adapterNewSimulcasts = MediaItemAdapter(AoDParser.newSimulcastsList)
|
||||
binding.recyclerNewSimulcasts.adapter = adapterNewSimulcasts
|
||||
val simulcastsJob = lifecycleScope.launch {
|
||||
// val latestSeasonTag = Crunchyroll.seasonList().items.first().id
|
||||
// val newSimulcasts = Crunchyroll.browse(seasonTag = latestSeasonTag, n = 50)
|
||||
val newSimulcasts = Crunchyroll.browse(sortBy = SortBy.NEWLY_ADDED, n = 50)
|
||||
|
||||
// new titles
|
||||
adapterNewTitles = MediaItemAdapter(AoDParser.newTitlesList)
|
||||
binding.recyclerNewTitles.adapter = adapterNewTitles
|
||||
adapterNewTitles = MediaItemAdapter(newSimulcasts.toItemMediaList())
|
||||
binding.recyclerNewTitles.adapter = adapterNewTitles
|
||||
}
|
||||
asyncJobList.add(simulcastsJob)
|
||||
|
||||
// top ten
|
||||
adapterTopTen = MediaItemAdapter(AoDParser.topTenList)
|
||||
binding.recyclerTopTen.adapter = adapterTopTen
|
||||
// newly added / top ten
|
||||
val newlyAddedJob = lifecycleScope.launch {
|
||||
adapterTopTen = MediaItemAdapter(Crunchyroll.browse(sortBy = SortBy.POPULARITY, n = 10).toItemMediaList())
|
||||
binding.recyclerTopTen.adapter = adapterTopTen
|
||||
}
|
||||
asyncJobList.add(newlyAddedJob)
|
||||
|
||||
asyncJobList.joinAll()
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
binding.buttonPlayHighlight.setOnClickListener {
|
||||
// TODO get next episode
|
||||
GlobalScope.launch {
|
||||
val media = AoDParser.getMediaById(highlightMedia.id)
|
||||
// TODO implement
|
||||
lifecycleScope.launch {
|
||||
//val media = AoDParser.getMediaById(0)
|
||||
|
||||
Log.d(javaClass.name, "Starting Player with mediaId: ${media.id}")
|
||||
(activity as MainActivity).startPlayer(media.id, media.episodes.first().id)
|
||||
// Log.d(javaClass.name, "Starting Player with mediaId: ${media.aodId}")
|
||||
//(activity as MainActivity).startPlayer(media.aodId, media.playlist.first().mediaId)
|
||||
}
|
||||
}
|
||||
|
||||
binding.textHighlightMyList.setOnClickListener {
|
||||
if (StorageController.myList.contains(highlightMedia.id)) {
|
||||
StorageController.myList.remove(highlightMedia.id)
|
||||
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_add_24)
|
||||
} else {
|
||||
StorageController.myList.add(highlightMedia.id)
|
||||
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_check_24)
|
||||
}
|
||||
StorageController.saveMyList(requireContext())
|
||||
|
||||
updateMyListMedia() // update my list, since it has changed
|
||||
// TODO implement
|
||||
// if (StorageController.myList.contains(0)) {
|
||||
// StorageController.myList.remove(0)
|
||||
// binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_add_24)
|
||||
// } else {
|
||||
// StorageController.myList.add(0)
|
||||
// binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_check_24)
|
||||
// }
|
||||
// StorageController.saveMyList(requireContext())
|
||||
}
|
||||
|
||||
binding.textHighlightInfo.setOnClickListener {
|
||||
activity?.showFragment(MediaFragment(highlightMedia.id))
|
||||
}
|
||||
|
||||
adapterMyList.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterUpNext.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterNewEpisodes.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterWatchlist.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterNewSimulcasts.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterNewTitles.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id))
|
||||
}
|
||||
|
||||
adapterNewTitles.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
adapterTopTen.onItemClick = { id, _ ->
|
||||
activity?.showFragment(MediaFragment(id)) //(mediaId))
|
||||
}
|
||||
|
||||
adapterTopTen.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update my media list
|
||||
* TODO
|
||||
* * auto call when StorageController.myList is changed
|
||||
* * only update actual change and not all data (performance)
|
||||
*/
|
||||
fun updateMyListMedia() {
|
||||
val myListMedia = StorageController.myList.map { elementId ->
|
||||
AoDParser.itemMediaList.first {
|
||||
elementId == it.id
|
||||
}
|
||||
}
|
||||
|
||||
adapterMyList.updateMediaList(myListMedia)
|
||||
adapterMyList.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
}
|
@ -5,12 +5,13 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mosad.teapod.databinding.FragmentLibraryBinding
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import org.mosad.teapod.util.adapter.MediaItemAdapter
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
import org.mosad.teapod.util.showFragment
|
||||
@ -20,6 +21,10 @@ class LibraryFragment : Fragment() {
|
||||
private lateinit var binding: FragmentLibraryBinding
|
||||
private lateinit var adapter: MediaItemAdapter
|
||||
|
||||
private val itemList = arrayListOf<ItemMedia>()
|
||||
private val pageSize = 30
|
||||
private var nextItemIndex = 0
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentLibraryBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
@ -29,20 +34,56 @@ class LibraryFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// init async
|
||||
GlobalScope.launch {
|
||||
lifecycleScope.launch {
|
||||
// create and set the adapter, needs context
|
||||
withContext(Dispatchers.Main) {
|
||||
context?.let {
|
||||
adapter = MediaItemAdapter(AoDParser.itemMediaList)
|
||||
adapter.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
}
|
||||
context?.let {
|
||||
val initialResults = Crunchyroll.browse(n = pageSize)
|
||||
itemList.addAll(initialResults.items.map { item ->
|
||||
ItemMedia(item.id, item.title, item.images.poster_wide[0][0].source)
|
||||
})
|
||||
nextItemIndex += pageSize
|
||||
|
||||
binding.recyclerMediaLibrary.adapter = adapter
|
||||
binding.recyclerMediaLibrary.addItemDecoration(MediaItemDecoration(9))
|
||||
adapter = MediaItemAdapter(itemList)
|
||||
adapter.onItemClick = { mediaIdStr, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaIdStr))
|
||||
}
|
||||
|
||||
binding.recyclerMediaLibrary.adapter = adapter
|
||||
binding.recyclerMediaLibrary.addItemDecoration(MediaItemDecoration(9))
|
||||
// TODO replace with pagination3
|
||||
// https://medium.com/swlh/paging3-recyclerview-pagination-made-easy-333c7dfa8797
|
||||
binding.recyclerMediaLibrary.addOnScrollListener(PaginationScrollListener())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
inner class PaginationScrollListener: RecyclerView.OnScrollListener() {
|
||||
private var isLoading = false
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
val layoutManager = recyclerView.layoutManager as GridLayoutManager?
|
||||
|
||||
if (!isLoading) layoutManager?.let {
|
||||
// itemList.size - 5 to start loading a bit earlier than the actual end
|
||||
if (layoutManager.findLastCompletelyVisibleItemPosition() >= (itemList.size - 5)) {
|
||||
// load new browse results async
|
||||
isLoading = true
|
||||
lifecycleScope.launch {
|
||||
val firstNewItemIndex = itemList.lastIndex + 1
|
||||
val results = Crunchyroll.browse(start = nextItemIndex, n = pageSize)
|
||||
itemList.addAll(results.items.map { item ->
|
||||
ItemMedia(item.id, item.title, item.images.poster_wide[0][0].source)
|
||||
})
|
||||
nextItemIndex += pageSize
|
||||
|
||||
adapter.notifyItemRangeInserted(firstNewItemIndex, pageSize)
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -10,35 +10,40 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.fragment.app.activityViewModels
|
||||
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.*
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentMediaBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.NoneUpNextSeriesItem
|
||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
|
||||
import org.mosad.teapod.util.*
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
|
||||
import org.mosad.teapod.util.tmdb.TMDBApiController
|
||||
import org.mosad.teapod.util.tmdb.TMDBMovie
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVShow
|
||||
|
||||
/**
|
||||
* 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 mediaId: Int) : Fragment() {
|
||||
class MediaFragment(private val mediaIdStr: String) : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMediaBinding
|
||||
private lateinit var pagerAdapter: FragmentStateAdapter
|
||||
|
||||
private val fragments = arrayListOf<Fragment>()
|
||||
|
||||
private val model: MediaFragmentViewModel by activityViewModels()
|
||||
|
||||
private val fragments = arrayListOf<Fragment>()
|
||||
private var watchlistJobRunning = false
|
||||
private var runOnResume = false
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentMediaBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
@ -46,37 +51,51 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
println("onViewCreated")
|
||||
|
||||
binding.frameLoading.visibility = View.VISIBLE
|
||||
|
||||
// tab layout and pager TODO
|
||||
// tab layout and pager
|
||||
pagerAdapter = ScreenSlidePagerAdapter(requireActivity())
|
||||
// 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 = if (model.media.type == MediaType.TVSHOW && position == 0) {
|
||||
getString(R.string.episodes)
|
||||
} else {
|
||||
getString(R.string.similar_titles)
|
||||
tab.text = when(position) {
|
||||
0 -> getString(R.string.episodes)
|
||||
1 -> getString(R.string.similar_titles)
|
||||
else -> ""
|
||||
}
|
||||
}.attach()
|
||||
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
model.load(mediaId) // load the streams and tmdb for the selected media
|
||||
lifecycleScope.launch {
|
||||
model.loadCrunchy(mediaIdStr)
|
||||
|
||||
if (this@MediaFragment.isAdded) {
|
||||
updateGUI()
|
||||
initActions()
|
||||
}
|
||||
updateGUI()
|
||||
initActions()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// update the next ep text if there is one, since it may have changed
|
||||
if (model.nextEpisode.title.isNotEmpty()) {
|
||||
binding.textTitle.text = model.nextEpisode.title
|
||||
if (runOnResume) {
|
||||
lifecycleScope.launch {
|
||||
model.updateOnResume()
|
||||
|
||||
if (model.upNextSeries != NoneUpNextSeriesItem) {
|
||||
binding.textTitle.text = model.upNextSeries.panel.title
|
||||
}
|
||||
|
||||
// needs to be called after model.updateOnResume()
|
||||
if (fragments.elementAtOrNull(0) is MediaFragmentEpisodes) {
|
||||
(fragments[0] as MediaFragmentEpisodes).updateWatchedState()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runOnResume = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,71 +104,82 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
*/
|
||||
private fun updateGUI() = with(model) {
|
||||
// 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
|
||||
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)
|
||||
.into(binding.imagePoster)
|
||||
Glide.with(requireContext()).load(backdropUrl)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3)))
|
||||
.into(binding.imageBackdrop)
|
||||
|
||||
Glide.with(requireContext()).load(posterUrl)
|
||||
.into(binding.imagePoster)
|
||||
|
||||
binding.textTitle.text = media.info.title
|
||||
binding.textYear.text = media.info.year.toString()
|
||||
binding.textAge.text = media.info.age.toString()
|
||||
binding.textOverview.text = media.info.shortDesc
|
||||
if (StorageController.myList.contains(media.id)) {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
} else {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
|
||||
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 != NoneUpNextSeriesItem) {
|
||||
upNextSeries.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)
|
||||
val fragmentsSize = if (fragments.lastIndex < 0) 0 else fragments.lastIndex
|
||||
fragments.clear()
|
||||
pagerAdapter.notifyDataSetChanged()
|
||||
pagerAdapter.notifyItemRangeRemoved(0, fragmentsSize)
|
||||
|
||||
// specific gui
|
||||
if (media.type == MediaType.TVSHOW) {
|
||||
// get next episode
|
||||
nextEpisode = if (media.episodes.firstOrNull{ !it.watched } != null) {
|
||||
media.episodes.first{ !it.watched }
|
||||
} else {
|
||||
media.episodes.first()
|
||||
}
|
||||
// add the episodes fragment (as tab). Note: Movies are tv shows!
|
||||
MediaFragmentEpisodes().also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
|
||||
// title is the next episodes title
|
||||
binding.textTitle.text = nextEpisode.title
|
||||
|
||||
// episodes count
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_episodes_count,
|
||||
media.info.episodesCount,
|
||||
media.info.episodesCount
|
||||
)
|
||||
|
||||
// episodes
|
||||
fragments.add(MediaFragmentEpisodes())
|
||||
pagerAdapter.notifyDataSetChanged()
|
||||
} else if (media.type == MediaType.MOVIE) {
|
||||
|
||||
if (tmdb.runtime > 0) {
|
||||
// specific gui (via tmdb)
|
||||
when (tmdbResult) {
|
||||
is TMDBTVShow -> {
|
||||
// episodes count
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_runtime,
|
||||
tmdb.runtime,
|
||||
tmdb.runtime
|
||||
R.plurals.text_episodes_count,
|
||||
episodesCrunchy.total,
|
||||
episodesCrunchy.total
|
||||
)
|
||||
} else {
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// if has similar titles
|
||||
if (media.info.similar.isNotEmpty()) {
|
||||
fragments.add(MediaFragmentSimilar())
|
||||
pagerAdapter.notifyDataSetChanged()
|
||||
}
|
||||
// TODO reimplement
|
||||
// if (media.similar.isNotEmpty()) {
|
||||
// MediaFragmentSimilar().also {
|
||||
// fragments.add(it)
|
||||
// pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
// }
|
||||
// }
|
||||
|
||||
// disable scrolling on appbar, if no tabs where added
|
||||
if(fragments.isEmpty()) {
|
||||
@ -162,27 +192,24 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
|
||||
private fun initActions() = with(model) {
|
||||
binding.buttonPlay.setOnClickListener {
|
||||
when (media.type) {
|
||||
MediaType.MOVIE -> playEpisode(media.episodes.first())
|
||||
MediaType.TVSHOW -> playEpisode(nextEpisode)
|
||||
else -> Log.e(javaClass.name, "Wrong Type: $media.type")
|
||||
if (upNextSeries != NoneUpNextSeriesItem) {
|
||||
playEpisode(upNextSeries.panel.episodeMetadata.seasonId, upNextSeries.panel.id)
|
||||
}
|
||||
}
|
||||
|
||||
// add or remove media from myList
|
||||
binding.linearMyListAction.setOnClickListener {
|
||||
if (StorageController.myList.contains(media.id)) {
|
||||
StorageController.myList.remove(media.id)
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
|
||||
} else {
|
||||
StorageController.myList.add(media.id)
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
}
|
||||
StorageController.saveMyList(requireContext())
|
||||
// don't allow parallel execution
|
||||
if (!watchlistJobRunning) {
|
||||
watchlistJobRunning = true
|
||||
lifecycleScope.launch {
|
||||
setWatchlist()
|
||||
|
||||
// notify home fragment on change
|
||||
parentFragmentManager.findFragmentByTag("HomeFragment")?.let {
|
||||
(it as HomeFragment).updateMyListMedia()
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,11 +218,11 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||
* play the current episode
|
||||
* TODO this is also used in MediaFragmentEpisode, we should only have on implementation
|
||||
*/
|
||||
private fun playEpisode(ep: Episode) {
|
||||
(activity as MainActivity).startPlayer(model.media.id, ep.id)
|
||||
Log.d(javaClass.name, "Started Player with episodeId: ${ep.id}")
|
||||
private fun playEpisode(seasonId: String, episodeId: String) {
|
||||
(activity as MainActivity).startPlayer(seasonId, episodeId)
|
||||
Log.d(javaClass.name, "Started Player with episodeId: $episodeId")
|
||||
|
||||
model.updateNextEpisode(ep) // set the correct next episode
|
||||
//model.updateNextEpisode(episodeId) // set the correct next episode
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,16 +1,19 @@
|
||||
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.PopupMenu
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.databinding.FragmentMediaEpisodesBinding
|
||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
||||
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
|
||||
import org.mosad.teapod.databinding.FragmentMediaEpisodesBinding
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
|
||||
|
||||
class MediaFragmentEpisodes : Fragment() {
|
||||
@ -28,34 +31,71 @@ class MediaFragmentEpisodes : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
adapterRecEpisodes = EpisodeItemAdapter(model.media.episodes)
|
||||
adapterRecEpisodes = EpisodeItemAdapter(
|
||||
model.currentEpisodesCrunchy,
|
||||
model.tmdbTVSeason.episodes,
|
||||
model.currentPlayheads
|
||||
)
|
||||
binding.recyclerEpisodes.adapter = adapterRecEpisodes
|
||||
|
||||
// set onItemClick only in adapter is initialized
|
||||
if (this::adapterRecEpisodes.isInitialized) {
|
||||
adapterRecEpisodes.onImageClick = { _, position ->
|
||||
playEpisode(model.media.episodes[position])
|
||||
// set onItemClick, adapter is initialized
|
||||
adapterRecEpisodes.onImageClick = { seasonId, episodeId ->
|
||||
playEpisode(seasonId, episodeId)
|
||||
}
|
||||
|
||||
// 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 = model.currentSeasonCrunchy.title
|
||||
binding.buttonSeasonSelection.setOnClickListener { v ->
|
||||
showSeasonSelection(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateWatchedState() {
|
||||
// model.currentPlayheads is a val mutable map -> notify dataset changed
|
||||
adapterRecEpisodes.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
// if adapterRecEpisodes is initialized, update the watched state for the episodes
|
||||
if (this::adapterRecEpisodes.isInitialized) {
|
||||
model.media.episodes.forEachIndexed { index, episode ->
|
||||
adapterRecEpisodes.updateWatchedState(episode.watched, index)
|
||||
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.items.forEach { season ->
|
||||
popup.menu.add(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 = model.currentSeasonCrunchy.title
|
||||
adapterRecEpisodes.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun playEpisode(ep: Episode) {
|
||||
(activity as MainActivity).startPlayer(model.media.id, ep.id)
|
||||
Log.d(javaClass.name, "Started Player with episodeId: ${ep.id}")
|
||||
private fun playEpisode(seasonId: String, episodeId: String) {
|
||||
(activity as MainActivity).startPlayer(seasonId, episodeId)
|
||||
Log.d(javaClass.name, "Started Player with episodeId: $episodeId")
|
||||
|
||||
model.updateNextEpisode(ep) // set the correct next episode
|
||||
//model.updateNextEpisode(episodeId) // set the correct next episode
|
||||
}
|
||||
|
||||
}
|
@ -27,14 +27,14 @@ class MediaFragmentSimilar : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
adapterSimilar = MediaItemAdapter(model.media.info.similar)
|
||||
adapterSimilar = MediaItemAdapter(emptyList()) //(model.media.similar)
|
||||
binding.recyclerMediaSimilar.adapter = adapterSimilar
|
||||
binding.recyclerMediaSimilar.addItemDecoration(MediaItemDecoration(9))
|
||||
|
||||
// set onItemClick only in adapter is initialized
|
||||
if (this::adapterSimilar.isInitialized) {
|
||||
adapterSimilar.onItemClick = { mediaId, _ ->
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
activity?.showFragment(MediaFragment("")) //(mediaId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,25 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.coroutines.*
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.databinding.FragmentSearchBinding
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import org.mosad.teapod.util.adapter.MediaItemAdapter
|
||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
import org.mosad.teapod.util.showFragment
|
||||
|
||||
class SearchFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentSearchBinding
|
||||
private var adapter : MediaItemAdapter? = null
|
||||
private lateinit var adapter: MediaItemAdapter
|
||||
|
||||
private val itemList = arrayListOf<ItemMedia>()
|
||||
private var searchJob: Job? = null
|
||||
private var oldSearchQuery = ""
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentSearchBinding.inflate(inflater, container, false)
|
||||
@ -26,20 +34,18 @@ class SearchFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
GlobalScope.launch {
|
||||
lifecycleScope.launch {
|
||||
// create and set the adapter, needs context
|
||||
withContext(Dispatchers.Main) {
|
||||
context?.let {
|
||||
adapter = MediaItemAdapter(AoDParser.itemMediaList)
|
||||
adapter!!.onItemClick = { mediaId, _ ->
|
||||
adapter = MediaItemAdapter(itemList)
|
||||
adapter.onItemClick = { mediaIdStr, _ ->
|
||||
binding.searchText.clearFocus()
|
||||
activity?.showFragment(MediaFragment(mediaId))
|
||||
activity?.showFragment(MediaFragment(mediaIdStr))
|
||||
}
|
||||
|
||||
binding.recyclerMediaSearch.adapter = adapter
|
||||
binding.recyclerMediaSearch.addItemDecoration(MediaItemDecoration(9))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initActions()
|
||||
@ -48,16 +54,65 @@ class SearchFragment : Fragment() {
|
||||
private fun initActions() {
|
||||
binding.searchText.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
adapter?.filter?.filter(query)
|
||||
adapter?.notifyDataSetChanged()
|
||||
query?.let { search(it) }
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
adapter?.filter?.filter(newText)
|
||||
adapter?.notifyDataSetChanged()
|
||||
newText?.let { search(it) }
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun search(query: String) {
|
||||
// if the query hasn't changed since the last successful search, return
|
||||
if (query == oldSearchQuery) return
|
||||
|
||||
// cancel search job if one is already running
|
||||
if (searchJob?.isActive == true) searchJob?.cancel()
|
||||
|
||||
searchJob = lifecycleScope.async {
|
||||
// TODO maybe wait a few ms (500ms?) before searching, if the user inputs any other chars
|
||||
val results = Crunchyroll.search(query, 50)
|
||||
|
||||
itemList.clear() // TODO needs clean up
|
||||
|
||||
// TODO add top results first heading
|
||||
itemList.addAll(results.items[0].items.map { item ->
|
||||
ItemMedia(item.id, item.title, item.images.poster_wide[0][0].source)
|
||||
})
|
||||
|
||||
// TODO currently only tv shows are supported, hence only the first items array
|
||||
// should be always present
|
||||
|
||||
// // TODO add tv shows heading
|
||||
// if (results.items.size >= 2) {
|
||||
// itemList.addAll(results.items[1].items.map { item ->
|
||||
// ItemMedia(item.id, item.title, item.images.poster_wide[0][0].source)
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // TODO add movies heading
|
||||
// if (results.items.size >= 3) {
|
||||
// itemList.addAll(results.items[2].items.map { item ->
|
||||
// ItemMedia(item.id, item.title, item.images.poster_wide[0][0].source)
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// // TODO add episodes heading
|
||||
// if (results.items.size >= 4) {
|
||||
// itemList.addAll(results.items[3].items.map { item ->
|
||||
// ItemMedia(item.id, item.title, item.images.poster_wide[0][0].source)
|
||||
// })
|
||||
// }
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
//adapter.notifyItemRangeInserted(0, itemList.size)
|
||||
|
||||
// after successfully searching the query term, add it as old query, to make sure we
|
||||
// don't search again if the query hasn't changed
|
||||
oldSearchQuery = query
|
||||
}
|
||||
}
|
||||
}
|
@ -2,47 +2,176 @@ package org.mosad.teapod.ui.activity.main.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.util.*
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.parser.crunchyroll.*
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.DataTypes.MediaType
|
||||
import org.mosad.teapod.util.Meta
|
||||
import org.mosad.teapod.util.tmdb.*
|
||||
|
||||
/**
|
||||
* handle media, next ep and tmdb
|
||||
* TODO this lives in activity, is this correct?
|
||||
*/
|
||||
class MediaFragmentViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
var media = Media(-1, "", MediaType.OTHER)
|
||||
// var mediaCrunchy = NoneItem
|
||||
// internal set
|
||||
var seriesCrunchy = NoneSeries // movies are also series
|
||||
internal set
|
||||
var nextEpisode = Episode()
|
||||
var seasonsCrunchy = NoneSeasons
|
||||
internal set
|
||||
var tmdb = TMDBResponse()
|
||||
var currentSeasonCrunchy = NoneSeason
|
||||
internal set
|
||||
var episodesCrunchy = NoneEpisodes
|
||||
internal set
|
||||
val currentEpisodesCrunchy = arrayListOf<Episode>() // used for EpisodeItemAdapter (easier updates)
|
||||
|
||||
// additional media info
|
||||
val currentPlayheads: MutableMap<String, PlayheadObject> = mutableMapOf()
|
||||
var isWatchlist = false
|
||||
internal set
|
||||
var upNextSeries = NoneUpNextSeriesItem
|
||||
|
||||
// TMDB stuff
|
||||
var mediaType = MediaType.OTHER
|
||||
internal set
|
||||
var tmdbResult: TMDBResult = NoneTMDB // TODO rename
|
||||
internal set
|
||||
var tmdbTVSeason: TMDBTVSeason = NoneTMDBTVSeason
|
||||
internal set
|
||||
var mediaMeta: Meta? = null
|
||||
internal set
|
||||
|
||||
/**
|
||||
* set media, tmdb and nextEpisode
|
||||
* @param crunchyId the crunchyroll series id
|
||||
*/
|
||||
suspend fun load(mediaId: Int) {
|
||||
media = AoDParser.getMediaById(mediaId)
|
||||
tmdb = TMDBApiController().search(media.info.title, media.type)
|
||||
|
||||
if (media.type == MediaType.TVSHOW) {
|
||||
nextEpisode = if (media.episodes.firstOrNull{ !it.watched } != null) {
|
||||
media.episodes.first{ !it.watched }
|
||||
} else {
|
||||
media.episodes.first()
|
||||
suspend fun loadCrunchy(crunchyId: String) {
|
||||
// load series and seasons info in parallel
|
||||
listOf(
|
||||
viewModelScope.launch { seriesCrunchy = Crunchyroll.series(crunchyId) },
|
||||
viewModelScope.launch { seasonsCrunchy = Crunchyroll.seasons(crunchyId) },
|
||||
viewModelScope.launch { isWatchlist = Crunchyroll.isWatchlist(crunchyId) },
|
||||
viewModelScope.launch { upNextSeries = Crunchyroll.upNextSeries(crunchyId) }
|
||||
).joinAll()
|
||||
// println("series: $seriesCrunchy")
|
||||
// println("seasons: $seasonsCrunchy")
|
||||
println(upNextSeries)
|
||||
|
||||
// load the preferred season (preferred language, language per season, not per stream)
|
||||
currentSeasonCrunchy = seasonsCrunchy.getPreferredSeason(Preferences.preferredLocal)
|
||||
|
||||
// load episodes and metaDB in parallel (tmdb needs mediaType, which is set via episodes)
|
||||
listOf(
|
||||
viewModelScope.launch { episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id) },
|
||||
viewModelScope.launch { mediaMeta = null }, // TODO metaDB
|
||||
).joinAll()
|
||||
// println("episodes: $episodesCrunchy")
|
||||
|
||||
currentEpisodesCrunchy.clear()
|
||||
currentEpisodesCrunchy.addAll(episodesCrunchy.items)
|
||||
|
||||
// set media type
|
||||
mediaType = episodesCrunchy.items.firstOrNull()?.let {
|
||||
if (it.episodeNumber != null) MediaType.TVSHOW else MediaType.MOVIE
|
||||
} ?: MediaType.OTHER
|
||||
|
||||
// load playheads and tmdb in parallel
|
||||
listOf(
|
||||
viewModelScope.launch {
|
||||
// get playheads (including fully watched state)
|
||||
val episodeIDs = episodesCrunchy.items.map { it.id }
|
||||
currentPlayheads.clear()
|
||||
currentPlayheads.putAll(Crunchyroll.playheads(episodeIDs))
|
||||
},
|
||||
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
|
||||
}
|
||||
println(tmdbSearchResult)
|
||||
|
||||
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
|
||||
|
||||
println(tmdbResult)
|
||||
|
||||
// currently not used
|
||||
// tmdbTVSeason = if (tmdbResult is TMDBTVShow) {
|
||||
// tmdbApiController.getTVSeasonDetails(tmdbResult.id, 0)
|
||||
// } else NoneTMDBTVSeason
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.items.firstOrNull {
|
||||
it.id == seasonId
|
||||
} ?: currentSeasonCrunchy
|
||||
|
||||
episodesCrunchy = Crunchyroll.episodes(currentSeasonCrunchy.id)
|
||||
currentEpisodesCrunchy.clear()
|
||||
currentEpisodesCrunchy.addAll(episodesCrunchy.items)
|
||||
}
|
||||
|
||||
suspend fun setWatchlist() {
|
||||
isWatchlist = if (isWatchlist) {
|
||||
Crunchyroll.deleteWatchlist(seriesCrunchy.id)
|
||||
false
|
||||
} else {
|
||||
Crunchyroll.postWatchlist(seriesCrunchy.id)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateOnResume() {
|
||||
joinAll(
|
||||
viewModelScope.launch {
|
||||
val episodeIDs = episodesCrunchy.items.map { it.id }
|
||||
currentPlayheads.clear()
|
||||
currentPlayheads.putAll(Crunchyroll.playheads(episodeIDs))
|
||||
},
|
||||
viewModelScope.launch { upNextSeries = Crunchyroll.upNextSeries(seriesCrunchy.id) }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* get the next episode based on episode number (the true next episode)
|
||||
* get the next episode based on episodeId
|
||||
* if no matching is found, use first episode
|
||||
*/
|
||||
fun updateNextEpisode(currentEp: Episode) {
|
||||
if (media.type == MediaType.MOVIE) return // return if movie
|
||||
|
||||
nextEpisode = media.episodes.firstOrNull{ it.number > currentEp.number }
|
||||
?: media.episodes.first()
|
||||
fun updateNextEpisode(episodeId: Int) {
|
||||
// TODO reimplement if needed
|
||||
// if (media.type == MediaType.MOVIE) return // return if movie
|
||||
//
|
||||
// nextEpisodeId = media.playlist.firstOrNull { it.index > media.getEpisodeById(episodeId).index }?.mediaId
|
||||
// ?: media.playlist.first().mediaId
|
||||
}
|
||||
|
||||
}
|
@ -4,17 +4,18 @@ 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.AoDParser
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
|
||||
class OnLoginFragment: Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentOnLoginBinding
|
||||
private var loginJob: Job? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentOnLoginBinding.inflate(inflater, container, false)
|
||||
@ -28,24 +29,40 @@ class OnLoginFragment: Fragment() {
|
||||
|
||||
private fun initActions() {
|
||||
binding.buttonLogin.setOnClickListener {
|
||||
// get login credentials from gui
|
||||
val email = binding.editTextLogin.text.toString()
|
||||
val password = binding.editTextPassword.text.toString()
|
||||
onLogin()
|
||||
}
|
||||
|
||||
EncryptedPreferences.saveCredentials(email, password, requireContext()) // save the credentials
|
||||
binding.editTextPassword.setOnEditorActionListener { _, actionId, _ ->
|
||||
return@setOnEditorActionListener when (actionId) {
|
||||
EditorInfo.IME_ACTION_DONE -> {
|
||||
onLogin()
|
||||
false // false will hide the keyboards
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
binding.buttonLogin.isClickable = false
|
||||
loginJob = GlobalScope.launch {
|
||||
if (AoDParser.login()) {
|
||||
// if login was successful, switch to main
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class OnboardingActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityOnboardingBinding
|
||||
private lateinit var pagerAdapter: FragmentStateAdapter
|
||||
|
||||
private val fragments = arrayOf(OnLoginFragment())
|
||||
private val fragments = arrayOf(OnWelcomeFragment(), OnLoginFragment())
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* 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
|
||||
@ -7,6 +29,7 @@ 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
|
||||
@ -19,24 +42,20 @@ 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.util.Util
|
||||
import kotlinx.android.synthetic.main.activity_player.*
|
||||
import kotlinx.android.synthetic.main.player_controls.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.crunchyroll.NoneEpisode
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.ui.components.EpisodesListPlayer
|
||||
import org.mosad.teapod.ui.components.LanguageSettingsPlayer
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.hideBars
|
||||
import org.mosad.teapod.util.isInPiPMode
|
||||
import org.mosad.teapod.util.navToLauncherTask
|
||||
import org.mosad.teapod.util.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.concurrent.scheduleAtFixedRate
|
||||
@ -50,9 +69,6 @@ class PlayerActivity : AppCompatActivity() {
|
||||
private lateinit var timerUpdates: TimerTask
|
||||
|
||||
private var wasInPiP = false
|
||||
private var playWhenReady = true
|
||||
private var currentWindow = 0
|
||||
private var playbackPosition: Long = 0
|
||||
private var remainingTime: Long = 0
|
||||
|
||||
private val rwdTime: Long = 10000.unaryMinus()
|
||||
@ -64,15 +80,9 @@ class PlayerActivity : AppCompatActivity() {
|
||||
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))
|
||||
}
|
||||
|
||||
model.loadMedia(
|
||||
intent.getIntExtra(getString(R.string.intent_media_id), 0),
|
||||
intent.getIntExtra(getString(R.string.intent_episode_id), 0)
|
||||
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())
|
||||
@ -110,47 +120,34 @@ class PlayerActivity : AppCompatActivity() {
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (isInPiPMode()) { return }
|
||||
|
||||
if (Util.SDK_INT <= 23) {
|
||||
video_view?.onPause()
|
||||
releasePlayer()
|
||||
}
|
||||
if (isInPiPMode()) { return }
|
||||
if (Util.SDK_INT <= 23) { onPauseOnStop() }
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (Util.SDK_INT > 23) {
|
||||
video_view?.onPause()
|
||||
releasePlayer()
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, lead the new media and play it
|
||||
// when the intent changed, load the new media and play it
|
||||
intent?.let {
|
||||
model.loadMedia(
|
||||
it.getIntExtra(getString(R.string.intent_media_id), 0),
|
||||
it.getIntExtra(getString(R.string.intent_episode_id), 0)
|
||||
model.loadMediaAsync(
|
||||
it.getStringExtra(getString(R.string.intent_season_id)) ?: "",
|
||||
it.getStringExtra(getString(R.string.intent_episode_id)) ?: ""
|
||||
)
|
||||
model.playEpisode(model.currentEpisode, replace = true)
|
||||
model.playCurrentMedia()
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,8 +166,15 @@ class PlayerActivity : AppCompatActivity() {
|
||||
} else {
|
||||
val width = model.player.videoFormat?.width ?: 0
|
||||
val height = model.player.videoFormat?.height ?: 0
|
||||
val contentFrame: View = video_view.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)
|
||||
}
|
||||
@ -190,11 +194,6 @@ class PlayerActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initPlayer() {
|
||||
if (model.media.id < 0) {
|
||||
Log.e(javaClass.name, "No media was set.")
|
||||
this.finish()
|
||||
}
|
||||
|
||||
initVideoView()
|
||||
initTimeUpdates()
|
||||
|
||||
@ -209,8 +208,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
* set play when ready and listeners
|
||||
*/
|
||||
private fun initExoPlayer() {
|
||||
model.player.playWhenReady = playWhenReady
|
||||
model.player.addListener(object : Player.EventListener {
|
||||
model.player.addListener(object : Player.Listener {
|
||||
override fun onPlaybackStateChanged(state: Int) {
|
||||
super.onPlaybackStateChanged(state)
|
||||
|
||||
@ -226,14 +224,15 @@ class PlayerActivity : AppCompatActivity() {
|
||||
else -> View.VISIBLE
|
||||
}
|
||||
|
||||
if (state == ExoPlayer.STATE_ENDED && model.nextEpisode != null && Preferences.autoplay) {
|
||||
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.playEpisode(model.currentEpisode, true, playbackPosition)
|
||||
//model.playCurrentMedia(model.currentPlayhead)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@ -243,7 +242,10 @@ class PlayerActivity : AppCompatActivity() {
|
||||
// when the player controls get hidden, hide the bars too
|
||||
video_view.setControllerVisibilityListener {
|
||||
when (it) {
|
||||
View.GONE -> hideBars()
|
||||
View.GONE -> {
|
||||
hideBars()
|
||||
// TODO also hide the skip op button
|
||||
}
|
||||
View.VISIBLE -> updateControls()
|
||||
}
|
||||
}
|
||||
@ -261,15 +263,17 @@ class PlayerActivity : AppCompatActivity() {
|
||||
rwd_10.setOnButtonClickListener { rewind() }
|
||||
ffwd_10.setOnButtonClickListener { fastForward() }
|
||||
button_next_ep.setOnClickListener { playNextEpisode() }
|
||||
button_skip_op.setOnClickListener { skipOpening() }
|
||||
button_language.setOnClickListener { showLanguageSettings() }
|
||||
button_episodes.setOnClickListener { showEpisodesList() }
|
||||
button_next_ep_c.setOnClickListener { playNextEpisode() }
|
||||
}
|
||||
|
||||
private fun initGUI() {
|
||||
if (model.media.type == DataTypes.MediaType.MOVIE) {
|
||||
button_episodes.visibility = View.GONE
|
||||
}
|
||||
// TODO reimplement for cr
|
||||
// if (model.media.type == DataTypes.MediaType.MOVIE) {
|
||||
// button_episodes.visibility = View.GONE
|
||||
// }
|
||||
}
|
||||
|
||||
private fun initTimeUpdates() {
|
||||
@ -278,40 +282,51 @@ class PlayerActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
timerUpdates = Timer().scheduleAtFixedRate(0, 500) {
|
||||
GlobalScope.launch {
|
||||
var btnNextEpIsVisible: Boolean
|
||||
var controlsVisible: Boolean
|
||||
lifecycleScope.launch {
|
||||
val currentPosition = model.player.currentPosition
|
||||
val btnNextEpIsVisible = button_next_ep.isVisible
|
||||
val controlsVisible = controller.isVisible
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
if (model.player.duration > 0) {
|
||||
remainingTime = model.player.duration - model.player.currentPosition
|
||||
remainingTime = if (remainingTime < 0) 0 else remainingTime
|
||||
}
|
||||
btnNextEpIsVisible = button_next_ep.isVisible
|
||||
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
|
||||
}
|
||||
|
||||
// TODO add metaDB ending_start support
|
||||
// if remaining time < 20 sec, a next ep is set, autoplay is enabled and not in pip:
|
||||
// show next ep button
|
||||
if (remainingTime in 1..20000) {
|
||||
// if the next ep button is not visible, make it visible. Don't show in pip mode
|
||||
if (!btnNextEpIsVisible && model.nextEpisode != null && Preferences.autoplay && !isInPiPMode()) {
|
||||
withContext(Dispatchers.Main) { showButtonNextEp() }
|
||||
if (!btnNextEpIsVisible && hasNextEpisode() && Preferences.autoplay && !isInPiPMode()) {
|
||||
showButtonNextEp()
|
||||
}
|
||||
} else if (btnNextEpIsVisible) {
|
||||
withContext(Dispatchers.Main) { hideButtonNextEp() }
|
||||
hideButtonNextEp()
|
||||
}
|
||||
|
||||
// if meta data is present and opening_start & opening_duration are valid, show skip opening
|
||||
model.currentEpisodeMeta?.let {
|
||||
if (it.openingDuration > 0 &&
|
||||
currentPosition in it.openingStart..(it.openingStart + 10000) &&
|
||||
!button_skip_op.isVisible
|
||||
) {
|
||||
showButtonSkipOp()
|
||||
} else if (button_skip_op.isVisible && currentPosition !in it.openingStart..(it.openingStart + 10000)) {
|
||||
// the button should only be visible, if currentEpisodeMeta != null
|
||||
hideButtonSkipOp()
|
||||
}
|
||||
}
|
||||
|
||||
// if controls are visible, update them
|
||||
if (controlsVisible) {
|
||||
withContext(Dispatchers.Main) { updateControls() }
|
||||
updateControls()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun releasePlayer() {
|
||||
playbackPosition = model.player.currentPosition
|
||||
currentWindow = model.player.currentWindowIndex
|
||||
playWhenReady = model.player.playWhenReady
|
||||
private fun onPauseOnStop() {
|
||||
video_view?.onPause()
|
||||
model.player.pause()
|
||||
timerUpdates.cancel()
|
||||
}
|
||||
@ -334,24 +349,29 @@ class PlayerActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
/**
|
||||
* update title text and next ep button visibility, set ignoreNextStateEnded
|
||||
* 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()
|
||||
}
|
||||
|
||||
exo_text_title.text = model.getMediaTitle()
|
||||
|
||||
// hide the next ep button, if there is none
|
||||
button_next_ep_c.visibility = if (model.nextEpisode == null) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
// hide the next episode button, if there is none
|
||||
button_next_ep_c.visibility = if (hasNextEpisode()) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
// hide the episodes button, if the media type changed
|
||||
button_episodes.visibility = if (model.media.type == DataTypes.MediaType.MOVIE) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
/**
|
||||
* 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())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,12 +419,21 @@ class PlayerActivity : AppCompatActivity() {
|
||||
hideButtonNextEp()
|
||||
}
|
||||
|
||||
private fun skipOpening() {
|
||||
// calculate the seek time
|
||||
model.currentEpisodeMeta?.let {
|
||||
val seekTime = (it.openingStart + it.openingDuration) - model.player.currentPosition
|
||||
model.seekToOffset(seekTime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* show the next episode button
|
||||
* TODO improve the show animation
|
||||
*/
|
||||
private fun showButtonNextEp() {
|
||||
button_next_ep.visibility = View.VISIBLE
|
||||
button_next_ep.isVisible = true
|
||||
button_next_ep.alpha = 0.0f
|
||||
|
||||
button_next_ep.animate()
|
||||
@ -422,7 +451,28 @@ class PlayerActivity : AppCompatActivity() {
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
super.onAnimationEnd(animation)
|
||||
button_next_ep.visibility = View.GONE
|
||||
button_next_ep.isVisible = false
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun showButtonSkipOp() {
|
||||
button_skip_op.isVisible = true
|
||||
button_skip_op.alpha = 0.0f
|
||||
|
||||
button_skip_op.animate()
|
||||
.alpha(1.0f)
|
||||
.setListener(null)
|
||||
}
|
||||
|
||||
private fun hideButtonSkipOp() {
|
||||
button_skip_op.animate()
|
||||
.alpha(0.0f)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
super.onAnimationEnd(animation)
|
||||
button_skip_op.isVisible = false
|
||||
}
|
||||
})
|
||||
|
||||
@ -460,7 +510,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
*/
|
||||
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
||||
if (!isInPiPMode()) {
|
||||
if (controller.isVisible) controller.hide() else controller.show()
|
||||
if (controller.isVisible) controller.hide() else controller.show()
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -1,25 +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.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 com.google.android.exoplayer2.C
|
||||
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.SimpleExoPlayer
|
||||
import com.google.android.exoplayer2.source.MediaSource
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
|
||||
import com.google.android.exoplayer2.source.hls.HlsMediaSource
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
|
||||
import com.google.android.exoplayer2.util.Util
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.parser.crunchyroll.NoneEpisode
|
||||
import org.mosad.teapod.parser.crunchyroll.NoneEpisodes
|
||||
import org.mosad.teapod.parser.crunchyroll.NonePlayback
|
||||
import org.mosad.teapod.preferences.Preferences
|
||||
import org.mosad.teapod.util.DataTypes
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.util.Media
|
||||
import org.mosad.teapod.util.EpisodeMeta
|
||||
import org.mosad.teapod.util.Meta
|
||||
import org.mosad.teapod.util.TVShowMeta
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVSeason
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* PlayerViewModel handles all stuff related to media/episodes.
|
||||
@ -29,45 +60,95 @@ import kotlin.collections.ArrayList
|
||||
class PlayerViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
val player = SimpleExoPlayer.Builder(application).build()
|
||||
val dataSourceFactory = DefaultDataSourceFactory(application, Util.getUserAgent(application, "Teapod"))
|
||||
private val dataSourceFactory = DefaultDataSourceFactory(application, Util.getUserAgent(application, "Teapod"))
|
||||
private val mediaSession = MediaSessionCompat(application, "TEAPOD_PLAYER_SESSION")
|
||||
|
||||
val currentEpisodeChangedListener = ArrayList<() -> Unit>()
|
||||
val preferredLanguage = if (Preferences.preferSecondary) Locale.JAPANESE else Locale.GERMAN
|
||||
private val preferredLanguage = if (Preferences.preferSecondary) Locale.JAPANESE else Locale.GERMAN
|
||||
private var currentPlayhead: Long = 0
|
||||
|
||||
var media: Media = Media(-1, "", DataTypes.MediaType.OTHER)
|
||||
// tmdb/meta data TODO currently not implemented for cr
|
||||
var mediaMeta: Meta? = null
|
||||
internal set
|
||||
var currentEpisode = Episode()
|
||||
var tmdbTVSeason: TMDBTVSeason? =null
|
||||
internal set
|
||||
var nextEpisode: Episode? = null
|
||||
var currentEpisodeMeta: EpisodeMeta? = null
|
||||
internal set
|
||||
var currentLanguage: Locale = Locale.ROOT
|
||||
|
||||
// crunchyroll episodes/playback
|
||||
var episodes = NoneEpisodes
|
||||
internal set
|
||||
var currentEpisode = NoneEpisode
|
||||
internal set
|
||||
var currentPlayback = NonePlayback
|
||||
|
||||
// current playback settings
|
||||
var currentLanguage: Locale = Preferences.preferredLocal
|
||||
internal set
|
||||
|
||||
init {
|
||||
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()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
|
||||
mediaSession.release()
|
||||
player.release()
|
||||
|
||||
Log.d(javaClass.name, "Released player")
|
||||
}
|
||||
|
||||
fun loadMedia(mediaId: Int, episodeId: Int) {
|
||||
runBlocking {
|
||||
media = AoDParser.getMediaById(mediaId)
|
||||
}
|
||||
/**
|
||||
* 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)
|
||||
|
||||
currentEpisode = media.getEpisodeById(episodeId)
|
||||
nextEpisode = selectNextEpisode()
|
||||
currentLanguage = currentEpisode.getPreferredStream(preferredLanguage).language
|
||||
mediaSession.isActive = true
|
||||
}
|
||||
|
||||
fun loadMediaAsync(seasonId: String, episodeId: String) = viewModelScope.launch {
|
||||
episodes = Crunchyroll.episodes(seasonId)
|
||||
|
||||
setCurrentEpisode(episodeId)
|
||||
playCurrentMedia(currentPlayhead) // TODO, if fully watched, start from 0
|
||||
|
||||
// TODO reimplement for cr
|
||||
// run async as it should be loaded by the time the episodes a
|
||||
// viewModelScope.launch {
|
||||
// // get tmdb season info, if metaDB knows the tv show
|
||||
// if (media.type == DataTypes.MediaType.TVSHOW && mediaMeta != null) {
|
||||
// val tvShowMeta = mediaMeta as TVShowMeta
|
||||
// tmdbTVSeason = TMDBApiController().getTVSeasonDetails(tvShowMeta.tmdbId, tvShowMeta.tmdbSeasonNumber)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// currentEpisodeMeta = getEpisodeMetaByAoDMediaId(currentEpisodeAoD.mediaId)
|
||||
// currentLanguage = currentEpisodeAoD.getPreferredStream(preferredLanguage).language
|
||||
}
|
||||
|
||||
fun setLanguage(language: Locale) {
|
||||
currentLanguage = language
|
||||
|
||||
val seekTime = player.currentPosition
|
||||
val mediaSource = HlsMediaSource.Factory(dataSourceFactory).createMediaSource(
|
||||
MediaItem.fromUri(Uri.parse(currentEpisode.getPreferredStream(language).url))
|
||||
)
|
||||
playMedia(mediaSource, true, seekTime)
|
||||
playCurrentMedia(player.currentPosition)
|
||||
}
|
||||
|
||||
// player actions
|
||||
@ -81,51 +162,92 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
/**
|
||||
* play the next episode, if nextEpisode is not null
|
||||
* play the next episode, if nextEpisodeId is not null
|
||||
*/
|
||||
fun playNextEpisode() = nextEpisode?.let { it ->
|
||||
playEpisode(it, replace = true)
|
||||
fun playNextEpisode() = currentEpisode.nextEpisodeId?.let { nextEpisodeId ->
|
||||
setCurrentEpisode(nextEpisodeId, startPlayback = true)
|
||||
}
|
||||
|
||||
/**
|
||||
* set currentEpisode to the param episode and start playing it
|
||||
* update nextEpisode to reflect the change
|
||||
*
|
||||
* updateWatchedState for the next (now current) episode
|
||||
* Set currentEpisodeCr to the episode of the given ID
|
||||
* @param episodeId The ID of the episode you want to set currentEpisodeCr to
|
||||
*/
|
||||
fun playEpisode(episode: Episode, replace: Boolean = false, seekPosition: Long = 0) {
|
||||
val preferredStream = episode.getPreferredStream(currentLanguage)
|
||||
currentLanguage = preferredStream.language // update current language, since it may have changed
|
||||
currentEpisode = episode
|
||||
nextEpisode = selectNextEpisode()
|
||||
currentEpisodeChangedListener.forEach { it() } // update player gui (title)
|
||||
fun setCurrentEpisode(episodeId: String, startPlayback: Boolean = false) {
|
||||
currentEpisode = episodes.items.find { episode ->
|
||||
episode.id == episodeId
|
||||
} ?: NoneEpisode
|
||||
|
||||
// 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()
|
||||
runBlocking {
|
||||
joinAll(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
currentPlayback = Crunchyroll.playback(currentEpisode.playback)
|
||||
},
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
Crunchyroll.playheads(listOf(currentEpisode.id))[currentEpisode.id]?.let {
|
||||
currentPlayhead = (it.playhead.times(1000)).toLong()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
println("loaded playback ${currentEpisode.playback}")
|
||||
|
||||
// TODO update metadata and language (it should not be needed to update the language here!)
|
||||
|
||||
if (startPlayback) {
|
||||
playCurrentMedia()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the current media from currentPlaybackCr.
|
||||
*
|
||||
* @param seekPosition The seek position for the episode (default = 0).
|
||||
*/
|
||||
fun playCurrentMedia(seekPosition: Long = 0) {
|
||||
// get preferred stream url, set current language if it differs from the preferred one
|
||||
val preferredLocale = currentLanguage
|
||||
val fallbackLocal = Locale.US
|
||||
val url = when {
|
||||
currentPlayback.streams.adaptive_hls.containsKey(preferredLocale.toLanguageTag()) -> {
|
||||
currentPlayback.streams.adaptive_hls[preferredLocale.toLanguageTag()]?.url
|
||||
}
|
||||
currentPlayback.streams.adaptive_hls.containsKey(fallbackLocal.toLanguageTag()) -> {
|
||||
currentLanguage = fallbackLocal
|
||||
currentPlayback.streams.adaptive_hls[fallbackLocal.toLanguageTag()]?.url
|
||||
}
|
||||
else -> {
|
||||
currentLanguage = Locale.ROOT
|
||||
currentPlayback.streams.adaptive_hls[Locale.ROOT.toLanguageTag()]?.url ?: ""
|
||||
}
|
||||
}
|
||||
println("stream url: $url")
|
||||
|
||||
// create the media source object
|
||||
val mediaSource = HlsMediaSource.Factory(dataSourceFactory).createMediaSource(
|
||||
MediaItem.fromUri(Uri.parse(preferredStream.url))
|
||||
MediaItem.fromUri(Uri.parse(url))
|
||||
)
|
||||
playMedia(mediaSource, replace, seekPosition)
|
||||
|
||||
// if episodes has not been watched, mark as watched
|
||||
if (!episode.watched) {
|
||||
AoDParser.markAsWatched(media.id, episode.id)
|
||||
}
|
||||
}
|
||||
|
||||
fun playMedia(source: MediaSource, replace: Boolean = false, seekPosition: Long = 0) {
|
||||
if (replace || player.contentDuration == C.TIME_UNSET) {
|
||||
player.setMediaSource(source)
|
||||
player.prepare()
|
||||
if (seekPosition > 0) player.seekTo(seekPosition)
|
||||
player.playWhenReady = true
|
||||
}
|
||||
// the actual player playback code
|
||||
player.setMediaSource(mediaSource)
|
||||
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 {
|
||||
return if (media.type == DataTypes.MediaType.TVSHOW) {
|
||||
// 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.number,
|
||||
currentEpisode.description
|
||||
currentEpisode.episode,
|
||||
currentEpisode.title
|
||||
)
|
||||
} else {
|
||||
currentEpisode.title
|
||||
@ -133,16 +255,44 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the current episodeId, get the next episode. If there is no next
|
||||
* episode, return null
|
||||
* Check if the current episode is the last in the episodes list.
|
||||
*
|
||||
* @return Boolean: true if it is the last, else false.
|
||||
*/
|
||||
private fun selectNextEpisode(): Episode? {
|
||||
val nextEpIndex = media.episodes.indexOfFirst { it.id == currentEpisode.id } + 1
|
||||
return if (nextEpIndex < media.episodes.size) {
|
||||
media.episodes[nextEpIndex]
|
||||
fun currentEpisodeIsLastEpisode(): Boolean {
|
||||
return episodes.items.lastOrNull()?.id == currentEpisode.id
|
||||
}
|
||||
|
||||
fun getEpisodeMetaByAoDMediaId(aodMediaId: Int): EpisodeMeta? {
|
||||
val meta = mediaMeta
|
||||
return if (meta is TVShowMeta) {
|
||||
meta.episodes.firstOrNull { it.aodMediaId == aodMediaId }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
// TODO reimplement for cr
|
||||
private suspend fun loadMediaMeta(aodId: Int): Meta? {
|
||||
// return if (media.type == DataTypes.MediaType.TVSHOW) {
|
||||
// MetaDBController().getTVShowMetadata(aodId)
|
||||
// } else {
|
||||
// null
|
||||
// }
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the playhead of the current episode, if currentPosition > 1000ms.
|
||||
*/
|
||||
private fun updatePlayhead() {
|
||||
val playhead = (player.currentPosition / 1000)
|
||||
|
||||
if (playhead > 0) {
|
||||
viewModelScope.launch { Crunchyroll.postPlayheads(currentEpisode.id, playhead.toInt()) }
|
||||
Log.i(javaClass.name, "Set playhead for episode ${currentEpisode.id} to $playhead sec.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -28,16 +28,16 @@ class EpisodesListPlayer @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
model?.let {
|
||||
adapterRecEpisodes = PlayerEpisodeItemAdapter(model.media.episodes)
|
||||
|
||||
adapterRecEpisodes.onImageClick = { _, position ->
|
||||
adapterRecEpisodes = PlayerEpisodeItemAdapter(model.episodes, model.tmdbTVSeason?.episodes)
|
||||
adapterRecEpisodes.onImageClick = {_, episodeId ->
|
||||
(this.parent as ViewGroup).removeView(this)
|
||||
model.playEpisode(model.media.episodes[position], replace = true)
|
||||
model.setCurrentEpisode(episodeId, startPlayback = true)
|
||||
}
|
||||
adapterRecEpisodes.currentSelected = model.currentEpisode.number - 1
|
||||
// episodeNumber starts at 1, we need the episode index -> - 1
|
||||
adapterRecEpisodes.currentSelected = model.currentEpisode.episodeNumber?.minus(1) ?: 0
|
||||
|
||||
binding.recyclerEpisodesPlayer.adapter = adapterRecEpisodes
|
||||
binding.recyclerEpisodesPlayer.scrollToPosition(model.currentEpisode.number - 1) // number != index
|
||||
binding.recyclerEpisodesPlayer.scrollToPosition(adapterRecEpisodes.currentSelected)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,15 @@ 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 kotlinx.android.synthetic.main.button_fast_forward.view.*
|
||||
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
|
||||
@ -19,30 +21,30 @@ class FastForwardButton(context: Context, attrs: AttributeSet?): FrameLayout(con
|
||||
var onAnimationEndCallback: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.button_fast_forward, this)
|
||||
addView(binding.root)
|
||||
|
||||
buttonAnimation = ObjectAnimator.ofFloat(imageButton, View.ROTATION, 0f, 50f).apply {
|
||||
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?) {
|
||||
imageButton.isEnabled = false // disable button
|
||||
imageButton.setBackgroundResource(R.drawable.ic_baseline_forward_24)
|
||||
binding.imageButton.isEnabled = false // disable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_forward_24)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
labelAnimation = ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, 35f).apply {
|
||||
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?) {
|
||||
imageButton.isEnabled = true // enable button
|
||||
imageButton.setBackgroundResource(R.drawable.ic_baseline_forward_10_24)
|
||||
binding.imageButton.isEnabled = true // enable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_forward_10_24)
|
||||
|
||||
textView.visibility = View.GONE
|
||||
textView.animate().translationX(0f)
|
||||
binding.textView.visibility = View.GONE
|
||||
binding.textView.animate().translationX(0f)
|
||||
|
||||
onAnimationEndCallback?.invoke()
|
||||
}
|
||||
@ -51,7 +53,7 @@ class FastForwardButton(context: Context, attrs: AttributeSet?): FrameLayout(con
|
||||
}
|
||||
|
||||
fun setOnButtonClickListener(func: FastForwardButton.() -> Unit) {
|
||||
imageButton.setOnClickListener {
|
||||
binding.imageButton.setOnClickListener {
|
||||
func()
|
||||
}
|
||||
}
|
||||
@ -61,7 +63,7 @@ class FastForwardButton(context: Context, attrs: AttributeSet?): FrameLayout(con
|
||||
buttonAnimation.start()
|
||||
|
||||
// run lbl animation
|
||||
textView.visibility = View.VISIBLE
|
||||
binding.textView.visibility = View.VISIBLE
|
||||
labelAnimation.start()
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import org.mosad.teapod.databinding.PlayerLanguageSettingsBinding
|
||||
import org.mosad.teapod.ui.activity.player.PlayerViewModel
|
||||
import java.util.*
|
||||
|
||||
// TODO port to DialogFragment
|
||||
class LanguageSettingsPlayer @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
@ -24,16 +25,17 @@ class LanguageSettingsPlayer @JvmOverloads constructor(
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val binding = PlayerLanguageSettingsBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
var onViewRemovedAction: (() -> Unit)? = null // TODO find a better solution for this
|
||||
var onViewRemovedAction: (() -> Unit)? = null
|
||||
|
||||
private var currentLanguage = model?.currentLanguage ?: Locale.ROOT
|
||||
private var selectedLocale = model?.currentLanguage ?: Locale.ROOT
|
||||
|
||||
init {
|
||||
model?.let {
|
||||
model.currentEpisode.streams.forEach { stream ->
|
||||
addLanguage(stream.language.displayName, stream.language == currentLanguage) {
|
||||
currentLanguage = stream.language
|
||||
updateSelectedLanguage(it as TextView)
|
||||
model?.let { m ->
|
||||
m.currentPlayback.streams.adaptive_hls.keys.forEach { languageTag ->
|
||||
val locale = Locale.forLanguageTag(languageTag)
|
||||
addLanguage(locale, locale == m.currentLanguage) { v ->
|
||||
selectedLocale = locale
|
||||
updateSelectedLanguage(v as TextView)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,16 +43,16 @@ class LanguageSettingsPlayer @JvmOverloads constructor(
|
||||
binding.buttonCloseLanguageSettings.setOnClickListener { close() }
|
||||
binding.buttonCancel.setOnClickListener { close() }
|
||||
binding.buttonSelect.setOnClickListener {
|
||||
model?.setLanguage(currentLanguage)
|
||||
model?.setLanguage(selectedLocale)
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addLanguage(str: String, isSelected: Boolean, onClick: OnClickListener) {
|
||||
private fun addLanguage(locale: Locale, isSelected: Boolean, onClick: OnClickListener) {
|
||||
val text = TextView(context).apply {
|
||||
height = 96
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
text = str
|
||||
text = if (locale == Locale.ROOT) context.getString(R.string.no_subtitles) else locale.displayLanguage
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
|
||||
if (isSelected) {
|
||||
|
@ -5,13 +5,15 @@ 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 kotlinx.android.synthetic.main.button_rewind.view.*
|
||||
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
|
||||
@ -19,29 +21,29 @@ class RewindButton(context: Context, attrs: AttributeSet): FrameLayout(context,
|
||||
var onAnimationEndCallback: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.button_rewind, this)
|
||||
addView(binding.root)
|
||||
|
||||
buttonAnimation = ObjectAnimator.ofFloat(imageButton, View.ROTATION, 0f, -50f).apply {
|
||||
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?) {
|
||||
imageButton.isEnabled = false // disable button
|
||||
imageButton.setBackgroundResource(R.drawable.ic_baseline_rewind_24)
|
||||
binding.imageButton.isEnabled = false // disable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_rewind_24)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
labelAnimation = ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, -35f).apply {
|
||||
labelAnimation = ObjectAnimator.ofFloat(binding.textView, View.TRANSLATION_X, -35f).apply {
|
||||
duration = animationDuration
|
||||
addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
imageButton.isEnabled = true // enable button
|
||||
imageButton.setBackgroundResource(R.drawable.ic_baseline_rewind_10_24)
|
||||
binding.imageButton.isEnabled = true // enable button
|
||||
binding.imageButton.setBackgroundResource(R.drawable.ic_baseline_rewind_10_24)
|
||||
|
||||
textView.visibility = View.GONE
|
||||
textView.animate().translationX(0f)
|
||||
binding.textView.visibility = View.GONE
|
||||
binding.textView.animate().translationX(0f)
|
||||
|
||||
onAnimationEndCallback?.invoke()
|
||||
}
|
||||
@ -50,7 +52,7 @@ class RewindButton(context: Context, attrs: AttributeSet): FrameLayout(context,
|
||||
}
|
||||
|
||||
fun setOnButtonClickListener(func: RewindButton.() -> Unit) {
|
||||
imageButton.setOnClickListener {
|
||||
binding.imageButton.setOnClickListener {
|
||||
func()
|
||||
}
|
||||
}
|
||||
@ -60,7 +62,7 @@ class RewindButton(context: Context, attrs: AttributeSet): FrameLayout(context,
|
||||
buttonAnimation.start()
|
||||
|
||||
// run lbl animation
|
||||
textView.visibility = View.VISIBLE
|
||||
binding.textView.visibility = View.VISIBLE
|
||||
labelAnimation.start()
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
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) {
|
||||
@ -36,59 +35,47 @@ data class ThirdPartyComponent(
|
||||
* 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 the episodes workflow could use a clean up/rework
|
||||
*/
|
||||
data class Media(
|
||||
val id: Int,
|
||||
val link: String,
|
||||
// TODO replace playlist: List<AoDEpisode> with a map?
|
||||
data class AoDMedia(
|
||||
val aodId: Int,
|
||||
val type: DataTypes.MediaType,
|
||||
val info: Info = Info(),
|
||||
val episodes: ArrayList<Episode> = arrayListOf()
|
||||
val title: String,
|
||||
val shortText: String,
|
||||
val posterURL: String,
|
||||
var year: Int,
|
||||
var age: Int,
|
||||
val similar: List<ItemMedia>,
|
||||
val playlist: List<AoDEpisode>,
|
||||
) {
|
||||
fun hasEpisode(id: Int) = episodes.any { it.id == id }
|
||||
fun getEpisodeById(id: Int) = episodes.first { it.id == id }
|
||||
fun getEpisodeById(mediaId: Int) = playlist.firstOrNull { it.mediaId == mediaId }
|
||||
?: AoDEpisodeNone
|
||||
}
|
||||
|
||||
// TODO all val?
|
||||
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,
|
||||
var similar: List<ItemMedia> = listOf()
|
||||
)
|
||||
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 }
|
||||
|
||||
/**
|
||||
* number = episode number (0..n)
|
||||
*/
|
||||
data class Episode(
|
||||
val id: Int = -1,
|
||||
val streams: MutableList<Stream> = mutableListOf(),
|
||||
val title: String = "",
|
||||
val posterUrl: String = "",
|
||||
val description: String = "",
|
||||
var shortDesc: String = "",
|
||||
val number: Int = 0,
|
||||
var watched: Boolean = false,
|
||||
var watchedCallback: String = ""
|
||||
) {
|
||||
/**
|
||||
* get the preferred stream
|
||||
* @return the preferred stream, if not present use the first stream
|
||||
*/
|
||||
fun getPreferredStream(language: Locale) =
|
||||
streams.firstOrNull { it.language == language } ?: streams.first()
|
||||
|
||||
fun hasDub() = streams.any { it.language == Locale.GERMAN }
|
||||
fun getPreferredStream(language: Locale) = streams.firstOrNull { it.language == language }
|
||||
?: Stream("", Locale.ROOT)
|
||||
}
|
||||
|
||||
data class Stream(
|
||||
@ -96,25 +83,45 @@ data class Stream(
|
||||
val language : Locale
|
||||
)
|
||||
|
||||
/**
|
||||
* this class is used for tmdb responses
|
||||
* TODO why is runtime var?
|
||||
*/
|
||||
data class TMDBResponse(
|
||||
val id: Int = 0,
|
||||
val title: String = "",
|
||||
val overview: String = "",
|
||||
val posterUrl: String = "",
|
||||
val backdropUrl: String = "",
|
||||
var runtime: Int = 0
|
||||
// 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()
|
||||
)
|
||||
|
||||
/**
|
||||
* this class is used to represent the aod json API?
|
||||
*/
|
||||
data class AoDObject(
|
||||
val playlist: List<Playlist>,
|
||||
val extLanguage: String
|
||||
data class AoDPlaylist(
|
||||
val list: List<Playlist>,
|
||||
val language: Locale
|
||||
)
|
||||
|
||||
data class Playlist(
|
||||
|
159
app/src/main/java/org/mosad/teapod/util/MetaDBController.kt
Normal file
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.FileNotFoundException
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* TODO remove gson usage
|
||||
*/
|
||||
class MetaDBController {
|
||||
|
||||
companion object {
|
||||
private const val repoUrl = "https://gitlab.com/Seil0/teapodmetadb/-/raw/main/aod/"
|
||||
|
||||
var mediaList = MediaList(listOf())
|
||||
private var metaCacheList = arrayListOf<Meta>()
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
suspend fun list() = withContext(Dispatchers.IO) {
|
||||
val url = URL("$repoUrl/list.json")
|
||||
val json = url.readText()
|
||||
|
||||
mediaList = Gson().fromJson(json, MediaList::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta data for a movie from MetaDB
|
||||
* @param aodId The AoD id of the media
|
||||
* @return A meta movie object, or null if not found
|
||||
*/
|
||||
suspend fun getMovieMetadata(aodId: Int): MovieMeta? {
|
||||
return metaCacheList.firstOrNull {
|
||||
it.aodId == aodId
|
||||
} as MovieMeta? ?: getMovieMetadataFromDB(aodId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the meta data for a tv show from MetaDB
|
||||
* @param aodId The AoD id of the media
|
||||
* @return A meta tv show object, or null if not found
|
||||
*/
|
||||
suspend fun getTVShowMetadata(aodId: Int): TVShowMeta? {
|
||||
return metaCacheList.firstOrNull {
|
||||
it.aodId == aodId
|
||||
} as TVShowMeta? ?: getTVShowMetadataFromDB(aodId)
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun getMovieMetadataFromDB(aodId: Int): MovieMeta? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$repoUrl/movie/$aodId/media.json")
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
val meta = Gson().fromJson(json, MovieMeta::class.java)
|
||||
metaCacheList.add(meta)
|
||||
|
||||
meta
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested file was not found. Requested ID: $aodId", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
private suspend fun getTVShowMetadataFromDB(aodId: Int): TVShowMeta? = withContext(Dispatchers.IO) {
|
||||
val url = URL("$repoUrl/tv/$aodId/media.json")
|
||||
return@withContext try {
|
||||
val json = url.readText()
|
||||
val meta = Gson().fromJson(json, TVShowMeta::class.java)
|
||||
metaCacheList.add(meta)
|
||||
|
||||
meta
|
||||
} catch (ex: FileNotFoundException) {
|
||||
Log.w(javaClass.name, "Waring: The requested file was not found. Requested ID: $aodId", ex)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// class representing the media list json object
|
||||
data class MediaList(
|
||||
val media: List<Int>
|
||||
)
|
||||
|
||||
// abstract class used for meta data objects (tv, movie)
|
||||
abstract class Meta {
|
||||
abstract val id: Int
|
||||
abstract val aodId: Int
|
||||
abstract val tmdbId: Int
|
||||
}
|
||||
|
||||
// class representing the movie json object
|
||||
data class MovieMeta(
|
||||
override val id: Int,
|
||||
@SerializedName("aod_id")
|
||||
override val aodId: Int,
|
||||
@SerializedName("tmdb_id")
|
||||
override val tmdbId: Int
|
||||
): Meta()
|
||||
|
||||
// class representing the tv show json object
|
||||
data class TVShowMeta(
|
||||
override val id: Int,
|
||||
@SerializedName("aod_id")
|
||||
override val aodId: Int,
|
||||
@SerializedName("tmdb_id")
|
||||
override val tmdbId: Int,
|
||||
@SerializedName("tmdb_season_id")
|
||||
val tmdbSeasonId: Int,
|
||||
@SerializedName("tmdb_season_number")
|
||||
val tmdbSeasonNumber: Int,
|
||||
@SerializedName("episodes")
|
||||
val episodes: List<EpisodeMeta>
|
||||
): Meta()
|
||||
|
||||
// class used in TVShowMeta, part of the tv show json object
|
||||
data class EpisodeMeta(
|
||||
val id: Int,
|
||||
@SerializedName("aod_media_id")
|
||||
val aodMediaId: Int,
|
||||
@SerializedName("tmdb_id")
|
||||
val tmdbId: Int,
|
||||
@SerializedName("tmdb_number")
|
||||
val tmdbNumber: Int,
|
||||
@SerializedName("opening_start")
|
||||
val openingStart: Long,
|
||||
@SerializedName("opening_duration")
|
||||
val openingDuration: Long,
|
||||
@SerializedName("ending_start")
|
||||
val endingStart: Long,
|
||||
@SerializedName("ending_duration")
|
||||
val endingDuration: Long
|
||||
)
|
@ -1,44 +0,0 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonParser
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
|
||||
/**
|
||||
* 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() }
|
||||
|
||||
try {
|
||||
myList.clear()
|
||||
myList.addAll(JsonParser.parseString(file.readText()).asJsonArray.map { it.asInt }.distinct())
|
||||
} catch (ex: Exception) {
|
||||
myList.clear()
|
||||
Log.e(javaClass.name, "Parsing of My-List failed.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun saveMyList(context: Context): Job {
|
||||
val file = File(context.filesDir, fileNameMyList)
|
||||
|
||||
return GlobalScope.launch(Dispatchers.IO) {
|
||||
file.writeText(Gson().toJson(myList.distinct()))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.util.Log
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import kotlinx.coroutines.*
|
||||
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"
|
||||
|
||||
suspend fun search(title: String, type: MediaType): TMDBResponse {
|
||||
val searchTerm = title.replace("(Sub)", "").trim()
|
||||
|
||||
return when (type) {
|
||||
MediaType.MOVIE -> searchMovie(searchTerm).await()
|
||||
MediaType.TVSHOW -> searchTVShow(searchTerm).await()
|
||||
else -> {
|
||||
Log.e(javaClass.name, "Wrong Type: $type")
|
||||
TMDBResponse()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun searchTVShow(title: String): Deferred<TMDBResponse> {
|
||||
val url = URL("$searchTVUrl$preparedParameters&query=${URLEncoder.encode(title, "UTF-8")}")
|
||||
|
||||
return GlobalScope.async {
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
//println(response)
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun searchMovie(title: String): Deferred<TMDBResponse> {
|
||||
val url = URL("$searchMovieUrl$preparedParameters&query=${URLEncoder.encode(title, "UTF-8")}")
|
||||
|
||||
return GlobalScope.async {
|
||||
val response = JsonParser.parseString(url.readText()).asJsonObject
|
||||
//println(response)
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
return@async getStringNotNull(response,"runtime").toInt()
|
||||
}.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 {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,29 @@
|
||||
package org.mosad.teapod.util
|
||||
|
||||
import android.widget.TextView
|
||||
import org.mosad.teapod.parser.crunchyroll.Collection
|
||||
import org.mosad.teapod.parser.crunchyroll.ContinueWatchingItem
|
||||
import org.mosad.teapod.parser.crunchyroll.ContinueWatchingList
|
||||
import org.mosad.teapod.parser.crunchyroll.Item
|
||||
|
||||
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 Collection<Item>.toItemMediaList(): List<ItemMedia> {
|
||||
return this.items.map {
|
||||
ItemMedia(it.id, it.title, it.images.poster_wide[0][0].source)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("toItemMediaListContinueWatchingItem")
|
||||
fun Collection<ContinueWatchingItem>.toItemMediaList(): List<ItemMedia> {
|
||||
return this.items.map {
|
||||
ItemMedia(it.panel.episodeMetadata.seriesId, it.panel.title, it.panel.images.thumbnail[0][0].source)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ 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.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -11,11 +12,17 @@ import com.bumptech.glide.request.RequestOptions
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemEpisodeBinding
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.parser.crunchyroll.Episode
|
||||
import org.mosad.teapod.parser.crunchyroll.PlayheadsMap
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVEpisode
|
||||
|
||||
class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Adapter<EpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
class EpisodeItemAdapter(
|
||||
private val episodes: List<Episode>,
|
||||
private val tmdbEpisodes: List<TMDBTVEpisode>?,
|
||||
private val playheads: PlayheadsMap
|
||||
) : RecyclerView.Adapter<EpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
|
||||
var onImageClick: ((String, Int) -> Unit)? = null
|
||||
var onImageClick: ((seasonId: String, episodeId: String) -> Unit)? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EpisodeViewHolder {
|
||||
return EpisodeViewHolder(ItemEpisodeBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
@ -25,29 +32,41 @@ class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Ada
|
||||
val context = holder.binding.root.context
|
||||
val ep = episodes[position]
|
||||
|
||||
val titleText = if (ep.hasDub()) {
|
||||
context.getString(R.string.component_episode_title, ep.number, ep.description)
|
||||
val titleText = if (ep.episodeNumber != null) {
|
||||
// for tv shows add ep prefix and episode number
|
||||
if (ep.isDubbed) {
|
||||
context.getString(R.string.component_episode_title, ep.episode, ep.title)
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, ep.episode, ep.title)
|
||||
}
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, ep.number, ep.description)
|
||||
ep.title
|
||||
}
|
||||
|
||||
holder.binding.textEpisodeTitle.text = titleText
|
||||
holder.binding.textEpisodeDesc.text = ep.shortDesc
|
||||
holder.binding.textEpisodeDesc.text = if (ep.description.isNotEmpty()) {
|
||||
ep.description
|
||||
} else if (tmdbEpisodes != null && position < tmdbEpisodes.size){
|
||||
tmdbEpisodes[position].overview
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
if (episodes[position].posterUrl.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.posterUrl)
|
||||
// TODO is isNotEmpty() needed? also in PlayerEpisodeItemAdapter
|
||||
if (ep.images.thumbnail[0][0].source.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.images.thumbnail[0][0].source)
|
||||
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(holder.binding.imageEpisode)
|
||||
}
|
||||
|
||||
if (ep.watched) {
|
||||
holder.binding.imageWatched.setImageDrawable(
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_circle_24)
|
||||
)
|
||||
// add watched icon to episode, if the episode id is present in playheads and fullyWatched
|
||||
val watchedImage: Drawable? = if (playheads[ep.id]?.fullyWatched == true) {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_baseline_check_circle_24)
|
||||
} else {
|
||||
holder.binding.imageWatched.setImageDrawable(null)
|
||||
null
|
||||
}
|
||||
holder.binding.imageWatched.setImageDrawable(watchedImage)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
@ -56,13 +75,20 @@ class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Ada
|
||||
|
||||
fun updateWatchedState(watched: Boolean, position: Int) {
|
||||
// use getOrNull as there could be a index out of bound when running this in onResume()
|
||||
episodes.getOrNull(position)?.watched = watched
|
||||
|
||||
// TODO
|
||||
//episodes.getOrNull(position)?.watched = watched
|
||||
}
|
||||
|
||||
inner class EpisodeViewHolder(val binding: ItemEpisodeBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
inner class EpisodeViewHolder(val binding: ItemEpisodeBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
// on image click return the episode id and index (within the adapter)
|
||||
binding.imageEpisode.setOnClickListener {
|
||||
onImageClick?.invoke(episodes[adapterPosition].title, adapterPosition)
|
||||
onImageClick?.invoke(
|
||||
episodes[bindingAdapterPosition].seasonId,
|
||||
episodes[bindingAdapterPosition].id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,14 @@ package org.mosad.teapod.util.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Filter
|
||||
import android.widget.Filterable
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import org.mosad.teapod.databinding.ItemMediaBinding
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import java.util.*
|
||||
|
||||
class MediaItemAdapter(private val initMedia: List<ItemMedia>) : RecyclerView.Adapter<MediaItemAdapter.MediaViewHolder>(), Filterable {
|
||||
class MediaItemAdapter(private val items: List<ItemMedia>) : RecyclerView.Adapter<MediaItemAdapter.MediaViewHolder>() {
|
||||
|
||||
var onItemClick: ((Int, Int) -> Unit)? = null
|
||||
private val filter = MediaFilter()
|
||||
private var filteredMedia = initMedia.map { it.copy() }
|
||||
var onItemClick: ((id: String, position: Int) -> Unit)? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaItemAdapter.MediaViewHolder {
|
||||
return MediaViewHolder(ItemMediaBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
@ -22,58 +17,25 @@ class MediaItemAdapter(private val initMedia: List<ItemMedia>) : RecyclerView.Ad
|
||||
|
||||
override fun onBindViewHolder(holder: MediaItemAdapter.MediaViewHolder, position: Int) {
|
||||
holder.binding.root.apply {
|
||||
holder.binding.textTitle.text = filteredMedia[position].title
|
||||
Glide.with(context).load(filteredMedia[position].posterUrl).into(holder.binding.imagePoster)
|
||||
holder.binding.textTitle.text = items[position].title
|
||||
Glide.with(context).load(items[position].posterUrl).into(holder.binding.imagePoster)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return filteredMedia.size
|
||||
return items.size
|
||||
}
|
||||
|
||||
override fun getFilter(): Filter {
|
||||
return filter
|
||||
}
|
||||
|
||||
fun updateMediaList(mediaList: List<ItemMedia>) {
|
||||
filteredMedia = mediaList
|
||||
}
|
||||
|
||||
inner class MediaViewHolder(val binding: ItemMediaBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
inner class MediaViewHolder(val binding: ItemMediaBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
binding.root.setOnClickListener {
|
||||
onItemClick?.invoke(filteredMedia[adapterPosition].id, adapterPosition)
|
||||
onItemClick?.invoke(
|
||||
items[bindingAdapterPosition].id,
|
||||
bindingAdapterPosition
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
initMedia
|
||||
} else {
|
||||
initMedia.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()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,11 +9,12 @@ import com.bumptech.glide.request.RequestOptions
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.ItemEpisodePlayerBinding
|
||||
import org.mosad.teapod.util.Episode
|
||||
import org.mosad.teapod.parser.crunchyroll.Episodes
|
||||
import org.mosad.teapod.util.tmdb.TMDBTVEpisode
|
||||
|
||||
class PlayerEpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Adapter<PlayerEpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
class PlayerEpisodeItemAdapter(private val episodes: Episodes, private val tmdbEpisodes: List<TMDBTVEpisode>?) : RecyclerView.Adapter<PlayerEpisodeItemAdapter.EpisodeViewHolder>() {
|
||||
|
||||
var onImageClick: ((String, Int) -> Unit)? = null
|
||||
var onImageClick: ((seasonId: String, episodeId: String) -> Unit)? = null
|
||||
var currentSelected: Int = -1 // -1, since position should never be < 0
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EpisodeViewHolder {
|
||||
@ -22,19 +23,30 @@ class PlayerEpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerVi
|
||||
|
||||
override fun onBindViewHolder(holder: EpisodeViewHolder, position: Int) {
|
||||
val context = holder.binding.root.context
|
||||
val ep = episodes[position]
|
||||
val ep = episodes.items[position]
|
||||
|
||||
val titleText = if (ep.hasDub()) {
|
||||
context.getString(R.string.component_episode_title, ep.number, ep.description)
|
||||
val titleText = if (ep.episodeNumber != null) {
|
||||
// for tv shows add ep prefix and episode number
|
||||
if (ep.isDubbed) {
|
||||
context.getString(R.string.component_episode_title, ep.episode, ep.title)
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, ep.episode, ep.title)
|
||||
}
|
||||
} else {
|
||||
context.getString(R.string.component_episode_title_sub, ep.number, ep.description)
|
||||
ep.title
|
||||
}
|
||||
|
||||
holder.binding.textEpisodeTitle2.text = titleText
|
||||
holder.binding.textEpisodeDesc2.text = ep.shortDesc
|
||||
holder.binding.textEpisodeDesc2.text = if (ep.description.isNotEmpty()) {
|
||||
ep.description
|
||||
} else if (tmdbEpisodes != null && position < tmdbEpisodes.size){
|
||||
tmdbEpisodes[position].overview
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
if (episodes[position].posterUrl.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.posterUrl)
|
||||
if (ep.images.thumbnail[0][0].source.isNotEmpty()) {
|
||||
Glide.with(context).load(ep.images.thumbnail[0][0].source)
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(holder.binding.imageEpisode)
|
||||
}
|
||||
@ -48,15 +60,18 @@ class PlayerEpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerVi
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return episodes.size
|
||||
return episodes.items.size
|
||||
}
|
||||
|
||||
inner class EpisodeViewHolder(val binding: ItemEpisodePlayerBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
binding.imageEpisode.setOnClickListener {
|
||||
// don't execute, if it's the current episode
|
||||
if (currentSelected != adapterPosition) {
|
||||
onImageClick?.invoke(episodes[adapterPosition].title, adapterPosition)
|
||||
if (currentSelected != bindingAdapterPosition) {
|
||||
onImageClick?.invoke(
|
||||
episodes.items[bindingAdapterPosition].seasonId,
|
||||
episodes.items[bindingAdapterPosition].id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,150 @@
|
||||
/**
|
||||
* 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 com.github.kittinunf.fuel.Fuel
|
||||
import com.github.kittinunf.fuel.core.FuelError
|
||||
import com.github.kittinunf.fuel.core.Parameters
|
||||
import com.github.kittinunf.fuel.json.FuelJson
|
||||
import com.github.kittinunf.fuel.json.responseJson
|
||||
import com.github.kittinunf.result.Result
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
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 json = Json { ignoreUnknownKeys = true }
|
||||
|
||||
private val apiUrl = "https://api.themoviedb.org/3"
|
||||
private val apiKey = "de959cf9c07a08b5ca7cb51cda9a40c2"
|
||||
private val language = "de"
|
||||
|
||||
companion object{
|
||||
const val imageUrl = "https://image.tmdb.org/t/p/w500"
|
||||
}
|
||||
|
||||
private suspend fun request(
|
||||
endpoint: String,
|
||||
parameters: Parameters = emptyList()
|
||||
): Result<FuelJson, FuelError> = coroutineScope {
|
||||
val path = "$apiUrl$endpoint"
|
||||
val params = concatenate(listOf("api_key" to apiKey, "language" to language), parameters)
|
||||
|
||||
// TODO handle FileNotFoundException
|
||||
return@coroutineScope (Dispatchers.IO) {
|
||||
val (_, _, result) = Fuel.get(path, params)
|
||||
.responseJson()
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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/multi"
|
||||
val parameters = listOf("query" to query, "include_adult" to false)
|
||||
|
||||
val result = request(searchEndpoint, parameters)
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: 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)
|
||||
|
||||
val result = request(searchEndpoint, parameters)
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: 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?
|
||||
val result = request(movieEndpoint)
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: 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?
|
||||
val result = request(tvShowEndpoint)
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: 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?
|
||||
val result = request(tvShowSeasonEndpoint)
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneTMDBTVSeason
|
||||
}
|
||||
|
||||
}
|
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
|
||||
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 generes
|
||||
) : 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 generes
|
||||
) : 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, "", null, "")
|
||||
val NoneTMDBTVShow = TMDBTVShow(0, "", "", null, null, "", "", "")
|
||||
|
||||
@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)
|
6
app/src/main/res/drawable/ic_baseline_access_time_24.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<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="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>
|
@ -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>
|
@ -3,17 +3,18 @@
|
||||
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: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>
|
||||
<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
@ -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>
|
@ -1,5 +1,10 @@
|
||||
<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="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 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="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
@ -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>
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="?textBackground"/>
|
||||
<solid android:color="?attr/shapeTextBackground"/>
|
||||
<corners android:radius="3dp"/>
|
||||
</shape>
|
@ -16,9 +16,7 @@
|
||||
android:layout_gravity="center"
|
||||
android:animateLayoutChanges="true"
|
||||
android:foreground="@drawable/ripple_background"
|
||||
app:controller_layout_id="@layout/player_controls"
|
||||
app:fastforward_increment="10000"
|
||||
app:rewind_increment="10000" />
|
||||
app:controller_layout_id="@layout/player_controls" />
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/loading"
|
||||
@ -89,4 +87,20 @@
|
||||
app:backgroundTint="@color/exo_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="70dp"
|
||||
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/exo_white"
|
||||
app:iconGravity="textStart" />
|
||||
|
||||
</FrameLayout>
|
@ -79,8 +79,52 @@
|
||||
android:text="@string/account_login_desc"
|
||||
android:textColor="?textSecondary" />
|
||||
</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"
|
||||
app:tint="?iconColor" />
|
||||
|
||||
<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/account_subscription"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<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_subscription_desc"
|
||||
android:textColor="?textSecondary" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@ -176,7 +220,7 @@
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView4"
|
||||
android:id="@+id/image_autoplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/settings_autoplay"
|
||||
@ -237,7 +281,7 @@
|
||||
android:padding="7dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageViewTheme"
|
||||
android:id="@+id/image_theme"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/account"
|
||||
@ -274,6 +318,118 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_dev_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?themeSecondary"
|
||||
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:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<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">
|
||||
|
||||
<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"
|
||||
app:tint="?iconColor" />
|
||||
|
||||
<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"
|
||||
android:textColor="?textSecondary" />
|
||||
</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">
|
||||
|
||||
<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"
|
||||
app:tint="?iconColor" />
|
||||
|
||||
<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"
|
||||
android:textColor="?textSecondary" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_info"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -108,35 +108,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_my_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="7dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_my_list"
|
||||
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/my_list"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_my_list"
|
||||
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_episodes"
|
||||
android:id="@+id/linear_up_next"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
@ -150,7 +122,7 @@
|
||||
android:paddingTop="15dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:text="@string/new_episodes"
|
||||
android:text="@string/up_next"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@ -164,26 +136,26 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_new_simulcasts"
|
||||
android:id="@+id/linear_watchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="7dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_new_simulcasts"
|
||||
android:id="@+id/text_watchlist"
|
||||
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_simulcasts"
|
||||
android:text="@string/my_list"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_new_simulcasts"
|
||||
android:id="@+id/recycler_watchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
|
@ -111,6 +111,7 @@
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:text="@string/text_title_ex"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
@ -128,7 +129,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@ -136,15 +137,19 @@
|
||||
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="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:contentDescription="@string/my_list"
|
||||
android:padding="5dp"
|
||||
android:paddingStart="11dp"
|
||||
android:paddingTop="11dp"
|
||||
android:paddingEnd="11dp"
|
||||
android:paddingBottom="7dp"
|
||||
android:src="@drawable/ic_baseline_add_24"
|
||||
app:tint="?buttonBackground" />
|
||||
|
||||
@ -164,7 +169,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:background="@android:color/transparent"
|
||||
app:tabGravity="start"
|
||||
|
@ -1,10 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
<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:layout_width="match_parent"
|
||||
android:layout_height="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"
|
||||
@ -16,4 +30,4 @@
|
||||
tools:layout_editor_absoluteY="298dp"
|
||||
tools:listitem="@layout/item_episode" />
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
@ -65,6 +65,7 @@
|
||||
android:layout_margin="7dp"
|
||||
android:ems="10"
|
||||
android:hint="@string/password"
|
||||
android:imeOptions="actionDone"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
android:id="@+id/text_app_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:text="@string/on_welcome_heading"
|
||||
android:textAlignment="center"
|
||||
android:textSize="26sp"
|
||||
android:textStyle="bold" />
|
||||
|
@ -51,7 +51,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="5dp"
|
||||
android:maxLines="10"
|
||||
android:text="@string/text_overview_ex"
|
||||
android:textColor="@color/textPrimaryDark"/>
|
||||
android:textColor="@color/textPrimaryDark" />
|
||||
|
||||
</LinearLayout>
|
@ -125,7 +125,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:text="@string/language"
|
||||
android:text="@string/subtitles"
|
||||
android:textAllCaps="false"
|
||||
app:icon="@drawable/ic_baseline_subtitles_24"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -35,7 +35,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="44dp"
|
||||
android:text="@string/language"
|
||||
android:text="@string/subtitles"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/exo_white"
|
||||
android:textSize="16sp"
|
||||
@ -86,7 +86,7 @@
|
||||
android:id="@+id/button_select"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save"
|
||||
android:text="@string/apply"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/themePrimaryDark"
|
||||
android:textSize="16sp"
|
||||
|
@ -1,68 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<notices>
|
||||
<notice>
|
||||
<name>AndroidX</name>
|
||||
<url>https://developer.android.com/jetpack/androidx</url>
|
||||
<copyright>Copyright The Android Open Source Project</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Material Components for Android</name>
|
||||
<url>https://github.com/material-components/material-components-android</url>
|
||||
<copyright>Copyright The Android Open Source Project</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>ExoPlayer</name>
|
||||
<url>https://github.com/google/ExoPlayer</url>
|
||||
<copyright>Copyright The Android Open Source Project</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Gson</name>
|
||||
<url>https://github.com/google/gson</url>
|
||||
<copyright>Copyright 2008 Google Inc.</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Material design icons</name>
|
||||
<url>https://github.com/google/material-design-icons</url>
|
||||
<copyright>Copyright Google Inc.</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Material Dialogs</name>
|
||||
<url>https://github.com/afollestad/material-dialogs</url>
|
||||
<copyright>Copyright Aidan Follestad</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Jsoup</name>
|
||||
<url>https://jsoup.org/</url>
|
||||
<copyright>Copyright 2009 - 2020 Jonathan Hedley</copyright>
|
||||
<license>MIT License</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>kotlinx.coroutines</name>
|
||||
<url>https://github.com/Kotlin/kotlinx.coroutines</url>
|
||||
<copyright>Copyright 2016 - 2019 JetBrains</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Glide</name>
|
||||
<url>https://github.com/bumptech/glide</url>
|
||||
<copyright>Copyright Google, Inc</copyright>
|
||||
<license>BSD 2-Clause License</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>Glide Transformations</name>
|
||||
<url>https://github.com/wasabeef/glide-transformations</url>
|
||||
<copyright>Copyright 2020 Wasabeef</copyright>
|
||||
<license>Apache Software License 2.0</license>
|
||||
</notice>
|
||||
<notice>
|
||||
<name>The Movie Database API</name>
|
||||
<url>https://www.themoviedb.org</url>
|
||||
<copyright>This product uses the TMDb API but is not endorsed or certified by TMDb</copyright>
|
||||
</notice>
|
||||
</notices>
|
@ -7,6 +7,7 @@
|
||||
|
||||
<!-- home fragment -->
|
||||
<string name="highlight_media">Highlight</string>
|
||||
<string name="up_next">Weiterschauen</string>
|
||||
<string name="my_list">Meine Liste</string>
|
||||
<string name="new_episodes">Neue Episoden</string>
|
||||
<string name="new_simulcasts">Neue Simulcasts</string>
|
||||
@ -22,18 +23,19 @@
|
||||
<item quantity="one">%d Episode</item>
|
||||
<item quantity="other">%d Episoden</item>
|
||||
</plurals>
|
||||
<string name="text_runtime">%1$d Minuten</string>
|
||||
<plurals name="text_runtime">
|
||||
<item quantity="one">%d Minute</item>
|
||||
<item quantity="other">%d Minuten</item>
|
||||
</plurals>
|
||||
<string name="similar_titles">Ähnliche Titel</string>
|
||||
<string name="component_episode_title">Flg. %1$d %2$s</string>
|
||||
<string name="component_episode_title_sub">Flg. %1$d %2$s (OmU)</string>
|
||||
<string name="component_episode_title">Flg. %1$s %2$s</string>
|
||||
<string name="component_episode_title_sub">Flg. %1$s %2$s (OmU)</string>
|
||||
|
||||
<!-- settings fragment -->
|
||||
<string name="account">Account</string>
|
||||
<string name="account_login_desc">Zum bearbeiten tippen</string>
|
||||
<string name="account_subscription">Abo %1$s</string>
|
||||
<string name="account_subscription_desc">Zum verlängern tippen</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="info_about_desc">Version %1$s (%2$s)</string>
|
||||
<string name="settings">Einstellungen</string>
|
||||
@ -44,15 +46,23 @@
|
||||
<string name="theme">Design</string>
|
||||
<string name="theme_light">Hell</string>
|
||||
<string name="theme_dark">Dunkel</string>
|
||||
<string name="dev_settings">Entwickler Einstellungen</string>
|
||||
<string name="export_data">Daten exportieren</string>
|
||||
<string name="export_data_desc">Speichere "Meine Liste" in eine Datei</string>
|
||||
<string name="import_data">Daten importieren</string>
|
||||
<string name="import_data_desc">Lade "Meine Liste" aus einer Datei</string>
|
||||
<string name="import_data_success">"Meine Liste" erfolgreich importiert</string>
|
||||
|
||||
<!-- about fragment -->
|
||||
<string name="version">Version</string>
|
||||
<string name="authors">Autor</string>
|
||||
<string name="source">Quellcode</string>
|
||||
<string name="license">Lizenz</string>
|
||||
<string name="about_info">Eine inoffizielle App für Anime on Demand.</string>
|
||||
<string name="about_info">Eine inoffizielle App für Crunchyroll.</string>
|
||||
<string name="third_party_heading">Lizenzen von Drittanbietern</string>
|
||||
<string name="third_party_component_desc">© %1$s %2$s unter %3$s</string>
|
||||
<string name="dev_settings_enabled">Du bist jetzt ein Entwickler</string>
|
||||
<string name="dev_settings_already">Du bist schon ein Entwickler</string>
|
||||
|
||||
<!-- player -->
|
||||
<string name="close_player">Player schließen</string>
|
||||
@ -60,23 +70,29 @@
|
||||
<string name="play_pause">Abspielen/Pause</string>
|
||||
<string name="forward_10">10 Sekunden vorwärts</string>
|
||||
<string name="next_episode">Nächste Folge</string>
|
||||
<string name="skip_opening">Intro überspringen</string>
|
||||
<string name="language">Sprache</string>
|
||||
<string name="subtitles">Untertitel</string>
|
||||
<string name="episodes">Folgen</string>
|
||||
<string name="episode">Folge</string>
|
||||
<string name="no_subtitles">Aus</string>
|
||||
|
||||
<!-- Onboarding -->
|
||||
<string name="skip">Überspringen</string>
|
||||
<string name="next">Weiter</string>
|
||||
<string name="start">Fertig</string>
|
||||
<string name="on_welcome">Willkommen!\nTeapod ist eine inoffizielle App für AoD.</string>
|
||||
<string name="on_welcome_heading">Willkommen</string>
|
||||
<string name="on_welcome">Teapod ist eine inoffizielle App für Crunchyroll, die unter den Bedingungen der GPL 3 lizenziert ist.\n\nHinweis: Die Benutzung von Teapod kann gegen die Nutzungsbedingungen von Crunchyroll verstoßen.</string>
|
||||
<string name="on_get_started">Los geht\'s</string>
|
||||
<string name="on_login_heading">Login</string>
|
||||
<string name="on_login_desc">Um Teapod verwenden zu können musst du dich mit deinem AoD Account anmelden. Deine Login-Daten werden verschlüsselt auf deinem Gerät gespeichert.</string>
|
||||
<string name="on_login_desc">Um Teapod verwenden zu können musst du dich mit deinem Crunchyroll Account anmelden. Deine Login-Daten werden verschlüsselt auf deinem Gerät gespeichert.</string>
|
||||
<string name="on_login_failed">Login nicht erfolgreich! Stelle sicher das deine Login-Daten korrekt sind und versuche es erneut.</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="save">speichern</string>
|
||||
<string name="save">Speichern</string>
|
||||
<string name="apply">Übernehmen</string>
|
||||
<string name="cancel">@android:string/cancel</string>
|
||||
<string name="loading">Lädt…</string>
|
||||
<string name="dialog_timeout_head">Anmelden fehlgeschlagen</string>
|
||||
<string name="dialog_timeout_desc">Der Server scheint langsam zu antworten. Bitte versuche es später noch einmal.</string>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<attr format="color" name="themeSecondary"/>
|
||||
<attr format="color" name="textPrimary"/>
|
||||
<attr format="color" name="textSecondary"/>
|
||||
<attr format="color" name="textBackground"/>
|
||||
<attr format="color" name="iconColor"/>
|
||||
<attr format="color" name="buttonBackground"/>
|
||||
<attr format="color" name="shapeTextBackground"/>
|
||||
</resources>
|
@ -7,6 +7,7 @@
|
||||
|
||||
<!-- home fragment -->
|
||||
<string name="highlight_media">Highlight</string>
|
||||
<string name="up_next">Up next</string>
|
||||
<string name="my_list">My list</string>
|
||||
<string name="new_episodes">New episodes</string>
|
||||
<string name="new_simulcasts">New simulcasts</string>
|
||||
@ -29,14 +30,13 @@
|
||||
<item quantity="one">%d episode</item>
|
||||
<item quantity="other">%d episodes</item>
|
||||
</plurals>
|
||||
<string name="text_runtime">%1$d Minutes</string>
|
||||
<plurals name="text_runtime">
|
||||
<item quantity="one">%d Minute</item>
|
||||
<item quantity="other">%d Minutes</item>
|
||||
</plurals>
|
||||
<string name="similar_titles">Similar titles</string>
|
||||
<string name="component_episode_title">Ep. %1$d %2$s</string>
|
||||
<string name="component_episode_title_sub">Ep. %1$d %2$s (Sub)</string>
|
||||
<string name="component_episode_title">Ep. %1$s %2$s</string>
|
||||
<string name="component_episode_title_sub">Ep. %1$s %2$s (Sub)</string>
|
||||
<string name="component_poster_desc" translatable="false">episode poster</string>
|
||||
<string name="component_watched_desc" translatable="false">already watched</string>
|
||||
|
||||
@ -44,6 +44,8 @@
|
||||
<string name="account">Account</string>
|
||||
<string name="account_login_ex" translatable="false">user@example.com</string>
|
||||
<string name="account_login_desc">Tap to edit</string>
|
||||
<string name="account_subscription">Subscription %1$s</string>
|
||||
<string name="account_subscription_desc">Tap to extend</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="info_about" translatable="false">Teapod by @Seil0</string>
|
||||
<string name="info_about_desc">Version %1$s (%2$s)</string>
|
||||
@ -55,6 +57,13 @@
|
||||
<string name="theme">Theme</string>
|
||||
<string name="theme_light">Light</string>
|
||||
<string name="theme_dark">Dark</string>
|
||||
<string name="dev_settings">Developer Settings</string>
|
||||
<string name="export_data">export data</string>
|
||||
<string name="export_data_desc">export "My list" to a file</string>
|
||||
<string name="import_data">import data</string>
|
||||
<string name="import_data_desc">import "My list" from a file</string>
|
||||
<string name="import_data_success">imported "My list" successfully</string>
|
||||
|
||||
|
||||
<!-- about fragment -->
|
||||
<string name="version">Version</string>
|
||||
@ -65,10 +74,12 @@
|
||||
<string name="teapod_repo" translatable="false">git.mosad.xyz/Seil0/teapod</string>
|
||||
<string name="license">License</string>
|
||||
<string name="license_desc" translatable="false">GNU General Public License 3</string>
|
||||
<string name="about_info">An unofficial app for anime on demand.</string>
|
||||
<string name="about_info">An unofficial app for Crunchyroll.</string>
|
||||
<string name="tmdb_notice" translatable="false">This product uses the TMDb API but is not endorsed or certified by TMDb.</string>
|
||||
<string name="third_party_heading">Third Party Licenses</string>
|
||||
<string name="third_party_component_desc">© %1$s %2$s under %3$s</string>
|
||||
<string name="dev_settings_enabled">You are now a developer</string>
|
||||
<string name="dev_settings_already">You are already a developer</string>
|
||||
|
||||
<!-- player -->
|
||||
<string name="close_player">close player</string>
|
||||
@ -78,25 +89,31 @@
|
||||
<string name="rwd_10_s" translatable="false">- 10 s</string>
|
||||
<string name="fwd_10_s" translatable="false">+ 10 s</string>
|
||||
<string name="next_episode">Next Episode</string>
|
||||
<string name="skip_opening">Skip Opening</string>
|
||||
<string name="time_min_sec" translatable="false">%1$02d:%2$02d</string>
|
||||
<string name="time_hour_min_sec" translatable="false">%1$d:%2$02d:%3$02d</string>
|
||||
<string name="language">Language</string>
|
||||
<string name="subtitles">Subtitles</string>
|
||||
<string name="episodes">Episodes</string>
|
||||
<string name="episode">Episode</string>
|
||||
<string name="no_subtitles">None</string>
|
||||
|
||||
<!-- Onboarding -->
|
||||
<string name="skip">Skip</string>
|
||||
<string name="next">Next</string>
|
||||
<string name="start">Start</string>
|
||||
<string name="on_welcome">Welcome!\nTeapod is an unofficial App for AoD.</string>
|
||||
<string name="on_welcome_heading">Welcome</string>
|
||||
<string name="on_welcome">Teapod is an unofficial app for Crunchyroll, licensed under the terms and conditions of GPL 3.\n\nPlease note: Using Teapod may violate the ToS of Crunchyroll.</string>
|
||||
<string name="on_get_started">Get started</string>
|
||||
<string name="on_login_heading">Login</string>
|
||||
<string name="on_login_desc">To use Teapod you need to log in with your AoD account. Your Login-Data will be stored encrypted on your device.</string>
|
||||
<string name="on_login_desc">To use Teapod you have to log in with your Crunchyroll account. Your login data will be stored encrypted on your device.</string>
|
||||
<string name="on_login_failed">Could not login! Make sure Username and Password are correct and try again.</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="save">save</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="cancel">@android:string/cancel</string>
|
||||
<string name="apply">Apply</string>
|
||||
<string name="loading">Loading…</string>
|
||||
<string name="dialog_timeout_head">Login failed</string>
|
||||
<string name="dialog_timeout_desc">Looks like the server is taking to long to respond. Please try again later.</string>
|
||||
|
||||
@ -113,12 +130,12 @@
|
||||
<string name="save_key_user_password" translatable="false">org.mosad.teapod.user_password</string>
|
||||
<string name="save_key_prefer_secondary" translatable="false">org.mosad.teapod.prefer_secondary</string>
|
||||
<string name="save_key_autoplay" translatable="false">org.mosad.teapod.autoplay</string>
|
||||
<string name="save_key_dev_settings" translatable="false">org.mosad.teapod.dev.settings</string>
|
||||
<string name="save_key_theme" translatable="false">org.mosad.teapod.theme</string>
|
||||
|
||||
<!-- intents & states -->
|
||||
<string name="intent_media_id" translatable="false">intent_media_id</string>
|
||||
<string name="intent_season_id" translatable="false">intent_season_id</string>
|
||||
<string name="intent_episode_id" translatable="false">intent_episode_id</string>
|
||||
<string name="state_resume_window" translatable="false">state_resume_window</string>
|
||||
<string name="state_resume_position" translatable="false">state_resume_position</string>
|
||||
<string name="state_is_playing" translatable="false">state_is_playing</string>
|
||||
|
||||
</resources>
|
@ -4,6 +4,7 @@
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="popupMenuStyle">@style/Widget.App.PopupMenu</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.Light" parent="AppTheme">
|
||||
@ -14,7 +15,7 @@
|
||||
<item name="android:textColor">@color/textPrimaryLight</item>
|
||||
<item name="android:textColorPrimary">@color/textPrimaryLight</item>
|
||||
<item name="android:textColorHint">@color/textSecondaryLight</item>
|
||||
<item name="textBackground">@color/textBackgroundLight</item>
|
||||
<item name="shapeTextBackground">@color/textBackgroundLight</item>
|
||||
<item name="iconColor">@color/iconColorLight</item>
|
||||
<item name="buttonBackground">@color/buttonBackgroundLight</item>
|
||||
<item name="md_background_color">@color/themeSecondaryLight</item>
|
||||
@ -32,7 +33,7 @@
|
||||
<item name="android:textColor">@color/textPrimaryDark</item>
|
||||
<item name="android:textColorPrimary">@color/textPrimaryDark</item>
|
||||
<item name="android:textColorHint">@color/textSecondaryDark</item>
|
||||
<item name="textBackground">@color/textBackgroundDark</item>
|
||||
<item name="shapeTextBackground">@color/textBackgroundDark</item>
|
||||
<item name="iconColor">@color/iconColorDark</item>
|
||||
<item name="buttonBackground">@color/buttonBackgroundDark</item>
|
||||
<item name="md_background_color">@color/themeSecondaryDark</item>
|
||||
@ -65,4 +66,9 @@
|
||||
<item name="cornerSize">5dp</item>
|
||||
</style>
|
||||
|
||||
<!-- popup menus -->
|
||||
<style name="Widget.App.PopupMenu" parent="Widget.MaterialComponents.PopupMenu">
|
||||
<item name="android:popupBackground">?themeSecondary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -1,12 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.4.31"
|
||||
ext.kotlin_version = "1.6.0"
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.2'
|
||||
classpath 'com.android.tools.build:gradle:7.0.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
@ -17,7 +17,7 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
|
1
fastlane/metadata/android/de/changelogs/4100.txt
Normal file
@ -0,0 +1 @@
|
||||
* Ein Fehler beim laden einiger Serien wurde behoben (#36)
|
5
fastlane/metadata/android/de/changelogs/4200.txt
Normal file
@ -0,0 +1,5 @@
|
||||
* Entwickleroptionen
|
||||
* Export/Import für "Meine Liste"
|
||||
* Der Picture in Picture Modus hat nun Controlls (#35)
|
||||
* Teapod stürtzt nicht mehr ab, wenn ein Element aus "Meine List" nicht geladen werden konnte (#42)
|
||||
* Staffel-Informationen im Title werden bei der Suche in tmdb ignoriert (#43)
|
@ -1,6 +1,6 @@
|
||||
Teapod ist eine inoffizielle App für Anime-on-Demand (AoD).
|
||||
|
||||
* Schau dir alle Title von AoD auf deinem Android Gerät an
|
||||
* Schau dir alle Titel von AoD auf deinem Android Gerät an
|
||||
* Nativer Player auf Basis des ExoPayers
|
||||
* Bevorzuge die OmU Version über die App-Einstellungen
|
||||
* Speicher deine lieblings Anime in "Meine Liste"
|
||||
|
After Width: | Height: | Size: 401 KiB |
After Width: | Height: | Size: 419 KiB |
After Width: | Height: | Size: 393 KiB |
After Width: | Height: | Size: 261 KiB |
1
fastlane/metadata/android/en-US/changelogs/4100.txt
Normal file
@ -0,0 +1 @@
|
||||
* fixed a issue where some tv shows could not be loaded (#36)
|
5
fastlane/metadata/android/en-US/changelogs/4200.txt
Normal file
@ -0,0 +1,5 @@
|
||||
* Developer options
|
||||
* Export/Import for "My List"
|
||||
* The Picture in Picture Modus now has Controlls (#35)
|
||||
* Teapod deosn't crash, if a element from "My List" could not be loaded (#42)
|
||||
* Season-Information in titles will be ignored, when searching in tmdb (#43)
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
21
gradlew.bat
vendored
@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@ -54,7 +54,7 @@ goto fail
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
@ -64,21 +64,6 @@ echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|