From 4629fc01615766d0b9c16189fa7299facac58937 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 13 Jan 2021 11:54:55 +0100 Subject: [PATCH] Simplify authentication activity --- .../DownloadAuthenticationActivity.java | 41 ++++--------------- .../config/DownloadServiceCallbacksImpl.java | 1 - 2 files changed, 9 insertions(+), 33 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 912038e4c..5c52d8f86 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -1,41 +1,27 @@ package de.danoeh.antennapod.activity; import android.app.Activity; -import android.content.Intent; import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import android.widget.Button; import android.widget.EditText; import android.widget.TextView; - -import org.apache.commons.lang3.Validate; - +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.storage.DownloadRequester; +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. - * Other arguments are optional. - * The activity's result will be the same DownloadRequest with the entered username and password. */ 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"; - /** - * 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 etxtPassword; @@ -44,18 +30,15 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getNoTitleTheme()); super.onCreate(savedInstanceState); - setContentView(R.layout.download_authentication_activity); - TextView txtvDescription = findViewById(R.id.txtvDescription); + etxtUsername = findViewById(R.id.etxtUsername); 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"); DownloadRequest 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(); txtvDescription.setText(newDescription); @@ -64,22 +47,16 @@ public class DownloadAuthenticationActivity extends AppCompatActivity { etxtPassword.setText(savedInstanceState.getString("password")); } - butConfirm.setOnClickListener(v -> { + findViewById(R.id.butConfirm).setOnClickListener(v -> { String username = etxtUsername.getText().toString(); String password = etxtPassword.getText().toString(); request.setUsername(username); request.setPassword(password); - Intent result = new Intent(); - result.putExtra(RESULT_REQUEST, request); - setResult(Activity.RESULT_OK, result); - - if (sendToDownloadRequester) { - DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); - } + DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); finish(); }); - butCancel.setOnClickListener(v -> { + findViewById(R.id.butCancel).setOnClickListener(v -> { setResult(Activity.RESULT_CANCELED); finish(); }); 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 55bf05e43..f509f6dd4 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java +++ b/app/src/main/java/de/danoeh/antennapod/config/DownloadServiceCallbacksImpl.java @@ -31,7 +31,6 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks { public PendingIntent getAuthentificationNotificationContentIntent(Context context, DownloadRequest request) { final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class); activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request); - activityIntent.putExtra(DownloadAuthenticationActivity.ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, true); return PendingIntent.getActivity(context.getApplicationContext(), R.id.pending_intent_download_service_auth, activityIntent, PendingIntent.FLAG_ONE_SHOT); }