mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 09:27:16 +01:00
73 lines
2.9 KiB
Java
73 lines
2.9 KiB
Java
package com.reactnativecommunity.netinfo;
|
|
|
|
import com.facebook.react.bridge.Promise;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
import com.facebook.react.bridge.ReactMethod;
|
|
import com.facebook.react.module.annotations.ReactModule;
|
|
import com.reactnativecommunity.netinfo.AmazonFireDeviceConnectivityPoller;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@ReactModule(name = NetInfoModule.NAME)
|
|
/* loaded from: classes9.dex */
|
|
public class NetInfoModule extends ReactContextBaseJavaModule implements AmazonFireDeviceConnectivityPoller.ConnectivityChangedCallback {
|
|
public static final String NAME = "RNCNetInfo";
|
|
private final AmazonFireDeviceConnectivityPoller mAmazonConnectivityChecker;
|
|
private final ConnectivityReceiver mConnectivityReceiver;
|
|
private int numberOfListeners;
|
|
|
|
public NetInfoModule(ReactApplicationContext reactApplicationContext) {
|
|
super(reactApplicationContext);
|
|
this.numberOfListeners = 0;
|
|
this.mConnectivityReceiver = new NetworkCallbackConnectivityReceiver(reactApplicationContext);
|
|
this.mAmazonConnectivityChecker = new AmazonFireDeviceConnectivityPoller(reactApplicationContext, this);
|
|
}
|
|
|
|
@ReactMethod
|
|
public void addListener(String str) {
|
|
this.numberOfListeners++;
|
|
this.mConnectivityReceiver.hasListener = true;
|
|
}
|
|
|
|
@ReactMethod
|
|
public void getCurrentState(String str, Promise promise) {
|
|
this.mConnectivityReceiver.getCurrentState(str, promise);
|
|
}
|
|
|
|
@Override // com.facebook.react.bridge.NativeModule
|
|
public String getName() {
|
|
return NAME;
|
|
}
|
|
|
|
@Override // com.facebook.react.bridge.BaseJavaModule, com.facebook.react.bridge.NativeModule
|
|
public void initialize() {
|
|
this.mConnectivityReceiver.register();
|
|
this.mAmazonConnectivityChecker.register();
|
|
}
|
|
|
|
@Override // com.facebook.react.bridge.BaseJavaModule, com.facebook.react.bridge.NativeModule, com.facebook.react.turbomodule.core.interfaces.TurboModule
|
|
public void invalidate() {
|
|
this.mAmazonConnectivityChecker.unregister();
|
|
this.mConnectivityReceiver.unregister();
|
|
this.mConnectivityReceiver.hasListener = false;
|
|
}
|
|
|
|
@Override // com.reactnativecommunity.netinfo.AmazonFireDeviceConnectivityPoller.ConnectivityChangedCallback
|
|
public void onAmazonFireDeviceConnectivityChanged(boolean z) {
|
|
this.mConnectivityReceiver.setIsInternetReachableOverride(z);
|
|
}
|
|
|
|
@Override // com.facebook.react.bridge.NativeModule
|
|
public void onCatalystInstanceDestroy() {
|
|
invalidate();
|
|
}
|
|
|
|
@ReactMethod
|
|
public void removeListeners(Integer num) {
|
|
int intValue = this.numberOfListeners - num.intValue();
|
|
this.numberOfListeners = intValue;
|
|
if (intValue == 0) {
|
|
this.mConnectivityReceiver.hasListener = false;
|
|
}
|
|
}
|
|
}
|