Store password when entering after failed download

This commit is contained in:
ByteHamster 2021-01-13 12:02:35 +01:00
parent 4629fc0161
commit ff2ce8f14c
1 changed files with 39 additions and 9 deletions

View File

@ -2,16 +2,25 @@ package de.danoeh.antennapod.activity;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import de.danoeh.antennapod.R; 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.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.DownloadRequest; 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 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; import org.apache.commons.lang3.Validate;
/** /**
* Shows a username and a password text field. * 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. * 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 etxtUsername;
private EditText etxtPassword; private EditText etxtPassword;
private DownloadRequest request;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -36,7 +46,7 @@ public class DownloadAuthenticationActivity extends AppCompatActivity {
etxtPassword = findViewById(R.id.etxtPassword); etxtPassword = findViewById(R.id.etxtPassword);
Validate.isTrue(getIntent().hasExtra(ARG_DOWNLOAD_REQUEST), "Download request missing"); 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); TextView txtvDescription = findViewById(R.id.txtvDescription);
String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle(); String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle();
@ -47,14 +57,14 @@ public class DownloadAuthenticationActivity extends AppCompatActivity {
etxtPassword.setText(savedInstanceState.getString("password")); etxtPassword.setText(savedInstanceState.getString("password"));
} }
findViewById(R.id.butConfirm).setOnClickListener(v -> { findViewById(R.id.butConfirm).setOnClickListener(v ->
String username = etxtUsername.getText().toString(); Completable.fromAction(this::updatePassword)
String password = etxtPassword.getText().toString(); .subscribeOn(Schedulers.io())
request.setUsername(username); .observeOn(AndroidSchedulers.mainThread())
request.setPassword(password); .subscribe(() -> {
DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request);
finish(); finish();
}); }));
findViewById(R.id.butCancel).setOnClickListener(v -> { findViewById(R.id.butCancel).setOnClickListener(v -> {
setResult(Activity.RESULT_CANCELED); 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 @Override
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);