Skip to content

Commit

Permalink
增加了两处错误处理 (#47)
Browse files Browse the repository at this point in the history
* 增加了两处错误处理

添加了首页首次加载失败时的重试功能,增加了英语翻译。
添加了因app使用过程中断网,搜索失败的呈现。

* Delete DarockBili.xcodeproj/xcuserdata/lion.xcuserdatad/xcschemes/xcschememanagement.plist

---------

Co-authored-by: Mark Chan <[email protected]>
  • Loading branch information
Lightning-Lion and WindowsMEMZ authored Jan 2, 2024
1 parent 470c554 commit f847fde
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions DarockBili Watch App/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ struct MainView: View {
}
})
}
} else if isFailedToLoad {
Button {
LoadNewVideos()
} label: {
Label("加载失败,点击重试", systemImage: "wifi.exclamationmark")
}
} else {
ProgressView()
}
Expand Down
19 changes: 19 additions & 0 deletions DarockBili Watch App/InMain/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct SearchView: View {
Text("似乎在搜索时遇到了一些问题,以下是详细信息")
Text(debugResponse)
}
progressView()
}
}
.onAppear {
Expand Down Expand Up @@ -170,16 +171,34 @@ struct SearchView: View {
videos.append(["Pic": "https:" + video.1["pic"].string!, "Title": video.1["title"].string!.replacingOccurrences(of: "<em class=\"keyword\">", with: "").replacingOccurrences(of: "</em>", with: ""), "View": String(video.1["play"].int!), "Danmaku": String(video.1["danmaku"].int!), "UP": video.1["author"].string!, "BV": video.1["bvid"].string!])
}
debugResponse = respJson.debugDescription
} else {
debugResponse = "请检查您的网络连接状态"
}
}
}
}
} else {
debugResponse = "请检查您的网络连接状态"
}
}
isLoaded = true
}
}
}
@ViewBuilder
func progressView() -> some View {
let showError:Bool = {
if debugResponse.isEmpty {//这样是加载中或加载成功
return users.isEmpty && videos.isEmpty//两个都没有的话那肯定是加载中了,否则就是加载成功了
} else {//加载失败,有错误信息,不需要ProgressView
return false
}
}()
if showError {
ProgressView()
.padding(.top)
}
}
}

struct SearchView_Previews: PreviewProvider {
Expand Down
11 changes: 11 additions & 0 deletions DarockBili Watch App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@
},
"出现问题!" : {

},
"加载失败,点击重试" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Loading failed, tap to retry."
}
}
}
},
"加载更多" : {
"localizations" : {
Expand Down
Binary file not shown.

0 comments on commit f847fde

Please sign in to comment.