Skip to content

Commit 3b28313

Browse files
authored
Enhance Hero Card with Dynamic Rating Badge and Larger Layout (#2409)
1 parent 91983b3 commit 3b28313

File tree

8 files changed

+122
-11
lines changed

8 files changed

+122
-11
lines changed

app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,41 @@ class HomeParentItemAdapterPreview(
344344
homePreviewDescription.text =
345345
item.plot?.html() ?: ""
346346

347+
homePreviewDescription.text =
348+
item.plot?.html() ?: ""
349+
350+
homePreviewScore.text = item.score?.let { score ->
351+
homePreviewScore.context.getString(R.string.extension_rating, score.toString())
352+
} ?: ""
353+
354+
item.score?.toString()?.toDoubleOrNull()?.let { rating ->
355+
val color = when {
356+
rating < 5.0 -> android.graphics.Color.parseColor("#eb2f2f") // Red
357+
rating < 8.0 -> android.graphics.Color.parseColor("#eda009") // Yellow
358+
else -> android.graphics.Color.parseColor("#3bb33b") // Green
359+
}
360+
homePreviewScore.backgroundTintList = android.content.res.ColorStateList.valueOf(color)
361+
homePreviewScore.setTextColor(android.graphics.Color.WHITE)
362+
}
363+
364+
homePreviewScore.isGone = item.score == null
365+
366+
homePreviewYear.text = item.year?.toString() ?: ""
367+
homePreviewYear.isGone = item.year == null
368+
369+
homePreviewDuration.text = item.duration?.let { min ->
370+
homePreviewDuration.context.getString(R.string.duration_format, min)
371+
} ?: ""
372+
homePreviewDuration.isGone = item.duration == null
373+
374+
val castText = item.actors?.take(3)?.mapNotNull { it.actor.name }?.joinToString(", ")
375+
if (!castText.isNullOrBlank()) {
376+
homePreviewCast.text = homePreviewCast.context.getString(R.string.cast_format, castText)
377+
homePreviewCast.isVisible = true
378+
} else {
379+
homePreviewCast.isVisible = false
380+
}
381+
347382
homePreviewText.text = item.name.html()
348383
populateChips(
349384
homePreviewTags,
@@ -646,6 +681,12 @@ class HomeParentItemAdapterPreview(
646681
(binding as? FragmentHomeHeadTvBinding)?.apply {
647682
homePreviewInfoBtt.isVisible = true
648683
}
684+
// Explicitly bind the current item to ensure instant loading
685+
val currentPos = previewViewpager.currentItem
686+
val item = preview.value.second.getOrNull(currentPos)
687+
if (item != null) {
688+
onSelect(item, currentPos)
689+
}
649690
}
650691

651692
else -> {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<solid android:color="#F5C518" />
5+
<corners android:radius="4dp" />
6+
<padding
7+
android:bottom="2dp"
8+
android:left="4dp"
9+
android:right="4dp"
10+
android:top="2dp" />
11+
</shape>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
<shape>
55
<gradient
66
android:angle="90"
7-
android:startColor="#000000"
7+
android:startColor="#FF000000"
88
android:centerColor="#00000000"
99
android:endColor="#00000000"
10-
android:centerY="0.7"
10+
android:centerY="0.3"
1111
/>
1212
</shape>
1313
</item>
1414
<item>
1515
<shape>
1616
<gradient
1717
android:angle="270"
18-
android:startColor="#000000"
18+
android:startColor="#66000000"
1919
android:centerColor="#00000000"
2020
android:endColor="#00000000"
21-
android:centerY="0.7"
21+
android:centerY="0.5"
2222
/>
2323
</shape>
2424
</item>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android">
33
<solid android:color="?attr/colorPrimary"/>
4-
<corners android:radius="@dimen/rounded_image_radius"/>
4+
<corners android:radius="4dp"/>
55
<!-- <stroke android:color="@color/subColor" android:width="2dp"/>-->
66
</shape>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
android:orientation="vertical">
2323

2424
<!-- android:id="@+id/subs_settings" android:foreground="?android:attr/selectableItemBackgroundBorderless"
25+
-->
26+
<!--
2527
-->
2628
<LinearLayout
2729
android:layout_width="match_parent"

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<androidx.cardview.widget.CardView
3434
android:id="@+id/home_preview_info_btt"
3535
android:layout_width="match_parent"
36-
android:layout_height="300dp"
36+
android:layout_height="400dp"
3737
android:layout_marginStart="10dp"
3838
android:layout_marginTop="10dp"
3939
android:layout_marginEnd="10dp"
@@ -61,11 +61,12 @@
6161
android:id="@+id/home_preview_viewpager_text"
6262
android:layout_width="match_parent"
6363
android:layout_height="match_parent"
64+
android:background="@drawable/player_gradient_tv"
6465
android:layout_gravity="bottom"
6566
android:layout_marginStart="@dimen/navbar_width"
6667
android:gravity="bottom"
6768
android:orientation="vertical"
68-
android:padding="10dp">
69+
android:padding="20dp">
6970

7071
<ImageView
7172
android:id="@+id/home_background_poster_watermark_badge_holder"
@@ -81,12 +82,52 @@
8182
android:id="@+id/home_preview_text"
8283
android:layout_width="match_parent"
8384
android:layout_height="wrap_content"
85+
android:layout_marginTop="10dp"
8486
android:ellipsize="end"
8587
android:maxLines="1"
8688
android:textSize="25sp"
8789
android:textStyle="bold"
8890
tools:text="The Perfect Run" />
8991

92+
<LinearLayout
93+
android:layout_width="match_parent"
94+
android:layout_height="wrap_content"
95+
android:orientation="horizontal"
96+
android:layout_marginTop="10dp"
97+
android:layout_marginBottom="4dp"
98+
android:gravity="center_vertical">
99+
100+
<TextView
101+
android:id="@+id/home_preview_score"
102+
android:layout_width="wrap_content"
103+
android:layout_height="wrap_content"
104+
android:background="@drawable/rating_bg_color"
105+
android:textColor="@color/white"
106+
android:textStyle="bold"
107+
android:paddingStart="6dp"
108+
android:paddingEnd="6dp"
109+
android:paddingTop="2dp"
110+
android:paddingBottom="2dp"
111+
android:layout_marginEnd="12dp"
112+
tools:text="IMDb : 8.5" />
113+
114+
<TextView
115+
android:id="@+id/home_preview_year"
116+
android:layout_width="wrap_content"
117+
android:layout_height="wrap_content"
118+
android:textColor="@color/gray_200"
119+
android:layout_marginEnd="12dp"
120+
tools:text="2021" />
121+
122+
<TextView
123+
android:id="@+id/home_preview_duration"
124+
android:layout_width="wrap_content"
125+
android:layout_height="wrap_content"
126+
android:textColor="@color/gray_200"
127+
tools:text="120m" />
128+
129+
</LinearLayout>
130+
90131
<TextView
91132
android:id="@+id/home_preview_description"
92133
android:layout_width="match_parent"
@@ -97,6 +138,17 @@
97138
android:textSize="15sp"
98139
tools:text="very nice tv series" />
99140

141+
<TextView
142+
android:id="@+id/home_preview_cast"
143+
android:layout_width="match_parent"
144+
android:layout_height="wrap_content"
145+
android:ellipsize="end"
146+
android:maxLines="1"
147+
android:textSize="13sp"
148+
android:textColor="@color/gray_400"
149+
android:paddingBottom="5dp"
150+
tools:text="Cast: Actor One, Actor Two" />
151+
100152
<com.google.android.material.chip.ChipGroup
101153
android:id="@+id/home_preview_tags"
102154
style="@style/ChipParent"

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
tools:src="@drawable/example_poster" />
1616

1717
<View
18-
android:id="@+id/title_shadow"
18+
android:id="@+id/home_preview_dimmer"
1919
android:layout_width="match_parent"
20-
android:layout_height="300dp"
21-
android:layout_gravity="bottom"
22-
android:background="@drawable/background_shadow" />
20+
android:layout_height="match_parent"
21+
android:background="#000000"
22+
android:alpha="0.6" />
23+
24+
2325
</FrameLayout>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
<color name="white">#FFF</color>
2323
<color name="black">#000</color>
24+
<color name="gray_200">#EEEEEE</color>
25+
<color name="gray_400">#BDBDBD</color>
2426

2527
<color name="whiteText">#FFF</color>
2628
<color name="blackText">#000</color>
@@ -35,6 +37,7 @@
3537
<color name="subColorBg">#F53B66</color>
3638
<color name="typeColorText">#BEC8FF</color>
3739
<color name="typeColorBg">#3700B3</color>
40+
3841
<!--
3942
<color name="ratingColor">#4C3115</color>
4043
<color name="ratingColorBg">#FFA662</color>

0 commit comments

Comments
 (0)