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;
}
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;
}
}
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();
}
}
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);
}
Aggregations