Skip to content

Commit

Permalink
change usage of image loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahriyar13 committed Nov 15, 2023
1 parent 4271d7e commit 07af594
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
package com.mocoding.pokedex.ui.details

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBackIosNew
import androidx.compose.material.icons.rounded.Favorite
import androidx.compose.material.icons.rounded.FavoriteBorder
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mocoding.pokedex.ui.comingsoon.AsyncImage
import com.mocoding.pokedex.ui.details.components.AbilityRow
import com.mocoding.pokedex.ui.details.components.DetailsContent
import com.mocoding.pokedex.ui.details.components.PokemonInfos
import com.mocoding.pokedex.ui.details.components.PokemonStats
import com.mocoding.pokedex.ui.helper.LocalSafeArea

@Composable
internal fun DetailsScreen(component: DetailsComponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mocoding.pokedex.ui.comingsoon.AsyncImage
import com.mocoding.pokedex.ui.main.components.AsyncImage
import com.mocoding.pokedex.ui.details.DetailsComponent
import com.mocoding.pokedex.ui.details.store.DetailsStore
import com.mocoding.pokedex.ui.helper.LocalSafeArea
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package com.mocoding.pokedex.ui.main.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.mocoding.pokedex.ui.main.state.CategoryState
import com.mocoding.pokedex.ui.theme.Black
import com.seiko.imageloader.rememberAsyncImagePainter

@Composable
internal fun CategoryButton(
Expand Down Expand Up @@ -51,8 +45,6 @@ internal fun CategoryButton(

Spacer(Modifier.weight(1f))

val painter = rememberAsyncImagePainter(categoryState.iconUrl)

Box(
contentAlignment = Alignment.Center
) {
Expand All @@ -71,11 +63,11 @@ internal fun CategoryButton(
)
)

Image(
painter = painter,

AsyncImage(
url = categoryState.iconUrl,
contentDescription = categoryState.title,
modifier = Modifier
.offset(y = (-8).dp)
.size(40.dp)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,19 @@ package com.mocoding.pokedex.ui.main.components

import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Menu
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.center
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.mocoding.pokedex.core.model.Video
import com.mocoding.pokedex.ui.main.MainComponent
import com.mocoding.pokedex.ui.main.state.CategoryState
import com.mocoding.pokedex.ui.main.store.MainStore
import com.mocoding.pokedex.ui.theme.*
import com.seiko.imageloader.rememberAsyncImagePainter
import kotlinx.coroutines.delay

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun MainContent(
state: MainStore.State,
Expand All @@ -46,6 +36,7 @@ internal fun MainContent(
modifier = Modifier.padding(horizontal = 20.dp, vertical = 20.dp)
)

val containerColor = MaterialTheme.colorScheme.surface.copy(alpha = .2f)
TextField(
value = state.search,
onValueChange = { onEvent(MainStore.Intent.InputPokemonSearch(it)) },
Expand All @@ -59,13 +50,16 @@ internal fun MainContent(
Icon(Icons.Rounded.Search, contentDescription = "Search Pokemon")
}
},
colors = TextFieldDefaults.textFieldColors(
containerColor = MaterialTheme.colorScheme.surface.copy(alpha = .2f),
placeholderColor = MaterialTheme.colorScheme.surface,
colors = TextFieldDefaults.colors(
focusedContainerColor = containerColor,
unfocusedContainerColor = containerColor,
disabledContainerColor = containerColor,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
focusedLeadingIconColor = MaterialTheme.colorScheme.surface,
unfocusedLeadingIconColor = MaterialTheme.colorScheme.surface,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
focusedPlaceholderColor = MaterialTheme.colorScheme.surface,
unfocusedPlaceholderColor = MaterialTheme.colorScheme.surface,
),
shape = MaterialTheme.shapes.extraLarge,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mocoding.pokedex.ui.main.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
Expand All @@ -20,7 +19,6 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.mocoding.pokedex.core.model.Video
import com.mocoding.pokedex.ui.theme.Black
import com.seiko.imageloader.rememberAsyncImagePainter

@Composable
internal fun VideoItem(
Expand All @@ -29,8 +27,6 @@ internal fun VideoItem(
modifier: Modifier = Modifier
) {

val painter = rememberAsyncImagePainter(video.imageUrl)

Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = modifier
Expand All @@ -42,8 +38,8 @@ internal fun VideoItem(
Box(
contentAlignment = Alignment.Center
) {
Image(
painter = painter,
AsyncImage(
url = video.imageUrl,
contentDescription = video.title,
contentScale = ContentScale.Crop,
colorFilter = ColorFilter.tint(Black.copy(.5f), BlendMode.Darken),
Expand All @@ -53,7 +49,6 @@ internal fun VideoItem(
.clip(MaterialTheme.shapes.medium)
)


Icon(
Icons.Rounded.PlayArrow,
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.mocoding.pokedex.ui.pokedex.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Image
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand All @@ -17,10 +14,8 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.mocoding.pokedex.core.model.Pokemon
import com.mocoding.pokedex.ui.comingsoon.AsyncImage
import com.mocoding.pokedex.ui.main.components.AsyncImage
import com.mocoding.pokedex.ui.theme.*
import com.seiko.imageloader.ImageRequestState
import com.seiko.imageloader.rememberAsyncImagePainter

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down

0 comments on commit 07af594

Please sign in to comment.