Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Get Data from Internet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
Get Data from Internet
Commits
b92d429e
Commit
b92d429e
authored
2 years ago
by
62160052
Browse files
Options
Downloads
Patches
Plain Diff
Add the photo grid adapter
parent
f6cfeeb4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/example/android/marsphotos/overview/PhotoGridAdapter.kt
+42
-0
42 additions, 0 deletions
...m/example/android/marsphotos/overview/PhotoGridAdapter.kt
with
42 additions
and
0 deletions
app/src/main/java/com/example/android/marsphotos/overview/PhotoGridAdapter.kt
0 → 100644
+
42
−
0
View file @
b92d429e
package
com.example.android.marsphotos.overview
import
android.view.LayoutInflater
import
android.view.ViewGroup
import
androidx.recyclerview.widget.DiffUtil
import
androidx.recyclerview.widget.ListAdapter
import
androidx.recyclerview.widget.RecyclerView
import
com.example.android.marsphotos.databinding.GridViewItemBinding
import
com.example.android.marsphotos.network.MarsPhoto
class
PhotoGridAdapter
:
ListAdapter
<
MarsPhoto
,
PhotoGridAdapter
.
MarsPhotoViewHolder
>(
MarsPhotoViewHolder
)
{
class
MarsPhotoViewHolder
(
private
var
binding
:
GridViewItemBinding
):
RecyclerView
.
ViewHolder
(
binding
.
root
)
{
fun
bind
(
MarsPhoto
:
MarsPhoto
)
{
binding
.
photo
=
MarsPhoto
binding
.
executePendingBindings
()
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
PhotoGridAdapter
.
MarsPhotoViewHolder
{
return
MarsPhotoViewHolder
(
GridViewItemBinding
.
inflate
(
LayoutInflater
.
from
(
parent
.
context
)))
}
override
fun
onBindViewHolder
(
holder
:
PhotoGridAdapter
.
MarsPhotoViewHolder
,
position
:
Int
)
{
val
marsPhoto
=
getItem
(
position
)
holder
.
bind
(
marsPhoto
)
}
companion
object
DiffCallback
:
DiffUtil
.
ItemCallback
<
MarsPhoto
>()
{
override
fun
areItemsTheSame
(
oldItem
:
MarsPhoto
,
newItem
:
MarsPhoto
):
Boolean
{
return
oldItem
.
id
==
newItem
.
id
}
override
fun
areContentsTheSame
(
oldItem
:
MarsPhoto
,
newItem
:
MarsPhoto
):
Boolean
{
return
oldItem
.
imgSrcUrl
==
newItem
.
imgSrcUrl
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment