diff --git a/app/src/main/java/com/nextcloud/utils/extensions/Extensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/Extensions.kt index 1194301efdac..598bff9e0fc8 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/Extensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/Extensions.kt @@ -8,6 +8,8 @@ */ package com.nextcloud.utils.extensions +import android.os.Handler +import android.os.Looper import android.os.SystemClock import android.text.Selection import android.text.Spannable @@ -24,6 +26,12 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +fun mainThread(delay: Long = 1000, action: () -> Unit) { + Handler(Looper.getMainLooper()).postDelayed({ + action() + }, delay) +} + fun clickWithDebounce(view: View, debounceTime: Long = 600L, action: () -> Unit) { view.setOnClickListener(object : View.OnClickListener { private var lastClickTime: Long = 0 diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index f60f8325a272..be8688e92d30 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -148,7 +148,6 @@ public class ReceiveExternalFilesActivity extends FileActivity private SyncBroadcastReceiver mSyncBroadcastReceiver; private ReceiveExternalFilesAdapter receiveExternalFilesAdapter; - private boolean mSyncInProgress; private final static int REQUEST_CODE__SETUP_ACCOUNT = REQUEST_CODE__LAST_SHARED + 1; @@ -856,7 +855,6 @@ private void startSyncFolderOperation(OCFile folder) { executorService.execute(() -> { long currentSyncTime = System.currentTimeMillis(); - mSyncInProgress = true; final var optionalUser = getUser(); if (optionalUser.isEmpty()) { DisplayUtils.showSnackMessage(this, R.string.user_information_retrieval_error); @@ -1155,58 +1153,32 @@ public void onReceive(Context context, Intent intent) { boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null; - if (sameAccount) { - - if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { - mSyncInProgress = true; + if (sameAccount && !FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { + OCFile currentFile = (mFile == null) ? null : getStorageManager().getFileByPath(mFile.getRemotePath()); + OCFile currentDir = (getCurrentFolder() == null) ? null : getStorageManager().getFileByPath(getCurrentFolder().getRemotePath()); + if (currentDir == null) { + // current folder was removed from the server + DisplayUtils.showSnackMessage(getActivity(), R.string.sync_current_folder_was_removed, getCurrentFolder().getFileName()); + browseToRoot(); } else { - OCFile currentFile = (mFile == null) ? null : - getStorageManager().getFileByPath(mFile.getRemotePath()); - OCFile currentDir = (getCurrentFolder() == null) ? null : - getStorageManager().getFileByPath(getCurrentFolder().getRemotePath()); - - if (currentDir == null) { - // current folder was removed from the server - DisplayUtils.showSnackMessage( - getActivity(), - R.string.sync_current_folder_was_removed, - getCurrentFolder().getFileName() - ); - browseToRoot(); - - } else { - if (currentFile == null && !mFile.isFolder()) { - // currently selected file was removed in the server, and now we know it - currentFile = currentDir; - } - - if (currentDir.getRemotePath().equals(syncFolderRemotePath)) { - populateDirectoryList(currentFile); - } + if (currentFile == null && !mFile.isFolder()) { + // currently selected file was removed in the server, and now we know it + currentFile = currentDir; } - mSyncInProgress = !FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && - !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event); - - if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event) - /// TODO refactor and make common - && syncResult != null && !syncResult.isSuccess()) { - - if (syncResult.getCode() == ResultCode.UNAUTHORIZED || - (syncResult.isException() && syncResult.getException() - instanceof AuthenticatorException)) { - - requestCredentialsUpdate(); - - } else if (ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == syncResult.getCode()) { - - showUntrustedCertDialog(syncResult); - } + if (currentDir.getRemotePath().equals(syncFolderRemotePath)) { + populateDirectoryList(currentFile); } } - Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); + if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event) && syncResult != null && !syncResult.isSuccess()) { + if (syncResult.getCode() == ResultCode.UNAUTHORIZED || (syncResult.isException() && syncResult.getException() instanceof AuthenticatorException)) { + requestCredentialsUpdate(); + } else if (ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == syncResult.getCode()) { + showUntrustedCertDialog(syncResult); + } + } } } catch (RuntimeException e) { // avoid app crashes after changing the serial id of RemoteOperationResult diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt index 9c49e9df88a3..54bbad82e7ab 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt @@ -56,6 +56,7 @@ import com.nextcloud.client.di.Injectable import com.nextcloud.client.preferences.AppPreferences import com.nextcloud.client.preferences.AppPreferencesImpl import com.nextcloud.utils.extensions.getTypedActivity +import com.nextcloud.utils.extensions.mainThread import com.owncloud.android.MainApp import com.owncloud.android.R import com.owncloud.android.databinding.ListFragmentBinding @@ -720,6 +721,10 @@ open class ExtendedListFragment : true ) } + }.also { + mainThread { + mRefreshListLayout?.isRefreshing = false + } } }