Skip to content

Commit

Permalink
fix: fallback tag to id on ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
jd1378 committed May 12, 2024
1 parent 5491edf commit 0b235f9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<action android:name="io.github.jd1378.otphelper.actions.code_copy" />
<action android:name="io.github.jd1378.otphelper.actions.ignore_notif_app" />
<action android:name="io.github.jd1378.otphelper.actions.ignore_notif_tag" />
<action android:name="io.github.jd1378.otphelper.actions.ignore_notif_nid" />
</intent-filter>
</receiver>
<receiver
Expand Down
44 changes: 28 additions & 16 deletions app/src/main/java/io/github/jd1378/otphelper/NotifActionReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class NotifActionReceiver : BroadcastReceiver() {
const val INTENT_ACTION_CODE_COPY = "io.github.jd1378.otphelper.actions.code_copy"
const val INTENT_ACTION_IGNORE_TAG_NOTIFICATION_TAG =
"io.github.jd1378.otphelper.actions.ignore_notif_tag"
const val INTENT_ACTION_IGNORE_TAG_NOTIFICATION_NID =
"io.github.jd1378.otphelper.actions.ignore_notif_nid"
const val INTENT_ACTION_IGNORE_NOTIFICATION_APP =
"io.github.jd1378.otphelper.actions.ignore_notif_app"

Expand Down Expand Up @@ -53,33 +55,43 @@ class NotifActionReceiver : BroadcastReceiver() {

val notif = getActiveNotification(context, R.id.code_detected_notify_id)
if (notif != null) {
if (intent.action == INTENT_ACTION_IGNORE_TAG_NOTIFICATION_TAG) {
when (intent.action) {
INTENT_ACTION_IGNORE_TAG_NOTIFICATION_TAG,
INTENT_ACTION_IGNORE_TAG_NOTIFICATION_NID -> {

val ignoreWord = notif.extras.getString(CodeDetectedReceiver.INTENT_EXTRA_IGNORE_TAG)
val ignoreWord =
if (intent.action == INTENT_ACTION_IGNORE_TAG_NOTIFICATION_TAG) {
notif.extras.getString(CodeDetectedReceiver.INTENT_EXTRA_IGNORE_TAG)
} else {
notif.extras.getString(CodeDetectedReceiver.INTENT_EXTRA_IGNORE_NID)
}

if (ignoreWord != null) {
if (ignoreWord != null) {

@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch { ignoredNotifSetRepository.addIgnoredNotif(ignoreWord) }
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch { ignoredNotifSetRepository.addIgnoredNotif(ignoreWord) }

NotificationManagerCompat.from(context).cancel(R.id.code_detected_notify_id)
NotificationManagerCompat.from(context).cancel(R.id.code_detected_notify_id)

Toast.makeText(context, R.string.wont_detect_code_from_this_notif, Toast.LENGTH_LONG)
.show()
Toast.makeText(context, R.string.wont_detect_code_from_this_notif, Toast.LENGTH_LONG)
.show()
}
}
} else if (intent.action == INTENT_ACTION_IGNORE_NOTIFICATION_APP) {
INTENT_ACTION_IGNORE_NOTIFICATION_APP -> {
val ignoreWord = notif.extras.getString(CodeDetectedReceiver.INTENT_EXTRA_IGNORE_APP)

val ignoreWord = notif.extras.getString(CodeDetectedReceiver.INTENT_EXTRA_IGNORE_APP)
if (ignoreWord != null) {

if (ignoreWord != null) {
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch { ignoredNotifSetRepository.addIgnoredNotif(ignoreWord) }

@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch { ignoredNotifSetRepository.addIgnoredNotif(ignoreWord) }
NotificationManagerCompat.from(context).cancel(R.id.code_detected_notify_id)

NotificationManagerCompat.from(context).cancel(R.id.code_detected_notify_id)

Toast.makeText(context, R.string.wont_detect_code_from_this_app, Toast.LENGTH_LONG).show()
Toast.makeText(context, R.string.wont_detect_code_from_this_app, Toast.LENGTH_LONG)
.show()
}
}
else -> {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ class NotificationHelper {
R.drawable.baseline_visibility_off_24,
context.getString(R.string.ignore_tag),
ignoreTagPendingIntent)
} else if (extras.getString(CodeDetectedReceiver.INTENT_EXTRA_IGNORE_NID) != null) {
val ignoreNidPendingIntent =
PendingIntentCompat.getBroadcast(
context,
0,
Intent(NotifActionReceiver.INTENT_ACTION_IGNORE_TAG_NOTIFICATION_NID).apply {
setPackage(context.packageName)
putExtra("cancel_notif_id", R.id.code_detected_notify_id)
},
0,
false,
)

notificationBuilder.addAction(
R.drawable.baseline_visibility_off_24,
context.getString(R.string.ignore_tag),
ignoreNidPendingIntent)
}

NotificationManagerCompat.from(context)
Expand Down

0 comments on commit 0b235f9

Please sign in to comment.