Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2022-01-17 13:43:43 +0300
committerStefan Niedermann <info@niedermann.it>2022-01-17 13:43:43 +0300
commit7a1a8a2137c066f00bb7ac874706228bf7986347 (patch)
tree4c1d1122f4f9bc7106c06780d996e0096244f3be
parentf0ee4b42e0a224e34f7df7d593585125518a98b1 (diff)
Use @StringRes as message for OfflineException.Reason
And evaluate them in TipsAdapter Signed-off-by: Stefan Niedermann <info@niedermann.it>
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/api/ServerCommunicationErrorHandler.java8
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/exceptions/OfflineException.java53
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java2
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java11
-rw-r--r--app/src/main/res/values/strings.xml4
5 files changed, 42 insertions, 36 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/ServerCommunicationErrorHandler.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/ServerCommunicationErrorHandler.java
index a76bca956..7a12d2062 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/api/ServerCommunicationErrorHandler.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/ServerCommunicationErrorHandler.java
@@ -7,11 +7,11 @@ import java.util.Objects;
import it.niedermann.nextcloud.deck.exceptions.OfflineException;
public class ServerCommunicationErrorHandler {
- public static Throwable translateError (Throwable error){
+ public static Throwable translateError(Throwable error) {
try {
if (error.getClass() == UnknownErrorException.class) {
return handleSsoExceptions(error);
- } else if(error.getClass() == ClassNotFoundException.class) {
+ } else if (error.getClass() == ClassNotFoundException.class) {
return handleClassNotFoundError(error);
}
} catch (NullPointerException e) {
@@ -22,7 +22,7 @@ public class ServerCommunicationErrorHandler {
}
private static Throwable handleClassNotFoundError(Throwable error) {
- String message = Objects.requireNonNull(error.getMessage(), "ClassNotFound handler got no ExceptionMessage").toLowerCase();
+ final String message = Objects.requireNonNull(error.getMessage(), "ClassNotFound handler got no ExceptionMessage").toLowerCase();
if (message.contains("connecttimeoutexception")) {
return new OfflineException(OfflineException.Reason.CONNECTION_TIMEOUT);
}
@@ -30,7 +30,7 @@ public class ServerCommunicationErrorHandler {
}
private static Throwable handleSsoExceptions(Throwable error) {
- String message = Objects.requireNonNull(error.getMessage(), "SSO handler got no ExceptionMessage").toLowerCase();
+ final String message = Objects.requireNonNull(error.getMessage(), "SSO handler got no ExceptionMessage").toLowerCase();
if (message.contains("econnrefused") || message.contains("connection refused")) {
return new OfflineException(OfflineException.Reason.CONNECTION_REFUSED);
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/exceptions/OfflineException.java b/app/src/main/java/it/niedermann/nextcloud/deck/exceptions/OfflineException.java
index bcd41cb16..1415659a5 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/exceptions/OfflineException.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/exceptions/OfflineException.java
@@ -1,45 +1,50 @@
package it.niedermann.nextcloud.deck.exceptions;
-import androidx.annotation.Nullable;
+import androidx.annotation.NonNull;
+import androidx.annotation.StringRes;
+
+import it.niedermann.nextcloud.deck.R;
public class OfflineException extends IllegalStateException {
private final Reason reason;
+ public OfflineException() {
+ this(Reason.OFFLINE);
+ }
+
+ public OfflineException(@NonNull Reason reason) {
+ super(reason.getKey());
+ this.reason = reason;
+ }
+
+ @NonNull
+ public Reason getReason() {
+ return reason;
+ }
+
public enum Reason {
- OFFLINE("offline", "The device is currently offline"),
- CONNECTION_REFUSED("connection_refused", "Connection was refused, please check if your server is reachable"),
- CONNECTION_TIMEOUT("connection_timeout", "Connection timed out, please check if you're connected to the internet"),
+ OFFLINE("Device is currently offline", R.string.error_dialog_tip_offline_no_internet),
+ CONNECTION_REFUSED("Connection refused", R.string.error_dialog_tip_offline_connection_refused),
+ CONNECTION_TIMEOUT("Connection timeout", R.string.error_dialog_tip_offline_connection_timeout),
;
- private String key;
- private String whatHappened;
+ private final String key;
+ @StringRes
+ private final int message;
- Reason(String key, String whatHappened) {
+ Reason(@NonNull String key, @StringRes int message) {
this.key = key;
- this.whatHappened = whatHappened;
+ this.message = message;
}
public String getKey() {
return key;
}
- public String getWhatHappened() {
- return whatHappened;
+ @StringRes
+ public int getMessage() {
+ return message;
}
}
-
-
- public OfflineException() {
- this(Reason.OFFLINE);
- }
- public OfflineException(Reason reason) {
- super(reason.getWhatHappened());
- this.reason = reason;
- }
-
- @Nullable
- public Reason getReason() {
- return reason;
- }
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java
index 75c75f628..4406ce78e 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java
@@ -68,7 +68,7 @@ public class ServerAdapter {
}
public void ensureInternetConnection() {
- boolean isConnected = hasInternetConnection();
+ final boolean isConnected = hasInternetConnection();
if (!isConnected) {
throw new OfflineException();
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java
index 589bc187a..1e52271e4 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/exception/tips/TipsAdapter.java
@@ -17,12 +17,12 @@ import androidx.annotation.StringRes;
import androidx.core.util.Consumer;
import androidx.recyclerview.widget.RecyclerView;
-import com.nextcloud.android.sso.Constants;
import com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException;
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;
import com.nextcloud.android.sso.exceptions.TokenMismatchException;
import com.nextcloud.android.sso.exceptions.UnknownErrorException;
+import com.nextcloud.android.sso.model.FilesAppType;
import org.json.JSONException;
@@ -40,7 +40,6 @@ import it.niedermann.nextcloud.deck.model.Account;
public class TipsAdapter extends RecyclerView.Adapter<TipsViewHolder> {
- private static final String[] APPS = new String[]{Constants.PACKAGE_NAME_PROD, Constants.PACKAGE_NAME_DEV};
private static final Intent INTENT_APP_INFO = new Intent(ACTION_APPLICATION_DETAILS_SETTINGS)
.setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID))
.putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_deck_info);
@@ -80,7 +79,7 @@ public class TipsAdapter extends RecyclerView.Adapter<TipsViewHolder> {
add(R.string.error_dialog_min_version, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.nextcloud.client"))
.putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_update_files_app));
} else if (throwable instanceof OfflineException) {
- add(R.string.error_dialog_tip_offline);
+ add(((OfflineException) throwable).getReason().getMessage());
add(R.string.error_dialog_tip_sync_only_on_wifi);
} else if (throwable instanceof NextcloudApiNotRespondingException) {
add(R.string.error_dialog_tip_disable_battery_optimizations, new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_battery_settings));
@@ -191,10 +190,10 @@ public class TipsAdapter extends RecyclerView.Adapter<TipsViewHolder> {
@Nullable
private static Intent getOpenFilesIntent(@NonNull Context context) {
final var pm = context.getPackageManager();
- for (String app : APPS) {
+ for (final var filesAppType : FilesAppType.values()) {
try {
- pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES);
- return pm.getLaunchIntentForPackage(app)
+ pm.getPackageInfo(filesAppType.packageId, PackageManager.GET_ACTIVITIES);
+ return pm.getLaunchIntentForPackage(filesAppType.packageId)
.putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_nextcloud_app);
} catch (PackageManager.NameNotFoundException ignored) {
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e4fd8edb0..f0f382f45 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -239,7 +239,9 @@
<string name="error_dialog_tip_clear_storage_might_help">If the issue persists, try to clear the storage of both apps: Nextcloud and Nextcloud Deck to solve this issue.</string>
<string name="error_dialog_tip_database_upgrade_failed">The upgrade of the database failed. Please report the issue and clear the storage to use the app normally.</string>
<string name="error_dialog_tip_clear_storage">You can clear the storage by opening the app info and selecting Storage → Clear storage.</string>
- <string name="error_dialog_tip_offline">It looks like you tried to trigger a synchronization without an internet connection.</string>
+ <string name="error_dialog_tip_offline_no_internet">It looks like you tried to trigger a synchronization without an internet connection.</string>
+ <string name="error_dialog_tip_offline_connection_refused">Connection was refused, please check if your server is reachable via web browser.</string>
+ <string name="error_dialog_tip_offline_connection_timeout">Connection timed out, please check if you\'re connected to the internet. This may also happen when your server is busy.</string>
<string name="error_dialog_tip_sync_only_on_wifi">If you have enabled the "Sync only on Wi-Fi" setting, you can only synchronize when you are connected to a Wi-Fi.</string>
<string name="error_dialog_tip_files_force_stop">Something seems to be wrong with your Nextcloud app. Please try to force stop both, the Nextcloud app and the Nextcloud Deck app.</string>
<string name="error_dialog_tip_files_delete_storage">If force stopping them does not help, you can try to clear the storage of both apps.</string>