Skip to content

Commit 127a783

Browse files
Implement RecyclerView and adapter to RepositoryCellItem (#16)
1 parent 9527dab commit 127a783

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

solutions/devsprint-denis-vieira-1/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'com.android.application'
33
id 'org.jetbrains.kotlin.android'
4+
id "kotlin-kapt"
45
}
56

67
android {
@@ -47,4 +48,6 @@ dependencies {
4748
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
4849
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
4950
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
51+
implementation 'com.github.bumptech.glide:glide:4.13.2'
52+
kapt 'com.github.bumptech.glide:compiler:4.13.2'
5053
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
package com.devpass.githubapp.presentation
22

33
import androidx.recyclerview.widget.RecyclerView
4+
import com.bumptech.glide.Glide
5+
import com.devpass.githubapp.R
6+
import com.devpass.githubapp.data.model.Repository
47
import com.devpass.githubapp.databinding.ItemCellRepositoryBinding
58

69
class RepositoryCellItem(
7-
binding: ItemCellRepositoryBinding
10+
private val binding: ItemCellRepositoryBinding
811
) : RecyclerView.ViewHolder(binding.root) {
912

10-
fun bind() {
13+
fun bind(item: Repository) {
14+
with(binding){
15+
textviewRepositoryName.text = item.name
16+
textviewOwnerName.text = item.owner.login
1117

18+
Glide
19+
.with(root.context)
20+
.load(item.owner.avatarUrl)
21+
.centerCrop()
22+
.placeholder(R.drawable.ic_placeholder)
23+
.into(imageviewAvatar)
24+
}
1225
}
1326
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.devpass.githubapp.presentation
2+
3+
import android.view.LayoutInflater
4+
import android.view.ViewGroup
5+
import androidx.recyclerview.widget.RecyclerView
6+
import com.devpass.githubapp.data.model.Repository
7+
import com.devpass.githubapp.databinding.ItemCellRepositoryBinding
8+
9+
class RepositoryListAdapter : RecyclerView.Adapter<RepositoryCellItem>() {
10+
11+
private val repositories: List<Repository> = listOf()
12+
13+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepositoryCellItem {
14+
val inflater = LayoutInflater.from(parent.context)
15+
val binding = ItemCellRepositoryBinding.inflate(inflater, parent, false)
16+
return RepositoryCellItem(binding)
17+
}
18+
19+
override fun onBindViewHolder(holder: RepositoryCellItem, position: Int) {
20+
val item = repositories[position]
21+
holder.bind(item)
22+
}
23+
24+
override fun getItemCount(): Int = repositories.size
25+
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#656363"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
5+
</vector>

solutions/devsprint-denis-vieira-1/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
</com.google.android.material.appbar.AppBarLayout>
2222

23-
<include layout="@layout/content_repository_list" />
23+
<include layout="@layout/content_repository_list"/>
2424

2525
</androidx.coordinatorlayout.widget.CoordinatorLayout>

solutions/devsprint-denis-vieira-1/app/src/main/res/layout/content_repository_list.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
78
tools:context=".presentation.RepositoryListFragment">
89

9-
<TextView
10-
android:id="@+id/textview_first"
11-
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
13-
android:text="@string/hello_first_fragment"
10+
<androidx.recyclerview.widget.RecyclerView
11+
android:id="@+id/repositories_recyclerview"
12+
android:layout_width="0dp"
13+
android:layout_height="0dp"
1414
app:layout_constraintBottom_toBottomOf="parent"
1515
app:layout_constraintEnd_toEndOf="parent"
16-
app:layout_constraintHorizontal_bias="0.498"
1716
app:layout_constraintStart_toStartOf="parent"
18-
app:layout_constraintTop_toTopOf="parent" />
17+
app:layout_constraintTop_toTopOf="parent"
18+
tools:listitem="@layout/item_cell_repository" />
1919

2020
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)