SettingPage.ets 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  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 { Utility } from '../common/util/Utility'
  13. import { HSBColorPicker } from '@keke/color-picker'
  14. import { DialogHelper } from '@pura/harmony-dialog'
  15. import { bundleManager } from '@kit.AbilityKit'
  16. import { hilog } from '@kit.PerformanceAnalysisKit'
  17. @Preview
  18. // @Entry
  19. @Component
  20. export struct SettingPage {
  21. @Consume isShowDrawer: boolean;
  22. @Consume offsetX: number;
  23. @Consume mType: number;
  24. static readonly THEME_MODE: string = 'themeMode';
  25. static readonly SORT_TYPE: string = 'musicSortType';
  26. static readonly IS_BGPLAY_OPEN: string = 'isBgPlayOpen';
  27. static readonly IS_AUTO_RATATE: string = 'isAutoRatate';
  28. static readonly iS_MEMORY_PLAY: string = 'isMemoryPlay';
  29. static readonly IS_MIDIACODEC_OPEN: string = 'isMediacodec';
  30. static readonly iS_MUSIC_MEMORY_PLAY: string = 'isMusicMemoryPlay';
  31. static readonly iS_MUSIC_BG_COVER: string = 'isMusicBGCover';
  32. static readonly iS_SAVE_PLAY_MODE: string = 'isSavePlayMode';
  33. static readonly IS_COVER_RECTANGLE: string = 'isCoverRectangle'; //封面圆形或者方形
  34. static readonly IS_SHOW_SIMI: string = 'isShowSimi';
  35. static readonly IS_SHOW_FAV: string = 'isShowFAV';
  36. static readonly IS_SHOW_HISTORY: string = 'isShowHistory';
  37. static readonly IS_CUSTOMIZE_BG: string = 'is_customize_bg';
  38. static readonly IS_GRID_MUSIC: string = 'is_grid_music';
  39. static readonly IS_CUSTOMIZE_BG_PATH: string = 'is_customize_bg_path';
  40. static readonly IS_SCROLL_HIDE: string = 'isScrollHide';
  41. static readonly IS_SAMETIME_PLAY: string = 'isSameTimePlay';
  42. static readonly CUSTOMIZE_BG_BLUR: string = 'customize_bg_blur';
  43. static readonly BG_BRIGHTNESS: string = 'bg_brightness';
  44. static readonly IS_SHOW_ALLBAR: string = 'IS_SHOW_ALLBAR';
  45. static readonly IS_SHOW_TITLTBAR: string = 'IS_SHOW_TITLTBAR';
  46. static readonly IS_SHOW_PLAYPAGE_BACK: string = 'IS_SHOW_PLAYPAGE_BACK';
  47. static readonly IS_SHOW_SLLYRIC: string = 'IS_SHOW_SLLYRIC';
  48. static readonly IS_CIRCLE_BTN: string = 'isCircleBtn';
  49. static readonly IS_COVER_TOP: string = 'IS_COVER_TOP';
  50. static readonly IS_SHOW_HEADER: string = 'IS_SHOW_HEADER';
  51. static readonly IS_COVER_TOP_BIG: string = 'IS_COVER_TOP_BIG';
  52. public static THEME_COLOR_KEY: string = 'THEME_COLOR';
  53. public static TWO_FINGER_TYPE: string = 'twoFingerType';
  54. public static LONG_PRESS_SPEED: string = 'longPressSpeed';
  55. public static IS_PLAYLIST_BG_GRASS: string = 'isPlayListBgGrass';
  56. public static THEME_COLOR_LIST: Array<ThemeColorItem> = [
  57. { name: '玫瑰粉', color: '#FF4081', isVip: false },
  58. { name: '经典蓝', color: '#0A59F7', isVip: false },
  59. { name: '活力黄', color: '#FFC107', isVip: true },
  60. { name: '枫叶红', color: '#F44336', isVip: true },
  61. { name: '幻影紫', color: '#9C27B0', isVip: true },
  62. { name: '翡翠绿', color: '#64BB5C', isVip: true },
  63. { name: '竹青蓝', color: '#00BCD4', isVip: true },
  64. { name: '深空灰', color: '#607D8B', isVip: true },
  65. { name: '橙霞橙', color: '#FF9800', isVip: true },
  66. { name: '湖水蓝', color: '#00BFFF', isVip: true },
  67. { name: '柠檬绿', color: '#C6FF00', isVip: true },
  68. { name: '樱花粉', color: '#FF69B4', isVip: true },
  69. { name: '暮夜蓝', color: '#283593', isVip: true },
  70. { name: '薄荷青', color: '#1DE9B6', isVip: true },
  71. { name: '银沙灰', color: '#B0BEC5', isVip: true },
  72. { name: '自定义', color: '#ffecec', isVip: true }
  73. ];
  74. static readonly iS_START_AUTO_PLAY: string = 'isStartAutoPlay';
  75. static readonly iS_MEMORY_LAST_PLAY: string = 'isMemoryLastPlay';
  76. @State showApiDialog: boolean = false
  77. @State tempApiUrl: string = ''
  78. @State lyricApiUrl: string = PreferencesUtil.getStringSync('LRC_API', '')
  79. @State isBgPlayOpen: boolean = true //是否启用后台播放
  80. @State isAutoRatate: boolean = true //是否启用自动横竖屏
  81. @State isMemoryPlay: boolean = true //是否启用记忆播放
  82. @State isMediacodec: boolean = false //是否启用硬件解码
  83. @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
  84. @State isMusicBGCover: boolean = true //播放背景随封面
  85. @State sortType: number = 4 //默认排序方式
  86. @State isStartAutoPlay: boolean = false //启动后自动播放
  87. @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
  88. @State isShowSimi: boolean = false //是否显示私密音频
  89. @State isShowFAV: boolean = true //是否显示我的收藏
  90. @State isShowHistory: boolean = true //是否显示最近播放
  91. @State isShowPlayPageBack: boolean = false //是否显示播放页返回键
  92. @State isShowSingleLineLyric: boolean = false //是否显示播放页返回键
  93. @State isShowHeader: boolean = true
  94. @State isCustomizeBg: boolean = false //自定义背景界面
  95. @State isCustomizeBgSheet: boolean = false //自定义背景界面
  96. @State isShowTitleBar: boolean = true //是否显示分类导航条
  97. @State isShowAllBar: boolean = true //是否显示播放全部条
  98. @State longPressSpeed: number = 3 //长按默认倍数
  99. @State blurValue: number = 0 //背景模糊
  100. @State bgBrightness: number = 0 //背景亮度
  101. @State isGridMusic: boolean = true //是否网格布局
  102. @State isCircleBtn: boolean = false //是否圆形播放按钮
  103. @State twoFingerType: number = 3 //双指放大瘦小Grid或list的大小
  104. @State isScrollHide: boolean = false //是否滚动隐藏
  105. @State isSameTimePlay: boolean = false //是否和其他app同时播放
  106. @State isCoverRectangle: boolean = false
  107. @State isSavePlayMode: boolean = true
  108. @State isCoverTop: boolean = true
  109. @State isCoverTopBig: boolean = false//顶部大封面部分手机显示会和播放控制页重叠
  110. @State isPlayListBgGrass: boolean = true//是否播放列表玻璃透明效果
  111. @State customizeBgPath: string | undefined = '';
  112. context = getContext(this);
  113. @State showCoverApiDialog: boolean = false
  114. @State tempCoverApiUrl: string = ''
  115. @State coverApiUrl: string = PreferencesUtil.getStringSync('COVER_API', '')
  116. @State apiDialogType: 'lyric' | 'cover' = 'lyric'
  117. @State themeMode: number = 0 // 0: 跟随系统, 1: 浅色, 2: 深色
  118. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  119. ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  120. @StorageLink('isDarkMode') isDarkMode: boolean = false // 是否启用深色模式
  121. /** 当前断点类型(如大屏/小屏) */
  122. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  123. @State verName: string = ''
  124. @StorageProp('themeColor') themeColor: string =
  125. PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  126. @State showColorPicker: boolean = false
  127. @State customColor: string = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  128. @State isThemeSheet: boolean = false // 主题设置弹窗显示状态
  129. @State colorRows: Array<Array<ThemeColorItem>> = chunkArray(SettingPage.THEME_COLOR_LIST, 2);
  130. @State colorGroup: string = "group"
  131. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  132. apiDialogController: CustomDialogController = new CustomDialogController({
  133. builder: CustomContentDialog({
  134. primaryTitle: this.apiDialogType === 'lyric' ? '修改歌词API地址' : '修改封面API地址',
  135. contentBuilder: () => {
  136. this.buildApiDialogContent();
  137. },
  138. buttons: [
  139. {
  140. value: '取消',
  141. action: () => {
  142. this.apiDialogController.close();
  143. }
  144. },
  145. {
  146. value: '保存',
  147. action: () => {
  148. if (this.apiDialogType === 'lyric') {
  149. this.lyricApiUrl = this.tempApiUrl.trim()
  150. PreferencesUtil.put('LRC_API', this.lyricApiUrl)
  151. this.getUIContext().getPromptAction().showToast({
  152. message: '保存成功,当前LRC_API:' + this.lyricApiUrl,
  153. duration: 2000,
  154. showMode: promptAction.ToastShowMode.TOP_MOST,
  155. bottom: 85
  156. })
  157. } else {
  158. this.coverApiUrl = this.tempApiUrl.trim()
  159. PreferencesUtil.put('COVER_API', this.coverApiUrl)
  160. this.getUIContext().getPromptAction().showToast({
  161. message: '保存成功,当前COVER_API:' + this.coverApiUrl,
  162. duration: 2000,
  163. showMode: promptAction.ToastShowMode.TOP_MOST,
  164. bottom: 85
  165. })
  166. }
  167. this.apiDialogController.close();
  168. }
  169. }
  170. ]
  171. }),
  172. autoCancel: true,
  173. alignment: DialogAlignment.Center
  174. })
  175. @Builder
  176. buildApiDialogContent() {
  177. Column() {
  178. TextInput({
  179. text: this.tempApiUrl,
  180. placeholder: this.apiDialogType === 'lyric' ? '请输入歌词API地址' : '请输入封面API地址'
  181. })
  182. .onChange((val: string) => {
  183. this.tempApiUrl = val
  184. })
  185. .width('90%')
  186. .height(60)
  187. }
  188. .width('100%')
  189. }
  190. // 组件生命周期
  191. aboutToAppear() {
  192. this.geIDD()
  193. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  194. this.isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN, true)
  195. this.isAutoRatate = PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_RATATE, true)
  196. this.isMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_PLAY, true)
  197. this.isMediacodec = PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN, false)
  198. this.isMusicMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)
  199. this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
  200. this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
  201. this.isShowSimi = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SIMI, false)
  202. this.isShowFAV = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_FAV, true)
  203. this.isShowHistory = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HISTORY, true)
  204. this.isCustomizeBg = PreferencesUtil.getBooleanSync(SettingPage.IS_CUSTOMIZE_BG, false)
  205. this.customizeBgPath = PreferencesUtil.getStringSync(SettingPage.IS_CUSTOMIZE_BG_PATH, '')
  206. this.isGridMusic = PreferencesUtil.getBooleanSync(SettingPage.IS_GRID_MUSIC, true)
  207. this.isScrollHide = PreferencesUtil.getBooleanSync(SettingPage.IS_SCROLL_HIDE, false)
  208. this.isSameTimePlay = PreferencesUtil.getBooleanSync(SettingPage.IS_SAMETIME_PLAY, false)
  209. this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
  210. this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
  211. this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
  212. this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
  213. this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
  214. this.twoFingerType = PreferencesUtil.getNumberSync(SettingPage.TWO_FINGER_TYPE, 3)
  215. this.isCircleBtn = PreferencesUtil.getBooleanSync(SettingPage.IS_CIRCLE_BTN, true)
  216. this.isCoverTop = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP, false)
  217. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  218. this.isShowAllBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_ALLBAR, true)
  219. this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, true)
  220. this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
  221. this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
  222. this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
  223. this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
  224. this.isCoverRectangle = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_RECTANGLE, true)
  225. this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
  226. // 只用 themeMode 控制主题
  227. this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
  228. this.applyThemeMode(this.themeMode)
  229. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  230. AppStorage.setOrCreate('themeColor', themeColor);
  231. this.themeColor = themeColor;
  232. }
  233. // 监听颜色模式变化
  234. onColorModeChange(): void {
  235. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK;
  236. AppStorage.setOrCreate('isDarkMode', this.isDarkMode);
  237. }
  238. // 组件生命周期
  239. aboutToDisappear() {
  240. // 无需处理apiDialogController
  241. }
  242. applyThemeMode(mode: number) {
  243. let colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET
  244. if (mode === 1) {
  245. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
  246. } else if (mode === 2) {
  247. colorMode = ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  248. }
  249. AppStorage.setOrCreate('currentColorMode', colorMode)
  250. AppStorage.setOrCreate('isDarkMode', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK)
  251. PreferencesUtil.putSync(SettingPage.THEME_MODE, mode)
  252. AppStorage.setOrCreate('themeMode', mode)
  253. // 只有强制浅色/深色时才主动设置
  254. const context = getContext(this) as common.UIAbilityContext
  255. context.getApplicationContext().setColorMode(colorMode)
  256. }
  257. @Builder
  258. pickerBuilder() {
  259. Column({ space: 20 }) {
  260. HSBColorPicker({
  261. color: this.customColor,
  262. radius: 8,
  263. onChange: (value: string) => {
  264. this.customColor = value
  265. }
  266. })
  267. .layoutWeight(1)
  268. .padding(15)
  269. Row({ space: 10 }) {
  270. Button('取消')
  271. .stateEffect(true)
  272. .backgroundColor(this.themeColor)
  273. .onClick(() => {
  274. this.showColorPicker = false
  275. })
  276. Button('确定')
  277. .stateEffect(true)
  278. .backgroundColor(this.themeColor)
  279. .onClick(() => {
  280. this.themeColor = this.customColor
  281. PreferencesUtil.putSync(SettingPage.THEME_COLOR_KEY, this.customColor)
  282. AppStorage.setOrCreate('themeColor', this.customColor)
  283. this.sendChangeEvent()
  284. this.showColorPicker = false
  285. })
  286. }
  287. }
  288. .padding(20)
  289. .width('80%')
  290. .height(300)
  291. }
  292. @Builder
  293. themeSheetBuilder() {
  294. Column() {
  295. // 颜色模式分组卡片
  296. Column() {
  297. Row() {
  298. Row() {
  299. Image($r('app.media.theme'))
  300. .width(20)
  301. .height(20)
  302. .fillColor(this.themeColor)
  303. Text('颜色模式')
  304. .fontSize(15)
  305. .margin({ left: 6 })
  306. .fontWeight(500)
  307. }
  308. .layoutWeight(1)
  309. Blank()
  310. Row() {
  311. ForEach(['自动', '日间', '夜间'], (item: string, idx: number) => {
  312. Column() {
  313. Radio({
  314. value: idx.toString(),
  315. group: this.colorGroup,
  316. })
  317. .checked(this.themeMode === idx)
  318. .radioStyle({
  319. checkedBackgroundColor: this.themeColor
  320. })
  321. .margin({ left: 3, right: 3 })
  322. .onClick(() => {
  323. this.themeMode = idx
  324. this.applyThemeMode(idx)
  325. this.sendChangeEvent()
  326. })
  327. Text(item)
  328. .fontSize(15)
  329. .fontColor($r('app.color.text_color'))
  330. .margin({ top: 6 })
  331. .onClick(() => {
  332. this.themeMode = idx
  333. this.applyThemeMode(idx)
  334. this.sendChangeEvent()
  335. })
  336. }
  337. .alignItems(HorizontalAlign.Center)
  338. .margin({ left: 12, right: 12 })
  339. })
  340. }
  341. .margin({ left: 12, right: 12 })
  342. }
  343. }
  344. .backgroundColor($r('app.color.settings_background_main'))
  345. .borderRadius(18)
  346. .border({ width: 1, color: '#F0F0F0' })
  347. .shadow({
  348. radius: 12,
  349. color: 0x11000000,
  350. offsetX: 0,
  351. offsetY: 2
  352. })
  353. .margin({
  354. left: 0,
  355. right: 0,
  356. bottom: 20
  357. })
  358. .padding({
  359. top: 18,
  360. bottom: 18,
  361. left: 20,
  362. right: 20
  363. })
  364. .width('90%')
  365. // 主题色分组卡片
  366. Column() {
  367. Row() {
  368. Image($r('app.media.theme'))
  369. .width(20)
  370. .height(20)
  371. .fillColor(this.themeColor)
  372. Text('主题色')
  373. .fontSize(15)
  374. .fontWeight(500)
  375. .margin({ left: 8 })
  376. .layoutWeight(1)
  377. }
  378. .margin({ left: 20, top: 12 })
  379. Row() {
  380. Column() {
  381. ForEach(this.colorRows, (row: Array<ThemeColorItem>, rowIdx: number) => {
  382. Row() {
  383. ForEach(row, (item: ThemeColorItem, colIdx: number) => {
  384. Button() {
  385. Row() {
  386. Blank()
  387. .width(22)
  388. .height(22)
  389. .backgroundColor(item.name === '自定义' && this.isCustomThemeColor() ? this.themeColor :
  390. item.color)
  391. .border({ width: 2, color: $r('app.color.text_color') })
  392. .borderRadius(11)
  393. Text(item.name)
  394. .fontSize(15)
  395. .fontColor($r('app.color.text_color'))
  396. .margin({ left: 10 })
  397. // Text(item.isVip?'VIP':"Free")
  398. // .fontSize(10)
  399. // .fontColor(item.isVip?'#FFD700':"#000000") // 金色
  400. // .backgroundColor('#FFF9E3')
  401. // .borderRadius(6)
  402. // .padding({ left: 4, right: 4, top: 1, bottom: 1 })
  403. // .margin({ left: 4 })
  404. }
  405. .alignItems(VerticalAlign.Center)
  406. .justifyContent(FlexAlign.Start)
  407. .layoutWeight(1)
  408. }
  409. .height(40)
  410. .layoutWeight(1)
  411. .backgroundColor(
  412. (item.name === '自定义' && this.isCustomThemeColor()) || this.themeColor === item.color
  413. ? this.themeColor
  414. : $r('app.color.settings_background_main')
  415. )
  416. .borderRadius(20)
  417. .onClick(() => {
  418. if (item.isVip) {
  419. if (!Utility.isNoble()) {
  420. this.showVipDialog();
  421. return;
  422. }
  423. }
  424. if (item.name === '自定义') {
  425. this.showColorPicker = true
  426. } else {
  427. this.themeColor = item.color
  428. PreferencesUtil.putSync(SettingPage.THEME_COLOR_KEY, item.color)
  429. AppStorage.setOrCreate('themeColor', item.color)
  430. this.sendChangeEvent()
  431. }
  432. })
  433. .margin({ right: colIdx === 0 ? '4%' : 20, bottom: 10, left: 20 })
  434. })
  435. }
  436. .justifyContent(FlexAlign.Start)
  437. })
  438. }
  439. .margin({ left: 12, right: 12, top: 12 })
  440. }
  441. }
  442. .width('90%')
  443. .backgroundColor($r('app.color.settings_background_main'))
  444. .borderRadius(18)
  445. .border({ width: 1, color: '#F0F0F0' })
  446. .shadow({
  447. radius: 12,
  448. color: 0x11000000,
  449. offsetX: 0,
  450. offsetY: 2
  451. })
  452. .margin({
  453. left: 0,
  454. right: 0,
  455. bottom: 18
  456. })
  457. .padding({
  458. top: 18,
  459. bottom: 18,
  460. left: 0,
  461. right: 0
  462. })
  463. .bindPopup(this.showColorPicker, {
  464. builder: this.pickerBuilder(),
  465. placement: Placement.Top,
  466. mask: { color: '#33000000' },
  467. enableArrow: false, //是否显示箭头
  468. showInSubWindow: false,
  469. onStateChange: (e) => {
  470. if (!e.isVisible) {
  471. this.showColorPicker = false
  472. }
  473. }
  474. })
  475. // 主题色自定义弹窗
  476. }
  477. .padding({
  478. top: 8,
  479. bottom: 8,
  480. left: 15,
  481. right: 15
  482. })
  483. .width('100%')
  484. .backgroundColor(Color.Transparent)
  485. .borderRadius(24)
  486. }
  487. build() {
  488. Column() {
  489. Column() {
  490. Line().width('100%').height('100%')
  491. }
  492. .height(this.topRectHeight)
  493. .backgroundColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  494. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  495. // 自定义标题栏
  496. Stack() {
  497. // 居中标题
  498. Text('通用设置')
  499. .fontSize(20)
  500. .fontColor(Color.White)
  501. .align(Alignment.Center)
  502. // 左侧返回按钮
  503. Row() {
  504. Image($r('app.media.menu'))
  505. .width(29)
  506. .height(29)
  507. .margin({ left: 12, right: 8 })
  508. .onClick(() => {
  509. animateTo({ duration: 555 }, () => {
  510. // 动画闭包内控制Image组件的出现和消失
  511. this.isShowDrawer = !this.isShowDrawer
  512. this.offsetX = 0
  513. })
  514. })
  515. Blank().flexGrow(1)
  516. Blank().width(32)
  517. }
  518. .height(48)
  519. .width('100%')
  520. .alignItems(VerticalAlign.Center)
  521. }
  522. .height(48)
  523. .width('100%')
  524. .backgroundColor(this.isDarkMode ? $r('app.color.title_bar_bg') : this.themeColor)
  525. Scroll() {
  526. Column() {
  527. // 主题设置分组
  528. Column() {
  529. Row() {
  530. Text('个性化')
  531. .margin({ left: 18, right: 20 })
  532. .fontSize(16)
  533. .fontColor(Color.Gray)
  534. .fontWeight(480)
  535. .layoutWeight(1)
  536. }
  537. .height(48)
  538. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  539. // 主题设置弹框入口
  540. Button({ type: ButtonType.Normal, stateEffect: true }) {
  541. Row() {
  542. Text('主题设置')
  543. .margin({ left: 18 })
  544. .fontSize(15)
  545. .fontColor(Color.Gray)
  546. .fontWeight(480)
  547. .layoutWeight(1)
  548. Image($r('app.media.arrow_right'))
  549. .width(22)
  550. .height(22)
  551. .margin({ right: 18 })
  552. }
  553. }
  554. .backgroundColor(Color.Transparent)
  555. .height(55)
  556. .clickEffect({ level: ClickEffectLevel.HEAVY })
  557. .onClick(() => {
  558. this.showColorPicker = false;
  559. this.isThemeSheet = true;
  560. this.customColor = this.themeColor;
  561. })
  562. .bindSheet($$this.isThemeSheet, this.themeSheetBuilder(), {
  563. height: '95%',
  564. dragBar: true,
  565. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  566. showClose: true,
  567. blurStyle: BlurStyle.Thin,
  568. backgroundColor: Color.Transparent,
  569. title: { title: '主题设置' },
  570. shouldDismiss: (SheetDismiss: SheetDismiss) => {
  571. SheetDismiss.dismiss();
  572. this.showColorPicker = false;
  573. }
  574. })
  575. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  576. Button({ type: ButtonType.Normal, stateEffect: true }) {
  577. Row() {
  578. Text('自定义背景')
  579. .margin({ left: 18 })
  580. .fontSize(15)
  581. .fontColor(Color.Gray)
  582. .fontWeight(480)
  583. .layoutWeight(1)
  584. .bindSheet($$this.isCustomizeBgSheet, this.customizeBgSheet(), {
  585. height: '95%',
  586. dragBar: true,
  587. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  588. showClose: true,
  589. blurStyle: BlurStyle.Thin,
  590. backgroundColor: Color.Transparent,
  591. title: { title: '自定义背景' }
  592. })
  593. Blank()
  594. // 右侧箭头
  595. Image($r('app.media.arrow_right'))
  596. .width(22)
  597. .height(22)
  598. .margin({ left: 20, right: 20 })
  599. .align(Alignment.Center)
  600. }
  601. }
  602. .clickEffect({ level: ClickEffectLevel.HEAVY })
  603. .height(55)
  604. .onClick(() => {
  605. if (!Utility.isNoble()) {
  606. this.showVipDialog();
  607. return;
  608. }
  609. this.isCustomizeBgSheet = !this.isCustomizeBgSheet;
  610. })
  611. .backgroundColor(Color.Transparent)
  612. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  613. // 滚动隐藏'
  614. Row() {
  615. Text('滚动隐藏')
  616. .margin({ left: 18 })
  617. .fontSize(15)
  618. .fontColor(Color.Gray)
  619. .fontWeight(480)
  620. .layoutWeight(1)
  621. Toggle({ type: ToggleType.Switch, isOn: this.isScrollHide })
  622. .selectedColor(this.themeColor)
  623. .switchPointColor(Color.White)
  624. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  625. .margin({ right: 18 })
  626. .onChange((checked: boolean) => {
  627. this.isScrollHide = checked;
  628. PreferencesUtil.put(SettingPage.IS_SCROLL_HIDE, this.isScrollHide)
  629. this.sendChangeEvent()
  630. })
  631. .width(50)
  632. .height(30);
  633. }
  634. .height(55)
  635. .clickEffect({ level: ClickEffectLevel.HEAVY })
  636. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  637. // 网格布局
  638. Row() {
  639. Text('网格模式')
  640. .margin({ left: 18 })
  641. .fontSize(15)
  642. .fontColor(Color.Gray)
  643. .fontWeight(480)
  644. .layoutWeight(1)
  645. Toggle({ type: ToggleType.Switch, isOn: this.isGridMusic })
  646. .selectedColor(this.themeColor)
  647. .switchPointColor(Color.White)
  648. .margin({ right: 18 })
  649. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  650. .onChange((checked: boolean) => {
  651. this.isGridMusic = checked;
  652. PreferencesUtil.put(SettingPage.IS_GRID_MUSIC, this.isGridMusic)
  653. this.sendChangeEvent()
  654. })
  655. .width(50)
  656. .height(30);
  657. }
  658. .height(55)
  659. .clickEffect({ level: ClickEffectLevel.HEAVY })
  660. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  661. // 封面方形
  662. Row() {
  663. Text('封面方形')
  664. .margin({ left: 18 })
  665. .fontSize(15)
  666. .fontColor(Color.Gray)
  667. .fontWeight(480)
  668. .layoutWeight(1)
  669. Toggle({ type: ToggleType.Switch, isOn: this.isCoverRectangle })
  670. .selectedColor(this.themeColor)
  671. .switchPointColor(Color.White)
  672. .margin({ right: 18 })
  673. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  674. .onChange((checked: boolean) => {
  675. this.isCoverRectangle = checked;
  676. PreferencesUtil.put(SettingPage.IS_COVER_RECTANGLE, this.isCoverRectangle)
  677. this.sendChangeEvent()
  678. })
  679. .width(50)
  680. .height(30);
  681. }
  682. .height(55)
  683. .clickEffect({ level: ClickEffectLevel.HEAVY })
  684. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  685. //播放列表透明
  686. Row() {
  687. Text('播放列表背景透明')
  688. .margin({ left: 18 })
  689. .fontSize(15)
  690. .fontColor(Color.Gray)
  691. .fontWeight(480)
  692. .layoutWeight(1)
  693. Toggle({ type: ToggleType.Switch, isOn: this.isPlayListBgGrass })
  694. .selectedColor(this.themeColor)
  695. .switchPointColor(Color.White)
  696. .margin({ right: 18 })
  697. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  698. .onChange((checked: boolean) => {
  699. this.isPlayListBgGrass = checked;
  700. PreferencesUtil.put(SettingPage.IS_PLAYLIST_BG_GRASS, this.isPlayListBgGrass)
  701. this.sendChangeEvent()
  702. })
  703. .width(50)
  704. .height(30);
  705. }
  706. .height(55)
  707. .clickEffect({ level: ClickEffectLevel.HEAVY })
  708. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  709. // 网格封面大
  710. Row() {
  711. Text('列表封面大小')
  712. .margin({ left: 18 })
  713. .fontSize(15)
  714. .fontColor(Color.Gray)
  715. .fontWeight(480)
  716. .layoutWeight(1)
  717. Select([
  718. { value: CommonConstants.TWO_FINGER_TYPE[0] },
  719. { value: CommonConstants.TWO_FINGER_TYPE[1] },
  720. { value: CommonConstants.TWO_FINGER_TYPE[2] }])
  721. .font({ size: 15, weight: FontWeight.Medium })
  722. .fontColor(Color.Gray)
  723. .margin({ right: 18 })
  724. .selected(this.twoFingerType - 1)
  725. .value(CommonConstants.TWO_FINGER_TYPE[this.twoFingerType-1])
  726. .onSelect(async (_index: number, text?: string | undefined) => {
  727. _index++;
  728. this.twoFingerType = _index
  729. PreferencesUtil.put(SettingPage.TWO_FINGER_TYPE, this.twoFingerType)
  730. this.sendChangeEvent()
  731. })
  732. }
  733. .height(55)
  734. .clickEffect({ level: ClickEffectLevel.HEAVY })
  735. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  736. // 封面顶部
  737. Row() {
  738. Text('封面顶部')
  739. .margin({ left: 18 })
  740. .fontSize(15)
  741. .fontColor(Color.Gray)
  742. .fontWeight(480)
  743. .layoutWeight(1)
  744. Toggle({ type: ToggleType.Switch, isOn: this.isCoverTop })
  745. .selectedColor(this.themeColor)
  746. .switchPointColor(Color.White)
  747. .margin({ right: 18 })
  748. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  749. .onChange((checked: boolean) => {
  750. this.isCoverTop = checked;
  751. PreferencesUtil.put(SettingPage.IS_COVER_TOP, this.isCoverTop)
  752. this.sendChangeEvent()
  753. })
  754. .width(50)
  755. .height(30);
  756. }
  757. .height(55)
  758. .clickEffect({ level: ClickEffectLevel.HEAVY })
  759. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  760. // 封面顶部
  761. Row() {
  762. Text('顶部大封面')
  763. .margin({ left: 18 })
  764. .fontSize(15)
  765. .fontColor(Color.Gray)
  766. .fontWeight(480)
  767. .layoutWeight(1)
  768. Toggle({ type: ToggleType.Switch, isOn: this.isCoverTopBig })
  769. .selectedColor(this.themeColor)
  770. .switchPointColor(Color.White)
  771. .margin({ right: 18 })
  772. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  773. .onChange((checked: boolean) => {
  774. this.isCoverTopBig = checked;
  775. if(this.isCoverTopBig){
  776. ToastUtil.showToast('启动该开关部分设备封面太大导致和音乐控制重叠!')
  777. }
  778. PreferencesUtil.put(SettingPage.IS_COVER_TOP_BIG, this.isCoverTopBig)
  779. this.sendChangeEvent()
  780. })
  781. .width(50)
  782. .height(30);
  783. }
  784. .height(55)
  785. .clickEffect({ level: ClickEffectLevel.HEAVY })
  786. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  787. // 圆形播放按钮
  788. Row() {
  789. Text('圆形播放按钮')
  790. .margin({ left: 18 })
  791. .fontSize(15)
  792. .fontColor(Color.Gray)
  793. .fontWeight(480)
  794. .layoutWeight(1)
  795. Toggle({ type: ToggleType.Switch, isOn: this.isCircleBtn })
  796. .selectedColor(this.themeColor)
  797. .switchPointColor(Color.White)
  798. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  799. .margin({ right: 18 })
  800. .onChange((checked: boolean) => {
  801. this.isCircleBtn = checked;
  802. PreferencesUtil.put(SettingPage.IS_CIRCLE_BTN, this.isCircleBtn)
  803. this.sendChangeEvent()
  804. })
  805. .width(50)
  806. .height(30);
  807. }
  808. .height(55)
  809. .clickEffect({ level: ClickEffectLevel.HEAVY })
  810. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  811. }
  812. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  813. .animation({ duration: 500, curve: Curve.Ease, delay: 200 }))
  814. .backgroundColor($r('app.color.settings_background_main'))
  815. .borderRadius(20)
  816. .margin({
  817. left: 0,
  818. right: 0,
  819. top: 0,
  820. bottom: 10
  821. })
  822. .padding(0)
  823. // 音频设置分组
  824. Column() {
  825. Row() {
  826. Text('音频设置')
  827. .margin({ left: 18, right: 20 })
  828. .fontSize(16)
  829. .fontColor(Color.Gray)
  830. .fontWeight(480)
  831. .layoutWeight(1)
  832. }
  833. .height(48)
  834. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  835. // 启动时播放
  836. Row() {
  837. Text('启动时播放')
  838. .margin({ left: 18 })
  839. .fontSize(15)
  840. .fontColor(Color.Gray)
  841. .fontWeight(480)
  842. .layoutWeight(1)
  843. Toggle({ type: ToggleType.Switch, isOn: this.isStartAutoPlay })
  844. .selectedColor(this.themeColor)
  845. .switchPointColor(Color.White)
  846. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  847. .margin({ right: 18 })
  848. .onChange((checked: boolean) => {
  849. this.isStartAutoPlay = checked;
  850. PreferencesUtil.put(SettingPage.iS_START_AUTO_PLAY, this.isStartAutoPlay)
  851. })
  852. .width(50)
  853. .height(30);
  854. }
  855. .height(55)
  856. .clickEffect({ level: ClickEffectLevel.HEAVY })
  857. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  858. // 记住播放进度
  859. Row() {
  860. Text('记住最后一首进度')
  861. .margin({ left: 18 })
  862. .fontSize(15)
  863. .fontColor(Color.Gray)
  864. .fontWeight(480)
  865. .layoutWeight(1)
  866. Toggle({ type: ToggleType.Switch, isOn: this.isMemoryLastPlay })
  867. .selectedColor(this.themeColor)
  868. .switchPointColor(Color.White)
  869. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  870. .margin({ right: 18 })
  871. .onChange((checked: boolean) => {
  872. this.isMemoryLastPlay = checked;
  873. PreferencesUtil.put(SettingPage.iS_MEMORY_LAST_PLAY, this.isMemoryLastPlay)
  874. this.sendChangeEvent()
  875. })
  876. .width(50)
  877. .height(30);
  878. }
  879. .height(55)
  880. .clickEffect({ level: ClickEffectLevel.HEAVY })
  881. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  882. // 记忆播放
  883. Row() {
  884. Text('记忆播放')
  885. .margin({ left: 18 })
  886. .fontSize(15)
  887. .fontColor(Color.Gray)
  888. .fontWeight(480)
  889. .layoutWeight(1)
  890. Toggle({ type: ToggleType.Switch, isOn: this.isMusicMemoryPlay })
  891. .selectedColor(this.themeColor)
  892. .switchPointColor(Color.White)
  893. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  894. .margin({ right: 18 })
  895. .onChange((checked: boolean) => {
  896. this.isMusicMemoryPlay = checked;
  897. PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
  898. this.sendChangeEvent()
  899. })
  900. .width(50)
  901. .height(30);
  902. }
  903. .height(55)
  904. .clickEffect({ level: ClickEffectLevel.HEAVY })
  905. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  906. // 长按默认倍数
  907. Row() {
  908. Text('长按默认倍数')
  909. .margin({ left: 18 })
  910. .fontSize(15)
  911. .fontColor(Color.Gray)
  912. .fontWeight(480)
  913. .layoutWeight(1)
  914. Select([//倍速
  915. { value: '0.25x' },
  916. { value: '0.5x' },
  917. { value: '0.75x' },
  918. { value: '1x' },
  919. { value: '1.25x' },
  920. { value: '1.5x' },
  921. { value: '1.75x' },
  922. { value: '2x' },
  923. { value: '2.5x' },
  924. { value: '3x' }])
  925. .font({ size: 15, weight: FontWeight.Medium })
  926. .fontColor(Color.Gray)
  927. .margin({right:18})
  928. .selected(CommonConstants.video_speed_list.indexOf(this.longPressSpeed))
  929. .value(Utility.optimizedFormat(this.longPressSpeed))
  930. .onSelect(async (_index: number, text?: string | undefined) => {
  931. let speed = parseFloat(text?.replace('x', '') || '1');
  932. if (!CommonConstants.video_speed_list.includes(speed)) {
  933. speed = 1;
  934. }
  935. this.longPressSpeed = speed
  936. PreferencesUtil.put(SettingPage.LONG_PRESS_SPEED, this.longPressSpeed)
  937. this.sendChangeEvent()
  938. })
  939. }
  940. .height(55)
  941. .clickEffect({level:ClickEffectLevel.HEAVY})
  942. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  943. // 默认排序模式
  944. Row() {
  945. Text('默认排序模式')
  946. .margin({ left: 18 })
  947. .fontSize(15)
  948. .fontColor(Color.Gray)
  949. .fontWeight(480)
  950. .layoutWeight(1)
  951. Select([
  952. { value: CommonConstants.SORT_ARRAY[0] },
  953. { value: CommonConstants.SORT_ARRAY[1] },
  954. { value: CommonConstants.SORT_ARRAY[2] },
  955. { value: CommonConstants.SORT_ARRAY[3] },
  956. { value: CommonConstants.SORT_ARRAY[4] },
  957. { value: CommonConstants.SORT_ARRAY[5] },
  958. { value: CommonConstants.SORT_ARRAY[6] },
  959. { value: CommonConstants.SORT_ARRAY[7] }])
  960. .font({ size: 15, weight: FontWeight.Medium })
  961. .fontColor(Color.Gray)
  962. .margin({ right: 18 })
  963. .selected(this.sortType)
  964. .value(CommonConstants.SORT_ARRAY[this.sortType])
  965. .onSelect(async (_index: number, text?: string | undefined) => {
  966. this.sortType = _index
  967. PreferencesUtil.put(SettingPage.SORT_TYPE, this.sortType)
  968. this.sendChangeEvent()
  969. })
  970. }
  971. .height(55)
  972. .clickEffect({ level: ClickEffectLevel.HEAVY })
  973. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  974. // 保存播放模式
  975. Row() {
  976. Text('保存播放模式')
  977. .margin({ left: 18 })
  978. .fontSize(15)
  979. .fontColor(Color.Gray)
  980. .fontWeight(480)
  981. .layoutWeight(1)
  982. Toggle({ type: ToggleType.Switch, isOn: this.isSavePlayMode })
  983. .selectedColor(this.themeColor)
  984. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  985. .switchPointColor(Color.White)
  986. .margin({ right: 18 })
  987. .onChange((checked: boolean) => {
  988. this.isSavePlayMode = checked;
  989. PreferencesUtil.put(SettingPage.iS_SAVE_PLAY_MODE, this.isSavePlayMode)
  990. })
  991. .width(50)
  992. .height(30);
  993. }
  994. .height(55)
  995. .clickEffect({ level: ClickEffectLevel.HEAVY })
  996. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  997. .visibility(Visibility.None)
  998. Row() {
  999. Text('与其他应用同时播放')
  1000. .margin({ left: 18 })
  1001. .fontSize(15)
  1002. .fontColor(Color.Gray)
  1003. .fontWeight(480)
  1004. .layoutWeight(1)
  1005. Toggle({ type: ToggleType.Switch, isOn: this.isSameTimePlay })
  1006. .selectedColor(this.themeColor)
  1007. .switchPointColor(Color.White)
  1008. .margin({ right: 18 })
  1009. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1010. .onChange((checked: boolean) => {
  1011. this.isSameTimePlay = checked;
  1012. PreferencesUtil.put(SettingPage.IS_SAMETIME_PLAY, this.isSameTimePlay)
  1013. })
  1014. .width(50)
  1015. .height(30);
  1016. }
  1017. .height(55).clickEffect({ level: ClickEffectLevel.HEAVY })
  1018. .visibility(Visibility.None)
  1019. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1020. // 播放背景随音乐封面
  1021. Row() {
  1022. Text('播放背景随音乐封面')
  1023. .margin({ left: 18 })
  1024. .fontSize(15)
  1025. .fontColor(Color.Gray)
  1026. .fontWeight(480)
  1027. .layoutWeight(1)
  1028. Toggle({ type: ToggleType.Switch, isOn: this.isMusicBGCover })
  1029. .selectedColor(this.themeColor)
  1030. .switchPointColor(Color.White)
  1031. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1032. .margin({ right: 18 })
  1033. .onChange((checked: boolean) => {
  1034. this.isMusicBGCover = checked;
  1035. PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER, this.isMusicBGCover)
  1036. })
  1037. .width(50)
  1038. .height(30);
  1039. }
  1040. .height(55)
  1041. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1042. }
  1043. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  1044. .animation({ duration: 500, curve: Curve.Ease, delay: 400 }))
  1045. .backgroundColor($r('app.color.settings_background_main'))
  1046. .borderRadius(20)
  1047. .margin({
  1048. left: 0,
  1049. right: 0,
  1050. top: 10,
  1051. bottom: 10
  1052. })
  1053. .padding(0)
  1054. // API设置分组
  1055. this.apiBuilder()
  1056. //设置教程
  1057. this.jcBuilder()
  1058. //显示与隐藏设置
  1059. this.xsBuilder()
  1060. //空白
  1061. Column() {
  1062. Blank()
  1063. .height(88)
  1064. }.height(88)
  1065. }
  1066. .margin({
  1067. left: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 35 : 20,
  1068. right: this.currentBreakpoint !== BreakpointTypeEnum.SM ? 35 : 20,
  1069. top: 20,
  1070. bottom: 20
  1071. })
  1072. .justifyContent(FlexAlign.Start)
  1073. }
  1074. .scrollBar(BarState.Auto)
  1075. .height(px2vp(DisplayUtil.getHeight() - AppUtil.getStatusBarHeight() - AppUtil.getNavigationIndicatorHeight()))
  1076. .width('100%')
  1077. .margin({ bottom: 10 })
  1078. .backgroundColor($r('app.color.settings_background'))
  1079. }
  1080. .height('100%')
  1081. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
  1082. }
  1083. @Builder
  1084. xsBuilder() {
  1085. // 显示和隐藏分组
  1086. Column() {
  1087. Row() {
  1088. Text('显示隐藏')
  1089. .margin({ left: 18, right: 20 })
  1090. .fontSize(16)
  1091. .fontColor(Color.Gray)
  1092. .fontWeight(480)
  1093. .layoutWeight(1)
  1094. }
  1095. .onClick(() => {
  1096. ToastUtil.showToast(this.appIdentifier)
  1097. PreferencesUtil.putSync('isShowWX',true)
  1098. })
  1099. .height(48)
  1100. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1101. Row() {
  1102. Text('显示分类导航')
  1103. .margin({ left: 18 })
  1104. .fontSize(15)
  1105. .fontColor(Color.Gray)
  1106. .fontWeight(480)
  1107. .layoutWeight(1)
  1108. Toggle({ type: ToggleType.Switch, isOn: this.isShowTitleBar })
  1109. .selectedColor(this.themeColor)
  1110. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1111. .switchPointColor(Color.White)
  1112. .margin({ right: 18 })
  1113. .onChange((checked: boolean) => {
  1114. this.isShowTitleBar = checked;
  1115. PreferencesUtil.put(SettingPage.IS_SHOW_TITLTBAR, this.isShowTitleBar)
  1116. this.sendChangeEvent()
  1117. })
  1118. .width(50)
  1119. .height(30);
  1120. }
  1121. .height(55)
  1122. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1123. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1124. Row() {
  1125. Text('显示播放全部')
  1126. .margin({ left: 18 })
  1127. .fontSize(15)
  1128. .fontColor(Color.Gray)
  1129. .fontWeight(480)
  1130. .layoutWeight(1)
  1131. Toggle({ type: ToggleType.Switch, isOn: this.isShowAllBar })
  1132. .selectedColor(this.themeColor)
  1133. .switchPointColor(Color.White)
  1134. .margin({ right: 18 })
  1135. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1136. .onChange((checked: boolean) => {
  1137. this.isShowAllBar = checked;
  1138. PreferencesUtil.put(SettingPage.IS_SHOW_ALLBAR, this.isShowAllBar)
  1139. this.sendChangeEvent()
  1140. })
  1141. .width(50)
  1142. .height(30);
  1143. }
  1144. .height(55)
  1145. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1146. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1147. // 显示私密音频
  1148. Row() {
  1149. Text('显示私密音频')
  1150. .margin({ left: 18 })
  1151. .fontSize(15)
  1152. .fontColor(Color.Gray)
  1153. .fontWeight(480)
  1154. .layoutWeight(1)
  1155. Toggle({ type: ToggleType.Switch, isOn: this.isShowSimi })
  1156. .selectedColor(this.themeColor)
  1157. .switchPointColor(Color.White)
  1158. .margin({ right: 18 })
  1159. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1160. .onChange((checked: boolean) => {
  1161. this.isShowSimi = checked;
  1162. PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isShowSimi)
  1163. this.sendChangeEvent()
  1164. })
  1165. .width(50)
  1166. .height(30);
  1167. }
  1168. .height(55)
  1169. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1170. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1171. // 播放页单行歌词
  1172. Row() {
  1173. Text('播放页单行歌词')
  1174. .margin({ left: 18 })
  1175. .fontSize(15)
  1176. .fontColor(Color.Gray)
  1177. .fontWeight(480)
  1178. .layoutWeight(1)
  1179. Toggle({ type: ToggleType.Switch, isOn: this.isShowSingleLineLyric })
  1180. .selectedColor(this.themeColor)
  1181. .switchPointColor(Color.White)
  1182. .margin({ right: 18 })
  1183. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1184. .onChange((checked: boolean) => {
  1185. this.isShowSingleLineLyric = checked;
  1186. PreferencesUtil.put(SettingPage.IS_SHOW_SLLYRIC, this.isShowSingleLineLyric)
  1187. this.sendChangeEvent()
  1188. })
  1189. .width(50)
  1190. .height(30);
  1191. }
  1192. .height(55)
  1193. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1194. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1195. // 二级菜单新风格
  1196. Row() {
  1197. Text('二级菜单新风格')
  1198. .margin({ left: 18 })
  1199. .fontSize(15)
  1200. .fontColor(Color.Gray)
  1201. .fontWeight(480)
  1202. .layoutWeight(1)
  1203. Toggle({ type: ToggleType.Switch, isOn: this.isShowHeader })
  1204. .selectedColor(this.themeColor)
  1205. .switchPointColor(Color.White)
  1206. .margin({ right: 18 })
  1207. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1208. .onChange((checked: boolean) => {
  1209. this.isShowHeader = checked;
  1210. PreferencesUtil.put(SettingPage.IS_SHOW_HEADER, this.isShowHeader)
  1211. this.sendChangeEvent()
  1212. })
  1213. .width(50)
  1214. .height(30);
  1215. }
  1216. .height(55)
  1217. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1218. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1219. // 播放页返回键
  1220. Row() {
  1221. Text('显示播放页返回键')
  1222. .margin({ left: 18 })
  1223. .fontSize(15)
  1224. .fontColor(Color.Gray)
  1225. .fontWeight(480)
  1226. .layoutWeight(1)
  1227. Toggle({ type: ToggleType.Switch, isOn: this.isShowPlayPageBack })
  1228. .selectedColor(this.themeColor)
  1229. .switchPointColor(Color.White)
  1230. .margin({ right: 18 })
  1231. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1232. .onChange((checked: boolean) => {
  1233. this.isShowPlayPageBack = checked;
  1234. PreferencesUtil.put(SettingPage.IS_SHOW_PLAYPAGE_BACK, this.isShowPlayPageBack)
  1235. this.sendChangeEvent()
  1236. })
  1237. .width(50)
  1238. .height(30);
  1239. }
  1240. .height(55)
  1241. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1242. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1243. // 显示我的收藏
  1244. Row() {
  1245. Text('显示我的收藏')
  1246. .margin({ left: 18 })
  1247. .fontSize(15)
  1248. .fontColor(Color.Gray)
  1249. .fontWeight(480)
  1250. .layoutWeight(1)
  1251. Toggle({ type: ToggleType.Switch, isOn: this.isShowFAV })
  1252. .selectedColor(this.themeColor)
  1253. .switchPointColor(Color.White)
  1254. .margin({ right: 18 })
  1255. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1256. .onChange((checked: boolean) => {
  1257. this.isShowFAV = checked;
  1258. PreferencesUtil.put(SettingPage.IS_SHOW_FAV, this.isShowFAV)
  1259. this.sendChangeEvent()
  1260. })
  1261. .width(50)
  1262. .height(30);
  1263. }
  1264. .height(55)
  1265. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1266. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1267. // 显示最近播放
  1268. Row() {
  1269. Text('显示最近播放')
  1270. .margin({ left: 18 })
  1271. .fontSize(15)
  1272. .fontColor(Color.Gray)
  1273. .fontWeight(480)
  1274. .layoutWeight(1)
  1275. Toggle({ type: ToggleType.Switch, isOn: this.isShowHistory })
  1276. .selectedColor(this.themeColor)
  1277. .switchPointColor(Color.White)
  1278. .margin({ right: 18 })
  1279. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1280. .onChange((checked: boolean) => {
  1281. this.isShowHistory = checked;
  1282. PreferencesUtil.put(SettingPage.IS_SHOW_HISTORY, this.isShowHistory)
  1283. this.sendChangeEvent()
  1284. })
  1285. .width(50)
  1286. .height(30);
  1287. }
  1288. .height(55)
  1289. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1290. }
  1291. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  1292. .animation({ duration: 500, curve: Curve.Ease, delay: 600 }))
  1293. .backgroundColor($r('app.color.settings_background_main'))
  1294. .borderRadius(20)
  1295. .margin({
  1296. left: 0,
  1297. right: 0,
  1298. top: 10,
  1299. bottom: 20
  1300. })
  1301. .padding(0)
  1302. }
  1303. @Builder
  1304. jcBuilder() {
  1305. //设置教程
  1306. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  1307. Column() {
  1308. Row() {
  1309. Text('设置教程:')
  1310. .margin({ left: 18 })
  1311. .fontSize(15)
  1312. .fontColor(Color.Gray)
  1313. .fontWeight(480)
  1314. Text('点击进Q群讨论')
  1315. .margin({ right: 10 })
  1316. .fontSize(15)
  1317. .fontColor(Color.Gray)
  1318. .layoutWeight(1)
  1319. Blank()
  1320. // 右侧箭头
  1321. Image($r('app.media.arrow_right'))
  1322. .width(22)
  1323. .height(22)
  1324. .margin({ left: 20, right: 20 })
  1325. .align(Alignment.Center)
  1326. }
  1327. .height(55)
  1328. }
  1329. }
  1330. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1331. .onClick(() => {
  1332. const qqUrl =
  1333. `mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${CommonConstants.QQ_GROUP}&card_type=group&source=external`
  1334. let context = this.getUIContext().getHostContext() as common.UIAbilityContext
  1335. context.openLink(qqUrl, {})
  1336. })
  1337. .backgroundColor($r('app.color.settings_background_main'))
  1338. .borderRadius(15)
  1339. .margin({ top: 0, bottom: 20 })
  1340. .padding(0)
  1341. }
  1342. @Builder
  1343. apiBuilder() {
  1344. // API设置分组
  1345. Column() {
  1346. Row() {
  1347. Text('API设置')
  1348. .margin({ left: 18, right: 20 })
  1349. .fontSize(16)
  1350. .fontColor(Color.Gray)
  1351. .fontWeight(480)
  1352. .layoutWeight(1)
  1353. }
  1354. .height(48)
  1355. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1356. // 歌词API
  1357. Button({ type: ButtonType.Normal, stateEffect: true }) {
  1358. Row() {
  1359. Text('歌词:')
  1360. .margin({ left: 18, right: 6 })
  1361. .fontSize(15)
  1362. .fontColor(Color.Gray)
  1363. Text(this.lyricApiUrl)
  1364. .margin({ right: 10 })
  1365. .fontSize(15)
  1366. .fontColor(Color.Gray)
  1367. .layoutWeight(1)
  1368. Image(this.isDarkMode ? $r('app.media.rename2') : $r('app.media.rename'))
  1369. .width(20)
  1370. .height(20)
  1371. .margin({ right: 18 })
  1372. }
  1373. }
  1374. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1375. .backgroundColor(Color.Transparent)
  1376. .onClick(() => {
  1377. this.apiDialogType = 'lyric'
  1378. this.tempApiUrl = this.lyricApiUrl
  1379. this.apiDialogController.open()
  1380. })
  1381. .height(55)
  1382. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  1383. // 封面API
  1384. Button({ type: ButtonType.Normal, stateEffect: true }) {
  1385. Row() {
  1386. Text('封面:')
  1387. .margin({ left: 18, right: 6 })
  1388. .fontSize(15)
  1389. .fontColor(Color.Gray)
  1390. Text(this.coverApiUrl)
  1391. .margin({ right: 10 })
  1392. .fontSize(15)
  1393. .fontColor(Color.Gray)
  1394. .layoutWeight(1)
  1395. Image(this.isDarkMode ? $r('app.media.rename2') : $r('app.media.rename'))
  1396. .width(20)
  1397. .height(20)
  1398. .margin({ right: 18 })
  1399. }
  1400. }
  1401. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1402. .backgroundColor(Color.Transparent)
  1403. .onClick(() => {
  1404. this.apiDialogType = 'cover'
  1405. this.tempApiUrl = this.coverApiUrl
  1406. this.apiDialogController.open()
  1407. })
  1408. .height(55)
  1409. }
  1410. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  1411. .animation({ duration: 500, curve: Curve.Ease, delay: 600 }))
  1412. .backgroundColor($r('app.color.settings_background_main'))
  1413. .borderRadius(20)
  1414. .margin({
  1415. left: 0,
  1416. right: 0,
  1417. top: 10,
  1418. bottom: 20
  1419. })
  1420. .padding(0)
  1421. }
  1422. //发送广播通知更新UI
  1423. sendChangeEvent() {
  1424. const eventData: emitter.EventData = {};
  1425. emitter.emit({ eventId: 333 }, eventData); // 发送广播通知更新doSwipBack
  1426. }
  1427. goSelectImage() {
  1428. let selectUris: Array<string> = [];
  1429. let photoPicker = new photoAccessHelper.PhotoViewPicker();
  1430. let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
  1431. photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
  1432. photoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目
  1433. photoPicker.select(photoSelectOptions).then(async (photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
  1434. //用一个全局变量存储返回的uri
  1435. selectUris = photoSelectResult.photoUris;
  1436. console.info('photoViewPicker.select to file succeed and uris are:' + selectUris);
  1437. //使用fs.openSync接口,通过uri打开这个文件得到fd
  1438. let file = fileIo.openSync(selectUris[0], fileIo.OpenMode.READ_ONLY);
  1439. console.info('file fd: ' + file.fd);
  1440. const timestamp: number = Math.floor(Date.now() / 1000);
  1441. let name = timestamp + "_homebg"
  1442. let imagePath = this.context.filesDir + FileUtil.separator + name
  1443. imagePath = fileUri.getUriFromPath(imagePath)
  1444. let file2 = fileIo.openSync(imagePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE)
  1445. fileIo.copyFileSync(file.fd, file2.fd)
  1446. fileIo.closeSync(file);
  1447. fileIo.closeSync(file2);
  1448. this.customizeBgPath = imagePath
  1449. PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG_PATH, this.customizeBgPath)
  1450. this.sendChangeEvent()
  1451. }).catch((err: BusinessError) => {
  1452. console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
  1453. })
  1454. }
  1455. @Builder
  1456. customizeBgSheet() {
  1457. Scroll() {
  1458. Column() {
  1459. this.CustomizeBg()
  1460. }
  1461. }
  1462. .width('100%')
  1463. .height('100%')
  1464. }
  1465. @Builder
  1466. CustomizeBg() {
  1467. Column() {
  1468. Image(this.customizeBgPath)
  1469. .height('42%')
  1470. .alt($r('app.color.white'))
  1471. .objectFit(ImageFit.Contain)
  1472. .borderRadius(20)
  1473. .clip(true)
  1474. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1475. .blur(this.blurValue)
  1476. .brightness(this.bgBrightness + 0.8)
  1477. .margin({ left: 30, right: 30, bottom: 20 })
  1478. Row() {
  1479. Row() {
  1480. Button('选择图片')
  1481. .fontColor(Color.White)
  1482. .fontSize(12)
  1483. .height(48)
  1484. .width(100)
  1485. .clickEffect({ level: ClickEffectLevel.HEAVY })
  1486. .backgroundColor(this.themeColor)
  1487. .stateEffect(true)
  1488. .onClick(async () => {
  1489. this.goSelectImage()
  1490. })
  1491. }
  1492. .height('100%')
  1493. .justifyContent(FlexAlign.Center)
  1494. .layoutWeight(1)
  1495. }
  1496. .width('100%')
  1497. .height(58)
  1498. .margin({ bottom: 20 })
  1499. Column() {
  1500. Row() {
  1501. Text('自定义背景:')
  1502. .margin({ left: 18 })
  1503. .fontSize(15)
  1504. .fontColor($r('app.color.text_color'))
  1505. .fontWeight(480)
  1506. .layoutWeight(1)
  1507. Toggle({ type: ToggleType.Switch, isOn: this.isCustomizeBg })
  1508. .selectedColor(this.themeColor)
  1509. .switchPointColor(Color.White)
  1510. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
  1511. .margin({ right: 18 })
  1512. .onChange((checked: boolean) => {
  1513. this.isCustomizeBg = checked;
  1514. PreferencesUtil.put(SettingPage.IS_CUSTOMIZE_BG, this.isCustomizeBg)
  1515. this.sendChangeEvent()
  1516. })
  1517. .width(50)
  1518. .height(30);
  1519. }
  1520. .height(55)
  1521. }
  1522. .backgroundColor($r('app.color.settings_background_main'))
  1523. .borderRadius(15)
  1524. .margin({
  1525. left: 30,
  1526. right: 30,
  1527. top: 0,
  1528. bottom: 20
  1529. })
  1530. .padding(0)
  1531. Column() {
  1532. Row() {
  1533. Text('背景模糊:')
  1534. .margin({ left: 18 })
  1535. .fontSize(15)
  1536. .fontColor($r('app.color.text_color'))
  1537. .fontWeight(480)
  1538. Slider({
  1539. value: this.blurValue,
  1540. min: 0,
  1541. max: 100,
  1542. step: 1,
  1543. style: SliderStyle.OutSet
  1544. })
  1545. .blockColor(this.themeColor)
  1546. .trackColor($r('app.color.speed_text_color'))
  1547. .selectedColor($r('app.color.index_background'))
  1548. .trackThickness(8)
  1549. .onChange((value: number) => {
  1550. this.blurValue = value;
  1551. PreferencesUtil.put(SettingPage.CUSTOMIZE_BG_BLUR, this.blurValue)
  1552. this.sendChangeEvent()
  1553. })
  1554. .layoutWeight(1)
  1555. }
  1556. .height(55)
  1557. }
  1558. .backgroundColor($r('app.color.settings_background_main'))
  1559. .borderRadius(15)
  1560. .margin({
  1561. left: 30,
  1562. right: 30,
  1563. top: 0,
  1564. bottom: 20
  1565. })
  1566. .padding(0)
  1567. Column() {
  1568. Row() {
  1569. Text('背景亮度:')
  1570. .margin({ left: 18 })
  1571. .fontSize(15)
  1572. .fontColor($r('app.color.text_color'))
  1573. .fontWeight(480)
  1574. Slider({
  1575. value: this.bgBrightness,
  1576. min: -0.4,
  1577. max: 0.4,
  1578. step: 0.1,
  1579. style: SliderStyle.OutSet
  1580. })
  1581. .blockColor(this.themeColor)
  1582. .trackColor($r('app.color.speed_text_color'))
  1583. .selectedColor($r('app.color.index_background'))
  1584. .trackThickness(8)
  1585. .onChange((value: number) => {
  1586. this.bgBrightness = value;
  1587. PreferencesUtil.put(SettingPage.BG_BRIGHTNESS, this.bgBrightness)
  1588. this.sendChangeEvent()
  1589. })
  1590. .layoutWeight(1)
  1591. }
  1592. .height(55)
  1593. }
  1594. .backgroundColor($r('app.color.settings_background_main'))
  1595. .borderRadius(15)
  1596. .margin({
  1597. left: 30,
  1598. right: 30,
  1599. top: 0,
  1600. bottom: 20
  1601. })
  1602. .padding(0)
  1603. }
  1604. .margin({ bottom: 30 })
  1605. }
  1606. // 判断当前主题色是否为自定义色
  1607. isCustomThemeColor(): boolean {
  1608. for (let i = 0; i < SettingPage.THEME_COLOR_LIST.length - 1; i++) {
  1609. if (SettingPage.THEME_COLOR_LIST[i].color === this.themeColor) {
  1610. return false;
  1611. }
  1612. }
  1613. return true;
  1614. }
  1615. // 会员功能弹窗
  1616. showVipDialog() {
  1617. DialogHelper.showCustomContentDialog({
  1618. dialogId: 'vip',
  1619. title: "友情提示",
  1620. autoCancel: false,
  1621. backCancel: true,
  1622. contentBuilder: () => {
  1623. this.customVipBuilder("该功能需开通会员,非常感谢您的支持!")
  1624. },
  1625. buttons: [],
  1626. })
  1627. }
  1628. @Builder
  1629. customVipBuilder(content: string) {
  1630. Column() {
  1631. Text(content)
  1632. .fontColor(Color.Gray)
  1633. .fontSize(16)
  1634. .alignSelf(ItemAlign.Start)
  1635. .margin({ bottom: 15 })
  1636. Row() {
  1637. Button('取消')
  1638. .fontColor(Color.White)
  1639. .backgroundColor(this.themeColor)
  1640. .height(50)
  1641. .layoutWeight(1)
  1642. .stateEffect(true)
  1643. .margin({ right: 6 })
  1644. .onClick(() => {
  1645. DialogHelper.closeDialog('vip');
  1646. })
  1647. Button('开通')
  1648. .fontColor(Color.White)
  1649. .layoutWeight(1)
  1650. .height(50)
  1651. .backgroundColor(this.themeColor)
  1652. .stateEffect(true)
  1653. .margin({ left: 6 })
  1654. .onClick(() => {
  1655. this.isThemeSheet = false;
  1656. DialogHelper.closeDialog('vip');
  1657. this.mType = 1//跳转到用户中心
  1658. // router.pushUrl({
  1659. // url: 'pages/UserCenter'
  1660. // }, router.RouterMode.Single);
  1661. })
  1662. }
  1663. }
  1664. .width("100%")
  1665. .padding(10)
  1666. }
  1667. @State appIdentifier:string=''
  1668. geIDD() {
  1669. // 获取应用签名等信息示例代码
  1670. let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
  1671. bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
  1672. try {
  1673. bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
  1674. hilog.info(0x0000, 'testTag11', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
  1675. let inde = JSON.stringify(data)
  1676. this.appIdentifier = inde.substring(inde.indexOf('appIdentifier'),inde.indexOf('"certificate'))
  1677. hilog.info(0x0000, 'testTag11', 'appIdentifier Data: %{public}s', this.appIdentifier);
  1678. }).catch((err: BusinessError) => {
  1679. hilog.error(0x0000, 'testTag11', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
  1680. });
  1681. } catch (err) {
  1682. let message = (err as BusinessError).message;
  1683. hilog.error(0x0000, 'testTag33', 'getBundleInfoForSelf failed: %{public}s', message);
  1684. }
  1685. }
  1686. }
  1687. // 主题色类型声明
  1688. export interface ThemeColorItem {
  1689. name: string;
  1690. color: string;
  1691. isVip: boolean;
  1692. }
  1693. // 工具函数:将一维数组分成每行2个的二维数组
  1694. function chunkArray<T>(arr: Array<T>, size: number): Array<Array<T>> {
  1695. const result: Array<Array<T>> = [];
  1696. for (let i = 0; i < arr.length; i += size) {
  1697. const row: Array<T> = [];
  1698. for (let j = 0; j < size; j++) {
  1699. if (i + j < arr.length) {
  1700. row.push(arr[i + j]);
  1701. }
  1702. }
  1703. result.push(row);
  1704. }
  1705. return result;
  1706. }