Skip to content

Commit

Permalink
migrate to jetpack compose built in refresh indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsburrows committed Jan 26, 2024
1 parent 9e192de commit 6034f54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Gif Search using Jetpack Compose + Kotlin

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Build](https://github.com/jaredsburrows/android-gif-search/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/jaredsburrows/android-gif-search/actions/workflows/build.yml)
[![build](https://github.com/jaredsburrows/android-gif-search/actions/workflows/build.yml/badge.svg)](https://github.com/jaredsburrows/android-gif-search/actions/workflows/build.yml)
[![Twitter Follow](https://img.shields.io/twitter/follow/jaredsburrows.svg?style=social)](https://twitter.com/jaredsburrows)


Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/burrowsapps/gif/search/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ fun MainScreen() {
* app, and has a route property that corresponds to the screen's route in the navigation graph.
*/
sealed class Screen(val route: String) {
object Gif : Screen("gif")
object License : Screen("license")
data object Gif : Screen("gif")
data object License : Screen("license")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:OptIn(
ExperimentalMaterial3Api::class,
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class,
)

package com.burrowsapps.gif.search.ui.giflist
Expand All @@ -26,9 +27,13 @@ import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
Expand Down Expand Up @@ -85,8 +90,6 @@ import com.bumptech.glide.signature.ObjectKey
import com.burrowsapps.gif.search.R
import com.burrowsapps.gif.search.Screen
import com.burrowsapps.gif.search.ui.theme.GifTheme
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.components.rememberImageComponent
import com.skydoves.landscapist.glide.GlideImage
Expand Down Expand Up @@ -297,13 +300,17 @@ private fun TheContent(
openDialog = openDialog,
)
}

SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing.value),
val pullRefreshState = rememberPullRefreshState(
refreshing = isRefreshing.value,
onRefresh = {
// TODO handle trending vs search
gifViewModel.loadTrendingImages()
},
)

Box(
modifier = Modifier
.pullRefresh(pullRefreshState),
contentAlignment = Alignment.Center,
) {
val context = LocalContext.current
LazyVerticalGrid(
Expand Down Expand Up @@ -366,6 +373,12 @@ private fun TheContent(
}
}

PullRefreshIndicator(
isRefreshing.value,
pullRefreshState,
modifier = Modifier.align(Alignment.TopCenter),
)

InfiniteGridHandler(
gridState = gridState,
) {
Expand Down

0 comments on commit 6034f54

Please sign in to comment.