mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-21 20:35:58 +03:00
Handle not installed Files app more gracefully
This commit is contained in:
parent
04471e5df7
commit
4ff9198319
6 changed files with 25 additions and 12 deletions
|
@ -7,7 +7,8 @@ import it.niedermann.owncloud.notes.R;
|
|||
public enum LoginStatus {
|
||||
OK(0),
|
||||
NO_NETWORK(R.string.error_no_network),
|
||||
JSON_FAILED(R.string.error_json);
|
||||
JSON_FAILED(R.string.error_json),
|
||||
PROBLEM_WITH_FILES_APP(R.string.error_files_app);
|
||||
|
||||
@StringRes
|
||||
public final int str;
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.preference.PreferenceManager;
|
|||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException;
|
||||
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
|
||||
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;
|
||||
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
|
||||
|
@ -327,11 +328,14 @@ public class NoteServerSyncHelper {
|
|||
Log.e(TAG, "Exception", e);
|
||||
exceptions.add(e);
|
||||
} catch (NextcloudHttpRequestFailedException e) {
|
||||
if(e.getStatusCode() == 304) {
|
||||
if (e.getStatusCode() == 304) {
|
||||
Log.d(TAG, "Server returned HTTP Status Code 304 - Not Modified");
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (NextcloudApiNotRespondingException e) {
|
||||
Log.e(TAG, "Exception", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -384,13 +388,15 @@ public class NoteServerSyncHelper {
|
|||
exceptions.add(e);
|
||||
status = LoginStatus.JSON_FAILED;
|
||||
} catch (NextcloudHttpRequestFailedException e) {
|
||||
if(e.getStatusCode() == 304) {
|
||||
if (e.getStatusCode() == 304) {
|
||||
Log.d(TAG, "Server returned HTTP Status Code 304 - Not Modified");
|
||||
return LoginStatus.OK;
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
return LoginStatus.JSON_FAILED;
|
||||
}
|
||||
} catch (NextcloudApiNotRespondingException e) {
|
||||
return LoginStatus.PROBLEM_WITH_FILES_APP;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@ package it.niedermann.owncloud.notes.persistence;
|
|||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.nextcloud.android.sso.aidl.NextcloudRequest;
|
||||
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.NextcloudApiNotRespondingException;
|
||||
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
|
||||
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;
|
||||
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
|
||||
|
@ -26,7 +29,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.util.ServerResponse.NoteResponse;
|
||||
import it.niedermann.owncloud.notes.util.ServerResponse.NotesResponse;
|
||||
|
@ -118,13 +120,13 @@ public class NotesClient {
|
|||
}
|
||||
}
|
||||
|
||||
NotesResponse getNotes(long lastModified, String lastETag) throws NextcloudHttpRequestFailedException {
|
||||
NotesResponse getNotes(long lastModified, String lastETag) throws NextcloudHttpRequestFailedException, NextcloudApiNotRespondingException {
|
||||
Map<String, String> parameter = new HashMap<>();
|
||||
parameter.put(GET_PARAM_KEY_PRUNE_BEFORE, Long.toString(lastModified));
|
||||
return new NotesResponse(requestServer("notes", METHOD_GET, parameter, null, lastETag));
|
||||
}
|
||||
|
||||
private NoteResponse putNote(CloudNote note, String path, String method) throws JSONException, NextcloudHttpRequestFailedException {
|
||||
private NoteResponse putNote(CloudNote note, String path, String method) throws JSONException, NextcloudHttpRequestFailedException, NextcloudApiNotRespondingException {
|
||||
JSONObject paramObject = new JSONObject();
|
||||
paramObject.accumulate(JSON_CONTENT, note.getContent());
|
||||
paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis() / 1000);
|
||||
|
@ -141,11 +143,11 @@ public class NotesClient {
|
|||
* @throws JSONException
|
||||
* @throws NextcloudHttpRequestFailedException
|
||||
*/
|
||||
NoteResponse createNote(CloudNote note) throws JSONException, NextcloudHttpRequestFailedException {
|
||||
NoteResponse createNote(CloudNote note) throws JSONException, NextcloudHttpRequestFailedException, NextcloudApiNotRespondingException {
|
||||
return putNote(note, "notes", METHOD_POST);
|
||||
}
|
||||
|
||||
NoteResponse editNote(CloudNote note) throws JSONException, NextcloudHttpRequestFailedException {
|
||||
NoteResponse editNote(CloudNote note) throws JSONException, NextcloudHttpRequestFailedException, NextcloudApiNotRespondingException {
|
||||
return putNote(note, "notes/" + note.getRemoteId(), METHOD_PUT);
|
||||
}
|
||||
|
||||
|
@ -167,7 +169,7 @@ public class NotesClient {
|
|||
* @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 NextcloudHttpRequestFailedException {
|
||||
private ResponseData requestServer(String target, String method, Map<String, String> parameter, JSONObject requestBody, String lastETag) throws NextcloudHttpRequestFailedException, NextcloudApiNotRespondingException {
|
||||
NextcloudRequest.Builder requestBuilder = new NextcloudRequest.Builder()
|
||||
.setMethod(method)
|
||||
.setUrl(API_PATH + target);
|
||||
|
@ -216,6 +218,8 @@ public class NotesClient {
|
|||
} catch (Exception e) {
|
||||
if(e instanceof NextcloudHttpRequestFailedException) {
|
||||
throw (NextcloudHttpRequestFailedException) e;
|
||||
} else if(e instanceof NextcloudApiNotRespondingException) {
|
||||
throw (NextcloudApiNotRespondingException) e;
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ServerResponse {
|
|||
|
||||
private final NotesClient.ResponseData response;
|
||||
|
||||
public ServerResponse(NotesClient.ResponseData response) {
|
||||
ServerResponse(NotesClient.ResponseData response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class ServerResponse {
|
|||
return response.getLastModified();
|
||||
}
|
||||
|
||||
protected CloudNote getNoteFromJSON(JSONObject json) throws JSONException {
|
||||
CloudNote getNoteFromJSON(JSONObject json) throws JSONException {
|
||||
long id = 0;
|
||||
String title = "";
|
||||
String content = "";
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<string name="error_sync">Synchronization failed: %1$s</string>
|
||||
<string name="error_json">is the Notes app activated on the server?</string>
|
||||
<string name="error_no_network">no network connection</string>
|
||||
<string name="error_files_app">do you have installed the files app?</string>
|
||||
|
||||
<!-- Snackbar Actions -->
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
- Disable accountchooser after added a new account
|
||||
- Enable ripple effect on selecting a note
|
||||
- Enable ripple effect on selecting a note
|
||||
- Handle not installed Files app more gracefully
|
Loading…
Reference in a new issue