Null handling in OnlineFeedViewActivity (#3004)

This commit is contained in:
Burt Wiley Snyder 2019-02-01 09:57:19 -05:00 committed by H. Lehmann
parent 3b67381656
commit 7f100b3fa6
3 changed files with 19 additions and 9 deletions

View File

@ -29,6 +29,7 @@ import android.widget.TextView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -140,7 +141,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
StorageUtils.checkStorageAvailability(this); StorageUtils.checkStorageAvailability(this);
final String feedUrl; String feedUrl = null;
if (getIntent().hasExtra(ARG_FEEDURL)) { if (getIntent().hasExtra(ARG_FEEDURL)) {
feedUrl = getIntent().getStringExtra(ARG_FEEDURL); feedUrl = getIntent().getStringExtra(ARG_FEEDURL);
} else if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND) } else if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)
@ -150,10 +151,16 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
if (actionBar != null) { if (actionBar != null) {
actionBar.setTitle(R.string.add_feed_label); actionBar.setTitle(R.string.add_feed_label);
} }
} else {
throw new IllegalArgumentException("Activity must be started with feedurl argument!");
} }
if (feedUrl == null) {
Log.e(TAG, "feedUrl is null.");
new AlertDialog.Builder(OnlineFeedViewActivity.this).
setNeutralButton(android.R.string.ok,
(dialog, which) -> dialog.dismiss()).
setTitle(R.string.error_label).
setMessage(R.string.null_value_podcast_error).create().show();
} else {
Log.d(TAG, "Activity was started with url " + feedUrl); Log.d(TAG, "Activity was started with url " + feedUrl);
setLoadingLayout(); setLoadingLayout();
if (savedInstanceState == null) { if (savedInstanceState == null) {
@ -162,6 +169,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
startFeedDownload(feedUrl, savedInstanceState.getString("username"), savedInstanceState.getString("password")); startFeedDownload(feedUrl, savedInstanceState.getString("username"), savedInstanceState.getString("password"));
} }
} }
}
/** /**
* Displays a progress indicator. * Displays a progress indicator.

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.core.util; package de.danoeh.antennapod.core.util;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.core.BuildConfig; import de.danoeh.antennapod.core.BuildConfig;
@ -29,7 +30,7 @@ public final class URLChecker {
* @param url The url which is going to be prepared * @param url The url which is going to be prepared
* @return The prepared url * @return The prepared url
*/ */
public static String prepareURL(String url) { public static String prepareURL(@NonNull String url) {
url = url.trim(); url = url.trim();
if (url.startsWith("feed://")) { if (url.startsWith("feed://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://"); if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");

View File

@ -229,6 +229,7 @@
<string name="download_type_media">Media file</string> <string name="download_type_media">Media file</string>
<string name="download_type_image">Image</string> <string name="download_type_image">Image</string>
<string name="download_request_error_dialog_message_prefix">An error occurred when trying to download the file:\u0020</string> <string name="download_request_error_dialog_message_prefix">An error occurred when trying to download the file:\u0020</string>
<string name="null_value_podcast_error">No podcast was provided that could be shown.</string>
<string name="authentication_notification_title">Authentication required</string> <string name="authentication_notification_title">Authentication required</string>
<string name="authentication_notification_msg">The resource you requested requires a username and a password</string> <string name="authentication_notification_msg">The resource you requested requires a username and a password</string>
<string name="confirm_mobile_download_dialog_title">Confirm Mobile Download</string> <string name="confirm_mobile_download_dialog_title">Confirm Mobile Download</string>