瀏覽代碼

在欢迎界面载入首页文件夹的缓存

onecold 9 月之前
父節點
當前提交
1fa85103e9

+ 5 - 2
entry/src/main/ets/pages/NewIndex.ets

@@ -40,6 +40,7 @@ import { convertPlaylistSongsToVideoItems } from './PlaylistDetailPage';
 import MediaTable from '../common/util/MediaTable';
 import { showCreatePlaylistDialog } from '../dialog/PlaylistDialog';
 import { ImagePickerUtil } from '../common/util/ImagePickerUtil';
+import { ParamInfo } from '../viewmodel/ParamInfo';
 
 // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
 
@@ -229,6 +230,9 @@ struct NewIndex {
    */
 
   async aboutToAppear() {
+    let params = this.getUIContext().getRouter().getParams() as ParamInfo;
+    this.videoLocalList = params.videoList as VideoItem[];
+    console.info('onecold NewIndex aboutToAppear 被调用,length:'+ this.videoLocalList.length)
     this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
     this.idDefaultMediaKu = PreferencesUtil.getBooleanSync('idDefaultMediaKu', false)
     if(this.idDefaultMediaKu){
@@ -241,8 +245,7 @@ struct NewIndex {
     })
     this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
     this.breakpointSystem.register();
-    let params = router.getParams() as Record<string, Object>;
-    this.videoLocalList = params.videoList as VideoItem[];
+
     // Utility.setStatusBarLight()
     ScreenUtil.setScreenSize();
     this.bundleName = AppUtil.getBundleName()

+ 34 - 8
entry/src/main/ets/pages/SplashIndex.ets

@@ -14,7 +14,7 @@ import { ConfigManager } from '../common/util/ConfigManager'
 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 { AppUtil, Base64Util, FileUtil, LogUtil, PreferencesUtil, StrUtil, ToastUtil } from '@pura/harmony-utils'
 import { Utility } from '../common/util/Utility'
 import { VideoItem } from '../viewmodel/VideoItem'
 import { fileIo, fileUri, picker, ReadTextOptions } from '@kit.CoreFileKit'
@@ -131,9 +131,7 @@ struct  SplashIndex{
 
   @State rootPath:string = ''
   @State currentPath:string = ''
-  @State videoLocalList: Array<VideoItem> = []
-  @State  fileList: Array<String> = []
-  @State  dirList: Array<VideoItem> = []
+  @State videoLocalList: VideoItem[] = []
   @State expireDate:string = ''
   async mkDownLoadDir(){
 
@@ -142,9 +140,12 @@ struct  SplashIndex{
     let download_path = new fileUri.FileUri(documentSaveResult[0]).path
     this.rootPath = download_path
     let vPath = download_path + '/'+ STR_LOCK_VIDEO+ '/' + VIP_FILEPATH
+
     this.expireDate =  this.readDataFromFile(vPath)
     Utility.setNoble(this.expireDate)
-    this.doMain()
+    // 载入首页文件夹的缓存
+    this.loadCacheFromStorage(this.rootPath)
+
 
 
   }
@@ -209,6 +210,30 @@ struct  SplashIndex{
 
   }
 
+  // 缓存机制
+  private cache: Map<string, Array<VideoItem>> = new Map();
+  //查找缓存
+  private findCache(key: string): Array<VideoItem> | undefined {
+    return this.cache.get(key);
+  }
+  // 载入首页文件夹的缓存
+  async loadCacheFromStorage(curPath:string) {
+    const cacheString = await PreferencesUtil.getStringSync('music_cache', '');
+    if (cacheString) {
+      const cacheArray: [string, Array<VideoItem>][] = JSON.parse(cacheString);
+      this.cache = new Map(cacheArray);
+    }
+
+    const cachedValue = this.findCache(curPath);
+    // 合并文件夹和文件,文件夹在前,文件在后
+    if(cachedValue)
+      this.videoLocalList =  cachedValue;
+    console.log(" onecold 欢迎页面 this.videoLocalList.length = " + this.videoLocalList.length);
+    this.doMain()
+  }
+
+
+
   //初始化SDK
   async initCSJSDK(){
     await this.initAppConfig();
@@ -353,8 +378,8 @@ struct  SplashIndex{
 
 
   junpToMain(){
-    console.info('onecold SplashIndex junpToMain ' )
-    router.replace({
+    console.info('onecold SplashIndex junpToMain length= '+this.videoLocalList.length )
+    this.getUIContext().getRouter().replaceUrl({
       url: 'pages/NewIndex',
       params: {
         videoList: this.videoLocalList
@@ -423,4 +448,5 @@ struct  SplashIndex{
 
 
   }
-}
+}
+

+ 5 - 2
entry/src/main/ets/view/LocalMusic.ets

@@ -204,7 +204,7 @@ export struct LocalMusic {
   @State isZero: boolean = false
   @State fileList: Array<string> = []
   @State dirList: Array<VideoItem> = []
-  @Consume videoLocalList: Array<VideoItem>
+  @Consume videoLocalList:VideoItem[]
   @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
   // @State mediaKuList: Array<VideoItem> = []; //媒体库文件
   @StorageProp('mediaKuList')  mediaKuList: Array<VideoItem> = []; //媒体库文件
@@ -594,6 +594,9 @@ export struct LocalMusic {
 
   // 组件生命周期
   aboutToAppear() {
+    if(ArrayUtil.isNotEmpty(this.videoLocalList)&&this.modeType==0){
+      this.updateListData(this.videoLocalList)
+    }
     // 初始化 PlaylistTable
     this.playlistTable = new PlaylistTable(getContext(this))
 
@@ -1364,7 +1367,7 @@ export struct LocalMusic {
   updateListData(mList: Array<VideoItem>, noSort?: boolean) {
 
     animateTo({ duration: 666 }, () => {
-      this.opacityItem = 0;
+      this.opacityItem = 0.5;
     });
     setTimeout(() => {
       this.videoLocalList = mList;

+ 8 - 0
entry/src/main/ets/viewmodel/ParamInfo.ets

@@ -0,0 +1,8 @@
+import { VideoItem } from "./VideoItem"
+
+export  class ParamInfo {
+  videoList: VideoItem[]
+  constructor(videoList: VideoItem[]){
+    this.videoList = videoList
+  }
+}

+ 2 - 1
entry/src/main/module.json5

@@ -8,7 +8,8 @@
     "deviceTypes": [
       "phone",
       "tablet",
-      "2in1"
+      "2in1",
+      "tv"
     ],
     "querySchemes": [//支付宝配置
       "https",

+ 0 - 0
oh_modules/@pura/spinkit/consumer-rules.txt