|
|
@@ -300,6 +300,20 @@ const ITEM_HEIGHT_SMALL: number = 48; // 列表项小高度
|
|
|
const ITEM_HEIGHT: number = 65; // 列表项中高度
|
|
|
const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
|
|
|
|
|
|
+/**
|
|
|
+ * 排序模式枚举
|
|
|
+ * 定义各种排序方式的升序基准值
|
|
|
+ */
|
|
|
+export enum SortMode {
|
|
|
+ ByArtist = 0, // 按艺术家升序
|
|
|
+ ByAlbum = 2, // 按专辑升序
|
|
|
+ ByName = 4, // 按名称升序
|
|
|
+ ByTime = 6, // 按时间升序
|
|
|
+ ByAddTime = 7, // 按添加时间(只有降序)
|
|
|
+ ByCount = 8, // 按数量升序
|
|
|
+ ByDiscTrack = 10 // 按碟片编号-音轨号升序
|
|
|
+}
|
|
|
+
|
|
|
//功能强大的音乐播放器
|
|
|
@Preview
|
|
|
@Component
|
|
|
@@ -2215,69 +2229,35 @@ export struct LocalMusic {
|
|
|
SortMenuBuilder() {
|
|
|
Menu() {
|
|
|
MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.text_and_arrow_up')),
|
|
|
- content: "按艺术家升序"
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.person')),
|
|
|
+ content: "按艺术家",
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByArtist),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByArtist) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(0)
|
|
|
- })
|
|
|
- MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.text_and_arrow_down')),
|
|
|
- content: "按艺术家降序"
|
|
|
- })
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(1)
|
|
|
- })
|
|
|
MenuItem({
|
|
|
symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.textformat_size_square')),
|
|
|
- content: "按专辑升序"
|
|
|
+ content: "按专辑",
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByAlbum),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByAlbum) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(2)
|
|
|
- })
|
|
|
MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.character_arrow_clockwise')),
|
|
|
- content: "按专辑降序"
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.textformat')),
|
|
|
+ content: "按名称",
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByName),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByName) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(3)
|
|
|
- })
|
|
|
- MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.text_and_arrow_up')),
|
|
|
- content: $r('app.string.sort_by_name')
|
|
|
- })
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(4)
|
|
|
- })
|
|
|
- MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.text_and_arrow_down')),
|
|
|
- content: '按名称降序'
|
|
|
- })
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(5)
|
|
|
- })
|
|
|
MenuItem({
|
|
|
symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.clock')),
|
|
|
- content: $r('app.string.sort_by_time')
|
|
|
- })
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(6)
|
|
|
- })
|
|
|
-
|
|
|
- MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.timer')),
|
|
|
- content: '按添加时间降序'
|
|
|
+ content: $r('app.string.sort_by_time'),
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByTime),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByTime) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(7)
|
|
|
- })
|
|
|
MenuItem({
|
|
|
symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.music')),
|
|
|
- content: '按碟片编号-音轨号升序'
|
|
|
+ content: '按碟片音轨号',
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByDiscTrack),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByDiscTrack) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(10)
|
|
|
- })
|
|
|
.visibility((this.modeType==0||(this.modeType==3&&this.isCanBack))?Visibility.Visible:Visibility.None)
|
|
|
|
|
|
}.attributeModifier(new MenuModifier())
|
|
|
@@ -2286,38 +2266,41 @@ export struct LocalMusic {
|
|
|
@Builder
|
|
|
SortMenuForArtistAblumBuilder() {
|
|
|
Menu() {
|
|
|
-
|
|
|
MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.text_and_arrow_up')),
|
|
|
- content: $r('app.string.sort_by_name')
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.textformat')),
|
|
|
+ content: "按名称",
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByName),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByName) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(4)
|
|
|
- })
|
|
|
MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.text_and_arrow_down')),
|
|
|
- content: '按名称降序'
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.clock')),
|
|
|
+ content: '按数量',
|
|
|
+ builder: this.SubSortBuilder(SortMode.ByCount),
|
|
|
+ symbolEndIcon: this.isSortTypeInRange(SortMode.ByCount) ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
- .onClick(async () => {
|
|
|
- await this.doSortType(5)
|
|
|
- })
|
|
|
+
|
|
|
+ }.attributeModifier(new MenuModifier())
|
|
|
+ }
|
|
|
+
|
|
|
+ @Builder SubSortBuilder(sortType: number){
|
|
|
+ Menu(){
|
|
|
MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.clock')),
|
|
|
- content: '按数量升序'
|
|
|
+ content: "升序",
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.arrow_up')),
|
|
|
+ symbolEndIcon: this.sortType === sortType ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
.onClick(async () => {
|
|
|
- await this.doSortType(8)
|
|
|
+ await this.doSortType(sortType)
|
|
|
})
|
|
|
-
|
|
|
MenuItem({
|
|
|
- symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.timer')),
|
|
|
- content: '按数量降序'
|
|
|
+ content: "降序",
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.arrow_down')),
|
|
|
+ symbolEndIcon: this.sortType === sortType + 1 ? new SymbolGlyphModifier($r('sys.symbol.checkmark')) : undefined
|
|
|
})
|
|
|
.onClick(async () => {
|
|
|
- await this.doSortType(9)
|
|
|
+ await this.doSortType(sortType + 1) // 降序的sortType = 升序的sortType + 1
|
|
|
})
|
|
|
-
|
|
|
- }.attributeModifier(new MenuModifier())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2434,6 +2417,16 @@ export struct LocalMusic {
|
|
|
return PreferencesUtil.getNumberSync(storageKey, defaultSortType);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查当前sortType是否在指定排序类型的范围内
|
|
|
+ * 用于判断是否显示打勾图标
|
|
|
+ * @param baseSortType 基础排序类型(升序的值)
|
|
|
+ * @returns 如果当前sortType是该排序类型的升序或降序,返回true
|
|
|
+ */
|
|
|
+ private isSortTypeInRange(baseSortType: number): boolean {
|
|
|
+ return this.sortType === baseSortType || this.sortType === baseSortType + 1;
|
|
|
+ }
|
|
|
+
|
|
|
showSheelDialog() {
|
|
|
// if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
|
|
|
// this.showTips()
|