diff options
author | ByteHamster <info@bytehamster.com> | 2021-01-13 12:02:35 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-01-13 12:02:35 +0100 |
commit | ff2ce8f14ced57becb74f751387392e11c714d80 (patch) | |
tree | 2e2b6695f05abe34ef485b0dae77d12c932ed013 /app | |
parent | 4629fc01615766d0b9c16189fa7299facac58937 (diff) | |
download | AntennaPod-ff2ce8f14ced57becb74f751387392e11c714d80.zip |
Store password when entering after failed download
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java index 5c52d8f86..4900f0e27 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -2,16 +2,25 @@ package de.danoeh.antennapod.activity; import android.app.Activity; import android.os.Bundle; +import android.text.TextUtils; import android.widget.EditText; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.feed.FeedPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequester; +import io.reactivex.Completable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; import org.apache.commons.lang3.Validate; + /** * Shows a username and a password text field. * The activity MUST be started with the ARG_DOWNlOAD_REQUEST argument set to a non-null value. @@ -25,6 +34,7 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { private EditText etxtUsername; private EditText etxtPassword; + private DownloadRequest request; @Override protected void onCreate(Bundle savedInstanceState) { @@ -36,7 +46,7 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { etxtPassword = findViewById(R.id.etxtPassword); Validate.isTrue(getIntent().hasExtra(ARG_DOWNLOAD_REQUEST), "Download request missing"); - DownloadRequest request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); + request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); TextView txtvDescription = findViewById(R.id.txtvDescription); String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle(); @@ -47,14 +57,14 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { etxtPassword.setText(savedInstanceState.getString("password")); } - findViewById(R.id.butConfirm).setOnClickListener(v -> { - String username = etxtUsername.getText().toString(); - String password = etxtPassword.getText().toString(); - request.setUsername(username); - request.setPassword(password); - DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); - finish(); - }); + 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); @@ -63,6 +73,26 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { } + 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); + } + } + } + } + @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); |