SettingPage.ets 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. import TitleBar from '../view/TitleBar'
  2. import { promptAction, router } from '@kit.ArkUI'
  3. import { CommonConstants } from '../common/constants/CommonConstants'
  4. import { AppUtil, DeviceUtil, DisplayUtil, FileUtil, MD5, PreferencesUtil, ToastUtil } from '@pura/harmony-utils'
  5. import { CustomContentDialog } from '@kit.ArkUI'
  6. import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
  7. import common from '@ohos.app.ability.common';
  8. import { photoAccessHelper } from '@kit.MediaLibraryKit'
  9. import { fileIo, fileUri } from '@kit.CoreFileKit'
  10. import { BusinessError, emitter } from '@kit.BasicServicesKit'
  11. import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
  12. import { resourceManager } from '@kit.LocalizationKit'
  13. import {
  14. IBestButton,
  15. IBestColorPicker,
  16. IBestField,
  17. IBestIcon,
  18. IBestPopup,
  19. IBestRadio,
  20. IBestRadioGroup
  21. } from '@ibestservices/ibest-ui'
  22. import { Utility } from '../common/util/Utility'
  23. @Preview
  24. @Entry
  25. @Component
  26. export struct SettingPage {
  27. static readonly THEME_MODE: string = 'themeMode';
  28. static readonly SORT_TYPE: string = 'musicSortType';
  29. static readonly IS_BGPLAY_OPEN: string = 'isBgPlayOpen';
  30. static readonly IS_AUTO_RATATE: string = 'isAutoRatate';
  31. static readonly iS_MEMORY_PLAY: string = 'isMemoryPlay';
  32. static readonly IS_MIDIACODEC_OPEN: string = 'isMediacodec';
  33. static readonly iS_MUSIC_MEMORY_PLAY: string = 'isMusicMemoryPlay';
  34. static readonly iS_MUSIC_BG_COVER: string = 'isMusicBGCover';
  35. static readonly iS_SAVE_PLAY_MODE: string = 'isSavePlayMode';
  36. static readonly IS_COVER_RECTANGLE: string = 'isCoverRectangle'; //封面圆形或者方形
  37. static readonly IS_SHOW_SIMI: string = 'isShowSimi';
  38. static readonly IS_SHOW_FAV: string = 'isShowFAV';
  39. static readonly IS_SHOW_HISTORY: string = 'isShowHistory';
  40. static readonly IS_CUSTOMIZE_BG: string = 'is_customize_bg';
  41. static readonly IS_GRID_MUSIC: string = 'is_grid_music';
  42. static readonly IS_CUSTOMIZE_BG_PATH: string = 'is_customize_bg_path';
  43. static readonly IS_SCROLL_HIDE: string = 'isScrollHide';
  44. static readonly IS_SAMETIME_PLAY: string = 'isSameTimePlay';
  45. static readonly CUSTOMIZE_BG_BLUR: string = 'customize_bg_blur';
  46. static readonly BG_BRIGHTNESS: string = 'bg_brightness';
  47. public static THEME_COLOR_KEY: string = 'THEME_COLOR';
  48. public static THEME_COLOR_LIST: Array<ThemeColorItem> = [
  49. { name: '经典蓝', color: '#0A59F7' },
  50. { name: '活力黄', color: '#FFC107' },
  51. { name: '枫叶红', color: '#F44336' },
  52. { name: '玫瑰粉', color: '#FF4081' },
  53. { name: '幻影紫', color: '#9C27B0' },
  54. { name: '翡翠绿', color: '#64BB5C' },
  55. { name: '竹青蓝', color: '#00BCD4' },
  56. { name: '深空灰', color: '#607D8B' },
  57. { name: '橙霞橙', color: '#FF9800' },
  58. { name: '湖水蓝', color: '#00BFFF' },
  59. { name: '柠檬绿', color: '#C6FF00' },
  60. { name: '樱花粉', color: '#FF69B4' },
  61. { name: '暮夜蓝', color: '#283593' },
  62. { name: '薄荷青', color: '#1DE9B6' },
  63. { name: '银沙灰', color: '#B0BEC5' },
  64. { name: '自定义', color: '#ffecec' }
  65. ];
  66. @State showApiDialog: boolean = false
  67. @State tempApiUrl: string = ''
  68. @State lyricApiUrl: string = PreferencesUtil.getStringSync('LRC_API', '')
  69. @State isBgPlayOpen: boolean = true //是否启用后台播放
  70. @State isAutoRatate: boolean = true //是否启用自动横竖屏
  71. @State isMemoryPlay: boolean = true //是否启用记忆播放
  72. @State isMediacodec: boolean = false //是否启用硬件解码
  73. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  74. @State isMusicBGCover: boolean = true //播放背景随封面
  75. @State sortType: number = 4 //默认排序方式
  76. @State isStartAutoPlay: boolean = false //启动后自动播放
  77. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  78. @State isShowSimi: boolean = false //是否显示私密音频
  79. @State isShowFAV: boolean = true //是否显示我的收藏
  80. @State isShowHistory: boolean = true //是否显示最近播放
  81. @State isCustomizeBg: boolean = false //自定义背景界面
  82. @State isCustomizeBgSheet: boolean = false //自定义背景界面
  83. @State blurValue: number = 0 //背景模糊
  84. @State bgBrightness: number = 0 //背景亮度
  85. @State isGridMusic: boolean = false //是否网格布局
  86. @State isScrollHide: boolean = false //是否滚动隐藏
  87. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  88. @State isSavePlayMode: boolean = true
  89. @State customizeBgPath: string | undefined = '';
  90. context = getContext(this);
  91. @State showCoverApiDialog: boolean = false
  92. @State tempCoverApiUrl: string = ''
  93. @State coverApiUrl: string = PreferencesUtil.getStringSync('COVER_API', '')
  94. @State apiDialogType: 'lyric' | 'cover' = 'lyric'
  95. @State themeMode: number = 0 // 0: 跟随系统, 1: 浅色, 2: 深色
  96. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  97. ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  98. @StorageLink('isDarkMode') isDarkMode: boolean = false // 是否启用深色模式
  99. static readonly iS_START_AUTO_PLAY: string = 'isStartAutoPlay';
  100. static readonly iS_MEMORY_LAST_PLAY: string = 'isMemoryLastPlay';
  101. /** 当前断点类型(如大屏/小屏) */
  102. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  103. @State verName: string = ''
  104. @StorageProp('themeColor') themeColor: string = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  105. @State showColorPicker: boolean = false
  106. @State customColor: string = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  107. @State isThemeSheet: boolean = false // 主题设置弹窗显示状态
  108. @State colorRows: Array<Array<ThemeColorItem>> = chunkArray(SettingPage.THEME_COLOR_LIST, 2);
  109. @State colorGroup: string = "group"
  110. apiDialogController: CustomDialogController = new CustomDialogController({
  111. builder: CustomContentDialog({
  112. primaryTitle: this.apiDialogType === 'lyric' ? '修改歌词API地址' : '修改封面API地址',
  113. contentBuilder: () => {
  114. this.buildApiDialogContent();
  115. },
  116. buttons: [
  117. {
  118. value: '取消',
  119. action: () => {
  120. this.apiDialogController.close();
  121. }
  122. },
  123. {
  124. value: '保存',
  125. action: () => {
  126. if (this.apiDialogType === 'lyric') {
  127. this.lyricApiUrl = this.tempApiUrl.trim()
  128. PreferencesUtil.put('LRC_API', this.lyricApiUrl)
  129. this.getUIContext().getPromptAction().showToast({
  130. message: '保存成功,当前LRC_API:' + this.lyricApiUrl,
  131. duration: 2000,
  132. showMode: promptAction.ToastShowMode.TOP_MOST,
  133. bottom: 85
  134. })
  135. } else {
  136. this.coverApiUrl = this.tempApiUrl.trim()
  137. PreferencesUtil.put('COVER_API', this.coverApiUrl)
  138. this.getUIContext().getPromptAction().showToast({
  139. message: '保存成功,当前COVER_API:' + this.coverApiUrl,
  140. duration: 2000,
  141. showMode: promptAction.ToastShowMode.TOP_MOST,
  142. bottom: 85
  143. })
  144. }
  145. this.apiDialogController.close();
  146. }
  147. }
  148. ]
  149. }),
  150. autoCancel: true,
  151. alignment: DialogAlignment.Center
  152. })
  153. @Builder
  154. buildApiDialogContent() {
  155. Column() {
  156. TextInput({
  157. text: this.tempApiUrl,
  158. placeholder: this.apiDialogType === 'lyric' ? '请输入歌词API地址' : '请输入封面API地址'
  159. })
  160. .onChange((val: string) => {
  161. this.tempApiUrl = val
  162. })
  163. .width('90%')
  164. .height(60)
  165. }
  166. .width('100%')
  167. }
  168. // 组件生命周期
  169. aboutToAppear() {
  170. this.isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN, true)
  171. this.isAutoRatate = PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_RATATE, true)
  172. this.isMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_PLAY, true)
  173. this.isMediacodec = PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN, false)
  174. this.isMusicMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)
  175. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  176. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  177. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  178. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  179. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  180. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  181. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  182. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, false)
  183. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  184. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  185. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  186. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  187. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  188. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  189. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  190. // 只用 themeMode 控制主题
  191. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  192. this.applyThemeMode(this.themeMode)
  193. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  194. AppStorage.setOrCreate('themeColor', themeColor);
  195. this.themeColor = themeColor;
  196. }
  197. // 监听颜色模式变化
  198. onColorModeChange(): void {
  199. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK;
  200. AppStorage.setOrCreate('isDarkMode', this.isDarkMode);
  201. }
  202. // 组件生命周期
  203. aboutToDisappear() {
  204. // 无需处理apiDialogController
  205. }
  206. applyThemeMode(mode: number) {
  207. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  208. if (mode === 1) {
  209. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  210. } else if (mode === 2) {
  211. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  212. }
  213. AppStorage.setOrCreate('currentColorMode', colorMode)
  214. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  215. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  216. AppStorage.setOrCreate('themeMode', mode)
  217. // 只有强制浅色/深色时才主动设置
  218. const context = getContext(this) as common.UIAbilityContext
  219. context.getApplicationContext().setColorMode(colorMode)
  220. }
  221. //是不是手机横屏
  222. isPhoneLan() {
  223. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  224. && this.currentBreakpoint !== BreakpointTypeEnum.SM) {
  225. if (DisplayUtil.getFoldStatus() === 0) {
  226. return true
  227. }
  228. }
  229. return false
  230. }
  231. @Builder
  232. pickerBuilder() {
  233. Column({ space: 20 }) {
  234. IBestColorPicker({
  235. value: this.customColor
  236. })
  237. Row({ space: 20 }) {
  238. IBestButton({
  239. text: "取消",
  240. btnBorderRadius:10,
  241. onBtnClick: () => {
  242. this.showColorPicker = false
  243. }
  244. })
  245. IBestButton({
  246. type: "primary",
  247. text: "确定",
  248. btnBorderRadius:10,
  249. onBtnClick: () => {
  250. this.themeColor = this.customColor
  251. PreferencesUtil.putSync(SettingPage.THEME_COLOR_KEY, this.customColor)
  252. AppStorage.setOrCreate('themeColor', this.customColor)
  253. this.sendChangeEvent()
  254. this.showColorPicker = false
  255. }
  256. })
  257. }
  258. }.padding(20)
  259. }
  260. @Builder
  261. themeSheetBuilder() {
  262. Column() {
  263. // 颜色模式分组卡片
  264. Column() {
  265. Row() {
  266. Row(){
  267. IBestIcon({ name: 'brush-o', color: this.themeColor , iconSize: 20 })
  268. .margin({ right: 8 })
  269. Text('颜色模式')
  270. .fontSize(15)
  271. .fontWeight(500)
  272. }
  273. .layoutWeight(1)
  274. Blank()
  275. Row(){
  276. IBestRadioGroup({ group: this.colorGroup, active: $themeMode, placeDirection: Axis.Horizontal }) {
  277. ForEach(['自动', '日间', '夜间'], (item: string, idx: number) => {
  278. Column() {
  279. IBestRadio({
  280. group: this.colorGroup,
  281. checkedColor: this.themeColor,
  282. label: '',
  283. name: idx
  284. })
  285. .margin({ left: 3 })
  286. Text(item)
  287. .fontSize(15)
  288. .fontColor($r('app.color.text_color'))
  289. .margin({ top: 6 })
  290. }
  291. .onClick(() => {
  292. this.themeMode = idx
  293. this.applyThemeMode(idx)
  294. this.sendChangeEvent()
  295. })
  296. .alignItems(HorizontalAlign.Center)
  297. })
  298. }
  299. }
  300. .margin({left:12,right:12})
  301. }
  302. }
  303. .backgroundColor($r('app.color.settings_background_main'))
  304. .borderRadius(18)
  305. .border({ width: 1, color: '#F0F0F0' })
  306. .shadow({
  307. radius: 12,
  308. color: 0x11000000,
  309. offsetX: 0,
  310. offsetY: 2
  311. })
  312. .margin({
  313. left: 0,
  314. right: 0,
  315. bottom: 20
  316. })
  317. .padding({ top: 18, bottom: 18, left: 20, right: 20 })
  318. .width('90%')
  319. // 主题色分组卡片
  320. Column() {
  321. Row() {
  322. Image($r('app.media.theme'))
  323. .width(20)
  324. .height(20)
  325. .fillColor(this.themeColor)
  326. Text('主题色')
  327. .fontSize(15)
  328. .fontWeight(500)
  329. .margin({ left: 8 })
  330. .layoutWeight(1)
  331. }
  332. .margin({left:20, top: 12 })
  333. Row(){
  334. Column() {
  335. ForEach(this.colorRows, (row: Array<ThemeColorItem>, rowIdx: number) => {
  336. Row() {
  337. ForEach(row, (item: ThemeColorItem, colIdx: number) => {
  338. Button() {
  339. Row() {
  340. Blank()
  341. .width(22)
  342. .height(22)
  343. .backgroundColor(item.name === '自定义' && this.isCustomThemeColor() ? this.themeColor : item.color)
  344. .border({ width: 2, color:$r('app.color.text_color')})
  345. .borderRadius(11)
  346. Text(item.name)
  347. .fontSize(15)
  348. .fontColor($r('app.color.text_color'))
  349. .margin({ left: 10 })
  350. }
  351. .alignItems(VerticalAlign.Center)
  352. .justifyContent(FlexAlign.Start)
  353. .layoutWeight(1)
  354. }
  355. .height(40)
  356. .layoutWeight(1)
  357. .backgroundColor(
  358. (item.name === '自定义' && this.isCustomThemeColor()) || this.themeColor === item.color
  359. ? this.themeColor
  360. : $r('app.color.settings_background_main')
  361. )
  362. .borderRadius(20)
  363. .onClick(() => {
  364. if (item.name === '自定义') {
  365. this.showColorPicker = true
  366. } else {
  367. this.themeColor = item.color
  368. PreferencesUtil.putSync(SettingPage.THEME_COLOR_KEY, item.color)
  369. AppStorage.setOrCreate('themeColor', item.color)
  370. this.sendChangeEvent()
  371. }
  372. })
  373. .margin({ right: colIdx === 0 ? '4%' : 20, bottom: 10, left: 20 })
  374. })
  375. }
  376. .justifyContent(FlexAlign.Start)
  377. })
  378. }
  379. .margin({ left: 12, right: 12, top: 12 })
  380. }
  381. }
  382. .width('90%')
  383. .backgroundColor($r('app.color.settings_background_main'))
  384. .borderRadius(18)
  385. .border({ width: 1, color: '#F0F0F0' })
  386. .shadow({
  387. radius: 12,
  388. color: 0x11000000,
  389. offsetX: 0,
  390. offsetY: 2
  391. })
  392. .margin({
  393. left: 0,
  394. right: 0,
  395. bottom: 18
  396. })
  397. .padding({ top: 18, bottom: 18, left: 0, right: 0 })
  398. // 主题色自定义弹窗
  399. IBestPopup({
  400. visible: $showColorPicker,
  401. popupWidth: 320,
  402. contentBuilder: (): void => this.pickerBuilder(),
  403. cornerRadius:20,
  404. })
  405. }
  406. .padding({ top: 8, bottom: 8, left: 18, right: 18 })
  407. .width('100%')
  408. .backgroundColor(Color.Transparent)
  409. .borderRadius(24)
  410. }
  411. build() {
  412. Column() {
  413. Column() {
  414. Line().width('100%').height('100%')
  415. }
  416. .height(this.isPhoneLan() ? 0 : px2vp(AppUtil.getStatusBarHeight()))
  417. .backgroundColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  418. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  419. // 自定义标题栏
  420. Stack() {
  421. // 居中标题
  422. Text('通用设置')
  423. .fontSize(20)
  424. .fontColor(Color.White)
  425. .align(Alignment.Center)
  426. // 左侧返回按钮
  427. Row() {
  428. Image($r('app.media.left_back_white'))
  429. .width(32)
  430. .height(32)
  431. .margin({ left: 12, right: 8 })
  432. .onClick(() => {
  433. router.back();
  434. })
  435. Blank().flexGrow(1)
  436. Blank().width(32)
  437. }
  438. .height(48)
  439. .width('100%')
  440. .alignItems(VerticalAlign.Center)
  441. }
  442. .height(48)
  443. .width('100%')
  444. .backgroundColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  445. Scroll() {
  446. Column() {
  447. // 主题设置分组
  448. Column() {
  449. Row() {
  450. Text('个性化')
  451. .margin({ left: 18, right: 20 })
  452. .fontSize(16)
  453. .fontColor(Color.Gray)
  454. .fontWeight(480)
  455. .layoutWeight(1)
  456. }
  457. .height(48)
  458. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  459. // 主题设置弹框入口
  460. Row() {
  461. Text('主题设置')
  462. .margin({ left: 18 })
  463. .fontSize(15)
  464. .fontColor(Color.Gray)
  465. .fontWeight(480)
  466. .layoutWeight(1)
  467. Image($r('app.media.arrow_right'))
  468. .width(22)
  469. .height(22)
  470. .margin({ right: 18 })
  471. }
  472. .height(55)
  473. .onClick(() => {
  474. this.showColorPicker = false;
  475. this.isThemeSheet = true;
  476. // 如果当前颜色是自定义,则同步到自定义色块
  477. // if (this.isCustomThemeColor()) {
  478. this.customColor = this.themeColor;
  479. // }
  480. })
  481. .bindSheet($$this.isThemeSheet, this.themeSheetBuilder(), {
  482. height: '95%',
  483. dragBar: true,
  484. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  485. showClose: true,
  486. blurStyle: BlurStyle.Thin,
  487. backgroundColor: Color.Transparent,
  488. title: { title: '主题设置' },
  489. shouldDismiss:(SheetDismiss:SheetDismiss)=>{
  490. SheetDismiss.dismiss();
  491. this.showColorPicker = false;
  492. }
  493. })
  494. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  495. Button({ type: ButtonType.Normal, stateEffect: true }) {
  496. Row() {
  497. Text('自定义背景')
  498. .margin({ left: 18 })
  499. .fontSize(15)
  500. .fontColor(Color.Gray)
  501. .fontWeight(480)
  502. .layoutWeight(1)
  503. .bindSheet($$this.isCustomizeBgSheet, this.customizeBgSheet(), {
  504. height: '95%',
  505. dragBar: true,
  506. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  507. showClose: true,
  508. blurStyle: BlurStyle.Thin,
  509. backgroundColor: Color.Transparent,
  510. title: { title: '自定义背景' }
  511. })
  512. Blank()
  513. // 右侧箭头
  514. Image($r('app.media.arrow_right'))
  515. .width(22)
  516. .height(22)
  517. .margin({ left: 20, right: 20 })
  518. .align(Alignment.Center)
  519. }
  520. }
  521. .height(55)
  522. .onClick(() => {
  523. this.isCustomizeBgSheet = !this.isCustomizeBgSheet;
  524. })
  525. .backgroundColor(Color.Transparent)
  526. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  527. // 滚动隐藏'
  528. Row() {
  529. Text('滚动隐藏')
  530. .margin({ left: 18 })
  531. .fontSize(15)
  532. .fontColor(Color.Gray)
  533. .fontWeight(480)
  534. .layoutWeight(1)
  535. Toggle({ type: ToggleType.Switch, isOn: this.isScrollHide })
  536. .selectedColor($r('app.color.tab_item_bg'))
  537. .switchPointColor(Color.White)
  538. .margin({ right: 18 })
  539. .onChange((checked: boolean) => {
  540. this.isScrollHide = checked;
  541. PreferencesUtil.put(SettingPage.IS_SCROLL_HIDE, this.isScrollHide)
  542. this.sendChangeEvent()
  543. })
  544. .width(50)
  545. .height(30);
  546. }
  547. .height(55)
  548. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  549. // 显示私密音频
  550. Row() {
  551. Text('网格布局')
  552. .margin({ left: 18 })
  553. .fontSize(15)
  554. .fontColor(Color.Gray)
  555. .fontWeight(480)
  556. .layoutWeight(1)
  557. Toggle({ type: ToggleType.Switch, isOn: this.isGridMusic })
  558. .selectedColor($r('app.color.tab_item_bg'))
  559. .switchPointColor(Color.White)
  560. .margin({ right: 18 })
  561. .onChange((checked: boolean) => {
  562. this.isGridMusic = checked;
  563. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  564. this.sendChangeEvent()
  565. })
  566. .width(50)
  567. .height(30);
  568. }
  569. .height(55)
  570. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  571. // 显示私密音频
  572. Row() {
  573. Text('显示私密音频')
  574. .margin({ left: 18 })
  575. .fontSize(15)
  576. .fontColor(Color.Gray)
  577. .fontWeight(480)
  578. .layoutWeight(1)
  579. Toggle({ type: ToggleType.Switch, isOn: this.isShowSimi })
  580. .selectedColor($r('app.color.tab_item_bg'))
  581. .switchPointColor(Color.White)
  582. .margin({ right: 18 })
  583. .onChange((checked: boolean) => {
  584. this.isShowSimi = checked;
  585. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isShowSimi)
  586. this.sendChangeEvent()
  587. })
  588. .width(50)
  589. .height(30);
  590. }
  591. .height(55)
  592. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  593. // 显示我的收藏
  594. Row() {
  595. Text('显示我的收藏')
  596. .margin({ left: 18 })
  597. .fontSize(15)
  598. .fontColor(Color.Gray)
  599. .fontWeight(480)
  600. .layoutWeight(1)
  601. Toggle({ type: ToggleType.Switch, isOn: this.isShowFAV })
  602. .selectedColor($r('app.color.tab_item_bg'))
  603. .switchPointColor(Color.White)
  604. .margin({ right: 18 })
  605. .onChange((checked: boolean) => {
  606. this.isShowFAV = checked;
  607. PreferencesUtil.put(SettingPage.IS_SHOW_FAV, this.isShowFAV)
  608. this.sendChangeEvent()
  609. })
  610. .width(50)
  611. .height(30);
  612. }
  613. .height(55)
  614. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  615. // 显示最近播放
  616. Row() {
  617. Text('显示最近播放')
  618. .margin({ left: 18 })
  619. .fontSize(15)
  620. .fontColor(Color.Gray)
  621. .fontWeight(480)
  622. .layoutWeight(1)
  623. Toggle({ type: ToggleType.Switch, isOn: this.isShowHistory })
  624. .selectedColor($r('app.color.tab_item_bg'))
  625. .switchPointColor(Color.White)
  626. .margin({ right: 18 })
  627. .onChange((checked: boolean) => {
  628. this.isShowHistory = checked;
  629. PreferencesUtil.put(SettingPage.IS_SHOW_HISTORY, this.isShowHistory)
  630. this.sendChangeEvent()
  631. })
  632. .width(50)
  633. .height(30);
  634. }
  635. .height(55)
  636. }
  637. .backgroundColor($r('app.color.settings_background_main'))
  638. .borderRadius(20)
  639. .margin({
  640. left: 0,
  641. right: 0,
  642. top: 0,
  643. bottom: 10
  644. })
  645. .padding(0)
  646. // 音频设置分组
  647. Column() {
  648. Row() {
  649. Text('音频设置')
  650. .margin({ left: 18, right: 20 })
  651. .fontSize(16)
  652. .fontColor(Color.Gray)
  653. .fontWeight(480)
  654. .layoutWeight(1)
  655. }
  656. .height(48)
  657. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  658. // 启动时播放
  659. Row() {
  660. Text('启动时播放')
  661. .margin({ left: 18 })
  662. .fontSize(15)
  663. .fontColor(Color.Gray)
  664. .fontWeight(480)
  665. .layoutWeight(1)
  666. Toggle({ type: ToggleType.Switch, isOn: this.isStartAutoPlay })
  667. .selectedColor($r('app.color.tab_item_bg'))
  668. .switchPointColor(Color.White)
  669. .margin({ right: 18 })
  670. .onChange((checked: boolean) => {
  671. this.isStartAutoPlay = checked;
  672. PreferencesUtil.put(SettingPage.iS_START_AUTO_PLAY, this.isStartAutoPlay)
  673. })
  674. .width(50)
  675. .height(30);
  676. }
  677. .height(55)
  678. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  679. // 记住播放进度
  680. Row() {
  681. Text('记住最后一首进度')
  682. .margin({ left: 18 })
  683. .fontSize(15)
  684. .fontColor(Color.Gray)
  685. .fontWeight(480)
  686. .layoutWeight(1)
  687. Toggle({ type: ToggleType.Switch, isOn: this.isMemoryLastPlay })
  688. .selectedColor($r('app.color.tab_item_bg'))
  689. .switchPointColor(Color.White)
  690. .margin({ right: 18 })
  691. .onChange((checked: boolean) => {
  692. this.isMemoryLastPlay = checked;
  693. PreferencesUtil.put(SettingPage.iS_MEMORY_LAST_PLAY, this.isMemoryLastPlay)
  694. this.sendChangeEvent()
  695. })
  696. .width(50)
  697. .height(30);
  698. }
  699. .height(55)
  700. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  701. // 记忆播放
  702. Row() {
  703. Text('记忆播放')
  704. .margin({ left: 18 })
  705. .fontSize(15)
  706. .fontColor(Color.Gray)
  707. .fontWeight(480)
  708. .layoutWeight(1)
  709. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  710. .selectedColor($r('app.color.tab_item_bg'))
  711. .switchPointColor(Color.White)
  712. .margin({ right: 18 })
  713. .onChange((checked: boolean) => {
  714. this.isMusicMemoryPlay = checked;
  715. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  716. this.sendChangeEvent()
  717. })
  718. .width(50)
  719. .height(30);
  720. }
  721. .height(55)
  722. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  723. // 默认排序模式
  724. Row() {
  725. Text('默认排序模式')
  726. .margin({ left: 18 })
  727. .fontSize(15)
  728. .fontColor(Color.Gray)
  729. .fontWeight(480)
  730. .layoutWeight(1)
  731. Select([
  732. { value: CommonConstants.SORT_ARRAY[0] },
  733. { value: CommonConstants.SORT_ARRAY[1] },
  734. { value: CommonConstants.SORT_ARRAY[2] },
  735. { value: CommonConstants.SORT_ARRAY[3] },
  736. { value: CommonConstants.SORT_ARRAY[4] },
  737. { value: CommonConstants.SORT_ARRAY[5] },
  738. { value: CommonConstants.SORT_ARRAY[6] },
  739. { value: CommonConstants.SORT_ARRAY[7] }])
  740. .font({ size: 15, weight: FontWeight.Medium })
  741. .fontColor(Color.Gray)
  742. .margin({ right: 18 })
  743. .selected(this.sortType)
  744. .value(CommonConstants.SORT_ARRAY[this.sortType])
  745. .onSelect(async (_index: number, text?: string | undefined) => {
  746. this.sortType = _index
  747. PreferencesUtil.put(SettingPage.SORT_TYPE, this.sortType)
  748. this.sendChangeEvent()
  749. })
  750. }
  751. .height(55)
  752. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  753. .visibility(Visibility.None)
  754. // 默认排序模式
  755. Row() {
  756. Text('保存播放模式')
  757. .margin({ left: 18 })
  758. .fontSize(15)
  759. .fontColor(Color.Gray)
  760. .fontWeight(480)
  761. .layoutWeight(1)
  762. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  763. .selectedColor($r('app.color.tab_item_bg'))
  764. .switchPointColor(Color.White)
  765. .margin({ right: 18 })
  766. .onChange((checked: boolean) => {
  767. this.isSavePlayMode = checked;
  768. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  769. })
  770. .width(50)
  771. .height(30);
  772. }
  773. .height(55)
  774. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  775. .visibility(Visibility.None)
  776. Row() {
  777. Text('与其他应用同时播放')
  778. .margin({ left: 18 })
  779. .fontSize(15)
  780. .fontColor(Color.Gray)
  781. .fontWeight(480)
  782. .layoutWeight(1)
  783. Toggle({ type: ToggleType.Switch, isOn: this.isSameTimePlay })
  784. .selectedColor($r('app.color.tab_item_bg'))
  785. .switchPointColor(Color.White)
  786. .margin({ right: 18 })
  787. .onChange((checked: boolean) => {
  788. this.isSameTimePlay = checked;
  789. PreferencesUtil.put(SettingPage.IS_SAMETIME_PLAY, this.isSameTimePlay)
  790. })
  791. .width(50)
  792. .height(30);
  793. }
  794. .height(55)
  795. .visibility(Visibility.None)
  796. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  797. // 播放背景随音乐封面
  798. Row() {
  799. Text('播放背景随音乐封面')
  800. .margin({ left: 18 })
  801. .fontSize(15)
  802. .fontColor(Color.Gray)
  803. .fontWeight(480)
  804. .layoutWeight(1)
  805. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  806. .selectedColor($r('app.color.tab_item_bg'))
  807. .switchPointColor(Color.White)
  808. .margin({ right: 18 })
  809. .onChange((checked: boolean) => {
  810. this.isMusicBGCover = checked;
  811. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  812. })
  813. .width(50)
  814. .height(30);
  815. }
  816. .height(55)
  817. }
  818. .backgroundColor($r('app.color.settings_background_main'))
  819. .borderRadius(20)
  820. .margin({
  821. left: 0,
  822. right: 0,
  823. top: 10,
  824. bottom: 10
  825. })
  826. .padding(0)
  827. // API设置分组
  828. Column() {
  829. Row() {
  830. Text('API设置')
  831. .margin({ left: 18, right: 20 })
  832. .fontSize(16)
  833. .fontColor(Color.Gray)
  834. .fontWeight(480)
  835. .layoutWeight(1)
  836. }
  837. .height(48)
  838. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  839. // 歌词API
  840. Row() {
  841. Text('歌词:')
  842. .margin({ left: 18, right: 6 })
  843. .fontSize(15)
  844. .fontColor(Color.Gray)
  845. Text(this.lyricApiUrl)
  846. .margin({ right: 10 })
  847. .fontSize(15)
  848. .fontColor(Color.Gray)
  849. .layoutWeight(1)
  850. Image(this.isDarkMode ? $r('app.media.rename2') : $r('app.media.ic_public_edit'))
  851. .width(22)
  852. .height(22)
  853. .margin({ right: 18 })
  854. }
  855. .onClick(() => {
  856. this.apiDialogType = 'lyric'
  857. this.tempApiUrl = this.lyricApiUrl
  858. this.apiDialogController.open()
  859. })
  860. .height(55)
  861. // 封面API
  862. Row() {
  863. Text('封面:')
  864. .margin({ left: 18, right: 6 })
  865. .fontSize(15)
  866. .fontColor(Color.Gray)
  867. Text(this.coverApiUrl)
  868. .margin({ right: 10 })
  869. .fontSize(15)
  870. .fontColor(Color.Gray)
  871. .layoutWeight(1)
  872. Image(this.isDarkMode ? $r('app.media.rename2') : $r('app.media.ic_public_edit'))
  873. .width(22)
  874. .height(22)
  875. .margin({ right: 18 })
  876. }
  877. .onClick(() => {
  878. this.apiDialogType = 'cover'
  879. this.tempApiUrl = this.coverApiUrl
  880. this.apiDialogController.open()
  881. })
  882. .justifyContent(FlexAlign.Center)
  883. .height(55)
  884. }
  885. .backgroundColor($r('app.color.settings_background_main'))
  886. .borderRadius(20)
  887. .margin({
  888. left: 0,
  889. right: 0,
  890. top: 10,
  891. bottom: 20
  892. })
  893. .padding(0)
  894. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  895. Column() {
  896. Row() {
  897. Text('设置教程:')
  898. .margin({ left: 18 })
  899. .fontSize(15)
  900. .fontColor(Color.Gray)
  901. .fontWeight(480)
  902. Text('点击进Q群讨论')
  903. .margin({ right: 10 })
  904. .fontSize(15)
  905. .fontColor(Color.Gray)
  906. .layoutWeight(1)
  907. Blank()
  908. // 右侧箭头
  909. Image($r('app.media.arrow_right'))
  910. .width(22)
  911. .height(22)
  912. .margin({ left: 20, right: 20 })
  913. .align(Alignment.Center)
  914. }
  915. .height(55)
  916. }
  917. }
  918. .onClick(() => {
  919. const qqUrl = `mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${CommonConstants.QQ_GROUP}&card_type=group&source=external`;
  920. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  921. context.openLink(qqUrl, {})
  922. })
  923. .backgroundColor($r('app.color.settings_background_main'))
  924. .borderRadius(15)
  925. .margin({ top: 0, bottom: 20 })
  926. .padding(0)
  927. //空白
  928. Column() {
  929. Blank()
  930. .height(88)
  931. }.height(88)
  932. }
  933. .margin({
  934. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 35 : 20,
  935. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 35 : 20,
  936. top: 20,
  937. bottom: 20
  938. })
  939. .justifyContent(FlexAlign.Start)
  940. }
  941. .scrollBar(BarState.Auto)
  942. .height(px2vp(DisplayUtil.getHeight() - AppUtil.getStatusBarHeight() - AppUtil.getNavigationIndicatorHeight()))
  943. .width('100%')
  944. .margin({ bottom: 10 })
  945. .backgroundColor($r('app.color.settings_background'))
  946. }
  947. .height('100%')
  948. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  949. }
  950. //发送广播通知更新UI
  951. sendChangeEvent() {
  952. const eventData: emitter.EventData = {};
  953. emitter.emit({ eventId: 333 }, eventData); // 发送广播通知更新doSwipBack
  954. }
  955. goSelectImage() {
  956. let selectUris: Array<string> = [];
  957. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  958. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  959. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
  960. photoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目
  961. photoPicker.select(photoSelectOptions).then(async (photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
  962. //用一个全局变量存储返回的uri
  963. selectUris = photoSelectResult.photoUris;
  964. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  965. //使用fs.openSync接口,通过uri打开这个文件得到fd
  966. let file = fileIo.openSync(selectUris[0], fileIo.OpenMode.READ_ONLY);
  967. console.info('file fd: ' + file.fd);
  968. const timestamp: number = Math.floor(Date.now() / 1000);
  969. let name = timestamp + "_homebg"
  970. let imagePath = this.context.filesDir + FileUtil.separator + name
  971. imagePath = fileUri.getUriFromPath(imagePath)
  972. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  973. fileIo.copyFileSync(file.fd, file2.fd)
  974. fileIo.closeSync(file);
  975. fileIo.closeSync(file2);
  976. this.customizeBgPath = imagePath
  977. PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG_PATH, this.customizeBgPath)
  978. this.sendChangeEvent()
  979. }).catch((err: BusinessError) => {
  980. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  981. })
  982. }
  983. @Builder
  984. customizeBgSheet() {
  985. Scroll() {
  986. Column() {
  987. this.CustomizeBg()
  988. }
  989. }
  990. .width('100%')
  991. .height('100%')
  992. }
  993. @Builder
  994. CustomizeBg() {
  995. Column() {
  996. Image(this.customizeBgPath)
  997. .height('42%')
  998. .alt($r('app.color.white'))
  999. .objectFit(ImageFit.Contain)
  1000. .borderRadius(20)
  1001. .clip(true)
  1002. .blur(this.blurValue)
  1003. .brightness(this.bgBrightness + 0.8)
  1004. .margin({ left: 30, right: 30, bottom: 20 })
  1005. Row() {
  1006. Row() {
  1007. Button('选择图片')
  1008. .fontColor(Color.White)
  1009. .fontSize(12)
  1010. .height(48)
  1011. .width(100)
  1012. .backgroundColor($r('app.color.title_bar_bg'))
  1013. .stateEffect(true)
  1014. .onClick(async () => {
  1015. this.goSelectImage()
  1016. })
  1017. }
  1018. .height('100%')
  1019. .justifyContent(FlexAlign.Center)
  1020. .layoutWeight(1)
  1021. }
  1022. .width('100%')
  1023. .height(58)
  1024. .margin({ bottom: 20 })
  1025. Column() {
  1026. Row() {
  1027. Text('自定义背景:')
  1028. .margin({ left: 18 })
  1029. .fontSize(15)
  1030. .fontColor($r('app.color.text_color'))
  1031. .fontWeight(480)
  1032. .layoutWeight(1)
  1033. Toggle({ type: ToggleType.Switch, isOn: this.isCustomizeBg })
  1034. .selectedColor($r('app.color.tab_item_bg'))
  1035. .switchPointColor(Color.White)
  1036. .margin({ right: 18 })
  1037. .onChange((checked: boolean) => {
  1038. this.isCustomizeBg = checked;
  1039. PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG, this.isCustomizeBg)
  1040. this.sendChangeEvent()
  1041. })
  1042. .width(50)
  1043. .height(30);
  1044. }
  1045. .height(55)
  1046. }
  1047. .backgroundColor($r('app.color.settings_background_main'))
  1048. .borderRadius(15)
  1049. .margin({
  1050. left: 30,
  1051. right: 30,
  1052. top: 0,
  1053. bottom: 20
  1054. })
  1055. .padding(0)
  1056. Column() {
  1057. Row() {
  1058. Text('背景模糊:')
  1059. .margin({ left: 18 })
  1060. .fontSize(15)
  1061. .fontColor($r('app.color.text_color'))
  1062. .fontWeight(480)
  1063. Slider({
  1064. value: this.blurValue,
  1065. min: 0,
  1066. max: 100,
  1067. step: 1,
  1068. style: SliderStyle.OutSet
  1069. })
  1070. .blockColor(Color.Red)
  1071. .trackColor($r('app.color.speed_text_color'))
  1072. .selectedColor($r('app.color.index_background'))
  1073. .trackThickness(8)
  1074. .onChange((value: number) => {
  1075. this.blurValue = value;
  1076. PreferencesUtil.put(SettingPage.CUSTOMIZE_BG_BLUR, this.blurValue)
  1077. this.sendChangeEvent()
  1078. })
  1079. .layoutWeight(1)
  1080. }
  1081. .height(55)
  1082. }
  1083. .backgroundColor($r('app.color.settings_background_main'))
  1084. .borderRadius(15)
  1085. .margin({
  1086. left: 30,
  1087. right: 30,
  1088. top: 0,
  1089. bottom: 20
  1090. })
  1091. .padding(0)
  1092. Column() {
  1093. Row() {
  1094. Text('背景亮度:')
  1095. .margin({ left: 18 })
  1096. .fontSize(15)
  1097. .fontColor($r('app.color.text_color'))
  1098. .fontWeight(480)
  1099. Slider({
  1100. value: this.bgBrightness,
  1101. min: -0.4,
  1102. max: 0.4,
  1103. step: 0.1,
  1104. style: SliderStyle.OutSet
  1105. })
  1106. .blockColor(Color.Red)
  1107. .trackColor($r('app.color.speed_text_color'))
  1108. .selectedColor($r('app.color.index_background'))
  1109. .trackThickness(8)
  1110. .onChange((value: number) => {
  1111. this.bgBrightness = value;
  1112. PreferencesUtil.put(SettingPage.BG_BRIGHTNESS, this.bgBrightness)
  1113. this.sendChangeEvent()
  1114. })
  1115. .layoutWeight(1)
  1116. }
  1117. .height(55)
  1118. }
  1119. .backgroundColor($r('app.color.settings_background_main'))
  1120. .borderRadius(15)
  1121. .margin({
  1122. left: 30,
  1123. right: 30,
  1124. top: 0,
  1125. bottom: 20
  1126. })
  1127. .padding(0)
  1128. }
  1129. .margin({ bottom: 30 })
  1130. }
  1131. // 判断当前主题色是否为自定义色
  1132. isCustomThemeColor(): boolean {
  1133. for (let i = 0; i < SettingPage.THEME_COLOR_LIST.length - 1; i++) {
  1134. if (SettingPage.THEME_COLOR_LIST[i].color === this.themeColor) {
  1135. return false;
  1136. }
  1137. }
  1138. return true;
  1139. }
  1140. }
  1141. // 主题色类型声明
  1142. export interface ThemeColorItem {
  1143. name: string;
  1144. color: string;
  1145. }
  1146. // 工具函数:将一维数组分成每行2个的二维数组
  1147. function chunkArray<T>(arr: Array<T>, size: number): Array<Array<T>> {
  1148. const result: Array<Array<T>> = [];
  1149. for (let i = 0; i < arr.length; i += size) {
  1150. const row: Array<T> = [];
  1151. for (let j = 0; j < size; j++) {
  1152. if (i + j < arr.length) {
  1153. row.push(arr[i + j]);
  1154. }
  1155. }
  1156. result.push(row);
  1157. }
  1158. return result;
  1159. }