Search in sources :

Example 1 with ExportWriter

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

the class PreferenceController method export.

private boolean export(ExportWriter exportWriter) {
    Context context = ui.getActivity();
    final ProgressDialog progressDialog = new ProgressDialog(context);
    progressDialog.setMessage(context.getString(R.string.exporting_label));
    progressDialog.setIndeterminate(true);
    progressDialog.show();
    final AlertDialog.Builder alert = new AlertDialog.Builder(context).setNeutralButton(android.R.string.ok, (dialog, which) -> dialog.dismiss());
    Observable<File> observable = new ExportWorker(exportWriter).exportObservable();
    subscription = observable.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(output -> {
        alert.setTitle(R.string.opml_export_success_title);
        String message = context.getString(R.string.opml_export_success_sum) + output.toString();
        alert.setMessage(message);
        alert.setPositiveButton(R.string.send_label, (dialog, which) -> {
            Uri outputUri = Uri.fromFile(output);
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getResources().getText(R.string.opml_export_label));
            sendIntent.putExtra(Intent.EXTRA_STREAM, outputUri);
            sendIntent.setType("text/plain");
            context.startActivity(Intent.createChooser(sendIntent, context.getResources().getText(R.string.send_label)));
        });
        alert.create().show();
    }, error -> {
        alert.setTitle(R.string.export_error_label);
        alert.setMessage(error.getMessage());
        alert.show();
    }, () -> progressDialog.dismiss());
    return true;
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) Arrays(java.util.Arrays) DateUtils(android.text.format.DateUtils) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) FlattrUtils(de.danoeh.antennapod.core.util.flattr.FlattrUtils) PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Manifest(android.Manifest) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) Schedulers(rx.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) GpodnetSyncService(de.danoeh.antennapod.core.service.GpodnetSyncService) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) GpodnetSetHostnameDialog(de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog) GregorianCalendar(java.util.GregorianCalendar) ContextCompat(android.support.v4.content.ContextCompat) ActivityCompat(android.support.v4.app.ActivityCompat) DateFormat(android.text.format.DateFormat) ListPreference(android.preference.ListPreference) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) AutoFlattrPreferenceDialog(de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog) ListView(android.widget.ListView) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Subscription(rx.Subscription) TextWatcher(android.text.TextWatcher) Converter(de.danoeh.antennapod.core.util.Converter) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) ExportWriter(de.danoeh.antennapod.core.export.ExportWriter) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Observable(rx.Observable) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) SuppressLint(android.annotation.SuppressLint) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter) Calendar(java.util.Calendar) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Toast(android.widget.Toast) CrashReportWriter(de.danoeh.antennapod.CrashReportWriter) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Build(android.os.Build) ProxyDialog(de.danoeh.antennapod.dialog.ProxyDialog) R(de.danoeh.antennapod.R) PreferenceActivityGingerbread(de.danoeh.antennapod.activity.PreferenceActivityGingerbread) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) ProgressDialog(android.app.ProgressDialog) File(java.io.File) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) TimeUnit(java.util.concurrent.TimeUnit) WifiManager(android.net.wifi.WifiManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) GpodnetPreferences(de.danoeh.antennapod.core.preferences.GpodnetPreferences) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) File(java.io.File) Uri(android.net.Uri)

Example 2 with ExportWriter

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

the class ImportExportPreferencesFragment method exportWithWriter.

private void exportWithWriter(ExportWriter exportWriter, final Uri uri) {
    Context context = getActivity();
    progressDialog.show();
    if (uri == null) {
        Observable<File> observable = new ExportWorker(exportWriter, getContext()).exportObservable();
        disposable = observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(output -> {
            Uri fileUri = FileProvider.getUriForFile(context.getApplicationContext(), context.getString(R.string.provider_authority), output);
            showExportSuccessDialog(output.toString(), fileUri);
        }, this::showExportErrorDialog, progressDialog::dismiss);
    } else {
        DocumentFileExportWorker worker = new DocumentFileExportWorker(exportWriter, context, uri);
        disposable = worker.exportObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(output -> showExportSuccessDialog(output.getUri().toString(), output.getUri()), this::showExportErrorDialog, progressDialog::dismiss);
    }
}
Also used : Context(android.content.Context) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) PackageManager(android.content.pm.PackageManager) ExportWriter(de.danoeh.antennapod.core.export.ExportWriter) NonNull(androidx.annotation.NonNull) Date(java.util.Date) Completable(io.reactivex.Completable) Uri(android.net.Uri) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) StartActivityForResult(androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult) GetContent(androidx.activity.result.contract.ActivityResultContracts.GetContent) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) PodcastApp(de.danoeh.antennapod.PodcastApp) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Locale(java.util.Locale) OpmlImportActivity(de.danoeh.antennapod.activity.OpmlImportActivity) DatabaseExporter(de.danoeh.antennapod.core.storage.DatabaseExporter) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) R(de.danoeh.antennapod.R) ProgressDialog(android.app.ProgressDialog) File(java.io.File) ResolveInfo(android.content.pm.ResolveInfo) DocumentFileExportWorker(de.danoeh.antennapod.asynctask.DocumentFileExportWorker) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) ActivityNotFoundException(android.content.ActivityNotFoundException) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) FileProvider(androidx.core.content.FileProvider) FavoritesWriter(de.danoeh.antennapod.core.export.favorites.FavoritesWriter) Activity(android.app.Activity) Snackbar(com.google.android.material.snackbar.Snackbar) ActivityResult(androidx.activity.result.ActivityResult) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) DocumentFileExportWorker(de.danoeh.antennapod.asynctask.DocumentFileExportWorker) DocumentFileExportWorker(de.danoeh.antennapod.asynctask.DocumentFileExportWorker) File(java.io.File) Uri(android.net.Uri)

Aggregations

Activity (android.app.Activity)2 ProgressDialog (android.app.ProgressDialog)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Context (android.content.Context)2 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 Uri (android.net.Uri)2 Log (android.util.Log)2 R (de.danoeh.antennapod.R)2 PreferenceActivity (de.danoeh.antennapod.activity.PreferenceActivity)2 ExportWorker (de.danoeh.antennapod.asynctask.ExportWorker)2 ExportWriter (de.danoeh.antennapod.core.export.ExportWriter)2 HtmlWriter (de.danoeh.antennapod.core.export.html.HtmlWriter)2 OpmlWriter (de.danoeh.antennapod.core.export.opml.OpmlWriter)2 UserPreferences (de.danoeh.antennapod.core.preferences.UserPreferences)2 File (java.io.File)2 List (java.util.List)2 Manifest (android.Manifest)1 SuppressLint (android.annotation.SuppressLint)1 TimePickerDialog (android.app.TimePickerDialog)1