diff options
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java | 37 | ||||
-rw-r--r-- | ui/i18n/src/main/res/values/strings.xml | 2 |
2 files changed, 25 insertions, 14 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java index 10a41057c..3f1c17cdc 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportActivity.java @@ -6,7 +6,9 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Environment; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; import android.util.Log; import android.util.SparseBooleanArray; import android.view.Menu; @@ -45,6 +47,7 @@ import java.io.Reader; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; /** * Activity for Opml Import. @@ -140,15 +143,6 @@ public class OpmlImportActivity extends AppCompatActivity { return; } this.uri = uri; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && uri.toString().contains(Environment.getExternalStorageDirectory().toString())) { - int permission = ActivityCompat.checkSelfPermission(this, - android.Manifest.permission.READ_EXTERNAL_STORAGE); - if (permission != PackageManager.PERMISSION_GRANTED) { - requestPermission(); - return; - } - } startImport(); } @@ -244,12 +238,29 @@ public class OpmlImportActivity extends AppCompatActivity { getTitleList()); viewBinding.feedlist.setAdapter(listAdapter); }, e -> { + Log.d(TAG, Log.getStackTraceString(e)); + String message = e.getMessage() == null ? "" : e.getMessage(); + if (message.toLowerCase(Locale.ROOT).contains("permission") + && Build.VERSION.SDK_INT >= 23) { + int permission = ActivityCompat.checkSelfPermission(this, + android.Manifest.permission.READ_EXTERNAL_STORAGE); + if (permission != PackageManager.PERMISSION_GRANTED) { + requestPermission(); + return; + } + } viewBinding.progressBar.setVisibility(View.GONE); MaterialAlertDialogBuilder alert = new MaterialAlertDialogBuilder(this); alert.setTitle(R.string.error_label); - alert.setMessage(getString(R.string.opml_reader_error) + e.getMessage()); - alert.setNeutralButton(android.R.string.ok, (dialog, which) -> dialog.dismiss()); - alert.create().show(); + String userReadable = getString(R.string.opml_reader_error); + String details = e.getMessage(); + String total = userReadable + "\n\n" + details; + SpannableString errorMessage = new SpannableString(total); + errorMessage.setSpan(new ForegroundColorSpan(0x88888888), + userReadable.length(), total.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + alert.setMessage(errorMessage); + alert.setPositiveButton(android.R.string.ok, (dialog, which) -> finish()); + alert.show(); }); } } diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml index ab65b6c41..be9a9dcbc 100644 --- a/ui/i18n/src/main/res/values/strings.xml +++ b/ui/i18n/src/main/res/values/strings.xml @@ -577,7 +577,7 @@ <string name="database_import_summary">Import AntennaPod database from another device</string> <string name="opml_import_label">OPML import</string> <string name="opml_add_podcast_label">Import podcast list (OPML)</string> - <string name="opml_reader_error">An error has occurred while reading the OPML document:</string> + <string name="opml_reader_error">An error has occurred while reading the file. Make sure that you have actually selected an OPML file and that the file is valid.</string> <string name="opml_import_error_no_file">No file selected!</string> <string name="select_all_label">Select all</string> <string name="deselect_all_label">Deselect all</string> |