@@ -21,7 +21,9 @@ 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
26+ import com.nextcloud.client.account.User
2527import com.nextcloud.client.di.Injectable
2628import com.nextcloud.utils.fileNameValidator.FileNameValidator
2729import com.owncloud.android.R
@@ -48,6 +50,8 @@ import com.owncloud.android.utils.DisplayUtils
4850import com.owncloud.android.utils.ErrorMessageAdapter
4951import com.owncloud.android.utils.FileSortOrder
5052import com.owncloud.android.utils.PathUtils
53+ import kotlinx.coroutines.Dispatchers
54+ import kotlinx.coroutines.launch
5155import java.io.File
5256import javax.inject.Inject
5357
@@ -60,7 +64,6 @@ open class FolderPickerActivity :
6064 OnSortingOrderListener {
6165
6266 private var mSyncBroadcastReceiver: SyncBroadcastReceiver ? = null
63- private var mSyncInProgress = false
6467 private var mSearchOnlyFolders = false
6568 var isDoNotEnterEncryptedFolder = false
6669 private set
@@ -105,7 +108,6 @@ open class FolderPickerActivity :
105108 }
106109
107110 updateActionBarTitleAndHomeButtonByString(captionText)
108- setBackgroundText()
109111 handleBackPress()
110112 }
111113
@@ -211,25 +213,6 @@ open class FolderPickerActivity :
211213 transaction.commit()
212214 }
213215
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-
233216 protected val listOfFilesFragment: OCFileListFragment ?
234217 get() {
235218 val listOfFiles = supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FOLDERS )
@@ -259,21 +242,33 @@ open class FolderPickerActivity :
259242 }
260243
261244 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 )
245+ val optionalUser = user ? : return
246+ if (optionalUser.isEmpty) {
247+ return
248+ }
249+ val user: User = optionalUser.get()
250+ listOfFilesFragment?.setEmptyListMessage(EmptyListState .LOADING )
251+
252+ lifecycleScope.launch(Dispatchers .IO ) {
253+ val currentSyncTime = System .currentTimeMillis()
254+ val operation = RefreshFolderOperation (
255+ folder,
256+ currentSyncTime,
257+ false ,
258+ ignoreETag,
259+ storageManager,
260+ user,
261+ applicationContext
262+ )
263+ operation.execute(
264+ account,
265+ this @FolderPickerActivity,
266+ { _, _ ->
267+ listOfFilesFragment?.setEmptyListMessage(EmptyListState .LOCAL_FILE_LIST_EMPTY_FILE )
268+ },
269+ null
270+ )
275271 }
276- setBackgroundText()
277272 }
278273
279274 override fun onResume () {
@@ -554,9 +549,7 @@ open class FolderPickerActivity :
554549 return
555550 }
556551
557- if (FileSyncAdapter .EVENT_FULL_SYNC_START == event) {
558- mSyncInProgress = true
559- } else {
552+ if (FileSyncAdapter .EVENT_FULL_SYNC_START != event) {
560553 var (currentFile, currentDir) = getCurrentFileAndDirectory()
561554
562555 if (currentDir == null ) {
@@ -572,22 +565,17 @@ open class FolderPickerActivity :
572565 file = currentFile
573566 }
574567
575- mSyncInProgress = (
576- FileSyncAdapter .EVENT_FULL_SYNC_END != event &&
577- RefreshFolderOperation .EVENT_SINGLE_FOLDER_SHARES_SYNCED != event
578- )
579-
580568 checkCredentials(syncResult, event)
581569 }
582570
583571 DataHolderUtil .getInstance().delete(intent.getStringExtra(FileSyncAdapter .EXTRA_RESULT ))
584- Log_OC .d(TAG , " Setting progress visibility to $mSyncInProgress " )
585- setBackgroundText()
586572 } catch (e: RuntimeException ) {
587573 Log_OC .e(TAG , " Error on broadcast receiver" , e)
588574 // avoid app crashes after changing the serial id of RemoteOperationResult
589575 // in owncloud library with broadcast notifications pending to process
590576 DataHolderUtil .getInstance().delete(intent.getStringExtra(FileSyncAdapter .EXTRA_RESULT ))
577+ } finally {
578+ listOfFilesFragment?.setEmptyListMessage(EmptyListState .LOCAL_FILE_LIST_EMPTY_FILE )
591579 }
592580 }
593581
0 commit comments