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

Commit

Permalink
chore: dep updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker committed Jul 18, 2020
1 parent d9cf845 commit 0708ab9
Show file tree
Hide file tree
Showing 44 changed files with 152 additions and 178 deletions.
26 changes: 12 additions & 14 deletions src/admob/admob.android.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { firebase } from "../firebase-common";
import { BannerOptions, InterstitialOptions, PreloadRewardedVideoAdOptions, ShowRewardedVideoAdOptions } from "./admob";
import { AD_SIZE, BANNER_DEFAULTS, rewardedVideoCallbacks } from "./admob-common";
import * as appModule from "tns-core-modules/application";
import { topmost } from "tns-core-modules/ui/frame";
import { layout } from "tns-core-modules/utils/utils";
import { Application, Frame, Utils } from "@nativescript/core";

declare const com: any;

Expand All @@ -22,7 +20,7 @@ export function showBanner(arg: BannerOptions): Promise<any> {
}
}

firebase.admob.adView = new com.google.android.gms.ads.AdView(appModule.android.foregroundActivity);
firebase.admob.adView = new com.google.android.gms.ads.AdView(Application.android.foregroundActivity);
firebase.admob.adView.setAdUnitId(settings.androidBannerId);
const bannerType = _getBannerType(settings.size);
firebase.admob.adView.setAdSize(bannerType);
Expand Down Expand Up @@ -53,7 +51,7 @@ export function showBanner(arg: BannerOptions): Promise<any> {
const ad = _buildAdRequest(settings);
firebase.admob.adView.loadAd(ad);

const density = layout.getDisplayDensity(),
const density = Utils.layout.getDisplayDensity(),
top = settings.margins.top * density,
bottom = settings.margins.bottom * density;

Expand All @@ -71,21 +69,21 @@ export function showBanner(arg: BannerOptions): Promise<any> {
relativeLayoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_TOP);
}

const adViewLayout = new android.widget.RelativeLayout(appModule.android.foregroundActivity);
const adViewLayout = new android.widget.RelativeLayout(Application.android.foregroundActivity);
adViewLayout.addView(firebase.admob.adView, relativeLayoutParams);

const relativeLayoutParamsOuter = new android.widget.RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT);

// Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.topmost()' doesn't resolve to 'undefined'.
// Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.Frame.topmost()' doesn't resolve to 'undefined'.
// Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case.
setTimeout(() => {
const top = topmost();
const top = Frame.topmost();
if (top !== undefined && top.currentPage && top.currentPage.android && top.currentPage.android.getParent()) {
top.currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
} else if (appModule.android && appModule.android.foregroundActivity) {
appModule.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
} else if (Application.android && Application.android.foregroundActivity) {
Application.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
} else {
console.log("Could not find a view to add the banner to");
}
Expand All @@ -101,7 +99,7 @@ export function preloadInterstitial(arg: InterstitialOptions): Promise<any> {
return new Promise((resolve, reject) => {
try {
const settings = firebase.merge(arg, BANNER_DEFAULTS);
const activity = appModule.android.foregroundActivity || appModule.android.startActivity;
const activity = Application.android.foregroundActivity || Application.android.startActivity;
firebase.admob.interstitialView = new com.google.android.gms.ads.InterstitialAd(activity);
firebase.admob.interstitialView.setAdUnitId(settings.androidInterstitialId);

Expand Down Expand Up @@ -152,7 +150,7 @@ export function showInterstitial(arg?: InterstitialOptions): Promise<any> {
}

const settings = firebase.merge(arg, BANNER_DEFAULTS);
const activity = appModule.android.foregroundActivity || appModule.android.startActivity;
const activity = Application.android.foregroundActivity || Application.android.startActivity;
firebase.admob.interstitialView = new com.google.android.gms.ads.InterstitialAd(activity);
firebase.admob.interstitialView.setAdUnitId(settings.androidInterstitialId);

Expand Down Expand Up @@ -192,7 +190,7 @@ export function preloadRewardedVideoAd(arg: PreloadRewardedVideoAdOptions): Prom
return new Promise((resolve, reject) => {
try {
const settings = firebase.merge(arg, BANNER_DEFAULTS);
const activity = appModule.android.foregroundActivity || appModule.android.startActivity;
const activity = Application.android.foregroundActivity || Application.android.startActivity;
firebase.admob.rewardedAdVideoView = com.google.android.gms.ads.MobileAds.getRewardedVideoAdInstance(activity);

rewardedVideoCallbacks.onLoaded = resolve;
Expand Down Expand Up @@ -326,7 +324,7 @@ function _buildAdRequest(settings): any {
if (settings.testing) {
builder.addTestDevice(com.google.android.gms.ads.AdRequest.DEVICE_ID_EMULATOR);
// This will request test ads on the emulator and device by passing this hashed device ID.
const activity = appModule.android.foregroundActivity || appModule.android.startActivity;
const activity = Application.android.foregroundActivity || Application.android.startActivity;
const ANDROID_ID = android.provider.Settings.Secure.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
let deviceId = _md5(ANDROID_ID);
if (deviceId !== null) {
Expand Down
5 changes: 2 additions & 3 deletions src/admob/admob.ios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { device } from "tns-core-modules/platform/platform";
import { DeviceType } from "tns-core-modules/ui/enums/enums";
import { Device, Enums } from "@nativescript/core";
import { firebase } from "../firebase-common";
import { BannerOptions, InterstitialOptions, PreloadRewardedVideoAdOptions, ShowRewardedVideoAdOptions } from "./admob";
import { AD_SIZE, BANNER_DEFAULTS, rewardedVideoCallbacks } from "./admob-common";
Expand Down Expand Up @@ -330,7 +329,7 @@ function _getBannerType(size): any {
return {"size": {"width": 120, "height": 600}, "flags": 0};
} else if (size === AD_SIZE.SMART_BANNER || size === AD_SIZE.FLUID) {
const orientation = UIDevice.currentDevice.orientation;
const isIPad = device.deviceType === DeviceType.Tablet;
const isIPad = Device.deviceType === Enums.DeviceType.Tablet;
if (orientation === UIDeviceOrientation.Portrait || orientation === UIDeviceOrientation.PortraitUpsideDown) {
// return kGADAdSizeSmartBannerPortrait;
return {"size": {"width": 0, "height": 0, "smartHeight": isIPad ? 90 : 50}, "flags": 18};
Expand Down
18 changes: 9 additions & 9 deletions src/analytics/analytics.android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as appModule from "tns-core-modules/application";
import { Application } from "@nativescript/core";
import { LogComplexEventOptions, LogComplexEventParameter, LogEventOptions, SetScreenNameOptions, SetUserPropertyOptions } from "./analytics";
import { ENABLE_ANALYTICS_HINT, validateAnalyticsKey, validateAnalyticsParam } from "./analytics-common";

Expand Down Expand Up @@ -35,7 +35,7 @@ export function logEvent(options: LogEventOptions): Promise<void> {
}

com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()
Application.android.context || Application.getNativeApplication()
).logEvent(options.key, bundle);

resolve();
Expand Down Expand Up @@ -65,7 +65,7 @@ export function logComplexEvent(options: LogComplexEventOptions): Promise<void>
}

com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()
Application.android.context || Application.getNativeApplication()
).logEvent(options.key, bundle);

resolve();
Expand All @@ -90,7 +90,7 @@ export function setUserId(arg): Promise<void> {
}

com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()).setUserId(arg.userId);
Application.android.context || Application.getNativeApplication()).setUserId(arg.userId);

resolve();
} catch (ex) {
Expand Down Expand Up @@ -118,7 +118,7 @@ export function setUserProperty(options: SetUserPropertyOptions): Promise<void>
}

com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()
Application.android.context || Application.getNativeApplication()
).setUserProperty(options.key, options.value);

resolve();
Expand All @@ -143,8 +143,8 @@ export function setScreenName(options: SetScreenNameOptions): Promise<void> {
}

com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()
).setCurrentScreen(appModule.android.foregroundActivity, options.screenName, null);
Application.android.context || Application.getNativeApplication()
).setCurrentScreen(Application.android.foregroundActivity, options.screenName, null);

resolve();
} catch (ex) {
Expand All @@ -157,15 +157,15 @@ export function setScreenName(options: SetScreenNameOptions): Promise<void> {
export function setAnalyticsCollectionEnabled(enabled: boolean): void {
if (isAnalyticsAvailable()) {
com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()
Application.android.context || Application.getNativeApplication()
).setAnalyticsCollectionEnabled(enabled);
}
}

export function setSessionTimeoutDuration(seconds: number): void {
if (isAnalyticsAvailable()) {
com.google.firebase.analytics.FirebaseAnalytics.getInstance(
appModule.android.context || appModule.getNativeApplication()
Application.android.context || Application.getNativeApplication()
).setSessionTimeoutDuration(seconds * 1000); // Android expects ms
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from "tns-core-modules/file-system"
import { File } from "@nativescript/core";
import * as firebaseStorage from "../../storage/storage";
import { ListResult, UploadFileResult, UploadMetadata } from "../../storage/storage";

Expand Down
4 changes: 2 additions & 2 deletions src/crashlytics/crashlytics.android.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENABLE_CRASHLYTICS_HINT } from "./crashlytics-common";
import * as appModule from 'tns-core-modules/application';
import { Application } from '@nativescript/core';

declare const com: any;

Expand Down Expand Up @@ -64,7 +64,7 @@ export function crash(): void {
export function setCrashlyticsCollectionEnabled(enabled: boolean): void {
if (isCrashlyticsAvailable()) {
io.fabric.sdk.android.Fabric.with(
appModule.getNativeApplication(),
Application.getNativeApplication(),
[new com.crashlytics.android.Crashlytics()]);
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/firebase-common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { prompt } from "tns-core-modules/ui/dialogs";
import { getString, setString } from "tns-core-modules/application-settings";
import { prompt, ApplicationSettings } from "@nativescript/core";
import { firestore } from "./firebase";
import * as admob from "./admob/admob";
import * as analytics from "./analytics/analytics";
Expand Down Expand Up @@ -119,10 +118,10 @@ export const firebase: any = {
});
},
rememberEmailForEmailLinkLogin: (email: string) => {
setString("FirebasePlugin.EmailLinkLogin", email);
ApplicationSettings.setString("FirebasePlugin.EmailLinkLogin", email);
},
getRememberedEmailForEmailLinkLogin: () => {
return getString("FirebasePlugin.EmailLinkLogin");
return ApplicationSettings.getString("FirebasePlugin.EmailLinkLogin");
},
strongTypeify: value => {
if (value === "true") {
Expand Down
Loading

0 comments on commit 0708ab9

Please sign in to comment.