|
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; |
69 | 70 | import com.nextcloud.utils.fileNameValidator.FileNameValidator; |
70 | 71 | import com.nextcloud.utils.view.FastScrollUtils; |
71 | 72 | import com.owncloud.android.MainApp; |
|
145 | 146 | import java.util.Collection; |
146 | 147 | import java.util.List; |
147 | 148 | import java.util.Optional; |
148 | | -import java.util.concurrent.Executors; |
149 | | -import java.util.concurrent.ScheduledExecutorService; |
150 | | -import java.util.concurrent.TimeUnit; |
151 | 149 |
|
152 | 150 | import javax.inject.Inject; |
153 | 151 |
|
@@ -254,8 +252,6 @@ public class FileDisplayActivity extends FileActivity |
254 | 252 | */ |
255 | 253 | private long fileIDForImmediatePreview = -1; |
256 | 254 |
|
257 | | - private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors()); |
258 | | - |
259 | 255 | public void setFileIDForImmediatePreview(long fileIDForImmediatePreview) { |
260 | 256 | this.fileIDForImmediatePreview = fileIDForImmediatePreview; |
261 | 257 | } |
@@ -443,19 +439,19 @@ private void checkOutdatedServer() { |
443 | 439 | DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG); |
444 | 440 | } |
445 | 441 | } |
446 | | - |
| 442 | + |
447 | 443 | private void checkNotifications() { |
448 | 444 | new Thread(() -> { |
449 | 445 | try { |
450 | 446 | RemoteOperationResult<List<Notification>> result = new GetNotificationsRemoteOperation() |
451 | 447 | .execute(clientFactory.createNextcloudClient(accountManager.getUser())); |
452 | | - |
| 448 | + |
453 | 449 | if (result.isSuccess() && !result.getResultData().isEmpty()) { |
454 | 450 | runOnUiThread(() -> mNotificationButton.setVisibility(View.VISIBLE)); |
455 | 451 | } else { |
456 | 452 | runOnUiThread(() -> mNotificationButton.setVisibility(View.GONE)); |
457 | 453 | } |
458 | | - |
| 454 | + |
459 | 455 | } catch (ClientFactory.CreationException e) { |
460 | 456 | Log_OC.e(TAG, "Could not fetch notifications!"); |
461 | 457 | } |
@@ -2184,36 +2180,35 @@ public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) { |
2184 | 2180 | * @param ignoreFocus reloads file list even without focus, e.g. on tablet mode, focus can still be in detail view |
2185 | 2181 | */ |
2186 | 2182 | public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag, boolean ignoreFocus) { |
| 2183 | + |
2187 | 2184 | // the execution is slightly delayed to allow the activity get the window focus if it's being started |
2188 | 2185 | // or if the method is called from a dialog that is being dismissed |
2189 | | - if (!TextUtils.isEmpty(searchQuery) || getUser().isEmpty()) { |
2190 | | - Log_OC.w(TAG,"Cannot startSyncFolderOperation, search query is empty or user not present"); |
2191 | | - return; |
2192 | | - } |
2193 | | - |
2194 | | - executor.schedule(() -> { |
2195 | | - Optional<User> user = getUser(); |
2196 | | - if (!ignoreFocus && !hasWindowFocus() || user.isEmpty()) { |
2197 | | - 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"); |
2198 | | - return; |
2199 | | - } |
| 2186 | + if (TextUtils.isEmpty(searchQuery) && getUser().isPresent()) { |
| 2187 | + getHandler().postDelayed(() -> { |
| 2188 | + Optional<User> user = getUser(); |
| 2189 | + |
| 2190 | + if (!ignoreFocus && !hasWindowFocus() || !user.isPresent()) { |
| 2191 | + // do not refresh if the user rotates the device while another window has focus |
| 2192 | + // or if the current user is no longer valid |
| 2193 | + return; |
| 2194 | + } |
2200 | 2195 |
|
2201 | | - long currentSyncTime = System.currentTimeMillis(); |
2202 | | - mSyncInProgress = true; |
| 2196 | + long currentSyncTime = System.currentTimeMillis(); |
| 2197 | + mSyncInProgress = true; |
2203 | 2198 |
|
2204 | | - // perform folder synchronization on background thread |
2205 | | - final var refreshFolderOperation = new RefreshFolderOperation(folder, currentSyncTime, false, ignoreETag, getStorageManager(), user.get(), getApplicationContext()); |
2206 | | - refreshFolderOperation.execute(getAccount(), MainApp.getAppContext(), FileDisplayActivity.this, null, null); |
| 2199 | + // perform folder synchronization |
| 2200 | + RemoteOperation refreshFolderOperation = new RefreshFolderOperation(folder, currentSyncTime, false, ignoreETag, getStorageManager(), user.get(), getApplicationContext()); |
| 2201 | + refreshFolderOperation.execute(getAccount(), MainApp.getAppContext(), FileDisplayActivity.this, null, null); |
2207 | 2202 |
|
2208 | | - // switch back to main thread |
2209 | | - getHandler().post(() -> { |
2210 | 2203 | OCFileListFragment fragment = getListOfFilesFragment(); |
| 2204 | + |
2211 | 2205 | if (fragment != null && !(fragment instanceof GalleryFragment)) { |
2212 | 2206 | fragment.setLoading(true); |
2213 | 2207 | } |
| 2208 | + |
2214 | 2209 | setBackgroundText(); |
2215 | | - }); |
2216 | | - }, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER, TimeUnit.MILLISECONDS); |
| 2210 | + }, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER); |
| 2211 | + } |
2217 | 2212 | } |
2218 | 2213 |
|
2219 | 2214 | private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) { |
@@ -2605,7 +2600,6 @@ public void onReceive(Context context, Intent intent) { |
2605 | 2600 |
|
2606 | 2601 | @Override |
2607 | 2602 | protected void onDestroy() { |
2608 | | - executor.shutdown(); |
2609 | 2603 | LocalBroadcastManager.getInstance(this).unregisterReceiver(refreshFolderEventReceiver); |
2610 | 2604 | super.onDestroy(); |
2611 | 2605 | } |
|
0 commit comments