Enhance the repository list view

main
Clément FRÉVILLE 2 years ago
parent 8f503b64a4
commit 1dd386c3d6

@ -12,10 +12,18 @@ class RepositoryListAdapter(private val dataSet: List<Repository>, private val o
class ViewHolder(view: View, private val onClick: (Repository) -> Unit) : RecyclerView.ViewHolder(view) {
private val repositoryNameView: TextView
private val repositoryDescriptionView: TextView
private val repositoryStarsView: TextView
private val repositoryLanguageView: TextView
private val repositoryForksView: TextView
private var currentRepository: Repository? = null
init {
repositoryNameView = view.findViewById(R.id.repository_name)
repositoryNameView = view.findViewById(R.id.repo_name)
repositoryDescriptionView = view.findViewById(R.id.repo_description)
repositoryStarsView = view.findViewById(R.id.repo_stars)
repositoryLanguageView = view.findViewById(R.id.repo_language)
repositoryForksView = view.findViewById(R.id.repo_forks)
itemView.setOnClickListener {
currentRepository?.let {
onClick(it)
@ -23,15 +31,42 @@ class RepositoryListAdapter(private val dataSet: List<Repository>, private val o
}
}
fun bind(repository: Repository) {
repositoryNameView.text = repository.name
fun bind(repository: Repository?) {
if (repository == null) {
val resources = itemView.resources
repositoryNameView.text = resources.getString(R.string.loading)
repositoryDescriptionView.visibility = View.GONE
repositoryStarsView.text = resources.getString(R.string.unknown)
repositoryLanguageView.visibility = View.GONE
repositoryForksView.text = resources.getString(R.string.unknown)
} else {
repositoryNameView.text = repository.name
var descriptionVisibility = View.GONE
if (repository.description != null) {
repositoryDescriptionView.text = repository.description
descriptionVisibility = View.VISIBLE
}
repositoryDescriptionView.visibility = descriptionVisibility
repositoryStarsView.text = repository.stars.toString()
repositoryForksView.text = repository.forks.toString()
var languageVisibility = View.GONE
if (!repository.language.isNullOrEmpty()) {
val resources = this.itemView.context.resources
repositoryLanguageView.text = resources.getString(R.string.language, repository.language)
languageVisibility = View.VISIBLE
}
repositoryLanguageView.visibility = languageVisibility
}
currentRepository = repository
}
}
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.repository_row_item, viewGroup, false)
.inflate(R.layout.repository_view_item, viewGroup, false)
return ViewHolder(view, onClick)
}

@ -1,3 +1,12 @@
package fr.uca.iut.clfreville2.teaiswarm.model
data class Repository(val owner: Owner, val name: String, val stars: Int = 0)
import com.squareup.moshi.Json
data class Repository(
val owner: Owner,
val name: String,
val description: String? = null,
@Json(name = "stars_count") val stars: Int = 0,
@Json(name = "forks_count") val forks: Int = 0,
val language: String? = null
)

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#000000"
android:pathData="M 21.081 7.505 C 21.081 5.842 19.746 4.508 18.081 4.508 C 16.416 4.508 15.081 5.842 15.081 7.505 C 15.081 8.599 15.696 9.573 16.581 10.082 L 16.581 10.532 C 16.551 11.311 16.236 12 15.636 12.599 C 15.036 13.199 14.346 13.513 13.566 13.543 C 12.321 13.573 11.346 13.783 10.566 14.218 L 10.566 7.085 C 11.451 6.576 12.066 5.617 12.066 4.508 C 12.066 2.845 10.731 1.512 9.066 1.512 C 7.401 1.512 6.081 2.845 6.081 4.508 C 6.081 5.602 6.696 6.576 7.581 7.085 L 7.581 16.915 C 6.696 17.439 6.081 18.398 6.081 19.492 C 6.081 21.155 7.416 22.488 9.081 22.488 C 10.746 22.488 12.081 21.155 12.081 19.492 C 12.081 18.698 11.781 17.993 11.286 17.454 C 11.421 17.364 12.006 16.84 12.171 16.75 C 12.546 16.585 13.011 16.495 13.581 16.495 C 15.156 16.42 16.506 15.821 17.706 14.622 C 18.906 13.423 19.506 11.655 19.581 10.097 L 19.551 10.097 C 20.466 9.558 21.081 8.599 21.081 7.505 Z M 9.081 2.71 C 10.071 2.71 10.881 3.534 10.881 4.508 C 10.881 5.482 10.056 6.306 9.081 6.306 C 8.106 6.306 7.281 5.482 7.281 4.508 C 7.281 3.534 8.106 2.71 9.081 2.71 Z M 9.081 21.305 C 8.091 21.305 7.281 20.481 7.281 19.507 C 7.281 18.533 8.106 17.709 9.081 17.709 C 10.056 17.709 10.881 18.533 10.881 19.507 C 10.881 20.481 10.056 21.305 9.081 21.305 Z M 18.081 9.318 C 17.091 9.318 16.281 8.494 16.281 7.52 C 16.281 6.546 17.106 5.722 18.081 5.722 C 19.056 5.722 19.881 6.546 19.881 7.52 C 19.881 8.494 19.056 9.318 18.081 9.318 Z"/>
</vector>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/row_item_margin_horizontal"
android:paddingTop="@dimen/row_item_margin_vertical">
<TextView
android:id="@+id/repo_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/title_color"
android:textSize="@dimen/repo_name_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="TeaIsWarm"/>
<TextView
android:id="@+id/repo_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="10"
android:paddingVertical="@dimen/row_item_margin_vertical"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/repo_description_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/repo_name"
tools:text="Le thé est chaud."/>
<TextView
android:id="@+id/repo_language"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:paddingVertical="@dimen/row_item_margin_vertical"
android:text="@string/language"
android:textSize="@dimen/repo_description_size"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/repo_description"
tools:ignore="RtlCompat" />
<ImageView
android:id="@+id/star"
android:layout_width="0dp"
android:layout_marginVertical="@dimen/row_item_margin_vertical"
android:layout_height="wrap_content"
android:src="@drawable/ic_star"
app:layout_constraintEnd_toStartOf="@+id/repo_stars"
app:layout_constraintBottom_toBottomOf="@+id/repo_stars"
app:layout_constraintTop_toTopOf="@+id/repo_stars" />
<TextView
android:id="@+id/repo_stars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingVertical="@dimen/row_item_margin_vertical"
android:textSize="@dimen/repo_description_size"
app:layout_constraintEnd_toStartOf="@id/forks"
app:layout_constraintBaseline_toBaselineOf="@+id/repo_forks"
tools:text="30" />
<ImageView
android:id="@+id/forks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/row_item_margin_vertical"
android:src="@drawable/ic_git_branch"
app:layout_constraintEnd_toStartOf="@+id/repo_forks"
app:layout_constraintBottom_toBottomOf="@+id/repo_forks"
app:layout_constraintTop_toTopOf="@+id/repo_forks" />
<TextView
android:id="@+id/repo_forks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingVertical="@dimen/row_item_margin_vertical"
android:textSize="@dimen/repo_description_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/repo_description"
tools:text="30" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -7,4 +7,7 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="title_color">#1F75FE</color>
<color name="title_color_alpha">#551F75FE</color>
</resources>

@ -1,3 +1,11 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
<dimen name="row_item_margin_vertical">12dp</dimen>
<dimen name="row_item_margin_horizontal">12dp</dimen>
<dimen name="repo_name_size">24sp</dimen>
<dimen name="repo_description_size">16sp</dimen>
<dimen name="repo_icon_size">24dp</dimen>
<dimen name="loading_progress_bar_size">36dp</dimen>
<dimen name="placeholder_item_height">32dp</dimen>
<dimen name="error_text_size">24sp</dimen>
</resources>

@ -8,4 +8,7 @@
</plurals>
<string name="previous">Previous</string>
<string name="next">Next</string>
<string name="language">Language: %s</string>
<string name="loading">Loading</string>
<string name="unknown">Unknown</string>
</resources>

@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.20-RC' apply false
}
Loading…
Cancel
Save