Skip to content

Commit c9c3c99

Browse files
Merge pull request #15932 from nextcloud/fix/loading-indicator
fix: loading indicator
2 parents 8bab794 + 596468e commit c9c3c99

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

app/src/main/java/com/nextcloud/utils/extensions/Extensions.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
package com.nextcloud.utils.extensions
1010

11+
import android.os.Handler
12+
import android.os.Looper
1113
import android.os.SystemClock
1214
import android.text.Selection
1315
import android.text.Spannable
@@ -24,6 +26,12 @@ import java.text.SimpleDateFormat
2426
import java.util.Date
2527
import java.util.Locale
2628

29+
fun mainThread(delay: Long = 1000, action: () -> Unit) {
30+
Handler(Looper.getMainLooper()).postDelayed({
31+
action()
32+
}, delay)
33+
}
34+
2735
fun clickWithDebounce(view: View, debounceTime: Long = 600L, action: () -> Unit) {
2836
view.setOnClickListener(object : View.OnClickListener {
2937
private var lastClickTime: Long = 0

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

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
148148

149149
private SyncBroadcastReceiver mSyncBroadcastReceiver;
150150
private ReceiveExternalFilesAdapter receiveExternalFilesAdapter;
151-
private boolean mSyncInProgress;
152151

153152
private final static int REQUEST_CODE__SETUP_ACCOUNT = REQUEST_CODE__LAST_SHARED + 1;
154153

@@ -856,7 +855,6 @@ private void startSyncFolderOperation(OCFile folder) {
856855

857856
executorService.execute(() -> {
858857
long currentSyncTime = System.currentTimeMillis();
859-
mSyncInProgress = true;
860858
final var optionalUser = getUser();
861859
if (optionalUser.isEmpty()) {
862860
DisplayUtils.showSnackMessage(this, R.string.user_information_retrieval_error);
@@ -1155,58 +1153,32 @@ public void onReceive(Context context, Intent intent) {
11551153
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name)
11561154
&& getStorageManager() != null;
11571155

1158-
if (sameAccount) {
1159-
1160-
if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
1161-
mSyncInProgress = true;
1156+
if (sameAccount && !FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
1157+
OCFile currentFile = (mFile == null) ? null : getStorageManager().getFileByPath(mFile.getRemotePath());
1158+
OCFile currentDir = (getCurrentFolder() == null) ? null : getStorageManager().getFileByPath(getCurrentFolder().getRemotePath());
11621159

1160+
if (currentDir == null) {
1161+
// current folder was removed from the server
1162+
DisplayUtils.showSnackMessage(getActivity(), R.string.sync_current_folder_was_removed, getCurrentFolder().getFileName());
1163+
browseToRoot();
11631164
} else {
1164-
OCFile currentFile = (mFile == null) ? null :
1165-
getStorageManager().getFileByPath(mFile.getRemotePath());
1166-
OCFile currentDir = (getCurrentFolder() == null) ? null :
1167-
getStorageManager().getFileByPath(getCurrentFolder().getRemotePath());
1168-
1169-
if (currentDir == null) {
1170-
// current folder was removed from the server
1171-
DisplayUtils.showSnackMessage(
1172-
getActivity(),
1173-
R.string.sync_current_folder_was_removed,
1174-
getCurrentFolder().getFileName()
1175-
);
1176-
browseToRoot();
1177-
1178-
} else {
1179-
if (currentFile == null && !mFile.isFolder()) {
1180-
// currently selected file was removed in the server, and now we know it
1181-
currentFile = currentDir;
1182-
}
1183-
1184-
if (currentDir.getRemotePath().equals(syncFolderRemotePath)) {
1185-
populateDirectoryList(currentFile);
1186-
}
1165+
if (currentFile == null && !mFile.isFolder()) {
1166+
// currently selected file was removed in the server, and now we know it
1167+
currentFile = currentDir;
11871168
}
11881169

1189-
mSyncInProgress = !FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
1190-
!RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event);
1191-
1192-
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event)
1193-
/// TODO refactor and make common
1194-
&& syncResult != null && !syncResult.isSuccess()) {
1195-
1196-
if (syncResult.getCode() == ResultCode.UNAUTHORIZED ||
1197-
(syncResult.isException() && syncResult.getException()
1198-
instanceof AuthenticatorException)) {
1199-
1200-
requestCredentialsUpdate();
1201-
1202-
} else if (ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == syncResult.getCode()) {
1203-
1204-
showUntrustedCertDialog(syncResult);
1205-
}
1170+
if (currentDir.getRemotePath().equals(syncFolderRemotePath)) {
1171+
populateDirectoryList(currentFile);
12061172
}
12071173
}
1208-
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
12091174

1175+
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event) && syncResult != null && !syncResult.isSuccess()) {
1176+
if (syncResult.getCode() == ResultCode.UNAUTHORIZED || (syncResult.isException() && syncResult.getException() instanceof AuthenticatorException)) {
1177+
requestCredentialsUpdate();
1178+
} else if (ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == syncResult.getCode()) {
1179+
showUntrustedCertDialog(syncResult);
1180+
}
1181+
}
12101182
}
12111183
} catch (RuntimeException e) {
12121184
// avoid app crashes after changing the serial id of RemoteOperationResult

app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import com.nextcloud.client.di.Injectable
5656
import com.nextcloud.client.preferences.AppPreferences
5757
import com.nextcloud.client.preferences.AppPreferencesImpl
5858
import com.nextcloud.utils.extensions.getTypedActivity
59+
import com.nextcloud.utils.extensions.mainThread
5960
import com.owncloud.android.MainApp
6061
import com.owncloud.android.R
6162
import com.owncloud.android.databinding.ListFragmentBinding
@@ -720,6 +721,10 @@ open class ExtendedListFragment :
720721
true
721722
)
722723
}
724+
}.also {
725+
mainThread {
726+
mRefreshListLayout?.isRefreshing = false
727+
}
723728
}
724729
}
725730

0 commit comments

Comments
 (0)