LaunchPage.ets
3.41 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import media from '@ohos.multimedia.media'
import App from '@system.app'
import Router from '@system.router'
import router from '@ohos.router'
import common from '@ohos.app.ability.common'
import CustomDialogComponent from '../view/CustomDialogComponent'
import preferences from '@ohos.data.preferences'
import { GlobalContext } from '../common/utils/GlobalContext'
@Entry
@Component
struct LaunchPage {
private context?: common.UIAbilityContext;
private timerId: number = 0;
private isJumpToAdvertising: boolean = false;
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogComponent(
{
cancel: () => {
this.onCancel();
},
confirm: () => {
this.onConfirm();
}
}),
alignment: DialogAlignment.Center,
offset: { dx: 0, dy: '-24' },
customStyle: true,
autoCancel: false
});
onCancel() {
// Exit the application.
this.context?.terminateSelf();
}
onConfirm() {
// Save privacy agreement status.
this.saveIsPrivacy();
this.jumpToAdvertisingPage();
}
jumpToAdvertisingPage() {
this.timerId = setTimeout(() => {
this.isJumpToAdvertising = true;
router.pushUrl({
url: 'pages/LaunchAdvertisingPage'
}).catch((error: Error) => {
//Logger.error(CommonConstants.LAUNCHER_PAGE_TAG, 'LauncherPage pushUrl error ' + JSON.stringify(error));
});
}, 1000);
}
onPageShow() {
this.context = getContext(this) as common.UIAbilityContext;
// Get the operation class for saving data.
this.getDataPreferences(this).then((preferences: preferences.Preferences) => {
preferences.get('isPrivacy', true).then((value: preferences.ValueType) => {
//Logger.info(CommonConstants.LAUNCHER_PAGE_TAG, 'onPageShow value: ' + value);
if (value) {
// let isJumpPrivacy: boolean = globalThis.isJumpPrivacy ?? false;
// let isJumpPrivacy: boolean = (GlobalContext.getContext().getObject('isJumpPrivacy') as boolean) ?? false;
// if (!isJumpPrivacy) {
this.dialogController.open();
// }
} else {
this.jumpToAdvertisingPage();
}
});
});
}
onPageHide() {
if (this.isJumpToAdvertising) {
router.clear();
}
// globalThis.isJumpPrivacy = true;
//GlobalContext.getContext().setObject('isJumpPrivacy', true);
clearTimeout(this.timerId);
}
getDataPreferences(common: Object) {
return preferences.getPreferences(getContext(common), 'myStore');
}
saveIsPrivacy() {
let preferences: Promise<preferences.Preferences> = this.getDataPreferences(this);
preferences.then((result: preferences.Preferences) => {
let privacyPut = result.put('isPrivacy', false);
result.flush();
privacyPut.then(() => {
//Logger.info('LauncherPage', 'Put the value of startup Successfully.');
}).catch((err: Error) => {
//Logger.error('LauncherPage', 'Put the value of startup Failed, err: ' + err);
});
}).catch((err: Error) => {
//Logger.error('LauncherPage', 'Get the preferences Failed, err: ' + err);
});
}
build(){
Stack({alignContent:Alignment.Bottom}){
Image($r('app.media.LaunchPage_logo'))
.width('278lpx')
.height('154lpx')
.margin({
bottom:'48lpx'
})
}
.width('100%')
.height('100%')
.backgroundColor(Color.White)
}
}