Use authentication dialog instead of dedicated activity
This commit is contained in:
parent
c92db6e4b8
commit
bb1d5fc169
|
@ -88,6 +88,7 @@
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.DownloadAuthenticationActivity"
|
android:name=".activity.DownloadAuthenticationActivity"
|
||||||
|
android:theme="@style/Theme.AntennaPod.Dark.Translucent"
|
||||||
android:launchMode="singleInstance"/>
|
android:launchMode="singleInstance"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package de.danoeh.antennapod.activity;
|
package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.TextView;
|
|
||||||
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.FeedMedia;
|
||||||
|
@ -15,6 +11,7 @@ import de.danoeh.antennapod.core.service.download.DownloadRequest;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
|
import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
@ -32,71 +29,48 @@ public class DownloadAuthenticationActivity extends AppCompatActivity {
|
||||||
*/
|
*/
|
||||||
public static final String ARG_DOWNLOAD_REQUEST = "request";
|
public static final String ARG_DOWNLOAD_REQUEST = "request";
|
||||||
|
|
||||||
private EditText etxtUsername;
|
|
||||||
private EditText etxtPassword;
|
|
||||||
private DownloadRequest request;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
setTheme(UserPreferences.getNoTitleTheme());
|
setTheme(UserPreferences.getTranslucentTheme());
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.download_authentication_activity);
|
|
||||||
|
|
||||||
etxtUsername = findViewById(R.id.etxtUsername);
|
|
||||||
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");
|
||||||
request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST);
|
DownloadRequest request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST);
|
||||||
|
|
||||||
TextView txtvDescription = findViewById(R.id.txtvDescription);
|
new AuthenticationDialog(this, R.string.authentication_label, true, "", "") {
|
||||||
String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle();
|
@Override
|
||||||
txtvDescription.setText(newDescription);
|
protected void onConfirmed(String username, String password) {
|
||||||
|
Completable.fromAction(
|
||||||
|
() -> {
|
||||||
|
request.setUsername(username);
|
||||||
|
request.setPassword(password);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
etxtUsername.setText(savedInstanceState.getString("username"));
|
long mediaId = request.getFeedfileId();
|
||||||
etxtPassword.setText(savedInstanceState.getString("password"));
|
FeedMedia media = DBReader.getFeedMedia(mediaId);
|
||||||
}
|
if (media != null) {
|
||||||
|
FeedPreferences preferences = media.getItem().getFeed().getPreferences();
|
||||||
findViewById(R.id.butConfirm).setOnClickListener(v ->
|
if (TextUtils.isEmpty(preferences.getPassword())
|
||||||
Completable.fromAction(this::updatePassword)
|
|| TextUtils.isEmpty(preferences.getUsername())) {
|
||||||
.subscribeOn(Schedulers.io())
|
preferences.setUsername(username);
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
preferences.setPassword(password);
|
||||||
.subscribe(() -> {
|
DBWriter.setFeedPreferences(preferences);
|
||||||
DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request);
|
}
|
||||||
finish();
|
}
|
||||||
}));
|
}
|
||||||
|
})
|
||||||
findViewById(R.id.butCancel).setOnClickListener(v -> {
|
.subscribeOn(Schedulers.io())
|
||||||
setResult(Activity.RESULT_CANCELED);
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
finish();
|
.subscribe(() -> {
|
||||||
});
|
DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request);
|
||||||
|
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 onCancelled() {
|
||||||
super.onSaveInstanceState(outState);
|
finish();
|
||||||
outState.putString("username", etxtUsername.getText().toString());
|
}
|
||||||
outState.putString("password", etxtPassword.getText().toString());
|
}.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
|
||||||
@Override
|
@Override
|
||||||
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.setAction("request" + request.getFeedfileId());
|
||||||
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request);
|
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request);
|
||||||
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);
|
||||||
|
|
|
@ -29,6 +29,7 @@ public abstract class AuthenticationDialog extends AlertDialog.Builder {
|
||||||
etxtPassword.setText(passwordInitialValue);
|
etxtPassword.setText(passwordInitialValue);
|
||||||
}
|
}
|
||||||
setOnCancelListener(dialog -> onCancelled());
|
setOnCancelListener(dialog -> onCancelled());
|
||||||
|
setOnDismissListener(dialog -> onCancelled());
|
||||||
setNegativeButton(R.string.cancel_label, null);
|
setNegativeButton(R.string.cancel_label, null);
|
||||||
setPositiveButton(R.string.confirm_label, (dialog, which)
|
setPositiveButton(R.string.confirm_label, (dialog, which)
|
||||||
-> onConfirmed(etxtUsername.getText().toString(), etxtPassword.getText().toString()));
|
-> onConfirmed(etxtUsername.getText().toString(), etxtPassword.getText().toString()));
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/txtvTitle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/authentication_notification_title"
|
|
||||||
android:textSize="@dimen/text_size_large"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/txtvDescription"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/authentication_notification_msg"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/etxtUsername"
|
|
||||||
android:hint="@string/username_label"
|
|
||||||
android:focusable="true"
|
|
||||||
android:focusableInTouchMode="true"
|
|
||||||
android:cursorVisible="true"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/etxtPassword"
|
|
||||||
android:hint="@string/password_label"
|
|
||||||
android:inputType="textPassword"
|
|
||||||
android:focusable="true"
|
|
||||||
android:focusableInTouchMode="true"
|
|
||||||
android:cursorVisible="true"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="end">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/butCancel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/cancel_label"
|
|
||||||
style="@style/Widget.MaterialComponents.Button.TextButton"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/butConfirm"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/confirm_label"
|
|
||||||
style="@style/Widget.MaterialComponents.Button.TextButton"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
Loading…
Reference in New Issue