Skip to content

Commit

Permalink
feat : show favorite button in bottom dialog (#858)
Browse files Browse the repository at this point in the history
Co-authored-by: coxju <coxju>
  • Loading branch information
coxju committed Jan 10, 2024
1 parent 42fd0b5 commit 97ec98b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
29 changes: 29 additions & 0 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,35 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
}
}

observeNullable(viewModel.favoriteStatus) observeFavoriteStatus@{ isFavorite ->
resultviewPreviewFavorite.isVisible = isFavorite != null
if (isFavorite == null) return@observeFavoriteStatus

val drawable = if (isFavorite) {
R.drawable.ic_baseline_favorite_24
} else {
R.drawable.ic_baseline_favorite_border_24
}

resultviewPreviewFavorite.setImageResource(drawable)
}

resultviewPreviewFavorite.setOnClickListener{
viewModel.toggleFavoriteStatus(this@MainActivity) { newStatus: Boolean? ->
if (newStatus == null) return@toggleFavoriteStatus

val message = if (newStatus) {
R.string.favorite_added
} else {
R.string.favorite_removed
}

val name = (viewModel.page.value as? Resource.Success)?.value?.title
?: txt(R.string.no_data).asStringNull(this@MainActivity) ?: ""
showToast(txt(message, name), Toast.LENGTH_SHORT)
}
}

if (!isTvSettings()) // dont want this clickable on tv layout
resultviewPreviewDescription.setOnClickListener { view ->
view.context?.let { ctx ->
Expand Down
41 changes: 31 additions & 10 deletions app/src/main/res/layout/bottom_resultview_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,36 @@
android:layout_marginStart="10dp"
android:orientation="vertical">

<TextView
android:id="@+id/resultview_preview_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:textSize="16sp"

android:textStyle="bold"
tools:text="The Perfect Run">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

</TextView>
<TextView
android:id="@+id/resultview_preview_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:textSize="16sp"
android:layout_gravity="start|center_vertical"
android:textStyle="bold"
android:layout_marginEnd="25dp"
tools:text="The Perfect Run">

</TextView>

<ImageView
android:id="@+id/resultview_preview_favorite"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="end|center_vertical"

android:layout_margin="5dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:elevation="10dp"
android:nextFocusDown="@id/resultview_preview_bookmark"
android:src="@drawable/ic_baseline_favorite_border_24"
app:tint="?attr/textColor" />
</FrameLayout>

<com.lagradost.cloudstream3.widget.FlowLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -123,6 +142,7 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/resultview_preview_bookmark"
android:layout_weight="1"
android:nextFocusUp="@id/resultview_preview_favorite"
android:nextFocusRight="@id/resultview_preview_more_info"

tools:visibility="visible"
Expand All @@ -136,6 +156,7 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/resultview_preview_more_info"
android:layout_weight="1"
android:nextFocusUp="@id/resultview_preview_favorite"
android:nextFocusLeft="@id/resultview_preview_bookmark"

tools:visibility="visible"
Expand Down

0 comments on commit 97ec98b

Please sign in to comment.