diff --git a/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.h b/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.h index 88c6c9e7..43e6a858 100644 --- a/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.h +++ b/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.h @@ -26,6 +26,7 @@ - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser; - (id )photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index; - (void)helpToDelete; +- (void)helpToChangeGroup:(UIViewController *)viewController; @optional diff --git a/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m b/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m index 3b601a0f..d42e9077 100644 --- a/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m +++ b/Pods/MWPhotoBrowser/MWPhotoBrowser/Classes/MWPhotoBrowser.m @@ -207,6 +207,10 @@ - (void)deleteAction { [self.delegate helpToDelete]; } +- (void)changeGroupAction { + [self.delegate helpToChangeGroup:self]; +} + - (void)performLayout { // Setup @@ -434,7 +438,8 @@ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; _viewIsActive = YES; UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteAction)]; - self.navigationItem.rightBarButtonItem = deleteButton; + UIBarButtonItem *changeGroupButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(changeGroupAction)]; + self.navigationItem.rightBarButtonItems = @[deleteButton, changeGroupButton]; } - (void)willMoveToParentViewController:(UIViewController *)parent { diff --git a/e-Hentai.xcodeproj/project.pbxproj b/e-Hentai.xcodeproj/project.pbxproj index cfe24bff..dc08deb8 100644 --- a/e-Hentai.xcodeproj/project.pbxproj +++ b/e-Hentai.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 0103B8BF1A01E6FC00CF314F /* ColorThemeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0103B8BE1A01E6FC00CF314F /* ColorThemeViewController.m */; }; + 01051A941A6CDE1A00DE3461 /* GroupSelectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01051A931A6CDE1A00DE3461 /* GroupSelectViewController.m */; }; 0107D9AA19DBF656006C5673 /* UIAlertView+Hentai.m in Sources */ = {isa = PBXBuildFile; fileRef = 0107D9A919DBF656006C5673 /* UIAlertView+Hentai.m */; }; 010E3ADF19E3B93800B866FB /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 010E3ADE19E3B93800B866FB /* MobileCoreServices.framework */; }; 010E3AE119E3B94700B866FB /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 010E3AE019E3B94700B866FB /* SystemConfiguration.framework */; }; @@ -36,7 +37,8 @@ 01519AF11A3051280091C985 /* IPadPhotoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01519AF01A3051280091C985 /* IPadPhotoViewController.xib */; }; 01519AF51A3053BA0091C985 /* IPadDownloadManagerCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01519AF41A3053BA0091C985 /* IPadDownloadManagerCell.xib */; }; 015B89E819FF9B2500CFA9DE /* SupportKitLocalizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 015B89E619FF9B2500CFA9DE /* SupportKitLocalizable.strings */; }; - 0163C7D719D8FD5300105ECF /* DownloadedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0163C7D619D8FD5300105ECF /* DownloadedViewController.m */; }; + 01622DE11A6F415F004D0632 /* DownloadedGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01622DDC1A6F415F004D0632 /* DownloadedGroupViewController.m */; }; + 01622DE41A6F418B004D0632 /* DownloadedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01622DE31A6F418B004D0632 /* DownloadedViewController.m */; }; 0163E4721A3FD019007C3D58 /* DiveExHentai.m in Sources */ = {isa = PBXBuildFile; fileRef = 0163E4711A3FD019007C3D58 /* DiveExHentai.m */; }; 016A359F19B6FB8A00E3371A /* HentaiParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 016A359E19B6FB8A00E3371A /* HentaiParser.m */; }; 016BBF0B19B94E4F0015E11E /* FilesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 016BBEFB19B94E4F0015E11E /* FilesManager.m */; }; @@ -92,6 +94,7 @@ 01A907F01A493A96006F4179 /* HentaiCacheLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = 01A907EF1A493A96006F4179 /* HentaiCacheLibrary.m */; }; 01AD623E1A5797D500962CBD /* SettingV2ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01AD623D1A5797D500962CBD /* SettingV2ViewController.m */; }; 01B423211A44136400FAB920 /* Pgyer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 01B4231F1A44136400FAB920 /* Pgyer.a */; }; + 01BB0FC11A6CDBBF002FEFC7 /* GroupManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 01BB0FC01A6CDBBF002FEFC7 /* GroupManager.m */; }; 01BBD60119E3D428003538CF /* HentaiPhotoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 01BBD5FF19E3D428003538CF /* HentaiPhotoCell.m */; }; 01BBD60219E3D428003538CF /* HentaiPhotoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01BBD60019E3D428003538CF /* HentaiPhotoCell.xib */; }; 01CD0E2E19DE808B006155FD /* DownloadManagerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01CD0E2C19DE808B006155FD /* DownloadManagerViewController.m */; }; @@ -103,6 +106,8 @@ /* Begin PBXFileReference section */ 0103B8BD1A01E6FC00CF314F /* ColorThemeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorThemeViewController.h; sourceTree = ""; }; 0103B8BE1A01E6FC00CF314F /* ColorThemeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorThemeViewController.m; sourceTree = ""; }; + 01051A921A6CDE1A00DE3461 /* GroupSelectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupSelectViewController.h; sourceTree = ""; }; + 01051A931A6CDE1A00DE3461 /* GroupSelectViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupSelectViewController.m; sourceTree = ""; }; 0107D9A819DBF656006C5673 /* UIAlertView+Hentai.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+Hentai.h"; sourceTree = ""; }; 0107D9A919DBF656006C5673 /* UIAlertView+Hentai.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+Hentai.m"; sourceTree = ""; }; 010E3ADE19E3B93800B866FB /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; @@ -153,8 +158,10 @@ 01519AF41A3053BA0091C985 /* IPadDownloadManagerCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = IPadDownloadManagerCell.xib; path = DownloadManagerViewController/DownloadManagerCell/IPadDownloadManagerCell.xib; sourceTree = ""; }; 015B89E419FF9AC900CFA9DE /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/InfoPlist.strings"; sourceTree = ""; }; 015B89E719FF9B2500CFA9DE /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/SupportKitLocalizable.strings"; sourceTree = ""; }; - 0163C7D519D8FD5300105ECF /* DownloadedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DownloadedViewController.h; path = DownloadedViewController/DownloadedViewController.h; sourceTree = ""; }; - 0163C7D619D8FD5300105ECF /* DownloadedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DownloadedViewController.m; path = DownloadedViewController/DownloadedViewController.m; sourceTree = ""; }; + 01622DDC1A6F415F004D0632 /* DownloadedGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DownloadedGroupViewController.m; sourceTree = ""; }; + 01622DDF1A6F415F004D0632 /* DownloadedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadedViewController.h; sourceTree = ""; }; + 01622DE31A6F418B004D0632 /* DownloadedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DownloadedViewController.m; sourceTree = ""; }; + 01622DE51A6F4192004D0632 /* DownloadedGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadedGroupViewController.h; sourceTree = ""; }; 0163E4701A3FD019007C3D58 /* DiveExHentai.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiveExHentai.h; sourceTree = ""; }; 0163E4711A3FD019007C3D58 /* DiveExHentai.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DiveExHentai.m; sourceTree = ""; }; 016A359D19B6FB8A00E3371A /* HentaiParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HentaiParser.h; sourceTree = ""; }; @@ -241,6 +248,8 @@ 01AD623D1A5797D500962CBD /* SettingV2ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SettingV2ViewController.m; path = SettingViewController/SettingV2ViewController.m; sourceTree = ""; }; 01B4231F1A44136400FAB920 /* Pgyer.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = Pgyer.a; sourceTree = ""; }; 01B423201A44136400FAB920 /* Pgyer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pgyer.h; sourceTree = ""; }; + 01BB0FBF1A6CDBBF002FEFC7 /* GroupManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupManager.h; sourceTree = ""; }; + 01BB0FC01A6CDBBF002FEFC7 /* GroupManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupManager.m; sourceTree = ""; }; 01BBD5FE19E3D428003538CF /* HentaiPhotoCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HentaiPhotoCell.h; path = HentaiPhotoCell/HentaiPhotoCell.h; sourceTree = ""; }; 01BBD5FF19E3D428003538CF /* HentaiPhotoCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HentaiPhotoCell.m; path = HentaiPhotoCell/HentaiPhotoCell.m; sourceTree = ""; }; 01BBD60019E3D428003538CF /* HentaiPhotoCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = HentaiPhotoCell.xib; path = HentaiPhotoCell/HentaiPhotoCell.xib; sourceTree = ""; }; @@ -448,13 +457,23 @@ path = Hpple; sourceTree = ""; }; - 0163C7D419D8FC5600105ECF /* DownloadedViewController */ = { + 01622DDB1A6F415F004D0632 /* DownloadedGroupViewController */ = { isa = PBXGroup; children = ( - 0163C7D519D8FD5300105ECF /* DownloadedViewController.h */, - 0163C7D619D8FD5300105ECF /* DownloadedViewController.m */, + 01622DE51A6F4192004D0632 /* DownloadedGroupViewController.h */, + 01622DDC1A6F415F004D0632 /* DownloadedGroupViewController.m */, + 01622DDD1A6F415F004D0632 /* DownloadedViewController */, ); - name = DownloadedViewController; + path = DownloadedGroupViewController; + sourceTree = ""; + }; + 01622DDD1A6F415F004D0632 /* DownloadedViewController */ = { + isa = PBXGroup; + children = ( + 01622DDF1A6F415F004D0632 /* DownloadedViewController.h */, + 01622DE31A6F418B004D0632 /* DownloadedViewController.m */, + ); + path = DownloadedViewController; sourceTree = ""; }; 0163E46F1A3FD019007C3D58 /* DiveExHentai */ = { @@ -633,6 +652,7 @@ children = ( 013F8F061A490B66002B8C47 /* RealmModels */, 0137F40919C1684500528359 /* HentaiDownloadCenter */, + 01BB0FBE1A6CDB51002FEFC7 /* GroupManager */, 0150033319B6E5E90055F47D /* HentaiParser */, 0163E46F1A3FD019007C3D58 /* DiveExHentai */, 0150033619B6E5E90055F47D /* ThirdParty */, @@ -645,7 +665,7 @@ 011AEA5219DD294200A15CA5 /* MenuViewController */, 0118080A19B6F06200FE0DA1 /* MainViewController */, 01758F711A3FE05300677BA2 /* ExMainViewController */, - 0163C7D419D8FC5600105ECF /* DownloadedViewController */, + 01622DDB1A6F415F004D0632 /* DownloadedGroupViewController */, 01CD0E2A19DE8058006155FD /* DownloadManagerViewController */, 01BFAD4D19DE430A00A5649F /* SettingViewController */, 0118081119B6F06200FE0DA1 /* PhotoViewController */, @@ -687,6 +707,17 @@ path = Pgyer; sourceTree = ""; }; + 01BB0FBE1A6CDB51002FEFC7 /* GroupManager */ = { + isa = PBXGroup; + children = ( + 01BB0FBF1A6CDBBF002FEFC7 /* GroupManager.h */, + 01BB0FC01A6CDBBF002FEFC7 /* GroupManager.m */, + 01051A921A6CDE1A00DE3461 /* GroupSelectViewController.h */, + 01051A931A6CDE1A00DE3461 /* GroupSelectViewController.m */, + ); + path = GroupManager; + sourceTree = ""; + }; 01BBD5FD19E3D415003538CF /* HentaiPhotoCell */ = { isa = PBXGroup; children = ( @@ -879,7 +910,10 @@ 0118081519B6F06200FE0DA1 /* FakeViewController.m in Sources */, 019290241A25D6C70094B423 /* DaiPortalWarehouse.m in Sources */, 0118081B19B6F06200FE0DA1 /* PhotoViewController.m in Sources */, + 01051A941A6CDE1A00DE3461 /* GroupSelectViewController.m in Sources */, + 01622DE11A6F415F004D0632 /* DownloadedGroupViewController.m in Sources */, 0137F40F19C1695800528359 /* HentaiDownloadBookOperation.m in Sources */, + 01622DE41A6F418B004D0632 /* DownloadedViewController.m in Sources */, 016BBF1019B94E4F0015E11E /* LightWeightPlist+SourceFromDisk.m in Sources */, 019290231A25D6C70094B423 /* DaiPortalPerformHelper.m in Sources */, 01A166EC19E28D5E00203360 /* NSDictionary+Hentai.m in Sources */, @@ -887,12 +921,12 @@ 011AEA5119DD28DE00A15CA5 /* SliderViewController.m in Sources */, 019290251A25D6C70094B423 /* NSObject+DaiPortal.m in Sources */, 01BBD60119E3D428003538CF /* HentaiPhotoCell.m in Sources */, + 01BB0FC11A6CDBBF002FEFC7 /* GroupManager.m in Sources */, 013F8F171A490E06002B8C47 /* HentaiSaveLibrary.m in Sources */, 01D068E31A5AACF40062971E /* UIView+Hentai.m in Sources */, 016BBF1119B94E4F0015E11E /* LightWeightPlist.m in Sources */, 019290211A25D6C70094B423 /* DaiPortal.m in Sources */, 016BBF0B19B94E4F0015E11E /* FilesManager.m in Sources */, - 0163C7D719D8FD5300105ECF /* DownloadedViewController.m in Sources */, 016BBF0E19B94E4F0015E11E /* LightWeightPlist+FilePath.m in Sources */, 0137F40C19C1688200528359 /* HentaiDownloadCenter.m in Sources */, 0163E4721A3FD019007C3D58 /* DiveExHentai.m in Sources */, diff --git a/e-Hentai/AppDelegate.m b/e-Hentai/AppDelegate.m index 7d2e3f11..c0c0b954 100644 --- a/e-Hentai/AppDelegate.m +++ b/e-Hentai/AppDelegate.m @@ -73,7 +73,7 @@ - (void)dataTransfer { [SVProgressHUD show]; NSArray *saveDatas = LWPArray(@"HentaiSaveLibrary"); for (NSDictionary *eachData in saveDatas) { - [HentaiSaveLibrary addSaveInfo:eachData]; + [HentaiSaveLibrary addSaveInfo:eachData toGroup:@""]; } LWPDelete(@"HentaiSaveLibrary"); diff --git a/e-Hentai/Common/NSString+Hentai.h b/e-Hentai/Common/NSString+Hentai.h index 9c96c319..34186b9d 100644 --- a/e-Hentai/Common/NSString+Hentai.h +++ b/e-Hentai/Common/NSString+Hentai.h @@ -13,4 +13,7 @@ //原先是取 lastPathComponent, 但是有些漫畫的檔案名稱會重複, 因此把倒數第二個 path 也列入編名 - (NSString *)hentai_lastTwoPathComponent; +//去除空格以及跳行 +- (NSString *)hentai_withoutSpace; + @end diff --git a/e-Hentai/Common/NSString+Hentai.m b/e-Hentai/Common/NSString+Hentai.m index 03b408fc..63324afb 100644 --- a/e-Hentai/Common/NSString+Hentai.m +++ b/e-Hentai/Common/NSString+Hentai.m @@ -16,4 +16,8 @@ - (NSString *)hentai_lastTwoPathComponent { return [NSString stringWithFormat:@"%@-%@", splitArray[lastPathIndex - 1], splitArray[lastPathIndex]]; } +- (NSString *)hentai_withoutSpace { + return [[self componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:@""]; +} + @end diff --git a/e-Hentai/DownloadedGroupViewController/DownloadedGroupViewController.h b/e-Hentai/DownloadedGroupViewController/DownloadedGroupViewController.h new file mode 100644 index 00000000..3ecbbaab --- /dev/null +++ b/e-Hentai/DownloadedGroupViewController/DownloadedGroupViewController.h @@ -0,0 +1,19 @@ +// +// DownloadedGroupViewController.h +// e-Hentai +// +// Created by 啟倫 陳 on 2015/1/19. +// Copyright (c) 2015年 ChilunChen. All rights reserved. +// + +#import "ColorThemeViewController.h" + +#import "OpenMenuProtocol.h" +#import "MenuDefaultCell.h" +#import "DownloadedViewController.h" + +@interface DownloadedGroupViewController : ColorThemeViewController + +@property (nonatomic, weak) id delegate; + +@end diff --git a/e-Hentai/DownloadedGroupViewController/DownloadedGroupViewController.m b/e-Hentai/DownloadedGroupViewController/DownloadedGroupViewController.m new file mode 100644 index 00000000..7e321a22 --- /dev/null +++ b/e-Hentai/DownloadedGroupViewController/DownloadedGroupViewController.m @@ -0,0 +1,91 @@ +// +// DownloadedGroupViewController.m +// e-Hentai +// +// Created by 啟倫 陳 on 2015/1/19. +// Copyright (c) 2015年 ChilunChen. All rights reserved. +// + +#import "DownloadedGroupViewController.h" + +@interface DownloadedGroupViewController () + +@property (nonatomic, strong) UITableView *downloadedGroupTableView; +@property (nonatomic, strong) NSMutableArray *groups; + +@end + +@implementation DownloadedGroupViewController + +#pragma mark - UITableViewDataSource + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return [self.groups count]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + MenuDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDefaultCell"]; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + cell.textLabel.text = self.groups[indexPath.row][@"title"]; + return cell; +} + +#pragma mark - UITableViewDelegate + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + DownloadedViewController *downloadedViewController = [DownloadedViewController new]; + if ([self.groups[indexPath.row][@"value"] isKindOfClass:[NSString class]]) { + downloadedViewController.group = self.groups[indexPath.row][@"value"]; + } + downloadedViewController.delegate = self.delegate; + [self.navigationController pushViewController:downloadedViewController animated:YES]; +} + +#pragma mark - private + +#pragma mark * init + +- (void)setupInitValues { + self.groups = [NSMutableArray array]; +} + +- (void)setupItemsOnNavigation { + UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self.delegate action:@selector(sliderControl)]; + self.navigationItem.leftBarButtonItem = menuButton; +} + +- (void)setupDownloadedGroupTableView { + self.downloadedGroupTableView = [[UITableView alloc] initWithFrame:self.view.bounds]; + self.downloadedGroupTableView.delegate = self; + self.downloadedGroupTableView.dataSource = self; + self.downloadedGroupTableView.backgroundColor = [UIColor clearColor]; + [self.downloadedGroupTableView registerClass:[MenuDefaultCell class] forCellReuseIdentifier:@"MenuDefaultCell"]; + [self.view addSubview:self.downloadedGroupTableView]; +} + +#pragma mark * misc + +//重載列表 +- (void)reloadGroups { + [self.groups removeAllObjects]; + [self.groups addObject:@{@"title":@"全部", @"value":@""}]; + [self.groups addObject:@{@"title":@"未分類", @"value":[NSNull null]}]; + [self.groups addObjectsFromArray:[HentaiSaveLibrary groups]]; + [self.downloadedGroupTableView reloadData]; +} + +#pragma mark - life cycle + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setupInitValues]; + [self setupItemsOnNavigation]; + [self setupDownloadedGroupTableView]; +} + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + [self reloadGroups]; +} + +@end diff --git a/e-Hentai/DownloadedViewController/DownloadedViewController.h b/e-Hentai/DownloadedGroupViewController/DownloadedViewController/DownloadedViewController.h similarity index 85% rename from e-Hentai/DownloadedViewController/DownloadedViewController.h rename to e-Hentai/DownloadedGroupViewController/DownloadedViewController/DownloadedViewController.h index d46032b9..238af793 100644 --- a/e-Hentai/DownloadedViewController/DownloadedViewController.h +++ b/e-Hentai/DownloadedGroupViewController/DownloadedViewController/DownloadedViewController.h @@ -10,4 +10,6 @@ @interface DownloadedViewController : MainViewController +@property (nonatomic, strong) NSString *group; + @end diff --git a/e-Hentai/DownloadedViewController/DownloadedViewController.m b/e-Hentai/DownloadedGroupViewController/DownloadedViewController/DownloadedViewController.m similarity index 67% rename from e-Hentai/DownloadedViewController/DownloadedViewController.m rename to e-Hentai/DownloadedGroupViewController/DownloadedViewController/DownloadedViewController.m index f8f52590..562fe16e 100644 --- a/e-Hentai/DownloadedViewController/DownloadedViewController.m +++ b/e-Hentai/DownloadedGroupViewController/DownloadedViewController/DownloadedViewController.m @@ -15,24 +15,43 @@ @interface DownloadedViewController () @property (nonatomic, strong) NSDictionary *currentInfo; @property (nonatomic, assign) BOOL onceFlag; @property (nonatomic, strong) NSMutableDictionary *textViewCacheMapping; +@property (nonatomic, readonly) NSUInteger hentaiSaveLibraryCount; @end @implementation DownloadedViewController +@dynamic hentaiSaveLibraryCount; + +#pragma mark - dynamic + +- (NSUInteger)hentaiSaveLibraryCount { + if (self.group) { + if ([self.group isEqualToString:@""]) { + return [HentaiSaveLibrary count]; + } + else { + return [HentaiSaveLibrary countByGroup:self.group]; + } + } + else { + return [HentaiSaveLibrary countByGroup:@""]; + } +} + #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [HentaiSaveLibrary count]; + return self.hentaiSaveLibraryCount; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - NSUInteger inverseIndex = [HentaiSaveLibrary count] - 1 - indexPath.section; + NSUInteger inverseIndex = self.hentaiSaveLibraryCount - 1 - indexPath.section; static NSString *identifier = @"MainTableViewCell"; MainTableViewCell *cell = (MainTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; - NSDictionary *hentaiInfo = [HentaiSaveLibrary saveInfoAtIndex:inverseIndex][@"hentaiInfo"]; + NSDictionary *hentaiInfo = [self saveInfoAtIndex:inverseIndex][@"hentaiInfo"]; //設定 ipad / iphone 共通資訊 NSURL *imageURL = [NSURL URLWithString:hentaiInfo[@"thumb"]]; @@ -58,9 +77,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N #pragma mark - UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { - NSUInteger inverseIndex = [HentaiSaveLibrary count] - 1 - section; + NSUInteger inverseIndex = self.hentaiSaveLibraryCount - 1 - section; - NSString *sectinoText = [HentaiSaveLibrary saveInfoAtIndex:inverseIndex][@"hentaiInfo"][@"title"]; + NSString *sectinoText = [self saveInfoAtIndex:inverseIndex][@"hentaiInfo"][@"title"]; UITextView *titleTextView = self.textViewCacheMapping[sectinoText]; if (!titleTextView) { titleTextView = [UITextView new]; @@ -77,16 +96,16 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { - NSUInteger inverseIndex = [HentaiSaveLibrary count] - 1 - section; + NSUInteger inverseIndex = self.hentaiSaveLibraryCount - 1 - section; - NSString *sectinoText = [HentaiSaveLibrary saveInfoAtIndex:inverseIndex][@"hentaiInfo"][@"title"]; + NSString *sectinoText = [self saveInfoAtIndex:inverseIndex][@"hentaiInfo"][@"title"]; return self.textViewCacheMapping[sectinoText]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - NSUInteger inverseIndex = [HentaiSaveLibrary count] - 1 - indexPath.section; + NSUInteger inverseIndex = self.hentaiSaveLibraryCount - 1 - indexPath.section; - self.currentInfo = [HentaiSaveLibrary saveInfoAtIndex:inverseIndex]; + self.currentInfo = [self saveInfoAtIndex:inverseIndex]; NSDictionary *hentaiInfo = self.currentInfo[@"hentaiInfo"]; if ([[HentaiSettingManager temporarySettings][@"useNewBrowser"] boolValue]) { @@ -112,6 +131,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath else { PhotoViewController *photoViewController = [PhotoViewController new]; photoViewController.hentaiInfo = hentaiInfo; + photoViewController.originGroup = self.currentInfo[@"group"]; [self.delegate needToPushViewController:photoViewController]; } } @@ -130,30 +150,53 @@ - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser { } - (void)helpToDelete { + @weakify(self); [UIAlertView hentai_alertViewWithTitle:@"警告~ O3O" message:@"確定要刪除這部作品嗎?" cancelButtonTitle:@"我按錯了~ Q3Q" otherButtonTitles:@[@"對~ O3O 不好看~"] onClickIndex:^(NSInteger clickIndex) { - [self.navigationController popViewControllerAnimated:YES]; - NSDictionary *hentaiInfo = self.currentInfo[@"hentaiInfo"]; - NSString *hentaiKey = [hentaiInfo hentai_hentaiKey]; - - [[[FilesManager documentFolder] fcd:@"Hentai"] rd:hentaiKey]; - [HentaiSaveLibrary removeSaveInfoAtIndex:[HentaiSaveLibrary indexOfHentaiKey:hentaiKey]]; + @strongify(self); + if (self) { + [self.navigationController popViewControllerAnimated:YES]; + NSDictionary *hentaiInfo = self.currentInfo[@"hentaiInfo"]; + NSString *hentaiKey = [hentaiInfo hentai_hentaiKey]; + + [[[FilesManager documentFolder] fcd:@"Hentai"] rd:hentaiKey]; + [HentaiSaveLibrary removeSaveInfoAtHentaiKey:hentaiKey]; + } } onCancel:^{ }]; } +- (void)helpToChangeGroup:(UIViewController *)viewController { + @weakify(self); + [GroupManager presentFromViewController:viewController originGroup:self.currentInfo[@"group"] completion:^(NSString *selectedGroup) { + @strongify(self); + if (self && selectedGroup) { + [HentaiSaveLibrary changeToGroup:selectedGroup atHentaiKey:self.currentInfo[@"hentaiKey"]]; + } + }]; +} + #pragma mark - private #pragma mark * override methods from MainViewController - (void)setupInitValues { - self.title = @"已經下載的漫畫"; + if (self.group) { + if ([self.group isEqualToString:@""]) { + self.title = @"全部"; + } + else { + self.title = self.group; + } + } + else { + self.title = @"未分類"; + } + self.onceFlag = NO; self.textViewCacheMapping = [NSMutableDictionary dictionary]; } - (void)setupItemsOnNavigation { - UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self.delegate action:@selector(sliderControl)]; - self.navigationItem.leftBarButtonItem = menuButton; } - (void)setupRefreshControlOnTableView { @@ -171,11 +214,32 @@ - (void)setupRecvNotifications { - (void)allowNavigationBarGesture { } +#pragma mark * misc + +- (NSDictionary *)saveInfoAtIndex:(NSUInteger)index { + if (self.group) { + if ([self.group isEqualToString:@""]) { + return [HentaiSaveLibrary saveInfoAtIndex:index]; + } + else { + return [HentaiSaveLibrary saveInfoAtIndex:index byGroup:self.group]; + } + } + else { + return [HentaiSaveLibrary saveInfoAtIndex:index byGroup:@""]; + } +} + #pragma mark - life cycle - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [self.listTableView reloadData]; + if (self.hentaiSaveLibraryCount) { + [self.listTableView reloadData]; + } + else { + [self.navigationController popViewControllerAnimated:YES]; + } } @end diff --git a/e-Hentai/GroupManager/GroupManager.h b/e-Hentai/GroupManager/GroupManager.h new file mode 100644 index 00000000..2246a0a3 --- /dev/null +++ b/e-Hentai/GroupManager/GroupManager.h @@ -0,0 +1,19 @@ +// +// GroupManager.h +// e-Hentai +// +// Created by 啟倫 陳 on 2015/1/19. +// Copyright (c) 2015年 ChilunChen. All rights reserved. +// + +#import + +@interface GroupManager : NSObject + +//開啓分類選擇 ++ (void)presentFromViewController:(UIViewController *)viewController completion:(void (^)(NSString *selectedGroup))completion; + +//開啓分類選擇, 已有原先分類 ++ (void)presentFromViewController:(UIViewController *)viewController originGroup:(NSString *)originGroup completion:(void (^)(NSString *selectedGroup))completion; + +@end diff --git a/e-Hentai/GroupManager/GroupManager.m b/e-Hentai/GroupManager/GroupManager.m new file mode 100644 index 00000000..c037a1a0 --- /dev/null +++ b/e-Hentai/GroupManager/GroupManager.m @@ -0,0 +1,31 @@ +// +// GroupManager.m +// e-Hentai +// +// Created by 啟倫 陳 on 2015/1/19. +// Copyright (c) 2015年 ChilunChen. All rights reserved. +// + +#import "GroupManager.h" + +#import "GroupSelectViewController.h" +#import "HentaiNavigationController.h" + +@implementation GroupManager + ++ (void)presentFromViewController:(UIViewController *)viewController completion:(void (^)(NSString *selectedGroup))completion { + [self presentFromViewController:viewController originGroup:@"" completion:completion]; +} + ++ (void)presentFromViewController:(UIViewController *)viewController originGroup:(NSString *)originGroup completion:(void (^)(NSString *selectedGroup))completion { + GroupSelectViewController *groupSelectViewController = [GroupSelectViewController new]; + groupSelectViewController.completion = completion; + groupSelectViewController.originGroup = originGroup; + HentaiNavigationController *hentaiNavigation = [[HentaiNavigationController alloc] initWithRootViewController:groupSelectViewController]; + hentaiNavigation.autoRotate = NO; + hentaiNavigation.hentaiMask = UIInterfaceOrientationMaskPortrait; + [viewController presentViewController:hentaiNavigation animated:YES completion: ^{ + }]; +} + +@end diff --git a/e-Hentai/GroupManager/GroupSelectViewController.h b/e-Hentai/GroupManager/GroupSelectViewController.h new file mode 100644 index 00000000..e54d65e0 --- /dev/null +++ b/e-Hentai/GroupManager/GroupSelectViewController.h @@ -0,0 +1,16 @@ +// +// GroupSelectViewController.h +// e-Hentai +// +// Created by 啟倫 陳 on 2015/1/19. +// Copyright (c) 2015年 ChilunChen. All rights reserved. +// + +#import "QuickDialogController.h" + +@interface GroupSelectViewController : QuickDialogController + +@property (nonatomic, copy) void (^completion)(NSString *selectedGroup); +@property (nonatomic, strong) NSString *originGroup; + +@end diff --git a/e-Hentai/GroupManager/GroupSelectViewController.m b/e-Hentai/GroupManager/GroupSelectViewController.m new file mode 100644 index 00000000..d194a27a --- /dev/null +++ b/e-Hentai/GroupManager/GroupSelectViewController.m @@ -0,0 +1,140 @@ +// +// GroupSelectViewController.m +// e-Hentai +// +// Created by 啟倫 陳 on 2015/1/19. +// Copyright (c) 2015年 ChilunChen. All rights reserved. +// + +#import "GroupSelectViewController.h" + +@interface GroupSelectViewController () + +@property (nonatomic, strong) NSMutableArray *groupTitles; + +@end + +@implementation GroupSelectViewController + +- (void)setOriginGroup:(NSString *)originGroup { + _originGroup = originGroup; + NSInteger selectedIndex = -1; + for (NSString *eachTitle in self.groupTitles) { + if ([eachTitle isEqualToString:originGroup]) { + selectedIndex = [self.groupTitles indexOfObject:eachTitle]; + break; + } + } + QSection *existingGroupSection = [self.root sectionWithKey:@"existingGroupSection"]; + QRadioElement *existingGroupElement = existingGroupSection.elements[0]; + existingGroupElement.selected = selectedIndex; + [self.quickDialogTableView reloadData]; +} + +#pragma mark - private + +#pragma mark * init + +- (QRootElement *)rootMaker { + //基本樣貌設定 + QRootElement *root = [QRootElement new]; + root.grouped = YES; + root.title = @"選擇分類"; + root.controllerName = @"GroupSelectViewController"; + + //建立分類 section + QSection *createGroupSection = [[QSection alloc] initWithTitle:@"建立分類"]; + QEntryElement *createGroupElement = [[QEntryElement alloc] initWithTitle:@"建立一個新的分類" Value:@"" Placeholder:@"留白則為不分類"]; + createGroupElement.key = @"createGroup"; + [createGroupSection addElement:createGroupElement]; + [root addSection:createGroupSection]; + + NSArray *groups = [HentaiSaveLibrary groups]; + + //如果有舊有分類才秀這個部分 + if ([groups count]) { + self.groupTitles = [NSMutableArray array]; + for (NSDictionary *eachGroup in groups) { + [self.groupTitles addObject:eachGroup[@"title"]]; + } + QSection *existingGroupSection = [[QSection alloc] initWithTitle:@"舊有分類"]; + existingGroupSection.key = @"existingGroupSection"; + QRadioElement *existingGroupElement = [[QRadioElement alloc] initWithItems:self.groupTitles selected:-1 title:@"從舊有分類選擇"]; + existingGroupElement.key = @"existingGroup"; + [existingGroupSection addElement:existingGroupElement]; + [root addSection:existingGroupSection]; + } + + return root; +} + +- (void)setupItemsOnNavigation { + UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction)]; + self.navigationItem.leftBarButtonItem = cancelButton; + + UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction)]; + self.navigationItem.rightBarButtonItem = doneButton; +} + +#pragma mark * actions + +- (void)cancelAction { + @weakify(self); + [self dismissViewControllerAnimated:YES completion:^{ + @strongify(self); + if (self) { + self.completion(nil); + } + }]; +} + +- (void)doneAction { + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + [self.root fetchValueIntoObject:result]; + + NSString *createGroupString = [result[@"createGroup"] hentai_withoutSpace]; + + @weakify(self); + [self dismissViewControllerAnimated:YES completion:^{ + @strongify(self); + + if (self) { + //沒有舊分類的時候 + if ([result count] == 1) { + self.completion(createGroupString); + } + else { + NSNumber *indexOfExistingGroup = result[@"existingGroup"]; + if ([indexOfExistingGroup integerValue] == -1) { + self.completion(createGroupString); + } + else { + NSString *existingGroupString = [self.groupTitles[[indexOfExistingGroup integerValue]] hentai_withoutSpace]; + + if (![createGroupString isEqualToString:@""]) { + self.completion(createGroupString); + } + else { + self.completion(existingGroupString); + } + } + } + } + }]; +} + +#pragma mark - life cycle + +- (id)init { + self = [super initWithRoot:[self rootMaker]]; + if (self) { + } + return self; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setupItemsOnNavigation]; +} + +@end diff --git a/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.h b/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.h index d9256981..af819f99 100644 --- a/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.h +++ b/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.h @@ -22,6 +22,7 @@ typedef enum { @property (nonatomic, weak) id delegate; @property (nonatomic, strong) NSDictionary *hentaiInfo; +@property (nonatomic, strong) NSString *group; @property (nonatomic, assign) HentaiDownloadBookOperationStatus status; @property (nonatomic, readonly) NSInteger recvCount; @property (nonatomic, readonly) NSInteger totalCount; diff --git a/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.m b/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.m index f2a4c78f..68bda4db 100644 --- a/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.m +++ b/e-Hentai/HentaiDownloadCenter/HentaiDownloadBookOperation.m @@ -195,7 +195,7 @@ - (void)checkEndOfFile { if ([self verifySaveInfo:saveInfo]) { //如果 cache 有暫存就殺光光 [[[FilesManager cacheFolder] fcd:@"Hentai"] rd:self.hentaiKey]; - [HentaiSaveLibrary addSaveInfo:saveInfo]; + [HentaiSaveLibrary addSaveInfo:saveInfo toGroup:self.group]; [HentaiCacheLibrary removeCacheInfoForKey:self.hentaiKey]; [[self portal:HentaiDownloadSuccessNotification] send:[DaiPortalPackage item:self.hentaiInfo[@"title"]]]; } diff --git a/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.h b/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.h index b1d7d92f..64595fef 100644 --- a/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.h +++ b/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.h @@ -17,7 +17,7 @@ typedef void (^HentaiMonitorBlock)(NSDictionary *centerDetail); @interface HentaiDownloadCenter : NSObject -+ (void)addBook:(NSDictionary *)hentaiInfo; ++ (void)addBook:(NSDictionary *)hentaiInfo toGroup:(NSString *)group; + (BOOL)isDownloading:(NSDictionary *)hentaiInfo; + (BOOL)isActiveFolder:(NSString *)folder; diff --git a/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.m b/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.m index 17d2faeb..d159381b 100644 --- a/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.m +++ b/e-Hentai/HentaiDownloadCenter/HentaiDownloadCenter.m @@ -46,10 +46,10 @@ + (void)hentaiDownloadBookOperationChange:(HentaiDownloadBookOperation *)operati #pragma mark - class method -+ (void)addBook:(NSDictionary *)hentaiInfo { ++ (void)addBook:(NSDictionary *)hentaiInfo toGroup:(NSString *)group { //下載過的話不給下 - BOOL isExist = ([HentaiSaveLibrary indexOfHentaiKey:[hentaiInfo hentai_hentaiKey]] == NSNotFound)?NO:YES; + BOOL isExist = ([HentaiSaveLibrary saveInfoAtHentaiKey:[hentaiInfo hentai_hentaiKey]])?YES:NO; //如果在 queue 裡面也不給下 isExist = isExist | [self isDownloading:hentaiInfo]; @@ -61,6 +61,7 @@ + (void)addBook:(NSDictionary *)hentaiInfo { HentaiDownloadBookOperation *newOperation = [HentaiDownloadBookOperation new]; newOperation.delegate = (id )self; newOperation.hentaiInfo = hentaiInfo; + newOperation.group = group; newOperation.status = HentaiDownloadBookOperationStatusWaiting; [self operationActivity:newOperation]; [[self allBooksOperationQueue] addOperation:newOperation]; diff --git a/e-Hentai/MainViewController/MainViewController.m b/e-Hentai/MainViewController/MainViewController.m index 3210fdc4..9eca50a8 100644 --- a/e-Hentai/MainViewController/MainViewController.m +++ b/e-Hentai/MainViewController/MainViewController.m @@ -115,12 +115,12 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *hentaiInfo = self.listArray[indexPath.section]; - NSUInteger indexInHentaiSaveLibrary = [HentaiSaveLibrary indexOfHentaiKey:[hentaiInfo hentai_hentaiKey]]; - BOOL isExist = (indexInHentaiSaveLibrary == NSNotFound)?NO:YES; + NSDictionary *saveInfo = [HentaiSaveLibrary saveInfoAtHentaiKey:[hentaiInfo hentai_hentaiKey]]; - if (isExist) { + if (saveInfo) { PhotoViewController *photoViewController = [PhotoViewController new]; - photoViewController.hentaiInfo = [HentaiSaveLibrary saveInfoAtIndex:indexInHentaiSaveLibrary][@"hentaiInfo"]; + photoViewController.hentaiInfo = saveInfo[@"hentaiInfo"]; + photoViewController.originGroup = @""; [self.delegate needToPushViewController:photoViewController]; } else { @@ -144,11 +144,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath else { PhotoViewController *photoViewController = [PhotoViewController new]; photoViewController.hentaiInfo = hentaiInfo; + photoViewController.originGroup = @""; [self.delegate needToPushViewController:photoViewController]; } } else { - [HentaiDownloadCenter addBook:hentaiInfo]; + [GroupManager presentFromViewController:self completion:^(NSString *selectedGroup) { + if (selectedGroup) { + [HentaiDownloadCenter addBook:hentaiInfo toGroup:selectedGroup]; + } + }]; } } onCancel:nil]; } @@ -189,8 +194,7 @@ - (NSString *)filterDependOnURL:(NSString *)urlString { } //去除掉空白換行字符後, 如果長度不為 0, 則表示有字 - NSCharacterSet *emptyCharacter = [NSCharacterSet whitespaceAndNewlineCharacterSet]; - if ([[[HentaiSettingManager temporaryHentaiPrefer][@"searchText"] componentsSeparatedByCharactersInSet:emptyCharacter] componentsJoinedByString:@""].length) { + if ([[HentaiSettingManager temporaryHentaiPrefer][@"searchText"] hentai_withoutSpace].length) { [filterURLString appendFormat:@"&f_search=%@", [HentaiSettingManager temporaryHentaiPrefer][@"searchText"]]; } [filterURLString appendString:@"&f_apply=Apply+Filter"]; diff --git a/e-Hentai/Menu.plist b/e-Hentai/Menu.plist index cc7633e5..ba84ec21 100644 --- a/e-Hentai/Menu.plist +++ b/e-Hentai/Menu.plist @@ -24,7 +24,7 @@ image dropbox_copyrighted controller - DownloadedViewController + DownloadedGroupViewController displayName diff --git a/e-Hentai/PhotoViewController/PhotoViewController.h b/e-Hentai/PhotoViewController/PhotoViewController.h index 63cf5619..dcfbc8d0 100644 --- a/e-Hentai/PhotoViewController/PhotoViewController.h +++ b/e-Hentai/PhotoViewController/PhotoViewController.h @@ -17,6 +17,7 @@ @interface PhotoViewController : ColorThemeViewController @property (nonatomic, strong) NSDictionary *hentaiInfo; +@property (nonatomic, strong) NSString *originGroup; @property (weak, nonatomic) IBOutlet UITableView *hentaiTableView; @end diff --git a/e-Hentai/PhotoViewController/PhotoViewController.m b/e-Hentai/PhotoViewController/PhotoViewController.m index 83233567..877aec59 100644 --- a/e-Hentai/PhotoViewController/PhotoViewController.m +++ b/e-Hentai/PhotoViewController/PhotoViewController.m @@ -39,19 +39,6 @@ @interface PhotoViewController () @property (nonatomic, assign) BOOL isHighResolution; -- (void)backAction; -- (void)saveAction; -- (void)deleteAction; - -- (void)setupInitValues; - -- (CGSize)imagePortraitHeight:(CGSize)landscapeSize; -- (void)preloadImages:(NSArray *)images; -- (NSInteger)availableCount; - -- (void)setupForDownloadedIndex:(NSUInteger)index; -- (NSUInteger)indexOfHentaiKey; - @end @implementation PhotoViewController @@ -92,22 +79,42 @@ - (void)backAction { } - (void)saveAction { + @weakify(self); [UIAlertView hentai_alertViewWithTitle:@"你想要儲存這本漫畫嗎?" message:nil cancelButtonTitle:@"不要好了...Q3Q" otherButtonTitles:@[@"加入下載管理員~ O3O"] onClickIndex: ^(NSInteger clickIndex) { - [HentaiDownloadCenter addBook:self.hentaiInfo]; - [self backAction]; + [GroupManager presentFromViewController:self completion:^(NSString *selectedGroup) { + @strongify(self); + if (self && selectedGroup) { + [HentaiDownloadCenter addBook:self.hentaiInfo toGroup:selectedGroup]; + [self backAction]; + } + }]; } onCancel: ^{ }]; } - (void)deleteAction { + @weakify(self); [UIAlertView hentai_alertViewWithTitle:@"警告~ O3O" message:@"確定要刪除這部作品嗎?" cancelButtonTitle:@"我按錯了~ Q3Q" otherButtonTitles:@[@"對~ O3O 不好看~"] onClickIndex:^(NSInteger clickIndex) { - [[[FilesManager documentFolder] fcd:@"Hentai"] rd:self.hentaiKey]; - [HentaiSaveLibrary removeSaveInfoAtIndex:[self indexOfHentaiKey]]; - [self backAction]; + @strongify(self); + if (self) { + [[[FilesManager documentFolder] fcd:@"Hentai"] rd:self.hentaiKey]; + [HentaiSaveLibrary removeSaveInfoAtHentaiKey:self.hentaiKey]; + [self backAction]; + } } onCancel:^{ }]; } +- (void)changeGroupAction { + @weakify(self); + [GroupManager presentFromViewController:self originGroup:self.originGroup completion:^(NSString *selectedGroup) { + @strongify(self); + if (self && selectedGroup) { + [HentaiSaveLibrary changeToGroup:selectedGroup atHentaiKey:self.hentaiKey]; + } + }]; +} + #pragma mark - setup inits - (void)setupInitValues { @@ -204,10 +211,10 @@ - (void)preloadImages:(NSArray *)images { } //設定下載好的相關資料 -- (void)setupForDownloadedIndex:(NSUInteger)index { +- (void)setupForDownloadedSaveInfo:(NSDictionary *)saveInfo { UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteAction)]; - self.navigationItem.rightBarButtonItem = deleteButton; - NSDictionary *saveInfo = [HentaiSaveLibrary saveInfoAtIndex:index]; + UIBarButtonItem *changeGroupButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(changeGroupAction)]; + self.navigationItem.rightBarButtonItems = @[deleteButton, changeGroupButton]; [self.hentaiImageURLs setArray:saveInfo[@"images"]]; [self.hentaiResults setDictionary:saveInfo[@"hentaiResult"]]; self.realDisplayCount = [self.hentaiImageURLs count]; @@ -215,11 +222,6 @@ - (void)setupForDownloadedIndex:(NSUInteger)index { [self.hentaiTableView reloadData]; } -//找尋是不是有下載過 -- (NSUInteger)indexOfHentaiKey { - return [HentaiSaveLibrary indexOfHentaiKey:self.hentaiKey]; -} - #pragma mark - HentaiDownloadImageOperationDelegate - (void)downloadResult:(NSString *)urlString heightOfSize:(CGFloat)height isSuccess:(BOOL)isSuccess { @@ -365,11 +367,11 @@ - (void)viewDidLoad { [super viewDidLoad]; [self setupInitValues]; - NSUInteger indexOfHentaiKey = [self indexOfHentaiKey]; + NSDictionary *saveInfo = [HentaiSaveLibrary saveInfoAtHentaiKey:self.hentaiKey]; //如果本機有存檔案就用本機的 - if (indexOfHentaiKey != NSNotFound) { - [self setupForDownloadedIndex:indexOfHentaiKey]; + if (saveInfo) { + [self setupForDownloadedSaveInfo:saveInfo]; } //否則則從網路上取得 else { @@ -409,7 +411,7 @@ - (void)viewWillDisappear:(BOOL)animated { //結束時把 queue 清掉, 並且記錄目前已下載的東西有哪些 [self.hentaiQueue cancelAllOperations]; - if ([self indexOfHentaiKey] != NSNotFound) { + if ([HentaiSaveLibrary saveInfoAtHentaiKey:self.hentaiKey]) { [HentaiCacheLibrary removeCacheInfoForKey:self.hentaiKey]; } else { diff --git a/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.h b/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.h index 81336e49..85c02f7b 100644 --- a/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.h +++ b/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.h @@ -20,11 +20,15 @@ @property RLMArray *hentaiResult; @property RLMArray *images; -+ (void)addSaveInfo:(NSDictionary *)saveInfo; ++ (void)addSaveInfo:(NSDictionary *)saveInfo toGroup:(NSString *)group; + (NSUInteger)count; -+ (NSUInteger)indexOfHentaiKey:(NSString *)hentaiKey; ++ (NSUInteger)countByGroup:(NSString *)group; ++ (void)changeToGroup:(NSString *)group atHentaiKey:(NSString *)hentaiKey; ++ (NSDictionary *)saveInfoAtHentaiKey:(NSString *)hentaiKey; + (NSDictionary *)saveInfoAtIndex:(NSUInteger)index; -+ (void)removeSaveInfoAtIndex:(NSUInteger)index; ++ (NSDictionary *)saveInfoAtIndex:(NSUInteger)index byGroup:(NSString *)group; ++ (void)removeSaveInfoAtHentaiKey:(NSString *)hentaiKey; ++ (NSArray *)groups; @end diff --git a/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.m b/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.m index 295b14f4..ba034180 100644 --- a/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.m +++ b/e-Hentai/RealmModels/HentaiSaveLibrary/HentaiSaveLibrary.m @@ -13,10 +13,10 @@ @implementation HentaiSaveLibrary #pragma mark - class method //儲存整本作品的資訊 -+ (void)addSaveInfo:(NSDictionary *)saveInfo { ++ (void)addSaveInfo:(NSDictionary *)saveInfo toGroup:(NSString *)group { HentaiSaveLibrary *newLibrary = [HentaiSaveLibrary new]; newLibrary.hentaiKey = saveInfo[@"hentaiKey"]; - newLibrary.group = @""; + newLibrary.group = group; HentaiSaveLibrary_HentaiInfo *newInfo = [HentaiSaveLibrary_HentaiInfo new]; newInfo.category = saveInfo[@"hentaiInfo"][@"category"]; @@ -57,22 +57,93 @@ + (NSUInteger)count { return [[HentaiSaveLibrary allObjectsInRealm:[self hentaiSaveLibraryRealm]] count]; } -//用 hentaiKey 查詢所在 index -+ (NSUInteger)indexOfHentaiKey:(NSString *)hentaiKey { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hentaiKey contains[c] %@", hentaiKey]; +//某個 group 的數量 ++ (NSUInteger)countByGroup:(NSString *)group { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"group == %@", group]; + return [[HentaiSaveLibrary objectsInRealm:[self hentaiSaveLibraryRealm] withPredicate:predicate] count]; +} + +//update 某一個作品的 group ++ (void)changeToGroup:(NSString *)group atHentaiKey:(NSString *)hentaiKey { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hentaiKey == %@", hentaiKey]; RLMResults *resultObjects = [HentaiSaveLibrary objectsInRealm:[self hentaiSaveLibraryRealm] withPredicate:predicate]; if (resultObjects.count) { - return [[HentaiSaveLibrary allObjectsInRealm:[self hentaiSaveLibraryRealm]] indexOfObject:[resultObjects firstObject]]; + HentaiSaveLibrary *saveInfo = [resultObjects firstObject]; + [[self hentaiSaveLibraryRealm] beginWriteTransaction]; + saveInfo.group = group; + [[self hentaiSaveLibraryRealm] commitWriteTransaction]; } - return NSNotFound; +} + +//從 hentaikey 直接回 saveinfo ++ (NSDictionary *)saveInfoAtHentaiKey:(NSString *)hentaiKey { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hentaiKey == %@", hentaiKey]; + RLMResults *resultObjects = [HentaiSaveLibrary objectsInRealm:[self hentaiSaveLibraryRealm] withPredicate:predicate]; + if (resultObjects.count) { + HentaiSaveLibrary *saveInfo = [resultObjects firstObject]; + return [self dictionaryFromRealm:saveInfo]; + } + return nil; } //指定 index 返回內容 + (NSDictionary *)saveInfoAtIndex:(NSUInteger)index { - NSMutableDictionary *returnInfo = [NSMutableDictionary dictionary]; HentaiSaveLibrary *infoObject = [[HentaiSaveLibrary allObjectsInRealm:[self hentaiSaveLibraryRealm]] objectAtIndex:index]; + return [self dictionaryFromRealm:infoObject]; +} + ++ (NSDictionary *)saveInfoAtIndex:(NSUInteger)index byGroup:(NSString *)group { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"group == %@", group]; + HentaiSaveLibrary *infoObject = [[HentaiSaveLibrary objectsInRealm:[self hentaiSaveLibraryRealm] withPredicate:predicate] objectAtIndex:index]; + return [self dictionaryFromRealm:infoObject]; +} + +//移除某一個 hentaikey 的內容 ++ (void)removeSaveInfoAtHentaiKey:(NSString *)hentaiKey { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hentaiKey == %@", hentaiKey]; + RLMResults *resultObjects = [HentaiSaveLibrary objectsInRealm:[self hentaiSaveLibraryRealm] withPredicate:predicate]; + if (resultObjects.count) { + HentaiSaveLibrary *removeObject = [resultObjects firstObject]; + [self removeHentaiSaveLibrary:removeObject]; + } +} + ++ (NSArray *)groups { + NSMutableDictionary *categorys = [NSMutableDictionary dictionary]; + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"group != %@", @""]; + RLMResults *resultObjects = [HentaiSaveLibrary objectsInRealm:[self hentaiSaveLibraryRealm] withPredicate:predicate]; for (HentaiSaveLibrary *eachHentaiSaveLibrary in resultObjects) { + if (![eachHentaiSaveLibrary.group isEqualToString:@""]) { + categorys[eachHentaiSaveLibrary.group] = eachHentaiSaveLibrary.group; + } + } + NSMutableArray *groups = [NSMutableArray array]; + for (NSString *eachKey in [categorys allKeys]) { + [groups addObject:@{@"title":eachKey, @"value":eachKey}]; + } + return [groups sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *obj1, NSDictionary *obj2) { + NSString *string1 = obj1[@"title"]; + NSString *string2 = obj2[@"title"]; + return [string1 compare:string2]; + }]; +} + +#pragma mark - private + ++ (void)removeHentaiSaveLibrary:(HentaiSaveLibrary *)removeObject { + [[self hentaiSaveLibraryRealm] beginWriteTransaction]; + [[self hentaiSaveLibraryRealm] deleteObject:removeObject.hentaiInfo]; + [[self hentaiSaveLibraryRealm] deleteObjects:removeObject.hentaiResult]; + [[self hentaiSaveLibraryRealm] deleteObjects:removeObject.images]; + [[self hentaiSaveLibraryRealm] deleteObject:removeObject]; + [[self hentaiSaveLibraryRealm] commitWriteTransaction]; +} + ++ (NSDictionary *)dictionaryFromRealm:(HentaiSaveLibrary *)realm { + NSMutableDictionary *returnInfo = [NSMutableDictionary dictionary]; + HentaiSaveLibrary *infoObject = realm; returnInfo[@"hentaiKey"] = infoObject.hentaiKey; + returnInfo[@"group"] = infoObject.group; NSMutableDictionary *hentaiInfoDictionary = [NSMutableDictionary dictionary]; HentaiSaveLibrary_HentaiInfo *hentaiInfoObject = infoObject.hentaiInfo; @@ -103,20 +174,6 @@ + (NSDictionary *)saveInfoAtIndex:(NSUInteger)index { return returnInfo; } -//移除某一個 index 內容 -+ (void)removeSaveInfoAtIndex:(NSUInteger)index { - HentaiSaveLibrary *removeObject = [[HentaiSaveLibrary allObjectsInRealm:[self hentaiSaveLibraryRealm]] objectAtIndex:index]; - - [[self hentaiSaveLibraryRealm] beginWriteTransaction]; - [[self hentaiSaveLibraryRealm] deleteObject:removeObject.hentaiInfo]; - [[self hentaiSaveLibraryRealm] deleteObjects:removeObject.hentaiResult]; - [[self hentaiSaveLibraryRealm] deleteObjects:removeObject.images]; - [[self hentaiSaveLibraryRealm] deleteObject:removeObject]; - [[self hentaiSaveLibraryRealm] commitWriteTransaction]; -} - -#pragma mark - private - //存在特定檔案 + (RLMRealm *)hentaiSaveLibraryRealm { NSString *realmPath = [[FilesManager documentFolder] currentPath]; diff --git a/e-Hentai/e-Hentai-Prefix.pch b/e-Hentai/e-Hentai-Prefix.pch index eadf7001..fa12cdd5 100644 --- a/e-Hentai/e-Hentai-Prefix.pch +++ b/e-Hentai/e-Hentai-Prefix.pch @@ -48,6 +48,7 @@ #import "UIView+Hentai.h" #import "UIImageView+Hentai.h" #import "HentaiSettingManager.h" + #import "GroupManager.h" //因為在 ios8 下, 回的 screenSize 是不固定的, 所以用這個方法來做判斷 #define realScreenHeight MAX([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width)