blob: 1e2542b07604910d449d35ca65de35dff297d987 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package it.niedermann.owncloud.notes.shared.util;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import com.nextcloud.android.sso.AccountImporter;
import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.nextcloud.android.sso.ui.UiExceptionManager;
public class SSOUtil {
private static final String TAG = SSOUtil.class.getSimpleName();
private SSOUtil() {
throw new UnsupportedOperationException("Do not instantiate this util class.");
}
/**
* Opens a dialog which allows the user to pick a Nextcloud account (which previously has to be configured in the files app).
* Also allows to configure a new Nextcloud account in the files app and directly import it.
*
* @param activity should implement AccountImporter.onActivityResult
*/
public static void askForNewAccount(@NonNull Activity activity) {
try {
AccountImporter.pickNewAccount(activity);
} catch (NextcloudFilesAppNotInstalledException e1) {
UiExceptionManager.showDialogForException(activity, e1);
Log.w(TAG, "=============================================================");
Log.w(TAG, "Nextcloud app is not installed. Cannot choose account");
e1.printStackTrace();
} catch (AndroidGetAccountsPermissionNotGranted e2) {
AccountImporter.requestAndroidAccountPermissionsAndPickAccount(activity);
}
}
public static boolean isConfigured(Context context) {
try {
SingleAccountHelper.getCurrentSingleSignOnAccount(context);
return true;
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
return false;
}
}
}
|