NewIndex.ets 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. import { AppUtil, DeviceUtil,DisplayUtil, PreferencesUtil, ToastUtil } from '@pura/harmony-utils';
  2. import TitleBar from '../view/TitleBar';
  3. import { router } from '@kit.ArkUI';
  4. import mainViewModel, { MainViewModel } from '../viewmodel/MainViewModel';
  5. import ItemData from '../viewmodel/ItemData';
  6. import type { sysResource } from '../viewmodel/ItemData';
  7. import { CommonConstants } from '../common/constants/CommonConstants';
  8. import { VideoItem } from '../viewmodel/VideoItem';
  9. import ScreenUtil from '../common/util/ScreenUtil';
  10. import { Utility } from '../common/util/Utility';
  11. import { BusinessError, emitter } from '@kit.BasicServicesKit';
  12. import { common } from '@kit.AbilityKit';
  13. import { AdSlot, AdSlotBuilder,
  14. CSJAdCreator,
  15. CSJAdSdk, CSJNativeExpressAd, NativeExpressAdListener } from '@csj/openadsdk';
  16. import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
  17. import { ArrayList } from '@kit.ArkTS';
  18. import { CSJUtil } from '../common/util/CSJUtil';
  19. import { LocalMusic } from '../view/LocalMusic';
  20. import { StreamContent } from '../view/StreamContent';
  21. import { AvSessionController } from '../controller/AvSessionController';
  22. import { ImageKnife } from '@ohos/imageknife';
  23. import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  24. import dataStorage from '@ohos.data.storage';
  25. import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
  26. import { SettingPage } from './SettingPage';
  27. import { deviceInfo } from '@kit.BasicServicesKit';
  28. import { resourceManager } from '@kit.LocalizationKit';
  29. import { systemShare } from '@kit.ShareKit';
  30. import { uniformTypeDescriptor } from '@kit.ArkData';
  31. import { IBestIcon } from "@ibestservices/ibest-ui";
  32. const TAG = 'NewIndex'; // 日志标签
  33. /**
  34. * 首页主组件,包含顶部标题栏、主内容区(本地音乐/网络内容)、侧边抽屉菜单等。
  35. * 支持多端适配、广告集成、导航、生命周期管理等功能。
  36. */
  37. @Preview
  38. @Entry
  39. @Component
  40. struct NewIndex{
  41. /** 列表滚动器,用于抽屉菜单列表滚动 */
  42. private scroller: Scroller = new Scroller();
  43. /** 应用包名 */
  44. @State bundleName:string = ''
  45. @State appName:string = ''
  46. /** 是否显示侧边抽屉菜单 */
  47. @Provide isShowDrawer:boolean = false;
  48. /** 抽屉菜单 X 轴偏移量,用于手势滑动动画 */
  49. @Provide offsetX: number = 0;
  50. /** 本地视频列表,页面参数传入 */
  51. @Provide videoLocalList: Array<VideoItem> = []
  52. /** Y 轴偏移量(预留) */
  53. @State offsetY: number = 0;
  54. /** 主内容类型(0:本地音乐,1:网络内容) */
  55. @State mType:number = 0
  56. /** 模式类型(如歌手、专辑等) */
  57. @Provide modeType:number = 0
  58. /** 是否为零状态(预留) */
  59. @Provide('isZero') isZero:boolean = false;
  60. /** 是否显示赞助入口 */
  61. @State isShowSponsorship:boolean = false
  62. /** 页面上下文 */
  63. context = getContext(this);
  64. /** 音乐是否为零状态(预留) */
  65. @Provide('isMusicZero') isMusicZero:boolean = false;
  66. /** 本地音乐列表,持久化存储 */
  67. @StorageLink('musicLocalList') musicLocalList: Array<VideoItem> = []
  68. @Provide isFavMusic:boolean = false
  69. /** 标题栏配置模型 */
  70. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  71. .setTitleTextStyle(FontStyle.Normal)
  72. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  73. .setLeftIcon($r('app.media.menu'))
  74. .setLeftIconWidth(28)
  75. .setLeftIconHeight(28)
  76. .setTitleBarMinHeight(64)
  77. .setTitleName('首页')
  78. // .setRightIcon($r('app.media.add'))
  79. .setTitleFontSize(19)
  80. .setTitleFontColor(Color.White)
  81. .setTitleBarBackground($r('app.color.title_bar_bg'))
  82. .setLeftTitleBackground($r('app.color.title_bar_bg'))
  83. .setOnLeftClickListener(() => {
  84. // 打开菜单栏动画
  85. animateTo({ duration: 555 }, () => {
  86. this.isShowDrawer = true
  87. this.offsetX = 0
  88. })
  89. })
  90. .setRightTitleBackground($r('app.color.title_bar_bg'))
  91. // .setOnRightClickListener(()=>{
  92. // // this.goSelectVideo()
  93. // this.showSheelDialog()
  94. // })
  95. /** 应用版本号 */
  96. @State versionName:string =''
  97. /** 音频根目录路径 */
  98. @Provide rootPath:string = ''
  99. /** 当前路径 */
  100. @Provide currentPath:string = ''
  101. /** 是否为历史记录页面 */
  102. @Provide isHistory:boolean = false
  103. /** 是否可以返回上一级 */
  104. @Provide isCanBack:boolean= false
  105. @StorageProp('currentColorMode') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  106. /**
  107. * 一多界面适配断点系统
  108. */
  109. private breakpointSystem: BreakpointSystem = new BreakpointSystem();
  110. /** 当前断点类型(如大屏/小屏) */
  111. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  112. /** 记录上一次点击返回键的时间戳,用于双击退出 */
  113. private backTime:number=0;
  114. /**
  115. * 返回键处理逻辑:
  116. * - 如果不是根目录或有历史记录,发送广播通知更新列表
  117. * - 如果是根目录,双击返回键退出应用,否则提示
  118. */
  119. onBackPress(): boolean | void {
  120. if(this.currentPath !== this.rootPath||this.isHistory||this.isFavMusic||(this.modeType!==0&&this.isCanBack)){
  121. const eventData: emitter.EventData = {};
  122. emitter.emit({ eventId: 888 }, eventData); // 发送音频广播通知更新doSwipBack
  123. }else{
  124. let nowtime = Date.now();
  125. if(nowtime - this.backTime < 1000){
  126. const mContext = getContext(this) as common.UIAbilityContext
  127. mContext.terminateSelf(); // 关闭应用
  128. AvSessionController.getInstance(true).unregisterSessionListener()
  129. }else {
  130. if(this.isShowDrawer){
  131. // 如果抽屉菜单打开,先关闭抽屉
  132. animateTo({ duration: 555 }, () => {
  133. this.isShowDrawer = false
  134. })
  135. }else{
  136. this.backTime=nowtime;
  137. ToastUtil.showToast("再按一次将退出当前应用")
  138. }
  139. }
  140. }
  141. return true;
  142. }
  143. /**
  144. * 页面显示生命周期钩子
  145. * - 注册断点系统
  146. * - 获取页面参数
  147. * - 设置状态栏样式
  148. * - 初始化图片缓存
  149. * - 判断是否显示赞助入口
  150. */
  151. async aboutToAppear() {
  152. Utility.enableFullScreen()
  153. Utility.getAppName(getContext(this)).then((appName:string)=>{
  154. this.appName = appName
  155. })
  156. this.breakpointSystem.register();
  157. let params = router.getParams() as Record<string, Object>;
  158. this.videoLocalList = params.videoList as VideoItem[];
  159. Utility.setStatusBarLight()
  160. ScreenUtil.setScreenSize();
  161. this.bundleName = AppUtil.getBundleName()
  162. this.versionName = AppUtil.getVersionName();
  163. await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024)
  164. this.isShowSponsorship = Utility.isOpenTime()
  165. }
  166. /**
  167. * 页面消失生命周期钩子
  168. * 注销断点系统
  169. */
  170. aboutToDisappear() {
  171. console.info('NewIndex aboutToDisappear');
  172. this.breakpointSystem.unregister();
  173. }
  174. /**
  175. * 构建主页面结构,包括顶部横线、主内容区和抽屉菜单
  176. */
  177. build() {
  178. Stack({ alignContent: Alignment.TopStart }) {
  179. // 顶部横线
  180. Column(){
  181. Line()
  182. .width('100%')
  183. .height(1)
  184. }
  185. .backgroundColor($r('app.color.title_bar_bg'))
  186. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  187. // 主内容区
  188. Column() {
  189. Stack(){
  190. // 本地音乐内容区
  191. LocalMusic()
  192. .visibility(this.mType===0?Visibility.Visible:Visibility.None)
  193. // 网络内容区
  194. StreamContent()
  195. .visibility(this.mType===1?Visibility.Visible:Visibility.None)
  196. }
  197. }
  198. .width('100%')
  199. .height('100%')
  200. .justifyContent(FlexAlign.Start)
  201. .backgroundColor($r('app.color.bottom_control_background'))
  202. // 侧边抽屉菜单
  203. if(this.isShowDrawer){
  204. Column() {
  205. Column() {
  206. // 抽屉顶部背景图
  207. Image($r('app.media.bg_music'))
  208. .width('100%')
  209. .visibility(this.isCoverOpacity()?Visibility.None:Visibility.Visible)
  210. .height(180)
  211. Blank()
  212. .backgroundColor($r('app.color.title_bar_bg'))
  213. .visibility(this.isCoverOpacity()?Visibility.Visible:Visibility.None)
  214. .width('100%')
  215. .height(55)
  216. // 动态生成抽屉菜单内容
  217. this.getDrawerView()
  218. }
  219. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'40%':'75%')
  220. .height('100%')
  221. .backgroundColor($r('app.color.silvery'))
  222. .onClick((event:ClickEvent)=>{
  223. // 阻止事件冒泡
  224. })
  225. }
  226. .width('100%')
  227. .height('100%')
  228. .backgroundColor($r('app.color.ban_touming'))
  229. .alignItems(HorizontalAlign.Start)
  230. .onClick((event:ClickEvent)=>{
  231. // 点击抽屉外部关闭抽屉
  232. animateTo({ duration: 555 }, () => {
  233. this.isShowDrawer = false
  234. })
  235. })
  236. .translate({ x: this.offsetX, y: 0, z: 0 })
  237. .transition({ type: TransitionType.Insert, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
  238. .transition({ type: TransitionType.Delete, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
  239. .gesture(
  240. PanGesture()
  241. .onActionUpdate((event:GestureEvent)=>{
  242. // 手势滑动更新抽屉偏移
  243. if(event.offsetX<0){
  244. this.offsetX = event.offsetX;
  245. }
  246. })
  247. .onActionEnd(() => {
  248. // 手势结束判断是否关闭抽屉
  249. if(this.offsetX<-DisplayUtil.getWidth()/9){
  250. animateTo({ duration: 555 }, () => {
  251. this.isShowDrawer = false
  252. })
  253. }else{
  254. animateTo({ duration: 555 }, () => {
  255. this.isShowDrawer = true
  256. this.offsetX = 0
  257. })
  258. }
  259. })
  260. )
  261. }
  262. }
  263. }
  264. /**
  265. * 动态生成抽屉菜单内容
  266. * 根据 isShowSponsorship 展示不同菜单项
  267. */
  268. @Builder
  269. getDrawerView(){
  270. List({space: 0, scroller: this.scroller}){
  271. ForEach(this.isShowSponsorship?mainViewModel.getDrawerData2():mainViewModel.getDrawerData(),(item: ItemData)=>{
  272. ListItem(){
  273. Row() {
  274. // 菜单图标
  275. if (typeof item.img === 'object' && item.img !== null && (item.img as sysResource).type === 'symbol') {
  276. SymbolGlyph((item.img as sysResource).value as Resource)
  277. .size({ width: 22, height: 22 })
  278. .fontColor([$r("app.color.img_color")])
  279. .alignSelf(ItemAlign.Center)
  280. .margin({ left: 2 })
  281. }else if (typeof item.img === 'object' && item.img !== null && (item.img as sysResource).type === 'ibest') {
  282. IBestIcon({
  283. name: (item.img as sysResource).value as string,
  284. iconSize:22,
  285. color: $r("app.color.img_color"),
  286. }).margin({ left: 2 })
  287. .alignSelf(ItemAlign.Center)
  288. }else {
  289. Image(item.img as Resource)
  290. .height(22)
  291. .alignSelf(ItemAlign.Center)
  292. .fillColor($r('app.color.img_color'))
  293. .margin({ left: 2 })
  294. }
  295. // 菜单标题
  296. Text(item.title)
  297. .margin({ left: 10, right: 20 })
  298. .fontSize(15)
  299. .fontColor($r('app.color.index_tab_font_color'))
  300. .fontWeight(480)
  301. Blank()
  302. // 右侧箭头
  303. Image($r('app.media.arrow_right'))
  304. .width(22)
  305. .height(22)
  306. .margin({ left: 20, right: 0 })
  307. .align(Alignment.Center)
  308. }
  309. .width('100%')
  310. .height(55)
  311. .useEffect(true)
  312. .onClick(async () => {
  313. // 根据 item.id 跳转或切换功能
  314. switch (item.id) {
  315. case MainViewModel.MENU_MUSIC:
  316. this.mType = 0
  317. animateTo({ duration: 555 }, () => {
  318. this.isShowDrawer = false
  319. })
  320. break
  321. case MainViewModel.MENU_FILE_SCAN:
  322. router.pushUrl({
  323. url: 'pages/ScanFilePage'
  324. });
  325. break
  326. case MainViewModel.MENU_HOME:
  327. this.mType = 0
  328. this.modeType = 0
  329. animateTo({ duration: 555 }, () => {
  330. this.isShowDrawer = false
  331. })
  332. break
  333. case MainViewModel.MENU_MIEDIA_KU:
  334. this.modeType = 1
  335. animateTo({ duration: 555 }, () => {
  336. this.isShowDrawer = false
  337. })
  338. break
  339. case MainViewModel.MENU_MIEDIA_ARTIST:
  340. this.modeType = 2
  341. animateTo({ duration: 555 }, () => {
  342. this.isShowDrawer = false
  343. })
  344. break
  345. case MainViewModel.MENU_MIEDIA_ALBUM:
  346. this.modeType = 3
  347. animateTo({ duration: 555 }, () => {
  348. this.isShowDrawer = false
  349. })
  350. break
  351. case MainViewModel.MENU_SETTING:
  352. router.pushUrl({
  353. url: 'pages/SettingPage'
  354. }, router.RouterMode.Single);
  355. break
  356. case MainViewModel.MENU_VIP:
  357. router.pushUrl({
  358. url: 'pages/VipPage'
  359. }, router.RouterMode.Single);
  360. break
  361. case MainViewModel.MENU_USER:
  362. router.pushUrl({
  363. url: 'pages/UserCenter'
  364. }, router.RouterMode.Single);
  365. break
  366. case MainViewModel.MENU_NET_CONNECT:
  367. this.mType = 1
  368. animateTo({ duration: 555 }, () => {
  369. this.isShowDrawer = false
  370. })
  371. break
  372. case MainViewModel.MENU_SIMI:
  373. router.pushUrl({
  374. url: 'pages/VerifyPage'
  375. });
  376. break
  377. case MainViewModel.MENU_LIKE:
  378. router.pushUrl({
  379. url: 'pages/LikeVideoPage'
  380. });
  381. break
  382. case MainViewModel.MENU_DUTY:
  383. router.pushUrl({
  384. url: 'pages/WebIndex',
  385. params: { titleName: '用户协议', webUrl: CommonConstants.NEW_DUTY }
  386. });
  387. break
  388. case MainViewModel.MENU_HAOPING:
  389. Utility.gotoMarket(getContext(this) as common.UIAbilityContext,this.bundleName)
  390. break
  391. case MainViewModel.MENU_TEST_SPEED:
  392. router.pushUrl({
  393. url: 'pages/SpeedIndex'
  394. });
  395. break
  396. case MainViewModel.MENU_OPTIMIZE:
  397. router.pushUrl({
  398. url: 'pages/AddSpeedPage'
  399. });
  400. break
  401. case MainViewModel.MENU_ABOUT:
  402. router.pushUrl({
  403. url: 'pages/AboutPage'
  404. }, router.RouterMode.Single);
  405. break
  406. case MainViewModel.MENU_UPDATE:
  407. AlertDialog.show({title:'版本更新',message:'当前版本为最新版本:'+this.versionName,
  408. autoCancel:true, alignment:DialogAlignment.Center,
  409. offset:{dx:0,dy:-20},//在Y轴方向上的编译量
  410. confirm:{
  411. value:'确定',fontColor:Color.White,backgroundColor:$r('app.color.title_bar_bg'),
  412. action:()=>{
  413. }
  414. }
  415. })
  416. break
  417. case MainViewModel.MENU_YSZC:
  418. router.pushUrl({
  419. url: 'pages/WebIndex',
  420. params: { titleName: '隐私政策', webUrl: CommonConstants.NEW_YS_HW }
  421. });
  422. break
  423. case MainViewModel.MENU_SHARE:
  424. this.gotoShare()
  425. break
  426. }
  427. })
  428. }
  429. .width('90%')
  430. .height(55)
  431. })
  432. }
  433. .width('100%')
  434. .alignListItem(ListItemAlign.Center)
  435. .backgroundColor($r('app.color.silvery'))
  436. .layoutWeight(1)
  437. // .divider({ strokeWidth: 1, color: this.isDarkMode? '333333':'#ffe9f0f0' })
  438. .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
  439. }
  440. gotoShare(){
  441. let shareData: systemShare.SharedData = new systemShare.SharedData({
  442. utd: uniformTypeDescriptor.UniformDataType.TEXT,
  443. content: 'https://appgallery.huawei.com/app/detail?id='+this.bundleName,
  444. title: this.appName, // 不传title字段时,显示content
  445. description: '精心雕琢的无损音乐播放器',
  446. // thumbnail: new Uint8Array() // 推荐传入适合的缩略图 不传则显示默认text图标
  447. });
  448. // 进行分享面板显示
  449. let controller: systemShare.ShareController = new systemShare.ShareController(shareData);
  450. let context = getContext(this) as common.UIAbilityContext;
  451. controller.show(context, {
  452. selectionMode: systemShare.SelectionMode.SINGLE,
  453. previewMode: systemShare.SharePreviewMode.DETAIL,
  454. }).then(() => {
  455. console.info('ShareController show success.');
  456. }).catch((error: BusinessError) => {
  457. console.error(`ShareController show error. code: ${error.code}, message: ${error.message}`);
  458. });
  459. }
  460. /**
  461. * ================== 穿山甲广告相关 ==================
  462. */
  463. /** Banner广告对象 */
  464. private declare bannerAd: CSJNativeExpressAd;
  465. /** 广告加载状态 */
  466. @State private status: string = "未加载"
  467. /** 是否展示广告 */
  468. @State private isShowAd: boolean = false
  469. /** 广告位配置信息 */
  470. private declare mAdSlot: AdSlot;
  471. /** 服务端bidding广告内容(可选) */
  472. private mBiddingAdm = ''
  473. /** 广告加载监听器 */
  474. private expressLoadAdListener: NativeExpressAdListener = {
  475. /**
  476. * 广告加载失败回调
  477. */
  478. onError: (code: number, message: string) => {
  479. console.error("加载广告失败,code=" + code + ",message=" + message);
  480. this.status = "加载广告失败,code=" + code + ",message=" + message;
  481. },
  482. /**
  483. * 广告加载成功回调
  484. * @param ads 返回的广告列表
  485. */
  486. onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  487. console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  488. if (ads && ads.length > 0) {
  489. ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  490. // 设置广告交互监听
  491. ad.setExpressInteractionListener({
  492. /** 广告点击回调 */
  493. onAdClicked: (type: number) => {
  494. console.log("BannerExpressAdPage==onAdClicked......");
  495. },
  496. /** 广告展示回调 */
  497. onAdShow: (type: number) => {
  498. console.log("BannerExpressAdPage==onAdShow......");
  499. },
  500. /** 模板渲染失败回调 */
  501. onRenderFail: (code: number, msg: string) => {
  502. console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  503. },
  504. /** 模板渲染成功回调 */
  505. onRenderSuccess: (width: number, height: number) => {
  506. console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  507. this.bannerAd = ad;
  508. this.status = "广告加载完成待展示";
  509. this.showBannerAd()
  510. }
  511. })
  512. // 设置广告轮播时间
  513. ad.setSlideIntervalTime(30 * 1000);//设置轮播时间长
  514. this.setDislikeCallback(ad); //设置dislike
  515. ad.render(this.getUIContext()) // 开始渲染广告
  516. this.status = "广告加载中...";
  517. });
  518. }
  519. }
  520. }
  521. /**
  522. * 设置广告 dislike 回调
  523. * @param ad 广告对象
  524. */
  525. private setDislikeCallback(ad: CSJNativeExpressAd) {
  526. ad.setDislikeCallback({
  527. /** dislike 弹窗显示 */
  528. onShow: () => {
  529. console.log("BannerExpressAdPage==dislike......show");
  530. },
  531. /** 选择 dislike 选项 */
  532. onSelected: (position: number, value: string, enforceRemove: boolean) => {
  533. this.isShowAd = false;
  534. console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value + ",enforce=" + enforceRemove);
  535. },
  536. /** 点击取消 dislike */
  537. onCancel: () => {
  538. console.log("BannerExpressAdPage==dislike......onCancel");
  539. }
  540. })
  541. }
  542. /**
  543. * 加载Banner广告
  544. * @param rit 广告位ID
  545. */
  546. loadBannerAd(rit: string) {
  547. // 仅在满足条件时加载广告
  548. if(!Utility.isNoble()){
  549. return
  550. }
  551. if(!Utility.isPassInstallTime(2)){
  552. return
  553. }
  554. this.isShowAd = false;
  555. let adCreator:CSJAdCreator = CSJAdSdk.getAdCreator()
  556. this.mAdSlot = new AdSlotBuilder()
  557. .setCodeId(rit)
  558. .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  559. .setAdCount(1)
  560. .setBidAdm(this.mBiddingAdm)
  561. .build()
  562. PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  563. adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  564. this.status = "广告加载中..."
  565. }
  566. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  567. HeightBreakpoint.HEIGHT_LG;
  568. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  569. //是否是Pura X外屏,或者小屏幕
  570. isPuraWP() {
  571. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  572. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  573. }
  574. //是否是Pura X外屏,或者小屏幕或者手机横屏
  575. isCoverOpacity() {
  576. if (this.isPuraWP()) {
  577. return true
  578. }
  579. if (this.isPhoneLan()) {
  580. return true
  581. }
  582. if (deviceInfo.marketName.includes('Pura X')
  583. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  584. return true
  585. }
  586. return false
  587. }
  588. //是不是手机横屏
  589. isPhoneLan() {
  590. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  591. && this.currentBreakpoint !== BreakpointTypeEnum.SM) {
  592. if (DisplayUtil.getFoldStatus() === 0 || DisplayUtil.getFoldStatus() === 2) {
  593. return true
  594. }
  595. }
  596. return false
  597. }
  598. /**
  599. * 展示Banner广告
  600. */
  601. showBannerAd() {
  602. if (!this.bannerAd) {
  603. return
  604. }
  605. this.isShowAd = true
  606. this.status = "已展示"
  607. }
  608. /**
  609. * ================== 穿山甲广告相关结束 ==================
  610. */
  611. // geIDD() {
  612. // // 获取应用签名等信息示例代码
  613. // let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
  614. // bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
  615. // try {
  616. // bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
  617. // hilog.info(0x0000, 'testTag11', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
  618. // }).catch((err: BusinessError) => {
  619. // hilog.error(0x0000, 'testTag11', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
  620. // });
  621. // } catch (err) {
  622. // let message = (err as BusinessError).message;
  623. // hilog.error(0x0000, 'testTag33', 'getBundleInfoForSelf failed: %{public}s', message);
  624. // }
  625. // }
  626. }