Skip to content

Commit

Permalink
Merge pull request #19 from shinrenpan/develop
Browse files Browse the repository at this point in the history
v0.9.5
  • Loading branch information
shinrenpan authored Jun 14, 2024
2 parents 78fbbe9 + a3999a2 commit 072beed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Comic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20240614;
CURRENT_PROJECT_VERSION = 20240615;
DEVELOPMENT_TEAM = VZWPMD258L;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -640,7 +640,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.9.4;
MARKETING_VERSION = 0.9.5;
PRODUCT_BUNDLE_IDENTIFIER = com.shinrenpan.Comic;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -655,7 +655,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20240614;
CURRENT_PROJECT_VERSION = 20240615;
DEVELOPMENT_TEAM = VZWPMD258L;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -666,7 +666,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.9.4;
MARKETING_VERSION = 0.9.5;
PRODUCT_BUNDLE_IDENTIFIER = com.shinrenpan.Comic;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
56 changes: 46 additions & 10 deletions Sources/MVVVR/Reader/ReaderVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ private extension ReaderVC {

func setupSelf() {
view.backgroundColor = vo.mainView.backgroundColor
navigationItem.rightBarButtonItem = makeEpisodePickerItem()

setToolbarItems([
vo.prevItem,
.init(systemItem: .flexibleSpace),
vo.directionItem,
vo.moreItem,
.init(systemItem: .flexibleSpace),
vo.nextItem,
], animated: false)
Expand Down Expand Up @@ -114,10 +113,7 @@ private extension ReaderVC {
doLoadPrev()
}

vo.directionItem.primaryAction = .init { [weak self] _ in
guard let self else { return }
horizontalRead.toggle()
}
vo.moreItem.menu = makeMoreItemMenu()

vo.nextItem.primaryAction = .init(title: "下一話") { [weak self] _ in
guard let self else { return }
Expand Down Expand Up @@ -145,7 +141,6 @@ private extension ReaderVC {
vo.list.setCollectionViewLayout(layout, animated: false)
layout.invalidateLayout()
vo.list.reloadData()
vo.directionItem.title = horizontalRead ? "橫向閱讀" : "直式閱讀"
}

// MARK: - Handle State
Expand Down Expand Up @@ -202,13 +197,54 @@ private extension ReaderVC {
}
}

func makeEpisodePickerItem() -> UIBarButtonItem {
let action = UIAction { [weak self] _ in
func makeReaderDirectionAction() -> UIAction {
let title: String = horizontalRead ? "直式閱讀" : "橫向閱讀"

return .init(title: title) { [weak self] _ in
guard let self else { return }
horizontalRead.toggle()
}.setup(\.attributes, value: .disabled)
}

func makeEpisodePickAction() -> UIAction {
.init(title: "選取集數", image: .init(systemName: "list.number")) { [weak self] _ in
guard let self else { return }
router.showEpisodePicker(comic: vm.model.comic)
}
}

func makeFaveriteAction() -> UIAction {
let title: String = vm.model.comic.favorited ? "取消收藏" : "加入收藏"
let image: UIImage? = vm.model.comic.favorited ? .init(systemName: "star.fill") : .init(systemName: "star")

return .init(title: title, image: image) { [weak self] _ in
guard let self else { return }
vm.model.comic.favorited.toggle()
}
}

func makeMoreItemMenu() -> UIMenu {
let readerDirection = UIDeferredMenuElement.uncached { [weak self] completion in
guard let self else { return }
let action = makeReaderDirectionAction()

DispatchQueue.main.async {
completion([action])
}
}

let episodePick = makeEpisodePickAction()

let favorite = UIDeferredMenuElement.uncached { [weak self] completion in
guard let self else { return }
let action = makeFaveriteAction()

DispatchQueue.main.async {
completion([action])
}
}

return .init(image: .init(systemName: "list.number"), primaryAction: action)
return .init(title: "更多...", children: [readerDirection, favorite, episodePick])
}

// MARK: - Do Something
Expand Down
7 changes: 5 additions & 2 deletions Sources/MVVVR/Reader/ReaderVO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ final class ReaderVO {
let prevItem = UIBarButtonItem(title: "上一話")
.setup(\.isEnabled, value: false)

let directionItem = UIBarButtonItem(title: "")
let moreItem = UIBarButtonItem(title: "更多...")
.setup(\.isEnabled, value: false)

let nextItem = UIBarButtonItem(title: "下一話")
.setup(\.isEnabled, value: false)

Expand Down Expand Up @@ -48,6 +49,8 @@ extension ReaderVO {
mainView.isHidden = false
list.reloadData()
mainView.isUserInteractionEnabled = true
moreItem.isEnabled = true

prevItem.isEnabled = model.hasPrev
prevItem.title = model.prevEpisode?.title ?? "上一話"
nextItem.isEnabled = model.hasNext
Expand All @@ -63,7 +66,7 @@ extension ReaderVO {
mainView.isHidden = true
prevItem.isEnabled = false
prevLabel.isHidden = true
directionItem.isEnabled = false
moreItem.isEnabled = false
nextItem.isEnabled = false
nextLabel.isHidden = true
}
Expand Down

0 comments on commit 072beed

Please sign in to comment.