Make errors on 'add feed' page more pretty

This commit is contained in:
ByteHamster 2021-03-04 12:02:00 +01:00
parent 6020f481c5
commit 2e750effa1
2 changed files with 23 additions and 22 deletions

View File

@ -8,7 +8,10 @@ import android.content.SharedPreferences;
import android.graphics.LightingColorFilter; import android.graphics.LightingColorFilter;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -288,11 +291,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
dialog.show(); dialog.show();
} }
} else { } else {
String errorMsg = status.getReason().getErrorString(OnlineFeedViewActivity.this); showErrorDialog(status.getReason().getErrorString(OnlineFeedViewActivity.this), status.getReasonDetailed());
if (status.getReasonDetailed() != null) {
errorMsg += " (" + status.getReasonDetailed() + ")";
}
showErrorDialog(errorMsg);
} }
} }
@ -324,18 +323,17 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
parser = Observable.fromCallable(this::doParseFeed) parser = Observable.fromCallable(this::doParseFeed)
.subscribeOn(Schedulers.computation()) .subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(optionalResult -> { .subscribe(
if(optionalResult.isPresent()) { optionalResult -> {
FeedHandlerResult result = optionalResult.get(); if (optionalResult.isPresent()) {
beforeShowFeedInformation(result.feed); FeedHandlerResult result = optionalResult.get();
showFeedInformation(result.feed, result.alternateFeedUrls); beforeShowFeedInformation(result.feed);
} showFeedInformation(result.feed, result.alternateFeedUrls);
}, error -> { }
String errorMsg = DownloadError.ERROR_PARSER_EXCEPTION.getErrorString( }, error -> {
OnlineFeedViewActivity.this) + " (" + error.getMessage() + ")"; showErrorDialog(error.getMessage(), "");
showErrorDialog(errorMsg); Log.d(TAG, "Feed parser exception: " + Log.getStackTraceString(error));
Log.d(TAG, "Feed parser exception: " + Log.getStackTraceString(error)); });
});
} }
@NonNull @NonNull
@ -350,8 +348,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
if (dialogShown) { if (dialogShown) {
return Optional.empty(); return Optional.empty();
} else { } else {
Log.d(TAG, "Supplied feed is an HTML web page that has no references to any feed"); throw new UnsupportedFeedtypeException(getString(R.string.download_error_unsupported_type_html));
throw e;
} }
} else { } else {
throw e; throw e;
@ -570,12 +567,16 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
} }
@UiThread @UiThread
private void showErrorDialog(String errorMsg) { private void showErrorDialog(String errorMsg, String details) {
if (!isFinishing() && !isPaused) { if (!isFinishing() && !isPaused) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.error_label); builder.setTitle(R.string.error_label);
if (errorMsg != null) { if (errorMsg != null) {
builder.setMessage(errorMsg); String total = errorMsg + "\n\n" + details;
SpannableString errorMessage = new SpannableString(total);
errorMessage.setSpan(new ForegroundColorSpan(0x88888888),
errorMsg.length(), total.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setMessage(errorMessage);
} else { } else {
builder.setMessage(R.string.download_error_error_unknown); builder.setMessage(R.string.download_error_error_unknown);
} }

View File

@ -255,7 +255,7 @@
<string name="download_error_unsupported_type_html">The podcast host\'s server sent a website, not a podcast.</string> <string name="download_error_unsupported_type_html">The podcast host\'s server sent a website, not a podcast.</string>
<string name="download_error_not_found">The podcast host\'s server does not know where to find the file. It may have been deleted.</string> <string name="download_error_not_found">The podcast host\'s server does not know where to find the file. It may have been deleted.</string>
<string name="download_error_connection_error">Connection Error</string> <string name="download_error_connection_error">Connection Error</string>
<string name="download_error_unknown_host">Unknown Host</string> <string name="download_error_unknown_host">Cannot find the server. Check if the address is typed correctly and if you have a working network connection.</string>
<string name="download_error_unauthorized">Authentication Error</string> <string name="download_error_unauthorized">Authentication Error</string>
<string name="download_error_file_type_type">File Type Error</string> <string name="download_error_file_type_type">File Type Error</string>
<string name="download_error_forbidden">The podcast host\'s server refuses to respond.</string> <string name="download_error_forbidden">The podcast host\'s server refuses to respond.</string>