Skip to content

Commit 8b6d0ec

Browse files
authored
Added new class Score (#1748)
1 parent 1226b01 commit 8b6d0ec

19 files changed

Lines changed: 512 additions & 133 deletions

File tree

app/src/main/java/com/lagradost/cloudstream3/syncproviders/SyncApi.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ interface SyncAPI : OAuth2API {
8080
var totalEpisodes: Int? = null,
8181

8282
var title: String? = null,
83-
/**1-1000*/
84-
var publicScore: Int? = null,
83+
var publicScore: Score? = null,
8584
/**In minutes*/
8685
var duration: Int? = null,
8786
var synopsis: String? = null,
@@ -154,7 +153,7 @@ interface SyncAPI : OAuth2API {
154153
val episodesCompleted: Int?,
155154
val episodesTotal: Int?,
156155
/** Out of 100 */
157-
val personalRating: Int?,
156+
val personalRating: Int?, // TODO also update this to Score
158157
val lastUpdatedUnixTime: Long?,
159158
override val apiName: String,
160159
override var type: TvType?,
@@ -164,7 +163,7 @@ interface SyncAPI : OAuth2API {
164163
val releaseDate: Date?,
165164
override var id: Int? = null,
166165
val plot : String? = null,
167-
val rating: Int? = null,
166+
val rating: Score? = null,
168167
val tags: List<String>? = null
169168
) : SearchResponse
170169
}

app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/AniListApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
141141
}
142142
)
143143
},
144-
publicScore = season.averageScore?.times(100),
144+
publicScore = Score.from100(season.averageScore),
145145
recommendations = season.recommendations?.edges?.mapNotNull { rec ->
146146
val recMedia = rec.node.mediaRecommendation
147147
SyncAPI.SyncSearchResult(

app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/MALApi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
88
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
99
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
1010
import com.lagradost.cloudstream3.R
11+
import com.lagradost.cloudstream3.Score
1112
import com.lagradost.cloudstream3.ShowStatus
1213
import com.lagradost.cloudstream3.TvType
1314
import com.lagradost.cloudstream3.app
@@ -214,7 +215,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
214215
id = internalId.toString(),
215216
totalEpisodes = malAnime.numEpisodes,
216217
title = malAnime.title,
217-
publicScore = malAnime.mean?.toFloat()?.times(1000)?.toInt(),
218+
publicScore = Score.from10(malAnime.mean),
218219
duration = malAnime.averageEpisodeDuration,
219220
synopsis = malAnime.synopsis,
220221
airStatus = when (malAnime.status) {

app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class EpisodeAdapter(
188188
season = card.season,
189189
id = card.id,
190190
parentId = card.parentId,
191-
rating = card.rating,
191+
score = card.score,
192192
description = card.description,
193193
cacheTime = System.currentTimeMillis(),
194194
), null
@@ -230,9 +230,9 @@ class EpisodeAdapter(
230230

231231
episodePoster.loadImage(card.poster)
232232

233-
if (card.rating != null) {
233+
if (card.score != null) {
234234
episodeRating.text = episodeRating.context?.getString(R.string.rated_format)
235-
?.format(card.rating.toFloat() / 10f)
235+
?.format(card.score.toFloat(10)) // TODO Change rated_format to use card.score.toString()
236236
} else {
237237
episodeRating.text = ""
238238
}
@@ -347,7 +347,7 @@ class EpisodeAdapter(
347347
season = card.season,
348348
id = card.id,
349349
parentId = card.parentId,
350-
rating = card.rating,
350+
score = card.score,
351351
description = card.description,
352352
cacheTime = System.currentTimeMillis(),
353353
), null

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment
55
import androidx.preference.PreferenceManager
66
import com.lagradost.cloudstream3.DubStatus
77
import com.lagradost.cloudstream3.R
8+
import com.lagradost.cloudstream3.Score
89
import com.lagradost.cloudstream3.SearchResponse
910
import com.lagradost.cloudstream3.TvType
1011
import com.lagradost.cloudstream3.ui.result.EpisodeAdapter.Companion.getPlayerAction
@@ -39,7 +40,7 @@ data class ResultEpisode(
3940
val index: Int,
4041
val position: Long, // time in MS
4142
val duration: Long, // duration in MS
42-
val rating: Int?,
43+
val score: Score?,
4344
val description: String?,
4445
val isFiller: Boolean?,
4546
val tvType: TvType,
@@ -81,7 +82,7 @@ fun buildResultEpisode(
8182
apiName: String,
8283
id: Int,
8384
index: Int,
84-
rating: Int? = null,
85+
rating: Score? = null,
8586
description: String? = null,
8687
isFiller: Boolean? = null,
8788
tvType: TvType,

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,8 @@ open class ResultFragmentPhone : FullScreenPlayer() {
696696
season = null,
697697
id = ep.id,
698698
parentId = ep.id,
699-
rating = null,
700-
description = null,
699+
score = ep.score,
700+
description = ep.description,
701701
cacheTime = System.currentTimeMillis(),
702702
),
703703
null

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ fun LoadResponse.toResultData(repo: APIRepository): ResultData {
264264
),
265265
yearText = txt(year?.toString()),
266266
apiName = txt(apiName),
267-
ratingText = rating?.div(1000f)
268-
?.let { if (it <= 0.1f) null else txt(R.string.rating_format, it) },
267+
ratingText = score?.toStringNull(0.1, 10, 1, false, '.')
268+
?.let { txt(R.string.rating_format, it) },
269269
contentRatingText = txt(contentRating),
270270
vpnText = txt(
271271
when (repo.vpnStatus) {
@@ -738,7 +738,7 @@ class ResultViewModel2 : ViewModel() {
738738
season = episode.season,
739739
id = episode.id,
740740
parentId = parentId,
741-
rating = episode.rating,
741+
score = episode.score,
742742
description = episode.description,
743743
cacheTime = System.currentTimeMillis(),
744744
)
@@ -925,7 +925,7 @@ class ResultViewModel2 : ViewModel() {
925925
response.syncData,
926926
plot = response.plot,
927927
tags = response.tags,
928-
rating = response.rating
928+
score = response.score
929929
)
930930
)
931931
}
@@ -1022,7 +1022,7 @@ class ResultViewModel2 : ViewModel() {
10221022
response.year,
10231023
response.syncData,
10241024
plot = response.plot,
1025-
rating = response.rating,
1025+
score = response.score,
10261026
tags = response.tags
10271027
)
10281028
)
@@ -1093,7 +1093,7 @@ class ResultViewModel2 : ViewModel() {
10931093
response.year,
10941094
response.syncData,
10951095
plot = response.plot,
1096-
rating = response.rating,
1096+
score = response.score,
10971097
tags = response.tags
10981098
)
10991099
)
@@ -1404,7 +1404,7 @@ class ResultViewModel2 : ViewModel() {
14041404
},
14051405
isCasting = isCasting
14061406
)
1407-
} catch (e : CancellationException) {
1407+
} catch (e: CancellationException) {
14081408
// Do nothing
14091409
} catch (e: Exception) {
14101410
logError(e)
@@ -1660,13 +1660,14 @@ class ResultViewModel2 : ViewModel() {
16601660
// Show player selection dialog
16611661
val players = VideoClickActionHolder.getPlayers(ctx)
16621662
val options = mutableListOf<Pair<UiText, Int>>()
1663-
1663+
16641664
// Add internal player option
16651665
options.add(txt(R.string.episode_action_play_in_app) to ACTION_PLAY_EPISODE_IN_PLAYER)
1666-
1666+
16671667
// Add external player options
16681668
options.addAll(players.filter { it !is AlwaysAskAction }.map { player ->
1669-
player.name to (VideoClickActionHolder.uniqueIdToId(player.uniqueId()) ?: ACTION_PLAY_EPISODE_IN_PLAYER)
1669+
player.name to (VideoClickActionHolder.uniqueIdToId(player.uniqueId())
1670+
?: ACTION_PLAY_EPISODE_IN_PLAYER)
16701671
})
16711672

16721673
postPopup(
@@ -1723,7 +1724,7 @@ class ResultViewModel2 : ViewModel() {
17231724

17241725
if (meta != null) {
17251726
duration = duration ?: meta.duration
1726-
rating = rating ?: meta.publicScore
1727+
score = score ?: meta.publicScore
17271728
tags = tags ?: meta.genres
17281729
plot = if (plot.isNullOrBlank()) meta.synopsis else plot
17291730
posterUrl = posterUrl ?: meta.posterUrl ?: meta.backgroundPosterUrl
@@ -1942,8 +1943,8 @@ class ResultViewModel2 : ViewModel() {
19421943
return when (sorting) {
19431944
EpisodeSortType.NUMBER_ASC -> episodes.sortedBy { it.episode }
19441945
EpisodeSortType.NUMBER_DESC -> episodes.sortedByDescending { it.episode }
1945-
EpisodeSortType.RATING_HIGH_LOW -> episodes.sortedByDescending { it.rating ?: 0 }
1946-
EpisodeSortType.RATING_LOW_HIGH -> episodes.sortedBy { it.rating ?: 0 }
1946+
EpisodeSortType.RATING_HIGH_LOW -> episodes.sortedByDescending { it.score?.toDouble() ?: 0.0 }
1947+
EpisodeSortType.RATING_LOW_HIGH -> episodes.sortedBy { it.score?.toDouble() ?: 0.0 }
19471948
EpisodeSortType.DATE_NEWEST -> episodes.sortedByDescending { it.airDate }
19481949
EpisodeSortType.DATE_OLDEST -> episodes.sortedBy { it.airDate }
19491950
}
@@ -2022,7 +2023,7 @@ class ResultViewModel2 : ViewModel() {
20222023
return when (type) {
20232024
EpisodeSortType.NUMBER_ASC, EpisodeSortType.NUMBER_DESC -> true
20242025
EpisodeSortType.RATING_HIGH_LOW, EpisodeSortType.RATING_LOW_HIGH ->
2025-
episodes.any { it.rating != null }
2026+
episodes.any { it.score != null }
20262027

20272028
EpisodeSortType.DATE_NEWEST, EpisodeSortType.DATE_OLDEST ->
20282029
episodes.any { it.airDate != null }
@@ -2274,7 +2275,7 @@ class ResultViewModel2 : ViewModel() {
22742275
loadResponse.apiName,
22752276
id,
22762277
index,
2277-
i.rating,
2278+
i.score,
22782279
i.description,
22792280
fillers.getOrDefault(episode, false),
22802281
loadResponse.type,
@@ -2330,7 +2331,7 @@ class ResultViewModel2 : ViewModel() {
23302331
loadResponse.apiName,
23312332
id,
23322333
index,
2333-
episode.rating,
2334+
episode.score,
23342335
episode.description,
23352336
null,
23362337
loadResponse.type,
@@ -2620,7 +2621,7 @@ class ResultViewModel2 : ViewModel() {
26202621
override var posterUrl: String?,
26212622
override var year: Int? = null,
26222623
override var plot: String? = null,
2623-
override var rating: Int? = null,
2624+
override var score: Score? = null,
26242625
override var tags: List<String>? = null,
26252626
override var duration: Int? = null,
26262627
override var trailers: MutableList<TrailerData> = mutableListOf(),
@@ -2654,12 +2655,12 @@ class ResultViewModel2 : ViewModel() {
26542655
).apply {
26552656
if (searchResponse is SyncAPI.LibraryItem) {
26562657
this.plot = searchResponse.plot
2657-
this.rating = searchResponse.personalRating?.times(100) ?: searchResponse.rating
2658+
this.score = Score.from100(searchResponse.personalRating) ?: searchResponse.rating
26582659
this.tags = searchResponse.tags
26592660
}
26602661
if (searchResponse is DataStoreHelper.BookmarkedData) {
26612662
this.plot = searchResponse.plot
2662-
this.rating = searchResponse.rating
2663+
this.score = searchResponse.score
26632664
this.tags = searchResponse.tags
26642665
}
26652666
}

app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object SearchHelper {
3838
season = card.season,
3939
id = id,
4040
parentId = card.parentId ?: return,
41-
rating = null,
41+
score = null,
4242
description = null,
4343
cacheTime = System.currentTimeMillis(),
4444
)

0 commit comments

Comments
 (0)