Skip to content

Commit

Permalink
Merge pull request #29 from AmityCo/release-furies
Browse files Browse the repository at this point in the history
chore: add furies source code
  • Loading branch information
Enixma authored Mar 30, 2023
2 parents f1e848e + 407a133 commit 78443d8
Show file tree
Hide file tree
Showing 337 changed files with 2,841 additions and 2,605 deletions.
4 changes: 2 additions & 2 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3324,8 +3324,8 @@
<ID>UnusedImports:AmityCommunityBaseNotificationSettingsFragment.kt$import androidx.appcompat.app.AppCompatActivity</ID>
<ID>UnusedImports:AmityFollowersBaseViewHolder.kt$import android.content.DialogInterface</ID>
<ID>UnusedImports:AmityFollowersBaseViewHolder.kt$import com.amity.socialcloud.uikit.common.utils.AmityAlertDialogUtil</ID>
<ID>UnusedImports:AmityFollowersBaseViewHolder.kt$import io.reactivex.android.schedulers.AndroidSchedulers</ID>
<ID>UnusedImports:AmityFollowersBaseViewHolder.kt$import io.reactivex.schedulers.Schedulers</ID>
<ID>UnusedImports:AmityFollowersBaseViewHolder.kt$import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers</ID>
<ID>UnusedImports:AmityFollowersBaseViewHolder.kt$import io.reactivex.rxjava3.schedulers.Schedulers</ID>
<ID>UnusedImports:AmityMessageListActivity.kt$import com.amity.socialcloud.uikit.chat.messages.fragment.AmityChatRoomWithTextComposeBarFragment</ID>
<ID>UnusedImports:AmityMessageListViewModel.kt$import com.amity.socialcloud.uikit.common.common.isNotEmptyOrBlank</ID>
<ID>UnusedImports:AmitySampleApp.kt$import android.view.View</ID>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
ext {
gradleBuildVersion = '4.2.2'
kotlinVersion = "1.4.21"
kotlinVersion = "1.7.20"
jacocoVersion = '0.8.5'
}
repositories {
Expand Down
4 changes: 2 additions & 2 deletions buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
amityKotlinVersion = "1.4.21"
amityLifecycleExtensionVersion = "2.0.0"
amityMockkVersion = "1.10.0"
amityMessagingSdkVersion = '5.30.0'
amityRxLifeCycleVersion = '1.1.1'
amityMessagingSdkVersion = '6.5.0'
amityRxLifeCycleVersion = '1.1.2-beta01'

amityJacocoVersion = '0.8.5'
amityExoplayerVersion = '2.16.1'
Expand Down
5 changes: 0 additions & 5 deletions buildsystem/submodule.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ dependencies {

testImplementation "io.mockk:mockk:$rootProject.amityMockkVersion"

// Rx Dependencies
implementation "io.reactivex.rxjava2:rxjava:2.2.19"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"

testImplementation "org.mockito:mockito-inline:3.5.13"

androidTestImplementation "org.mockito:mockito-inline:3.5.13"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import androidx.activity.viewModels
import androidx.appcompat.app.ActionBar
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import com.amity.socialcloud.sdk.chat.message.AmityMessage
import com.amity.socialcloud.sdk.model.chat.message.AmityMessage
import com.amity.socialcloud.uikit.chat.BR
import com.amity.socialcloud.uikit.chat.R
import com.amity.socialcloud.uikit.chat.databinding.AmityActivityEditMessageBinding
import com.amity.socialcloud.uikit.common.base.AmityBaseActivity
import io.reactivex.disposables.Disposable
import io.reactivex.rxjava3.disposables.Disposable

class AmityEditMessageActivity :
AmityBaseActivity<AmityActivityEditMessageBinding, AmityEditMessageViewModel>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.amity.socialcloud.uikit.chat.editMessage

import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import com.amity.socialcloud.sdk.chat.AmityChatClient
import com.amity.socialcloud.sdk.chat.message.AmityMessage
import com.amity.socialcloud.sdk.api.chat.AmityChatClient
import com.amity.socialcloud.sdk.model.chat.message.AmityMessage
import com.amity.socialcloud.uikit.common.base.AmityBaseViewModel
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Flowable

class AmityEditMessageViewModel : AmityBaseViewModel() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.amity.socialcloud.uikit.chat.home

import com.amity.socialcloud.sdk.chat.AmityChatClient
import com.amity.socialcloud.sdk.api.chat.AmityChatClient
import com.amity.socialcloud.uikit.chat.home.callback.AmityRecentChatFragmentDelegate
import com.amity.socialcloud.uikit.chat.home.callback.AmityRecentChatItemClickListener
import com.amity.socialcloud.uikit.common.base.AmityBaseViewModel
import com.amity.socialcloud.uikit.common.model.AmitySelectMemberItem
import io.reactivex.Completable
import io.reactivex.rxjava3.core.Completable

private const val MAX_CHANNEL_NAME_LENGTH = 90

Expand All @@ -20,9 +20,8 @@ class AmityChatHomePageViewModel : AmityBaseViewModel() {
onChatCreateFailed: () -> Unit
): Completable {
return AmityChatClient.newChannelRepository()
.createChannel()
.communityType()
.withDisplayName(displayName = createChatDisplayName(selectedMembers = selectedMembers))
.createChannel(displayName = createChatDisplayName(selectedMembers = selectedMembers))
.community()
.userIds(userIds = selectedMembers.map { it.id })
.build()
.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package com.amity.socialcloud.uikit.chat.messages.adapter

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.View
import androidx.core.net.toUri
import com.amity.socialcloud.uikit.chat.R
import com.amity.socialcloud.uikit.chat.messages.viewHolder.AmityAudioMsgBaseViewHolder
import com.amity.socialcloud.uikit.common.common.showSnackBar
import com.amity.socialcloud.uikit.common.utils.AmityDateUtils
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.material.snackbar.Snackbar
import okhttp3.OkHttpClient

class AmityAudioMessageHelper(
private val context: Context
) {

private val TAG = "AmityAudioMessageHelper"

var playingMsgId = "-1"
private set

private var playingAmityAudioHolder: AmityAudioMsgBaseViewHolder? = null
private val uiUpdateHandler by lazy { Handler(Looper.getMainLooper()) }

private val uAmpAudioAttributes: AudioAttributes =
AudioAttributes.Builder()
.setContentType(C.CONTENT_TYPE_MUSIC)
.setUsage(C.USAGE_MEDIA)
.build()

private val exoPlayer by lazy {
ExoPlayer.Builder(context).build().apply {
setAudioAttributes(uAmpAudioAttributes, true)
setHandleAudioBecomingNoisy(true)
}
}

private val client: OkHttpClient by lazy {
OkHttpClient.Builder().build()
}

private val okHttpDataSourceFactory: OkHttpDataSource.Factory by lazy {
OkHttpDataSource.Factory(client).setUserAgent("USER_AGENT")
}

fun setPlayingAmityAudioHolder(holder: AmityAudioMsgBaseViewHolder?) {
this.playingAmityAudioHolder = holder
if (holder == null) {
updateNotPlayingState()
} else {
updatePlayingState()
}
}

fun playAudio(vh: AmityAudioMsgBaseViewHolder) {
if (!vh.audioMsgBaseViewModel.isPlaying.get()) {
resetMediaPlayer()
playingAmityAudioHolder?.audioMsgBaseViewModel?.isPlaying?.set(false)
playingAmityAudioHolder?.audioMsgBaseViewModel?.buffering?.set(false)
playingAmityAudioHolder = vh
}

exoPlayer.addListener(exoPlayerListener)

try {
if (exoPlayer.isPlaying) {
resetMediaPlayer()
updateNotPlayingState()
} else {
playingMsgId =
playingAmityAudioHolder?.audioMsgBaseViewModel?.amityMessage?.getMessageId()
?: "-1"
playingAmityAudioHolder?.audioMsgBaseViewModel?.buffering?.set(true)
val url: String =
playingAmityAudioHolder?.audioMsgBaseViewModel?.audioUrl?.get() ?: ""
val mediaItem = MediaItem.fromUri(url.toUri()).buildUpon().build()
val mediaSource = ProgressiveMediaSource.Factory(okHttpDataSourceFactory)
.createMediaSource(mediaItem)
exoPlayer.setMediaSource(mediaSource)
exoPlayer.prepare()
exoPlayer.playWhenReady = true
}
} catch (ex: Exception) {
Log.e(TAG, "playAudio: ${ex.localizedMessage}")
}
}

fun audioMessageDeleted() {
playingAmityAudioHolder?.audioMsgBaseViewModel?.isPlaying?.set(false)
playingAmityAudioHolder = null
resetMediaPlayer()
uiUpdateHandler.removeCallbacks(updateSeekBar)
}

private fun resetMediaPlayer() {
playingMsgId = "-1"
try {
exoPlayer.pause()
} catch (e: IllegalStateException) {
Log.e(TAG, "resetMediaPlayer: ${e.localizedMessage}")
}
exoPlayer.clearMediaItems()
exoPlayer.stop()
}

fun pauseAndResetPlayer() {
playingAmityAudioHolder?.audioMsgBaseViewModel?.isPlaying?.set(false)
resetMediaPlayer()
uiUpdateHandler.removeCallbacks(updateSeekBar)
}

fun releaseMediaPlayer() {
exoPlayer.release()
}

private val exoPlayerListener = object : Player.Listener {
override fun onPlaybackStateChanged(playbackState: Int) {
when (playbackState) {
Player.STATE_READY -> {
updatePlayingState()
}
Player.STATE_ENDED -> {
exoPlayer.seekTo(0)
updateNotPlayingState()
playingAmityAudioHolder?.audioMsgBaseViewModel?.duration?.set("0:00")
exoPlayer.clearMediaItems()
exoPlayer.stop()
}
else -> super.onPlaybackStateChanged(playbackState)
}
}

override fun onPlayerError(error: PlaybackException) {
super.onPlayerError(error)
Log.e(TAG, "onPlayerError: ${error.printStackTrace()}")
playingAmityAudioHolder?.audioMsgBaseViewModel?.buffering?.set(false)
playingAmityAudioHolder?.itemView?.findViewById<View>(android.R.id.content)
?.showSnackBar(
context.getString(R.string.amity_playback_error),
Snackbar.LENGTH_SHORT
)
}
}

private val updateSeekBar = object : Runnable {
override fun run() {
val timeElapsed = exoPlayer.currentPosition
playingAmityAudioHolder?.audioMsgBaseViewModel?.duration?.set(
AmityDateUtils.getFormattedTimeForChat(timeElapsed.toInt())
)
uiUpdateHandler.postDelayed(this, 400L)
}
}

private fun updatePlayingState() {
playingAmityAudioHolder?.audioMsgBaseViewModel?.duration?.set(
AmityDateUtils.getFormattedTimeForChat(exoPlayer.duration.toInt())
)
playingAmityAudioHolder?.audioMsgBaseViewModel?.buffering?.set(false)
playingAmityAudioHolder?.audioMsgBaseViewModel?.isPlaying?.set(true)
uiUpdateHandler.post(updateSeekBar)
}

private fun updateNotPlayingState() {
playingAmityAudioHolder?.audioMsgBaseViewModel?.isPlaying?.set(false)
playingAmityAudioHolder?.audioMsgBaseViewModel?.buffering?.set(false)
uiUpdateHandler.removeCallbacks(updateSeekBar)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.amity.socialcloud.uikit.chat.messages.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.amity.socialcloud.sdk.AmityCoreClient
import com.amity.socialcloud.sdk.chat.message.AmityMessage
import com.amity.socialcloud.sdk.api.core.AmityCoreClient
import com.amity.socialcloud.sdk.model.chat.message.AmityMessage
import com.amity.socialcloud.uikit.chat.R
import com.amity.socialcloud.uikit.chat.messages.viewHolder.*
import com.amity.socialcloud.uikit.chat.messages.viewModel.AmityAudioMsgViewModel
Expand All @@ -18,7 +18,7 @@ class AmityMessageItemUtil {
inflater: LayoutInflater,
parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?,
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?,
messageItemListener: AmityMessageItemListener?,
audioPlayListener: AmityAudioPlayListener
): AmityChatMessageBaseViewHolder {
Expand Down Expand Up @@ -81,7 +81,7 @@ class AmityMessageItemUtil {
private fun getReceiverTextMsgViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
viewHolderListener.getViewHolder(inflater, parent, itemType)!!
Expand All @@ -99,7 +99,7 @@ class AmityMessageItemUtil {
private fun getSenderTextMsgViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?,
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?,
messageItemListener: AmityMessageItemListener?,
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
Expand All @@ -123,7 +123,7 @@ class AmityMessageItemUtil {
private fun getReceiverImageMsgViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
viewHolderListener.getViewHolder(inflater, parent, itemType)!!
Expand All @@ -142,7 +142,7 @@ class AmityMessageItemUtil {
private fun getSenderImageMsgViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
viewHolderListener.getViewHolder(inflater, parent, itemType)!!
Expand All @@ -160,7 +160,7 @@ class AmityMessageItemUtil {
private fun getReceiverAudioMsgViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?,
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?,
audioPlayListener: AmityAudioPlayListener
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
Expand All @@ -179,7 +179,7 @@ class AmityMessageItemUtil {
private fun getSenderAudioMsgViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?,
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?,
audioPlayListener: AmityAudioPlayListener
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class AmityMessageItemUtil {
private fun getSenderCustomMessageViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
viewHolderListener.getViewHolder(inflater, parent, itemType)!!
Expand All @@ -225,7 +225,7 @@ class AmityMessageItemUtil {
private fun getReceiverCustomMessageViewHolder(
inflater: LayoutInflater, parent: ViewGroup,
itemType: Int,
viewHolderListener: AmityMessageListAdapter.CustomViewHolderListener?
viewHolderListener: AmityMessagePagingAdapter.CustomViewHolderListener?
): AmityChatMessageBaseViewHolder {
return if (viewHolderListener?.getViewHolder(inflater, parent, itemType) != null) {
viewHolderListener.getViewHolder(inflater, parent, itemType)!!
Expand All @@ -243,7 +243,7 @@ class AmityMessageItemUtil {
if (message == null) {
return MessageType.MESSAGE_ID_UNKNOWN
}
return getContentType(message, message.getUserId() == AmityCoreClient.getUserId())
return getContentType(message, message.getCreatorId() == AmityCoreClient.getUserId())
}

private fun getContentType(message: AmityMessage, isSelf: Boolean): Int {
Expand Down
Loading

0 comments on commit 78443d8

Please sign in to comment.