Skip to content

Commit

Permalink
Merge pull request #208 from tatsuz0u/develop
Browse files Browse the repository at this point in the history
Bugfixes & Features
  • Loading branch information
tatsuz0u authored Feb 7, 2022
2 parents 5862fb3 + 8e2ca7a commit 2f11bef
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [closed]
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
APP_VERSION: '2.0.0'
APP_VERSION: '2.1.0'
SCHEME_NAME: 'EhPanda'
ALTSTORE_JSON_PATH: './AltStore.json'
BUILDS_PATH: '/tmp/action-builds'
Expand Down
9 changes: 9 additions & 0 deletions EhPanda/App/Tools/Clients/DatabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ extension DatabaseClient {
return updateGalleryState(gid: gid, key: "comments", value: comments.toData())
}

func removeImageURLs(gid: String) -> Effect<Never, Never> {
guard gid.isValidGID else { return .none }
return updateGalleryState(gid: gid) { galleryStateMO in
galleryStateMO.imageURLs = nil
galleryStateMO.previewURLs = nil
galleryStateMO.thumbnailURLs = nil
galleryStateMO.originalImageURLs = nil
}
}
func removeImageURLs() -> Effect<Never, Never> {
.fireAndForget {
DispatchQueue.main.async {
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
"reading.view.toolbar.item.title.autoPlay" = "Auto-Play";
"reading.view.toolbar.item.title.dualPageMode" = "Dual-Page mode";
"reading.view.toolbar.item.title.exceptTheCover" = "Except the cover";
"reading.view.toolbar.item.button.retryAllFailedImages" = "Retry failed images";
"reading.view.toolbar.item.button.reloadAllImages" = "Reload all images";
"reading.view.toolbar.item.button.readingSetting" = "Reading setting";
// AutoPlayPolicy
"enum.auto.play.policy.value.off" = "Off";

Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
"reading.view.toolbar.item.title.autoPlay" = "Auto-Play";
"reading.view.toolbar.item.title.dualPageMode" = "Dual-Page mode";
"reading.view.toolbar.item.title.exceptTheCover" = "Except the cover";
"reading.view.toolbar.item.button.retryAllFailedImages" = "Retry all failed images";
"reading.view.toolbar.item.button.reloadAllImages" = "Reload all images";
"reading.view.toolbar.item.button.readingSetting" = "Reading setting";
// AutoPlayPolicy
"enum.auto.play.policy.value.off" = "Off";

Expand Down
5 changes: 4 additions & 1 deletion EhPanda/App/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"loading.view.title.preparingDatabase" = "データベース準備中...";
"not.login.view.title.needLogin" = "本機能をご利用になるにはログインが必要です";
"not.login.view.button.login" = "ログイン";
"error.view.button.retry" = "やり直す";
"error.view.button.retry" = "リトライ";
"error.view.button.dropDatabase" = "データベースを削除";
"error.view.title.tryLater" = "しばらくしてからもう一度お試しください";
"error.view.title.network" = "ネットワーク障害が発生しました";
Expand Down Expand Up @@ -338,6 +338,9 @@
"reading.view.toolbar.item.title.autoPlay" = "自動再生";
"reading.view.toolbar.item.title.dualPageMode" = "デュアルページモード";
"reading.view.toolbar.item.title.exceptTheCover" = "カバーを除く";
"reading.view.toolbar.item.button.retryAllFailedImages" = "読み込み失敗した画像をすべてリトライ";
"reading.view.toolbar.item.button.reloadAllImages" = "画像をすべて再読み込み";
"reading.view.toolbar.item.button.readingSetting" = "閲覧設定";
// AutoPlayPolicy
"enum.auto.play.policy.value.off" = "オフ";

Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
"reading.view.toolbar.item.title.autoPlay" = "자동 재생";
"reading.view.toolbar.item.title.dualPageMode" = "두 장을 한 화면으로 보기";
"reading.view.toolbar.item.title.exceptTheCover" = "표지 제외하기";
"reading.view.toolbar.item.button.retryAllFailedImages" = "Retry failed images";
"reading.view.toolbar.item.button.reloadAllImages" = "Reload all images";
"reading.view.toolbar.item.button.readingSetting" = "Reading setting";
// AutoPlayPolicy
"enum.auto.play.policy.value.off" = "Off";

Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
"reading.view.toolbar.item.title.autoPlay" = "自动播放";
"reading.view.toolbar.item.title.dualPageMode" = "双页模式";
"reading.view.toolbar.item.title.exceptTheCover" = "封面除外";
"reading.view.toolbar.item.button.retryAllFailedImages" = "重试所有读取失败图片";
"reading.view.toolbar.item.button.reloadAllImages" = "重新加载所有图片";
"reading.view.toolbar.item.button.readingSetting" = "阅读设置";
// AutoPlayPolicy
"enum.auto.play.policy.value.off" = "不启用";

Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
"reading.view.toolbar.item.title.autoPlay" = "Auto-Play";
"reading.view.toolbar.item.title.dualPageMode" = "雙頁模式";
"reading.view.toolbar.item.title.exceptTheCover" = "封面除外";
"reading.view.toolbar.item.button.retryAllFailedImages" = "Retry failed images";
"reading.view.toolbar.item.button.reloadAllImages" = "Reload all images";
"reading.view.toolbar.item.button.readingSetting" = "Reading setting";
// AutoPlayPolicy
"enum.auto.play.policy.value.off" = "Off";

Expand Down
2 changes: 0 additions & 2 deletions EhPanda/DataFlow/AppDelegateStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ let appDelegateReducer = Reducer<AppState, AppDelegateAction, AppDelegateEnviron
.init { state, action, environment in
switch action {
case .onLaunchFinish:
let bypassesSNIFiltering = state.settingState.setting.bypassesSNIFiltering
state.appLockState.becomeInactiveDate = .distantPast
return .merge(
environment.libraryClient.initializeLogger().fireAndForget(),
environment.libraryClient.initializeWebImage().fireAndForget(),
environment.dfClient.setActive(bypassesSNIFiltering).fireAndForget(),
environment.cookiesClient.removeYay().fireAndForget(),
environment.cookiesClient.ignoreOffensive().fireAndForget(),
environment.cookiesClient.fulfillAnotherHostField().fireAndForget(),
Expand Down
27 changes: 22 additions & 5 deletions EhPanda/DataFlow/AppStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,36 @@ let appReducerCore = Reducer<AppState, AppAction, AppEnvironment> { state, actio

case .tabBar(.setTabBarItemType(let type)):
var effects = [Effect<AppAction, Never>]()
let hapticEffect: Effect<AppAction, Never> = environment.hapticClient
.generateFeedback(.soft).fireAndForget()
if type == state.tabBarState.tabBarItemType {
switch type {
case .home:
effects.append(.init(value: .home(.fetchAllGalleries)))
if state.homeState.route != nil {
effects.append(.init(value: .home(.setNavigation(nil))))
} else {
effects.append(.init(value: .home(.fetchAllGalleries)))
}
case .favorites:
effects.append(.init(value: .favorites(.fetchGalleries())))
if state.favoritesState.route != nil {
effects.append(.init(value: .favorites(.setNavigation(nil))))
} else {
effects.append(.init(value: .favorites(.fetchGalleries())))
}
case .search:
effects.append(.init(value: .searchRoot(.fetchDatabaseInfos)))
if state.searchRootState.route != nil {
effects.append(.init(value: .searchRoot(.setNavigation(nil))))
} else {
effects.append(.init(value: .searchRoot(.fetchDatabaseInfos)))
}
case .setting:
break
if state.settingState.route != nil {
effects.append(.init(value: .setting(.setNavigation(nil))))
effects.append(hapticEffect)
}
}
if [.home, .favorites, .search].contains(type) {
effects.append(environment.hapticClient.generateFeedback(.soft).fireAndForget())
effects.append(hapticEffect)
}
}
if type == .setting && environment.deviceClient.isPad() {
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/View/Detail/DataFlow/DetailStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ let detailReducer = Reducer<DetailState, DetailAction, DetailEnvironment>.recurs
}
return environment.hapticClient.generateNotificationFeedback(.error).fireAndForget()

case .reading(.onPerformDismiss):
return .init(value: .setNavigation(nil))

case .reading:
return .none

Expand Down
3 changes: 3 additions & 0 deletions EhPanda/View/Detail/DataFlow/PreviewsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ let previewsReducer = Reducer<PreviewsState, PreviewsAction, PreviewsEnvironment
}
return .none

case .reading(.onPerformDismiss):
return .init(value: .setNavigation(nil))

case .reading:
return .none
}
Expand Down
3 changes: 1 addition & 2 deletions EhPanda/View/Detail/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ struct DetailView: View {
.fullScreenCover(unwrapping: viewStore.binding(\.$route), case: /DetailState.Route.reading) { _ in
ReadingView(
store: store.scope(state: \.readingState, action: DetailAction.reading),
setting: $setting, blurRadius: blurRadius,
dismissAction: { viewStore.send(.setNavigation(nil)) }
setting: $setting, blurRadius: blurRadius
)
.accentColor(setting.accentColor)
.autoBlur(radius: blurRadius)
Expand Down
3 changes: 1 addition & 2 deletions EhPanda/View/Detail/PreviewsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ struct PreviewsView: View {
.fullScreenCover(unwrapping: viewStore.binding(\.$route), case: /PreviewsState.Route.reading) { _ in
ReadingView(
store: store.scope(state: \.readingState, action: PreviewsAction.reading),
setting: $setting, blurRadius: blurRadius,
dismissAction: { viewStore.send(.setNavigation(nil)) }
setting: $setting, blurRadius: blurRadius
)
.accentColor(setting.accentColor)
.autoBlur(radius: blurRadius)
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Favorites/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct FavoritesView: View {
fetchMoreAction: { viewStore.send(.fetchMoreGalleries) },
navigateAction: { viewStore.send(.setNavigation(.detail($0))) },
translateAction: {
tagTranslator.tryTranslate(text: $0, returnOriginal: setting.translatesTags)
tagTranslator.tryTranslate(text: $0, returnOriginal: !setting.translatesTags)
}
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Home/ToplistsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ToplistsView: View {
fetchMoreAction: { viewStore.send(.fetchMoreGalleries) },
navigateAction: { viewStore.send(.setNavigation(.detail($0))) },
translateAction: {
tagTranslator.tryTranslate(text: $0, returnOriginal: setting.translatesTags)
tagTranslator.tryTranslate(text: $0, returnOriginal: !setting.translatesTags)
}
)
.sheet(
Expand Down
38 changes: 38 additions & 0 deletions EhPanda/View/Reading/ReadingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct ReadingState: Equatable {
@BindableState var route: Route?
let gallery: Gallery

var forceRefreshID: UUID = .init()
var hudConfig: TTProgressHUDConfig = .loading

var imageURLLoadingStates = [Int: LoadingState]()
Expand Down Expand Up @@ -194,11 +195,14 @@ enum ReadingAction: BindableAction {
case setSliderValue(Float)
case setOrientationPortrait(Bool)
case onTimerFired
case onPerformDismiss
case onAppear(Bool)

case onWebImageRetry(Int)
case onWebImageSucceeded(Int)
case onWebImageFailed(Int)
case reloadAllWebImages
case retryAllFailedWebImages

case copyImage(URL)
case saveImage(URL)
Expand All @@ -213,6 +217,7 @@ enum ReadingAction: BindableAction {
case onMagnificationGestureEnded(Double, Double)
case onDragGestureChanged(DragGesture.Value)
case onDragGestureEnded(DragGesture.Value)
case onControlPanelDismissGestureEnded(DragGesture.Value)

case syncReadingProgress
case syncPreviewURLs([Int: URL])
Expand Down Expand Up @@ -310,6 +315,9 @@ let readingReducer = Reducer<ReadingState, ReadingAction, ReadingEnvironment> {
state.pageIndex += 1
return .none

case .onPerformDismiss:
return .none

case .onAppear(let enablesLandscape):
var effects: [Effect<ReadingAction, Never>] = [
.init(value: .fetchDatabaseInfos)
Expand All @@ -331,6 +339,30 @@ let readingReducer = Reducer<ReadingState, ReadingAction, ReadingEnvironment> {
state.imageURLLoadingStates[index] = .failed(.webImageFailed)
return .none

case .reloadAllWebImages:
state.previewURLs = .init()
state.thumbnailURLs = .init()
state.imageURLs = .init()
state.originalImageURLs = .init()
state.mpvKey = nil
state.mpvImageKeys = .init()
state.mpvReloadTokens = .init()
state.forceRefreshID = .init()
return environment.databaseClient.removeImageURLs(gid: state.gallery.id).fireAndForget()

case .retryAllFailedWebImages:
state.imageURLLoadingStates.forEach { (index, loadingState) in
if case .failed = loadingState {
state.imageURLLoadingStates[index] = .idle
}
}
state.previewLoadingStates.forEach { (index, loadingState) in
if case .failed = loadingState {
state.previewLoadingStates[index] = .idle
}
}
return .none

case .copyImage(let imageURL):
return .init(value: .fetchImage(.copy, imageURL))

Expand Down Expand Up @@ -437,6 +469,12 @@ let readingReducer = Reducer<ReadingState, ReadingAction, ReadingEnvironment> {
}
return .none

case .onControlPanelDismissGestureEnded(let value):
return value.predictedEndTranslation.height > 30 ? .merge(
environment.hapticClient.generateFeedback(.light).fireAndForget(),
.init(value: .onPerformDismiss)
) : .none

case .syncReadingProgress:
return environment.databaseClient
.updateReadingProgress(gid: state.gallery.id, progress: .init(state.sliderValue)).fireAndForget()
Expand Down
20 changes: 12 additions & 8 deletions EhPanda/View/Reading/ReadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ struct ReadingView: View {
@ObservedObject private var viewStore: ViewStore<ReadingState, ReadingAction>
@Binding private var setting: Setting
private let blurRadius: Double
private let dismissAction: () -> Void

@StateObject private var page: Page = .first()

init(
store: Store<ReadingState, ReadingAction>,
setting: Binding<Setting>, blurRadius: Double,
dismissAction: @escaping () -> Void
setting: Binding<Setting>, blurRadius: Double
) {
self.store = store
viewStore = ViewStore(store)
_setting = setting
self.blurRadius = blurRadius
self.dismissAction = dismissAction
}

private var backgroundColor: Color {
Expand Down Expand Up @@ -62,15 +59,20 @@ struct ReadingView: View {
.offset(viewStore.offset).gesture(tapGesture).gesture(dragGesture)
.gesture(magnificationGesture).ignoresSafeArea()
.id(viewStore.databaseLoadingState)
.id(viewStore.forceRefreshID)
ControlPanel(
showsPanel: viewStore.binding(\.$showsPanel),
showsSliderPreview: viewStore.binding(\.$showsSliderPreview),
sliderValue: viewStore.binding(\.$sliderValue),
setting: $setting,
autoPlayPolicy: viewStore.binding(\.$autoPlayPolicy),
range: 1...Float(viewStore.gallery.pageCount),
previewURLs: viewStore.previewURLs, dismissAction: dismissAction,
previewURLs: viewStore.previewURLs,
dismissGesture: controlPanelDismissGesture,
dismissAction: { viewStore.send(.onPerformDismiss) },
navigateSettingAction: { viewStore.send(.setNavigation(.readingSetting)) },
reloadAllImagesAction: { viewStore.send(.reloadAllWebImages) },
retryAllFailedImagesAction: { viewStore.send(.retryAllFailedWebImages) },
fetchPreviewURLsAction: { viewStore.send(.fetchPreviewURLs($0)) }
)
}
Expand Down Expand Up @@ -175,10 +177,13 @@ extension ReadingView {
.onEnded { viewStore.send(.onMagnificationGestureEnded($0, setting.maximumScaleFactor)) }
}
var dragGesture: some Gesture {
DragGesture(minimumDistance: 0.0, coordinateSpace: .local)
DragGesture(minimumDistance: .zero, coordinateSpace: .local)
.onChanged { viewStore.send(.onDragGestureChanged($0)) }
.onEnded { viewStore.send(.onDragGestureEnded($0)) }
}
var controlPanelDismissGesture: some Gesture {
DragGesture().onEnded { viewStore.send(.onControlPanelDismissGestureEnded($0)) }
}
}

// MARK: HorizontalImageStack
Expand Down Expand Up @@ -449,8 +454,7 @@ struct ReadingView_Previews: PreviewProvider {
)
),
setting: .constant(.init()),
blurRadius: 0,
dismissAction: {}
blurRadius: 0
)
}
}
Expand Down
Loading

0 comments on commit 2f11bef

Please sign in to comment.