Search in sources :

Example 1 with OpmlElement

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

the class OpmlFeedQueuer method doInBackground.

@Override
protected Void doInBackground(Void... params) {
    DownloadRequester requester = DownloadRequester.getInstance();
    for (int selected : selection) {
        OpmlElement element = OpmlImportHolder.getReadElements().get(selected);
        Feed feed = new Feed(element.getXmlUrl(), null, element.getText());
        try {
            requester.downloadFeed(context.getApplicationContext(), feed);
        } catch (DownloadRequestException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : DownloadRequester(de.danoeh.antennapod.core.storage.DownloadRequester) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) SuppressLint(android.annotation.SuppressLint) OpmlElement(de.danoeh.antennapod.core.export.opml.OpmlElement) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 2 with OpmlElement

use of de.danoeh.antennapod.core.export.opml.OpmlElement 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 3 with OpmlElement

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

the class OpmlImportBaseActivity method startImport.

/** Starts the import process. */
protected void startImport() {
    try {
        Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8);
        importWorker = new OpmlImportWorker(this, mReader) {

            @Override
            protected void onPostExecute(ArrayList<OpmlElement> result) {
                super.onPostExecute(result);
                if (result != null) {
                    Log.d(TAG, "Parsing was successful");
                    OpmlImportHolder.setReadElements(result);
                    startActivityForResult(new Intent(OpmlImportBaseActivity.this, OpmlFeedChooserActivity.class), 0);
                } else {
                    Log.d(TAG, "Parser error occurred");
                }
            }
        };
        importWorker.executeAsync();
    } catch (Exception e) {
        Log.d(TAG, Log.getStackTraceString(e));
        String message = getString(R.string.opml_reader_error);
        new MaterialDialog.Builder(this).content(message + " " + e.getMessage()).positiveText(android.R.string.ok).show();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Intent(android.content.Intent) OpmlImportWorker(de.danoeh.antennapod.asynctask.OpmlImportWorker) OpmlElement(de.danoeh.antennapod.core.export.opml.OpmlElement)

Example 4 with OpmlElement

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

the class OpmlImportActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    viewBinding = OpmlSelectionBinding.inflate(getLayoutInflater());
    setContentView(viewBinding.getRoot());
    viewBinding.feedlist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    viewBinding.feedlist.setOnItemClickListener((parent, view, position, id) -> {
        SparseBooleanArray checked = viewBinding.feedlist.getCheckedItemPositions();
        int checkedCount = 0;
        for (int i = 0; i < checked.size(); i++) {
            if (checked.valueAt(i)) {
                checkedCount++;
            }
        }
        if (checkedCount == listAdapter.getCount()) {
            selectAll.setVisible(false);
            deselectAll.setVisible(true);
        } else {
            deselectAll.setVisible(false);
            selectAll.setVisible(true);
        }
    });
    viewBinding.butCancel.setOnClickListener(v -> {
        setResult(RESULT_CANCELED);
        finish();
    });
    viewBinding.butConfirm.setOnClickListener(v -> {
        viewBinding.progressBar.setVisibility(View.VISIBLE);
        Completable.fromAction(() -> {
            SparseBooleanArray checked = viewBinding.feedlist.getCheckedItemPositions();
            for (int i = 0; i < checked.size(); i++) {
                if (!checked.valueAt(i)) {
                    continue;
                }
                OpmlElement element = readElements.get(checked.keyAt(i));
                Feed feed = new Feed(element.getXmlUrl(), null, element.getText());
                DownloadService.download(this, false, DownloadRequestCreator.create(feed).build());
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(() -> {
            viewBinding.progressBar.setVisibility(View.GONE);
            Intent intent = new Intent(OpmlImportActivity.this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
        }, e -> {
            viewBinding.progressBar.setVisibility(View.GONE);
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
        });
    });
    Uri uri = getIntent().getData();
    if (uri != null && uri.toString().startsWith("/")) {
        uri = Uri.parse("file://" + uri.toString());
    } else {
        String extraText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
        if (extraText != null) {
            uri = Uri.parse(extraText);
        }
    }
    importUri(uri);
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray) Intent(android.content.Intent) Uri(android.net.Uri) OpmlElement(de.danoeh.antennapod.core.export.opml.OpmlElement) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

OpmlElement (de.danoeh.antennapod.core.export.opml.OpmlElement)4 Intent (android.content.Intent)2 SuppressLint (android.annotation.SuppressLint)1 Uri (android.net.Uri)1 SparseBooleanArray (android.util.SparseBooleanArray)1 OpmlImportWorker (de.danoeh.antennapod.asynctask.OpmlImportWorker)1 OpmlReader (de.danoeh.antennapod.core.export.opml.OpmlReader)1 Feed (de.danoeh.antennapod.core.feed.Feed)1 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)1 DownloadRequester (de.danoeh.antennapod.core.storage.DownloadRequester)1 Feed (de.danoeh.antennapod.model.feed.Feed)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1