mirror of https://github.com/readrops/Readrops.git
Display notification when opml export is over
This commit is contained in:
parent
3bef12e7b5
commit
d2bca6f8e8
|
@ -2,6 +2,8 @@ package com.readrops.app.fragments.settings;
|
|||
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
|
@ -9,10 +11,11 @@ import android.os.Bundle;
|
|||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
@ -26,6 +29,7 @@ import com.readrops.app.activities.ManageFeedsFoldersActivity;
|
|||
import com.readrops.app.database.entities.account.Account;
|
||||
import com.readrops.app.database.entities.account.AccountType;
|
||||
import com.readrops.app.utils.OPMLMatcher;
|
||||
import com.readrops.app.utils.ReadropsApp;
|
||||
import com.readrops.app.utils.Utils;
|
||||
import com.readrops.app.viewmodels.AccountViewModel;
|
||||
import com.readrops.readropslibrary.opml.OPMLParser;
|
||||
|
@ -153,13 +157,13 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
|||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
Utils.showSnackbar(getView(), e.getMessage());
|
||||
}
|
||||
})))
|
||||
.show();
|
||||
}
|
||||
|
||||
// region opml parsing
|
||||
// region opml import
|
||||
|
||||
private void openOPMLFile() {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
|
@ -207,6 +211,14 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
|||
});
|
||||
}
|
||||
|
||||
private void displayErrorMessage() {
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.processing_file_failed)
|
||||
.neutralText(R.string.cancel)
|
||||
.iconRes(R.drawable.ic_error)
|
||||
.show();
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region opml export
|
||||
|
@ -232,28 +244,44 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
|||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
displayErrorMessage();
|
||||
Utils.showSnackbar(getView(), e.getMessage());
|
||||
}
|
||||
})
|
||||
.subscribe(new DisposableCompletableObserver() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.d(TAG, "onComplete: ");
|
||||
displayNotification(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Utils.showSnackbar(getView(), e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
|
||||
displayErrorMessage();
|
||||
Utils.showSnackbar(getView(), e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void displayNotification(File file) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(file.getAbsolutePath()));
|
||||
|
||||
Notification notification = new NotificationCompat.Builder(getContext(), ReadropsApp.OPML_EXPORT_CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.opml_export))
|
||||
.setContentText(file.getName())
|
||||
.setSmallIcon(R.drawable.ic_readrops)
|
||||
.setContentIntent(PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.setDeleteIntent(PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.setAutoCancel(true)
|
||||
.build();
|
||||
|
||||
NotificationManagerCompat manager = NotificationManagerCompat.from(getContext());
|
||||
manager.notify(2, notification);
|
||||
}
|
||||
|
||||
private boolean isExternalStoragePermissionGranted() {
|
||||
return ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
@ -288,12 +316,4 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
|
||||
//endregion
|
||||
|
||||
private void displayErrorMessage() {
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.processing_file_failed)
|
||||
.neutralText(R.string.cancel)
|
||||
.iconRes(R.drawable.ic_error)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,28 +14,35 @@ import io.reactivex.plugins.RxJavaPlugins;
|
|||
public class ReadropsApp extends Application {
|
||||
|
||||
public static final String FEEDS_COLORS_CHANNEL_ID = "feedsColorsChannel";
|
||||
public static final String OPML_EXPORT_CHANNEL_ID = "opmlExportChannel";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
RxJavaPlugins.setErrorHandler(e -> { });
|
||||
RxJavaPlugins.setErrorHandler(e -> {
|
||||
});
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Stetho.initializeWithDefaults(this);
|
||||
}
|
||||
|
||||
createNotificationChannel();
|
||||
createNotificationChannels();
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
private void createNotificationChannels() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel feedsColorsChannel = new NotificationChannel(FEEDS_COLORS_CHANNEL_ID,
|
||||
getString(R.string.feeds_colors), NotificationManager.IMPORTANCE_DEFAULT);
|
||||
feedsColorsChannel.setDescription(getString(R.string.get_feeds_colors));
|
||||
|
||||
NotificationChannel opmlExportChannel = new NotificationChannel(OPML_EXPORT_CHANNEL_ID,
|
||||
getString(R.string.opml_export), NotificationManager.IMPORTANCE_DEFAULT);
|
||||
|
||||
NotificationManager manager = getSystemService(NotificationManager.class);
|
||||
|
||||
manager.createNotificationChannel(feedsColorsChannel);
|
||||
manager.createNotificationChannel(opmlExportChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,8 +97,8 @@
|
|||
<string name="opml_processing">Traitement du fichier OPML</string>
|
||||
<string name="operation_takes_time">Cette opération peut prendre un certain temps car il faut interroger chaque flux.</string>
|
||||
<string name="processing_file_failed">Une erreur s\'est produite lors du traitement du fichier</string>
|
||||
<string name="import_opml">Importer un fichier OPML</string>
|
||||
<string name="export_feeds_folders_opml">Exporter les flux et les dossiers dans un fichier OPML</string>
|
||||
<string name="opml_import">Import OPML</string>
|
||||
<string name="opml_export">Export OPML</string>
|
||||
<string name="external_storage_opml_export">L\'export des soubscriptions nécessite l\'accès au stockage</string>
|
||||
<string name="try_again">Réessayer</string>
|
||||
<string name="permissions">Permissions</string>
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
</string-array>
|
||||
|
||||
<string-array name="opml_import_export">
|
||||
<item>@string/import_opml</item>
|
||||
<item>@string/export_feeds_folders_opml</item>
|
||||
<item>@string/opml_import</item>
|
||||
<item>@string/opml_export</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="items_per_feed_numbers_values">
|
||||
|
|
|
@ -105,8 +105,8 @@
|
|||
<string name="opml_processing">Processing OPML file</string>
|
||||
<string name="operation_takes_time">This operation can take a significant time as each feed needs to be queried.</string>
|
||||
<string name="processing_file_failed">An error occurred during the file processing</string>
|
||||
<string name="import_opml">Import OPML file</string>
|
||||
<string name="export_feeds_folders_opml">Export feeds and folders to an OPML file</string>
|
||||
<string name="opml_import">OPML import</string>
|
||||
<string name="opml_export">OPML export</string>
|
||||
<string name="subscriptions" translatable="false">Subscriptions</string>
|
||||
<string name="external_storage_opml_export">Subscriptions export needs external storage permission</string>
|
||||
<string name="try_again">Try again</string>
|
||||
|
|
Loading…
Reference in New Issue