diff options
author | David Luhmer <david-dev@live.de> | 2018-06-15 15:29:48 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2018-06-15 15:33:35 +0300 |
commit | 35e3ebcf5bc2c121868270768ebb84c7aaed4246 (patch) | |
tree | df7d69b84669b6c6ae7391bd883a755d8363e901 /News-Android-App | |
parent | cbb9043bdc2be965919586b20d283794c751c921 (diff) |
Update app to use latest nextcloud sso handler (basic error handling)
Diffstat (limited to 'News-Android-App')
5 files changed, 47 insertions, 27 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java index c4b08055..f795f0ea 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java @@ -65,10 +65,13 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import de.luhmer.owncloud.accountimporter.helper.AccountImporter; -import de.luhmer.owncloud.accountimporter.helper.NextcloudAPI; -import de.luhmer.owncloud.accountimporter.helper.SingleSignOnAccount; +import de.luhmer.owncloud.accountimporter.AccountImporter; +import de.luhmer.owncloud.accountimporter.api.NextcloudAPI; +import de.luhmer.owncloud.accountimporter.exceptions.NextcloudFilesAppNotInstalledException; +import de.luhmer.owncloud.accountimporter.helper.SingleAccountHelper; import de.luhmer.owncloud.accountimporter.interfaces.IAccountImport; +import de.luhmer.owncloud.accountimporter.model.SingleSignOnAccount; +import de.luhmer.owncloud.accountimporter.ui.UiExceptionManager; import de.luhmer.owncloudnewsreader.authentication.AuthenticatorActivity; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.di.ApiProvider; @@ -80,7 +83,9 @@ import io.reactivex.annotations.NonNull; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_OK; +import static de.luhmer.owncloud.accountimporter.AccountImporter.CHOOSE_ACCOUNT_SSO; /** * Activity which displays a login screen to the user, offering registration as @@ -89,8 +94,6 @@ import static android.app.Activity.RESULT_OK; public class LoginDialogFragment extends DialogFragment implements IAccountImport { final String TAG = LoginDialogFragment.class.getCanonicalName(); - final int CHOOSE_ACCOUNT = 12; - static LoginDialogFragment instance; public static LoginDialogFragment getInstance() { @@ -256,9 +259,12 @@ public class LoginDialogFragment extends DialogFragment implements IAccountImpor mCbDisableHostnameVerificationView.setVisibility(View.VISIBLE); if(isChecked) { - Intent intent = AccountManager.newChooseAccountIntent(null, null, new String[] {"nextcloud"}, - true, null, null, null, null); - startActivityForResult(intent, CHOOSE_ACCOUNT); + try { + AccountImporter.PickNewAccount(LoginDialogFragment.this); + throw new NextcloudFilesAppNotInstalledException(); + } catch (NextcloudFilesAppNotInstalledException e) { + UiExceptionManager.ShowDialogForException(getActivity(), e); + } } else { importedAccount = null; } @@ -434,7 +440,7 @@ public class LoginDialogFragment extends DialogFragment implements IAccountImpor dialogLogin.show(); if(mSwSingleSignOn.isChecked()) { - AccountImporter.SetCurrentAccount(getActivity(), importedAccount); + SingleAccountHelper.SetCurrentAccount(getActivity(), importedAccount); } @@ -530,15 +536,18 @@ public class LoginDialogFragment extends DialogFragment implements IAccountImpor super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { - if (requestCode == CHOOSE_ACCOUNT) { + if (requestCode == CHOOSE_ACCOUNT_SSO) { importedAccount = null; String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); - Account account = AccountImporter.GetAccountForName(getActivity(), accountName); if(account != null) { accountAccessGranted(account); } } + } else if (resultCode == RESULT_CANCELED) { + if (requestCode == CHOOSE_ACCOUNT_SSO) { + Toast.makeText(getActivity(), "App is not installed!", Toast.LENGTH_LONG).show(); + } } } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index e6027b84..08880154 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -69,7 +69,9 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; -import de.luhmer.owncloud.accountimporter.helper.NextcloudAPI; +import de.luhmer.owncloud.accountimporter.api.NextcloudAPI; +import de.luhmer.owncloud.accountimporter.exceptions.SSOException; +import de.luhmer.owncloud.accountimporter.ui.UiExceptionManager; import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter; import de.luhmer.owncloudnewsreader.LoginDialogFragment.LoginSuccessfulListener; import de.luhmer.owncloudnewsreader.adapter.NewsListRecyclerAdapter; @@ -421,7 +423,13 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(SyncFailedEvent event) { - Toast.makeText(NewsReaderListActivity.this, event.exception().getLocalizedMessage(), Toast.LENGTH_LONG).show(); + Throwable exception = event.exception(); + if(event.exception() instanceof SSOException){ + UiExceptionManager.ShowDialogForException(this, (SSOException) exception); + //UiExceptionManager.ShowNotificationForException(this, (SSOException) exception); + } else { + Toast.makeText(NewsReaderListActivity.this, exception.getLocalizedMessage(), Toast.LENGTH_LONG).show(); + } UpdateButtonLayout(); syncFinishedHandler(); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/di/ApiProvider.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/di/ApiProvider.java index da24281a..87d2e0d0 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/di/ApiProvider.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/di/ApiProvider.java @@ -11,9 +11,11 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; -import de.luhmer.owncloud.accountimporter.helper.AccountImporter; -import de.luhmer.owncloud.accountimporter.helper.NextcloudAPI; -import de.luhmer.owncloud.accountimporter.helper.SingleSignOnAccount; +import de.luhmer.owncloud.accountimporter.AccountImporter; +import de.luhmer.owncloud.accountimporter.api.NextcloudAPI; +import de.luhmer.owncloud.accountimporter.exceptions.SSOException; +import de.luhmer.owncloud.accountimporter.helper.SingleAccountHelper; +import de.luhmer.owncloud.accountimporter.model.SingleSignOnAccount; import de.luhmer.owncloudnewsreader.SettingsActivity; import de.luhmer.owncloudnewsreader.helper.GsonConfig; import de.luhmer.owncloudnewsreader.reader.OkHttpImageDownloader; @@ -70,8 +72,12 @@ public class ApiProvider { initImageLoader(mPrefs, client, context); if(useSSO) { - Account account = AccountImporter.GetCurrentAccount(context); - initSsoApi(account, apiConnectedListener); + try { + Account account = SingleAccountHelper.GetCurrentAccount(context); + initSsoApi(account, apiConnectedListener); + } catch (SSOException e) { + e.printStackTrace(); + } } else { initRetrofitApi(baseUrl, client); apiConnectedListener.onConnected(); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO.java index 373fa275..6dd8f406 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO.java @@ -2,13 +2,14 @@ package de.luhmer.owncloudnewsreader.reader.nextcloud; import com.google.gson.reflect.TypeToken; +import java.io.InputStream; import java.lang.reflect.Type; import java.util.HashMap; import java.util.List; import java.util.Map; -import de.luhmer.owncloud.accountimporter.helper.NextcloudAPI; -import de.luhmer.owncloud.accountimporter.helper.NextcloudRequest; +import de.luhmer.owncloud.accountimporter.aidl.NextcloudRequest; +import de.luhmer.owncloud.accountimporter.api.NextcloudAPI; import de.luhmer.owncloudnewsreader.database.model.Feed; import de.luhmer.owncloudnewsreader.database.model.Folder; import de.luhmer.owncloudnewsreader.database.model.RssItem; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO_Helper.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO_Helper.java index db3a2fbf..6159202e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO_Helper.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/nextcloud/API_SSO_Helper.java @@ -1,14 +1,10 @@ package de.luhmer.owncloudnewsreader.reader.nextcloud; -import android.os.ParcelFileDescriptor; -import android.os.RemoteException; - -import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; -import de.luhmer.owncloud.accountimporter.helper.NextcloudAPI; -import de.luhmer.owncloud.accountimporter.helper.NextcloudRequest; +import de.luhmer.owncloud.accountimporter.aidl.NextcloudRequest; +import de.luhmer.owncloud.accountimporter.api.NextcloudAPI; import io.reactivex.Completable; import io.reactivex.functions.Action; import okhttp3.Request; @@ -41,7 +37,7 @@ public class API_SSO_Helper { public static <T> Call<T> WrapInCall(final NextcloudAPI nextcloudAPI, final NextcloudRequest nextcloudRequest, final Type resType) { return new Call<T>() { @Override - public Response<T> execute() throws IOException { + public Response<T> execute() { try { T body = nextcloudAPI.performRequest(resType, nextcloudRequest); return Response.success(body); |