Skip to content

Commit

Permalink
convert PDF files using projector converter
Browse files Browse the repository at this point in the history
  • Loading branch information
AderanFeng committed Apr 12, 2024
1 parent 7699c8e commit d073da7
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ dependencies {
api 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.8.0'

// Agora
implementation("com.github.netless-io:whiteboard-android:nl_2.17.0-alpha.13") {
implementation("com.github.netless-io:whiteboard-android:nl_2.17.0-alpha.14") {
force true
}
// for local fastboard debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.herewhite.sdk.domain.ConvertedFiles
import com.herewhite.sdk.domain.Promise
import com.herewhite.sdk.domain.RoomPhase
import com.herewhite.sdk.domain.SDKError
import com.herewhite.sdk.domain.Scene
import com.herewhite.sdk.domain.WindowAppParam
import com.herewhite.sdk.domain.WindowPrefersColorScheme.Dark
import com.herewhite.sdk.domain.WindowPrefersColorScheme.Light
Expand Down Expand Up @@ -256,8 +256,8 @@ class AgoraBoardRoom @Inject constructor(
fastRoom?.setAppliance(FastAppliance.SELECTOR)
}

override fun insertPpt(dir: String, files: ConvertedFiles, title: String) {
val param = WindowAppParam.createSlideApp(dir, files.scenes, title)
override fun insertPpt(dir: String, scenes: List<Scene>, title: String) {
val param = WindowAppParam.createSlideApp(dir, scenes.toTypedArray(), title)
fastRoom?.room?.addApp(param, null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ class CloudStorageRepository @Inject constructor(
* @param fileSize
* @param path DirectoryPath
*/
suspend fun updateStart(fileName: String, fileSize: Long, path: String): Result<CloudUploadStartResp> {
suspend fun updateStart(
fileName: String,
fileSize: Long,
path: String,
convertType: String = "WhiteboardProjector"
): Result<CloudUploadStartResp> {
return withContext(Dispatchers.IO) {
cloudStorageService.updateStart(
CloudUploadStartReq(fileName = fileName, fileSize = fileSize, targetDirectoryPath = path)
CloudUploadStartReq(
fileName = fileName,
fileSize = fileSize,
targetDirectoryPath = path,
convertType = convertType,
)
).toResult()
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/io/agora/flat/di/interfaces/BoardRoom.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.agora.flat.di.interfaces

import com.herewhite.sdk.domain.ConvertedFiles
import com.herewhite.sdk.domain.Scene
import io.agora.board.fast.FastboardView
import io.agora.board.fast.ui.RoomControllerGroup
import io.agora.flat.common.board.BoardError
Expand All @@ -27,7 +28,7 @@ interface BoardRoom {
// courseware
fun insertImage(imageUrl: String, w: Int, h: Int)

fun insertPpt(dir: String, files: ConvertedFiles, title: String)
fun insertPpt(dir: String, scenes: List<Scene>, title: String)

fun insertProjectorPpt(taskUuid: String, prefixUrl: String, title: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class CloudUploadStartReq constructor(
val fileName: String,
val fileSize: Long,
val targetDirectoryPath: String,
val convertType: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ data class CloudUploadStartResp constructor(
val ossFilePath: String,
val policy: String,
val signature: String,
val convertType: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.agora.flat.data.Success
import io.agora.flat.data.model.*
import io.agora.flat.data.onSuccess
import io.agora.flat.data.repository.CloudStorageRepository
import io.agora.flat.http.model.CloudUploadStartResp
import io.agora.flat.util.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.herewhite.sdk.converter.ProjectorQuery
import com.herewhite.sdk.domain.ConversionInfo
import com.herewhite.sdk.domain.ConvertException
import com.herewhite.sdk.domain.ConvertedFiles
import com.herewhite.sdk.domain.PptPage
import com.herewhite.sdk.domain.Scene
import dagger.hilt.android.lifecycle.HiltViewModel
import io.agora.flat.Constants
import io.agora.flat.common.board.AgoraBoardRoom
Expand Down Expand Up @@ -204,24 +206,31 @@ class ClassCloudViewModel @Inject constructor(

fun insertCourseware(file: CloudFile) {
viewModelScope.launch {
// "正在插入课件……"
when (file.fileURL.coursewareType()) {
CoursewareType.Image -> {
insertImage(file.fileURL)
}

CoursewareType.Audio, CoursewareType.Video -> {
boardRoom.insertVideo(file.fileURL, file.fileName)
}

CoursewareType.DocStatic -> {
insertDocs(file, false)
if (file.resourceType == ResourceType.WhiteboardConvert) {
insertV5Docs(file, false)
} else if (file.resourceType == ResourceType.WhiteboardProjector) {
insertProjectorDocs(file)
}
}

CoursewareType.DocDynamic -> {
if (file.resourceType == ResourceType.WhiteboardConvert) {
insertDocs(file, true)
insertV5Docs(file, true)
} else if (file.resourceType == ResourceType.WhiteboardProjector) {
insertProjectorDocs(file)
}
}

else -> {
// Not Support Mobile
}
Expand All @@ -231,8 +240,8 @@ class ClassCloudViewModel @Inject constructor(

private suspend fun insertImage(fileUrl: String) {
val imageInfo = loadImageInfo(fileUrl)
val change = imageInfo.orientation == ExifInterface.ORIENTATION_ROTATE_90
|| imageInfo.orientation == ExifInterface.ORIENTATION_ROTATE_270
val change =
imageInfo.orientation == ExifInterface.ORIENTATION_ROTATE_90 || imageInfo.orientation == ExifInterface.ORIENTATION_ROTATE_270
if (change) {
boardRoom.insertImage(fileUrl, w = imageInfo.height, h = imageInfo.width)
} else {
Expand Down Expand Up @@ -275,7 +284,7 @@ class ClassCloudViewModel @Inject constructor(
}
}

private fun insertDocs(file: CloudFile, dynamic: Boolean) {
private fun insertV5Docs(file: CloudFile, dynamic: Boolean) {
val convert = ConverterV5.Builder().apply {
setResource(file.fileURL)
setType(if (dynamic) ConvertType.Dynamic else ConvertType.Static)
Expand All @@ -287,7 +296,11 @@ class ClassCloudViewModel @Inject constructor(
}

override fun onFinish(ppt: ConvertedFiles, convertInfo: ConversionInfo) {
boardRoom.insertPpt("/${file.whiteboardConvert.taskUUID}/${UUID.randomUUID()}", ppt, file.fileName)
boardRoom.insertPpt(
"/${file.whiteboardConvert.taskUUID}/${UUID.randomUUID()}",
ppt.scenes.toList(),
file.fileName
)
}

override fun onFailure(e: ConvertException) {
Expand All @@ -297,10 +310,20 @@ class ClassCloudViewModel @Inject constructor(
convert.startConvertTask()
}

private fun ProjectorQuery.QueryResponse.scenes(): List<Scene> {
return IntRange(1, images.size).mapNotNull { index ->
images["$index"]?.let {
Scene("$index", PptPage(it.url, it.width.toDouble(), it.height.toDouble()))
}
}
}

private fun ProjectorQuery.QueryResponse.isStatic() = type == "static"

private fun insertProjectorDocs(file: CloudFile) {
val projectorQuery = ProjectorQuery.Builder()
.setTaskToken(file.whiteboardProjector.taskToken)
.setTaskUuid(file.whiteboardProjector.taskUUID)
.setTaskToken(file.whiteboardProjector.taskToken)
.setRegion(appEnv.region.toRegion())
.setPoolInterval(2000)
.setCallback(object : ProjectorQuery.Callback {
Expand All @@ -309,14 +332,21 @@ class ClassCloudViewModel @Inject constructor(
}

override fun onFinish(response: ProjectorQuery.QueryResponse) {
boardRoom.insertProjectorPpt(file.whiteboardProjector.taskUUID, response.prefix, file.fileName)
if (response.isStatic()) {
boardRoom.insertPpt(
"/${response.uuid}/${UUID.randomUUID()}",
response.scenes(),
file.fileName
)
} else {
boardRoom.insertProjectorPpt(file.whiteboardProjector.taskUUID, response.prefix, file.fileName)
}
}

override fun onFailure(e: ConvertException?) {

}
})
.build()
}).build()
projectorQuery.startQuery()
}

Expand Down

0 comments on commit d073da7

Please sign in to comment.