Skip to content

Commit

Permalink
Optimize localizable, added Sleep Time (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThreeManager785 authored and WindowsMEMZ committed Oct 12, 2024
1 parent 84e1644 commit 9c8af08
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 84 deletions.
2 changes: 1 addition & 1 deletion DarockBili Watch App/Bangumi/BangumiDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct BangumiDetailView: View {
.tag(2)
.navigationTitle("Bangumi.commnets")
}
.navigationTitle("番剧")
.navigationTitle("Bangumi")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
let headers: HTTPHeaders = [
Expand Down
18 changes: 18 additions & 0 deletions DarockBili Watch App/DarockBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ struct DarockBili_Watch_AppApp: App {
@WKApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@Environment(\.scenePhase) var scenePhase
// Screen Time
@AppStorage("isSleepNotificationOn") var isSleepNotificationOn = false
@AppStorage("notifyHour") var notifyHour = 0
@AppStorage("notifyMinute") var notifyMinute = 0
@AppStorage("IsScreenTimeEnabled") var isScreenTimeEnabled = true
@State var screenTimeCaculateTimer: Timer? = nil
@State var isMemoryWarningPresented = false
Expand All @@ -119,6 +122,8 @@ struct DarockBili_Watch_AppApp: App {
@State var systemResourceRefreshTimer: Timer?
@State var memoryUsage: Float = 0.0
@State var isShowMemoryUsage = false
@State var currentHour = 0
@State var currentMinute = 0
var body: some Scene {
WindowGroup {
if UserDefaults.standard.string(forKey: "NewSignalError") ?? "" != "" {
Expand Down Expand Up @@ -200,6 +205,19 @@ struct DarockBili_Watch_AppApp: App {
timer.invalidate()
}
}
let timer = Timer(timeInterval: 1, repeats: true) { timer in
currentHour = getCurrentTime().hour
currentMinute = getCurrentTime().minute
}
let sleepTimeCheck = Timer(timeInterval: 60, repeats: true) { timer in
if currentHour == notifyHour && currentMinute == notifyMinute && isSleepNotificationOn {
tipWithText(String(localized: "Sleep.notification"), symbol: "bed.double.fill")
}
}
RunLoop.current.add(timer, forMode: .default)
timer.fire()
RunLoop.current.add(sleepTimeCheck, forMode: .default)
sleepTimeCheck.fire()
}
.overlay {
VStack {
Expand Down
4 changes: 2 additions & 2 deletions DarockBili Watch App/Live/LiveDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct LiveDetailView: View {
.bold()
}
}
.navigationTitle("直播")
.navigationTitle("Live")
.navigationBarTitleDisplayMode(.inline)
.sheet(isPresented: $isLivePlayerPresented, content: {LivePlayerView()})
.onAppear {
Expand Down Expand Up @@ -294,7 +294,7 @@ struct LiveDetailView: View {
}
HStack {
Image(systemName: "clock")
Text("\(startTime) 开始")
Text("Live.starting.\(startTime)")
Spacer()
}
.offset(y: publishTimeTextOffset)
Expand Down
8 changes: 4 additions & 4 deletions DarockBili Watch App/Others/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct AboutCredits: View {
if isGenshin {
ZStack(alignment: .center) {
Color.white
Text("原神")
Text("About.genshin")
.font(.system(size: 30, weight: .heavy))
.foregroundColor(.black)
.opacity(genshinOverlayTextOpacity)
Expand All @@ -140,16 +140,16 @@ struct AboutCredits: View {
@State var codeInput = ""
var body: some View {
VStack {
TextField("神秘代码", text: $codeInput)
TextField("About.mystery-code", text: $codeInput)
Button(action: {
if codeInput == "Genshin" {
isGenshin = true
dismiss()
} else {
codeInput = "输入错误"
codeInput = String(localized: "About.mystery-code.error")
}
}, label: {
Text("确认")
Text("About.confirm")
})
}
}
Expand Down
95 changes: 91 additions & 4 deletions DarockBili Watch App/Others/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ struct SettingsView: View {
Text("Settings.battery")
}
})
NavigationLink(destination: {SleepTimeView().navigationTitle("Settings.sleep")}, label: {
HStack {
ZStack {
Color.cyan
.frame(width: 20, height: 20)
.clipShape(Circle())
Image(systemName: "bed.double.fill")
.font(.system(size: 12))
}
Text("Settings.sleep")
}
})
NavigationLink(destination: {FeedbackView().navigationTitle("Settings.feedback")}, label: {
HStack {
ZStack {
Expand Down Expand Up @@ -368,20 +380,20 @@ struct ScreenTimeSettingsView: View {
Button(role: .destructive, action: {
isScreenTimeEnabled = false
}, label: {
Text("关闭“屏幕使用时间”")
Text("Screen-time.off")
})
} footer: {
Text("将不再记录您的屏幕使用时间, 已记录的数据不会被删除")
Text("Screen-time.description")
}
} else {
Section {
Button(action: {
isScreenTimeEnabled = true
}, label: {
Text("开启屏幕使用时间")
Text("Screen-time.on")
})
} footer: {
Text("“屏幕使用时间”会记录您每天使用喵哩喵哩的时间并作出统计")
Text("Screen-time.usage")
}
}
}
Expand Down Expand Up @@ -454,6 +466,81 @@ struct BatterySettingsView: View {
}
}

struct SleepTimeView: View {
@AppStorage("isSleepNotificationOn") var isSleepNotificationOn = false
@AppStorage("notifyHour") var notifyHour = 0
@AppStorage("notifyMinute") var notifyMinute = 0
@State var currentHour = 0
@State var currentMinute = 0
@State var currentSecond = 0
@State var isEditingTime = false
var body: some View {
List {
Section(content: {
Toggle(isOn: $isSleepNotificationOn, label: {
Text("Sleep")
})
if isSleepNotificationOn {
Button(action: {
isEditingTime = true
}, label: {
Text("Sleep.edit.\(notifyHour<10 ? "0\(notifyHour)" : "\(notifyHour)").\(notifyMinute<10 ? "0\(notifyMinute)" : "\(notifyMinute)")")
})
}
}, footer: {
Text("Sleep.discription")
})
Section {
Text("Sleep.current.\(currentHour<10 ? "0\(currentHour)" : "\(currentHour)").\(currentMinute<10 ? "0\(currentMinute)" : "\(currentMinute)").\(currentSecond<10 ? "0\(currentSecond)" : "\(currentSecond)")")
}
}
.navigationTitle("Sleep")
.onAppear {
let timer = Timer(timeInterval: 0.5, repeats: true) { timer in
currentHour = getCurrentTime().hour
currentMinute = getCurrentTime().minute
currentSecond = getCurrentTime().second
}
RunLoop.current.add(timer, forMode: .default)
timer.fire()
}
.sheet(isPresented: $isEditingTime, content: {
VStack {
Text("Sleep.edit.title")
.bold()
HStack {
Picker("Sleep.edit.hour", selection: $notifyHour) {
ForEach(0..<24) { index in
Text("\(index<10 ? "0\(index)" : "\(index)")").tag(index)
}
}
Text(":")
Picker("Sleep.edit.minute", selection: $notifyMinute) {
ForEach(0..<60) { index in
Text("\(index<10 ? "0\(index)" : "\(index)")").tag(index)
}
}
}
}
})
}
}

struct Time {
var hour: Int
var minute: Int
var second: Int
}

func getCurrentTime() -> Time {
let calendar = Calendar.current
let components = calendar.dateComponents([.hour, .minute, .second], from: Date())
let currentTime = Time(hour: components.hour ?? 0, minute: components.minute ?? 0, second: components.second ?? 0)
return currentTime
}



struct DebugMenuView: View {
var body: some View {
List {
Expand Down
2 changes: 1 addition & 1 deletion DarockBili Watch App/PersonalCenter/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct HistoryView: View {
HStack {
Spacer(minLength: 0)
Image(systemName: "xmark.bin.fill")
Text("这里空空如也")
Text("History.none")
Spacer(minLength: 0)
}
.padding()
Expand Down
2 changes: 1 addition & 1 deletion DarockBili Watch App/Video/VideoDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ struct VideoDetailView: View {
}
.accentColor(.white)
.animation(.smooth, value: isLoading)
.navigationTitle("视频")
.navigationTitle("Video")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
let headers: HTTPHeaders = [
Expand Down
2 changes: 1 addition & 1 deletion DarockBili Watch App/Video/VideoDownloadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct VideoDownloadView: View {
Section {
NavigationLink(destination: {DownloadingListView()}, label: {
HStack {
Text("视频下载列表")
Text("Download.title")
Spacer()
Image(systemName: "chevron.right")
.opacity(0.65)
Expand Down
Loading

0 comments on commit 9c8af08

Please sign in to comment.