Fixing padding, using unread badge setting againpull/3117/head
parent
214008ac5c
commit
0bc81a8237
@ -0,0 +1,63 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||
import kotlinx.android.synthetic.main.unread_download_badge.view.*
|
||||
|
||||
class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null):
|
||||
MaterialCardView(context, attrs) {
|
||||
|
||||
fun setUnreadDownload(unread: Int, downloads: Int) {
|
||||
// Update the unread count and its visibility.
|
||||
with(unread_text) {
|
||||
text = if (unread == -1) "0" else unread.toString()
|
||||
setTextColor(if (unread == -1) context.getResourceColor(android.R.attr.colorAccent)
|
||||
else Color.WHITE)
|
||||
visibility = when {
|
||||
unread > 0 || unread == -1 -> View.VISIBLE
|
||||
else -> View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
// Update the download count or local status and its visibility.
|
||||
with(download_text) {
|
||||
visibility = if (downloads == -2 || downloads > 0) View.VISIBLE else View.GONE
|
||||
text = if (downloads == -2)
|
||||
resources.getString(R.string.local_source_badge)
|
||||
else downloads.toString()
|
||||
}
|
||||
|
||||
// Show the bade card if unread or downloads exists
|
||||
badge_view.visibility = if (download_text.visibility == View.VISIBLE || unread_text
|
||||
.visibility != View.GONE) View.VISIBLE else View.GONE
|
||||
|
||||
// Show the angles divider if both unread and downloads exists
|
||||
unread_angle.visibility = if (download_text.visibility == View.VISIBLE && unread_text
|
||||
.visibility != View.GONE) View.VISIBLE else View.GONE
|
||||
|
||||
if (unread_angle.visibility == View.VISIBLE) {
|
||||
download_text.updatePaddingRelative(end = 8.dpToPx)
|
||||
unread_text.updatePaddingRelative(start = 2.dpToPx)
|
||||
}
|
||||
else {
|
||||
download_text.updatePaddingRelative(end = 5.dpToPx)
|
||||
unread_text.updatePaddingRelative(start = 5.dpToPx)
|
||||
}
|
||||
}
|
||||
|
||||
fun setInLibrary(inLibrary: Boolean) {
|
||||
badge_view.visibility = if (inLibrary) View.VISIBLE else View.GONE
|
||||
unread_angle.visibility = View.GONE
|
||||
unread_text.updatePaddingRelative(start = 5.dpToPx)
|
||||
unread_text.visibility = if (inLibrary) View.VISIBLE else View.GONE
|
||||
unread_text.text = resources.getText(R.string.in_library)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<eu.kanade.tachiyomi.ui.library.LibraryBadge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/badge_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="10dp"
|
||||
app:cardElevation="5dp"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/download_text"
|
||||
style="@style/TextAppearance.Regular.Caption.Light"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/pale_green"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:textColor="@color/md_black_1000"
|
||||
android:textSize="13sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="1"
|
||||
tools:paddingEnd="8dp"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/unread_angle"
|
||||
android:layout_width="10dp"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_height="0dp"
|
||||
android:src="@drawable/unread_angled_badge"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/unread_text"
|
||||
app:layout_constraintEnd_toStartOf="@id/unread_text"
|
||||
app:layout_constraintTop_toTopOf="@+id/unread_text" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/unread_text"
|
||||
style="@style/TextAppearance.Regular.Caption.Light"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/colorAccent"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:textColor="@color/md_white_1000"
|
||||
android:textSize="13sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/download_text"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/download_text"
|
||||
app:layout_constraintTop_toTopOf="@+id/download_text"
|
||||
tools:text="20"
|
||||
tools:visibility="visible"
|
||||
tools:paddingStart="2dp"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.kanade.tachiyomi.ui.library.LibraryBadge>
|
Loading…
Reference in new issue