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 = [] @State fileList: Array = [] @State dirList: Array = [] @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 { 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]) } }