- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: interstitials and rewarded ads (#18)
* fix: wrong event naming * fix: RN prefix * fix: add module suffix * fix: make android work * fix: module name * fix: missing rctconvert * Update android/src/main/java/io/invertase/googleads/common/RCTConvert.java Co-authored-by: Mike Hardy <github@mikehardy.net>
- v14.7.2
- v14.7.1
- v14.7.0
- v14.6.0
- v14.5.0
- v14.4.3
- v14.4.2
- v14.4.1
- v14.4.0
- v14.3.1
- v14.3.0
- v14.2.5
- v14.2.4
- v14.2.3
- v14.2.2
- v14.2.1
- v14.2.0
- v14.1.0
- v14.0.1
- v14.0.0
- v13.6.1
- v13.6.0
- v13.5.0
- v13.4.0
- v13.3.1
- v13.3.0
- v13.2.1
- v13.2.0
- v13.1.0
- v13.0.2
- v13.0.1
- v13.0.0
- v12.11.0
- v12.10.0
- v12.9.0
- v12.8.0
- v12.7.1
- v12.7.0
- v12.6.0
- v12.5.1
- v12.5.0
- v12.4.0
- v12.3.0
- v12.2.0
- v12.1.2
- v12.1.1
- v12.1.0
- v12.0.0
- v11.7.0
- v11.6.5
- v11.6.4
- v11.6.3
- v11.6.2
- v11.6.1
- v11.6.0
- v11.5.0
- v11.4.1
- v11.4.0
- v11.3.0
- v11.2.0
- v11.1.1
- v11.1.0
- v11.0.0
- v10.3.2
- v10.3.1
- v10.3.0
- v10.2.0
- v10.1.3
- v10.1.2
- v10.1.1
- v10.1.0
- v10.0.1
- v10.0.0
- v9.1.2
- v9.1.1
- v9.1.0
- v9.0.0
- v8.2.3
- v8.2.2
- v8.2.1
- v8.2.0
- v8.1.2
- v8.1.1
- v8.1.0
- v8.0.1
- v8.0.0
- v7.0.1
- v7.0.0
- v6.3.0
- v6.2.5
- v6.2.4
- v6.2.3
- v6.2.2
- v6.2.1
- v6.2.0
- v6.1.0
- v6.0.1
- v6.0.0
- v5.1.1
- v5.1.0
- v5.0.1
- v5.0.0
- v4.2.0
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.2
- v4.0.1
- v4.0.0
- v3.4.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.0
- v2.0.1
- v2.0.0
- v1.0.2
- v1.0.1
- v1.0.0
Showing
13 changed files
with
355 additions
and
23 deletions.
There are no files selected for viewing
173 changes: 173 additions & 0 deletions
173
android/src/main/java/io/invertase/googleads/ReactNativeAppModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package io.invertase.googleads; | ||
|
||
/* | ||
* Copyright (c) 2016-present Invertase Limited & Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this library except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.WritableMap; | ||
import io.invertase.googleads.common.ReactNativeApp; | ||
import io.invertase.googleads.common.RCTConvert; | ||
import io.invertase.googleads.common.ReactNativeEvent; | ||
import io.invertase.googleads.common.ReactNativeEventEmitter; | ||
import io.invertase.googleads.common.ReactNativeJSON; | ||
import io.invertase.googleads.common.ReactNativeMeta; | ||
import io.invertase.googleads.common.ReactNativePreferences; | ||
import io.invertase.googleads.common.ReactNativeModule; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ReactNativeAppModule extends ReactNativeModule { | ||
private static final String TAG = "RNAppModule"; | ||
|
||
ReactNativeAppModule(ReactApplicationContext reactContext) { | ||
super(reactContext, TAG); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
super.initialize(); | ||
ReactNativeEventEmitter.getSharedInstance().attachReactContext(getContext()); | ||
} | ||
|
||
@ReactMethod | ||
public void initializeApp(ReadableMap options, ReadableMap appConfig, Promise promise) { | ||
// ReactNativeApp reactNativeApp = | ||
// RCTConvertFirebase.readableMapToFirebaseApp(options, appConfig, getContext()); | ||
|
||
// WritableMap reactNativeAppMap = RCTConvertFirebase.reactNativeAppToWritableMap(reactNativeApp); | ||
// promise.resolve(reactNativeAppMap); | ||
promise.resolve(options); | ||
} | ||
|
||
@ReactMethod | ||
public void setAutomaticDataCollectionEnabled(String appName, Boolean enabled) { | ||
// ReactNativeApp reactNativeApp = ReactNativeApp.getInstance(appName); | ||
// reactNativeApp.setDataCollectionDefaultEnabled(enabled); | ||
} | ||
|
||
@ReactMethod | ||
public void deleteApp(String appName, Promise promise) { | ||
// ReactNativeApp reactNativeApp = ReactNativeApp.getInstance(appName); | ||
|
||
// if (reactNativeApp != null) { | ||
// reactNativeApp.delete(); | ||
// } | ||
|
||
promise.resolve(null); | ||
} | ||
|
||
@ReactMethod | ||
public void eventsNotifyReady(Boolean ready) { | ||
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance(); | ||
emitter.notifyJsReady(ready); | ||
} | ||
|
||
@ReactMethod | ||
public void eventsGetListeners(Promise promise) { | ||
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance(); | ||
promise.resolve(emitter.getListenersMap()); | ||
} | ||
|
||
@ReactMethod | ||
public void eventsPing(String eventName, ReadableMap eventBody, Promise promise) { | ||
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance(); | ||
emitter.sendEvent( | ||
new ReactNativeEvent( | ||
eventName, RCTConvert.readableMapToWritableMap(eventBody))); | ||
promise.resolve(RCTConvert.readableMapToWritableMap(eventBody)); | ||
} | ||
|
||
@ReactMethod | ||
public void eventsAddListener(String eventName) { | ||
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance(); | ||
emitter.addListener(eventName); | ||
} | ||
|
||
@ReactMethod | ||
public void eventsRemoveListener(String eventName, Boolean all) { | ||
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance(); | ||
emitter.removeListener(eventName, all); | ||
} | ||
|
||
@ReactMethod | ||
public void addListener(String eventName) { | ||
// Keep: Required for RN built in Event Emitter Calls. | ||
} | ||
|
||
@ReactMethod | ||
public void removeListeners(Integer count) { | ||
// Keep: Required for RN built in Event Emitter Calls. | ||
} | ||
|
||
/** ------------------ META ------------------ */ | ||
@ReactMethod | ||
public void metaGetAll(Promise promise) { | ||
promise.resolve(ReactNativeMeta.getSharedInstance().getAll()); | ||
} | ||
|
||
/** ------------------ JSON ------------------ */ | ||
@ReactMethod | ||
public void jsonGetAll(Promise promise) { | ||
promise.resolve(ReactNativeJSON.getSharedInstance().getAll()); | ||
} | ||
|
||
/** ------------------ PREFERENCES ------------------ */ | ||
@ReactMethod | ||
public void preferencesSetBool(String key, boolean value, Promise promise) { | ||
ReactNativePreferences.getSharedInstance().setBooleanValue(key, value); | ||
promise.resolve(null); | ||
} | ||
|
||
@ReactMethod | ||
public void preferencesSetString(String key, String value, Promise promise) { | ||
ReactNativePreferences.getSharedInstance().setStringValue(key, value); | ||
promise.resolve(null); | ||
} | ||
|
||
@ReactMethod | ||
public void preferencesGetAll(Promise promise) { | ||
promise.resolve(ReactNativePreferences.getSharedInstance().getAll()); | ||
} | ||
|
||
@ReactMethod | ||
public void preferencesClearAll(Promise promise) { | ||
ReactNativePreferences.getSharedInstance().clearAll(); | ||
promise.resolve(null); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getConstants() { | ||
Map<String, Object> constants = new HashMap<>(); | ||
// List<Map<String, Object>> appsList = new ArrayList<>(); | ||
// List<ReactNativeApp> reactNativeApps = ReactNativeApp.getApps(getReactApplicationContext()); | ||
|
||
// for (ReactNativeApp app : reactNativeApps) { | ||
// appsList.add(RCTConvertFirebase.reactNativeAppToMap(app)); | ||
// } | ||
|
||
// constants.put("NATIVE_FIREBASE_APPS", appsList); | ||
|
||
// constants.put("FIREBASE_RAW_JSON", ReactNativeJSON.getSharedInstance().getRawJSON()); | ||
|
||
return constants; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
android/src/main/java/io/invertase/googleads/common/RCTConvert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package io.invertase.googleads.common; | ||
|
||
/* | ||
* Copyright (c) 2016-present Invertase Limited & Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this library except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.WritableMap; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Utilities to convert to and from React Native bridge formats. | ||
*/ | ||
public class RCTConvert { | ||
private static String TAG = "RCTConvert"; | ||
|
||
/** | ||
* Takes a value and calls the appropriate setter for its type on the target map + key | ||
* | ||
* @param key String key to set on target map | ||
* @param value Object value to set on target map | ||
* @param map WritableMap target map to write the value to | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static WritableMap mapPutValue(String key, @Nullable Object value, WritableMap map) { | ||
if (value == null) { | ||
map.putNull(key); | ||
return map; | ||
} | ||
|
||
String type = value.getClass().getName(); | ||
|
||
switch (type) { | ||
case "java.lang.Boolean": | ||
map.putBoolean(key, (Boolean) value); | ||
break; | ||
case "java.lang.Long": | ||
Long longVal = (Long) value; | ||
map.putDouble(key, (double) longVal); | ||
break; | ||
case "java.lang.Float": | ||
float floatVal = (float) value; | ||
map.putDouble(key, (double) floatVal); | ||
break; | ||
case "java.lang.Double": | ||
map.putDouble(key, (Double) value); | ||
break; | ||
case "java.lang.Integer": | ||
map.putInt(key, (int) value); | ||
break; | ||
case "java.lang.String": | ||
map.putString(key, (String) value); | ||
break; | ||
case "org.json.JSONObject$1": | ||
map.putString(key, value.toString()); | ||
break; | ||
default: | ||
if (List.class.isAssignableFrom(value.getClass())) { | ||
map.putArray(key, Arguments.makeNativeArray((List<Object>) value)); | ||
} else if (Map.class.isAssignableFrom(value.getClass())) { | ||
WritableMap childMap = Arguments.createMap(); | ||
Map<String, Object> valueMap = (Map<String, Object>) value; | ||
|
||
for (Map.Entry<String, Object> entry : valueMap.entrySet()) { | ||
mapPutValue(entry.getKey(), entry.getValue(), childMap); | ||
} | ||
|
||
map.putMap(key, childMap); | ||
} else { | ||
Log.d(TAG, "utils:mapPutValue:unknownType:" + type); | ||
map.putNull(key); | ||
} | ||
} | ||
|
||
return map; | ||
} | ||
|
||
// TODO Remove me - also in SharedUtils | ||
public static WritableMap readableMapToWritableMap(ReadableMap map) { | ||
WritableMap writableMap = Arguments.createMap(); | ||
// https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/WritableNativeMap.java#L58 | ||
writableMap.merge(map); | ||
return writableMap; | ||
} | ||
|
||
public static Map<String, Object> toHashMap(ReadableMap readableMap) { | ||
// https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeMap.java#L263 | ||
return readableMap.toHashMap(); | ||
} | ||
|
||
public static List<Object> toArrayList(ReadableArray readableArray) { | ||
// https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.java#L140 | ||
return readableArray.toArrayList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters