Skip to content

Commit

Permalink
Revert "Merge pull request #175 from learningequality/notifications"
Browse files Browse the repository at this point in the history
This reverts commit fac73e5, reversing
changes made to 5cac903.
  • Loading branch information
bjester committed Nov 28, 2023
1 parent fac73e5 commit f5e4222
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class PythonWorker extends RemoteListenableWorker {

public static PythonWorker mWorker = null;

public int notificationId;

public static ThreadLocal<Integer> threadNotificationId = new ThreadLocal<>();

private String notificationTitle;
Expand All @@ -48,7 +50,7 @@ public PythonWorker(

notificationTitle = context.getString(R.string.app_name);

threadNotificationId.set(ThreadLocalRandom.current().nextInt(1, 65537));
notificationId = ThreadLocalRandom.current().nextInt(1, 65537);

PythonWorker.mWorker = this;

Expand Down Expand Up @@ -84,8 +86,6 @@ public ListenableFuture<Result> startRemoteWork() {
runAsForeground();
}

int notificationId = getNotificationId();

// The python thread handling the work needs to be run in a
// separate thread so that future can be returned. Without
// it, any cancellation can't be processed.
Expand Down Expand Up @@ -138,7 +138,7 @@ public static native int nativeStart(
);

public ForegroundInfo getForegroundInfo() {
return new ForegroundInfo(getNotificationId(), Notifications.createNotification(notificationTitle, null, -1, -1));
return new ForegroundInfo(notificationId, Notifications.createNotification(notificationTitle, null, -1, -1));
}

public void runAsForeground() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.app.Notification;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
Expand Down Expand Up @@ -36,10 +34,8 @@ public static void showNotification(int notificationId, String notificationTitle
}

public static void hideNotification(int notificationId) {
new Handler(Looper.getMainLooper()).postDelayed(() -> {
Context context = ContextUtil.getApplicationContext();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(notificationId);
}, 5000); // Delay in milliseconds (5 seconds)
Context context = ContextUtil.getApplicationContext();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(notificationId);
}
}

0 comments on commit f5e4222

Please sign in to comment.