SplashIndex.ets 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. import UserPrivacyDialog from '../dialog/UserPrivacyDialog'
  2. import { common } from '@kit.AbilityKit'
  3. import data_preferences from '@ohos.data.preferences'
  4. import Logger from '../common/util/Logger'
  5. import { router, window } from '@kit.ArkUI'
  6. import { CommonConstants } from '../common/constants/CommonConstants'
  7. import { CSJUtil } from '../common/util/CSJUtil'
  8. import { ConfigManager } from '../common/util/ConfigManager'
  9. // import { AdSlotBuilder, CSJAdCreator, CSJAdSdk, CSJSplashAd,
  10. // CSJSplashAdCloseType,
  11. // CSJSplashAdInteractionListener,
  12. // CSJSplashAdLoadListener,
  13. // CSJSplashAdLoadParam,} from '@csj/openadsdk'
  14. import { UIUtil } from '../common/util/UIUtil'
  15. import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils'
  16. import { DemoConstants } from '../entryability/DemoConstants'
  17. import { AppUtil, Base64Util, FileUtil, LogUtil, StrUtil, ToastUtil } from '@pura/harmony-utils'
  18. import { Utility } from '../common/util/Utility'
  19. import { VideoItem } from '../viewmodel/VideoItem'
  20. import { LocalMusic } from '../view/LocalMusic'
  21. import { fileIo, fileUri, picker, ReadTextOptions } from '@kit.CoreFileKit'
  22. import { VipPage } from './VipPage'
  23. import { VipData } from '../viewmodel/VipData'
  24. //定义常量存储首选项中的键
  25. const H_STORE:string = 'wifiAppStore'
  26. const IS_PRIVACY:string = 'isPrivacy'
  27. //排序模式参数
  28. interface VideoNameParts {
  29. nonNumeric: string;
  30. numeric: number;
  31. }
  32. function extractParts(name: string): VideoNameParts {
  33. const match = name.match(/^(\D*)(\d*)/);
  34. return {
  35. nonNumeric: match?.[1] || '',
  36. numeric: parseInt(match?.[2] || '0', 10)
  37. };
  38. }
  39. @Builder
  40. function bottomViewBuilder() {
  41. Text('Bottom View')
  42. .backgroundColor(Color.Yellow)
  43. .width(UIUtil.getScreenWidthVp())
  44. .height(UIUtil.getScreenHeightVp() - adHeight)
  45. }
  46. @Builder
  47. function closeBtnBuilder(closeBlock: () => void) {
  48. Text('close')
  49. .textAlign(TextAlign.Center)
  50. .backgroundColor(Color.Yellow)
  51. .width(60)
  52. .height(60)
  53. .borderRadius(30)
  54. .margin({ top: 50, right: 40 })
  55. .onClick((event) => {
  56. closeBlock()
  57. })
  58. }
  59. let globalBuilder: WrappedBuilder<[]> = wrapBuilder(bottomViewBuilder)
  60. let globalCloseBtnBuilder: WrappedBuilder<[closeBlock: () => void]> = wrapBuilder(closeBtnBuilder)
  61. let screenWidth: number = UIUtil.getScreenWidthVp()
  62. let screenHeight: number = UIUtil.getScreenHeightVp()
  63. let adWidth: number = Math.round(screenWidth)
  64. let adHeight: number = Math.round(screenHeight)
  65. @Entry
  66. @Component
  67. struct SplashIndex{
  68. context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
  69. @Provide isToPri:boolean = false
  70. //穿山甲属性
  71. // private mAdCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
  72. // private splashAd: CSJSplashAd | undefined
  73. @State adLoadSuccess: Boolean = false
  74. @State errorMsg: string | undefined = undefined;
  75. @State startLoad: boolean = false;
  76. @State appName:string = ''
  77. // private mLoadListener: CSJSplashAdLoadListener = {
  78. // onAdLoaded: (splashAd: CSJSplashAd) => {
  79. // // ToastUtil.showToast("开屏回调 - 加载广告成功")
  80. // console.log("开屏回调 -加载广告成功 onAdLoaded")
  81. // this.splashAd = splashAd
  82. // this.adLoadSuccess = true
  83. // this.startLoad = false
  84. // this.showKP()
  85. // },
  86. //
  87. // onError: (code: number, message: string) => {
  88. // this.errorMsg = "onError\ncode: " + code + "\nmessage: " + message
  89. // console.log(`开屏回调 - onError code: ${code} message: ${message}`)
  90. //
  91. //
  92. // this.junpToMain()
  93. //
  94. //
  95. // },
  96. // onRenderSuccess: (splashAd: CSJSplashAd) => {
  97. // console.log("开屏回调 - onRenderSuccess")
  98. // },
  99. //
  100. // onRenderFail:(code: number, message: string) => {
  101. // console.log("开屏回调 - onRenderFail")
  102. // this.junpToMain()
  103. // }
  104. // }
  105. @State widthLabelText: string = "宽:" + adWidth
  106. @State heightLabelText: string = "高:" + adHeight
  107. private useCustomCloseBtn: boolean = false
  108. private mBiddingAdm = '' //服务端bidding才需要设置
  109. private loadTimeout: number = 5000
  110. private mWindow: window.Window | undefined = undefined
  111. dialogController:CustomDialogController = new CustomDialogController({
  112. builder:UserPrivacyDialog({
  113. cancel:()=>{this.exitApp()},
  114. confirm:()=>{this.onConfirm()}
  115. }
  116. )})
  117. @State rootPath:string = ''
  118. @State currentPath:string = ''
  119. @State videoLocalList: Array<VideoItem> = []
  120. @State fileList: Array<String> = []
  121. @State dirList: Array<VideoItem> = []
  122. @State expireDate:string = ''
  123. async mkDownLoadDir(){
  124. const documentViewPicker = new picker.DocumentViewPicker()
  125. let documentSaveResult = await documentViewPicker.save({ pickerMode: picker.DocumentPickerMode.DOWNLOAD })
  126. let download_path = new fileUri.FileUri(documentSaveResult[0]).path
  127. this.rootPath = download_path
  128. let vPath = download_path + '/'+ LocalMusic.STR_LOCK_VIDEO+ '/' + VipPage.VIP_FILEPATH
  129. this.expireDate = this.readDataFromFile(vPath)
  130. Utility.setNoble(this.expireDate)
  131. this.doMain()
  132. }
  133. readDataFromFile(filePath:string){
  134. if(!FileUtil.accessSync(filePath)){
  135. return ''
  136. }
  137. let readTextOptions: ReadTextOptions = {
  138. offset: 0,
  139. length: 0,
  140. encoding: 'utf-8'
  141. };
  142. let stat = fileIo.statSync(filePath);
  143. readTextOptions.length = stat.size;
  144. let str = fileIo.readTextSync(filePath, readTextOptions);
  145. const parsedData: VipData = JSON.parse(str);
  146. // LogUtil.info('onecold parsedData.expireDate = ' + parsedData.expireDate)
  147. let result = Base64Util.decodeSync( parsedData.expireDate)
  148. // LogUtil.info('onecold 解密的result = ' +StrUtil.unit8ArrayToStr(result))
  149. return StrUtil.unit8ArrayToStr(result);
  150. }
  151. async doMain(){
  152. this.junpToMain()
  153. // if(!Utility.isNoble()&&Utility.isPassInstallTime(2)){
  154. // //判断用户安装app是否超过2天,超过2天才展示广告
  155. // CSJUtil.get().init()
  156. // CSJUtil.get().start()
  157. // setTimeout(()=>{
  158. // this.loadKPCSJ()
  159. // },200)
  160. // LogUtil.info('onecold 尊敬的赞助用户,欢迎您!' )
  161. // this.junpToMain()
  162. // }else{
  163. // LogUtil.info('onecold 尊敬的赞助用户,欢迎您!' )
  164. // this.junpToMain()
  165. // }
  166. }
  167. //点击同意后保存数据
  168. onConfirm(){
  169. this.dialogController.close()
  170. let preferences = data_preferences.getPreferences(this.context,H_STORE)
  171. //异步处理首选项的数据
  172. preferences.then((res)=>{
  173. res.put(IS_PRIVACY,true).then(()=>{
  174. res.flush()
  175. //记录日志
  176. Logger.debug('SplashIndex','isPricacy记录成功')
  177. }).catch((err:Error) =>{
  178. Logger.error('SplashIndex','isPricacy记录失败,原因:'+err)
  179. })
  180. })
  181. // this.junpToMainNow();
  182. // 初始化配置
  183. this.initCSJSDK()
  184. }
  185. //初始化SDK
  186. async initCSJSDK(){
  187. await this.initAppConfig();
  188. this.mkDownLoadDir()
  189. }
  190. /**
  191. * 初始化应用配置
  192. */
  193. private async initAppConfig(): Promise<void> {
  194. try {
  195. Logger.info('SplashIndex', '开始初始化应用配置...');
  196. const success = await ConfigManager.initConfig();
  197. if (success) {
  198. Logger.info('SplashIndex', '应用配置初始化成功');
  199. } else {
  200. Logger.error('SplashIndex', '应用配置初始化失败,使用默认配置');
  201. }
  202. } catch (error) {
  203. Logger.error('SplashIndex', '初始化应用配置异常:' + error);
  204. }
  205. }
  206. //退出App
  207. exitApp(){
  208. this.context.terminateSelf()
  209. }
  210. //判断是否弹出隐私政策对话框
  211. aboutToAppear(): void {
  212. Utility.getAppName(getContext(this)).then((appName:string)=>{
  213. this.appName = appName
  214. })
  215. let preferences = data_preferences.getPreferences(this.context,H_STORE)
  216. preferences.then((res) =>{
  217. res.get(IS_PRIVACY,false).then((isPrivacy) =>{
  218. if(isPrivacy == true){
  219. //说明用户已经点击过同意
  220. this.initCSJSDK()
  221. }else {
  222. //弹出弹窗
  223. this.dialogController.open()
  224. }
  225. })
  226. })
  227. }
  228. //加载开屏广告
  229. loadKPCSJ(){
  230. // this.errorMsg = undefined;
  231. // this.adLoadSuccess = false;
  232. // this.startLoad = true;
  233. // let adSlot = new AdSlotBuilder()
  234. // .setCodeId(CSJUtil.getWelcomeD())
  235. // .setAcceptSize(adWidth,
  236. // adHeight)
  237. // // .setBidAdm(this.mBiddingAdm)
  238. // .build()
  239. // let param = new CSJSplashAdLoadParam(adSlot, this.mLoadListener, this.getUIContext(),this.loadTimeout)
  240. // PrintBiddingTokenUtils.printBiddingToken(adSlot, this.mAdCreator);
  241. // this.mAdCreator.loadSplashAd(param)
  242. }
  243. showKP(){
  244. // if (this.splashAd != undefined) {
  245. // this.splashAd.setInteractionListener(this.mSplashAdInteractionListener)
  246. // // 方式一:直接showSplashAd
  247. // if (adHeight < screenHeight) {
  248. // this.splashAd?.showSplashAd(DemoConstants.windowStage, globalBuilder,
  249. // this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined)
  250. // } else {
  251. // this.splashAd?.showSplashAd(DemoConstants.windowStage, undefined,
  252. // this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined)
  253. // }
  254. // }
  255. }
  256. // CSJSplashAdInteractionListener
  257. // private mSplashAdInteractionListener: CSJSplashAdInteractionListener = {
  258. // onDidShow: () => {
  259. // console.log("开屏回调 - onDidShow")
  260. // },
  261. //
  262. // onDidClose: (closeType: CSJSplashAdCloseType) => {
  263. // console.log(`开屏回调 - onDidClose 关闭原因:${closeType}`)
  264. //
  265. // this.splashAd = undefined
  266. // setTimeout(()=>{
  267. // this.junpToMain()
  268. // },200)
  269. //
  270. //
  271. // // 方式二:需自行移除广告
  272. // // this.mWindow?.destroyWindow()
  273. //
  274. // },
  275. //
  276. // onDidClick: () => {
  277. // console.log("开屏回调 - onDidClick")
  278. //
  279. // },
  280. //
  281. // onVideoDidPlayFinish: () => {
  282. // console.log("开屏回调 - onVideoDidPlayFinish")
  283. // this.junpToMain()
  284. // },
  285. //
  286. // onVideoDidPlayFail: () => {
  287. // console.log("开屏回调 - onVideoDidPlayFail")
  288. // this.junpToMain()
  289. // }
  290. // }
  291. onPageShow(): void {
  292. if(this.isToPri){//判断是否跳转到隐私正常或者用户协议,如果是就弹出同意dialog
  293. this.aboutToAppear()
  294. this.isToPri = false
  295. }
  296. }
  297. onPageHide(): void {
  298. if (this.dialogController != null) {
  299. this.dialogController.close()
  300. }
  301. }
  302. pageTransition() {
  303. // 定义页面进入时的效果,从左侧滑入,时长为1200ms,无论页面栈发生push还是pop操作均可生效
  304. PageTransitionEnter({ type: RouteType.None, duration: 888 })
  305. .slide(SlideEffect.Left)
  306. // 定义页面退出时的效果,向左侧滑出,时长为1000ms,无论页面栈发生push还是pop操作均可生效
  307. PageTransitionExit({ type: RouteType.None, duration: 888 })
  308. .slide(SlideEffect.Left)
  309. }
  310. junpToMain(){
  311. router.pushUrl({
  312. url: 'pages/NewIndex',
  313. params: {
  314. videoList: this.videoLocalList
  315. }
  316. });
  317. }
  318. aboutToDisappear(): void {
  319. }
  320. build() {
  321. Column(){
  322. Column(){
  323. Image($r('app.media.icon'))
  324. .width(66)
  325. .height(66)
  326. .clip(true)
  327. .borderRadius('100%')
  328. .onClick(()=>{
  329. this.isToPri = true
  330. router.pushUrl({url:'pages/WebIndex',
  331. params:{ titleName:'ICP备案',webUrl:CommonConstants.ICP_URL}
  332. });
  333. })
  334. Text(this.appName)
  335. .fontColor(Color.Grey)
  336. .fontSize(18)
  337. .margin({top:20})
  338. Text(CommonConstants.ICP_NO)
  339. .fontColor(Color.Grey)
  340. .fontSize(9)
  341. .visibility(Visibility.None)
  342. .onClick(()=>{
  343. this.isToPri = true
  344. router.pushUrl({url:'pages/WebIndex',
  345. params:{ titleName:'ICP备案',webUrl:CommonConstants.ICP_URL}
  346. });
  347. })
  348. }
  349. .height(66)
  350. .width('100%')
  351. .margin({bottom:30})
  352. .justifyContent(FlexAlign.Center)
  353. // .backgroundColor(Color.White)
  354. }
  355. .justifyContent(FlexAlign.Center)
  356. .width('100%')
  357. .height('100%')
  358. // .backgroundImage($r('app.media.welcomeBg'))
  359. // .backgroundImageSize({height:'100%'})
  360. // .backgroundImagePosition(Alignment.Center)
  361. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  362. }
  363. }