Merge pull request #5503 from ByteHamster/remember-password
Remember password when adding new feed
This commit is contained in:
commit
a5cfdff231
|
@ -19,6 +19,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
@ -60,7 +61,6 @@ import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
||||||
import de.danoeh.antennapod.discovery.PodcastSearcherRegistry;
|
import de.danoeh.antennapod.discovery.PodcastSearcherRegistry;
|
||||||
import de.danoeh.antennapod.model.feed.Feed;
|
import de.danoeh.antennapod.model.feed.Feed;
|
||||||
import de.danoeh.antennapod.model.feed.FeedPreferences;
|
import de.danoeh.antennapod.model.feed.FeedPreferences;
|
||||||
import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
|
|
||||||
import de.danoeh.antennapod.model.playback.RemoteMedia;
|
import de.danoeh.antennapod.model.playback.RemoteMedia;
|
||||||
import de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException;
|
import de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException;
|
||||||
import io.reactivex.Maybe;
|
import io.reactivex.Maybe;
|
||||||
|
@ -101,6 +101,8 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
private String selectedDownloadUrl;
|
private String selectedDownloadUrl;
|
||||||
private Downloader downloader;
|
private Downloader downloader;
|
||||||
|
private String username = null;
|
||||||
|
private String password = null;
|
||||||
|
|
||||||
private boolean isPaused;
|
private boolean isPaused;
|
||||||
private boolean didPressSubscribe = false;
|
private boolean didPressSubscribe = false;
|
||||||
|
@ -144,12 +146,11 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
if (feedUrl.contains("subscribeonandroid.com")) {
|
if (feedUrl.contains("subscribeonandroid.com")) {
|
||||||
feedUrl = feedUrl.replaceFirst("((www.)?(subscribeonandroid.com/))", "");
|
feedUrl = feedUrl.replaceFirst("((www.)?(subscribeonandroid.com/))", "");
|
||||||
}
|
}
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState != null) {
|
||||||
lookupUrlAndDownload(feedUrl, null, null);
|
username = savedInstanceState.getString("username");
|
||||||
} else {
|
password = savedInstanceState.getString("password");
|
||||||
lookupUrlAndDownload(feedUrl, savedInstanceState.getString("username"),
|
|
||||||
savedInstanceState.getString("password"));
|
|
||||||
}
|
}
|
||||||
|
lookupUrlAndDownload(feedUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +211,8 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
if (feed != null && feed.getPreferences() != null) {
|
outState.putString("username", username);
|
||||||
outState.putString("username", feed.getPreferences().getUsername());
|
outState.putString("password", password);
|
||||||
outState.putString("password", feed.getPreferences().getPassword());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetIntent(String url) {
|
private void resetIntent(String url) {
|
||||||
|
@ -242,25 +241,21 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lookupUrlAndDownload(String url, String username, String password) {
|
private void lookupUrlAndDownload(String url) {
|
||||||
download = PodcastSearcherRegistry.lookupUrl(url)
|
download = PodcastSearcherRegistry.lookupUrl(url)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(lookedUpUrl -> startFeedDownload(lookedUpUrl, username, password),
|
.subscribe(this::startFeedDownload,
|
||||||
error -> {
|
error -> {
|
||||||
showNoPodcastFoundError();
|
showNoPodcastFoundError();
|
||||||
Log.e(TAG, Log.getStackTraceString(error));
|
Log.e(TAG, Log.getStackTraceString(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startFeedDownload(String url, String username, String password) {
|
private void startFeedDownload(String url) {
|
||||||
Log.d(TAG, "Starting feed download");
|
Log.d(TAG, "Starting feed download");
|
||||||
url = URLChecker.prepareURL(url);
|
url = URLChecker.prepareURL(url);
|
||||||
feed = new Feed(url, null);
|
feed = new Feed(url, null);
|
||||||
if (username != null && password != null) {
|
|
||||||
feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL,
|
|
||||||
VolumeAdaptionSetting.OFF, username, password));
|
|
||||||
}
|
|
||||||
String fileUrl = new File(getExternalCacheDir(),
|
String fileUrl = new File(getExternalCacheDir(),
|
||||||
FileNameGenerator.generateFileName(feed.getDownload_url())).toString();
|
FileNameGenerator.generateFileName(feed.getDownload_url())).toString();
|
||||||
feed.setFile_url(fileUrl);
|
feed.setFile_url(fileUrl);
|
||||||
|
@ -288,6 +283,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
parseFeed();
|
parseFeed();
|
||||||
} else if (status.getReason() == DownloadError.ERROR_UNAUTHORIZED) {
|
} else if (status.getReason() == DownloadError.ERROR_UNAUTHORIZED) {
|
||||||
if (!isFinishing() && !isPaused) {
|
if (!isFinishing() && !isPaused) {
|
||||||
|
if (username != null && password != null) {
|
||||||
|
Toast.makeText(this, R.string.download_error_unauthorized, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
dialog = new FeedViewAuthenticationDialog(OnlineFeedViewActivity.this,
|
dialog = new FeedViewAuthenticationDialog(OnlineFeedViewActivity.this,
|
||||||
R.string.authentication_notification_title,
|
R.string.authentication_notification_title,
|
||||||
downloader.getDownloadRequest().getSource()).create();
|
downloader.getDownloadRequest().getSource()).create();
|
||||||
|
@ -637,21 +635,17 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
if (urls.size() == 1) {
|
if (urls.size() == 1) {
|
||||||
// Skip dialog and display the item directly
|
// Skip dialog and display the item directly
|
||||||
resetIntent(urls.get(0));
|
resetIntent(urls.get(0));
|
||||||
startFeedDownload(urls.get(0), null, null);
|
startFeedDownload(urls.get(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayAdapter<String> adapter = new ArrayAdapter<>(OnlineFeedViewActivity.this, R.layout.ellipsize_start_listitem, R.id.txtvTitle, titles);
|
final ArrayAdapter<String> adapter = new ArrayAdapter<>(OnlineFeedViewActivity.this,
|
||||||
|
R.layout.ellipsize_start_listitem, R.id.txtvTitle, titles);
|
||||||
DialogInterface.OnClickListener onClickListener = (dialog, which) -> {
|
DialogInterface.OnClickListener onClickListener = (dialog, which) -> {
|
||||||
String selectedUrl = urls.get(which);
|
String selectedUrl = urls.get(which);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
resetIntent(selectedUrl);
|
resetIntent(selectedUrl);
|
||||||
FeedPreferences prefs = feed.getPreferences();
|
startFeedDownload(selectedUrl);
|
||||||
if(prefs != null) {
|
|
||||||
startFeedDownload(selectedUrl, prefs.getUsername(), prefs.getPassword());
|
|
||||||
} else {
|
|
||||||
startFeedDownload(selectedUrl, null, null);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AlertDialog.Builder ab = new AlertDialog.Builder(OnlineFeedViewActivity.this)
|
AlertDialog.Builder ab = new AlertDialog.Builder(OnlineFeedViewActivity.this)
|
||||||
|
@ -674,7 +668,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
private final String feedUrl;
|
private final String feedUrl;
|
||||||
|
|
||||||
FeedViewAuthenticationDialog(Context context, int titleRes, String feedUrl) {
|
FeedViewAuthenticationDialog(Context context, int titleRes, String feedUrl) {
|
||||||
super(context, titleRes, true, null, null);
|
super(context, titleRes, true, username, password);
|
||||||
this.feedUrl = feedUrl;
|
this.feedUrl = feedUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +680,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onConfirmed(String username, String password) {
|
protected void onConfirmed(String username, String password) {
|
||||||
startFeedDownload(feedUrl, username, password);
|
OnlineFeedViewActivity.this.username = username;
|
||||||
|
OnlineFeedViewActivity.this.password = password;
|
||||||
|
startFeedDownload(feedUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue