diff options
author | stefan-niedermann <info@niedermann.it> | 2020-01-12 14:07:22 +0300 |
---|---|---|
committer | stefan-niedermann <info@niedermann.it> | 2020-01-12 14:07:22 +0300 |
commit | 0932e46966191d254ae34f0a6caffa625aead2ba (patch) | |
tree | feff444c809f112b57c6bb7924e4d6a814731c44 /app | |
parent | 1fff7daf04ffb5acd5da40c15b81fce94e17b58e (diff) |
#659 Display better hint when files app version is not supported
Diffstat (limited to 'app')
4 files changed, 46 insertions, 28 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/LoginStatus.java b/app/src/main/java/it/niedermann/owncloud/notes/model/LoginStatus.java index 5c984696..7608590d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/LoginStatus.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/LoginStatus.java @@ -9,6 +9,7 @@ public enum LoginStatus { NO_NETWORK(R.string.error_no_network), JSON_FAILED(R.string.error_json), PROBLEM_WITH_FILES_APP(R.string.error_files_app), + FILES_APP_VERSION_TOO_OLD(R.string.error_files_app_version_too_old), UNKNOWN_PROBLEM(R.string.error_unknown); @StringRes diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java index 3861670c..85b8f901 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java @@ -21,6 +21,7 @@ import androidx.appcompat.app.AlertDialog; import com.google.android.material.snackbar.Snackbar; import com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; +import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException; import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; import com.nextcloud.android.sso.helper.SingleAccountHelper; @@ -402,6 +403,9 @@ public class NoteServerSyncHelper { exceptions.add(e); return LoginStatus.JSON_FAILED; } + } catch (NextcloudFilesAppNotSupportedException e) { + exceptions.add(e); + return LoginStatus.FILES_APP_VERSION_TOO_OLD; } catch (NextcloudApiNotRespondingException e) { exceptions.add(e); return LoginStatus.PROBLEM_WITH_FILES_APP; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java index 1db27910..7136c70e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java @@ -1,6 +1,7 @@ package it.niedermann.owncloud.notes.persistence; import android.content.Context; +import android.content.pm.PackageInfo; import android.util.Log; import androidx.annotation.WorkerThread; @@ -11,6 +12,7 @@ import com.nextcloud.android.sso.api.AidlNetworkRequest; import com.nextcloud.android.sso.api.NextcloudAPI; import com.nextcloud.android.sso.api.Response; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; +import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; import com.nextcloud.android.sso.helper.SingleAccountHelper; import com.nextcloud.android.sso.model.SingleSignOnAccount; @@ -93,9 +95,9 @@ public class NotesClient { this.context = context; updateAccount(); } - + void updateAccount() { - if(mNextcloudAPI != null) { + if (mNextcloudAPI != null) { mNextcloudAPI.stop(); } try { @@ -158,18 +160,18 @@ public class NotesClient { /** * Request-Method for POST, PUT with or without JSON-Object-Parameter * - * @param target Filepath to the wanted function - * @param method GET, POST, DELETE or PUT - * @param parameter optional headers to be sent + * @param target Filepath to the wanted function + * @param method GET, POST, DELETE or PUT + * @param parameter optional headers to be sent * @param requestBody JSON Object which shall be transferred to the server. - * @param lastETag optional ETag of last response + * @param lastETag optional ETag of last response * @return Body of answer */ private ResponseData requestServer(String target, String method, Map<String, String> parameter, JSONObject requestBody, String lastETag) throws Exception { NextcloudRequest.Builder requestBuilder = new NextcloudRequest.Builder() .setMethod(method) .setUrl(API_PATH + target); - if(parameter != null) { + if (parameter != null) { requestBuilder.setParameter(parameter); } @@ -188,27 +190,37 @@ public class NotesClient { StringBuilder result = new StringBuilder(); Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString()); - Response response = mNextcloudAPI.performNetworkRequestV2(nextcloudRequest); - Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString()); - BufferedReader rd = new BufferedReader(new InputStreamReader(response.getBody())); - String line; - while ((line = rd.readLine()) != null) { - result.append(line); - } - response.getBody().close(); - - String etag = ""; - AidlNetworkRequest.PlainHeader eTagHeader = response.getPlainHeader(HEADER_KEY_ETAG); - if (eTagHeader != null) { - etag = Objects.requireNonNull(eTagHeader.getValue()).replace("\"", ""); + try { + Response response = mNextcloudAPI.performNetworkRequestV2(nextcloudRequest); + Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString()); + BufferedReader rd = new BufferedReader(new InputStreamReader(response.getBody())); + String line; + while ((line = rd.readLine()) != null) { + result.append(line); + } + response.getBody().close(); + + String etag = ""; + AidlNetworkRequest.PlainHeader eTagHeader = response.getPlainHeader(HEADER_KEY_ETAG); + if (eTagHeader != null) { + etag = Objects.requireNonNull(eTagHeader.getValue()).replace("\"", ""); + } + + long lastModified = 0; + AidlNetworkRequest.PlainHeader lastModifiedHeader = response.getPlainHeader(HEADER_KEY_LAST_MODIFIED); + if (lastModifiedHeader != null) + lastModified = new Date(lastModifiedHeader.getValue()).getTime() / 1000; + Log.d(TAG, "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")"); + // return these header fields since they should only be saved after successful processing the result! + return new ResponseData(result.toString(), etag, lastModified); + } catch (NullPointerException e) { + int MIN_NEXTCLOUD_FILES_APP_VERSION_CODE = 30090000; + PackageInfo pInfo = context.getPackageManager().getPackageInfo("com.nextcloud.client", 0); + if (pInfo.versionCode < MIN_NEXTCLOUD_FILES_APP_VERSION_CODE) { + throw new NextcloudFilesAppNotSupportedException(); + } else { + throw e; + } } - - long lastModified = 0; - AidlNetworkRequest.PlainHeader lastModifiedHeader = response.getPlainHeader(HEADER_KEY_LAST_MODIFIED); - if (lastModifiedHeader != null) - lastModified = new Date(lastModifiedHeader.getValue()).getTime() / 1000; - Log.d(TAG, "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")"); - // return these header fields since they should only be saved after successful processing the result! - return new ResponseData(result.toString(), etag, lastModified); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b80aeb7..33741916 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -138,6 +138,7 @@ <string name="no_notes_yet_description">Press + button to create a new note</string> <string name="could_not_load_preview_two_digit_numbered_list">Could not load preview. Please check whether there is a two-digit numbered list item without content.</string> <string name="simple_more">More</string> + <string name="error_files_app_version_too_old">Is your files app version up to date?</string> <!-- Array: note modes --> <string-array name="noteMode_entries"> |