Skip to content

Commit 555d977

Browse files
authored
Added a rating preview on the poster (#1745)
1 parent ed37c07 commit 555d977

10 files changed

Lines changed: 38 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface SyncAPI : OAuth2API {
5151
override var quality: SearchQuality? = null,
5252
override var posterHeaders: Map<String, String>? = null,
5353
override var id: Int? = null,
54+
override var score: Score? = null,
5455
) : SearchResponse
5556

5657
abstract class AbstractSyncStatus {
@@ -163,7 +164,7 @@ interface SyncAPI : OAuth2API {
163164
val releaseDate: Date?,
164165
override var id: Int? = null,
165166
val plot : String? = null,
166-
val rating: Score? = null,
167+
override var score: Score? = null,
167168
val tags: List<String>? = null
168169
) : SearchResponse
169170
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,7 +2655,7 @@ class ResultViewModel2 : ViewModel() {
26552655
).apply {
26562656
if (searchResponse is SyncAPI.LibraryItem) {
26572657
this.plot = searchResponse.plot
2658-
this.score = Score.from100(searchResponse.personalRating) ?: searchResponse.rating
2658+
this.score = Score.from100(searchResponse.personalRating) ?: searchResponse.score
26592659
this.tags = searchResponse.tags
26602660
}
26612661
if (searchResponse is DataStoreHelper.BookmarkedData) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ object SearchResultBuilder {
9090
val ratingText = ((card.personalRating ?: 0).toDouble() / 10).toString()
9191
.replace(".0", "")
9292

93+
rating?.text = ratingText
94+
}
95+
} else {
96+
val ratingText = card.score?.toString(10, 1)
97+
val showRating = (ratingText ?: "") != ""
98+
rating?.isVisible = showRating
99+
if(showRating) {
93100
rating?.text = ratingText
94101
}
95102
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lagradost.cloudstream3.ui.search
22

3+
import com.lagradost.cloudstream3.Score
34
import com.lagradost.cloudstream3.SearchQuality
45
import com.lagradost.cloudstream3.SearchResponse
56
import com.lagradost.cloudstream3.TvType
@@ -15,5 +16,6 @@ class SyncSearchViewModel {
1516
override var id: Int?,
1617
override var quality: SearchQuality? = null,
1718
override var posterHeaders: Map<String, String>? = null,
19+
override var score: Score? = null,
1820
) : SearchResponse
1921
}

app/src/main/java/com/lagradost/cloudstream3/utils/DataStoreHelper.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ object DataStoreHelper {
259259
@JsonProperty("quality") override var quality: SearchQuality?,
260260
@JsonProperty("posterHeaders") override var posterHeaders: Map<String, String>?,
261261
@JsonProperty("plot") open val plot: String? = null,
262-
@JsonProperty("score") open var score: Score? = null,
262+
@JsonProperty("score") override var score: Score? = null,
263263
@JsonProperty("tags") open val tags: List<String>? = null,
264264
) : SearchResponse {
265265
@JsonProperty("rating", access = JsonProperty.Access.WRITE_ONLY)
@@ -326,7 +326,7 @@ object DataStoreHelper {
326326
year?.toYear(),
327327
this.id,
328328
plot = this.plot,
329-
rating = this.score,
329+
score = this.score,
330330
tags = this.tags
331331
)
332332
}
@@ -379,7 +379,7 @@ object DataStoreHelper {
379379
year?.toYear(),
380380
this.id,
381381
plot = this.plot,
382-
rating = this.score,
382+
score = this.score,
383383
tags = this.tags
384384
)
385385
}
@@ -432,7 +432,7 @@ object DataStoreHelper {
432432
year?.toYear(),
433433
this.id,
434434
plot = this.plot,
435-
rating = this.score,
435+
score = this.score,
436436
tags = this.tags
437437
)
438438
}
@@ -452,6 +452,7 @@ object DataStoreHelper {
452452
@JsonProperty("isFromDownload") val isFromDownload: Boolean,
453453
@JsonProperty("quality") override var quality: SearchQuality? = null,
454454
@JsonProperty("posterHeaders") override var posterHeaders: Map<String, String>? = null,
455+
@JsonProperty("score") override var score: Score? = null,
455456
) : SearchResponse
456457

