Skip to content

Commit 3fcffec

Browse files
alperozturk96backportbot[bot]
authored andcommitted
since startSyncFolderOperation called onResume and startSyncFolderOperation runs on main thread it must be run on background thread thus executor is used.
Signed-off-by: alperozturk <[email protected]> [skip ci]
1 parent e5a9023 commit 3fcffec

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import com.nextcloud.utils.extensions.BundleExtensionsKt;
6767
import com.nextcloud.utils.extensions.FileExtensionsKt;
6868
import com.nextcloud.utils.extensions.IntentExtensionsKt;
69-
import com.nextcloud.utils.extensions.ViewExtensionsKt;
7069
import com.nextcloud.utils.fileNameValidator.FileNameValidator;
7170
import com.nextcloud.utils.view.FastScrollUtils;
7271
import com.owncloud.android.MainApp;
@@ -146,6 +145,9 @@
146145
import java.util.Collection;
147146
import java.util.List;
148147
import java.util.Optional;
148+
import java.util.concurrent.Executors;
149+
import java.util.concurrent.ScheduledExecutorService;
150+
import java.util.concurrent.TimeUnit;
149151

150152
import javax.inject.Inject;
151153

@@ -2105,35 +2107,36 @@ public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
21052107
* @param ignoreFocus reloads file list even without focus, e.g. on tablet mode, focus can still be in detail view
21062108
*/
21072109
public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag, boolean ignoreFocus) {
2108-
21092110
// the execution is slightly delayed to allow the activity get the window focus if it's being started
21102111
// 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+
}
21202116

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+
}
21232123

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;
21272126

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);
21292130

2131+
// switch back to main thread
2132+
getHandler().post(() -> {
2133+
OCFileListFragment fragment = getListOfFilesFragment();
21302134
if (fragment != null && !(fragment instanceof GalleryFragment)) {
21312135
fragment.setLoading(true);
21322136
}
2133-
21342137
setBackgroundText();
2135-
}, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER);
2136-
}
2138+
});
2139+
}, DELAY_TO_REQUEST_REFRESH_OPERATION_LATER, TimeUnit.MILLISECONDS);
21372140
}
21382141

21392142
private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
@@ -2520,6 +2523,7 @@ public void onReceive(Context context, Intent intent) {
25202523

25212524
@Override
25222525
protected void onDestroy() {
2526+
executor.shutdown();
25232527
LocalBroadcastManager.getInstance(this).unregisterReceiver(refreshFolderEventReceiver);
25242528
super.onDestroy();
25252529
}

0 commit comments

Comments
 (0)