From 05b3f57a767d712ed6a533b1d64a0959584cc192 Mon Sep 17 00:00:00 2001
From: rebelonion <87634197+rebelonion@users.noreply.github.com>
Date: Wed, 17 Jan 2024 00:08:32 -0600
Subject: [PATCH] incognito notification onClick
---
app/src/main/AndroidManifest.xml | 2 ++
app/src/main/java/ani/dantotsu/App.kt | 1 -
app/src/main/java/ani/dantotsu/Functions.kt | 15 +++++++++++---
.../media/anime/SelectorDialogFragment.kt | 1 -
.../subcriptions/NotificationClickReceiver.kt | 20 +++++++++++++++++++
5 files changed, 34 insertions(+), 5 deletions(-)
create mode 100644 app/src/main/java/ani/dantotsu/subcriptions/NotificationClickReceiver.kt
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b72b3304..39c04cbe 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -68,6 +68,8 @@
android:name="android.appwidget.provider"
android:resource="@xml/currently_airing_widget_info" />
+
+
false
}
}
+
+const val INCOGNITO_CHANNEL_ID = 26
+@SuppressLint("LaunchActivityFromNotification")
fun incognitoNotification(context: Context){
- val CHANNEL_ID = 26
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val incognito = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("incognito", false)
if (incognito) {
+ val intent = Intent(context, NotificationClickReceiver::class.java)
+ val pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
+ PendingIntent.FLAG_IMMUTABLE)
val builder = NotificationCompat.Builder(context, Notifications.CHANNEL_INCOGNITO_MODE)
.setSmallIcon(R.drawable.ic_incognito_24)
.setContentTitle("Incognito Mode")
.setContentText("Disable Incognito Mode")
.setPriority(NotificationCompat.PRIORITY_HIGH)
+ .setContentIntent(pendingIntent)
.setOngoing(true)
- notificationManager.notify(CHANNEL_ID, builder.build())
+ notificationManager.notify(INCOGNITO_CHANNEL_ID, builder.build())
} else {
- notificationManager.cancel(CHANNEL_ID)
+ notificationManager.cancel(INCOGNITO_CHANNEL_ID)
}
}
diff --git a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt
index feec1d7d..0c3d244a 100644
--- a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt
+++ b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt
@@ -32,7 +32,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.text.DecimalFormat
-import java.util.concurrent.CountDownLatch
class SelectorDialogFragment : BottomSheetDialogFragment() {
diff --git a/app/src/main/java/ani/dantotsu/subcriptions/NotificationClickReceiver.kt b/app/src/main/java/ani/dantotsu/subcriptions/NotificationClickReceiver.kt
new file mode 100644
index 00000000..98b496af
--- /dev/null
+++ b/app/src/main/java/ani/dantotsu/subcriptions/NotificationClickReceiver.kt
@@ -0,0 +1,20 @@
+package ani.dantotsu.subcriptions
+
+import android.app.NotificationManager
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import ani.dantotsu.INCOGNITO_CHANNEL_ID
+
+
+class NotificationClickReceiver : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent?) {
+
+ context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
+ .putBoolean("incognito", false)
+ .apply()
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ notificationManager.cancel(INCOGNITO_CHANNEL_ID)
+
+ }
+}
\ No newline at end of file