457458
/**

app/src/main/res/drawable/rating_bg_color.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<solid android:color="?attr/colorPrimary"/>
44
<corners android:radius="@dimen/rounded_image_radius"/>
55
<!-- <stroke android:color="@color/subColor" android:width="2dp"/>-->
6-
</shape>
6+
</shape>

app/src/main/res/layout/home_result_grid.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
style="@style/SubButton"
111111
android:layout_gravity="end" />
112112

113+
<TextView
114+
android:id="@+id/text_rating"
115+
style="@style/RatingButton"
116+
android:layout_gravity="end"
117+
tools:text="7.7" />
118+
113119
<TextView
114120
android:id="@+id/text_flag"
115121
style="@style/SearchBox"

app/src/main/res/layout/home_result_grid_expanded.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
style="@style/SubButton"
110110
android:layout_gravity="end" />
111111

112+
<TextView
113+
android:id="@+id/text_rating"
114+
style="@style/RatingButton"
115+
android:layout_gravity="end"
116+
tools:text="7.7" />
117+
112118
<TextView
113119
android:id="@+id/text_flag"
114120
style="@style/SearchBox"

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
<item name="android:background">@drawable/rating_bg_color</item>
160160
<item name="drawableTint">?attr/colorOnPrimary</item>
161161
<item name="android:textColor">?attr/colorOnPrimary</item>
162-
<item name="drawableStartCompat">@drawable/ic_baseline_star_24</item>
162+
<!--<item name="drawableStartCompat">@drawable/ic_baseline_star_24</item>-->
163163
</style>
164164

165165
<style name="TypeButton" parent="@style/SearchBox">

library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ interface SearchResponse {
11921192
var posterHeaders: Map<String, String>?
11931193
var id: Int?
11941194
var quality: SearchQuality?
1195+
var score: Score?
11951196
}
11961197

11971198
fun MainAPI.newTorrentSearchResponse(
@@ -1349,6 +1350,7 @@ constructor(
13491350
override var id: Int? = null,
13501351
override var quality: SearchQuality? = null,
13511352
override var posterHeaders: Map<String, String>? = null,
1353+
override var score: Score? = null,
13521354
) : SearchResponse
13531355

13541356
fun AnimeSearchResponse.addDubStatus(status: DubStatus, episodes: Int? = null) {
@@ -1408,6 +1410,7 @@ constructor(
14081410
override var id: Int? = null,
14091411
override var quality: SearchQuality? = null,
14101412
override var posterHeaders: Map<String, String>? = null,
1413+
override var score: Score? = null,
14111414
) : SearchResponse
14121415

14131416
/** Data class of [SearchResponse] interface for Movies.
@@ -1425,7 +1428,8 @@ constructor(
14251428
var year: Int? = null,
14261429
override var id: Int? = null,
14271430
override var quality: SearchQuality? = null,
1428-
override var posterHeaders: Map<String, String>? = null
1431+
override var posterHeaders: Map<String, String>? = null,
1432+
override var score: Score? = null,
14291433
) : SearchResponse
14301434

14311435
/** Data class of [SearchResponse] interface for Live streams.
@@ -1444,6 +1448,7 @@ constructor(
14441448
override var quality: SearchQuality? = null,
14451449
override var posterHeaders: Map<String, String>? = null,
14461450
var lang: String? = null,
1451+
override var score: Score? = null,
14471452
) : SearchResponse
14481453

14491454
/** Data class of [SearchResponse] interface for Tv series.
@@ -1463,6 +1468,7 @@ constructor(
14631468
override var id: Int? = null,
14641469
override var quality: SearchQuality? = null,
14651470
override var posterHeaders: Map<String, String>? = null,
1471+
override var score: Score? = null,
14661472
) : SearchResponse
14671473

14681474
/** Data class of Trailer data.

0 commit comments

Comments
 (0)