Show profile avatar on topAppBar
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
package ac.cord.auxiliary.compose.ui.composable
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.Profile
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfileWithFollowing
|
||||
import ac.cord.auxiliary.compose.repository.NostrRepository
|
||||
import ac.cord.auxiliary.compose.ui.composable.navigation.routes.NostrEventDetailRoute
|
||||
import ac.cord.auxiliary.compose.ui.composable.navigation.routes.Route
|
||||
import ac.cord.auxiliary.compose.ui.composable.widgets.LoadingDataIndicator
|
||||
import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileAvatar
|
||||
import ac.cord.auxiliary.compose.ui.theme.AuxTheme
|
||||
import ac.cord.auxiliary.compose.ui.view.model.FeedListViewModel
|
||||
import ac.cord.auxiliary.compose.ui.view.model.HomeScreenType
|
||||
import ac.cord.auxiliary.compose.ui.view.model.HomeViewModel
|
||||
import ac.cord.auxiliary.compose.ui.view.state.FeedListUIState
|
||||
import ac.cord.auxiliary.compose.ui.view.state.HomeScreenUIState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
@@ -34,16 +41,19 @@ import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
initialHomeScreenUIState: HomeScreenUIState = HomeScreenUIState.Loading,
|
||||
onNavigateToEvent: (Route) -> Unit,
|
||||
onNavigateToWriteNewNote: () -> Unit,
|
||||
onNavigateToSearch: () -> Unit,
|
||||
@@ -53,74 +63,97 @@ fun HomeScreen(
|
||||
|
||||
val homeScreenViewModel: HomeViewModel = viewModel(
|
||||
factory = HomeViewModel.factory(
|
||||
initialHomeScreenUIState = initialHomeScreenUIState,
|
||||
nostrRepository = nostrRepository,
|
||||
pagerState = rememberPagerState { HomeScreenType.entries.size }
|
||||
),
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
titleContentColor = MaterialTheme.colorScheme.primary
|
||||
),
|
||||
title = {
|
||||
when(val homeScreenUIState = homeScreenViewModel.homeScreenUIState) {
|
||||
HomeScreenUIState.Error -> {
|
||||
Scaffold { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier.padding(innerPadding).fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Spacer(
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Text(
|
||||
"Aux"
|
||||
text = "Something went wrong"
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.Person,
|
||||
contentDescription = "Account"
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
onNavigateToSearch.invoke()
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.Search,
|
||||
contentDescription = "Search"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
},
|
||||
floatingActionButton = {
|
||||
ExtendedFloatingActionButton(
|
||||
onClick = onNavigateToWriteNewNote,
|
||||
icon = {
|
||||
Icon(
|
||||
Icons.Default.Create,
|
||||
contentDescription = "Write"
|
||||
Spacer(
|
||||
modifier = Modifier.weight(2f)
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text("Write")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier.padding(innerPadding).fillMaxSize()
|
||||
) {
|
||||
when(val homeScreenUIState = homeScreenViewModel.homeScreenUIState) {
|
||||
HomeScreenUIState.Error -> {
|
||||
Text("Something went wrong")
|
||||
is HomeScreenUIState.Loaded -> {
|
||||
Scaffold(
|
||||
modifier = Modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
titleContentColor = MaterialTheme.colorScheme.primary
|
||||
),
|
||||
title = {
|
||||
Text(
|
||||
"Aux"
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
onNavigateToEvent.invoke(
|
||||
NostrEventDetailRoute(
|
||||
nostrEventId = homeScreenUIState.profileWithFollowing.nostrEvent.id
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
ProfileAvatar(
|
||||
profile = homeScreenUIState.profileWithFollowing.profile,
|
||||
publicKey = homeScreenUIState.profileWithFollowing.profile.publicKey
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = {
|
||||
onNavigateToSearch.invoke()
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.Search,
|
||||
contentDescription = "Search"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
},
|
||||
floatingActionButton = {
|
||||
ExtendedFloatingActionButton(
|
||||
onClick = onNavigateToWriteNewNote,
|
||||
icon = {
|
||||
Icon(
|
||||
Icons.Default.Create,
|
||||
contentDescription = "Write"
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text("Write")
|
||||
}
|
||||
)
|
||||
}
|
||||
is HomeScreenUIState.Loaded -> {
|
||||
) { innerPadding ->
|
||||
Column(
|
||||
modifier = Modifier.padding(innerPadding).fillMaxSize()
|
||||
) {
|
||||
PrimaryScrollableTabRow(
|
||||
modifier = Modifier.padding(10.dp),
|
||||
edgePadding = 10.dp,
|
||||
@@ -183,19 +216,16 @@ fun HomeScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
HomeScreenUIState.Loading -> {
|
||||
LoadingDataIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
key(true) {
|
||||
homeScreenViewModel.initiate()
|
||||
HomeScreenUIState.Loading -> {
|
||||
LoadingDataIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
key(true) {
|
||||
homeScreenViewModel.initiate()
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@@ -206,6 +236,28 @@ private fun HomeScreenPreview() {
|
||||
modifier = Modifier.padding(20.dp)
|
||||
) {
|
||||
HomeScreen(
|
||||
initialHomeScreenUIState = HomeScreenUIState.Loaded(
|
||||
profileWithFollowing = LocalProfileWithFollowing(
|
||||
nostrEvent = NostrEvent(
|
||||
id = "eventId",
|
||||
pubKey = "publicKey",
|
||||
content = """Lorem Ipsum is simply dummy text of the printing and typesetting industry.
|
||||
|
||||
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
|
||||
|
||||
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.""".trimIndent(),
|
||||
tags = emptyArray(),
|
||||
sig = "",
|
||||
kind = TextNoteEvent.KIND
|
||||
),
|
||||
profile = Profile(
|
||||
publicKey = "pubKey",
|
||||
displayName = "John Doe",
|
||||
nostrEventId = "nostrEventId"
|
||||
),
|
||||
following = emptyList()
|
||||
)
|
||||
),
|
||||
onNavigateToEvent = {},
|
||||
onNavigateToWriteNewNote = {},
|
||||
onNavigateToSearch = {},
|
||||
|
||||
@@ -35,7 +35,7 @@ enum class HomeScreenType {
|
||||
}
|
||||
|
||||
class HomeViewModel(
|
||||
val initialHomeScreenUIState: HomeScreenUIState = HomeScreenUIState.Loading,
|
||||
val initialHomeScreenUIState: HomeScreenUIState,
|
||||
val nostrRepository: NostrRepository,
|
||||
val pagerState: PagerState
|
||||
): ViewModel() {
|
||||
@@ -123,11 +123,13 @@ class HomeViewModel(
|
||||
const val TAG = "HomeViewModel"
|
||||
|
||||
fun factory(
|
||||
initialHomeScreenUIState: HomeScreenUIState,
|
||||
nostrRepository: NostrRepository,
|
||||
pagerState: PagerState
|
||||
): ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
HomeViewModel(
|
||||
initialHomeScreenUIState = initialHomeScreenUIState,
|
||||
nostrRepository = nostrRepository,
|
||||
pagerState = pagerState,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user