From d073da72fc51c4b902d8aab83ee75828c763cc8c Mon Sep 17 00:00:00 2001 From: fenglibin Date: Fri, 12 Apr 2024 17:20:21 +0800 Subject: [PATCH] convert PDF files using projector converter --- app/build.gradle | 2 +- .../agora/flat/common/board/AgoraBoardRoom.kt | 6 +-- .../data/repository/CloudStorageRepository.kt | 14 ++++- .../io/agora/flat/di/interfaces/BoardRoom.kt | 3 +- .../flat/http/model/CloudUploadStartReq.kt | 1 + .../flat/http/model/CloudUploadStartResp.kt | 1 + .../cloud/list/CloudStorageViewModel.kt | 1 - .../ui/activity/play/ClassCloudViewModel.kt | 52 +++++++++++++++---- 8 files changed, 61 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 365213b4..36c40df0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/io/agora/flat/common/board/AgoraBoardRoom.kt b/app/src/main/java/io/agora/flat/common/board/AgoraBoardRoom.kt index 082e9e8e..b3b85bb3 100644 --- a/app/src/main/java/io/agora/flat/common/board/AgoraBoardRoom.kt +++ b/app/src/main/java/io/agora/flat/common/board/AgoraBoardRoom.kt @@ -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 @@ -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, title: String) { + val param = WindowAppParam.createSlideApp(dir, scenes.toTypedArray(), title) fastRoom?.room?.addApp(param, null) } diff --git a/app/src/main/java/io/agora/flat/data/repository/CloudStorageRepository.kt b/app/src/main/java/io/agora/flat/data/repository/CloudStorageRepository.kt index beb6de93..cd22e566 100644 --- a/app/src/main/java/io/agora/flat/data/repository/CloudStorageRepository.kt +++ b/app/src/main/java/io/agora/flat/data/repository/CloudStorageRepository.kt @@ -51,10 +51,20 @@ class CloudStorageRepository @Inject constructor( * @param fileSize * @param path DirectoryPath */ - suspend fun updateStart(fileName: String, fileSize: Long, path: String): Result { + suspend fun updateStart( + fileName: String, + fileSize: Long, + path: String, + convertType: String = "WhiteboardProjector" + ): Result { return withContext(Dispatchers.IO) { cloudStorageService.updateStart( - CloudUploadStartReq(fileName = fileName, fileSize = fileSize, targetDirectoryPath = path) + CloudUploadStartReq( + fileName = fileName, + fileSize = fileSize, + targetDirectoryPath = path, + convertType = convertType, + ) ).toResult() } } diff --git a/app/src/main/java/io/agora/flat/di/interfaces/BoardRoom.kt b/app/src/main/java/io/agora/flat/di/interfaces/BoardRoom.kt index 216305e3..38f8f752 100644 --- a/app/src/main/java/io/agora/flat/di/interfaces/BoardRoom.kt +++ b/app/src/main/java/io/agora/flat/di/interfaces/BoardRoom.kt @@ -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 @@ -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, title: String) fun insertProjectorPpt(taskUuid: String, prefixUrl: String, title: String) diff --git a/app/src/main/java/io/agora/flat/http/model/CloudUploadStartReq.kt b/app/src/main/java/io/agora/flat/http/model/CloudUploadStartReq.kt index 0b7fcce8..f95791cf 100644 --- a/app/src/main/java/io/agora/flat/http/model/CloudUploadStartReq.kt +++ b/app/src/main/java/io/agora/flat/http/model/CloudUploadStartReq.kt @@ -4,4 +4,5 @@ data class CloudUploadStartReq constructor( val fileName: String, val fileSize: Long, val targetDirectoryPath: String, + val convertType: String? = null, ) \ No newline at end of file diff --git a/app/src/main/java/io/agora/flat/http/model/CloudUploadStartResp.kt b/app/src/main/java/io/agora/flat/http/model/CloudUploadStartResp.kt index c1a8bd23..2af8db9d 100644 --- a/app/src/main/java/io/agora/flat/http/model/CloudUploadStartResp.kt +++ b/app/src/main/java/io/agora/flat/http/model/CloudUploadStartResp.kt @@ -6,4 +6,5 @@ data class CloudUploadStartResp constructor( val ossFilePath: String, val policy: String, val signature: String, + val convertType: String? = null, ) \ No newline at end of file diff --git a/app/src/main/java/io/agora/flat/ui/activity/cloud/list/CloudStorageViewModel.kt b/app/src/main/java/io/agora/flat/ui/activity/cloud/list/CloudStorageViewModel.kt index 54ca05d4..978ee8a5 100644 --- a/app/src/main/java/io/agora/flat/ui/activity/cloud/list/CloudStorageViewModel.kt +++ b/app/src/main/java/io/agora/flat/ui/activity/cloud/list/CloudStorageViewModel.kt @@ -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 diff --git a/app/src/main/java/io/agora/flat/ui/activity/play/ClassCloudViewModel.kt b/app/src/main/java/io/agora/flat/ui/activity/play/ClassCloudViewModel.kt index 0fa85442..f4d7b115 100644 --- a/app/src/main/java/io/agora/flat/ui/activity/play/ClassCloudViewModel.kt +++ b/app/src/main/java/io/agora/flat/ui/activity/play/ClassCloudViewModel.kt @@ -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 @@ -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 } @@ -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 { @@ -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) @@ -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) { @@ -297,10 +310,20 @@ class ClassCloudViewModel @Inject constructor( convert.startConvertTask() } + private fun ProjectorQuery.QueryResponse.scenes(): List { + 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 { @@ -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() }