Skip to content

Commit

Permalink
フィルター機能
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jan 8, 2021
1 parent a77f093 commit 40de94e
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 154 deletions.
16 changes: 8 additions & 8 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
AB2C029325A7F2E100F8F740 /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB2C029125A7F2E100F8F740 /* BlurView.swift */; };
AB2C029425A7F2E100F8F740 /* OverlaySheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB2C029225A7F2E100F8F740 /* OverlaySheet.swift */; };
AB40CFDC25983EC200D1DC9A /* FileStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB40CFDB25983EC200D1DC9A /* FileStorage.swift */; };
AB40CFDF25983EDF00D1DC9A /* FileHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB40CFDE25983EDF00D1DC9A /* FileHelper.swift */; };
AB718B2525A0C0AC00D32962 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB718B2425A0C0AC00D32962 /* CommentView.swift */; };
AB994DC02598B17500E9A367 /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB994DBF2598B17500E9A367 /* SettingView.swift */; };
AB994DC32598B3E000E9A367 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB994DC22598B3E000E9A367 /* WebView.swift */; };
AB994DCB2598D96200E9A367 /* AlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB994DCA2598D96200E9A367 /* AlertView.swift */; };
ABA732D925A8018A00B3D9AB /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA732D825A8018A00B3D9AB /* Extensions.swift */; };
ABA732DF25A852D800B3D9AB /* Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA732DE25A852D800B3D9AB /* Filter.swift */; };
ABA732E225A8590900B3D9AB /* FilterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA732E125A8590900B3D9AB /* FilterView.swift */; };
ABC3C7852593699B00E0C11B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ABC3C7692593699A00E0C11B /* Assets.xcassets */; };
ABC3C7862593699B00E0C11B /* Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC3C76A2593699A00E0C11B /* Common.swift */; };
ABC3C7872593699B00E0C11B /* EhPandaApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC3C76B2593699A00E0C11B /* EhPandaApp.swift */; };
Expand All @@ -41,8 +41,6 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
AB2C029125A7F2E100F8F740 /* BlurView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
AB2C029225A7F2E100F8F740 /* OverlaySheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverlaySheet.swift; sourceTree = "<group>"; };
AB40CFDB25983EC200D1DC9A /* FileStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileStorage.swift; sourceTree = "<group>"; };
AB40CFDE25983EDF00D1DC9A /* FileHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileHelper.swift; sourceTree = "<group>"; };
AB718B2425A0C0AC00D32962 /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = "<group>"; };
Expand All @@ -51,6 +49,8 @@
AB994DC22598B3E000E9A367 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
AB994DCA2598D96200E9A367 /* AlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertView.swift; sourceTree = "<group>"; };
ABA732D825A8018A00B3D9AB /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
ABA732DE25A852D800B3D9AB /* Filter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filter.swift; sourceTree = "<group>"; };
ABA732E125A8590900B3D9AB /* FilterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterView.swift; sourceTree = "<group>"; };
ABC3C7542593696C00E0C11B /* EhPanda.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EhPanda.app; sourceTree = BUILT_PRODUCTS_DIR; };
ABC3C7692593699A00E0C11B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
ABC3C76A2593699A00E0C11B /* Common.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Common.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -149,6 +149,7 @@
children = (
ABC3C7732593699A00E0C11B /* HomeView.swift */,
AB994DBF2598B17500E9A367 /* SettingView.swift */,
ABA732E125A8590900B3D9AB /* FilterView.swift */,
ABC3C7722593699A00E0C11B /* DetailView.swift */,
AB718B2425A0C0AC00D32962 /* CommentView.swift */,
ABC3C7742593699A00E0C11B /* ContentView.swift */,
Expand All @@ -166,8 +167,6 @@
ABC3C7772593699A00E0C11B /* RatingView.swift */,
AB994DCA2598D96200E9A367 /* AlertView.swift */,
ABF75F4225A1C11100544D29 /* Comment.swift */,
AB2C029125A7F2E100F8F740 /* BlurView.swift */,
AB2C029225A7F2E100F8F740 /* OverlaySheet.swift */,
);
path = "ツール";
sourceTree = "<group>";
Expand All @@ -184,6 +183,7 @@
isa = PBXGroup;
children = (
ABF75F3E25A19CD200544D29 /* User.swift */,
ABA732DE25A852D800B3D9AB /* Filter.swift */,
ABC3C7802593699A00E0C11B /* Manga.swift */,
);
path = "モデル";
Expand Down Expand Up @@ -285,6 +285,7 @@
ABA732D925A8018A00B3D9AB /* Extensions.swift in Sources */,
AB40CFDC25983EC200D1DC9A /* FileStorage.swift in Sources */,
ABCD2F0A259763FC008E5A20 /* Request.swift in Sources */,
ABA732E225A8590900B3D9AB /* FilterView.swift in Sources */,
ABCD2F07259760D4008E5A20 /* AppError.swift in Sources */,
ABC3C7892593699B00E0C11B /* Defaults.swift in Sources */,
AB40CFDF25983EDF00D1DC9A /* FileHelper.swift in Sources */,
Expand All @@ -294,8 +295,6 @@
ABC3C78F2593699B00E0C11B /* ViewModifiers.swift in Sources */,
ABCD2EF82597602D008E5A20 /* Store.swift in Sources */,
ABC3C7862593699B00E0C11B /* Common.swift in Sources */,
AB2C029425A7F2E100F8F740 /* OverlaySheet.swift in Sources */,
AB2C029325A7F2E100F8F740 /* BlurView.swift in Sources */,
ABCD2F0E25976B95008E5A20 /* Parser.swift in Sources */,
AB994DCB2598D96200E9A367 /* AlertView.swift in Sources */,
ABC3C78D2593699B00E0C11B /* HomeView.swift in Sources */,
Expand All @@ -306,6 +305,7 @@
ABC3C7872593699B00E0C11B /* EhPandaApp.swift in Sources */,
AB718B2525A0C0AC00D32962 /* CommentView.swift in Sources */,
ABF75F4325A1C11100544D29 /* Comment.swift in Sources */,
ABA732DF25A852D800B3D9AB /* Filter.swift in Sources */,
AB994DC02598B17500E9A367 /* SettingView.swift in Sources */,
ABF75F3F25A19CD200544D29 /* User.swift in Sources */,
);
Expand Down
11 changes: 10 additions & 1 deletion EhPanda/アプリ/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public var exx: Bool {
UserDefaults.standard.string(forKey: "entry") == "Rra3MKpjKBJLgraHqt9t"
}

