Use a notification instead of a ProgressDialog in MissionAdapter.
This commit is contained in:
parent
0ced9ba799
commit
917f459569
3 changed files with 36 additions and 20 deletions
|
@ -242,8 +242,9 @@ public class App extends MultiDexApplication {
|
|||
String name = getString(R.string.notification_channel_name);
|
||||
String description = getString(R.string.notification_channel_description);
|
||||
|
||||
// Keep this below DEFAULT to avoid making noise on every notification update
|
||||
final int importance = NotificationManager.IMPORTANCE_LOW;
|
||||
// Keep this below DEFAULT to avoid making noise on every notification update for the main
|
||||
// and update channels
|
||||
int importance = NotificationManager.IMPORTANCE_LOW;
|
||||
|
||||
final NotificationChannel mainChannel = new NotificationChannel(id, name, importance);
|
||||
mainChannel.setDescription(description);
|
||||
|
@ -255,9 +256,17 @@ public class App extends MultiDexApplication {
|
|||
final NotificationChannel appUpdateChannel = new NotificationChannel(id, name, importance);
|
||||
appUpdateChannel.setDescription(description);
|
||||
|
||||
id = getString(R.string.hash_channel_id);
|
||||
name = getString(R.string.hash_channel_name);
|
||||
description = getString(R.string.hash_channel_description);
|
||||
importance = NotificationManager.IMPORTANCE_HIGH;
|
||||
|
||||
final NotificationChannel hashChannel = new NotificationChannel(id, name, importance);
|
||||
hashChannel.setDescription(description);
|
||||
|
||||
final NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||
notificationManager.createNotificationChannels(Arrays.asList(mainChannel,
|
||||
appUpdateChannel));
|
||||
appUpdateChannel, hashChannel));
|
||||
}
|
||||
|
||||
protected boolean isDisposedRxExceptionsReported() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package us.shandian.giga.ui.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
|
@ -26,6 +26,8 @@ import android.widget.Toast;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
|
@ -91,6 +93,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
|
|||
private static final String DEFAULT_MIME_TYPE = "*/*";
|
||||
private static final String UNDEFINED_ETA = "--:--";
|
||||
|
||||
private static final int HASH_NOTIFICATION_ID = 123790;
|
||||
|
||||
static {
|
||||
ALGORITHMS.put(R.id.md5, "MD5");
|
||||
|
@ -678,28 +681,28 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
|
|||
return true;
|
||||
case R.id.md5:
|
||||
case R.id.sha1:
|
||||
ProgressDialog progressDialog = null;
|
||||
if (mContext != null) {
|
||||
// Create dialog
|
||||
progressDialog = new ProgressDialog(mContext);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.setMessage(mContext.getString(R.string.msg_wait));
|
||||
progressDialog.show();
|
||||
}
|
||||
final ProgressDialog finalProgressDialog = progressDialog;
|
||||
final NotificationManager notificationManager
|
||||
= ContextCompat.getSystemService(mContext, NotificationManager.class);
|
||||
final NotificationCompat.Builder progressNotificationBuilder
|
||||
= new NotificationCompat.Builder(mContext,
|
||||
mContext.getString(R.string.hash_channel_id))
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
||||
.setContentTitle(mContext.getString(R.string.msg_calculating_hash))
|
||||
.setContentText(mContext.getString(R.string.msg_wait))
|
||||
.setProgress(0, 0, true)
|
||||
.setOngoing(true);
|
||||
|
||||
notificationManager.notify(HASH_NOTIFICATION_ID, progressNotificationBuilder
|
||||
.build());
|
||||
final StoredFileHelper storage = h.item.mission.storage;
|
||||
compositeDisposable.add(
|
||||
Observable.fromCallable(() -> Utility.checksum(storage, ALGORITHMS.get(id)))
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> {
|
||||
if (finalProgressDialog != null) {
|
||||
Utility.copyToClipboard(finalProgressDialog.getContext(),
|
||||
result);
|
||||
if (mContext != null) {
|
||||
finalProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
Utility.copyToClipboard(mContext, result);
|
||||
notificationManager.cancel(HASH_NOTIFICATION_ID);
|
||||
})
|
||||
);
|
||||
return true;
|
||||
|
|
|
@ -195,6 +195,9 @@
|
|||
<string name="app_update_notification_channel_id" translatable="false">newpipeAppUpdate</string>
|
||||
<string name="app_update_notification_channel_name">App Update Notification</string>
|
||||
<string name="app_update_notification_channel_description">Notifications for new NewPipe version</string>
|
||||
<string name="hash_channel_id" translatable="false">newpipeHash</string>
|
||||
<string name="hash_channel_name">Video Hash Notification</string>
|
||||
<string name="hash_channel_description">Notifications for video hashing progress</string>
|
||||
<string name="unknown_content">[Unknown]</string>
|
||||
<string name="toggle_orientation">Toggle Orientation</string>
|
||||
<string name="switch_to_background">Switch to Background</string>
|
||||
|
@ -347,6 +350,7 @@
|
|||
<string name="msg_url_malform">Malformed URL or Internet not available</string>
|
||||
<string name="msg_running">NewPipe Downloading</string>
|
||||
<string name="msg_running_detail">Tap for details</string>
|
||||
<string name="msg_calculating_hash">Calculating hash</string>
|
||||
<string name="msg_wait">Please wait…</string>
|
||||
<string name="msg_copied">Copied to clipboard</string>
|
||||
<string name="no_available_dir">Please define a download folder later in settings</string>
|
||||
|
|
Loading…
Reference in a new issue