Skip to content

Commit

Permalink
chore: apply 4.0.0-beta28 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaing committed Dec 6, 2024
1 parent a691acf commit aefd375
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 84 deletions.
2 changes: 1 addition & 1 deletion buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
amityMockkVersion = "1.10.0"
amitySDKJitpackDependency = 'com.github.AmityCo.Amity-Social-Cloud-SDK-Android'
amitySDKMavenDependency = 'co.amity.android'
amityMessagingSdkVersion = '6.46.0'
amityMessagingSdkVersion = '6.47.0'
amitySDKDependency = amitySDKMavenDependency
amityRxLifeCycleVersion = '1.1.2-beta01'
amityJacocoVersion = '0.8.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.amity.socialcloud.uikit.community.compose.search.components.AmityUser
import com.amity.socialcloud.uikit.community.compose.search.global.AmitySocialGlobalSearchPageBehavior
import com.amity.socialcloud.uikit.community.compose.socialhome.AmitySocialHomePageBehavior
import com.amity.socialcloud.uikit.community.compose.socialhome.components.AmityCreatePostMenuComponentBehavior
import com.amity.socialcloud.uikit.community.compose.socialhome.components.AmityExploreComponentBehavior
import com.amity.socialcloud.uikit.community.compose.socialhome.components.AmityGlobalFeedComponentBehavior
import com.amity.socialcloud.uikit.community.compose.socialhome.components.AmityMyCommunitiesComponentBehavior
import com.amity.socialcloud.uikit.community.compose.socialhome.components.AmitySocialHomeTopNavigationComponentBehavior
Expand Down Expand Up @@ -124,6 +125,8 @@ object AmitySocialBehaviorHelper {
var pendingPostContentComponentBehavior: AmityPendingPostContentComponentBehavior =
AmityPendingPostContentComponentBehavior()

var exploreComponentBehavior: AmityExploreComponentBehavior = AmityExploreComponentBehavior()

var commentTrayComponentBehavior: AmityCommentTrayComponentBehavior =
AmityCommentTrayComponentBehavior()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -50,8 +51,8 @@ import com.amity.socialcloud.uikit.common.ui.scope.AmityComposePageScope
import com.amity.socialcloud.uikit.common.ui.theme.AmityTheme
import com.amity.socialcloud.uikit.common.utils.clickableWithoutRipple
import com.amity.socialcloud.uikit.common.utils.getIcon
import com.amity.socialcloud.uikit.community.compose.AmitySocialBehaviorHelper
import com.amity.socialcloud.uikit.community.compose.community.membership.element.AmityCommunityJoinButton
import com.amity.socialcloud.uikit.community.compose.community.profile.AmityCommunityProfilePageActivity
import com.amity.socialcloud.uikit.community.compose.socialhome.elements.AmityCommunityCategoryView
import com.amity.socialcloud.uikit.community.compose.ui.shimmer.AmityRecommendedCommunityShimmer
import kotlinx.coroutines.Dispatchers
Expand All @@ -61,17 +62,25 @@ import kotlinx.coroutines.Dispatchers
fun AmityRecommendedCommunitiesComponent(
modifier: Modifier = Modifier,
pageScope: AmityComposePageScope? = null,
onStateChanged: (AmityRecommendedCommunitiesViewModel.CommunityListState) -> Unit = {}
onStateChanged: (AmityRecommendedCommunitiesViewModel.CommunityListState) -> Unit = {},
) {
val context = LocalContext.current
val behavior by lazy {
AmitySocialBehaviorHelper.exploreComponentBehavior
}

val viewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) {
"No ViewModelStoreOwner was provided via LocalViewModelStoreOwner"
}
val viewModel =
viewModel<AmityRecommendedCommunitiesViewModel>(viewModelStoreOwner = viewModelStoreOwner)

val communities = viewModel.getRecommendedCommunities().collectAsState(initial = emptyList())
// Remember the Flow of communities
val communitiesFlow = remember {
viewModel.getRecommendedCommunities()
}

val communities = communitiesFlow.collectAsState(initial = emptyList())
val communityListState by viewModel.communityListState.collectAsState()

AmityBaseComponent(
Expand Down Expand Up @@ -115,13 +124,11 @@ fun AmityRecommendedCommunitiesComponent(
componentScope = getComponentScope(),
community = community,
onClick = {
val intent =
AmityCommunityProfilePageActivity.newIntent(
context = context,
communityId = community.getCommunityId()
)
context.startActivity(intent)
}
behavior.goToCommunityProfilePage(
context = context,
communityId = community.getCommunityId(),
)
},
)
}
}
Expand Down Expand Up @@ -347,7 +354,6 @@ fun AmityRecommendedCommunityView(
)
}
}