public var isPad: Bool {
UIDevice.current.userInterfaceIdiom == .pad
}

public var galleryType: GalleryType {
let rawValue = UserDefaults
.standard
Expand All @@ -71,7 +75,12 @@ public func readableUnit(bytes: Int64) -> String {

public func diskImageCaches() -> String {
let bytes = SDImageCache.shared.totalDiskSize()
return readableUnit(bytes: Int64(bytes))

if bytes == 0 {
return "0 KB"
} else {
return readableUnit(bytes: Int64(bytes))
}
}

public func browsingCaches() -> String {
Expand Down
138 changes: 113 additions & 25 deletions EhPanda/アプリ/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

class Defaults {
class URL {
// いわゆるホストドメイン
static var host: String {
if exx {
return galleryType == .eh ? ehentai : exhentai
} else {
return merge([ehentai, listCompact, nonh, f_search + "parody:durarara$"])
}
}

static let ehentai = "https://e-hentai.org/"
static let exhentai = "https://exhentai.org/"
static let forum = "https://forums.e-hentai.org/"
static let login = merge([forum + index, login_act])

// 各機能ページ
static let api = "api.php"
static let index = "index.php"
static let favorites = "favorites.php"
Expand All @@ -38,36 +39,123 @@ class Defaults {
static let listCompact = "inline_set=dm_l"
static let detailLarge = "inline_set=ts_l"

// フィルター
static let f_cats = "f_cats="
static let advSearch = "advsearch=1"
static let f_sname_on = "f_sname=on"
static let f_stags_on = "f_stags=on"
static let f_sdesc_on = "f_sdesc=on"
static let f_storr_on = "f_storr=on"
static let f_sto_on = "f_sto=on"
static let f_sdt1_on = "f_sdt1=on"
static let f_sdt2_on = "f_sdt2=on"
static let f_sh_on = "f_sh=on"
static let f_sr_on = "f_sr=on"
static let f_srdd = "f_srdd="
static let f_sp_on = "f_sp=on"
static let f_spf = "f_spf="
static let f_spt = "f_spt="
static let f_sfl_on = "f_sfl=on"
static let f_sfu_on = "f_sfu=on"
static let f_sft_on = "f_sft=on"
}
}

// MARK: リクエスト
extension Defaults.URL {
static func search(keyword: String, filter: Filter) -> String {
let params: [String]
= [host, listCompact, f_search + keyword.URLString()]
+ applyFilters(filter)
ePrint(merge(params))
return merge(params)
}
static func popularList() -> String {
merge([host, listCompact])
}
static func favoritesList() -> String {
merge([host + favorites, listCompact])
}

static func mangaDetail(url: String) -> String {
merge([url, ignoreOffensive, showComments, detailLarge])
}
static func contentPage(url: String, page: Int) -> String {
merge([url, p + "\(page)"])
}

static func addFavorite(id: String, token: String) -> String {
merge([host + gallerypopups, gid + id, t + token, addfav_act])
}
}

// MARK: フィルター
extension Defaults.URL {
static func applyFilters(_ filter: Filter) -> [String] {
var filters = [String]()

var category = 0
category += filter.doujinshi.isFiltered ? Category.Doujinshi.value : 0
category += filter.manga.isFiltered ? Category.Manga.value : 0
category += filter.artist_CG.isFiltered ? Category.Artist_CG.value : 0
category += filter.game_CG.isFiltered ? Category.Game_CG.value : 0
category += filter.western.isFiltered ? Category.Western.value : 0
category += filter.non_h.isFiltered ? Category.Non_H.value : 0
category += filter.image_set.isFiltered ? Category.Image_Set.value : 0
category += filter.cosplay.isFiltered ? Category.Cosplay.value : 0
category += filter.asian_porn.isFiltered ? Category.Asian_Porn.value : 0
category += filter.misc.isFiltered ? Category.Misc.value : 0

static func search(keyword: String) -> String {
merge([host, listCompact, f_search, keyword.URLString()])
}
static func popularList() -> String {
merge([host, listCompact])
}
static func favoritesList() -> String {
merge([host + favorites, listCompact])
if ![0, 1023].contains(category) {
filters.append(f_cats + "\(category)")
}

static func mangaDetail(url: String) -> String {
merge([url, ignoreOffensive, showComments, detailLarge])
}
static func contentPage(url: String, page: Int) -> String {
merge([url, p + "\(page)"])
}
if !filter.advanced { return filters }
filters.append(advSearch)

if filter.galleryName { filters.append(f_sname_on) }
if filter.galleryTags { filters.append(f_stags_on) }
if filter.galleryDesc { filters.append(f_sdesc_on) }
if filter.torrentFilenames { filters.append(f_storr_on) }
if filter.onlyWithTorrents { filters.append(f_sto_on) }
if filter.lowPowerTags { filters.append(f_sdt1_on) }
if filter.downvotedTags { filters.append(f_sdt2_on) }
if filter.expungedGalleries { filters.append(f_sh_on) }

static func addFavorite(id: String, token: String) -> String {
merge([host + gallerypopups, gid + id, t + token, addfav_act])
if filter.minRatingActivated,
[2, 3, 4, 5].contains(filter.minRating)
{
filters.append(f_sr_on)
filters.append(f_srdd + "\(filter.minRating)")
}

static func merge(_ urls: [String]) -> String {
let firstTwo = urls.prefix(2)
let remainder = urls.suffix(from: 2)
var joinedArray = [String]()
joinedArray.append(firstTwo.joined(separator: "?"))
joinedArray.append(remainder.joined(separator: "&"))
return joinedArray.joined(separator: "&")
if filter.pageRangeActivated,
let minPages = Int(filter.pageLowerBound),
let maxPages = Int(filter.pageUpperBound),
minPages > 0 && maxPages > 0 && minPages <= maxPages
{
filters.append(f_sp_on)
filters.append(f_spf + "\(minPages)")
filters.append(f_spt + "\(maxPages)")
}

if filter.disableLanguage { filters.append(f_sfl_on) }
if filter.disableUploader { filters.append(f_sfu_on) }
if filter.disableTags { filters.append(f_sft_on) }

return filters
}
}

// MARK: ツール
extension Defaults.URL {
static func merge(_ urls: [String]) -> String {
let firstTwo = urls.prefix(2)
let remainder = urls.suffix(from: 2)

var joinedArray = [String]()
joinedArray.append(firstTwo.joined(separator: "?"))
joinedArray.append(remainder.joined(separator: "&"))
return joinedArray.joined(separator: "&")
}
}
21 changes: 21 additions & 0 deletions EhPanda/アプリ/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@
"警告" = "WARNING";
"デバッグ専用機能です" = "It's for debug only";

// MARK: FilterView
"フィルター" = "Filters";
"基本" = "BASIC";
"高度な設定" = "Advanced Settings";
"高度" = "ADVANCED";
"ギャラリー名を検索" = "Search Gallery Name";
"ギャラリータグを検索" = "Search Gallery Tags";
"ギャラリー説明を検索" = "Search Gallery Description";
"トレントファイル名を検索" = "Search Torrent Filenames";
"トレントを含むもののみを表示" = "Only Show Galleries With Torrents";
"低希望タグを検索" = "Search Low-Power Tags";
"低評価タグを検索" = "Search Downvoted Tags";
"削除済みのギャラリーを表示" = "Show Expunged Galleries";
"評価の下限を指定" = "Set Minimum Rating";
"ページ数範囲を指定" = "Set Pages Range";
"範囲" = "Range";
"既定フィルター" = "DEFAULT FILTER";
"言語フィルターを無効化" = "Disable Language Filter";
"アップローダフィルターを無効化" = "Disable Uploader Filter";
"タグフィルターを無効化" = "Disable Tags Filter";

// MARK: Category
"同人誌" = "Doujinshi";
"漫画" = "Manga";
Expand Down
23 changes: 22 additions & 1 deletion EhPanda/アプリ/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"アカウント" = "账户";
"ギャラリー" = "画廊";
"ログイン済み" = "已登陆";
"ログイン" = "前往E-Hentai登陆";
"ログイン" = "登陆";
"ログアウト" = "退出登陆";
"本当にログアウトしますか?" = "确定要退出登陆吗?";
"キャッシュ" = "缓存";
Expand All @@ -60,6 +60,27 @@
"警告" = "警告";
"デバッグ専用機能です" = "这是仅为问题排查设计的功能";

// MARK: FilterView
"フィルター" = "筛选";
"基本" = "基础";
"高度な設定" = "高级选项";
"高度" = "高级";
"ギャラリー名を検索" = "搜索画廊名称";
"ギャラリータグを検索" = "搜索画廊标签";
"ギャラリー説明を検索" = "搜索画廊描述";
"トレントファイル名を検索" = "搜索种子文件名";
"トレントを含むもののみを表示" = "只显示带有种子的画廊";
"低希望タグを検索" = "搜索低期望标签";
"低評価タグを検索" = "搜索低评价标签";
"削除済みのギャラリーを表示" = "显示已被删除的画廊";
"評価の下限を指定" = "设定评分下限";
"ページ数範囲を指定" = "设定页数范围";
"範囲" = "范围";
"既定フィルター" = "默认筛选";
"言語フィルターを無効化" = "禁用语言筛选";
"アップローダフィルターを無効化" = "禁用上传者筛选";
"タグフィルターを無効化" = "禁用标签筛选";

// MARK: Category
"同人誌" = "同人志";
"漫画" = "漫画";
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/データフロー/AppAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import Foundation
enum AppAction {
case updateUser(user: User?)
case eraseCachedList
case initiateFilter

case toggleNavBarHidden(isHidden: Bool)

case toggleSettingPresented
case toggleWebViewPresented
case toggleLogoutPresented
case toggleFilterViewPresented
case toggleEraseImageCachesPresented
case toggleEraseCachedListPresented
case toggleDraftCommentViewPresented_Button
Expand All @@ -24,7 +27,6 @@ enum AppAction {
case cleanCommentContent_Button
case cleanCommentContent_BarItem

case toggleSettingPresented
case toggleHomeListType(type: HomeListType)

case fetchSearchItems(keyword: String)
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/データフロー/AppCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ protocol AppCommand {

struct FetchSearchItemsCommand: AppCommand {
let keyword: String
let filter: Filter

func execute(in store: Store) {
let token = SubscriptionToken()
SearchItemsRequest(keyword: keyword)
SearchItemsRequest(keyword: keyword, filter: filter)
.publisher
.receive(on: DispatchQueue.main)
.sink { completion in
Expand Down
Loading

0 comments on commit 40de94e

Please sign in to comment.