SettingPage.ets 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. @Preview
  14. @Entry
  15. @Component
  16. export struct SettingPage {
  17. @State showApiDialog: boolean = false
  18. @State tempApiUrl: string = ''
  19. @State lyricApiUrl: string = PreferencesUtil.getStringSync('LRC_API', '')
  20. @State isBgPlayOpen: boolean = true //是否启用后台播放
  21. @State isAutoRatate: boolean = true //是否启用自动横竖屏
  22. @State isMemoryPlay: boolean = true //是否启用记忆播放
  23. @State isMediacodec: boolean = false //是否启用硬件解码
  24. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  25. @State isMusicBGCover: boolean = true //播放背景随封面
  26. @State sortType: number = 4 //默认排序方式
  27. @State isShowSimi:boolean = false //是否显示私密音频
  28. @State isShowFAV:boolean = true //是否显示我的收藏
  29. @State isShowHistory:boolean = true //是否显示最近播放
  30. @State isCustomizeBg: boolean = false //自定义背景界面
  31. @State isCustomizeBgSheet: boolean = false //自定义背景界面
  32. @State blurValue: number = 0 //背景模糊
  33. @State bgBrightness: number = 0 //背景亮度
  34. @State isGridMusic: boolean = false //是否网格布局
  35. @State isScrollHide: boolean = false //是否滚动隐藏
  36. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  37. @State isSavePlayMode: boolean = true
  38. @State customizeBgPath: string | undefined = '';
  39. context = getContext(this);
  40. @State showCoverApiDialog: boolean = false
  41. @State tempCoverApiUrl: string = ''
  42. @State coverApiUrl: string = PreferencesUtil.getStringSync('COVER_API', '')
  43. @State apiDialogType: 'lyric' | 'cover' = 'lyric'
  44. @State themeMode: number = 0 // 0: 跟随系统, 1: 浅色, 2: 深色
  45. static readonly THEME_MODE: string = 'themeMode';
  46. static readonly SORT_TYPE: string = 'musicSortType';
  47. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  48. @StorageLink('isDarkMode') isDarkMode: boolean = false // 是否启用深色模式
  49. static readonly IS_BGPLAY_OPEN: string = 'isBgPlayOpen';
  50. static readonly IS_AUTO_RATATE: string = 'isAutoRatate';
  51. static readonly iS_MEMORY_PLAY: string = 'isMemoryPlay';
  52. static readonly IS_MIDIACODEC_OPEN: string = 'isMediacodec';
  53. static readonly iS_MUSIC_MEMORY_PLAY: string = 'isMusicMemoryPlay';
  54. static readonly iS_MUSIC_BG_COVER: string = 'isMusicBGCover';
  55. static readonly iS_SAVE_PLAY_MODE: string = 'isSavePlayMode';
  56. static readonly IS_COVER_RECTANGLE: string = 'isCoverRectangle'; //封面圆形或者方形
  57. static readonly IS_SHOW_SIMI: string = 'isShowSimi';
  58. static readonly IS_SHOW_FAV: string = 'isShowFAV';
  59. static readonly IS_SHOW_HISTORY: string = 'isShowHistory';
  60. static readonly IS_CUSTOMIZE_BG: string = 'is_customize_bg';
  61. static readonly IS_GRID_MUSIC: string = 'is_grid_music';
  62. static readonly IS_CUSTOMIZE_BG_PATH: string = 'is_customize_bg_path';
  63. static readonly IS_SCROLL_HIDE: string = 'isScrollHide';
  64. static readonly IS_SAMETIME_PLAY: string = 'isSameTimePlay';
  65. static readonly CUSTOMIZE_BG_BLUR: string = 'customize_bg_blur';
  66. static readonly BG_BRIGHTNESS: string = 'bg_brightness';
  67. /** 当前断点类型(如大屏/小屏) */
  68. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  69. @State verName: string = ''
  70. @StorageProp('themeColor') themeColor: string = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  71. apiDialogController: CustomDialogController = new CustomDialogController({
  72. builder: CustomContentDialog({
  73. primaryTitle: this.apiDialogType === 'lyric' ? '修改歌词API地址' : '修改封面API地址',
  74. contentBuilder: () => {
  75. this.buildApiDialogContent();
  76. },
  77. buttons: [
  78. {
  79. value: '取消',
  80. action: () => {
  81. this.apiDialogController.close();
  82. }
  83. },
  84. {
  85. value: '保存',
  86. action: () => {
  87. if (this.apiDialogType === 'lyric') {
  88. this.lyricApiUrl = this.tempApiUrl.trim()
  89. PreferencesUtil.put('LRC_API', this.lyricApiUrl)
  90. this.getUIContext().getPromptAction().showToast({
  91. message: '保存成功,当前LRC_API:' + this.lyricApiUrl,
  92. duration: 2000,
  93. showMode: promptAction.ToastShowMode.TOP_MOST,
  94. bottom: 85
  95. })
  96. } else {
  97. this.coverApiUrl = this.tempApiUrl.trim()
  98. PreferencesUtil.put('COVER_API', this.coverApiUrl)
  99. this.getUIContext().getPromptAction().showToast({
  100. message: '保存成功,当前COVER_API:' + this.coverApiUrl,
  101. duration: 2000,
  102. showMode: promptAction.ToastShowMode.TOP_MOST,
  103. bottom: 85
  104. })
  105. }
  106. this.apiDialogController.close();
  107. }
  108. }
  109. ]
  110. }),
  111. autoCancel: true,
  112. alignment: DialogAlignment.Center
  113. })
  114. @Builder
  115. buildApiDialogContent() {
  116. Column() {
  117. TextInput({ text: this.tempApiUrl, placeholder: this.apiDialogType === 'lyric' ? '请输入歌词API地址' : '请输入封面API地址' })
  118. .onChange((val: string) => {
  119. this.tempApiUrl = val
  120. })
  121. .width('90%')
  122. .height(60)
  123. }
  124. .width('100%')
  125. }
  126. // 组件生命周期
  127. aboutToAppear() {
  128. this.isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN, true)
  129. this.isAutoRatate = PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_RATATE, true)
  130. this.isMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_PLAY, true)
  131. this.isMediacodec = PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN, false)
  132. this.isMusicMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)
  133. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  134. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  135. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  136. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  137. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  138. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  139. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  140. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, false)
  141. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  142. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  143. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  144. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  145. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  146. // 只用 themeMode 控制主题
  147. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  148. this.applyThemeMode(this.themeMode)
  149. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  150. AppStorage.setOrCreate('themeColor', themeColor);
  151. this.themeColor = themeColor;
  152. }
  153. // 监听颜色模式变化
  154. onColorModeChange(): void {
  155. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK;
  156. AppStorage.setOrCreate('isDarkMode', this.isDarkMode);
  157. }
  158. // 组件生命周期
  159. aboutToDisappear() {
  160. // 无需处理apiDialogController
  161. }
  162. applyThemeMode(mode: number) {
  163. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  164. if (mode === 1) {
  165. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  166. } else if (mode === 2) {
  167. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  168. }
  169. AppStorage.setOrCreate('currentColorMode', colorMode)
  170. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  171. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  172. AppStorage.setOrCreate('themeMode', mode)
  173. // 只有强制浅色/深色时才主动设置
  174. const context = getContext(this) as common.UIAbilityContext
  175. context.getApplicationContext().setColorMode(colorMode)
  176. }
  177. //是不是手机横屏
  178. isPhoneLan() {
  179. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  180. && this.currentBreakpoint !== BreakpointTypeEnum.SM) {
  181. if (DisplayUtil.getFoldStatus() === 0 ) {
  182. return true
  183. }
  184. }
  185. return false
  186. }
  187. build() {
  188. Column() {
  189. Column(){
  190. Line().width('100%').height('100%')
  191. }
  192. .height(this.isPhoneLan()?0:px2vp(AppUtil.getStatusBarHeight()))
  193. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  194. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  195. // 自定义标题栏
  196. Stack() {
  197. // 居中标题
  198. Text('通用设置')
  199. .fontSize(20)
  200. .fontColor(Color.White)
  201. .align(Alignment.Center)
  202. // 左侧返回按钮
  203. Row() {
  204. Image($r('app.media.left_back_white'))
  205. .width(32)
  206. .height(32)
  207. .margin({ left: 12, right: 8 })
  208. .onClick(() => {
  209. router.back();
  210. })
  211. Blank().flexGrow(1)
  212. Blank().width(32)
  213. }
  214. .height(48)
  215. .width('100%')
  216. .alignItems(VerticalAlign.Center)
  217. }
  218. .height(48)
  219. .width('100%')
  220. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  221. Scroll() {
  222. Column() {
  223. // 主题设置分组
  224. Column() {
  225. Row() {
  226. Text('个性化')
  227. .margin({ left: 18, right: 20 })
  228. .fontSize(16)
  229. .fontColor(Color.Gray)
  230. .fontWeight(480)
  231. .layoutWeight(1)
  232. }
  233. .height(48)
  234. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  235. Row() {
  236. Text('主题模式')
  237. .margin({ left: 18 })
  238. .fontSize(15)
  239. .fontColor(Color.Gray)
  240. .fontWeight(480)
  241. .layoutWeight(1)
  242. Select([
  243. { value: '跟随系统' },
  244. { value: '浅色' },
  245. { value: '深色' }
  246. ])
  247. .font({ size: 15, weight: FontWeight.Medium })
  248. .fontColor(Color.Gray)
  249. .margin({ right: 18 })
  250. .selected(this.themeMode)
  251. .value(['跟随系统', '浅色', '深色'][this.themeMode])
  252. .onSelect((_index: number) => {
  253. this.themeMode = _index
  254. this.applyThemeMode(_index)
  255. this.getUIContext().getPromptAction().showToast({
  256. message: ['已切换为跟随系统', '已切换为浅色', '已切换为深色'][_index],
  257. duration: 2000,
  258. showMode: promptAction.ToastShowMode.TOP_MOST,
  259. bottom: 85
  260. })
  261. this.sendChangeEvent()
  262. })
  263. }
  264. .height(55)
  265. // 主题色选择
  266. Row() {
  267. Text('主题色')
  268. .margin({ left: 18 })
  269. .fontSize(15)
  270. .fontColor(Color.Gray)
  271. .fontWeight(480)
  272. .layoutWeight(1)
  273. Row() {
  274. ForEach(SettingPage.THEME_COLOR_LIST, (color: string, index: number) => {
  275. Blank()
  276. .width(32)
  277. .height(32)
  278. .backgroundColor(color)
  279. .borderRadius(16)
  280. .border({ width: this.themeColor === color ? 3 : 1, color: this.themeColor === color ? Color.Black : Color.Gray })
  281. .margin({ right: 8 })
  282. .onClick(() => {
  283. this.themeColor = color
  284. PreferencesUtil.putSync(SettingPage.THEME_COLOR_KEY, color)
  285. AppStorage.setOrCreate('themeColor', color)
  286. this.sendChangeEvent()
  287. })
  288. })
  289. }
  290. .margin({ right: 18 })
  291. }
  292. .height(55)
  293. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  294. Row() {
  295. Text('自定义背景')
  296. .margin({ left: 18 })
  297. .fontSize(15)
  298. .fontColor(Color.Gray)
  299. .fontWeight(480)
  300. .layoutWeight(1)
  301. .bindSheet($$this.isCustomizeBgSheet, this.customizeBgSheet(), {
  302. height: '90%',
  303. dragBar: true,
  304. preferType: this.currentBreakpoint!==BreakpointTypeEnum.SM?SheetType.CENTER:SheetType.BOTTOM,
  305. showClose: true,
  306. blurStyle: BlurStyle.Thin,
  307. backgroundColor: Color.Transparent,
  308. title: { title: '自定义背景' }
  309. })
  310. Blank()
  311. // 右侧箭头
  312. Image($r('app.media.arrow_right'))
  313. .width(22)
  314. .height(22)
  315. .margin({ left: 20, right: 20 })
  316. .align(Alignment.Center)
  317. }
  318. .height(55)
  319. .onClick(() => {
  320. this.isCustomizeBgSheet = !this.isCustomizeBgSheet;
  321. })
  322. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  323. // 滚动隐藏'
  324. Row() {
  325. Text('滚动隐藏')
  326. .margin({ left: 18 })
  327. .fontSize(15)
  328. .fontColor(Color.Gray)
  329. .fontWeight(480)
  330. .layoutWeight(1)
  331. Toggle({ type: ToggleType.Switch, isOn: this.isScrollHide })
  332. .selectedColor($r('app.color.tab_item_bg'))
  333. .switchPointColor(Color.White)
  334. .margin({ right: 18 })
  335. .onChange((checked: boolean) => {
  336. this.isScrollHide = checked;
  337. PreferencesUtil.put(SettingPage.IS_SCROLL_HIDE, this.isScrollHide)
  338. this.sendChangeEvent()
  339. })
  340. .width(50)
  341. .height(30);
  342. }
  343. .height(55)
  344. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  345. // 显示私密音频
  346. Row() {
  347. Text('网格布局')
  348. .margin({ left: 18 })
  349. .fontSize(15)
  350. .fontColor(Color.Gray)
  351. .fontWeight(480)
  352. .layoutWeight(1)
  353. Toggle({ type: ToggleType.Switch, isOn: this.isGridMusic })
  354. .selectedColor($r('app.color.tab_item_bg'))
  355. .switchPointColor(Color.White)
  356. .margin({ right: 18 })
  357. .onChange((checked: boolean) => {
  358. this.isGridMusic = checked;
  359. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  360. this.sendChangeEvent()
  361. })
  362. .width(50)
  363. .height(30);
  364. }
  365. .height(55)
  366. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  367. // 显示私密音频
  368. Row() {
  369. Text('显示私密音频')
  370. .margin({ left: 18 })
  371. .fontSize(15)
  372. .fontColor(Color.Gray)
  373. .fontWeight(480)
  374. .layoutWeight(1)
  375. Toggle({ type: ToggleType.Switch, isOn: this.isShowSimi })
  376. .selectedColor($r('app.color.tab_item_bg'))
  377. .switchPointColor(Color.White)
  378. .margin({ right: 18 })
  379. .onChange((checked: boolean) => {
  380. this.isShowSimi = checked;
  381. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isShowSimi)
  382. this.sendChangeEvent()
  383. })
  384. .width(50)
  385. .height(30);
  386. }
  387. .height(55)
  388. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  389. // 显示我的收藏
  390. Row() {
  391. Text('显示我的收藏')
  392. .margin({ left: 18 })
  393. .fontSize(15)
  394. .fontColor(Color.Gray)
  395. .fontWeight(480)
  396. .layoutWeight(1)
  397. Toggle({ type: ToggleType.Switch, isOn: this.isShowFAV })
  398. .selectedColor($r('app.color.tab_item_bg'))
  399. .switchPointColor(Color.White)
  400. .margin({ right: 18 })
  401. .onChange((checked: boolean) => {
  402. this.isShowFAV = checked;
  403. PreferencesUtil.put(SettingPage.IS_SHOW_FAV, this.isShowFAV)
  404. this.sendChangeEvent()
  405. })
  406. .width(50)
  407. .height(30);
  408. }
  409. .height(55)
  410. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  411. // 显示最近播放
  412. Row() {
  413. Text('显示最近播放')
  414. .margin({ left: 18 })
  415. .fontSize(15)
  416. .fontColor(Color.Gray)
  417. .fontWeight(480)
  418. .layoutWeight(1)
  419. Toggle({ type: ToggleType.Switch, isOn: this.isShowHistory })
  420. .selectedColor($r('app.color.tab_item_bg'))
  421. .switchPointColor(Color.White)
  422. .margin({ right: 18 })
  423. .onChange((checked: boolean) => {
  424. this.isShowHistory = checked;
  425. PreferencesUtil.put(SettingPage.IS_SHOW_HISTORY, this.isShowHistory)
  426. this.sendChangeEvent()
  427. })
  428. .width(50)
  429. .height(30);
  430. }
  431. .height(55)
  432. }
  433. .backgroundColor($r('app.color.settings_background_main'))
  434. .borderRadius(20)
  435. .margin({ left: 0, right: 0, top: 0, bottom: 10 })
  436. .padding(0)
  437. // 音频设置分组
  438. Column() {
  439. Row() {
  440. Text('音频设置')
  441. .margin({ left: 18, right: 20 })
  442. .fontSize(16)
  443. .fontColor(Color.Gray)
  444. .fontWeight(480)
  445. .layoutWeight(1)
  446. }
  447. .height(48)
  448. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  449. // 记忆播放
  450. Row() {
  451. Text('记忆播放')
  452. .margin({ left: 18 })
  453. .fontSize(15)
  454. .fontColor(Color.Gray)
  455. .fontWeight(480)
  456. .layoutWeight(1)
  457. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  458. .selectedColor($r('app.color.tab_item_bg'))
  459. .switchPointColor(Color.White)
  460. .margin({ right: 18 })
  461. .onChange((checked: boolean) => {
  462. this.isMusicMemoryPlay = checked;
  463. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  464. })
  465. .width(50)
  466. .height(30);
  467. }
  468. .height(55)
  469. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  470. // 默认排序模式
  471. Row() {
  472. Text('默认排序模式')
  473. .margin({ left: 18 })
  474. .fontSize(15)
  475. .fontColor(Color.Gray)
  476. .fontWeight(480)
  477. .layoutWeight(1)
  478. Select([
  479. { value: CommonConstants.SORT_ARRAY[0] },
  480. { value: CommonConstants.SORT_ARRAY[1] },
  481. { value: CommonConstants.SORT_ARRAY[2] },
  482. { value: CommonConstants.SORT_ARRAY[3] },
  483. { value: CommonConstants.SORT_ARRAY[4] },
  484. { value: CommonConstants.SORT_ARRAY[5] },
  485. { value: CommonConstants.SORT_ARRAY[6] },
  486. { value: CommonConstants.SORT_ARRAY[7] }])
  487. .font({ size: 15, weight: FontWeight.Medium })
  488. .fontColor(Color.Gray)
  489. .margin({ right: 18 })
  490. .selected(this.sortType)
  491. .value(CommonConstants.SORT_ARRAY[this.sortType])
  492. .onSelect(async (_index: number, text?: string | undefined) => {
  493. this.sortType = _index
  494. PreferencesUtil.put(SettingPage.SORT_TYPE, this.sortType)
  495. this.sendChangeEvent()
  496. })
  497. }
  498. .height(55)
  499. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  500. .visibility(Visibility.None)
  501. // 默认排序模式
  502. Row() {
  503. Text('保存播放模式')
  504. .margin({ left: 18 })
  505. .fontSize(15)
  506. .fontColor(Color.Gray)
  507. .fontWeight(480)
  508. .layoutWeight(1)
  509. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  510. .selectedColor($r('app.color.tab_item_bg'))
  511. .switchPointColor(Color.White)
  512. .margin({ right: 18 })
  513. .onChange((checked: boolean) => {
  514. this.isSavePlayMode = checked;
  515. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  516. })
  517. .width(50)
  518. .height(30);
  519. }
  520. .height(55)
  521. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  522. .visibility(Visibility.None)
  523. Row() {
  524. Text('与其他应用同时播放')
  525. .margin({ left: 18 })
  526. .fontSize(15)
  527. .fontColor(Color.Gray)
  528. .fontWeight(480)
  529. .layoutWeight(1)
  530. Toggle({ type: ToggleType.Switch, isOn: this.isSameTimePlay })
  531. .selectedColor($r('app.color.tab_item_bg'))
  532. .switchPointColor(Color.White)
  533. .margin({ right: 18 })
  534. .onChange((checked: boolean) => {
  535. this.isSameTimePlay = checked;
  536. PreferencesUtil.put(SettingPage.IS_SAMETIME_PLAY, this.isSameTimePlay)
  537. })
  538. .width(50)
  539. .height(30);
  540. }
  541. .height(55)
  542. .visibility(Visibility.None)
  543. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  544. // 播放背景随音乐封面
  545. Row() {
  546. Text('播放背景随音乐封面')
  547. .margin({ left: 18 })
  548. .fontSize(15)
  549. .fontColor(Color.Gray)
  550. .fontWeight(480)
  551. .layoutWeight(1)
  552. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  553. .selectedColor($r('app.color.tab_item_bg'))
  554. .switchPointColor(Color.White)
  555. .margin({ right: 18 })
  556. .onChange((checked: boolean) => {
  557. this.isMusicBGCover = checked;
  558. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  559. })
  560. .width(50)
  561. .height(30);
  562. }
  563. .height(55)
  564. }
  565. .backgroundColor($r('app.color.settings_background_main'))
  566. .borderRadius(20)
  567. .margin({ left: 0, right: 0, top: 10, bottom: 10 })
  568. .padding(0)
  569. // API设置分组
  570. Column() {
  571. Row() {
  572. Text('API设置')
  573. .margin({ left: 18, right: 20 })
  574. .fontSize(16)
  575. .fontColor(Color.Gray)
  576. .fontWeight(480)
  577. .layoutWeight(1)
  578. }
  579. .height(48)
  580. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  581. // 歌词API
  582. Row() {
  583. Text('歌词:')
  584. .margin({ left: 18, right: 6 })
  585. .fontSize(15)
  586. .fontColor(Color.Gray)
  587. Text(this.lyricApiUrl)
  588. .margin({ right: 10 })
  589. .fontSize(15)
  590. .fontColor(Color.Gray)
  591. .layoutWeight(1)
  592. Image(this.isDarkMode?$r('app.media.rename2'):$r('app.media.ic_public_edit'))
  593. .width(22)
  594. .height(22)
  595. .margin({ right: 18 })
  596. }
  597. .onClick(() => {
  598. this.apiDialogType = 'lyric'
  599. this.tempApiUrl = this.lyricApiUrl
  600. this.apiDialogController.open()
  601. })
  602. .height(55)
  603. // 封面API
  604. Row() {
  605. Text('封面:')
  606. .margin({ left: 18, right: 6 })
  607. .fontSize(15)
  608. .fontColor(Color.Gray)
  609. Text(this.coverApiUrl)
  610. .margin({ right: 10 })
  611. .fontSize(15)
  612. .fontColor(Color.Gray)
  613. .layoutWeight(1)
  614. Image(this.isDarkMode?$r('app.media.rename2'):$r('app.media.ic_public_edit'))
  615. .width(22)
  616. .height(22)
  617. .margin({ right: 18 })
  618. }
  619. .onClick(() => {
  620. this.apiDialogType = 'cover'
  621. this.tempApiUrl = this.coverApiUrl
  622. this.apiDialogController.open()
  623. })
  624. .justifyContent(FlexAlign.Center)
  625. .height(55)
  626. }
  627. .backgroundColor($r('app.color.settings_background_main'))
  628. .borderRadius(20)
  629. .margin({ left: 0, right: 0, top: 10, bottom: 20 })
  630. .padding(0)
  631. //空白
  632. Column() {
  633. Blank()
  634. .height(88)
  635. }.height(88)
  636. }
  637. .margin({ left: this.currentBreakpoint !== BreakpointTypeEnum.SM?35:20,
  638. right: this.currentBreakpoint !== BreakpointTypeEnum.SM?35:20, top: 20, bottom: 20 })
  639. .justifyContent(FlexAlign.Start)
  640. }
  641. .scrollBar(BarState.Auto)
  642. .height(px2vp(DisplayUtil.getHeight()-AppUtil.getStatusBarHeight()-AppUtil.getNavigationIndicatorHeight()))
  643. .width('100%')
  644. .margin({bottom:10})
  645. .backgroundColor($r('app.color.settings_background'))
  646. }
  647. .height('100%')
  648. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  649. }
  650. //发送广播通知更新UI
  651. sendChangeEvent(){
  652. const eventData: emitter.EventData = {};
  653. emitter.emit({ eventId: 333 }, eventData); // 发送音频广播通知更新doSwipBack
  654. }
  655. goSelectImage() {
  656. let selectUris: Array<string> = [];
  657. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  658. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  659. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
  660. photoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目
  661. photoPicker.select(photoSelectOptions).then(async (photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
  662. //用一个全局变量存储返回的uri
  663. selectUris = photoSelectResult.photoUris;
  664. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  665. //使用fs.openSync接口,通过uri打开这个文件得到fd
  666. let file = fileIo.openSync(selectUris[0], fileIo.OpenMode.READ_ONLY);
  667. console.info('file fd: ' + file.fd);
  668. const timestamp: number = Math.floor(Date.now() / 1000);
  669. let name = timestamp+"_homebg"
  670. let imagePath = this.context.filesDir + FileUtil.separator + name
  671. imagePath = fileUri.getUriFromPath(imagePath)
  672. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  673. fileIo.copyFileSync(file.fd, file2.fd)
  674. fileIo.closeSync(file);
  675. fileIo.closeSync(file2);
  676. this.customizeBgPath = imagePath
  677. PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG_PATH, this.customizeBgPath)
  678. this.sendChangeEvent()
  679. }).catch((err: BusinessError) => {
  680. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  681. })
  682. }
  683. @Builder
  684. customizeBgSheet() {
  685. Scroll() {
  686. Column() {
  687. this.CustomizeBg()
  688. }
  689. }
  690. .width('100%')
  691. .height('100%')
  692. }
  693. @Builder
  694. CustomizeBg() {
  695. Column() {
  696. Image( this.customizeBgPath)
  697. .height('42%')
  698. .alt($r('app.color.white'))
  699. .objectFit( ImageFit.Contain)
  700. .borderRadius(20)
  701. .clip(true)
  702. .blur(this.blurValue)
  703. .brightness(this.bgBrightness+0.8)
  704. .margin({left:30,right:30,bottom:20 })
  705. Row() {
  706. Row() {
  707. Button('选择图片')
  708. .fontColor(Color.White)
  709. .fontSize(12)
  710. .height(48)
  711. .width(100)
  712. .backgroundColor($r('app.color.title_bar_bg'))
  713. .stateEffect(true)
  714. .onClick(async () => {
  715. this.goSelectImage()
  716. })
  717. }
  718. .height('100%')
  719. .justifyContent(FlexAlign.Center)
  720. .layoutWeight(1)
  721. }
  722. .width('100%')
  723. .height(58)
  724. .margin({ bottom:20 })
  725. Column() {
  726. Row() {
  727. Text('自定义背景:')
  728. .margin({ left: 18 })
  729. .fontSize(15)
  730. .fontColor($r('app.color.text_color'))
  731. .fontWeight(480)
  732. .layoutWeight(1)
  733. Toggle({ type: ToggleType.Switch, isOn: this.isCustomizeBg })
  734. .selectedColor($r('app.color.tab_item_bg'))
  735. .switchPointColor(Color.White)
  736. .margin({ right: 18 })
  737. .onChange((checked: boolean) => {
  738. this.isCustomizeBg = checked;
  739. PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG, this.isCustomizeBg)
  740. this.sendChangeEvent()
  741. })
  742. .width(50)
  743. .height(30);
  744. }
  745. .height(55)
  746. }
  747. .backgroundColor($r('app.color.settings_background_main'))
  748. .borderRadius(15)
  749. .margin({ left: 30, right: 30, top: 0, bottom: 20 })
  750. .padding(0)
  751. Column() {
  752. Row() {
  753. Text('背景模糊:')
  754. .margin({ left: 18 })
  755. .fontSize(15)
  756. .fontColor($r('app.color.text_color'))
  757. .fontWeight(480)
  758. Slider({
  759. value: this.blurValue,
  760. min: 0,
  761. max: 100,
  762. step: 1,
  763. style: SliderStyle.OutSet
  764. })
  765. .blockColor(Color.Red)
  766. .trackColor($r('app.color.speed_text_color'))
  767. .selectedColor($r('app.color.index_background'))
  768. .trackThickness(8)
  769. .onChange((value: number) => {
  770. this.blurValue = value;
  771. PreferencesUtil.put(SettingPage.CUSTOMIZE_BG_BLUR, this.blurValue)
  772. this.sendChangeEvent()
  773. })
  774. .layoutWeight(1)
  775. }
  776. .height(55)
  777. }
  778. .backgroundColor($r('app.color.settings_background_main'))
  779. .borderRadius(15)
  780. .margin({ left: 30, right: 30, top: 0, bottom: 20 })
  781. .padding(0)
  782. Column() {
  783. Row() {
  784. Text('背景亮度:')
  785. .margin({ left: 18 })
  786. .fontSize(15)
  787. .fontColor($r('app.color.text_color'))
  788. .fontWeight(480)
  789. Slider({
  790. value: this.bgBrightness,
  791. min: -0.4,
  792. max: 0.4,
  793. step: 0.1,
  794. style: SliderStyle.OutSet
  795. })
  796. .blockColor(Color.Red)
  797. .trackColor($r('app.color.speed_text_color'))
  798. .selectedColor($r('app.color.index_background'))
  799. .trackThickness(8)
  800. .onChange((value: number) => {
  801. this.bgBrightness = value;
  802. PreferencesUtil.put(SettingPage.BG_BRIGHTNESS, this.bgBrightness)
  803. this.sendChangeEvent()
  804. })
  805. .layoutWeight(1)
  806. }
  807. .height(55)
  808. }
  809. .backgroundColor($r('app.color.settings_background_main'))
  810. .borderRadius(15)
  811. .margin({ left: 30, right: 30, top: 0, bottom: 20 })
  812. .padding(0)
  813. }
  814. .margin({ bottom: 30 })
  815. }
  816. public static THEME_COLOR_KEY: string = 'THEME_COLOR';
  817. public static THEME_COLOR_LIST: Array<string> = [
  818. '#FF4081', // 默认
  819. '#0A59F7', // 蓝
  820. '#64BB5C', // 绿
  821. '#ED6F21', // 橙
  822. '#5BA854' // 青
  823. ];
  824. }