|
66 | 66 | import com.nextcloud.utils.extensions.BundleExtensionsKt; |
67 | 67 | import com.nextcloud.utils.extensions.FileExtensionsKt; |
68 | 68 | import com.nextcloud.utils.extensions.IntentExtensionsKt; |
69 | | -import com.nextcloud.utils.extensions.ViewExtensionsKt; |
70 | 69 | import com.nextcloud.utils.fileNameValidator.FileNameValidator; |
71 | 70 | import com.nextcloud.utils.view.FastScrollUtils; |
72 | 71 | import com.owncloud.android.MainApp; |
|
146 | 145 | import java.util.Collection; |
147 | 146 | import java.util.List; |
148 | 147 | import java.util.Optional; |
| 148 | +import java.util.concurrent.Executors; |
| 149 | +import java.util.concurrent.ScheduledExecutorService; |
| 150 | +import java.util.concurrent.TimeUnit; |
149 | 151 |
|
150 | 152 | import javax.inject.Inject; |
151 | 153 |
|
@@ -2105,35 +2107,36 @@ public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) { |
2105 | 2107 | * @param ignoreFocus reloads file list even without focus, e.g. on tablet mode, focus can still be in detail view |
2106 | 2108 | */ |
2107 | 2109 | public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag, boolean ignoreFocus) { |
2108 | | - |
2109 | 2110 | // the execution is slightly delayed to allow the activity get the window focus if it's being started |
2110 | 2111 | // or if the method is called from a dialog that is being dismissed |
2111 | | - if (TextUtils.isEmpty(searchQuery) && getUser().isPresent()) { |
2112 | | - getHandler().postDelayed(() -> { |
2113 | | - Optional<User> user = getUser(); |
2114 | | - |
2115 | | - if (!ignoreFocus && !hasWindowFocus() || !user.isPresent()) { |
2116 | | - // do not refresh if the user rotates the device while another window has focus |
2117 | | - // or if the current user is no longer valid |
2118 | | - return; |
2119 | | - } |
| 2112 | + if (!TextUtils.isEmpty(searchQuery) || getUser().isEmpty()) { |
| 2113 | + Log_OC.w(TAG,"Cannot startSyncFolderOperation, search query is empty or user not present"); |
| 2114 | + return; |
| 2115 | + } |
2120 | 2116 |
|
2121 | | - long currentSyncTime = System.currentTimeMillis(); |
2122 | | - mSyncInProgress = true; |
| 2117 | + executor.schedule(() -> { |
| 2118 | + Optional<User> user = getUser(); |
| 2119 | + if (!ignoreFocus && !hasWindowFocus() || user.isEmpty()) { |
| 2120 | + Log_OC.w(TAG,"do not refresh if the user rotates the device while another window has focus or if the current user is no longer valid"); |
| 2121 | + return; |
| 2122 | + } |
2123 | 2123 |
|
2124 | | - // perform folder synchronization |
2125 | | - RemoteOperation refreshFolderOperation = new RefreshFolderOperation(folder, currentSyncTime, false, ignoreETag, getStorageManager(), user.get(), getApplicationContext()); |
2126 | | - refreshFolderOperation.execute(getAccount(), MainApp.getAppContext(), FileDisplayActivity.this, null, null); |
| 2124 | + long currentSyncTime = System.currentTimeMillis(); |
| 2125 | + mSyncInProgress = true; |
2127 | 2126 |
|
2128 | | - OCFileListFragment fragment = getListOfFilesFragment(); |
| 2127 | + // perform folder synchronization on background thread |
| 2128 | + final var refreshFolderOperation = new RefreshFolderOperation(folder, currentSyncTime, false, ignoreETag, getStorageManager(), user.get(), getApplicationContext()); |
| 2129 | + refreshFolderOperation.execute(getAccount(), MainApp.getAppContext(), FileDisplayActivity.this, null, null); |
2129 | 2130 |
|
| 2131 | + // switch back to main thread |
| 2132 | + getHandler().post(() -> { |
| 2133 | + OCFileListFragment fragment = getListOfFilesFragment(); |
2130 | 2134 | if (fragment != null && !(fragment instanceof GalleryFragment)) { |
2131 | 2135 | fragment.setLoading(true); |
2132 | 2136 | } |
2133 | | - |
2134 | 2137 | setBackgroundText(); |
2135 | | - }, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER); |
2136 | | - } |
| 2138 | + }); |
| 2139 | + }, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER, TimeUnit.MILLISECONDS); |
2137 | 2140 | } |
2138 | 2141 |
|
2139 | 2142 | private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) { |
@@ -2520,6 +2523,7 @@ public void onReceive(Context context, Intent intent) { |
2520 | 2523 |
|
2521 | 2524 | @Override |
2522 | 2525 | protected void onDestroy() { |
| 2526 | + executor.shutdown(); |
2523 | 2527 | LocalBroadcastManager.getInstance(this).unregisterReceiver(refreshFolderEventReceiver); |
2524 | 2528 | super.onDestroy(); |
2525 | 2529 | } |
|
0 commit comments