Skip to content

Commit 222ebb4

Browse files
committed
分类的排序变更
1 parent 8968ec2 commit 222ebb4

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

SwiftPamphletApp.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
08026C522869B43D00792EF1 /* 191.md in Resources */ = {isa = PBXBuildFile; fileRef = 08026C3E2869AD7800792EF1 /* 191.md */; };
2626
08026C532869B44400792EF1 /* 192.md in Resources */ = {isa = PBXBuildFile; fileRef = 08026C3F2869B00D00792EF1 /* 192.md */; };
2727
08038767276700F100519B15 /* CCYRESTfulAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08038766276700F100519B15 /* CCYRESTfulAPI.swift */; };
28+
0805F4962BAAABEA0008BB52 /* ViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0805F4952BAAABEA0008BB52 /* ViewStyle.swift */; };
2829
083554E12756503B0095E0EE /* AnimateLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 083554E02756503B0095E0EE /* AnimateLayout.swift */; };
2930
083554E327572BB60095E0EE /* AppVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 083554E227572BB60095E0EE /* AppVM.swift */; };
3031
08397E232B9EE8F400DFDD02 /* InfoDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */; };
@@ -290,6 +291,7 @@
290291
08026C422869B22E00792EF1 /* 176.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = 176.md; sourceTree = "<group>"; };
291292
08026C502869B41B00792EF1 /* 190.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 190.md; sourceTree = "<group>"; };
292293
08038766276700F100519B15 /* CCYRESTfulAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCYRESTfulAPI.swift; sourceTree = "<group>"; };
294+
0805F4952BAAABEA0008BB52 /* ViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewStyle.swift; sourceTree = "<group>"; };
293295
083554E02756503B0095E0EE /* AnimateLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimateLayout.swift; sourceTree = "<group>"; };
294296
083554E227572BB60095E0EE /* AppVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVM.swift; sourceTree = "<group>"; };
295297
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoDataModel.swift; sourceTree = "<group>"; };
@@ -1182,6 +1184,7 @@
11821184
isa = PBXGroup;
11831185
children = (
11841186
086A5F512744EF4C00FECE02 /* ViewComponet.swift */,
1187+
0805F4952BAAABEA0008BB52 /* ViewStyle.swift */,
11851188
);
11861189
path = ViewComponet;
11871190
sourceTree = "<group>";
@@ -1712,6 +1715,7 @@
17121715
086A5F3A2744EDA500FECE02 /* APIRequest.swift in Sources */,
17131716
086A5F522744EF4C00FECE02 /* ViewComponet.swift in Sources */,
17141717
086A5F672754C27900FECE02 /* DBHandler.swift in Sources */,
1718+
0805F4962BAAABEA0008BB52 /* ViewStyle.swift in Sources */,
17151719
08BE637927CDCFD9002BC6A8 /* DataSortingListView.swift in Sources */,
17161720
08BE636E27C8D6FD002BC6A8 /* PlayLazyVGridAndLazyHGridView.swift in Sources */,
17171721
08522BE227CF52ED005FF059 /* PlayColor.swift in Sources */,

SwiftPamphletApp/InfoOrganizer/Category/CategoryListView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftData
1010

1111
struct CategoryListView: View {
1212
@Environment(\.modelContext) var modelContext
13-
@Query(IOCategory.all) var cates: [IOCategory]
13+
@Query(IOCategory.allOrderByName) var cates: [IOCategory]
1414
@State var selectCate: IOCategory?
1515

1616
var body: some View {

SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct InfoListView: View {
1414
@Binding var selectInfo:IOInfo?
1515
@State private var sortOrder = [SortDescriptor(\IOInfo.updateDate, order: .reverse)]
1616

17-
@Query(sort: [SortDescriptor(\IOCategory.updateDate, order: .reverse)]) var cates: [IOCategory]
17+
@Query(sort: [SortDescriptor(\IOCategory.name, order: .forward)]) var cates: [IOCategory]
1818
@State private var filterCate = ""
1919
@State var limit: Int = 100
2020
@State var filterStar: Bool = false
@@ -39,9 +39,8 @@ struct InfoListView: View {
3939
}
4040
ToolbarItem(placement: .navigation) {
4141
Toggle(isOn: $filterStar) {
42-
Image(systemName: filterStar ? "star.fill" : "star")
4342
}
44-
.toggleStyle(.button)
43+
.toggleStyle(SymbolToggleStyle(systemImage: "star.fill", activeColor: .yellow))
4544
}
4645
ToolbarItem(placement: .navigation) {
4746
Menu("Sort", systemImage: "arrow.up.arrow.down.square") {

SwiftPamphletApp/InfoOrganizer/Model/InfoDataModel.swift

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class IOCategory {
6363
let fd = FetchDescriptor(sortBy: [SortDescriptor(\IOCategory.updateDate, order: .reverse)])
6464
return fd
6565
}
66+
static var allOrderByName: FetchDescriptor<IOCategory> {
67+
let fd = FetchDescriptor(sortBy: [SortDescriptor(\IOCategory.name, order: .forward)])
68+
return fd
69+
}
6670

6771
static func delete(_ cate: IOCategory) {
6872
if let context = cate.modelContext {

SwiftPamphletApp/Setting/SettingView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct SettingView: View {
2828
}
2929
.padding(20)
3030
.tabItem {
31-
Label("通常", systemImage: "gearshape")
31+
Label("设置", systemImage: "gearshape")
3232
}
3333
}
3434
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// ViewStyle.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/3/20.
6+
//
7+
8+
import SwiftUI
9+
10+
struct SymbolToggleStyle: ToggleStyle {
11+
12+
var systemImage: String = "checkmark"
13+
var activeColor: Color = .green
14+
15+
func makeBody(configuration: Configuration) -> some View {
16+
HStack {
17+
configuration.label
18+
19+
Spacer()
20+
21+
RoundedRectangle(cornerRadius: 25)
22+
.fill(configuration.isOn ? activeColor : Color(.lightGray))
23+
.overlay {
24+
Circle()
25+
.fill(.white)
26+
.padding(3)
27+
.overlay {
28+
Image(systemName: systemImage)
29+
.foregroundColor(configuration.isOn ? activeColor : Color(.lightGray))
30+
}
31+
.offset(x: configuration.isOn ? 10 : -10)
32+
33+
}
34+
.frame(width: 50, height: 25)
35+
.onTapGesture {
36+
withAnimation(.spring()) {
37+
configuration.isOn.toggle()
38+
}
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)