Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a notification instead of a ProgressDialog in MissionAdapter. #5142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ private void initNotificationChannels() {
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);
Expand All @@ -255,9 +256,17 @@ private void initNotificationChannels() {
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() {
Expand Down
37 changes: 20 additions & 17 deletions app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,6 +26,8 @@
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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -678,28 +681,28 @@ private boolean handlePopupItem(@NonNull ViewHolderItem h, @NonNull MenuItem opt
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;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down