Skip to content

Commit

Permalink
chore: apply 4.0.0-beta25 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
kornsitti committed Nov 22, 2024
1 parent 70580d4 commit a691acf
Show file tree
Hide file tree
Showing 28 changed files with 558 additions and 173 deletions.
2 changes: 1 addition & 1 deletion amity-uikit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ dependencies {
api project(path: ':social')
api project(path: ':chat')

api "co.amity.android:amity-sdk:$amityMessagingSdkVersion"
api "$amitySDKDependency:amity-sdk:$amityMessagingSdkVersion"
}
2 changes: 1 addition & 1 deletion buildsystem/activity.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {
// Glide dependencide
implementation 'com.github.bumptech.glide:glide:4.12.0'
kapt 'com.github.bumptech.glide:compiler:4.12.0'
api "co.amity.android:amity-sdk:$amityMessagingSdkVersion"
api "$amitySDKDependency:amity-sdk:$amityMessagingSdkVersion"

implementation 'com.github.chrisbanes:PhotoView:2.3.0'
}
5 changes: 4 additions & 1 deletion buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ buildscript {
amityKotlinVersion = "1.6.20"
amityLifecycleExtensionVersion = "2.0.0"
amityMockkVersion = "1.10.0"
amityMessagingSdkVersion = '6.45.0'
amitySDKJitpackDependency = 'com.github.AmityCo.Amity-Social-Cloud-SDK-Android'
amitySDKMavenDependency = 'co.amity.android'
amityMessagingSdkVersion = '6.46.0'
amitySDKDependency = amitySDKMavenDependency
amityRxLifeCycleVersion = '1.1.2-beta01'
amityJacocoVersion = '0.8.5'
amityExoplayerVersion = '2.18.5'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.amity.socialcloud.uikit.common.eventbus

import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow

object AmityUIKitSnackbar {

private val _snackbarMessage = MutableSharedFlow<String?>(1)
val snackbarMessage: SharedFlow<String?> = _snackbarMessage.asSharedFlow()

fun publishSnackbarMessage(message: String?) {
_snackbarMessage.tryEmit(message)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import androidx.annotation.DrawableRes
import androidx.compose.material3.SnackbarHostState
import com.amity.socialcloud.uikit.common.config.AmityUIKitConfig
import com.amity.socialcloud.uikit.common.config.AmityUIKitConfigController
import com.amity.socialcloud.uikit.common.eventbus.AmityUIKitSnackbar
import com.amity.socialcloud.uikit.common.ui.elements.AmityProgressSnackbarVisuals
import com.amity.socialcloud.uikit.common.ui.elements.AmitySnackbarVisuals
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

internal class AmityComposePageScopeImpl(
Expand All @@ -15,6 +17,17 @@ internal class AmityComposePageScopeImpl(
private val coroutineScope: CoroutineScope,
) : AmityComposePageScope {

init {
coroutineScope.launch {
AmityUIKitSnackbar.snackbarMessage.collectLatest { message ->
if (message != null) {
showSnackbar(message)
AmityUIKitSnackbar.publishSnackbarMessage(null)
}
}
}
}

override fun getId(): String {
return pageId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.ContextWrapper
import android.content.Intent
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.annotation.StringRes
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
Expand All @@ -20,6 +21,7 @@ import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.State
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
Expand All @@ -37,6 +39,8 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
Expand All @@ -48,6 +52,7 @@ import androidx.palette.graphics.Palette.Swatch
import com.amity.socialcloud.uikit.common.common.toDp
import com.amity.socialcloud.uikit.common.common.views.AmityColorPaletteUtil
import com.amity.socialcloud.uikit.common.common.views.AmityColorShade
import com.amity.socialcloud.uikit.common.compose.R
import com.amity.socialcloud.uikit.common.ui.theme.AmityTheme
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
Expand Down Expand Up @@ -226,4 +231,23 @@ fun measureTextWidth(text: String, style: TextStyle): Dp {
val textMeasurer = rememberTextMeasurer()
val widthInPixels = textMeasurer.measure(text, style).size.width
return with(LocalDensity.current) { widthInPixels.toDp() }
}

@Composable
@ReadOnlyComposable
fun amityStringResource(
configString: String = "",
@StringRes id: Int = R.string.empty_string,
): String {
LocalConfiguration.current
val resources = LocalContext.current.resources
return configString.ifEmpty { resources.getString(id) }
}

fun Context.amityStringResource(
configString: String = "",
@StringRes id: Int = R.string.empty_string,
): String {
val resources = this.resources
return configString.ifEmpty { resources.getString(id) }
}
4 changes: 4 additions & 0 deletions common-compose/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="empty_string" />
</resources>
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dependencies {
implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'

implementation "co.amity.android:amity-push-fcm:$amityMessagingSdkVersion"
implementation "$amitySDKDependency:amity-push-fcm:$amityMessagingSdkVersion"


implementation 'androidx.activity:activity-compose:1.7.0'
Expand Down
4 changes: 2 additions & 2 deletions social-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ dependencies {

implementation "androidx.camera:camera-view:1.2.2"
implementation "androidx.camera:camera-extensions:1.2.2"
implementation("co.amity.android:amity-video-publisher:$amityMessagingSdkVersion")
implementation("co.amity.android:amity-video-player:$amityMessagingSdkVersion")
implementation("$amitySDKDependency:amity-video-publisher:$amityMessagingSdkVersion")
implementation("$amitySDKDependency:amity-video-player:$amityMessagingSdkVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fun AmityCommunityJoinButton(
modifier: Modifier = Modifier,
community: AmityCommunity,
) {
var isJoined by remember {
var isJoined by remember(community.getCommunityId()) {
mutableStateOf(community.isJoined())
}
var isInProgress by remember {
var isInProgress by remember(community.getCommunityId()) {
mutableStateOf(false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.compose.collectAsLazyPagingItems
import com.amity.socialcloud.sdk.api.core.AmityCoreClient
import com.amity.socialcloud.sdk.api.social.AmitySocialClient
import com.amity.socialcloud.sdk.helper.core.coroutines.asFlow
import com.amity.socialcloud.sdk.model.core.permission.AmityPermission
import com.amity.socialcloud.sdk.model.social.community.AmityCommunityPostSettings
Expand All @@ -58,6 +59,7 @@ import com.amity.socialcloud.uikit.community.compose.paging.feed.community.amity
import com.amity.socialcloud.uikit.community.compose.post.detail.AmityPostCategory
import com.amity.socialcloud.uikit.community.compose.post.detail.components.AmityPostShimmer
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map

@OptIn(ExperimentalMaterialApi::class, ExperimentalFoundationApi::class)
@SuppressLint("UnrememberedMutableState")
Expand Down Expand Up @@ -106,6 +108,51 @@ fun AmityCommunityProfilePage(
}
.collectAsState(initial = false)

val hasManageStoryPermission by AmityCoreClient.hasPermission(AmityPermission.MANAGE_COMMUNITY_STORY)
.atCommunity(communityId)
.check()
.asFlow()
.catch {
emit(false)
}
.collectAsState(initial = false)

val allowAllUserStoryCreation by AmitySocialClient.getSettings()
.asFlow()
.map { it.getStorySettings().isAllowAllUserToCreateStory() }
.catch {
emit(false)
}
.collectAsState(initial = false)

val isOnlyAdminCanPost by remember(community?.getPostSettings()) {
derivedStateOf {
community?.getPostSettings() == AmityCommunityPostSettings.ADMIN_CAN_POST_ONLY
}
}

val shouldShowPostCreationButton by remember(
isOnlyAdminCanPost,
hasCreatePrivilege,
community?.isJoined()
) {
derivedStateOf {
(!isOnlyAdminCanPost || hasCreatePrivilege)
&& (community?.isJoined() == true)
}
}

val shouldShowStoryCreationButton by remember(
allowAllUserStoryCreation,
hasManageStoryPermission,
community?.isJoined()
) {
derivedStateOf {
(allowAllUserStoryCreation || hasManageStoryPermission)
&& (community?.isJoined() == true)
}
}

LaunchedEffect(state.isRefreshing) {
if (state.isRefreshing) {
announcementPosts.refresh()
Expand Down Expand Up @@ -216,7 +263,7 @@ fun AmityCommunityProfilePage(
}
when (selectedTabIndex) {
0 -> {
if(communityPosts.loadState.refresh == LoadState.Loading) {
if (communityPosts.loadState.refresh == LoadState.Loading) {
repeat(4) {
item {
AmityPostShimmer()
Expand Down Expand Up @@ -279,7 +326,8 @@ fun AmityCommunityProfilePage(
pageScope = getPageScope(),
elementId = "community_create_post_button",
) {
if((community != null && community!!.isJoined() && community!!.getPostSettings() != AmityCommunityPostSettings.ADMIN_CAN_POST_ONLY) || hasCreatePrivilege) {
if (shouldShowPostCreationButton || shouldShowStoryCreationButton) {

FloatingActionButton(
onClick = {
expanded = true
Expand All @@ -305,6 +353,8 @@ fun AmityCommunityProfilePage(
modifier = Modifier,
community = community!!,
shouldShow = expanded,
shouldShowPostCreationButton = shouldShowPostCreationButton,
shouldShowStoryCreationButton = shouldShowStoryCreationButton,
onDismiss = { expanded = false },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ fun AmityCommunityInfoView(
.height(20.dp)
.background(color = AmityTheme.colors.baseShade4)
) {}
Row(modifier = Modifier.clickable {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable {
community?.let{
behavior.goToMemberListPage(
AmityCommunityProfilePageBehavior.Context(
Expand Down
Loading

0 comments on commit a691acf

Please sign in to comment.