Merge pull request #4855 from ByteHamster/simplify-password
Remember entered password
This commit is contained in:
commit
092e9a9a20
@ -1,61 +1,54 @@
|
|||||||
package de.danoeh.antennapod.activity;
|
package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import org.apache.commons.lang3.Validate;
|
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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
* Other arguments are optional.
|
|
||||||
* The activity's result will be the same DownloadRequest with the entered username and password.
|
|
||||||
*/
|
*/
|
||||||
public class DownloadAuthenticationActivity extends AppCompatActivity {
|
public class DownloadAuthenticationActivity extends AppCompatActivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The download request object that contains information about the resource that requires a username and a password
|
* The download request object that contains information about the resource that requires a username and a password.
|
||||||
*/
|
*/
|
||||||
public static final String ARG_DOWNLOAD_REQUEST = "request";
|
public static final String ARG_DOWNLOAD_REQUEST = "request";
|
||||||
/**
|
|
||||||
* True if the request should be sent to the DownloadRequester when this activity is finished, false otherwise.
|
|
||||||
* The default value is false.
|
|
||||||
*/
|
|
||||||
public static final String ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL = "send_to_downloadrequester";
|
|
||||||
|
|
||||||
private static final String RESULT_REQUEST = "request";
|
|
||||||
|
|
||||||
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) {
|
||||||
setTheme(UserPreferences.getNoTitleTheme());
|
setTheme(UserPreferences.getNoTitleTheme());
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.download_authentication_activity);
|
setContentView(R.layout.download_authentication_activity);
|
||||||
TextView txtvDescription = findViewById(R.id.txtvDescription);
|
|
||||||
etxtUsername = findViewById(R.id.etxtUsername);
|
etxtUsername = findViewById(R.id.etxtUsername);
|
||||||
etxtPassword = findViewById(R.id.etxtPassword);
|
etxtPassword = findViewById(R.id.etxtPassword);
|
||||||
Button butConfirm = findViewById(R.id.butConfirm);
|
|
||||||
Button butCancel = findViewById(R.id.butCancel);
|
|
||||||
|
|
||||||
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);
|
||||||
boolean sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false);
|
|
||||||
|
|
||||||
|
TextView txtvDescription = findViewById(R.id.txtvDescription);
|
||||||
String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle();
|
String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle();
|
||||||
txtvDescription.setText(newDescription);
|
txtvDescription.setText(newDescription);
|
||||||
|
|
||||||
@ -64,28 +57,42 @@ public class DownloadAuthenticationActivity extends AppCompatActivity {
|
|||||||
etxtPassword.setText(savedInstanceState.getString("password"));
|
etxtPassword.setText(savedInstanceState.getString("password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
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(() -> {
|
||||||
Intent result = new Intent();
|
DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request);
|
||||||
result.putExtra(RESULT_REQUEST, request);
|
finish();
|
||||||
setResult(Activity.RESULT_OK, result);
|
}));
|
||||||
|
|
||||||
if (sendToDownloadRequester) {
|
findViewById(R.id.butCancel).setOnClickListener(v -> {
|
||||||
DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request);
|
|
||||||
}
|
|
||||||
finish();
|
|
||||||
});
|
|
||||||
|
|
||||||
butCancel.setOnClickListener(v -> {
|
|
||||||
setResult(Activity.RESULT_CANCELED);
|
setResult(Activity.RESULT_CANCELED);
|
||||||
finish();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
@ -31,7 +31,6 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
|
|||||||
public PendingIntent getAuthentificationNotificationContentIntent(Context context, DownloadRequest request) {
|
public PendingIntent getAuthentificationNotificationContentIntent(Context context, DownloadRequest request) {
|
||||||
final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class);
|
final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class);
|
||||||
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request);
|
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request);
|
||||||
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, true);
|
|
||||||
return PendingIntent.getActivity(context.getApplicationContext(),
|
return PendingIntent.getActivity(context.getApplicationContext(),
|
||||||
R.id.pending_intent_download_service_auth, activityIntent, PendingIntent.FLAG_ONE_SHOT);
|
R.id.pending_intent_download_service_auth, activityIntent, PendingIntent.FLAG_ONE_SHOT);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user