mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-25 00:14:00 +01:00
Tweak OPML import (#6906)
- Only request storage permission when ContentResolver fails - Easier to read error message
This commit is contained in:
parent
0f5600932d
commit
c07ae17962
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user