Search in sources :

Example 1 with OpmlReader

use of de.danoeh.antennapod.core.export.opml.OpmlReader in project AntennaPod by AntennaPod.

the class OpmlImportWorker method doInBackground.

@Override
protected ArrayList<OpmlElement> doInBackground(Void... params) {
    Log.d(TAG, "Starting background work");
    if (mReader == null) {
        return null;
    }
    OpmlReader opmlReader = new OpmlReader();
    try {
        ArrayList<OpmlElement> result = opmlReader.readDocument(mReader);
        mReader.close();
        return result;
    } catch (XmlPullParserException e) {
        e.printStackTrace();
        exception = e;
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        exception = e;
        return null;
    }
}
Also used : OpmlReader(de.danoeh.antennapod.core.export.opml.OpmlReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) OpmlElement(de.danoeh.antennapod.core.export.opml.OpmlElement)

Example 2 with OpmlReader

use of de.danoeh.antennapod.core.export.opml.OpmlReader in project AntennaPod by AntennaPod.

the class OpmlImportActivity method startImport.

/**
 * Starts the import process.
 */
private void startImport() {
    viewBinding.progressBar.setVisibility(View.VISIBLE);
    Observable.fromCallable(() -> {
        InputStream opmlFileStream = getContentResolver().openInputStream(uri);
        BOMInputStream bomInputStream = new BOMInputStream(opmlFileStream);
        ByteOrderMark bom = bomInputStream.getBOM();
        String charsetName = (bom == null) ? "UTF-8" : bom.getCharsetName();
        Reader reader = new InputStreamReader(bomInputStream, charsetName);
        OpmlReader opmlReader = new OpmlReader();
        ArrayList<OpmlElement> result = opmlReader.readDocument(reader);
        reader.close();
        return result;
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        viewBinding.progressBar.setVisibility(View.GONE);
        Log.d(TAG, "Parsing was successful");
        readElements = result;
        listAdapter = new ArrayAdapter<>(OpmlImportActivity.this, android.R.layout.simple_list_item_multiple_choice, getTitleList());
        viewBinding.feedlist.setAdapter(listAdapter);
    }, e -> {
        viewBinding.progressBar.setVisibility(View.GONE);
        AlertDialog.Builder alert = new AlertDialog.Builder(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();
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) BOMInputStream(org.apache.commons.io.input.BOMInputStream) ByteOrderMark(org.apache.commons.io.ByteOrderMark) InputStreamReader(java.io.InputStreamReader) BOMInputStream(org.apache.commons.io.input.BOMInputStream) InputStream(java.io.InputStream) OpmlReader(de.danoeh.antennapod.core.export.opml.OpmlReader) ArrayList(java.util.ArrayList) OpmlReader(de.danoeh.antennapod.core.export.opml.OpmlReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Aggregations

OpmlReader (de.danoeh.antennapod.core.export.opml.OpmlReader)2 AlertDialog (androidx.appcompat.app.AlertDialog)1 OpmlElement (de.danoeh.antennapod.core.export.opml.OpmlElement)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 ByteOrderMark (org.apache.commons.io.ByteOrderMark)1 BOMInputStream (org.apache.commons.io.input.BOMInputStream)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1