forked from NativeScript/firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.ts
94 lines (90 loc) · 2.46 KB
/
index.android.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { firebase, FirebaseApp, FirebaseError } from '@nativescript/firebase-core';
import { IInstallations } from './common';
let defaultInstallations: Installations;
const fb = firebase();
Object.defineProperty(fb, 'installations', {
value: (app?: FirebaseApp) => {
if (!app) {
if (!defaultInstallations) {
defaultInstallations = new Installations();
}
return defaultInstallations;
}
return new Installations(app);
},
writable: false,
});
export class Installations implements IInstallations {
_native: com.google.firebase.installations.FirebaseInstallations;
_app: FirebaseApp;
constructor(app?: FirebaseApp) {
if (app?.native) {
this._native = com.google.firebase.installations.FirebaseInstallations.getInstance(app.native);
} else {
if (defaultInstallations) {
return defaultInstallations;
}
defaultInstallations = this;
this._native = com.google.firebase.installations.FirebaseInstallations.getInstance();
}
}
delete(): Promise<void> {
return new Promise((resolve, reject) => {
org.nativescript.firebase.installations.FirebaseInstallations.delete(
this.native,
new org.nativescript.firebase.installations.FirebaseInstallations.Callback<java.lang.Void>({
onSuccess(param0) {
resolve();
},
onError(error) {
reject(FirebaseError.fromNative(error));
},
})
);
});
}
getId(): Promise<string> {
return new Promise((resolve, reject) => {
org.nativescript.firebase.installations.FirebaseInstallations.id(
this.native,
new org.nativescript.firebase.installations.FirebaseInstallations.Callback<string>({
onSuccess(param0) {
resolve(param0);
},
onError(error) {
reject(FirebaseError.fromNative(error));
},
})
);
});
}
getToken(forceRefresh = false): Promise<string> {
return new Promise((resolve, reject) => {
org.nativescript.firebase.installations.FirebaseInstallations.getToken(
this.native,
forceRefresh,
new org.nativescript.firebase.installations.FirebaseInstallations.Callback<com.google.firebase.installations.InstallationTokenResult>({
onSuccess(param0) {
resolve(param0.getToken());
},
onError(error) {
reject(FirebaseError.fromNative(error));
},
})
);
});
}
get native() {
return this._native;
}
get android() {
return this.native;
}
get app(): FirebaseApp {
if (!this._app) {
// @ts-ignore
this._app = FirebaseApp.fromNative(this.native.app);
}
return this._app;
}
}