Skip to content

Commit

Permalink
Update Compose in RecyclerView implementation. (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
arriolac committed May 20, 2022
1 parent 2680662 commit 395d403
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.google.samples.apps.sunflower.adapters.PlantAdapter
import com.google.samples.apps.sunflower.data.Plant
import com.google.samples.apps.sunflower.databinding.FragmentPlantListBinding
import com.google.samples.apps.sunflower.utilities.InjectorUtils
import com.google.samples.apps.sunflower.viewmodels.PlantListViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,15 @@

package com.google.samples.apps.sunflower.adapters

import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.Card
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.navigation.findNavController
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import com.google.android.material.composethemeadapter.MdcTheme
import com.google.samples.apps.sunflower.HomeViewPagerFragmentDirections
import com.google.samples.apps.sunflower.PlantListFragment
import com.google.samples.apps.sunflower.R
import com.google.samples.apps.sunflower.compose.ComposeViewHolder
import com.google.samples.apps.sunflower.compose.plantlist.PlantListItemView
import com.google.samples.apps.sunflower.data.Plant

Expand All @@ -67,13 +44,13 @@ class PlantAdapter : ListAdapter<Plant, RecyclerView.ViewHolder>(PlantDiffCallba

class PlantViewHolder(
composeView: ComposeView
) : ComposeViewHolder<Plant>(composeView) {

@Composable
override fun Content(input: Plant) {
MdcTheme {
PlantListItemView(plant = input) {
navigateToPlant(input)
) : RecyclerView.ViewHolder(composeView) {
fun bind(plant: Plant) {
(itemView as ComposeView).setContent {
MdcTheme {
PlantListItemView(plant = plant) {
navigateToPlant(plant)
}
}
}
}
Expand All @@ -83,7 +60,7 @@ class PlantAdapter : ListAdapter<Plant, RecyclerView.ViewHolder>(PlantDiffCallba
HomeViewPagerFragmentDirections.actionViewPagerFragmentToPlantDetailFragment(
plant.plantId
)
composeView.findNavController().navigate(direction)
itemView.findNavController().navigate(direction)
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ private fun PlantImage(
model = ImageRequest.Builder(LocalContext.current)
.data(data = imageUrl)
.crossfade(true)
.build()
)

Image(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fun PlantListItemView(plant: Plant, onClick: () -> Unit) {
model = ImageRequest.Builder(LocalContext.current)
.data(plant.imageUrl)
.crossfade(true)
.build()
)
Image(
painter = painter,
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buildscript {
activityComposeVersion = '1.3.0-rc02'
appCompatVersion = '1.1.0'
coilVersion = '2.0.0'
composeVersion = '1.2.0-beta01'
composeVersion = '1.2.0-beta02'
composeThemeAdapterVersion = '1.1.1'
constraintLayoutVersion = '2.1.0-alpha2'
constraintLayoutComposeVersion = '1.0.0-alpha08'
Expand All @@ -42,7 +42,7 @@ buildscript {
lifecycleVersion = '2.3.0'
materialVersion = '1.3.0'
navigationVersion = '2.4.1'
recyclerViewVersion = '1.1.0-alpha05'
recyclerViewVersion = '1.3.0-alpha02'
roomVersion = '2.4.2'
runnerVersion = '1.0.1'
truthVersion = '1.0.1'
Expand Down

0 comments on commit 395d403

Please sign in to comment.