diff --git a/lib/build.gradle b/lib/build.gradle index cb2b1577eebd428d2b69268e56012a1f85274c04..eb0af0b3c8314340ae6d9a6d417cca6205812868 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -18,7 +18,7 @@ group = 'foundation.e.lib' def versionMajor = 1 def versionMinor = 0 -def versionPatch = 3 +def versionPatch = 4 def releasePatch = "alpha" def libName = "Android-SingleSignOn" diff --git a/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java b/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java index dc5248d1aa5c95161eb4697b48e323dc7a140115..d00c96f38ac39848e52259651d12e8d9147cc4e7 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java +++ b/lib/src/main/java/com/nextcloud/android/sso/AccountImporter.java @@ -107,6 +107,29 @@ public class AccountImporter { } } + public static void pickAccount(Activity activity, Account account) throws NextcloudFilesAppNotInstalledException, + AndroidGetAccountsPermissionNotGranted, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + checkAndroidAccountPermissions(activity); + + if (appInstalledOrNot(activity)) { + requestAuthToken(activity, account); + } else { + throw new NextcloudFilesAppNotInstalledException(); + } + } + + public static void pickAccount(Fragment fragment, Account account) throws NextcloudFilesAppNotInstalledException, + AndroidGetAccountsPermissionNotGranted, NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + checkAndroidAccountPermissions(fragment.getContext()); + + if (appInstalledOrNot(fragment.requireContext())) { + requestAuthToken(fragment, account); + } else { + throw new NextcloudFilesAppNotInstalledException(); + } + } + + public static void requestAndroidAccountPermissionsAndPickAccount(Activity activity) { ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.GET_ACCOUNTS}, REQUEST_GET_ACCOUNTS_PERMISSION); @@ -346,7 +369,17 @@ public class AccountImporter { } public static void requestAuthToken(Fragment fragment, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Intent authIntent = buildRequestAuthTokenIntent(fragment.getContext(), intent); + final Account account = getAccount(fragment.getContext(), intent); + requestAuthToken(fragment, account); + } + + public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + final Account account = getAccount(activity, intent); + requestAuthToken(activity, account); + } + + public static void requestAuthToken(Fragment fragment, Account account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + final Intent authIntent = buildRequestAuthTokenIntent(account); try { fragment.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); } catch (ActivityNotFoundException e) { @@ -354,18 +387,20 @@ public class AccountImporter { } } - public static void requestAuthToken(Activity activity, Intent intent) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { - Intent authIntent = buildRequestAuthTokenIntent(activity, intent); + public static void requestAuthToken(Activity activity, Account account) throws NextcloudFilesAppNotSupportedException, NextcloudFilesAppAccountPermissionNotGrantedException { + final Intent authIntent = buildRequestAuthTokenIntent(account); try { activity.startActivityForResult(authIntent, REQUEST_AUTH_TOKEN_SSO); } catch (ActivityNotFoundException e) { throw new NextcloudFilesAppNotSupportedException(); } } + private static Account getAccount(Context context, Intent intent) { + final String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); + return AccountImporter.getAccountForName(context, accountName); + } - private static Intent buildRequestAuthTokenIntent(Context context, Intent intent) throws NextcloudFilesAppAccountPermissionNotGrantedException { - String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); - Account account = AccountImporter.getAccountForName(context, accountName); + private static Intent buildRequestAuthTokenIntent(Account account) throws NextcloudFilesAppAccountPermissionNotGrantedException { if(account == null) { throw new NextcloudFilesAppAccountPermissionNotGrantedException(); }