@@ -62,8 +62,11 @@ import java.util.concurrent.ExecutionException
6262 */
6363class FileViewerUtils (private val context : Context , private val user : User ) {
6464
65- fun openFile (message : ChatMessage , openWhenDownloadState : MutableState <Boolean >, downloadState :
66- MutableState <List <String >>) {
65+ fun openFile (
66+ message : ChatMessage ,
67+ openWhenDownloadState : MutableState <Boolean >,
68+ downloadState : MutableState <List <String >>
69+ ) {
6770 val fileName = message.fileParameters.name
6871 val mimetype = message.fileParameters.mimetype
6972 val link = message.fileParameters.link
@@ -81,7 +84,11 @@ class FileViewerUtils(private val context: Context, private val user: User) {
8184 )
8285 }
8386
84- fun openFile (fileInfo : FileInfo , openWhenDownloadState : MutableState <Boolean >, downloadState : MutableState <List <String >>? = null) {
87+ fun openFile (
88+ fileInfo : FileInfo ,
89+ openWhenDownloadState : MutableState <Boolean >,
90+ downloadState : MutableState <List <String >>? = null
91+ ) {
8592 if (isSupportedForInternalViewer(fileInfo.mimetype) ||
8693 canBeHandledByExternalApp(fileInfo.mimetype, fileInfo.fileName)
8794 ) {
@@ -111,7 +118,11 @@ class FileViewerUtils(private val context: Context, private val user: User) {
111118 return intent.resolveActivity(context.packageManager) != null
112119 }
113120
114- private fun openOrDownloadFile (fileInfo : FileInfo , openWhenDownloadState : MutableState <Boolean >, downloadState : MutableState <List <String >>? ) {
121+ private fun openOrDownloadFile (
122+ fileInfo : FileInfo ,
123+ openWhenDownloadState : MutableState <Boolean >,
124+ downloadState : MutableState <List <String >>?
125+ ) {
115126 val file = File (context.cacheDir, fileInfo.fileName)
116127 if (file.exists()) {
117128 openFileByMimetype(fileInfo.fileName, fileInfo.mimetype, fileInfo.link, fileInfo.fileId)
@@ -133,18 +144,17 @@ class FileViewerUtils(private val context: Context, private val user: User) {
133144 VIDEO_MP4 ,
134145 VIDEO_QUICKTIME ,
135146 VIDEO_OGG ,
136- VIDEO_WEBM
137- -> openMediaView(filename, mimetype)
147+ VIDEO_WEBM -> openMediaView(filename, mimetype)
148+
138149 IMAGE_PNG ,
139150 IMAGE_JPEG ,
140151 IMAGE_GIF ,
141- IMAGE_HEIC
142- -> openImageView(filename, mimetype)
152+ IMAGE_HEIC -> openImageView(filename, mimetype)
153+
143154 TEXT_MARKDOWN ,
144- TEXT_PLAIN
145- -> openTextView(filename, mimetype, link, fileId)
146- else
147- -> openFileByExternalApp(filename, mimetype)
155+ TEXT_PLAIN -> openTextView(filename, mimetype, link, fileId)
156+
157+ else -> openFileByExternalApp(filename, mimetype)
148158 }
149159 } else {
150160 Log .e(TAG , " can't open file with unknown mimetype" )
@@ -243,12 +253,16 @@ class FileViewerUtils(private val context: Context, private val user: User) {
243253 VIDEO_WEBM ,
244254 TEXT_MARKDOWN ,
245255 TEXT_PLAIN -> true
256+
246257 else -> false
247258 }
248259
249260 @SuppressLint(" LongLogTag" )
250- private fun downloadFileToCache (fileInfo : FileInfo , openWhenDownloadState : MutableState <Boolean >, downloadState :
251- MutableState <List <String >>? ) {
261+ private fun downloadFileToCache (
262+ fileInfo : FileInfo ,
263+ openWhenDownloadState : MutableState <Boolean >,
264+ downloadState : MutableState <List <String >>?
265+ ) {
252266 downloadState?.value = downloadState.value + fileInfo.fileId
253267
254268 // check if download worker is already running
@@ -331,6 +345,7 @@ class FileViewerUtils(private val context: Context, private val user: User) {
331345 // )
332346 }
333347 }
348+
334349 WorkInfo .State .SUCCEEDED -> {
335350 if (openWhenDownloadState.value) {
336351 openFileByMimetype(fileName, mimetype, link, fileId)
@@ -345,10 +360,12 @@ class FileViewerUtils(private val context: Context, private val user: User) {
345360 // progressUi.messageText?.text = fileName
346361 // progressUi.progressBar?.visibility = View.GONE
347362 }
363+
348364 WorkInfo .State .FAILED -> {
349365 // progressUi.messageText?.text = fileName
350366 // progressUi.progressBar?.visibility = View.GONE
351367 }
368+
352369 else -> {
353370 }
354371 }
0 commit comments