Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ff91983 authored by stefan-niedermann's avatar stefan-niedermann
Browse files

Handle not installed Files app more gracefully

parent 04471e5d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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;
+8 −2
Original line number Diff line number Diff line
@@ -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;
@@ -332,6 +333,9 @@ public class NoteServerSyncHelper {
                    } else {
                        e.printStackTrace();
                    }
                } catch (NextcloudApiNotRespondingException e) {
                    Log.e(TAG, "Exception", e);
                    e.printStackTrace();
                }
            }
        }
@@ -391,6 +395,8 @@ public class NoteServerSyncHelper {
                    e.printStackTrace();
                    return LoginStatus.JSON_FAILED;
                }
            } catch (NextcloudApiNotRespondingException e) {
                return LoginStatus.PROBLEM_WITH_FILES_APP;
            }
            return status;
        }
+10 −6
Original line number Diff line number Diff line
@@ -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();
            }
+2 −2
Original line number Diff line number Diff line
@@ -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 = "";
+1 −0
Original line number Diff line number Diff line
@@ -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 -->

Loading