Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def MIN_IAP_SDK_VERSION = '1.6.6'

android {
compileSdkVersion 33

namespace "sqip.react"
defaultConfig {
minSdkVersion 24
targetSdkVersion 33
Expand Down
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sqip.react">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>

27 changes: 26 additions & 1 deletion android/src/main/java/sqip/react/SquareInAppPaymentsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import sqip.InAppPaymentsSdk;

import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.util.HashMap;
import java.util.Map;
class SquareInAppPaymentsModule extends ReactContextBaseJavaModule {

private final Handler mainLooperHandler;
private final Map<String, Integer> listeners;

public SquareInAppPaymentsModule(ReactApplicationContext reactContext) {
super(reactContext);
mainLooperHandler = new Handler(Looper.getMainLooper());
this.listeners = new HashMap<>();

}

@Override
Expand All @@ -47,4 +52,24 @@ public void run() {
}
});
}

@ReactMethod
public void addListener(String eventName) {
if (!listeners.containsKey(eventName)) {
listeners.put(eventName, 1);
} else {
listeners.put(eventName, listeners.get(eventName) + 1);
} }

@ReactMethod
public void removeListeners(Integer count) {
for (Map.Entry<String, Integer> entry : listeners.entrySet()) {
int currentCount = entry.getValue();
if (currentCount <= count) {
listeners.remove(entry.getKey());
} else {
listeners.put(entry.getKey(), currentCount - count);
}
} }
}