Skip to content

Commit

Permalink
1.2 - Show loading HUD when user saves entry
Browse files Browse the repository at this point in the history
in advanced edit
  • Loading branch information
香風智乃 authored and 香風智乃 committed Feb 15, 2019
1 parent 0b86196 commit ba1513e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Shukofukurou-IOS/View Controllers/AdvEditTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "TitleInfoTableViewCell.h"
#import "listservice.h"
#import "ThemeManager.h"
#import "MBProgressHUD.h"
#import "Utility.h"

@interface AdvEditTableViewController ()
Expand All @@ -29,6 +30,7 @@ @interface AdvEditTableViewController ()
@property (weak, nonatomic) IBOutlet UINavigationItem *navitem;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *savebtn;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *cancelbtn;
@property (strong) MBProgressHUD *hud;
@end

@implementation AdvEditTableViewController
Expand Down Expand Up @@ -616,6 +618,7 @@ - (void)updateAnime {
__weak AdvEditTableViewController *weakSelf = self;
_savebtn.enabled = NO;
_cancelbtn.enabled = NO;
[self showloadingview:YES];
[listservice updateAnimeTitleOnList:selectededitid withEpisode:((NSNumber *)entry[@"episode"]).intValue withStatus:entry[@"status"] withScore:((NSNumber *)entry[@"score"]).intValue withExtraFields:extraparameters completion:^(id responseobject) {
NSMutableDictionary *updatedfields = [[NSMutableDictionary alloc] initWithDictionary:@{@"watched_episodes" : entry[@"episode"], @"watched_status" : entry[@"status"], @"score" : entry[@"score"], @"last_updated" : [Utility getLastUpdatedDateWithResponseObject:responseobject withService:[listservice getCurrentServiceID]]}];
[updatedfields addEntriesFromDictionary:[self generateExtraFieldsUpdateEntryWithType:0 withUpdateDictionary:entry]];
Expand All @@ -633,6 +636,7 @@ - (void)updateAnime {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.savebtn.enabled = YES;
weakSelf.cancelbtn.enabled = YES;
[self showloadingview:NO];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
});
}
Expand All @@ -641,6 +645,7 @@ - (void)updateAnime {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.savebtn.enabled = YES;
weakSelf.cancelbtn.enabled = YES;
[self showloadingview:NO];
});
}];
}
Expand All @@ -665,6 +670,7 @@ - (void)updateManga {
__weak AdvEditTableViewController *weakSelf = self;
_savebtn.enabled = NO;
_cancelbtn.enabled = NO;
[self showloadingview:YES];
[listservice updateMangaTitleOnList:selectededitid withChapter:((NSNumber *)entry[@"chapter"]).intValue withVolume:((NSNumber *)entry[@"volume"]).intValue withStatus:entry[@"status"] withScore:((NSNumber *)entry[@"score"]).intValue withExtraFields:extraparameters completion:^(id responseobject) {
NSMutableDictionary *updatedfields = [[NSMutableDictionary alloc] initWithDictionary:@{@"chapters_read" : entry[@"chapter"], @"volumes_read" : entry[@"volume"], @"read_status" : entry[@"status"], @"score" : entry[@"score"], @"last_updated" : [Utility getLastUpdatedDateWithResponseObject:responseobject withService:[listservice getCurrentServiceID]]}];
[updatedfields addEntriesFromDictionary:[self generateExtraFieldsUpdateEntryWithType:0 withUpdateDictionary:entry]];
Expand All @@ -682,13 +688,15 @@ - (void)updateManga {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.savebtn.enabled = YES;
weakSelf.cancelbtn.enabled = YES;
[self showloadingview:NO];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
});
}error:^(NSError * error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"%@", error.localizedDescription);
weakSelf.savebtn.enabled = YES;
weakSelf.cancelbtn.enabled = YES;
[self showloadingview:NO];
});
}];
}
Expand All @@ -698,4 +706,16 @@ - (IBAction)canceledit:(id)sender {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark HUD
- (void)showloadingview:(bool)show {
if (show) {
_hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
_hud.label.text = @"Saving...";
_hud.bezelView.blurEffectStyle = [NSUserDefaults.standardUserDefaults boolForKey:@"darkmode"] ? UIBlurEffectStyleDark : UIBlurEffectStyleLight;
_hud.contentColor = [ThemeManager sharedCurrentTheme].textColor;
}
else if (!show) {
[_hud hideAnimated:YES];
}
}
@end

0 comments on commit ba1513e

Please sign in to comment.