Skip to content

Commit cce90bf

Browse files
Merge pull request #16530 from nextcloud/backport/16529/stable-3.36
[stable-3.36] fix(media): photo search event
2 parents f0ab72c + 2a97457 commit cce90bf

3 files changed

Lines changed: 24 additions & 42 deletions

File tree

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

app/src/main/java/com/owncloud/android/ui/events/SearchEvent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ data class SearchEvent(val searchQuery: String, val searchType: SearchRemoteOper
3333
SearchRemoteOperation.SearchType.FAVORITE_SEARCH -> SearchType.FAVORITE_SEARCH
3434
SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH -> SearchType.RECENTLY_MODIFIED_SEARCH
3535
SearchRemoteOperation.SearchType.SHARED_FILTER -> SearchType.SHARED_FILTER
36+
SearchRemoteOperation.SearchType.PHOTO_SEARCH -> SearchType.GALLERY_SEARCH
37+
SearchRemoteOperation.SearchType.GALLERY_SEARCH -> SearchType.GALLERY_SEARCH
3638
else -> null
3739
}
3840

app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,8 @@ class PreviewImageActivity :
166166
preferences
167167
)
168168
} else {
169-
// get parent from path
170-
var parentFolder = file?.let { storageManager.getFileById(it.parentId) }
171-
172-
if (parentFolder == null) {
173-
// should not be necessary
174-
parentFolder = storageManager.getFileByEncryptedRemotePath(OCFile.ROOT_PATH)
175-
}
169+
val parentFolder = file?.let { storageManager.getFileById(it.parentId) }
170+
?: storageManager.getFileByEncryptedRemotePath(OCFile.ROOT_PATH)
176171

177172
previewImagePagerAdapter = PreviewImagePagerAdapter(
178173
this,

0 commit comments

Comments
 (0)