diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-03-28 11:45:45 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2021-03-28 11:45:45 +0300 |
commit | 49f173b6023a294d8a33ffcd6a7d4c185805fbfd (patch) | |
tree | 5a4a3640ec7cdcdf68b53382226b515973257d44 /app | |
parent | 1d00fcc34ee63e722bc673b580b7b36f5b649e4d (diff) |
#887 Fix endless spinner
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app')
3 files changed, 34 insertions, 9 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java b/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java index e857f0d56..170bf337d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java @@ -15,6 +15,9 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import it.niedermann.nextcloud.deck.util.MimeTypeUtil; @@ -23,6 +26,7 @@ public class DeckLog { private static final StringBuffer DEBUG_LOG = new StringBuffer(); private static boolean PERSIST_LOGS = false; private static final String TAG = DeckLog.class.getSimpleName(); + private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); public static void enablePersistentLogs(boolean persistLogs) { PERSIST_LOGS = persistLogs; @@ -66,7 +70,13 @@ public class DeckLog { final StackTraceElement caller = Thread.currentThread().getStackTrace()[stackTracePosition]; final String print = "(" + caller.getFileName() + ":" + caller.getLineNumber() + ") " + caller.getMethodName() + "() → " + TextUtils.join(" ", messages); if (PERSIST_LOGS) { - DEBUG_LOG.append(print).append("\n"); + DEBUG_LOG + .append(dtf.format(Instant.now().atZone(ZoneId.systemDefault()))) + .append(" ") + .append(severity.name()) + .append(" ") + .append(print) + .append("\n"); } switch (severity) { case DEBUG: diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java index de0acc53b..036d74cb4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java @@ -453,32 +453,36 @@ public class SyncManager { @Override public void onError(Throwable throwable) { if (throwable instanceof NextcloudHttpRequestFailedException) { - NextcloudHttpRequestFailedException requestFailedException = (NextcloudHttpRequestFailedException) throwable; + final NextcloudHttpRequestFailedException requestFailedException = (NextcloudHttpRequestFailedException) throwable; + DeckLog.verbose("HTTP Status " + requestFailedException.getStatusCode()); if (requestFailedException.getStatusCode() == HTTP_UNAVAILABLE && requestFailedException.getCause() != null) { - String errorString = requestFailedException.getCause().getMessage(); - Capabilities capabilities = GsonConfig.getGson().fromJson(errorString, Capabilities.class); - DeckLog.verbose("HTTP Status", HTTP_UNAVAILABLE + ": This server seems to be in maintenance mode."); + final String errorString = requestFailedException.getCause().getMessage(); + final Capabilities capabilities = GsonConfig.getGson().fromJson(errorString, Capabilities.class); if (capabilities.isMaintenanceEnabled()) { + DeckLog.verbose("Yes, it is in maintenance mode according to the capabilities"); doAsync(() -> onResponse(ParsedResponse.of(capabilities))); } else { - onError(throwable); + DeckLog.error("No, it is not in maintenance mode according to the capabilities."); + callback.onError(throwable); } } else if (requestFailedException.getStatusCode() == HTTP_NOT_MODIFIED) { DeckLog.verbose("HTTP Status", HTTP_NOT_MODIFIED + ": There haven't been any changes on the server side for this request."); - //could be after maintenance. so we have to at least revert the maintenance flag + // could be after maintenance. so we have to at least revert the maintenance flag doAsync(() -> { - Account acc = dataBaseAdapter.getAccountByIdDirectly(account.getId()); + final Account acc = dataBaseAdapter.getAccountByIdDirectly(account.getId()); if (acc.isMaintenanceEnabled()) { acc.setMaintenanceEnabled(false); dataBaseAdapter.updateAccount(acc); } - Capabilities capabilities = new Capabilities(); + final Capabilities capabilities = new Capabilities(); capabilities.setMaintenanceEnabled(false); capabilities.setDeckVersion(acc.getServerDeckVersionAsObject()); capabilities.setTextColor(acc.getTextColor()); capabilities.setColor(acc.getColor()); callback.onResponse(capabilities); }); + } else { + callback.onError(throwable); } } else { callback.onError(throwable); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index 58f08237e..d4fe623b3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -385,6 +385,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener binding.swipeRefreshLayout.setOnRefreshListener(() -> { + DeckLog.info("Triggered manual refresh"); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); @@ -399,10 +400,13 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener DeckLog.info("Do not clear Glide caches, because the user currently does not have a working internet connection"); } } else DeckLog.warn("ConnectivityManager is null"); + DeckLog.verbose("Trigger refresh capabilities for", mainViewModel.getCurrentAccount().getName()); refreshCapabilities(mainViewModel.getCurrentAccount()); + DeckLog.verbose("Trigger synchronization for", mainViewModel.getCurrentAccount().getName()); mainViewModel.synchronize(new IResponseCallback<Boolean>(mainViewModel.getCurrentAccount()) { @Override public void onResponse(Boolean response) { + DeckLog.info("End of synchronization for " + mainViewModel.getCurrentAccount().getName() + " → Stop spinner."); runOnUiThread(() -> binding.swipeRefreshLayout.setRefreshing(false)); } @@ -410,6 +414,8 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener public void onError(Throwable throwable) { super.onError(throwable); runOnUiThread(() -> { + DeckLog.logError(throwable); + DeckLog.info("End of synchronization for " + mainViewModel.getCurrentAccount().getName() + " → Stop spinner."); binding.swipeRefreshLayout.setRefreshing(false); showSyncFailedSnackbar(throwable); }); @@ -525,12 +531,16 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener } private void refreshCapabilities(final Account account) { + DeckLog.verbose("Refreshing capabilities for", account.getName()); mainViewModel.refreshCapabilities(new IResponseCallback<Capabilities>(account) { @Override public void onResponse(Capabilities response) { + DeckLog.verbose("Finished refreshing capabilities for", account.getName(), "successfully."); if (response.isMaintenanceEnabled()) { + DeckLog.verbose("Maintenance mode is enabled → Stop spinner."); binding.swipeRefreshLayout.setRefreshing(false); } else { + DeckLog.verbose("Maintenance mode is disabled → Stop spinner."); // If we notice after updating the capabilities, that the new version is not supported, but it was previously, recreate the activity to make sure all elements are disabled properly if (mainViewModel.getCurrentAccount().getServerDeckVersionAsObject().isSupported() && !response.getDeckVersion().isSupported()) { ActivityCompat.recreate(MainActivity.this); @@ -540,6 +550,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener @Override public void onError(Throwable throwable) { + DeckLog.warn("Error on refreshing capabilities for", account.getName(), "(" + throwable.getMessage() + ") → Stop spinner."); binding.swipeRefreshLayout.setRefreshing(false); if (throwable instanceof OfflineException) { DeckLog.info("Cannot refresh capabilities because device is offline."); |