Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

feat: add increase and decrease methods #20

Merged
merged 4 commits into from
Jul 27, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip: android
robingenz committed Jul 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 72b6926e1fada57bdbd38ffe443bdf1123839a74
13 changes: 13 additions & 0 deletions android/src/main/java/dev/robingenz/capacitor/badge/Badge.java
Original file line number Diff line number Diff line change
@@ -31,6 +31,19 @@ public void set(int count) {
ShortcutBadger.applyCount(context, count);
}

public void increase() {
int count = get();
set(count + 1);
}

public void decrease() {
int count = get();
if (count < 1) {
return;
}
set(count - 1);
}

public void clear() {
set(0);
}
Original file line number Diff line number Diff line change
@@ -40,6 +40,26 @@ public void set(PluginCall call) {
}
}

@PluginMethod
public void increase(PluginCall call) {
try {
implementation.increase();
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}

@PluginMethod
public void decrease(PluginCall call) {
try {
implementation.decrease();
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}

@PluginMethod
public void clear(PluginCall call) {
try {