Skip to content

Commit 6f46c64

Browse files
Merge pull request #129 from nextcloud/throwErrorOnAbort
throw exception if SSO import is cancelled
2 parents 3a7b857 + a76ea3b commit 6f46c64

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/main/java/com/nextcloud/android/sso/AccountImporter.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
import android.util.Log;
3535
import android.widget.Toast;
3636

37-
import androidx.core.app.ActivityCompat;
38-
import androidx.core.content.ContextCompat;
39-
import androidx.fragment.app.Fragment;
40-
37+
import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
4138
import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted;
4239
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
4340
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountPermissionNotGrantedException;
@@ -52,6 +49,9 @@
5249
import java.util.Arrays;
5350
import java.util.List;
5451

52+
import androidx.core.app.ActivityCompat;
53+
import androidx.core.content.ContextCompat;
54+
import androidx.fragment.app.Fragment;
5555
import io.reactivex.annotations.NonNull;
5656

5757
import static android.app.Activity.RESULT_CANCELED;
@@ -221,17 +221,18 @@ public interface IAccountAccessGranted {
221221
}
222222

223223
public static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity,
224-
IAccountAccessGranted callback) {
224+
IAccountAccessGranted callback) throws AccountImportCancelledException {
225225
onActivityResult(requestCode, resultCode, data, activity, null, callback);
226226
}
227227

228228
public static void onActivityResult(int requestCode, int resultCode, Intent data, Fragment fragment,
229-
IAccountAccessGranted callback) {
229+
IAccountAccessGranted callback) throws AccountImportCancelledException {
230230
onActivityResult(requestCode, resultCode, data, null, fragment, callback);
231231
}
232232

233233
private static void onActivityResult(int requestCode, int resultCode, Intent data, Activity activity,
234-
Fragment fragment, IAccountAccessGranted callback) {
234+
Fragment fragment, IAccountAccessGranted callback)
235+
throws AccountImportCancelledException {
235236
Context context = (activity != null) ? activity : fragment.getContext();
236237

237238
if (resultCode == RESULT_OK) {
@@ -268,8 +269,8 @@ private static void onActivityResult(int requestCode, int resultCode, Intent dat
268269
} else if (resultCode == RESULT_CANCELED) {
269270
switch (requestCode) {
270271
case CHOOSE_ACCOUNT_SSO:
271-
Toast.makeText(context, R.string.select_account_unknown_error_toast, Toast.LENGTH_LONG).show();
272-
break;
272+
// nothing to do here
273+
throw new AccountImportCancelledException();
273274
case REQUEST_AUTH_TOKEN_SSO:
274275
try {
275276
handleFailedAuthRequest(data);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.nextcloud.android.sso.exceptions;
2+
3+
import android.content.Context;
4+
5+
import com.nextcloud.android.sso.R;
6+
import com.nextcloud.android.sso.model.ExceptionMessage;
7+
8+
/**
9+
* Nextcloud SingleSignOn
10+
*
11+
* @author Tobias Kaminsky
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU General Public License as published by
15+
* the Free Software Foundation, either version 3 of the License, or
16+
* (at your option) any later version.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public License
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
*/
26+
27+
public class AccountImportCancelledException extends SSOException {
28+
29+
@Override
30+
public void loadExceptionMessage(Context context) {
31+
this.em = new ExceptionMessage(
32+
context.getString(R.string.sso_canceled),
33+
context.getString(R.string.sso_canceled_message)
34+
);
35+
}
36+
}

src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@
3838
<string name="nextcloud_files_api_not_responsing_message">Nextcloud files app api is not responding. Please report this issue.</string>
3939

4040
<string name="select_account_unknown_error_toast">Something went wrong.. please try again</string>
41+
<string name="sso_canceled">SSO import canceled</string>
42+
<string name="sso_canceled_message">SSO import was cancelled by user</string>
4143

4244
</resources>

0 commit comments

Comments
 (0)