make versions in DataTypes -> Episodes -> Episode nullable since it is in fact nullable

This commit is contained in:
Jannik 2023-04-16 16:24:28 +02:00
parent cf02bee7d4
commit 4bceacf75c
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
6 changed files with 29 additions and 27 deletions

View File

@ -34,7 +34,6 @@ import io.ktor.http.*
import io.ktor.serialization.* import io.ktor.serialization.*
import io.ktor.serialization.kotlinx.json.* import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@ -149,7 +148,7 @@ object Crunchyroll {
} }
return@coroutineScope (Dispatchers.IO) { return@coroutineScope (Dispatchers.IO) {
val response: T = client.request(url) { val response = client.request(url) {
method = httpMethod method = httpMethod
header("Authorization", "${token.tokenType} ${token.accessToken}") header("Authorization", "${token.tokenType} ${token.accessToken}")
params.forEach { params.forEach {
@ -161,9 +160,9 @@ object Crunchyroll {
setBody(bodyObject) setBody(bodyObject)
contentType(ContentType.Application.Json) contentType(ContentType.Application.Json)
} }
}.body() }
response response.body<T>()
} }
} }
@ -389,7 +388,7 @@ object Crunchyroll {
return try { return try {
requestGet(seriesEndpoint, parameters) requestGet(seriesEndpoint, parameters)
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in series().", ex) Log.e(TAG, "Exception in series() for id $seriesId.", ex)
NoneSeries NoneSeries
} }
} }
@ -418,7 +417,7 @@ object Crunchyroll {
Log.e(TAG, "JsonConvertException in upNextSeries() with seriesId=$seriesId", ex) Log.e(TAG, "JsonConvertException in upNextSeries() with seriesId=$seriesId", ex)
NoneUpNextSeriesList NoneUpNextSeriesList
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in upNextSeries().", ex) Log.e(TAG, "Exception in upNextSeries() for seriesId $seriesId.", ex)
NoneUpNextSeriesList NoneUpNextSeriesList
} }
} }
@ -439,7 +438,7 @@ object Crunchyroll {
return try { return try {
requestGet(seasonsEndpoint, parameters) requestGet(seasonsEndpoint, parameters)
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in seasons().", ex) Log.e(TAG, "Exception in seasons() for seriesId $seriesId.", ex)
NoneSeasons NoneSeasons
} }
} }
@ -460,7 +459,7 @@ object Crunchyroll {
return try { return try {
requestGet(episodesEndpoint, parameters) requestGet(episodesEndpoint, parameters)
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in episodes().", ex) Log.e(TAG, "Exception in episodes() for seasonId $seasonId.", ex)
NoneEpisodes NoneEpisodes
} }
} }
@ -480,7 +479,7 @@ object Crunchyroll {
return try { return try {
requestGet(url, parameters) requestGet(url, parameters)
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in streams().", ex) Log.e(TAG, "Exception in streams() with url $url.", ex)
NoneStreams NoneStreams
} }
} }
@ -512,7 +511,7 @@ object Crunchyroll {
(requestGet(watchlistSeriesEndpoint, parameters) as Collection2<IsWatchlistItem>) (requestGet(watchlistSeriesEndpoint, parameters) as Collection2<IsWatchlistItem>)
.total == 1 .total == 1
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in isWatchlist() with seriesId = $seriesId", ex) Log.e(TAG, "Exception in isWatchlist() with seriesId $seriesId", ex)
false false
} }
} }
@ -536,7 +535,7 @@ object Crunchyroll {
try { try {
requestPost(watchlistPostEndpoint, parameters, json) requestPost(watchlistPostEndpoint, parameters, json)
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in postWatchlist() with seriesId = $seriesId", ex) Log.e(TAG, "Exception in postWatchlist() with seriesId $seriesId", ex)
} }
} }
@ -555,7 +554,7 @@ object Crunchyroll {
try { try {
requestDelete(watchlistDeleteEndpoint, parameters) requestDelete(watchlistDeleteEndpoint, parameters)
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(TAG, "Exception in deleteWatchlist() with seriesId = $seriesId", ex) Log.e(TAG, "Exception in deleteWatchlist() with seriesId $seriesId", ex)
} }
} }
@ -575,7 +574,6 @@ object Crunchyroll {
"locale" to Preferences.preferredSubtitleLocale.toLanguageTag() "locale" to Preferences.preferredSubtitleLocale.toLanguageTag()
) )
return try { return try {
requestGet(playheadsEndpoint, parameters) requestGet(playheadsEndpoint, parameters)
} catch (ex: Exception) { } catch (ex: Exception) {

View File

@ -302,7 +302,7 @@ data class Episode(
@SerialName("is_dubbed") val isDubbed: Boolean, @SerialName("is_dubbed") val isDubbed: Boolean,
@SerialName("images") val images: Thumbnail, @SerialName("images") val images: Thumbnail,
@SerialName("duration_ms") val durationMs: Int, @SerialName("duration_ms") val durationMs: Int,
@SerialName("versions") val versions: List<Version>, @SerialName("versions") val versions: List<Version>? = null,
@SerialName("streams_link") val streamsLink: String, @SerialName("streams_link") val streamsLink: String,
) )

View File

@ -157,9 +157,9 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
if (newAudioLocale != currentAudioLocale) { if (newAudioLocale != currentAudioLocale) {
currentAudioLocale = newAudioLocale currentAudioLocale = newAudioLocale
currentVersion = currentEpisode.versions.firstOrNull { currentVersion = currentEpisode.versions?.firstOrNull {
it.audioLocale == currentAudioLocale.toLanguageTag() it.audioLocale == currentAudioLocale.toLanguageTag()
} ?: currentEpisode.versions.first() } ?: currentEpisode.versions?.first() ?: NoneVersion
viewModelScope.launch { viewModelScope.launch {
currentStreams = Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID) currentStreams = Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID)
@ -223,14 +223,18 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
joinAll( joinAll(
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
currentVersion = if (Preferences.preferSubbed) { currentVersion = if (Preferences.preferSubbed) {
currentEpisode.versions.first { it.original } currentEpisode.versions?.first { it.original } ?: NoneVersion
} else { } else {
currentEpisode.versions currentEpisode.versions?.firstOrNull { it.audioLocale == currentAudioLocale.toLanguageTag() }
.firstOrNull { it.audioLocale == currentAudioLocale.toLanguageTag() } ?: currentEpisode.versions?.first() ?: NoneVersion
?: currentEpisode.versions.first()
} }
currentStreams = Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID) // get the current streams object, if no version is set, use streamsLink
currentStreams = if (currentVersion != NoneVersion) {
Crunchyroll.streamsFromMediaGUID(currentVersion.mediaGUID)
} else {
Crunchyroll.streams(currentEpisode.streamsLink)
}
Log.d(classTag, currentVersion.toString()) Log.d(classTag, currentVersion.toString())
}, },
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {

View File

@ -64,7 +64,7 @@ class LanguageSettingsDialogFragment : DialogFragment() {
val currentAudioLocal = Locale.forLanguageTag(model.currentVersion.audioLocale) val currentAudioLocal = Locale.forLanguageTag(model.currentVersion.audioLocale)
var selectedAudioView: TextView? = null var selectedAudioView: TextView? = null
model.currentEpisode.versions.forEach { version -> model.currentEpisode.versions?.forEach { version ->
val locale = Locale.forLanguageTag(version.audioLocale) val locale = Locale.forLanguageTag(version.audioLocale)
val audioView = addLanguage(binding.linearAudioLanguages, locale) { v -> val audioView = addLanguage(binding.linearAudioLanguages, locale) { v ->
selectedAudioLocale = locale selectedAudioLocale = locale

View File

@ -8,7 +8,8 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -572,9 +573,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/info_about_desc" android:text="@string/info_about_desc" />
/>
<!-- android:textColor="?textSecondary" -->
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -9,7 +9,8 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"