@@ -1935,18 +1935,17 @@ class FileDisplayActivity :
19351935 }
19361936
19371937 fun previewImageWithSearchContext (file : OCFile , searchFragment : Boolean , currentSearchType : SearchType ? ) {
1938- // preview image - it handles the download, if needed
1939- if (searchFragment) {
1940- val type = when (currentSearchType) {
1938+ val type = if (searchFragment) {
1939+ when (currentSearchType) {
19411940 SearchType .FAVORITE_SEARCH -> VirtualFolderType .FAVORITE
19421941 SearchType .GALLERY_SEARCH -> VirtualFolderType .GALLERY
19431942 else -> VirtualFolderType .NONE
19441943 }
1945-
1946- startImagePreview(file, type, file.isDown)
19471944 } else {
1948- startImagePreview(file, file.isDown)
1945+ null
19491946 }
1947+
1948+ startImagePreview(file, file.isDown, type)
19501949 }
19511950
19521951 fun previewFile (file : OCFile , setFabVisible : CompletionCallback ? ) {
@@ -2472,43 +2471,29 @@ class FileDisplayActivity :
24722471 }
24732472 }
24742473
2475- fun startImagePreview (file : OCFile , showPreview : Boolean ) {
2476- val showDetailsIntent = Intent (this , PreviewImageActivity ::class .java)
2477- showDetailsIntent.putExtra(EXTRA_FILE , file)
2478- showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2479- showDetailsIntent.putExtra(
2480- EXTRA_USER ,
2481- user.orElseThrow(Supplier { RuntimeException () })
2482- )
2483- if (showPreview) {
2484- startActivity(showDetailsIntent)
2485- } else {
2486- val fileOperationsHelper =
2487- FileOperationsHelper (this , userAccountManager, connectivityService, editorUtils)
2488- fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
2474+ fun startImagePreview (file : OCFile , showPreview : Boolean , type : VirtualFolderType ? = null) {
2475+ if (user.isEmpty) {
2476+ Log_OC .e(TAG , " cannot start image preview" )
2477+ return
24892478 }
2490- }
24912479
2492- fun startImagePreview (file : OCFile , type : VirtualFolderType ? , showPreview : Boolean ) {
2493- val showDetailsIntent = Intent (this , PreviewImageActivity ::class .java)
2494- showDetailsIntent.putExtra(EXTRA_FILE , file)
2495- showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2496- showDetailsIntent.putExtra(
2497- EXTRA_USER ,
2498- user.orElseThrow(Supplier { RuntimeException () })
2499- )
2500- showDetailsIntent.putExtra(PreviewImageActivity .EXTRA_VIRTUAL_TYPE , type)
2480+ val intent = Intent (this , PreviewImageActivity ::class .java).apply {
2481+ putExtra(EXTRA_FILE , file)
2482+ putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2483+ putExtra(EXTRA_USER , user.get())
2484+ type?.let { putExtra(PreviewImageActivity .EXTRA_VIRTUAL_TYPE , it) }
2485+ }
25012486
25022487 if (showPreview) {
2503- startActivity(showDetailsIntent )
2488+ startActivity(intent )
25042489 } else {
2505- val fileOperationsHelper = FileOperationsHelper (
2490+ val helper = FileOperationsHelper (
25062491 this ,
25072492 userAccountManager,
25082493 connectivityService,
25092494 editorUtils
25102495 )
2511- fileOperationsHelper .startSyncForFileAndIntent(file, showDetailsIntent )
2496+ helper .startSyncForFileAndIntent(file, intent )
25122497 }
25132498 }
25142499
@@ -2772,8 +2757,8 @@ class FileDisplayActivity :
27722757 val virtualType = bundle.get(PreviewImageActivity .EXTRA_VIRTUAL_TYPE ) as VirtualFolderType ?
27732758 startImagePreview(
27742759 file,
2775- virtualType ,
2776- true
2760+ true ,
2761+ virtualType
27772762 )
27782763 } else {
27792764 startImagePreview(file, true )
0 commit comments