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

Commit 4259b642 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

enh: Exception handling

parent 0b7add29
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -191,7 +191,7 @@ public class AccountImporter {
                Log.e(TAG, "[getSingleSignOnAccount]", e);
                Log.e(TAG, "[getSingleSignOnAccount]", e);
            }
            }
        }
        }
        throw new NextcloudFilesAppAccountNotFoundException();
        throw new NextcloudFilesAppAccountNotFoundException(accountName);
    }
    }


    public static SingleSignOnAccount extractSingleSignOnAccountFromResponse(Intent intent, Context context) {
    public static SingleSignOnAccount extractSingleSignOnAccountFromResponse(Intent intent, Context context) {
+0 −38
Original line number Original line Diff line number Diff line
/*
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso.exceptions;

import android.content.Context;

import androidx.annotation.NonNull;

import com.nextcloud.android.sso.R;
import com.nextcloud.android.sso.model.ExceptionMessage;

public class CurrentAccountNotFoundException extends SSOException {

    @Override
    public void loadExceptionMessage(@NonNull Context context) {
        this.em = new ExceptionMessage(
            context.getString(R.string.current_account_not_found_exception_title),
            context.getString(R.string.current_account_not_found_exception_message)
        );
    }
}
+16 −4
Original line number Original line Diff line number Diff line
@@ -20,6 +20,9 @@
package com.nextcloud.android.sso.exceptions;
package com.nextcloud.android.sso.exceptions;


import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;


@@ -30,10 +33,19 @@ public class NextcloudApiNotRespondingException extends SSOException {


    @Override
    @Override
    public void loadExceptionMessage(@NonNull Context context) {
    public void loadExceptionMessage(@NonNull Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.em = new ExceptionMessage(
                    context.getString(R.string.nextcloud_files_api_not_responding_title),
                    context.getString(R.string.nextcloud_files_api_not_responding_message),
                    R.string.nextcloud_files_api_not_responding_action,
                    new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
            );
        } else {
            this.em = new ExceptionMessage(
            this.em = new ExceptionMessage(
                    context.getString(R.string.nextcloud_files_api_not_responding_title),
                    context.getString(R.string.nextcloud_files_api_not_responding_title),
                    context.getString(R.string.nextcloud_files_api_not_responding_message)
                    context.getString(R.string.nextcloud_files_api_not_responding_message)
            );
            );
        }
        }
    }


}
}
+20 −1
Original line number Original line Diff line number Diff line
@@ -22,17 +22,36 @@ package com.nextcloud.android.sso.exceptions;
import android.content.Context;
import android.content.Context;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.nextcloud.android.sso.R;
import com.nextcloud.android.sso.R;
import com.nextcloud.android.sso.model.ExceptionMessage;
import com.nextcloud.android.sso.model.ExceptionMessage;


public class NextcloudFilesAppAccountNotFoundException extends SSOException {
public class NextcloudFilesAppAccountNotFoundException extends SSOException {


    @Nullable
    final String accountName;

    public NextcloudFilesAppAccountNotFoundException() {
        this(null);
    }

    public NextcloudFilesAppAccountNotFoundException(@Nullable String accountName) {
        this.accountName = accountName;
    }

    @Override
    @Override
    public void loadExceptionMessage(@NonNull Context context) {
    public void loadExceptionMessage(@NonNull Context context) {
        final String message;
        if (accountName == null) {
            message = context.getString(R.string.nextcloud_files_app_account_not_found_message);
        } else {
            message = context.getString(R.string.nextcloud_files_app_account_not_found_with_account_message, accountName);
        }

        this.em = new ExceptionMessage(
        this.em = new ExceptionMessage(
                context.getString(R.string.nextcloud_files_app_account_not_found_title),
                context.getString(R.string.nextcloud_files_app_account_not_found_title),
                context.getString(R.string.nextcloud_files_app_account_not_found_message)
                message
        );
        );
    }
    }
}
}
+5 −3
Original line number Original line Diff line number Diff line
@@ -20,6 +20,8 @@
package com.nextcloud.android.sso.exceptions;
package com.nextcloud.android.sso.exceptions;


import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;


@@ -32,9 +34,9 @@ public class NextcloudFilesAppNotInstalledException extends SSOException {
    public void loadExceptionMessage(@NonNull Context context) {
    public void loadExceptionMessage(@NonNull Context context) {
        this.em = new ExceptionMessage(
        this.em = new ExceptionMessage(
                context.getString(R.string.nextcloud_files_app_not_installed_title),
                context.getString(R.string.nextcloud_files_app_not_installed_title),
                context.getString(
                context.getString(R.string.nextcloud_files_app_not_installed_message),
                        R.string.nextcloud_files_app_not_installed_message,
                R.string.nextcloud_files_app_not_installed_action,
                        "https://play.google.com/store/apps/details?id=com.nextcloud.client")
                new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.url_files_app_marketplace)))
        );
        );
    }
    }
}
}
Loading