@@ -21,6 +21,7 @@ import android.view.Menu
2121import android.view.MenuItem
2222import android.view.View
2323import androidx.activity.OnBackPressedCallback
24+ import androidx.lifecycle.lifecycleScope
2425import androidx.localbroadcastmanager.content.LocalBroadcastManager
2526import com.nextcloud.client.di.Injectable
2627import com.nextcloud.utils.fileNameValidator.FileNameValidator
@@ -48,6 +49,8 @@ import com.owncloud.android.utils.DisplayUtils
4849import com.owncloud.android.utils.ErrorMessageAdapter
4950import com.owncloud.android.utils.FileSortOrder
5051import com.owncloud.android.utils.PathUtils
52+ import kotlinx.coroutines.Dispatchers
53+ import kotlinx.coroutines.launch
5154import java.io.File
5255import javax.inject.Inject
5356
@@ -60,7 +63,6 @@ open class FolderPickerActivity :
6063 OnSortingOrderListener {
6164
6265 private var mSyncBroadcastReceiver: SyncBroadcastReceiver ? = null
63- private var mSyncInProgress = false
6466 private var mSearchOnlyFolders = false
6567 var isDoNotEnterEncryptedFolder = false
6668 private set
@@ -105,8 +107,13 @@ open class FolderPickerActivity :
105107 }
106108
107109 updateActionBarTitleAndHomeButtonByString(captionText)
108- setBackgroundText()
109110 handleBackPress()
111+ listOfFilesFragment?.let {
112+ if (it.isEmpty) {
113+ it.setEmptyListMessage(EmptyListState .ADD_FOLDER )
114+ return
115+ }
116+ }
110117 }
111118
112119 override fun onDestroy () {
@@ -211,25 +218,6 @@ open class FolderPickerActivity :
211218 transaction.commit()
212219 }
213220
214- /* *
215- * Show a text message on screen view for notifying user if content is loading or folder is empty
216- */
217- private fun setBackgroundText () {
218- val listFragment = listOfFilesFragment
219-
220- if (listFragment == null ) {
221- Log_OC .e(TAG , " OCFileListFragment is null" )
222- }
223-
224- listFragment?.let {
225- if (mSyncInProgress) {
226- it.setEmptyListMessage(EmptyListState .LOADING )
227- } else {
228- it.setEmptyListMessage(EmptyListState .ADD_FOLDER )
229- }
230- }
231- }
232-
233221 protected val listOfFilesFragment: OCFileListFragment ?
234222 get() {
235223 val listOfFiles = supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FOLDERS )
@@ -259,21 +247,27 @@ open class FolderPickerActivity :
259247 }
260248
261249 private fun startSyncFolderOperation (folder : OCFile ? , ignoreETag : Boolean ) {
262- val currentSyncTime = System .currentTimeMillis()
263- mSyncInProgress = true
264-
265- RefreshFolderOperation (
266- folder,
267- currentSyncTime,
268- false ,
269- ignoreETag,
270- storageManager,
271- user.orElseThrow { RuntimeException (" User not set" ) },
272- applicationContext
273- ).also {
274- it.execute(account, this , null , null )
250+ listOfFilesFragment?.setEmptyListMessage(EmptyListState .LOADING )
251+ lifecycleScope.launch(Dispatchers .IO ) {
252+ val currentSyncTime = System .currentTimeMillis()
253+ val operation = RefreshFolderOperation (
254+ folder,
255+ currentSyncTime,
256+ false ,
257+ ignoreETag,
258+ storageManager,
259+ user.orElseThrow { RuntimeException (" User not set" ) },
260+ applicationContext
261+ )
262+ operation.execute(
263+ account,
264+ this @FolderPickerActivity,
265+ { _, _ ->
266+ listOfFilesFragment?.setEmptyListMessage(EmptyListState .IDLE )
267+ },
268+ null
269+ )
275270 }
276- setBackgroundText()
277271 }
278272
279273 override fun onResume () {
@@ -554,9 +548,7 @@ open class FolderPickerActivity :
554548 return
555549 }
556550
557- if (FileSyncAdapter .EVENT_FULL_SYNC_START == event) {
558- mSyncInProgress = true
559- } else {
551+ if (FileSyncAdapter .EVENT_FULL_SYNC_START != event) {
560552 var (currentFile, currentDir) = getCurrentFileAndDirectory()
561553
562554 if (currentDir == null ) {
@@ -572,22 +564,17 @@ open class FolderPickerActivity :
572564 file = currentFile
573565 }
574566
575- mSyncInProgress = (
576- FileSyncAdapter .EVENT_FULL_SYNC_END != event &&
577- RefreshFolderOperation .EVENT_SINGLE_FOLDER_SHARES_SYNCED != event
578- )
579-
580567 checkCredentials(syncResult, event)
581568 }
582569
583570 DataHolderUtil .getInstance().delete(intent.getStringExtra(FileSyncAdapter .EXTRA_RESULT ))
584- Log_OC .d(TAG , " Setting progress visibility to $mSyncInProgress " )
585- setBackgroundText()
586571 } catch (e: RuntimeException ) {
587572 Log_OC .e(TAG , " Error on broadcast receiver" , e)
588573 // avoid app crashes after changing the serial id of RemoteOperationResult
589574 // in owncloud library with broadcast notifications pending to process
590575 DataHolderUtil .getInstance().delete(intent.getStringExtra(FileSyncAdapter .EXTRA_RESULT ))
576+ } finally {
577+ listOfFilesFragment?.setEmptyListMessage(EmptyListState .IDLE )
591578 }
592579 }
593580
0 commit comments