Loading README.md +26 −23 Original line number Original line Diff line number Diff line Loading @@ -25,7 +25,7 @@ dependencies { ```java ```java private void openAccountChooser() { private void openAccountChooser() { try { try { AccountImporter.PickNewAccount(LoginDialogFragment.this); AccountImporter.PickNewAccount(currentFragment); } catch (NextcloudFilesAppNotInstalledException e) { } catch (NextcloudFilesAppNotInstalledException e) { UiExceptionManager.ShowDialogForException(getActivity(), e); UiExceptionManager.ShowDialogForException(getActivity(), e); } } Loading @@ -35,19 +35,12 @@ private void openAccountChooser() { public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { AccountImporter.onActivityResult(requestCode, resultCode, data, LoginDialogFragment.this, new AccountImporter.IAccountAccessGranted() { if (requestCode == CHOOSE_ACCOUNT_SSO) { @Override String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); public void accountAccessGranted(SingleSignOnAccount account) { Account account = AccountImporter.GetAccountForName(getActivity(), accountName); // TODO init api here.. if(account != null) { SingleAccountHelper.SetCurrentAccount(getActivity(), account); } } } else if (resultCode == RESULT_CANCELED) { if (requestCode == CHOOSE_ACCOUNT_SSO) { // Something went wrong.. } } } }); } } // Complete example: https://github.com/nextcloud/news-android/blob/master/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java // Complete example: https://github.com/nextcloud/news-android/blob/master/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java Loading @@ -56,8 +49,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { 3) How to get account information? 3) How to get account information? ```java ```java Account account = AccountImporter.GetCurrentAccount(getActivity()); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(getActivity(), account); // ssoAccount.name // Name of the account used in the android account manager // ssoAccount.name // Name of the account used in the android account manager // ssoAccount.username // ssoAccount.username Loading Loading @@ -156,14 +148,13 @@ SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(ge private API mApi; private API mApi; public ApiProvider(NextcloudAPI.ApiConnectedListener callback) { public ApiProvider(NextcloudAPI.ApiConnectedListener callback) { Account account = SingleAccountHelper.GetCurrentAccount(context); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(context, account); NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), callback); NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), callback); mApi = new API_SSO(nextcloudAPI); mApi = new API_SSO(nextcloudAPI); } } } } ``` ``` Enjoy! If you're already using retrofit, you don't need to modify your application logic. Just exchange the API and you're good to go! Enjoy! If you're already using retrofit, you don't need to modify your application logic. Just exchange the API and you're good to go! 4.2) **Without Retrofit** 4.2) **Without Retrofit** Loading @@ -177,8 +168,7 @@ SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(ge @Override @Override protected void onStart() { protected void onStart() { Account account = SingleAccountHelper.GetCurrentAccount(context); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(context, account); mNextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), new NextcloudAPI.ApiConnectedListener() { mNextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), new NextcloudAPI.ApiConnectedListener() { @Override @Override public void onConnected() { public void onConnected() { Loading Loading @@ -220,6 +210,19 @@ SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(ge } } ``` ``` ## Additional Info: In case that you require some sso features that were introduced in a specific nextcloud files app version, you can run a simple version check using the following helper method: ```java int MIN_NEXTCLOUD_FILES_APP_VERSION_CODE = 30030052; if (VersionCheckHelper.verifyMinVersion(context, MIN_NEXTCLOUD_FILES_APP_VERSION_CODE)) { // Version requirement is satisfied! } ``` ## Video ## Video   Loading Loading
README.md +26 −23 Original line number Original line Diff line number Diff line Loading @@ -25,7 +25,7 @@ dependencies { ```java ```java private void openAccountChooser() { private void openAccountChooser() { try { try { AccountImporter.PickNewAccount(LoginDialogFragment.this); AccountImporter.PickNewAccount(currentFragment); } catch (NextcloudFilesAppNotInstalledException e) { } catch (NextcloudFilesAppNotInstalledException e) { UiExceptionManager.ShowDialogForException(getActivity(), e); UiExceptionManager.ShowDialogForException(getActivity(), e); } } Loading @@ -35,19 +35,12 @@ private void openAccountChooser() { public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { AccountImporter.onActivityResult(requestCode, resultCode, data, LoginDialogFragment.this, new AccountImporter.IAccountAccessGranted() { if (requestCode == CHOOSE_ACCOUNT_SSO) { @Override String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); public void accountAccessGranted(SingleSignOnAccount account) { Account account = AccountImporter.GetAccountForName(getActivity(), accountName); // TODO init api here.. if(account != null) { SingleAccountHelper.SetCurrentAccount(getActivity(), account); } } } else if (resultCode == RESULT_CANCELED) { if (requestCode == CHOOSE_ACCOUNT_SSO) { // Something went wrong.. } } } }); } } // Complete example: https://github.com/nextcloud/news-android/blob/master/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java // Complete example: https://github.com/nextcloud/news-android/blob/master/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java Loading @@ -56,8 +49,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { 3) How to get account information? 3) How to get account information? ```java ```java Account account = AccountImporter.GetCurrentAccount(getActivity()); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(getActivity(), account); // ssoAccount.name // Name of the account used in the android account manager // ssoAccount.name // Name of the account used in the android account manager // ssoAccount.username // ssoAccount.username Loading Loading @@ -156,14 +148,13 @@ SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(ge private API mApi; private API mApi; public ApiProvider(NextcloudAPI.ApiConnectedListener callback) { public ApiProvider(NextcloudAPI.ApiConnectedListener callback) { Account account = SingleAccountHelper.GetCurrentAccount(context); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(context, account); NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), callback); NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), callback); mApi = new API_SSO(nextcloudAPI); mApi = new API_SSO(nextcloudAPI); } } } } ``` ``` Enjoy! If you're already using retrofit, you don't need to modify your application logic. Just exchange the API and you're good to go! Enjoy! If you're already using retrofit, you don't need to modify your application logic. Just exchange the API and you're good to go! 4.2) **Without Retrofit** 4.2) **Without Retrofit** Loading @@ -177,8 +168,7 @@ SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(ge @Override @Override protected void onStart() { protected void onStart() { Account account = SingleAccountHelper.GetCurrentAccount(context); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(context, account); mNextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), new NextcloudAPI.ApiConnectedListener() { mNextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), new NextcloudAPI.ApiConnectedListener() { @Override @Override public void onConnected() { public void onConnected() { Loading Loading @@ -220,6 +210,19 @@ SingleSignOnAccount ssoAccount = AccountImporter.GetAuthTokenInSeparateThread(ge } } ``` ``` ## Additional Info: In case that you require some sso features that were introduced in a specific nextcloud files app version, you can run a simple version check using the following helper method: ```java int MIN_NEXTCLOUD_FILES_APP_VERSION_CODE = 30030052; if (VersionCheckHelper.verifyMinVersion(context, MIN_NEXTCLOUD_FILES_APP_VERSION_CODE)) { // Version requirement is satisfied! } ``` ## Video ## Video   Loading