You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.4 KiB
136 lines
4.4 KiB
/* |
|
* Copyright 2020 The Android Open Source Project |
|
* |
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
* you may not use this file except in compliance with the License. |
|
* You may obtain a copy of the License at |
|
* |
|
* https://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.example.jetsnack.ui.home |
|
|
|
import androidx.compose.animation.AnimatedVisibility |
|
import androidx.compose.animation.ExperimentalAnimationApi |
|
import androidx.compose.animation.expandVertically |
|
import androidx.compose.animation.fadeIn |
|
import androidx.compose.animation.fadeOut |
|
import androidx.compose.animation.shrinkVertically |
|
import androidx.compose.animation.slideInVertically |
|
import androidx.compose.animation.slideOutVertically |
|
//import androidx.compose.desktop.ui.tooling.preview.Preview |
|
import androidx.compose.foundation.layout.Box |
|
import androidx.compose.foundation.layout.Column |
|
import androidx.compose.foundation.layout.Spacer |
|
import androidx.compose.foundation.layout.WindowInsets |
|
import androidx.compose.foundation.layout.fillMaxSize |
|
import androidx.compose.foundation.layout.windowInsetsTopHeight |
|
import androidx.compose.foundation.lazy.LazyColumn |
|
import androidx.compose.foundation.lazy.itemsIndexed |
|
import androidx.compose.runtime.Composable |
|
import androidx.compose.runtime.getValue |
|
import androidx.compose.runtime.mutableStateOf |
|
import androidx.compose.runtime.remember |
|
import androidx.compose.runtime.saveable.rememberSaveable |
|
import androidx.compose.runtime.setValue |
|
import androidx.compose.ui.Alignment |
|
import androidx.compose.ui.Modifier |
|
import androidx.compose.ui.unit.dp |
|
import com.example.jetsnack.model.Filter |
|
import com.example.jetsnack.model.SnackCollection |
|
import com.example.jetsnack.model.SnackRepo |
|
import com.example.jetsnack.ui.components.FilterBar |
|
import com.example.jetsnack.ui.components.JetsnackDivider |
|
import com.example.jetsnack.ui.components.JetsnackSurface |
|
import com.example.jetsnack.ui.components.SnackCollection |
|
import com.example.jetsnack.ui.snackdetail.jetSnackStatusBarsPadding |
|
import com.example.jetsnack.ui.theme.JetsnackTheme |
|
|
|
@Composable |
|
fun Feed( |
|
onSnackClick: (Long) -> Unit, |
|
modifier: Modifier = Modifier |
|
) { |
|
val snackCollections = remember { SnackRepo.getSnacks() } |
|
val filters = remember { SnackRepo.getFilters() } |
|
Feed( |
|
snackCollections, |
|
filters, |
|
onSnackClick, |
|
modifier |
|
) |
|
} |
|
|
|
@Composable |
|
private fun Feed( |
|
snackCollections: List<SnackCollection>, |
|
filters: List<Filter>, |
|
onSnackClick: (Long) -> Unit, |
|
modifier: Modifier = Modifier |
|
) { |
|
|
|
JetsnackSurface(modifier = modifier.fillMaxSize()) { |
|
Column { |
|
DestinationBar(modifier = Modifier.jetSnackStatusBarsPadding()) |
|
SnackCollectionList(snackCollections, filters, onSnackClick) |
|
} |
|
} |
|
} |
|
|
|
@OptIn(ExperimentalAnimationApi::class) |
|
@Composable |
|
private fun SnackCollectionList( |
|
snackCollections: List<SnackCollection>, |
|
filters: List<Filter>, |
|
onSnackClick: (Long) -> Unit, |
|
modifier: Modifier = Modifier |
|
) { |
|
var filtersVisible by rememberSaveable { mutableStateOf(false) } |
|
Box(modifier) { |
|
LazyColumn { |
|
|
|
item { |
|
FilterBar(filters, onShowFilters = { filtersVisible = true }) |
|
} |
|
itemsIndexed(snackCollections) { index, snackCollection -> |
|
if (index > 0) { |
|
JetsnackDivider(thickness = 2.dp) |
|
} |
|
|
|
SnackCollection( |
|
snackCollection = snackCollection, |
|
onSnackClick = onSnackClick, |
|
index = index |
|
) |
|
} |
|
} |
|
} |
|
AnimatedVisibility( |
|
visible = filtersVisible, |
|
enter = slideInVertically() + expandVertically( |
|
expandFrom = Alignment.Top |
|
) + fadeIn(initialAlpha = 0.3f), |
|
exit = slideOutVertically() + shrinkVertically() + fadeOut() |
|
) { |
|
FilterScreen( |
|
onDismiss = { filtersVisible = false } |
|
) |
|
} |
|
} |
|
|
|
@Composable |
|
expect fun snackCollectionListItemWindowInsets(): WindowInsets |
|
|
|
//@Preview |
|
@Composable |
|
fun HomePreview() { |
|
JetsnackTheme { |
|
Feed(onSnackClick = { }) |
|
} |
|
}
|
|
|