Skip to content

Commit

Permalink
refactor: Better swipe to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed May 3, 2021
1 parent 03eb106 commit 7137a8f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 148 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dependencies {
implementation("androidx.compose.material:material:$composeVersion")
implementation("androidx.compose.material:material-icons-extended:$composeVersion")
implementation("androidx.compose.ui:ui-tooling:$composeVersion")
implementation("com.google.accompanist:accompanist-swiperefresh:0.8.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04")
implementation("androidx.activity:activity-compose:1.3.0-alpha07")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.tien.piholeconnect.R
import com.tien.piholeconnect.model.RuleType
import com.tien.piholeconnect.ui.component.AddFilterRuleDialog
import com.tien.piholeconnect.ui.component.SwipeToRefreshLayout
import com.tien.piholeconnect.ui.component.TopBarProgressIndicator
import com.tien.piholeconnect.util.showGenericPiHoleConnectionError
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -85,8 +86,8 @@ fun FilterRulesScreen(
)
}
}) {
SwipeToRefreshLayout(
refreshingState = isRefreshing,
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
onRefresh = {
viewModel.viewModelScope.launch {
isRefreshing = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.github.mikephil.charting.formatter.ValueFormatter
import com.github.mikephil.charting.listener.ChartTouchListener
import com.github.mikephil.charting.listener.OnChartGestureListener
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.tien.piholeconnect.R
import com.tien.piholeconnect.ui.component.*
import com.tien.piholeconnect.ui.theme.info
Expand Down Expand Up @@ -125,19 +127,15 @@ fun HomeScreen(
)
}) {
var isScrollEnabled by remember { mutableStateOf(true) }
SwipeToRefreshLayout(
enabled = isScrollEnabled,
refreshingState = isRefreshing,
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
onRefresh = {
viewModel.viewModelScope.launch {
isRefreshing = true
viewModel.apply {
refresh()
isRefreshing = false
}
viewModel.refresh()
isRefreshing = false
}
})
{
}) {
Column(
Modifier
.fillMaxHeight()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.tien.piholeconnect.ui.component.LogItem
import com.tien.piholeconnect.ui.component.SwipeToRefreshLayout
import com.tien.piholeconnect.ui.component.TopBarProgressIndicator
import com.tien.piholeconnect.util.showGenericPiHoleConnectionError
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -49,8 +50,8 @@ fun LogScreen(

if (!viewModel.hasBeenLoaded) return

SwipeToRefreshLayout(
refreshingState = isRefreshing,
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
onRefresh = {
viewModel.viewModelScope.launch {
isRefreshing = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.tien.piholeconnect.ui.component.RankedListCard
import com.tien.piholeconnect.ui.component.SwipeToRefreshLayout
import com.tien.piholeconnect.ui.component.TopBarProgressIndicator
import com.tien.piholeconnect.ui.theme.info
import com.tien.piholeconnect.ui.theme.success
Expand Down Expand Up @@ -53,8 +54,8 @@ fun StatisticsScreen(

if (!viewModel.hasBeenLoaded) return

SwipeToRefreshLayout(
refreshingState = isRefreshing,
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
onRefresh = {
viewModel.viewModelScope.launch {
isRefreshing = true
Expand Down

0 comments on commit 7137a8f

Please sign in to comment.