Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jul 10, 2021
2 parents 1b854f3 + 8e84256 commit 6e30975
Show file tree
Hide file tree
Showing 45 changed files with 1,427 additions and 1,092 deletions.
81 changes: 71 additions & 10 deletions EhPanda.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions EhPanda/App/EhPandaApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ struct EhPandaApp: App {
}

private extension EhPandaApp {
var setting: Setting? {
var setting: Setting {
store.appState.settings.setting
}
var accentColor: Color? {
setting?.accentColor
var accentColor: Color {
setting.accentColor
}
var preferredColorScheme: ColorScheme? {
setting?.colorScheme ?? .none
setting.colorScheme
}

func onStartTasks() {
DispatchQueue.main.async {
store.dispatch(.initializeStates)
store.dispatch(.fetchFavoriteNames)
store.dispatch(.fetchUserInfo)
}
Expand Down
12 changes: 12 additions & 0 deletions EhPanda/App/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ extension Array where Element: Publisher {
}
}

extension Encodable {
func toData() -> Data? {
try? JSONEncoder().encode(self)
}
}

extension Data {
func toObject<O: Decodable>() -> O? {
try? JSONDecoder().decode(O.self, from: self)
}
}

extension Float {
func fixedRating() -> Float {
let lowerbound = Int(self)
Expand Down
48 changes: 48 additions & 0 deletions EhPanda/App/Tools/AppEnvStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// AppEnvStorage.swift
// EhPanda
//
// Created by 荒木辰造 on R 3/07/10.
//

import SwiftyBeaver

@propertyWrapper
struct AppEnvStorage<T: Encodable> {
private var key: String

private var appEnv: AppEnv {
PersistenceController.fetchAppEnvNonNil()
}

var wrappedValue: T {
get {
let mirror = Mirror(reflecting: appEnv)
for child in mirror.children where child.label == key {
if let value = child.value as? T {
return value
}
}
SwiftyBeaver.error(
"Failed in force downcasting to generic type..."
+ "Shutting down now..."
)
fatalError()
}
set {
PersistenceController.update { appEnvMO in
appEnvMO.setValue(newValue.toData(), forKeyPath: key)
}
}
}

init(type: T.Type, key: String? = nil) {
if let key = key {
self.key = key
} else {
self.key = String(
describing: type
).lowercased()
}
}
}
60 changes: 0 additions & 60 deletions EhPanda/App/Tools/FileHelper.swift

This file was deleted.

42 changes: 0 additions & 42 deletions EhPanda/App/Tools/FileStorage.swift

This file was deleted.

22 changes: 13 additions & 9 deletions EhPanda/App/Tools/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct Parser {
}

// MARK: Detail
static func parseMangaDetail(doc: HTMLDocument) throws -> MangaDetail {
static func parseMangaDetail(doc: HTMLDocument, gid: String) throws -> (MangaDetail, MangaState) {
func parseCoverURL(node: XMLElement?) throws -> String {
guard let coverHTML = node?.at_xpath("//div [@id='gd1']")?.innerHTML,
let rangeA = coverHTML.range(of: "url("),
Expand Down Expand Up @@ -257,6 +257,7 @@ struct Parser {
}

var tmpMangaDetail: MangaDetail?
var tmpMangaState: MangaState?
for link in doc.xpath("//div [@class='gm']") {
guard let gdtNode = doc.at_xpath("//div [@id='gdt']"),
let gd3Node = link.at_xpath("//div [@id='gd3']"),
Expand All @@ -267,7 +268,7 @@ struct Parser {
let gdfNode = gd3Node.at_xpath("//div [@id='gdf']"),
let rating = try? parseRating(node: gdrNode),
let coverURL = try? parseCoverURL(node: link),
let detailTags = try? parseTags(node: gd4Node),
let tags = try? parseTags(node: gd4Node),
let previews = try? parsePreviews(node: gdtNode),
let arcAndTor = try? parseArcAndTor(node: gd5Node),
let infoPanel = try? parseInfoPanel(node: gddNode),
Expand All @@ -290,14 +291,11 @@ struct Parser {
archiveURL: arcAndTor.0,
alterImagesURL: try? parseAlterImagesURL(doc: doc),
alterImages: [],
torrents: [],
comments: parseComments(doc: doc),
previews: previews,
gid: gid,
title: engTitle,
jpnTitle: jpnTitle,
rating: rating,
ratingCount: ratingCount,
detailTags: detailTags,
category: category,
language: language,
uploader: uploader,
Expand All @@ -309,13 +307,19 @@ struct Parser {
sizeType: infoPanel[3],
torrentCount: arcAndTor.1
)
tmpMangaState = MangaState(
gid: gid, tags: tags,
previews: previews,
comments: parseComments(doc: doc)
)
break
}

guard let mangaDetail = tmpMangaDetail
guard let mangaDetail = tmpMangaDetail,
let mangaState = tmpMangaState
else { throw AppError.parseFailed }

return mangaDetail
return (mangaDetail, mangaState)
}

// MARK: Comment
Expand Down Expand Up @@ -856,7 +860,7 @@ extension Parser {
}

// MARK: DownloadCmdResp
static func parseDownloadCommandResponse(doc: HTMLDocument) throws -> Resp {
static func parseDownloadCommandResponse(doc: HTMLDocument) throws -> String {
guard let dbNode = doc.at_xpath("//div [@id='db']")
else { throw AppError.parseFailed }

Expand Down
8 changes: 8 additions & 0 deletions EhPanda/App/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ func dispatchMainSync(execute work: () -> Void) {
}
}

func dispatchMainAsync(execute work: @escaping () -> Void) {
if Thread.isMainThread {
work()
} else {
DispatchQueue.main.async(execute: work)
}
}

func presentActivityVC(items: [Any]) {
let activityVC = UIActivityViewController(
activityItems: items,
Expand Down
3 changes: 0 additions & 3 deletions EhPanda/App/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
"Are you sure to logout?" = "本当にログアウトしますか?";
"Are you sure to clear?" = "本当に削除しますか?";
"Clear" = "削除";
"Warning" = "警告";
"It's for debug only." = "デバッグ専用機能です";

"General" = "一般";
"Close slide menu after selection" = "選択後スライドメニューを閉じる";
Expand All @@ -89,7 +87,6 @@
"App switcher blur" = "アプリスイッチャーぼかし";
"Cache" = "キャッシュ";
"Clear image caches" = "画像キャッシュを削除";
"Clear web caches" = "ウェブキャッシュを削除";
"Copy cookies" = "クッキーをコピー";

"Appearance" = "外観";
Expand Down
3 changes: 0 additions & 3 deletions EhPanda/App/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
"Are you sure to logout?" = "确定要退出登录吗?";
"Are you sure to clear?" = "确定要清空吗?";
"Clear" = "清空";
"Warning" = "警告";
"It's for debug only." = "这是仅为问题排查设计的功能";

"General" = "一般";
"Close slide menu after selection" = "选择后关闭侧边栏";
Expand All @@ -89,7 +87,6 @@
"App switcher blur" = "在应用切换器中模糊处理";
"Cache" = "缓存";
"Clear image caches" = "清空图片缓存";
"Clear web caches" = "清空网络缓存";
"Copy cookies" = "复制Cookies";

"Appearance" = "外观";
Expand Down
3 changes: 0 additions & 3 deletions EhPanda/App/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
"Are you sure to logout?" = "確定要登出嗎?";
"Are you sure to clear?" = "確定要清空嗎?";
"Clear" = "清空";
"Warning" = "警告";
"It's for debug only." = "僅用於偵錯的功能";

"General" = "一般";
"Close slide menu after selection" = "選擇後關閉側邊選單";
Expand All @@ -89,7 +87,6 @@
"App switcher blur" = "模糊多工處理中的預覽";
"Cache" = "快取";
"Clear image caches" = "清空圖片快取";
"Clear web caches" = "清空網頁快取";
"Copy cookies" = "複製Cookies";

"Appearance" = "外觀";
Expand Down
19 changes: 2 additions & 17 deletions EhPanda/DataFlow/AppAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@ import Kanna
import Foundation

enum AppAction {
case replaceUser(user: User?)
case clearCachedList
case clearHistoryItems
case initializeStates
case replaceUser(user: User)
case initializeFilter
case clearDetailViewCommentContent
case clearCommentViewCommentContent
case saveAspectBox(gid: String, box: [Int: CGFloat])
case saveReadingProgress(gid: String, tag: Int)
case updateDiskImageCacheSize(size: String)
case updateAppIconType(iconType: IconType)
case updateHistoryItems(gid: String)
case updateHistoryKeywords(text: String)
case clearHistoryKeywords
case updateSearchKeyword(text: String)
case updateViewControllersCount
case resetDownloadCommandResponse
case replaceMangaCommentJumpID(gid: String?)
case updateIsSlideMenuClosed(isClosed: Bool)

Expand Down Expand Up @@ -69,32 +64,22 @@ enum AppAction {
case fetchMoreFavoritesItems(index: Int)
case fetchMoreFavoritesItemsDone(carriedValue: FavoritesIndex, result: Result<(PageNumber, [Manga]), AppError>)
case fetchMangaDetail(gid: String)
case fetchMangaDetailDone(result: Result<(Identity, MangaDetail, APIKey), AppError>)
case fetchMangaArchive(gid: String)
case fetchMangaArchiveDone(result: Result<(Identity, MangaArchive, CurrentGP?, CurrentCredits?), AppError>)
case fetchMangaDetailDone(result: Result<(MangaDetail, MangaState, APIKey?), AppError>)
case fetchMangaArchiveFunds(gid: String)
case fetchMangaArchiveFundsDone(result: Result<((CurrentGP, CurrentCredits)), AppError>)
case fetchMangaTorrents(gid: String)
case fetchMangaTorrentsDone(result: Result<(Identity, [MangaTorrent]), AppError>)
case fetchAssociatedItems(depth: Int, keyword: AssociatedKeyword)
case fetchAssociatedItemsDone(result: Result<(Depth, AssociatedKeyword, PageNumber, [Manga]), AppError>)
case fetchMoreAssociatedItems(depth: Int, keyword: AssociatedKeyword)
case fetchMoreAssociatedItemsDone(result: Result<(Depth, AssociatedKeyword, PageNumber, [Manga]), AppError>)
case fetchAlterImages(gid: String)
case fetchAlterImagesDone(result: Result<(Identity, [MangaAlterData]), AppError>)
case updateMangaComments(gid: String)
case updateMangaCommentsDone(result: Result<(Identity, [MangaComment]), AppError>)
case updateMangaDetail(gid: String)
case updateMangaDetailDone(result: Result<(Identity, MangaDetail), AppError>)
case fetchMangaContents(gid: String)
case fetchMangaContentsDone(result: Result<(Identity, PageNumber, [MangaContent]), AppError>)
case fetchMoreMangaContents(gid: String)
case fetchMoreMangaContentsDone(result: Result<(Identity, PageNumber, [MangaContent]), AppError>)

case addFavorite(gid: String, favIndex: Int)
case deleteFavorite(gid: String)
case sendDownloadCommand(gid: String, resolution: String)
case sendDownloadCommandDone(result: Resp?)
case rate(gid: String, rating: Int)
case comment(gid: String, content: String)
case editComment(gid: String, commentID: String, content: String)
Expand Down
Loading

0 comments on commit 6e30975

Please sign in to comment.