Skip to content

Commit

Permalink
Merge pull request #47 from AmityCo/release-3.13.0-sparta
Browse files Browse the repository at this point in the history
chore: Apply release 3.13.0 source code
  • Loading branch information
kornsitti authored Oct 6, 2023
2 parents 80c5472 + 5ae039f commit 743dcf8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 53 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
classpath 'com.google.gms:google-services:4.3.10'
classpath "com.google.firebase:firebase-crashlytics-gradle:2.9.9"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
amityKotlinVersion = "1.6.20"
amityLifecycleExtensionVersion = "2.0.0"
amityMockkVersion = "1.10.0"
amityMessagingSdkVersion = '6.17.0'
amityMessagingSdkVersion = '6.19.0'
amityRxLifeCycleVersion = '1.1.2-beta01'

amityJacocoVersion = '0.8.5'
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
compileSdkVersion 33
Expand All @@ -13,7 +14,7 @@ android {
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "3.8.0"
versionName "3.13.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -65,6 +66,8 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.9'

implementation 'com.google.firebase:firebase-messaging:23.1.2'
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.4.1'
implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0'

implementation 'com.f2prateek.rx.preferences2:rx-preferences:2.0.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open class AmityLivestreamVideoPlayerActivity : RxAppCompatActivity() {
setContentView(binding.root)
supportActionBar?.hide()
viewModel.streamId = intent.getStringExtra(EXTRA_STREAM_ID) ?: ""
getVideoURL()
prepareToStream()
observeInvalidStream()
}

Expand All @@ -45,18 +45,26 @@ open class AmityLivestreamVideoPlayerActivity : RxAppCompatActivity() {
super.onPause()
}

private fun getVideoURL() {
viewModel.getVideoURL(
onLoadURLSuccess = { startStreaming(it) },
onLoadURLError = { presentStreamLoadingError() })
private fun prepareToStream() {
viewModel.checkStreamStatus(
onValidStatus = {isLive ->
if(isLive) {
binding.liveTextview.visibility = View.VISIBLE
} else {
binding.liveTextview.visibility = View.INVISIBLE
}
startStreaming()
},
onInvalidStatus = { presentStreamLoadingError() }
)
.doOnError { presentStreamLoadingError() }
.untilLifecycleEnd(this)
.subscribe()
}

private fun startStreaming(liveStreamURL: String) {
private fun startStreaming() {
binding.videoPlayer.enableStopWhenPause()
binding.videoPlayer.play(viewModel.streamId, liveStreamURL)
binding.videoPlayer.play(viewModel.streamId)
}

private fun observeInvalidStream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ abstract class AmityFeedFragment : AmityBaseFragment() {
onClickFileItem(it.file)
}
is PostContentClickEvent.Livestream -> {
navigateToLivestreamPlayer(it.stream)
navigateToStreamPlayer(it.stream)
}
}
}
Expand All @@ -336,25 +336,15 @@ abstract class AmityFeedFragment : AmityBaseFragment() {
.subscribe()
}

private fun navigateToLivestreamPlayer(stream: AmityStream) {
val recordings = stream.getRecordings()
//recorded stream video
if (stream.getStatus() == AmityStream.Status.LIVE) {
private fun navigateToStreamPlayer(stream: AmityStream) {
if (stream.getStatus() == AmityStream.Status.LIVE
|| stream.getStatus() == AmityStream.Status.RECORDED) {
val livestreamIntent = AmityLivestreamVideoPlayerActivity.newIntent(
context = requireContext(),
streamId = stream.getStreamId()
)
requireContext().startActivity(livestreamIntent)
}
//live stream video
else if (!recordings.isNullOrEmpty() && recordings[0]?.getUrl(AmityRecordingData.Format.MP4) != null) {
val videoIntent = AmityVideoPlayerActivity
.newIntent(
context = requireContext(),
videoUrl = recordings[0]!!.getUrl(AmityRecordingData.Format.MP4)!!
)
requireContext().startActivity(videoIntent)
}
}

private fun observePostOptionClickEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class AmityLiveStreamPostCreatorViewModel :

private fun createStream(title: String, description: String): Single<AmityStream> {
return AmityVideoClient.newStreamRepository()
.createVideoStream(
.createStream(
title = title,
description = description,
resolution = AmityBroadcastResolution.HD_720P,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.amity.socialcloud.uikit.community.newsfeed.viewmodel

import com.amity.socialcloud.sdk.api.video.AmityVideoClient
import com.amity.socialcloud.sdk.model.video.stream.AmityStream
import com.amity.socialcloud.sdk.model.video.stream.AmityWatcherData
import com.amity.socialcloud.uikit.common.base.AmityBaseViewModel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Completable
Expand All @@ -14,27 +13,32 @@ class AmityLiveStreamVideoPlayerViewModel :

var streamId: String = ""

fun getVideoURL(
onLoadURLSuccess: (String) -> Unit,
onLoadURLError: () -> Unit
fun checkStreamStatus(
onValidStatus: (isLive: Boolean) -> Unit,
onInvalidStatus: () -> Unit
): Completable {
AmityVideoClient.newStreamRepository().fetchStream(streamId).subscribe()
return AmityVideoClient.newStreamRepository()
.observeStream(streamId)
.map {
if (it.getStatus() == AmityStream.Status.LIVE) {
return@map it.getWatcherData()?.getUrl(AmityWatcherData.Format.FLV) ?: EMPTY_URL
} else {
return@map EMPTY_URL
}
}
.getStream(streamId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.distinctUntilChanged { old, new ->
old.getStatus() == new.getStatus()
}
.doOnNext {
if (it != EMPTY_URL) {
onLoadURLSuccess.invoke(it)
} else {
onLoadURLError.invoke()
when(it.getStatus()) {
AmityStream.Status.LIVE -> {
onValidStatus.invoke(true)
}
AmityStream.Status.RECORDED -> {
onValidStatus.invoke(false)
}
AmityStream.Status.IDLE -> {
onInvalidStatus.invoke()
}
else -> {
// do nothing
}
}
}
.ignoreElements()
Expand All @@ -45,7 +49,7 @@ class AmityLiveStreamVideoPlayerViewModel :
onStreamDeleted: () -> Unit
): Completable {
return AmityVideoClient.newStreamRepository()
.observeStream(streamId)
.getStream(streamId)
.filter { it.getStatus() == AmityStream.Status.ENDED || it.isDeleted() }
.firstOrError()
.subscribeOn(Schedulers.io())
Expand All @@ -60,5 +64,3 @@ class AmityLiveStreamVideoPlayerViewModel :
.ignoreElement()
}
}

private const val EMPTY_URL = ""

0 comments on commit 743dcf8

Please sign in to comment.