|
|
|
@ -16,14 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.feature.interests
|
|
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
|
import androidx.compose.foundation.layout.WindowInsets
|
|
|
|
|
import androidx.compose.foundation.layout.WindowInsetsSides
|
|
|
|
|
import androidx.compose.foundation.layout.only
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.foundation.layout.safeDrawing
|
|
|
|
|
import androidx.compose.foundation.layout.windowInsetsPadding
|
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.filled.MoreVert
|
|
|
|
|
import androidx.compose.material.icons.filled.Search
|
|
|
|
@ -31,15 +24,18 @@ import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.hilt.navigation.compose.hiltViewModel
|
|
|
|
|
import com.google.accompanist.pager.ExperimentalPagerApi
|
|
|
|
|
import com.google.accompanist.pager.HorizontalPager
|
|
|
|
|
import com.google.accompanist.pager.rememberPagerState
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.LoadingWheel
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.component.NiaTab
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.component.NiaTabRow
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.component.NiaTopAppBar
|
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.component.*
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun InterestsRoute(
|
|
|
|
@ -118,6 +114,8 @@ fun InterestsScreen(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalPagerApi::class)
|
|
|
|
|
@Composable
|
|
|
|
|
private fun InterestsContent(
|
|
|
|
|
tabState: InterestsTabState,
|
|
|
|
@ -130,26 +128,38 @@ private fun InterestsContent(
|
|
|
|
|
modifier: Modifier = Modifier
|
|
|
|
|
) {
|
|
|
|
|
Column(modifier) {
|
|
|
|
|
NiaTabRow(selectedTabIndex = tabState.currentIndex) {
|
|
|
|
|
val pagerState = rememberPagerState()
|
|
|
|
|
val scope = rememberCoroutineScope()
|
|
|
|
|
NiaTabRow(
|
|
|
|
|
selectedTabIndex = pagerState.currentPage
|
|
|
|
|
) {
|
|
|
|
|
tabState.titles.forEachIndexed { index, titleId ->
|
|
|
|
|
NiaTab(
|
|
|
|
|
selected = index == tabState.currentIndex,
|
|
|
|
|
onClick = { switchTab(index) },
|
|
|
|
|
selected = pagerState.currentPage == index,
|
|
|
|
|
onClick = {
|
|
|
|
|
switchTab(index)
|
|
|
|
|
scope.launch {
|
|
|
|
|
pagerState.scrollToPage(index)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
text = { Text(text = stringResource(id = titleId)) }
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
when (tabState.currentIndex) {
|
|
|
|
|
0 -> {
|
|
|
|
|
TopicsTabContent(
|
|
|
|
|
HorizontalPager(
|
|
|
|
|
state = pagerState,
|
|
|
|
|
count = tabState.titles.size,
|
|
|
|
|
verticalAlignment = Alignment.Top,
|
|
|
|
|
contentPadding = PaddingValues(top = 12.dp),
|
|
|
|
|
) { index ->
|
|
|
|
|
when (index) {
|
|
|
|
|
0 -> TopicsTabContent(
|
|
|
|
|
topics = uiState.topics,
|
|
|
|
|
onTopicClick = navigateToTopic,
|
|
|
|
|
onFollowButtonClick = followTopic,
|
|
|
|
|
modifier = Modifier.padding(top = 8.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
1 -> {
|
|
|
|
|
AuthorsTabContent(
|
|
|
|
|
1 -> AuthorsTabContent(
|
|
|
|
|
authors = uiState.authors,
|
|
|
|
|
onAuthorClick = navigateToAuthor,
|
|
|
|
|
onFollowButtonClick = followAuthor,
|
|
|
|
|