@@ -278,6 +278,7 @@ class FileDisplayActivity :
278278 observeWorkerState()
279279 startMetadataSyncForRoot()
280280 handleBackPress()
281+ registerUnifiedSearchReceiver()
281282 }
282283
283284 private fun loadSavedInstanceState (savedInstanceState : Bundle ? ) {
@@ -731,7 +732,13 @@ class FileDisplayActivity :
731732 val transaction = fragmentManager.beginTransaction()
732733 transaction.addToBackStack(null )
733734 transaction.replace(R .id.left_fragment_container, fragment, TAG_LIST_OF_FILES )
734- transaction.commit()
735+
736+ if (fragmentManager.isStateSaved) {
737+ transaction.commitAllowingStateLoss()
738+ } else {
739+ transaction.commit()
740+ }
741+
735742 callback.onComplete(true )
736743 } else {
737744 callback.onComplete(false )
@@ -1953,7 +1960,7 @@ class FileDisplayActivity :
19531960 else -> VirtualFolderType .NONE
19541961 }
19551962
1956- startImagePreview(file, type, file.isDown)
1963+ startImagePreview(file, file.isDown, type )
19571964 } else {
19581965 startImagePreview(file, file.isDown)
19591966 }
@@ -2482,44 +2489,33 @@ class FileDisplayActivity :
24822489 }
24832490 }
24842491
2485- fun startImagePreview (file : OCFile , showPreview : Boolean ) {
2486- val showDetailsIntent = Intent (this , PreviewImageActivity ::class .java)
2487- showDetailsIntent.putExtra(EXTRA_FILE , file)
2488- showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2489- showDetailsIntent.putExtra(
2490- EXTRA_USER ,
2491- user.orElseThrow(Supplier { RuntimeException () })
2492- )
2493- if (showPreview) {
2494- startActivity(showDetailsIntent)
2495- } else {
2496- val fileOperationsHelper =
2497- FileOperationsHelper (this , userAccountManager, connectivityService, editorUtils)
2498- fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
2492+ fun startImagePreview (file : OCFile , preview : Boolean , type : VirtualFolderType ? = null) {
2493+ val optionalUser = user
2494+ if (optionalUser.isEmpty) {
2495+ Log_OC .e(TAG , " user is empty cannot preview image" )
2496+ return
24992497 }
2500- }
25012498
2502- fun startImagePreview (file : OCFile , type : VirtualFolderType ? , showPreview : Boolean ) {
2503- val showDetailsIntent = Intent (this , PreviewImageActivity ::class .java)
2504- showDetailsIntent.putExtra(EXTRA_FILE , file)
2505- showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2506- showDetailsIntent.putExtra(
2507- EXTRA_USER ,
2508- user.orElseThrow(Supplier { RuntimeException () })
2509- )
2510- showDetailsIntent.putExtra(PreviewImageActivity .EXTRA_VIRTUAL_TYPE , type)
2499+ val intent = Intent (this , PreviewImageActivity ::class .java).apply {
2500+ putExtra(EXTRA_FILE , file)
2501+ putExtra(EXTRA_LIVE_PHOTO_FILE , file.livePhotoVideo)
2502+ putExtra(EXTRA_USER , optionalUser.get())
2503+ putExtra(PreviewImageActivity .EXTRA_VIRTUAL_TYPE , type)
2504+ putExtra(PreviewImageActivity .EXTRA_LAST_SEARCH_QUERY , listOfFilesFragment?.lastSearchQuery)
2505+ }
25112506
2512- if (showPreview) {
2513- startActivity(showDetailsIntent)
2514- } else {
2515- val fileOperationsHelper = FileOperationsHelper (
2516- this ,
2517- userAccountManager,
2518- connectivityService,
2519- editorUtils
2520- )
2521- fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent)
2507+ if (preview) {
2508+ startActivity(intent)
2509+ return
25222510 }
2511+
2512+ val operation = FileOperationsHelper (
2513+ this ,
2514+ userAccountManager,
2515+ connectivityService,
2516+ editorUtils
2517+ )
2518+ operation.startSyncForFileAndIntent(file, intent)
25232519 }
25242520
25252521 /* *
@@ -2782,8 +2778,8 @@ class FileDisplayActivity :
27822778 val virtualType = bundle.get(PreviewImageActivity .EXTRA_VIRTUAL_TYPE ) as VirtualFolderType ?
27832779 startImagePreview(
27842780 file,
2785- virtualType ,
2786- true
2781+ true ,
2782+ virtualType
27872783 )
27882784 } else {
27892785 startImagePreview(file, true )
@@ -3043,23 +3039,41 @@ class FileDisplayActivity :
30433039 binding.fabMain.visibility = visibility
30443040 }
30453041
3046- fun showFile (selectedFile : OCFile ? , message : String? ) {
3042+ private fun registerUnifiedSearchReceiver () {
3043+ val filter = IntentFilter (UNIFIED_SEARCH_EVENT_ACTION )
3044+ LocalBroadcastManager .getInstance(this ).registerReceiver(unifiedSearchReceiver, filter)
3045+ }
3046+
3047+ private val unifiedSearchReceiver: BroadcastReceiver = object : BroadcastReceiver () {
3048+ override fun onReceive (context : Context , intent : Intent ) {
3049+ val query = intent.getStringExtra(PreviewImageActivity .EXTRA_LAST_SEARCH_QUERY ) ? : return
3050+ Handler (Looper .getMainLooper()).post {
3051+ if (! isFinishing && ! isDestroyed) {
3052+ performUnifiedSearch(query, null )
3053+ }
3054+ }
3055+ }
3056+ }
3057+
3058+ @JvmOverloads
3059+ fun showFile (selectedFile : OCFile ? , message : String? , lastSearchQuery : String? = null) {
30473060 dismissLoadingDialog()
30483061
30493062 getOCFileListFragmentFromFile(object : TransactionInterface {
30503063 override fun onOCFileListFragmentComplete (listOfFiles : OCFileListFragment ) {
3051- if (TextUtils .isEmpty(message) ) {
3064+ if (message? .isEmpty() == true ) {
30523065 val temp = file
30533066 file = getCurrentDir()
30543067 listOfFiles.listDirectory(getCurrentDir(), temp, MainApp .isOnlyOnDevice())
30553068 updateActionBarTitleAndHomeButton(null )
30563069 } else {
3057- val view = listOfFiles.view
3058- if (view != null ) {
3059- DisplayUtils .showSnackMessage(view, message)
3070+ listOfFiles.view?.let {
3071+ DisplayUtils .showSnackMessage(it, message)
30603072 }
30613073 }
3074+
30623075 if (selectedFile != null ) {
3076+ listOfFiles.setLastSearchQuery(lastSearchQuery)
30633077 listOfFiles.onItemClicked(selectedFile)
30643078 }
30653079 }
@@ -3124,6 +3138,8 @@ class FileDisplayActivity :
31243138
31253139 const val ACTION_DETAILS : String = " com.owncloud.android.ui.activity.action.DETAILS"
31263140
3141+ const val UNIFIED_SEARCH_EVENT_ACTION = " PHOTO_SEARCH_EVENT"
3142+
31273143 @JvmField
31283144 val REQUEST_CODE__SELECT_CONTENT_FROM_APPS : Int = REQUEST_CODE__LAST_SHARED + 1
31293145
0 commit comments