| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- import UserPrivacyDialog from '../dialog/UserPrivacyDialog'
- import { common } from '@kit.AbilityKit'
- import data_preferences from '@ohos.data.preferences'
- import Logger from '../common/util/Logger'
- import { router, window } from '@kit.ArkUI'
- import { CommonConstants } from '../common/constants/CommonConstants'
- import { CSJUtil } from '../common/util/CSJUtil'
- import { ConfigManager } from '../common/util/ConfigManager'
- // import { AdSlotBuilder, CSJAdCreator, CSJAdSdk, CSJSplashAd,
- // CSJSplashAdCloseType,
- // CSJSplashAdInteractionListener,
- // CSJSplashAdLoadListener,
- // CSJSplashAdLoadParam,} from '@csj/openadsdk'
- import { UIUtil } from '../common/util/UIUtil'
- import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils'
- import { DemoConstants } from '../entryability/DemoConstants'
- import { AppUtil, Base64Util, FileUtil, LogUtil, StrUtil, ToastUtil } from '@pura/harmony-utils'
- import { Utility } from '../common/util/Utility'
- import { VideoItem } from '../viewmodel/VideoItem'
- import { LocalMusic } from '../view/LocalMusic'
- import { fileIo, fileUri, picker, ReadTextOptions } from '@kit.CoreFileKit'
- import { VipPage } from './VipPage'
- import { VipData } from '../viewmodel/VipData'
- //定义常量存储首选项中的键
- const H_STORE:string = 'wifiAppStore'
- const IS_PRIVACY:string = 'isPrivacy'
- //排序模式参数
- interface VideoNameParts {
- nonNumeric: string;
- numeric: number;
- }
- function extractParts(name: string): VideoNameParts {
- const match = name.match(/^(\D*)(\d*)/);
- return {
- nonNumeric: match?.[1] || '',
- numeric: parseInt(match?.[2] || '0', 10)
- };
- }
- @Builder
- function bottomViewBuilder() {
- Text('Bottom View')
- .backgroundColor(Color.Yellow)
- .width(UIUtil.getScreenWidthVp())
- .height(UIUtil.getScreenHeightVp() - adHeight)
- }
- @Builder
- function closeBtnBuilder(closeBlock: () => void) {
- Text('close')
- .textAlign(TextAlign.Center)
- .backgroundColor(Color.Yellow)
- .width(60)
- .height(60)
- .borderRadius(30)
- .margin({ top: 50, right: 40 })
- .onClick((event) => {
- closeBlock()
- })
- }
- let globalBuilder: WrappedBuilder<[]> = wrapBuilder(bottomViewBuilder)
- let globalCloseBtnBuilder: WrappedBuilder<[closeBlock: () => void]> = wrapBuilder(closeBtnBuilder)
- let screenWidth: number = UIUtil.getScreenWidthVp()
- let screenHeight: number = UIUtil.getScreenHeightVp()
- let adWidth: number = Math.round(screenWidth)
- let adHeight: number = Math.round(screenHeight)
- @Entry
- @Component
- struct SplashIndex{
- context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
- @Provide isToPri:boolean = false
- //穿山甲属性
- // private mAdCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
- // private splashAd: CSJSplashAd | undefined
- @State adLoadSuccess: Boolean = false
- @State errorMsg: string | undefined = undefined;
- @State startLoad: boolean = false;
- @State appName:string = ''
- // private mLoadListener: CSJSplashAdLoadListener = {
- // onAdLoaded: (splashAd: CSJSplashAd) => {
- // // ToastUtil.showToast("开屏回调 - 加载广告成功")
- // console.log("开屏回调 -加载广告成功 onAdLoaded")
- // this.splashAd = splashAd
- // this.adLoadSuccess = true
- // this.startLoad = false
- // this.showKP()
- // },
- //
- // onError: (code: number, message: string) => {
- // this.errorMsg = "onError\ncode: " + code + "\nmessage: " + message
- // console.log(`开屏回调 - onError code: ${code} message: ${message}`)
- //
- //
- // this.junpToMain()
- //
- //
- // },
- // onRenderSuccess: (splashAd: CSJSplashAd) => {
- // console.log("开屏回调 - onRenderSuccess")
- // },
- //
- // onRenderFail:(code: number, message: string) => {
- // console.log("开屏回调 - onRenderFail")
- // this.junpToMain()
- // }
- // }
- @State widthLabelText: string = "宽:" + adWidth
- @State heightLabelText: string = "高:" + adHeight
- private useCustomCloseBtn: boolean = false
- private mBiddingAdm = '' //服务端bidding才需要设置
- private loadTimeout: number = 5000
- private mWindow: window.Window | undefined = undefined
- dialogController:CustomDialogController = new CustomDialogController({
- builder:UserPrivacyDialog({
- cancel:()=>{this.exitApp()},
- confirm:()=>{this.onConfirm()}
- }
- )})
- @State rootPath:string = ''
- @State currentPath:string = ''
- @State videoLocalList: Array<VideoItem> = []
- @State fileList: Array<String> = []
- @State dirList: Array<VideoItem> = []
- @State expireDate:string = ''
- async mkDownLoadDir(){
- const documentViewPicker = new picker.DocumentViewPicker()
- let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
- let download_path = new fileUri.FileUri(documentSaveResult[0]).path
- this.rootPath = download_path
- let vPath = download_path + '/'+ LocalMusic.STR_LOCK_VIDEO+ '/' + VipPage.VIP_FILEPATH
- this.expireDate = this.readDataFromFile(vPath)
- Utility.setNoble(this.expireDate)
- this.doMain()
- }
- readDataFromFile(filePath:string){
- if(!FileUtil.accessSync(filePath)){
- return ''
- }
- let readTextOptions: ReadTextOptions = {
- offset: 0,
- length: 0,
- encoding: 'utf-8'
- };
- let stat = fileIo.statSync(filePath);
- readTextOptions.length = stat.size;
- let str = fileIo.readTextSync(filePath, readTextOptions);
- const parsedData: VipData = JSON.parse(str);
- // LogUtil.info('onecold parsedData.expireDate = ' + parsedData.expireDate)
- let result = Base64Util.decodeSync( parsedData.expireDate)
- // LogUtil.info('onecold 解密的result = ' +StrUtil.unit8ArrayToStr(result))
- return StrUtil.unit8ArrayToStr(result);
- }
- async doMain(){
- this.junpToMain()
- // if(!Utility.isNoble()&&Utility.isPassInstallTime(2)){
- // //判断用户安装app是否超过2天,超过2天才展示广告
- // CSJUtil.get().init()
- // CSJUtil.get().start()
- // setTimeout(()=>{
- // this.loadKPCSJ()
- // },200)
- // LogUtil.info('onecold 尊敬的赞助用户,欢迎您!' )
- // this.junpToMain()
- // }else{
- // LogUtil.info('onecold 尊敬的赞助用户,欢迎您!' )
- // this.junpToMain()
- // }
- }
- //点击同意后保存数据
- onConfirm(){
- this.dialogController.close()
- let preferences = data_preferences.getPreferences(this.context,H_STORE)
- //异步处理首选项的数据
- preferences.then((res)=>{
- res.put(IS_PRIVACY,true).then(()=>{
- res.flush()
- //记录日志
- Logger.debug('SplashIndex','isPricacy记录成功')
- }).catch((err:Error) =>{
- Logger.error('SplashIndex','isPricacy记录失败,原因:'+err)
- })
- })
- // this.junpToMainNow();
- // 初始化配置
- this.initCSJSDK()
- }
- //初始化SDK
- async initCSJSDK(){
- await this.initAppConfig();
- this.mkDownLoadDir()
- }
- /**
- * 初始化应用配置
- */
- private async initAppConfig(): Promise<void> {
- try {
- Logger.info('SplashIndex', '开始初始化应用配置...');
- const success = await ConfigManager.initConfig();
- if (success) {
- Logger.info('SplashIndex', '应用配置初始化成功');
- } else {
- Logger.error('SplashIndex', '应用配置初始化失败,使用默认配置');
- }
- } catch (error) {
- Logger.error('SplashIndex', '初始化应用配置异常:' + error);
- }
- }
- //退出App
- exitApp(){
- this.context.terminateSelf()
- }
- //判断是否弹出隐私政策对话框
- aboutToAppear(): void {
- Utility.getAppName(getContext(this)).then((appName:string)=>{
- this.appName = appName
- })
- let preferences = data_preferences.getPreferences(this.context,H_STORE)
- preferences.then((res) =>{
- res.get(IS_PRIVACY,false).then((isPrivacy) =>{
- if(isPrivacy == true){
- //说明用户已经点击过同意
- this.initCSJSDK()
- }else {
- //弹出弹窗
- this.dialogController.open()
- }
- })
- })
- }
- //加载开屏广告
- loadKPCSJ(){
- // this.errorMsg = undefined;
- // this.adLoadSuccess = false;
- // this.startLoad = true;
- // let adSlot = new AdSlotBuilder()
- // .setCodeId(CSJUtil.getWelcomeD())
- // .setAcceptSize(adWidth,
- // adHeight)
- // // .setBidAdm(this.mBiddingAdm)
- // .build()
- // let param = new CSJSplashAdLoadParam(adSlot, this.mLoadListener, this.getUIContext(),this.loadTimeout)
- // PrintBiddingTokenUtils.printBiddingToken(adSlot, this.mAdCreator);
- // this.mAdCreator.loadSplashAd(param)
- }
- showKP(){
- // if (this.splashAd != undefined) {
- // this.splashAd.setInteractionListener(this.mSplashAdInteractionListener)
- // // 方式一:直接showSplashAd
- // if (adHeight < screenHeight) {
- // this.splashAd?.showSplashAd(DemoConstants.windowStage, globalBuilder,
- // this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined)
- // } else {
- // this.splashAd?.showSplashAd(DemoConstants.windowStage, undefined,
- // this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined)
- // }
- // }
- }
- // CSJSplashAdInteractionListener
- // private mSplashAdInteractionListener: CSJSplashAdInteractionListener = {
- // onDidShow: () => {
- // console.log("开屏回调 - onDidShow")
- // },
- //
- // onDidClose: (closeType: CSJSplashAdCloseType) => {
- // console.log(`开屏回调 - onDidClose 关闭原因:${closeType}`)
- //
- // this.splashAd = undefined
- // setTimeout(()=>{
- // this.junpToMain()
- // },200)
- //
- //
- // // 方式二:需自行移除广告
- // // this.mWindow?.destroyWindow()
- //
- // },
- //
- // onDidClick: () => {
- // console.log("开屏回调 - onDidClick")
- //
- // },
- //
- // onVideoDidPlayFinish: () => {
- // console.log("开屏回调 - onVideoDidPlayFinish")
- // this.junpToMain()
- // },
- //
- // onVideoDidPlayFail: () => {
- // console.log("开屏回调 - onVideoDidPlayFail")
- // this.junpToMain()
- // }
- // }
- onPageShow(): void {
- if(this.isToPri){//判断是否跳转到隐私正常或者用户协议,如果是就弹出同意dialog
- this.aboutToAppear()
- this.isToPri = false
- }
- }
- onPageHide(): void {
- if (this.dialogController != null) {
- this.dialogController.close()
- }
- }
- pageTransition() {
- // 定义页面进入时的效果,从左侧滑入,时长为1200ms,无论页面栈发生push还是pop操作均可生效
- PageTransitionEnter({ type: RouteType.None, duration: 888 })
- .slide(SlideEffect.Left)
- // 定义页面退出时的效果,向左侧滑出,时长为1000ms,无论页面栈发生push还是pop操作均可生效
- PageTransitionExit({ type: RouteType.None, duration: 888 })
- .slide(SlideEffect.Left)
- }
- junpToMain(){
- router.pushUrl({
- url: 'pages/NewIndex',
- params: {
- videoList: this.videoLocalList
- }
- });
- }
- aboutToDisappear(): void {
- }
- build() {
- Column(){
- Column(){
- Image($r('app.media.icon'))
- .width(66)
- .height(66)
- .clip(true)
- .borderRadius('100%')
- .onClick(()=>{
- this.isToPri = true
- router.pushUrl({url:'pages/WebIndex',
- params:{ titleName:'ICP备案',webUrl:CommonConstants.ICP_URL}
- });
- })
- Text(this.appName)
- .fontColor(Color.Grey)
- .fontSize(18)
- .margin({top:20})
- Text(CommonConstants.ICP_NO)
- .fontColor(Color.Grey)
- .fontSize(9)
- .visibility(Visibility.None)
- .onClick(()=>{
- this.isToPri = true
- router.pushUrl({url:'pages/WebIndex',
- params:{ titleName:'ICP备案',webUrl:CommonConstants.ICP_URL}
- });
- })
- }
- .height(66)
- .width('100%')
- .margin({bottom:30})
- .justifyContent(FlexAlign.Center)
- // .backgroundColor(Color.White)
- }
- .justifyContent(FlexAlign.Center)
- .width('100%')
- .height('100%')
- // .backgroundImage($r('app.media.welcomeBg'))
- // .backgroundImageSize({height:'100%'})
- // .backgroundImagePosition(Alignment.Center)
- .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
- }
- }
|