Skip to content

Commit

Permalink
Migrate to molecule 2.0, ktor 3.0.0-rc1, and qdsfdhvh-image-loader 1.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
xxfast committed Sep 24, 2024
1 parent 25cee30 commit bd085aa
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/browser.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/runConfigurations/ios.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.outlined.FavoriteBorder
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.rounded.Error
import androidx.compose.material.icons.rounded.ExitToApp
import androidx.compose.material.icons.rounded.OpenInFull
import androidx.compose.material.icons.rounded.Refresh
Expand Down Expand Up @@ -54,19 +55,24 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.seiko.imageloader.AsyncImagePainter
import com.seiko.imageloader.ImageRequestState
import com.seiko.imageloader.rememberAsyncImagePainter
import com.seiko.imageloader.model.ImageAction
import com.seiko.imageloader.model.ImageEvent
import com.seiko.imageloader.model.ImageRequest
import com.seiko.imageloader.model.ImageResult
import com.seiko.imageloader.rememberImageAction
import com.seiko.imageloader.rememberImageActionPainter
import io.github.xxfast.androidx.compose.material3.windowsizeclass.LocalWindowSizeClass
import io.github.xxfast.decompose.router.rememberOnRoute
import io.github.xxfast.nytimes.components.TwoPanelScaffold
import io.github.xxfast.nytimes.models.ArticleUri
import io.github.xxfast.nytimes.models.Multimedia
import io.github.xxfast.nytimes.models.TopStorySection
import io.github.xxfast.nytimes.screens.summary.StorySummaryView
import io.github.xxfast.nytimes.screens.topStories.Loading
Expand Down Expand Up @@ -169,26 +175,13 @@ fun StoryView(
.padding(8.dp)
) {
if (!state.article.multimedia.isNullOrEmpty()) Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.clip(MaterialTheme.shapes.extraLarge)
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(16.dp))
) {
val painter: AsyncImagePainter =
rememberAsyncImagePainter(state.article.multimedia.first().url)

if (painter.requestState is ImageRequestState.Loading)
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))

Image(
painter = painter,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(16.dp))
.fillMaxWidth()
.height(420.dp)
)
ArticleImage(state.article.multimedia.first().url)
}

Column(
Expand Down Expand Up @@ -329,3 +322,23 @@ fun StoryView(
)
}
}

@Composable
fun ArticleImage(imageUrl: String) {
val action: ImageAction by rememberImageAction(ImageRequest(imageUrl))
val painter: Painter = rememberImageActionPainter(action)

when (action) {
is ImageEvent.Start -> CircularProgressIndicator()
is ImageResult.OfError -> Icon(Icons.Rounded.Error, null)
else -> Image(
painter = painter,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(16.dp))
.fillMaxWidth()
.height(420.dp)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.seiko.imageloader.AsyncImagePainter
import com.seiko.imageloader.ImageRequestState
import com.seiko.imageloader.rememberAsyncImagePainter
import io.github.xxfast.nytimes.models.ArticleUri
import io.github.xxfast.nytimes.models.TopStorySection
import io.github.xxfast.nytimes.screens.story.ArticleImage

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun StorySummaryView(
summary: SummaryState,
Expand All @@ -57,19 +54,7 @@ fun StorySummaryView(
.clip(MaterialTheme.shapes.extraLarge)
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
) {
val painter: AsyncImagePainter = rememberAsyncImagePainter(summary.imageUrl)

if (painter.requestState is ImageRequestState.Loading)
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))

Image(
painter = painter,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth()
.height(180.dp)
)
ArticleImage(summary.imageUrl)
}

Text(
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ buildscript {
classpath(libs.agp)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.kotlin.serialization)
classpath(libs.molecule.gradle.plugin)
classpath(libs.buildkonfig.gradle.plugin)
}
}
Expand Down
7 changes: 3 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ kotlinx-coroutines = "1.7.2"
kotlinx-datetime = "0.4.0"
kotlinx-serialization = "1.5.1"
kstore = "0.8.0"
ktor = "2.3.6"
molecule = "1.2.0"
qdsfdhvh-image-loader = "1.5.1"
ktor = "3.0.0-rc-1"
molecule = "2.0.0"
qdsfdhvh-image-loader = "1.8.3"
wear-compose = "1.3.1"
okio = "3.6.0"

Expand Down Expand Up @@ -53,7 +53,6 @@ ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "kto
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
molecule-gradle-plugin = { module = "app.cash.molecule:molecule-gradle-plugin", version.ref = "molecule" }
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
qdsfdhvh-image-loader = { module = "io.github.qdsfdhvh:image-loader", version.ref = "qdsfdhvh-image-loader" }
wear-compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "wear-compose" }
Expand Down

0 comments on commit bd085aa

Please sign in to comment.