Migrating the UserProfile page to the new ViewModel structure
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.dal
|
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
|
||||||
import com.vitorpamplona.amethyst.service.model.PeopleListEvent
|
|
||||||
|
|
||||||
object PeopleListFeedFilter : FeedFilter<Note>() {
|
|
||||||
lateinit var account: Account
|
|
||||||
|
|
||||||
override fun feedKey(): String {
|
|
||||||
return account.userProfile().pubkeyHex
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
|
||||||
val privKey = account.loggedIn.privKey ?: return emptyList()
|
|
||||||
|
|
||||||
val lists = LocalCache.addressables.values
|
|
||||||
.asSequence()
|
|
||||||
.filter {
|
|
||||||
(it.event is PeopleListEvent)
|
|
||||||
}
|
|
||||||
.toSet()
|
|
||||||
|
|
||||||
return lists
|
|
||||||
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
|
||||||
.reversed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+4
-12
@@ -5,25 +5,17 @@ import com.vitorpamplona.amethyst.model.LocalCache
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
|
|
||||||
object UserProfileBookmarksFeedFilter : FeedFilter<Note>() {
|
class UserProfileBookmarksFeedFilter(val user: User, val account: Account) : FeedFilter<Note>() {
|
||||||
lateinit var account: Account
|
|
||||||
var user: User? = null
|
|
||||||
|
|
||||||
override fun feedKey(): String {
|
override fun feedKey(): String {
|
||||||
return account.userProfile().pubkeyHex + "-" + user?.pubkeyHex
|
return account.userProfile().pubkeyHex + "-" + user.pubkeyHex
|
||||||
}
|
|
||||||
|
|
||||||
fun loadUserProfile(accountLoggedIn: Account, user: User?) {
|
|
||||||
account = accountLoggedIn
|
|
||||||
this.user = user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
val notes = user?.latestBookmarkList?.taggedEvents()?.mapNotNull {
|
val notes = user.latestBookmarkList?.taggedEvents()?.mapNotNull {
|
||||||
LocalCache.checkGetOrCreateNote(it)
|
LocalCache.checkGetOrCreateNote(it)
|
||||||
}?.toSet() ?: emptySet()
|
}?.toSet() ?: emptySet()
|
||||||
|
|
||||||
val addresses = user?.latestBookmarkList?.taggedAddresses()?.map {
|
val addresses = user.latestBookmarkList?.taggedAddresses()?.map {
|
||||||
LocalCache.getOrCreateAddressableNote(it)
|
LocalCache.getOrCreateAddressableNote(it)
|
||||||
}?.toSet() ?: emptySet()
|
}?.toSet() ?: emptySet()
|
||||||
|
|
||||||
|
|||||||
+6
-14
@@ -4,23 +4,15 @@ import com.vitorpamplona.amethyst.model.Account
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
|
|
||||||
object UserProfileConversationsFeedFilter : FeedFilter<Note>() {
|
class UserProfileConversationsFeedFilter(val user: User, val account: Account) : FeedFilter<Note>() {
|
||||||
var account: Account? = null
|
|
||||||
var user: User? = null
|
|
||||||
|
|
||||||
override fun feedKey(): String {
|
override fun feedKey(): String {
|
||||||
return account?.userProfile()?.pubkeyHex + "-" + user?.pubkeyHex
|
return account.userProfile().pubkeyHex + "-" + user.pubkeyHex
|
||||||
}
|
|
||||||
|
|
||||||
fun loadUserProfile(accountLoggedIn: Account, user: User?) {
|
|
||||||
account = accountLoggedIn
|
|
||||||
this.user = user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
return user?.notes
|
return user.notes
|
||||||
?.filter { account?.isAcceptable(it) == true && !it.isNewThread() }
|
.filter { account.isAcceptable(it) == true && !it.isNewThread() }
|
||||||
?.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
||||||
?.reversed() ?: emptyList()
|
.reversed() ?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-15
@@ -8,27 +8,19 @@ import com.vitorpamplona.amethyst.service.model.AppRecommendationEvent
|
|||||||
import com.vitorpamplona.amethyst.service.model.BookmarkListEvent
|
import com.vitorpamplona.amethyst.service.model.BookmarkListEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.PeopleListEvent
|
import com.vitorpamplona.amethyst.service.model.PeopleListEvent
|
||||||
|
|
||||||
object UserProfileNewThreadFeedFilter : FeedFilter<Note>() {
|
class UserProfileNewThreadFeedFilter(val user: User, val account: Account) : FeedFilter<Note>() {
|
||||||
var account: Account? = null
|
|
||||||
var user: User? = null
|
|
||||||
|
|
||||||
override fun feedKey(): String {
|
override fun feedKey(): String {
|
||||||
return account?.userProfile()?.pubkeyHex + "-" + user?.pubkeyHex
|
return account.userProfile().pubkeyHex + "-" + user.pubkeyHex
|
||||||
}
|
|
||||||
|
|
||||||
fun loadUserProfile(accountLoggedIn: Account, user: User) {
|
|
||||||
account = accountLoggedIn
|
|
||||||
this.user = user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
val longFormNotes = LocalCache.addressables.values
|
val longFormNotes = LocalCache.addressables.values
|
||||||
.filter { it.author == user && (it.event !is PeopleListEvent && it.event !is BookmarkListEvent && it.event !is AppRecommendationEvent) }
|
.filter { it.author == user && (it.event !is PeopleListEvent && it.event !is BookmarkListEvent && it.event !is AppRecommendationEvent) }
|
||||||
|
|
||||||
return user?.notes
|
return user.notes
|
||||||
?.plus(longFormNotes)
|
.plus(longFormNotes)
|
||||||
?.filter { account?.isAcceptable(it) == true && it.isNewThread() }
|
.filter { account.isAcceptable(it) == true && it.isNewThread() }
|
||||||
?.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
||||||
?.reversed() ?: emptyList()
|
.reversed() ?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-11
@@ -5,21 +5,13 @@ import com.vitorpamplona.amethyst.model.Note
|
|||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
import com.vitorpamplona.amethyst.service.model.ReportEvent
|
||||||
|
|
||||||
object UserProfileReportsFeedFilter : FeedFilter<Note>() {
|
class UserProfileReportsFeedFilter(val user: User) : FeedFilter<Note>() {
|
||||||
var user: User? = null
|
|
||||||
|
|
||||||
override fun feedKey(): String {
|
override fun feedKey(): String {
|
||||||
return user?.pubkeyHex ?: ""
|
return user.pubkeyHex ?: ""
|
||||||
}
|
|
||||||
|
|
||||||
fun loadUserProfile(user: User?) {
|
|
||||||
this.user = user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
val myUser = user ?: return emptyList()
|
val reportNotes = LocalCache.notes.values.filter { (it.event as? ReportEvent)?.isTaggedUser(user.pubkeyHex) == true }
|
||||||
|
|
||||||
val reportNotes = LocalCache.notes.values.filter { (it.event as? ReportEvent)?.isTaggedUser(myUser.pubkeyHex) == true }
|
|
||||||
|
|
||||||
return reportNotes
|
return reportNotes
|
||||||
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
||||||
|
|||||||
@@ -81,11 +81,38 @@ class NostrThreadFeedViewModel(val noteId: String) : FeedViewModel(ThreadFeedFil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NostrUserProfileNewThreadsFeedViewModel(val user: User, val account: Account) : FeedViewModel(UserProfileNewThreadFeedFilter(user, account)) {
|
||||||
|
class Factory(val user: User, val account: Account) : ViewModelProvider.Factory {
|
||||||
|
override fun <NostrUserProfileNewThreadsFeedViewModel : ViewModel> create(modelClass: Class<NostrUserProfileNewThreadsFeedViewModel>): NostrUserProfileNewThreadsFeedViewModel {
|
||||||
|
return NostrUserProfileNewThreadsFeedViewModel(user, account) as NostrUserProfileNewThreadsFeedViewModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class NostrUserProfileConversationsFeedViewModel(val user: User, val account: Account) : FeedViewModel(UserProfileConversationsFeedFilter(user, account)) {
|
||||||
|
class Factory(val user: User, val account: Account) : ViewModelProvider.Factory {
|
||||||
|
override fun <NostrUserProfileConversationsFeedViewModel : ViewModel> create(modelClass: Class<NostrUserProfileConversationsFeedViewModel>): NostrUserProfileConversationsFeedViewModel {
|
||||||
|
return NostrUserProfileConversationsFeedViewModel(user, account) as NostrUserProfileConversationsFeedViewModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class NostrHashtagFeedViewModel : FeedViewModel(HashtagFeedFilter)
|
class NostrHashtagFeedViewModel : FeedViewModel(HashtagFeedFilter)
|
||||||
class NostrUserProfileNewThreadsFeedViewModel : FeedViewModel(UserProfileNewThreadFeedFilter)
|
|
||||||
class NostrUserProfileConversationsFeedViewModel : FeedViewModel(UserProfileConversationsFeedFilter)
|
class NostrUserProfileReportFeedViewModel(val user: User) : FeedViewModel(UserProfileReportsFeedFilter(user)) {
|
||||||
class NostrUserProfileReportFeedViewModel : FeedViewModel(UserProfileReportsFeedFilter)
|
class Factory(val user: User) : ViewModelProvider.Factory {
|
||||||
class NostrUserProfileBookmarksFeedViewModel : FeedViewModel(UserProfileBookmarksFeedFilter)
|
override fun <NostrUserProfileReportFeedViewModel : ViewModel> create(modelClass: Class<NostrUserProfileReportFeedViewModel>): NostrUserProfileReportFeedViewModel {
|
||||||
|
return NostrUserProfileReportFeedViewModel(user) as NostrUserProfileReportFeedViewModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class NostrUserProfileBookmarksFeedViewModel(val user: User, val account: Account) : FeedViewModel(UserProfileBookmarksFeedFilter(user, account)) {
|
||||||
|
class Factory(val user: User, val account: Account) : ViewModelProvider.Factory {
|
||||||
|
override fun <NostrUserProfileBookmarksFeedViewModel : ViewModel> create(modelClass: Class<NostrUserProfileBookmarksFeedViewModel>): NostrUserProfileBookmarksFeedViewModel {
|
||||||
|
return NostrUserProfileBookmarksFeedViewModel(user, account) as NostrUserProfileBookmarksFeedViewModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class NostrChatroomListKnownFeedViewModel(val account: Account) : FeedViewModel(ChatroomListKnownFeedFilter(account)) {
|
class NostrChatroomListKnownFeedViewModel(val account: Account) : FeedViewModel(ChatroomListKnownFeedFilter(account)) {
|
||||||
class Factory(val account: Account) : ViewModelProvider.Factory {
|
class Factory(val account: Account) : ViewModelProvider.Factory {
|
||||||
override fun <NostrChatroomListKnownFeedViewModel : ViewModel> create(modelClass: Class<NostrChatroomListKnownFeedViewModel>): NostrChatroomListKnownFeedViewModel {
|
override fun <NostrChatroomListKnownFeedViewModel : ViewModel> create(modelClass: Class<NostrChatroomListKnownFeedViewModel>): NostrChatroomListKnownFeedViewModel {
|
||||||
|
|||||||
@@ -76,9 +76,6 @@ import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
|||||||
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
|
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
|
||||||
import com.vitorpamplona.amethyst.ui.components.figureOutMimeType
|
import com.vitorpamplona.amethyst.ui.components.figureOutMimeType
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileBookmarksFeedFilter
|
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileConversationsFeedFilter
|
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileNewThreadFeedFilter
|
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.ShowQRDialog
|
import com.vitorpamplona.amethyst.ui.navigation.ShowQRDialog
|
||||||
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
|
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
|
||||||
@@ -165,33 +162,66 @@ fun PrepareViewModels(baseUser: User, accountViewModel: AccountViewModel, nav: (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val threadsViewModel: NostrUserProfileNewThreadsFeedViewModel = viewModel(
|
||||||
|
key = baseUser.pubkeyHex + "UserProfileNewThreadsFeedViewModel",
|
||||||
|
factory = NostrUserProfileNewThreadsFeedViewModel.Factory(
|
||||||
|
baseUser,
|
||||||
|
accountViewModel.account
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val repliesViewModel: NostrUserProfileConversationsFeedViewModel = viewModel(
|
||||||
|
key = baseUser.pubkeyHex + "UserProfileConversationsFeedViewModel",
|
||||||
|
factory = NostrUserProfileConversationsFeedViewModel.Factory(
|
||||||
|
baseUser,
|
||||||
|
accountViewModel.account
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val bookmarksFeedViewModel: NostrUserProfileBookmarksFeedViewModel = viewModel(
|
||||||
|
key = baseUser.pubkeyHex + "UserProfileBookmarksFeedViewModel",
|
||||||
|
factory = NostrUserProfileBookmarksFeedViewModel.Factory(
|
||||||
|
baseUser,
|
||||||
|
accountViewModel.account
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val reportsFeedViewModel: NostrUserProfileReportFeedViewModel = viewModel(
|
||||||
|
key = baseUser.pubkeyHex + "UserProfileReportFeedViewModel",
|
||||||
|
factory = NostrUserProfileReportFeedViewModel.Factory(
|
||||||
|
baseUser
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
ProfileScreen(
|
ProfileScreen(
|
||||||
baseUser = baseUser,
|
baseUser = baseUser,
|
||||||
|
threadsViewModel,
|
||||||
|
repliesViewModel,
|
||||||
followsFeedViewModel,
|
followsFeedViewModel,
|
||||||
followersFeedViewModel,
|
followersFeedViewModel,
|
||||||
appRecommendations,
|
appRecommendations,
|
||||||
zapFeedViewModel,
|
zapFeedViewModel,
|
||||||
|
bookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav
|
nav = nav
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProfileScreen(
|
fun ProfileScreen(
|
||||||
baseUser: User,
|
baseUser: User,
|
||||||
|
threadsViewModel: NostrUserProfileNewThreadsFeedViewModel,
|
||||||
|
repliesViewModel: NostrUserProfileConversationsFeedViewModel,
|
||||||
followsFeedViewModel: NostrUserProfileFollowsUserFeedViewModel,
|
followsFeedViewModel: NostrUserProfileFollowsUserFeedViewModel,
|
||||||
followersFeedViewModel: NostrUserProfileFollowersUserFeedViewModel,
|
followersFeedViewModel: NostrUserProfileFollowersUserFeedViewModel,
|
||||||
appRecommendations: NostrUserAppRecommendationsFeedViewModel,
|
appRecommendations: NostrUserAppRecommendationsFeedViewModel,
|
||||||
zapFeedViewModel: NostrUserProfileZapsFeedViewModel,
|
zapFeedViewModel: NostrUserProfileZapsFeedViewModel,
|
||||||
|
bookmarksFeedViewModel: NostrUserProfileBookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel: NostrUserProfileReportFeedViewModel,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
UserProfileNewThreadFeedFilter.loadUserProfile(accountViewModel.account, baseUser)
|
|
||||||
UserProfileConversationsFeedFilter.loadUserProfile(accountViewModel.account, baseUser)
|
|
||||||
UserProfileReportsFeedFilter.loadUserProfile(baseUser)
|
|
||||||
UserProfileBookmarksFeedFilter.loadUserProfile(accountViewModel.account, baseUser)
|
|
||||||
|
|
||||||
NostrUserProfileDataSource.loadUserProfile(baseUser)
|
NostrUserProfileDataSource.loadUserProfile(baseUser)
|
||||||
|
|
||||||
val lifeCycleOwner = LocalLifecycleOwner.current
|
val lifeCycleOwner = LocalLifecycleOwner.current
|
||||||
@@ -223,16 +253,42 @@ fun ProfileScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var columnSize by remember { mutableStateOf(IntSize.Zero) }
|
RenderSurface(
|
||||||
var tabsSize by remember { mutableStateOf(IntSize.Zero) }
|
baseUser,
|
||||||
|
threadsViewModel,
|
||||||
|
repliesViewModel,
|
||||||
|
appRecommendations,
|
||||||
|
followsFeedViewModel,
|
||||||
|
followersFeedViewModel,
|
||||||
|
zapFeedViewModel,
|
||||||
|
bookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel,
|
||||||
|
accountViewModel,
|
||||||
|
nav
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
private fun RenderSurface(
|
||||||
|
baseUser: User,
|
||||||
|
threadsViewModel: NostrUserProfileNewThreadsFeedViewModel,
|
||||||
|
repliesViewModel: NostrUserProfileConversationsFeedViewModel,
|
||||||
|
appRecommendations: NostrUserAppRecommendationsFeedViewModel,
|
||||||
|
followsFeedViewModel: NostrUserProfileFollowsUserFeedViewModel,
|
||||||
|
followersFeedViewModel: NostrUserProfileFollowersUserFeedViewModel,
|
||||||
|
zapFeedViewModel: NostrUserProfileZapsFeedViewModel,
|
||||||
|
bookmarksFeedViewModel: NostrUserProfileBookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel: NostrUserProfileReportFeedViewModel,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: (String) -> Unit
|
||||||
|
) {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
color = MaterialTheme.colors.background
|
color = MaterialTheme.colors.background
|
||||||
) {
|
) {
|
||||||
val pagerState = rememberPagerState()
|
var columnSize by remember { mutableStateOf(IntSize.Zero) }
|
||||||
val coroutineScope = rememberCoroutineScope()
|
var tabsSize by remember { mutableStateOf(IntSize.Zero) }
|
||||||
val scrollState = rememberScrollState()
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -241,8 +297,23 @@ fun ProfileScreen(
|
|||||||
columnSize = it
|
columnSize = it
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
val pagerState = rememberPagerState()
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val scrollState = rememberScrollState()
|
||||||
|
|
||||||
|
val tabRowModifier = remember {
|
||||||
|
Modifier.onSizeChanged {
|
||||||
|
tabsSize = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val pagerModifier = with(LocalDensity.current) {
|
||||||
|
Modifier.height((columnSize.height - tabsSize.height).toDp())
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = remember {
|
||||||
|
Modifier
|
||||||
.verticalScroll(scrollState)
|
.verticalScroll(scrollState)
|
||||||
.nestedScroll(object : NestedScrollConnection {
|
.nestedScroll(object : NestedScrollConnection {
|
||||||
override fun onPreScroll(
|
override fun onPreScroll(
|
||||||
@@ -261,38 +332,75 @@ fun ProfileScreen(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
) {
|
|
||||||
Column() {
|
|
||||||
ProfileHeader(baseUser, appRecommendations, nav, accountViewModel)
|
|
||||||
ScrollableTabRow(
|
|
||||||
backgroundColor = MaterialTheme.colors.background,
|
|
||||||
selectedTabIndex = pagerState.currentPage,
|
|
||||||
edgePadding = 8.dp,
|
|
||||||
modifier = Modifier.onSizeChanged {
|
|
||||||
tabsSize = it
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
CreateAndRenderTabs(baseUser, pagerState)
|
RenderScreen(
|
||||||
}
|
|
||||||
HorizontalPager(
|
|
||||||
pageCount = 8,
|
|
||||||
state = pagerState,
|
|
||||||
modifier = with(LocalDensity.current) {
|
|
||||||
Modifier.height((columnSize.height - tabsSize.height).toDp())
|
|
||||||
}
|
|
||||||
) { page ->
|
|
||||||
CreateAndRenderPages(
|
|
||||||
page,
|
|
||||||
baseUser,
|
baseUser,
|
||||||
|
pagerState,
|
||||||
|
tabRowModifier,
|
||||||
|
pagerModifier,
|
||||||
|
threadsViewModel,
|
||||||
|
repliesViewModel,
|
||||||
|
appRecommendations,
|
||||||
followsFeedViewModel,
|
followsFeedViewModel,
|
||||||
followersFeedViewModel,
|
followersFeedViewModel,
|
||||||
zapFeedViewModel,
|
zapFeedViewModel,
|
||||||
|
bookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav
|
nav
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
private fun RenderScreen(
|
||||||
|
baseUser: User,
|
||||||
|
pagerState: PagerState,
|
||||||
|
tabRowModifier: Modifier,
|
||||||
|
pagerModifier: Modifier,
|
||||||
|
threadsViewModel: NostrUserProfileNewThreadsFeedViewModel,
|
||||||
|
repliesViewModel: NostrUserProfileConversationsFeedViewModel,
|
||||||
|
appRecommendations: NostrUserAppRecommendationsFeedViewModel,
|
||||||
|
followsFeedViewModel: NostrUserProfileFollowsUserFeedViewModel,
|
||||||
|
followersFeedViewModel: NostrUserProfileFollowersUserFeedViewModel,
|
||||||
|
zapFeedViewModel: NostrUserProfileZapsFeedViewModel,
|
||||||
|
bookmarksFeedViewModel: NostrUserProfileBookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel: NostrUserProfileReportFeedViewModel,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: (String) -> Unit
|
||||||
|
) {
|
||||||
|
Column() {
|
||||||
|
ProfileHeader(baseUser, appRecommendations, nav, accountViewModel)
|
||||||
|
ScrollableTabRow(
|
||||||
|
backgroundColor = MaterialTheme.colors.background,
|
||||||
|
selectedTabIndex = pagerState.currentPage,
|
||||||
|
edgePadding = 8.dp,
|
||||||
|
modifier = tabRowModifier
|
||||||
|
) {
|
||||||
|
CreateAndRenderTabs(baseUser, pagerState)
|
||||||
|
}
|
||||||
|
HorizontalPager(
|
||||||
|
pageCount = 8,
|
||||||
|
state = pagerState,
|
||||||
|
modifier = pagerModifier
|
||||||
|
) { page ->
|
||||||
|
CreateAndRenderPages(
|
||||||
|
page,
|
||||||
|
baseUser,
|
||||||
|
threadsViewModel,
|
||||||
|
repliesViewModel,
|
||||||
|
followsFeedViewModel,
|
||||||
|
followersFeedViewModel,
|
||||||
|
zapFeedViewModel,
|
||||||
|
bookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel,
|
||||||
|
accountViewModel,
|
||||||
|
nav
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,20 +409,24 @@ fun ProfileScreen(
|
|||||||
private fun CreateAndRenderPages(
|
private fun CreateAndRenderPages(
|
||||||
page: Int,
|
page: Int,
|
||||||
baseUser: User,
|
baseUser: User,
|
||||||
|
threadsViewModel: NostrUserProfileNewThreadsFeedViewModel,
|
||||||
|
repliesViewModel: NostrUserProfileConversationsFeedViewModel,
|
||||||
followsFeedViewModel: NostrUserProfileFollowsUserFeedViewModel,
|
followsFeedViewModel: NostrUserProfileFollowsUserFeedViewModel,
|
||||||
followersFeedViewModel: NostrUserProfileFollowersUserFeedViewModel,
|
followersFeedViewModel: NostrUserProfileFollowersUserFeedViewModel,
|
||||||
zapFeedViewModel: NostrUserProfileZapsFeedViewModel,
|
zapFeedViewModel: NostrUserProfileZapsFeedViewModel,
|
||||||
|
bookmarksFeedViewModel: NostrUserProfileBookmarksFeedViewModel,
|
||||||
|
reportsFeedViewModel: NostrUserProfileReportFeedViewModel,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
when (page) {
|
when (page) {
|
||||||
0 -> TabNotesNewThreads(accountViewModel, nav)
|
0 -> TabNotesNewThreads(threadsViewModel, accountViewModel, nav)
|
||||||
1 -> TabNotesConversations(accountViewModel, nav)
|
1 -> TabNotesConversations(repliesViewModel, accountViewModel, nav)
|
||||||
2 -> TabFollows(baseUser, followsFeedViewModel, accountViewModel, nav)
|
2 -> TabFollows(baseUser, followsFeedViewModel, accountViewModel, nav)
|
||||||
3 -> TabFollowers(baseUser, followersFeedViewModel, accountViewModel, nav)
|
3 -> TabFollowers(baseUser, followersFeedViewModel, accountViewModel, nav)
|
||||||
4 -> TabReceivedZaps(baseUser, zapFeedViewModel, accountViewModel, nav)
|
4 -> TabReceivedZaps(baseUser, zapFeedViewModel, accountViewModel, nav)
|
||||||
5 -> TabBookmarks(baseUser, accountViewModel, nav)
|
5 -> TabBookmarks(bookmarksFeedViewModel, accountViewModel, nav)
|
||||||
6 -> TabReports(baseUser, accountViewModel, nav)
|
6 -> TabReports(baseUser, reportsFeedViewModel, accountViewModel, nav)
|
||||||
7 -> TabRelays(baseUser, accountViewModel, nav)
|
7 -> TabRelays(baseUser, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,8 +479,7 @@ private fun ReportsTabHeader(baseUser: User) {
|
|||||||
|
|
||||||
LaunchedEffect(key1 = userState) {
|
LaunchedEffect(key1 = userState) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
UserProfileReportsFeedFilter.user = baseUser
|
val newSize = UserProfileReportsFeedFilter(baseUser).feed().size
|
||||||
val newSize = UserProfileReportsFeedFilter.feed().size
|
|
||||||
|
|
||||||
if (newSize != userReports) {
|
if (newSize != userReports) {
|
||||||
userReports = newSize
|
userReports = newSize
|
||||||
@@ -1125,9 +1236,7 @@ public fun DrawBanner(baseUser: User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TabNotesNewThreads(accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
fun TabNotesNewThreads(feedViewModel: NostrUserProfileNewThreadsFeedViewModel, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
||||||
val feedViewModel: NostrUserProfileNewThreadsFeedViewModel = viewModel()
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.invalidateData()
|
feedViewModel.invalidateData()
|
||||||
}
|
}
|
||||||
@@ -1148,9 +1257,7 @@ fun TabNotesNewThreads(accountViewModel: AccountViewModel, nav: (String) -> Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TabNotesConversations(accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
fun TabNotesConversations(feedViewModel: NostrUserProfileConversationsFeedViewModel, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
||||||
val feedViewModel: NostrUserProfileConversationsFeedViewModel = viewModel()
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.invalidateData()
|
feedViewModel.invalidateData()
|
||||||
}
|
}
|
||||||
@@ -1171,9 +1278,7 @@ fun TabNotesConversations(accountViewModel: AccountViewModel, nav: (String) -> U
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TabBookmarks(baseUser: User, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
fun TabBookmarks(feedViewModel: NostrUserProfileBookmarksFeedViewModel, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
||||||
val feedViewModel: NostrUserProfileBookmarksFeedViewModel = viewModel()
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
feedViewModel.invalidateData()
|
feedViewModel.invalidateData()
|
||||||
}
|
}
|
||||||
@@ -1263,9 +1368,7 @@ private fun WatchZapsAndUpdateFeed(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TabReports(baseUser: User, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
fun TabReports(baseUser: User, feedViewModel: NostrUserProfileReportFeedViewModel, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
||||||
val feedViewModel: NostrUserProfileReportFeedViewModel = viewModel()
|
|
||||||
|
|
||||||
WatchReportsAndUpdateFeed(baseUser, feedViewModel)
|
WatchReportsAndUpdateFeed(baseUser, feedViewModel)
|
||||||
|
|
||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user