From bb1d5fc16967d81aea549bb2a01051f7430cda36 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 22 Jan 2021 11:59:32 +0100 Subject: [PATCH] Use authentication dialog instead of dedicated activity --- app/src/main/AndroidManifest.xml | 1 + .../DownloadAuthenticationActivity.java | 96 +++++++------------ .../config/DownloadServiceCallbacksImpl.java | 1 + .../dialog/AuthenticationDialog.java | 1 + .../download_authentication_activity.xml | 64 ------------- 5 files changed, 38 insertions(+), 125 deletions(-) delete mode 100644 app/src/main/res/layout/download_authentication_activity.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b4a2c52a3..2d22c7815 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -88,6 +88,7 @@ { + request.setUsername(username); + request.setPassword(password); - if (savedInstanceState != null) { - etxtUsername.setText(savedInstanceState.getString("username")); - etxtPassword.setText(savedInstanceState.getString("password")); - } - - findViewById(R.id.butConfirm).setOnClickListener(v -> - Completable.fromAction(this::updatePassword) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(() -> { - DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); - finish(); - })); - - findViewById(R.id.butCancel).setOnClickListener(v -> { - setResult(Activity.RESULT_CANCELED); - finish(); - }); - - } - - private void updatePassword() { - String username = etxtUsername.getText().toString(); - String password = etxtPassword.getText().toString(); - request.setUsername(username); - request.setPassword(password); - - if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { - long mediaId = request.getFeedfileId(); - FeedMedia media = DBReader.getFeedMedia(mediaId); - if (media != null) { - FeedPreferences preferences = media.getItem().getFeed().getPreferences(); - if (TextUtils.isEmpty(preferences.getPassword()) || TextUtils.isEmpty(preferences.getUsername())) { - preferences.setUsername(username); - preferences.setPassword(password); - DBWriter.setFeedPreferences(preferences); - } + if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { + long mediaId = request.getFeedfileId(); + FeedMedia media = DBReader.getFeedMedia(mediaId); + if (media != null) { + FeedPreferences preferences = media.getItem().getFeed().getPreferences(); + if (TextUtils.isEmpty(preferences.getPassword()) + || TextUtils.isEmpty(preferences.getUsername())) { + preferences.setUsername(username); + preferences.setPassword(password); + DBWriter.setFeedPreferences(preferences); + } + } + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(() -> { + DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); + finish(); + }); } - } - } - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putString("username", etxtUsername.getText().toString()); - outState.putString("password", etxtPassword.getText().toString()); + @Override + protected void onCancelled() { + finish(); + } + }.show(); } } diff --git a/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java index f509f6dd4..f782308d1 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java +++ b/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java @@ -30,6 +30,7 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks { @Override public PendingIntent getAuthentificationNotificationContentIntent(Context context, DownloadRequest request) { final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class); + activityIntent.setAction("request" + request.getFeedfileId()); activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request); return PendingIntent.getActivity(context.getApplicationContext(), R.id.pending_intent_download_service_auth, activityIntent, PendingIntent.FLAG_ONE_SHOT); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java index 39d321f18..d89cc41ca 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java @@ -29,6 +29,7 @@ public abstract class AuthenticationDialog extends AlertDialog.Builder { etxtPassword.setText(passwordInitialValue); } setOnCancelListener(dialog -> onCancelled()); + setOnDismissListener(dialog -> onCancelled()); setNegativeButton(R.string.cancel_label, null); setPositiveButton(R.string.confirm_label, (dialog, which) -> onConfirmed(etxtUsername.getText().toString(), etxtPassword.getText().toString())); diff --git a/app/src/main/res/layout/download_authentication_activity.xml b/app/src/main/res/layout/download_authentication_activity.xml deleted file mode 100644 index e16a8b3a8..000000000 --- a/app/src/main/res/layout/download_authentication_activity.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - -