Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSO lib updates #1212

Merged
merged 3 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion News-Android-App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ dependencies {
// implementation 'com.google.android.gms:play-services:4.2.42'
// implementation project(path: ':MaterialShowcaseView:library', configuration: 'default')
// implementation project(':Android-SingleSignOn:lib')
implementation 'com.github.nextcloud:Android-SingleSignOn:0.7.0'
implementation 'com.github.nextcloud:Android-SingleSignOn:0.8.0'
implementation "androidx.core:core:1.10.1"
implementation 'androidx.annotation:annotation:1.6.0'
implementation "androidx.appcompat:appcompat:1.6.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private void loginSingleSignOn() {

resetDatabase();

SingleAccountHelper.setCurrentAccount(this, importedAccount.name);
SingleAccountHelper.commitCurrentAccount(this, importedAccount.name);

mApi.initApi(new NextcloudAPI.ApiConnectedListener() {
@Override
Expand Down Expand Up @@ -365,7 +365,7 @@ private void finishLogin(final ProgressDialog dialogLogin) {
mApi.getNewsAPI().version()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<NextcloudNewsVersion>() {
.subscribe(new Observer<>() {
boolean loginSuccessful = false;

@Override
Expand All @@ -380,7 +380,7 @@ public void onNext(@NonNull NextcloudNewsVersion version) {
loginSuccessful = true;
mPrefs.edit().putString(Constants.NEWS_WEB_VERSION_NUMBER_STRING, version.version).apply();

if(version.version.equals("0")) {
if (version.version.equals("0")) {
ShowAlertDialog(getString(R.string.login_dialog_title_error), getString(R.string.login_dialog_text_zero_version_code), LoginDialogActivity.this);
loginSuccessful = false;
}
Expand All @@ -395,7 +395,7 @@ public void onError(@NonNull Throwable e) {

Throwable t = OkHttpSSLClient.HandleExceptions(e);

if(t instanceof NextcloudHttpRequestFailedException && ((NextcloudHttpRequestFailedException) t).getStatusCode() == 302) {
if (t instanceof NextcloudHttpRequestFailedException && ((NextcloudHttpRequestFailedException) t).getStatusCode() == 302) {
ShowAlertDialog(
getString(R.string.login_dialog_title_error),
getString(R.string.login_dialog_text_news_app_not_installed_on_server,
Expand All @@ -410,12 +410,11 @@ public void onError(@NonNull Throwable e) {
public void onComplete() {
dialogLogin.dismiss();

Log.v(TAG, "onComplete() called");
Log.v(TAG, "onComplete() called - Login successful: " + loginSuccessful);

if(loginSuccessful) {
if (loginSuccessful) {
Intent returnIntent = new Intent();
setResult(RESULT_OK, returnIntent);

finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ public void onPostCreate(Bundle savedInstanceState) {
// Fragments are not ready when calling the method below in onCreate()
updateButtonLayout();

//Start auto sync if enabled
if (mPrefs.getBoolean(SettingsActivity.CB_SYNCONSTARTUP_STRING, true)) {
// Start auto sync if enabled (and user is logged in)
if (isUserLoggedIn() && mPrefs.getBoolean(SettingsActivity.CB_SYNCONSTARTUP_STRING, true)) {
startSync();
}
}
Expand Down Expand Up @@ -744,8 +744,8 @@ public void UpdateItemList() {

public void startSync()
{
if(mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null) == null) {
startLoginActivity();
if (!isUserLoggedIn()) {
startLoginActivity();
} else {
if (!OwnCloudSyncService.isSyncRunning()) {
mPostDelayHandler.stopRunningPostDelayHandler(); //Stop pending sync handler
Expand All @@ -754,7 +754,7 @@ public void startSync()
accBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
AccountManager mAccountManager = AccountManager.get(this);
Account[] accounts = mAccountManager.getAccounts();
for(Account acc : accounts) {
for (Account acc : accounts) {
String accountType = AccountGeneral.getAccountType(this);
if (acc.type.equals(accountType)) {
ContentResolver.requestSync(acc, accountType, accBundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ public void onError(Exception ex) { }
public void initApi(@NonNull NextcloudAPI.ApiConnectedListener apiConnectedListener) {
if(mNextcloudSsoApi != null) {
// Destroy previous Service Connection if we need to reconnect (e.g. login again)
mNextcloudSsoApi.stop();
mNextcloudSsoApi.close();
mNextcloudSsoApi = null;
}

boolean useSSO = mPrefs.getBoolean(SettingsActivity.SW_USE_SINGLE_SIGN_ON, false);
if(useSSO) {
// OkHttpClient client = new OkHttpClient.Builder().build();
// initImageLoader(mPrefs, client, context);
initSsoApi(apiConnectedListener);
} else {
if(mPrefs.contains(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING)) {
Expand All @@ -77,7 +75,6 @@ public void initApi(@NonNull NextcloudAPI.ApiConnectedListener apiConnectedListe
.build();
Log.d("ApiModule", "HttpUrl: " + baseUrl);
OkHttpClient client = OkHttpSSLClient.GetSslClient(baseUrl, username, password, mPrefs, mMemorizingTrustManager);
// initImageLoader(mPrefs, client, context);
initRetrofitApi(baseUrl, client);
apiConnectedListener.onConnected();
} else {
Expand Down