Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : show favorite button in bottom dialog #858

Merged
merged 1 commit into from Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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