mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: Repository item
This commit is contained in:
parent
22413f2943
commit
fc6331c3a1
50
src/main/kotlin/com/looker/droidify/ui/items/RepoItem.kt
Normal file
50
src/main/kotlin/com/looker/droidify/ui/items/RepoItem.kt
Normal file
@ -0,0 +1,50 @@
|
||||
package com.looker.droidify.ui.items
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import coil.load
|
||||
import com.looker.droidify.R
|
||||
import com.looker.droidify.databinding.ItemRepositoryXBinding
|
||||
import com.looker.droidify.entity.Repository
|
||||
import com.looker.droidify.utility.extension.resources.clear
|
||||
import com.looker.droidify.utility.extension.resources.getColorFromAttr
|
||||
import com.mikepenz.fastadapter.binding.AbstractBindingItem
|
||||
|
||||
class RepoItem(val item: Repository) :
|
||||
AbstractBindingItem<ItemRepositoryXBinding>() {
|
||||
override val type: Int
|
||||
get() = R.id.fastadapter_item
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater, parent: ViewGroup?)
|
||||
: ItemRepositoryXBinding = ItemRepositoryXBinding.inflate(inflater, parent, false)
|
||||
|
||||
override fun bindView(binding: ItemRepositoryXBinding, payloads: List<Any>) {
|
||||
val isEnabled = item.enabled
|
||||
val context = binding.repoItem.context
|
||||
|
||||
val textColor: ColorStateList = if (isEnabled)
|
||||
context.getColorFromAttr(R.attr.colorOnPrimaryContainer)
|
||||
else
|
||||
context.getColorFromAttr(R.attr.colorOnBackground)
|
||||
|
||||
binding.repoName.text = item.name
|
||||
binding.repoDescription.text = item.description.trim()
|
||||
|
||||
binding.repoItem.setCardBackgroundColor(
|
||||
if (item.enabled) context.getColorFromAttr(R.attr.colorPrimaryContainer)
|
||||
else context.getColorFromAttr(android.R.attr.colorBackground)
|
||||
)
|
||||
|
||||
binding.checkMark.apply {
|
||||
if (item.enabled) load(R.drawable.ic_check)
|
||||
else clear()
|
||||
}
|
||||
|
||||
textColor.let {
|
||||
binding.repoName.setTextColor(it)
|
||||
binding.repoDescription.setTextColor(it)
|
||||
binding.checkMark.imageTintList = it
|
||||
}
|
||||
}
|
||||
}
|
42
src/main/res/layout/item_repository_x.xml
Normal file
42
src/main/res/layout/item_repository_x.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<data>
|
||||
|
||||
</data>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/repoItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/shape_margin_medium">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:orientation="vertical"
|
||||
android:paddingEnd="48dp">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/repoName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?attr/textAppearanceTitleMedium" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/repoDescription"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true" />
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/checkMark"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="24dp" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</layout>
|
Loading…
x
Reference in New Issue
Block a user