Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 4578e378 authored by 62160052's avatar 62160052
Browse files

Add a binding adapter for the status ImageView

parent e8181f2e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -4,7 +4,7 @@
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/Users/Fair/Desktop/android-basics-kotlin-mars-photos-app-starter/app/src/main/res/drawable/ic_broken_image.xml" value="0.226" />
<entry key="..\:/Users/Fair/Desktop/android-basics-kotlin-mars-photos-app-starter/app/src/main/res/layout/fragment_overview.xml" value="0.33" />
<entry key="..\:/Users/Fair/Desktop/android-basics-kotlin-mars-photos-app-starter/app/src/main/res/layout/fragment_overview.xml" value="0.25" />
<entry key="..\:/Users/Fair/Desktop/android-basics-kotlin-mars-photos-app-starter/app/src/main/res/layout/grid_view_item.xml" value="0.24048913043478262" />
</map>
</option>
......
package com.example.android.marsphotos.overview
import android.view.View
import android.widget.ImageView
import androidx.core.net.toUri
import androidx.databinding.BindingAdapter
......@@ -26,6 +27,24 @@ fun bindRecyclerView(recyclerView: RecyclerView,
adapter.submitList(data)
}
@BindingAdapter("marsApiStatus")
fun bindStatus(statusImageView: ImageView,
status: MarsApiStatus?) {
when (status) {
MarsApiStatus.LOADING -> {
statusImageView.visibility = View.VISIBLE
statusImageView.setImageResource(R.drawable.loading_animation)
}
MarsApiStatus.ERROR -> {
statusImageView.visibility = View.VISIBLE
statusImageView.setImageResource(R.drawable.ic_connection_error)
}
MarsApiStatus.DONE -> {
statusImageView.visibility = View.GONE
}
}
}
class BindingAdapters {
}
......@@ -46,6 +46,15 @@
tools:itemCount="16"
tools:listitem="@layout/grid_view_item"
app:spanCount="2" />
<ImageView
android:id="@+id/status_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:marsApiStatus="@{viewModel.status}" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment