-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: save explore contents to the view model
Additionally add refresh button
- Loading branch information
Showing
5 changed files
with
263 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 41 additions & 7 deletions
48
app/src/main/java/live/shirabox/shirabox/ui/screen/explore/ExploreScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,74 @@ | ||
package live.shirabox.shirabox.ui.screen.explore | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.pullrefresh.PullRefreshIndicator | ||
import androidx.compose.material.pullrefresh.pullRefresh | ||
import androidx.compose.material.pullrefresh.rememberPullRefreshState | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.zIndex | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import androidx.navigation.NavController | ||
import live.shirabox.core.util.Util | ||
import live.shirabox.shirabox.ui.component.top.TopBar | ||
|
||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@ExperimentalMaterial3Api | ||
@Composable | ||
fun ExploreScreen(navController: NavController) { | ||
fun ExploreScreen( | ||
navController: NavController, | ||
model: ExploreViewModel = viewModel(factory = Util.viewModelFactory { | ||
ExploreViewModel() | ||
}) | ||
) { | ||
|
||
val lazyListState = rememberLazyListState() | ||
val pullRefreshState = rememberPullRefreshState(model.refreshing.value, { model.refresh() }) | ||
|
||
Scaffold( | ||
modifier = Modifier.pullRefresh(pullRefreshState), | ||
snackbarHost = { AppUpdateSnackbarHost() }, | ||
contentWindowInsets = WindowInsets(0.dp) | ||
) { | ||
LazyColumn( | ||
Box ( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(it), | ||
state = lazyListState, | ||
verticalArrangement = Arrangement.spacedBy(16.dp) | ||
) { | ||
item { TopBar(navController) } | ||
item { BaseMediaScreen(lazyListState = lazyListState) } | ||
contentAlignment = Alignment.TopCenter | ||
){ | ||
LazyColumn( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.zIndex(1f), | ||
state = lazyListState, | ||
verticalArrangement = Arrangement.spacedBy(16.dp) | ||
) { | ||
item { TopBar(navController) } | ||
item { BaseMediaScreen(model = model, lazyListState = lazyListState) } | ||
} | ||
|
||
PullRefreshIndicator( | ||
modifier = Modifier.zIndex(2f), | ||
refreshing = model.refreshing.value, | ||
state = pullRefreshState, | ||
scale = true, | ||
contentColor = MaterialTheme.colorScheme.primary | ||
) | ||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.