@@ -279,6 +279,7 @@ class FileDisplayActivity :
279279 observeWorkerState()
280280 startMetadataSyncForRoot()
281281 handleBackPress()
282+ registerUnifiedSearchReceiver()
282283 }
283284
284285 private fun loadSavedInstanceState (savedInstanceState : Bundle ? ) {
@@ -732,7 +733,13 @@ class FileDisplayActivity :
732733 val transaction = fragmentManager.beginTransaction()
733734 transaction.addToBackStack(null )
734735 transaction.replace(R .id.left_fragment_container, fragment, TAG_LIST_OF_FILES )
735- transaction.commit()
736+
737+ if (fragmentManager.isStateSaved) {
738+ transaction.commitAllowingStateLoss()
739+ } else {
740+ transaction.commit()
741+ }
742+
736743 callback.onComplete(true )
737744 } else {
738745 callback.onComplete(false )
@@ -1962,7 +1969,7 @@ class FileDisplayActivity :
19621969 else -> VirtualFolderType .NONE
19631970 }
19641971
1965- startImagePreview(file, type, file.isDown)
1972+ startImagePreview(file, file.isDown, type )
19661973 } else {
19671974 startImagePreview(file, file.isDown)
19681975 }
@@ -2491,44 +2498,33 @@ class FileDisplayActivity :
24912498 }
24922499 }
24932500
2494- fun startImagePreview (file : OCFile , showPreview : Boolean ) {
2495- val showDetailsIntent = Intent (this , PreviewImageActivity ::class .java)
2496- showDetailsIntent.putExtra(EXTRA_FILE , file)
2497- showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2498- showDetailsIntent.putExtra(
2499- EXTRA_USER ,
2500- user.orElseThrow(Supplier { RuntimeException () })
2501- )
2502- if (showPreview) {
2503- startActivity(showDetailsIntent)
2504- } else {
2505- val fileOperationsHelper =
2506- FileOperationsHelper (this , userAccountManager, connectivityService, editorUtils)
2507- fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
2501+ fun startImagePreview (file : OCFile , preview : Boolean , type : VirtualFolderType ? = null) {
2502+ val optionalUser = user
2503+ if (optionalUser.isEmpty) {
2504+ Log_OC .e(TAG , " user is empty cannot preview image" )
2505+ return
25082506 }
2509- }
25102507
2511- fun startImagePreview (file : OCFile , type : VirtualFolderType ? , showPreview : Boolean ) {
2512- val showDetailsIntent = Intent (this , PreviewImageActivity ::class .java)
2513- showDetailsIntent.putExtra(EXTRA_FILE , file)
2514- showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2515- showDetailsIntent.putExtra(
2516- EXTRA_USER ,
2517- user.orElseThrow(Supplier { RuntimeException () })
2518- )
2519- showDetailsIntent.putExtra(PreviewImageActivity .EXTRA_VIRTUAL_TYPE , type)
2508+ val intent = Intent (this , PreviewImageActivity ::class .java).apply {
2509+ putExtra(EXTRA_FILE , file)
2510+ putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2511+ putExtra(EXTRA_USER , optionalUser.get())
2512+ putExtra(PreviewImageActivity .EXTRA_VIRTUAL_TYPE , type)
2513+ putExtra(PreviewImageActivity .EXTRA_LAST_SEARCH_QUERY , listOfFilesFragment?.lastSearchQuery)
2514+ }
25202515
2521- if (showPreview) {
2522- startActivity(showDetailsIntent)
2523- } else {
2524- val fileOperationsHelper = FileOperationsHelper (
2525- this ,
2526- userAccountManager,
2527- connectivityService,
2528- editorUtils
2529- )
2530- fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
2516+ if (preview) {
2517+ startActivity(intent)
2518+ return
25312519 }
2520+
2521+ val operation = FileOperationsHelper (
2522+ this ,
2523+ userAccountManager,
2524+ connectivityService,
2525+ editorUtils
2526+ )
2527+ operation.startSyncForFileAndIntent(file, intent)
25322528 }
25332529
25342530 /* *
@@ -2791,8 +2787,8 @@ class FileDisplayActivity :
27912787 val virtualType = bundle.get(PreviewImageActivity .EXTRA_VIRTUAL_TYPE ) as VirtualFolderType ?
27922788 startImagePreview(
27932789 file,
2794- virtualType ,
2795- true
2790+ true ,
2791+ virtualType
27962792 )
27972793 } else {
27982794 startImagePreview(file, true )
@@ -3052,23 +3048,41 @@ class FileDisplayActivity :
30523048 binding.fabMain.visibility = visibility
30533049 }
30543050
3055- fun showFile (selectedFile : OCFile ? , message : String? ) {
3051+ private fun registerUnifiedSearchReceiver () {
3052+ val filter = IntentFilter (UNIFIED_SEARCH_EVENT_ACTION )
3053+ LocalBroadcastManager .getInstance(this ).registerReceiver(unifiedSearchReceiver, filter)
3054+ }
3055+
3056+ private val unifiedSearchReceiver: BroadcastReceiver = object : BroadcastReceiver () {
3057+ override fun onReceive (context : Context , intent : Intent ) {
3058+ val query = intent.getStringExtra(PreviewImageActivity .EXTRA_LAST_SEARCH_QUERY ) ? : return
3059+ Handler (Looper .getMainLooper()).post {
3060+ if (! isFinishing && ! isDestroyed) {
3061+ performUnifiedSearch(query, null )
3062+ }
3063+ }
3064+ }
3065+ }
3066+
3067+ @JvmOverloads
3068+ fun showFile (selectedFile : OCFile ? , message : String? , lastSearchQuery : String? = null) {
30563069 dismissLoadingDialog()
30573070
30583071 getOCFileListFragmentFromFile(object : TransactionInterface {
30593072 override fun onOCFileListFragmentComplete (listOfFiles : OCFileListFragment ) {
3060- if (TextUtils .isEmpty(message) ) {
3073+ if (message? .isEmpty() == true ) {
30613074 val temp = file
30623075 file = getCurrentDir()
30633076 listOfFiles.listDirectory(getCurrentDir(), temp, MainApp .isOnlyOnDevice())
30643077 updateActionBarTitleAndHomeButton(null )
30653078 } else {
3066- val view = listOfFiles.view
3067- if (view != null ) {
3068- DisplayUtils .showSnackMessage(view, message)
3079+ listOfFiles.view?.let {
3080+ DisplayUtils .showSnackMessage(it, message)
30693081 }
30703082 }
3083+
30713084 if (selectedFile != null ) {
3085+ listOfFiles.setLastSearchQuery(lastSearchQuery)
30723086 listOfFiles.onItemClicked(selectedFile)
30733087 }
30743088 }
@@ -3133,6 +3147,8 @@ class FileDisplayActivity :
31333147
31343148 const val ACTION_DETAILS : String = " com.owncloud.android.ui.activity.action.DETAILS"
31353149
3150+ const val UNIFIED_SEARCH_EVENT_ACTION = " PHOTO_SEARCH_EVENT"
3151+
31363152 @JvmField
31373153 val REQUEST_CODE__SELECT_CONTENT_FROM_APPS : Int = REQUEST_CODE__LAST_SHARED + 1
31383154
0 commit comments