AmityBaseElement(
pageScope = pageScope,
componentScope = componentScope,
Expand All @@ -366,15 +372,12 @@ fun AmityRecommendedCommunityView(
}
}

Column(

) {
Column {
Spacer(modifier = Modifier.weight(1f))
AmityCommunityJoinButton(
community = community
)
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.amity.socialcloud.uikit.community.compose.community.trending

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -21,98 +20,88 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.amity.socialcloud.uikit.common.ui.base.AmityBaseComponent
import com.amity.socialcloud.uikit.common.ui.scope.AmityComposePageScope
import com.amity.socialcloud.uikit.common.ui.theme.AmityTheme
import com.amity.socialcloud.uikit.community.compose.community.profile.AmityCommunityProfilePageActivity
import com.amity.socialcloud.uikit.community.compose.AmitySocialBehaviorHelper
import com.amity.socialcloud.uikit.community.compose.socialhome.elements.AmityJoinCommunityView
import com.amity.socialcloud.uikit.community.compose.ui.shimmer.AmityTrendingCommunityShimmer


@Composable
fun AmityTrendingCommunitiesComponent(
modifier: Modifier = Modifier,
pageScope: AmityComposePageScope? = null,
onStateChanged: (AmityTrendingCommunitiesViewModel.CommunityListState) -> Unit = {}
onStateChanged: (AmityTrendingCommunitiesViewModel.CommunityListState) -> Unit = {},
) {
val context = LocalContext.current
val behavior by lazy {
AmitySocialBehaviorHelper.exploreComponentBehavior
}

val viewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) {
"No ViewModelStoreOwner was provided via LocalViewModelStoreOwner"
}
val viewModel =
viewModel<AmityTrendingCommunitiesViewModel>(viewModelStoreOwner = viewModelStoreOwner)

val communities = viewModel.getTrendingCommunities().collectAsState(initial = emptyList())
// Remember the Flow of communities to prevent recreating on recomposition
val communitiesFlow = remember {
viewModel.getTrendingCommunities()
}

val communities = communitiesFlow.collectAsState(initial = emptyList())
val communityListState by viewModel.communityListState.collectAsState()

AmityBaseComponent(
pageScope = pageScope,
componentId = "trending_communities"
) {
LazyColumn(
modifier = modifier
.fillMaxWidth()
.heightIn(min = 0.dp, max = 554.dp)
.padding(horizontal = 16.dp)
Column(
modifier = modifier.fillMaxWidth()
) {
when (communityListState) {
AmityTrendingCommunitiesViewModel.CommunityListState.SUCCESS -> {
item {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.height(38.dp)
) {
Text(
text = "Trending now",
style = AmityTheme.typography.title
)
}
}
item {
Spacer(modifier = modifier.height(8.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.height(38.dp)
.padding(horizontal = 16.dp)
) {
Text(
text = "Trending now",
style = AmityTheme.typography.title
)
}
items(
count = communities.value.size,
key = { index -> index }
) { index ->
val community = communities.value[index]

communities.value.forEachIndexed { index, community ->
AmityJoinCommunityView(
modifier = modifier,
pageScope = pageScope,
componentScope = getComponentScope(),
community = community,
label = "0" + (index + 1),
onClick = {
val intent =
AmityCommunityProfilePageActivity.newIntent(
context = context,
communityId = community.getCommunityId()
)
context.startActivity(intent)
})

Spacer(modifier = modifier.height(8.dp))
if (index < communities.value.size - 1) {
HorizontalDivider(
color = AmityTheme.colors.divider
)
Spacer(modifier = modifier.height(8.dp))
}
behavior.goToCommunityProfilePage(
context = context,
communityId = community.getCommunityId(),
)
},
)
}
}

AmityTrendingCommunitiesViewModel.CommunityListState.LOADING -> {
item {
AmityTrendingCommunityShimmer()
}
AmityTrendingCommunityShimmer()
}

AmityTrendingCommunitiesViewModel.CommunityListState.EMPTY -> {

// Empty state handler if needed
}

AmityTrendingCommunitiesViewModel.CommunityListState.ERROR -> {

// Error state handler if needed
}

}
Spacer(modifier = modifier.height(100.dp))
onStateChanged(communityListState)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -33,7 +34,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
Expand Down Expand Up @@ -80,7 +80,6 @@ fun AmityExploreComponent(
}
)

val scrollState = rememberScrollState()

Box(
modifier = modifier
Expand All @@ -91,19 +90,21 @@ fun AmityExploreComponent(
Column {
AmityNewsFeedDivider()
AmityExploreCategoryShimmer(
modifier = Modifier.padding(
start = 16.dp,
top = 16.dp,
bottom = 16.dp,
end = 0.dp
)
modifier = Modifier
.fillMaxWidth()
.padding(
start = 16.dp,
top = 16.dp,
bottom = 16.dp,
end = 0.dp
)
)
AmityRecommendedCommunityShimmer()
AmityTrendingCommunityShimmer(modifier = Modifier.padding(start = 16.dp))
}
} else {
Column(
modifier = Modifier.verticalScroll(scrollState)
modifier = Modifier.verticalScroll(rememberScrollState())
) {
AmityNewsFeedDivider()
AmityCommunityCategoriesComponent(
Expand Down Expand Up @@ -222,29 +223,30 @@ fun AmityExploreComponent(
text = "Something went wrong",
modifier = Modifier.padding(top = 16.dp),
style = AmityTheme.typography.title.copy(
color = AmityTheme.colors.baseShade3
color = AmityTheme.colors.baseShade3,
)
)
Text(
text = "Please try again.",
modifier = Modifier.padding(top = 4.dp),
style = AmityTheme.typography.caption.copy(
color = AmityTheme.colors.baseShade3
color = AmityTheme.colors.baseShade3,
)
)
}
}

AmityRecommendedCommunitiesComponent(
pageScope = pageScope,
onStateChanged = {
viewModel.setRecommendedState(it)
}
},
)
AmityTrendingCommunitiesComponent(
pageScope = pageScope,
onStateChanged = {
viewModel.setTrendingState(it)
}
},
)
}
PullRefreshIndicator(
Expand All @@ -254,10 +256,4 @@ fun AmityExploreComponent(
)
}
}
}

@Preview(showBackground = true)
@Composable
fun AmityExploreComponentPreview() {
AmityExploreComponent()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.amity.socialcloud.uikit.community.compose.socialhome.components

import android.content.Context
import android.content.Intent
import androidx.activity.result.ActivityResultLauncher
import com.amity.socialcloud.uikit.community.compose.community.profile.AmityCommunityProfilePageActivity

open class AmityExploreComponentBehavior {

open fun goToCommunityProfilePage(
context: Context,
communityId: String
) {
val intent = AmityCommunityProfilePageActivity.newIntent(
context = context,
communityId = communityId
)
context.startActivity(intent)
}
}

0 comments on commit aefd375

Please sign in to comment.