Browse Source

通用设置发生改变的时候,自定义背景通知更新UI

onecold 1 year ago
parent
commit
e9cffa6024

+ 1 - 1
entry/src/main/ets/pages/NewIndex.ets

@@ -229,7 +229,7 @@ struct NewIndex{
       .width('100%')
       .height('100%')
       .justifyContent(FlexAlign.Start)
-      .backgroundColor($r('app.color.index_background'))
+      .backgroundColor($r('app.color.bottom_control_background'))
 
       // 侧边抽屉菜单
       if(this.isShowDrawer){

+ 19 - 12
entry/src/main/ets/pages/SettingPage.ets

@@ -7,7 +7,7 @@ import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
 import common from '@ohos.app.ability.common';
 import { photoAccessHelper } from '@kit.MediaLibraryKit'
 import { fileIo, fileUri } from '@kit.CoreFileKit'
-import { BusinessError } from '@kit.BasicServicesKit'
+import { BusinessError, emitter } from '@kit.BasicServicesKit'
 import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
 
 @Preview
@@ -284,7 +284,7 @@ export struct SettingPage {
                 .onChange((checked: boolean) => {
                   this.isShowSimi = checked;
                   PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isShowSimi)
-                  ToastUtil.showToast('本设置重启才生效')
+                  this.sendChangeEvent()
                 })
                 .width(50)
                 .height(30);
@@ -307,7 +307,7 @@ export struct SettingPage {
                 .onChange((checked: boolean) => {
                   this.isShowFAV = checked;
                   PreferencesUtil.put(SettingPage.IS_SHOW_FAV, this.isShowFAV)
-                  ToastUtil.showToast('本设置重启才生效')
+                  this.sendChangeEvent()
                 })
                 .width(50)
                 .height(30);
@@ -330,7 +330,7 @@ export struct SettingPage {
                 .onChange((checked: boolean) => {
                   this.isShowHistory = checked;
                   PreferencesUtil.put(SettingPage.IS_SHOW_HISTORY, this.isShowHistory)
-                  ToastUtil.showToast('本设置重启才生效')
+                  this.sendChangeEvent()
                 })
                 .width(50)
                 .height(30);
@@ -400,7 +400,7 @@ export struct SettingPage {
                 .onSelect(async (_index: number, text?: string | undefined) => {
                   this.sortType = _index
                   PreferencesUtil.put(SettingPage.SORT_TYPE, this.sortType)
-                  ToastUtil.showToast('本设置重启才生效')
+                  this.sendChangeEvent()
                 })
             }
             .height(55)
@@ -428,7 +428,7 @@ export struct SettingPage {
           }
           .backgroundColor($r('app.color.settings_background_main'))
           .borderRadius(20)
-          .margin({ left: 0, right: 0, top: 0, bottom: 10 })
+          .margin({ left: 0, right: 0, top: 10, bottom: 10 })
           .padding(0)
 
           // API设置分组
@@ -492,7 +492,7 @@ export struct SettingPage {
           }
           .backgroundColor($r('app.color.settings_background_main'))
           .borderRadius(20)
-          .margin({ left: 0, right: 0, top: 0, bottom: 10 })
+          .margin({ left: 0, right: 0, top: 10, bottom: 30 })
           .padding(0)
         }
         .margin({ left: 35, right: 35, top: 20, bottom: 30 })
@@ -509,6 +509,11 @@ export struct SettingPage {
     .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
   }
 
+  //发送广播通知更新UI
+  sendChangeEvent(){
+    const eventData: emitter.EventData = {};
+    emitter.emit({ eventId: 333 }, eventData); // 发送音频广播通知更新doSwipBack
+  }
 
   goSelectImage() {
 
@@ -526,7 +531,8 @@ export struct SettingPage {
       //使用fs.openSync接口,通过uri打开这个文件得到fd
       let file = fileIo.openSync(selectUris[0], fileIo.OpenMode.READ_ONLY);
       console.info('file fd: ' + file.fd);
-      let name = await MD5.digestSync('homeBg')
+      const timestamp: number = Math.floor(Date.now() / 1000);
+      let name = timestamp+"_homebg"
       let imagePath = this.context.filesDir + FileUtil.separator + name
       imagePath = fileUri.getUriFromPath(imagePath)
       let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
@@ -537,7 +543,7 @@ export struct SettingPage {
       this.customizeBgPath = imagePath
 
       PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG_PATH, this.customizeBgPath)
-
+      this.sendChangeEvent()
 
     }).catch((err: BusinessError) => {
 
@@ -567,7 +573,7 @@ export struct SettingPage {
         .objectFit( ImageFit.Contain)
         .borderRadius(20)
         .clip(true)
-        .margin({ left: 20,bottom:40 })
+        .margin({bottom:30 })
 
       Row() {
 
@@ -580,7 +586,6 @@ export struct SettingPage {
             .width(100)
             .backgroundColor($r('app.color.title_bar_bg'))
             .stateEffect(true)
-            .margin({ right: 5, left: 12 })
             .onClick(async () => {
 
               this.goSelectImage()
@@ -596,7 +601,7 @@ export struct SettingPage {
       }
       .width('100%')
       .height(58)
-
+      .margin({ left: 20,bottom:30 })
 
       Column() {
         Row() {
@@ -613,6 +618,8 @@ export struct SettingPage {
             .onChange((checked: boolean) => {
               this.isCustomizeBg = checked;
               PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG, this.isCustomizeBg)
+
+              this.sendChangeEvent()
             })
             .width(50)
             .height(30);

+ 14 - 111
entry/src/main/ets/view/LocalMusic.ets

@@ -405,7 +405,12 @@ export struct LocalMusic {
     // 监听ScanFilePage广播事件(更新数据库)
     emitter.on(eventScanUpdate, (eventData: emitter.EventData) => {
       this.doUpdateData()
+    });
 
+    let eventSetting: emitter.InnerEvent = { eventId: 333 }
+    // 监听广播事件(打开其他应用处理)
+    emitter.on(eventSetting, (eventData: emitter.EventData) => {
+      this.doChangeSetting()
 
     });
 
@@ -440,6 +445,14 @@ export struct LocalMusic {
     this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, false)
   }
 
+  doChangeSetting(){
+    this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
+    this.isCustomizeBg  = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
+    this.customizeBgPath  = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
+
+    this.doUpdateData()
+  }
+
   doChangeBarHeight() {
     if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
       (this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
@@ -749,116 +762,6 @@ export struct LocalMusic {
 
   }
 
-  // async getSortedFiles(curPath:string,isWorkerPost?:boolean,destPath?:string,isOpen?:boolean){
-  //   if(isWorkerPost){
-  //     workerInstance.postMessage({ code: 2, data: this.context });
-  //   }
-  //   if(this.modeType!==0){
-  //
-  //     return
-  //   }
-  //   this.isHistory = false
-  //   this.isCanBack = false
-  //   this.currentPath = curPath
-  //   this.titleBarModel.setTitleName(Utility.getFileDirName(this.currentPath,this.rootPath))
-  //   if(curPath === this.rootPath){
-  //     this.titleBarModel.setLeftIconMain($r('app.media.menu'))
-  //   }else{
-  //
-  //     if(this.rootPath === Utility.getParentDirectory(curPath))
-  //       this.titleBarModel.setLeftIconMain($r('app.media.left_back_white'))
-  //   }
-  //
-  //   // Get the current file list and calculate its hash
-  //
-  //   this.fileList = FileUtil.listFileSync(curPath);
-  //
-  //   const currentHash = simpleHash(this.fileList);
-  //
-  //
-  //   // Check cache
-  //   const cachedValue = this.findCache(curPath);
-  //   const cachedHash = this.findStringCache(curPath + '_hash');
-  //   const cachedDirList= this.findCache(curPath+"_dirList");
-  //   if(cachedValue!==undefined){
-  //     // this.videoLocalList = cachedValue;
-  //     this.updateListData(cachedValue)
-  //   }
-  //
-  //   if(cachedDirList!==undefined)
-  //     this.dirList = cachedDirList
-  //   //通过当前hash值和缓存hash判断list有没有变化
-  //   if (cachedValue && cachedHash === currentHash) {
-  //     // this.updatePixelMaps(curPath)
-  //     // this.setButtonStatus();
-  //
-  //     return;
-  //   }
-  //
-  //   this.fileList = FileUtil.listFileSync(curPath)
-  //   let directories: Array<VideoItem> = [];
-  //   let files: Array<VideoItem> = [];
-  //   for (let i = 0; i < this.fileList.length; i++) {
-  //     console.info(`The name of file: ${this.fileList[i]}`);
-  //     let path = curPath+'/'+this.fileList[i]
-  //     if(FileUtil.isDirectory(path)){
-  //       let item:VideoItem = new VideoItem(this.fileList[i].toString(),this.fileList[i].toString(),path,CommonConstants.TYPE_IS_DIR,0,'')
-  //
-  //       directories.push(item);
-  //       directories.sort((a, b) => a.cTime.localeCompare(b.cTime));
-  //       Utility.doSortListAscending(directories)
-  //
-  //     }else{
-  //       let item:VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context,path,CommonConstants.TYPE_LOCAL,false);
-  //       if(!path.endsWith('.lrc')&&Utility.isMeidaByExtension(path)&&!path.endsWith('.srt')){
-  //         files.push(item);
-  //         files.sort((a, b) => a.cTime.localeCompare(b.cTime));
-  //         Utility.doSortListAscending(files)
-  //       }
-  //
-  //     }
-  //   }
-  //
-  //   if(this.currentPath===this.rootPath){
-  //     this.dirList = directories
-  //     this.addCache(curPath+"_dirList", this.dirList);
-  //   }
-  //
-  //   if(this.isShowAd&&ArrayUtil.isNotEmpty(directories)){
-  //     let adItem:VideoItem = new VideoItem('','','',CommonConstants.TYPE_IS_CSJAD,0,'')
-  //     directories.push(adItem)
-  //   }
-  //   // 合并文件夹和文件,文件夹在前,文件在后,广告在中间
-  //   this.videoLocalList =  directories.concat(files);
-  //   this.dataSource.pushArrayData(this.videoLocalList);
-  //
-  //   this.addCache(curPath, this.videoLocalList);
-  //   await this.saveCacheToStorage();  // 保存缓存至本地存储
-  //
-  //   console.info(`gengxin 1: ${this.videoLocalList.length}`);
-  //   // this.updatePixelMaps(curPath)
-  //   this.addStringCache(curPath + '_hash', currentHash);
-  //   // this.setButtonStatus()
-  //   if(isOpen){
-  //
-  //     if (destPath === undefined) {
-  //       // 处理 destPath 为 undefined 的情况
-  //       return
-  //     }
-  //     if(destPath.endsWith('.lrc')){
-  //       ToastUtil.showToast('导入歌词成功!请注意歌词文件和歌曲要同个歌单路径。')
-  //       if(StrUtil.isNotEmpty(this.videoUrl)){
-  //         let lyricPath = this.videoUrl.substring(0,this.videoUrl.lastIndexOf('.'))+'.lrc'
-  //         this.initLyric(lyricPath);
-  //       }
-  //
-  //       return
-  //     }
-  //     let item2  = new VideoItem(Utility.getMediaNameByUri(destPath),destPath,destPath,0,0,'')
-  //     this.doPlay(item2)
-  //   }
-  //
-  // }
 
   //扫描文件夹入库
   async scanDirectory(curPath: string): Promise<VideoItem[]> {
@@ -3909,7 +3812,7 @@ export struct LocalMusic {
       })
 
       Button() {
-        Image($r('app.media.close'))
+        Image($r('app.media.ic_close'))
           .fillColor(Color.White)
           .width(13)
       }