iOS: #1203 (show story changes)

When there are changes, the “Show Changes” button appears before the date, like on the web. Tapping loads and displays the changes, and the button changes to “Hide Changes”, which works without loading. The insertion and deletion highlights support style-appropriate colors.
This commit is contained in:
David Sinclair 2019-06-19 20:45:30 -07:00
parent bb30c5cba6
commit 7d2b1dd5d2
5 changed files with 149 additions and 2 deletions

View file

@ -446,6 +446,10 @@
if (self.inTextView && [self.activeStory objectForKey:@"original_text"]) {
storyContent = [self.activeStory objectForKey:@"original_text"];
}
NSString *changes = self.activeStory[@"story_changes"];
if (changes != nil) {
storyContent = changes;
}
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
@ -791,6 +795,9 @@
}
}
NSString *storyToggleChanges = [self.activeStory[@"has_modifications"] boolValue] ? [NSString stringWithFormat:@"<a href=\"http://ios.newsblur.com/togglechanges\" "
"class=\"NB-story-toggle-changes\" id=\"NB-story-toggle-changes\">%@</a><span class=\"NB-middot\">&middot;</span>", self.activeStory[@"story_changes"] != nil ? @"Hide Changes" : @"Show Changes"] : @"";
NSString *storyDate = [Utilities formatLongDateFromTimestamp:[[self.activeStory
objectForKey:@"story_timestamp"]
integerValue]];
@ -800,6 +807,7 @@
" %@"
" <a href=\"%@\" class=\"NB-story-permalink\">%@</a>"
"</div>"
"%@"
"<div class=\"NB-story-date\">%@</div>"
"%@"
"%@"
@ -809,6 +817,7 @@
storyUnread,
storyPermalink,
storyTitle,
storyToggleChanges,
storyDate,
storyAuthor,
storyTags,
@ -1625,7 +1634,15 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
} else if ([action isEqualToString:@"unlike-comment"]) {
[self toggleLikeComment:NO];
}
return NO;
return NO;
} else if ([action isEqualToString:@"togglechanges"]) {
if (self.activeStory[@"story_changes"] != nil) {
[self.activeStory removeObjectForKey:@"story_changes"];
[self drawStory];
} else {
[self fetchStoryChanges];
}
return NO;
} else if ([action isEqualToString:@"share"]) {
[self openShareDialog];
return NO;
@ -2532,5 +2549,69 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
// NSLog(@"Fetched Text: %@", [self.activeStory objectForKey:@"story_title"]);
}
- (void)fetchStoryChanges {
if (!self.activeStoryId || !self.activeStory) return;
self.inTextView = YES;
// NSLog(@"Fetching Changes: %@", [self.activeStory objectForKey:@"story_title"]);
if (self.activeStory == appDelegate.storyPageControl.currentPage.activeStory) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.appDelegate.storyPageControl showFetchingTextNotifier];
});
}
NSString *urlString = [NSString stringWithFormat:@"%@/rss_feeds/story_changes",
self.appDelegate.url];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:[self.activeStory objectForKey:@"story_hash"] forKey:@"story_hash"];
[params setObject:@"true" forKey:@"show_changes"];
NSString *storyId = [self.activeStory objectForKey:@"id"];
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[self finishFetchStoryChanges:responseObject storyId:storyId];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self failedFetchStoryChanges:error];
}];
}
- (void)failedFetchStoryChanges:(NSError *)error {
[self.appDelegate.storyPageControl hideNotifier];
[MBProgressHUD hideHUDForView:self.webView animated:YES];
if (self.activeStory == appDelegate.storyPageControl.currentPage.activeStory) {
[self informError:@"Could not fetch changes"];
}
self.inTextView = NO;
[appDelegate.storyPageControl setTextButton:self];
}
- (void)finishFetchStoryChanges:(NSDictionary *)results storyId:(NSString *)storyId {
if ([results[@"failed"] boolValue]) {
[self failedFetchText:nil];
return;
}
if (![storyId isEqualToString:self.activeStory[@"id"]]) {
[self.appDelegate.storyPageControl hideNotifier];
[MBProgressHUD hideHUDForView:self.webView animated:YES];
self.inTextView = NO;
[appDelegate.storyPageControl setTextButton:self];
return;
}
NSMutableDictionary *newActiveStory = [self.activeStory mutableCopy];
NSDictionary *resultsStory = results[@"story"];
newActiveStory[@"story_changes"] = resultsStory[@"story_content"];
if ([self.activeStory[@"story_hash"] isEqualToString:appDelegate.activeStory[@"story_hash"]]) {
appDelegate.activeStory = newActiveStory;
}
self.activeStory = newActiveStory;
[self.appDelegate.storyPageControl hideNotifier];
[MBProgressHUD hideHUDForView:self.webView animated:YES];
self.inTextView = YES;
[self drawStory];
// NSLog(@"Fetched Changes: %@", self.activeStory[@"story_title"]);
}
@end

View file

@ -280,6 +280,13 @@ body.NB-iphone {
.NB-story-permalink {
color: #313350;
}
.NB-story-toggle-changes {
display: inline;
color: #818776;
font-size: .8em;
white-space: nowrap;
}
.NB-story-date {
display: inline;
color: #818776;
@ -657,11 +664,22 @@ div + p {
}
ins {
background-color: #BEE8BC;
text-decoration: none;
}
del {
display: none;
background-color: #f5c3c3
/*display: none;*/
}
.NB-story ins {
background-color: #BEE8BC;
text-decoration: none
}
.NB-story del {
background-color: #f5c3c3
}
/* Comments */

View file

@ -39,6 +39,9 @@ body {
.NB-story-permalink {
color: lightgray;
}
.NB-story-toggle-changes {
color: #818776;
}
.NB-story-date {
color: #818776;
}
@ -115,6 +118,25 @@ a:active {
background-color: #2f2f2f;
}
ins {
background-color: #475D49;
text-decoration: none;
}
del {
background-color: #685253
/*display: none;*/
}
.NB-story ins {
background-color: #475D49;
text-decoration: none
}
.NB-story del {
background-color: #685253
}
/* Comments */
.NB-story-comments-group:last-child {

View file

@ -40,6 +40,10 @@ body {
.NB-story-permalink {
color: lightgray;
}
.NB-story-toggle-changes {
color: #c6c6c6;
text-shadow: 0 1px 0 rgba(28, 28, 28, .1);
}
.NB-story-date {
color: #c6c6c6;
text-shadow: 0 1px 0 rgba(28, 28, 28, .1);
@ -117,6 +121,25 @@ a:active {
background-color: #6c696a;
}
ins {
background-color: #475D49;
text-decoration: none;
}
del {
background-color: #685253
/*display: none;*/
}
.NB-story ins {
background-color: #475D49;
text-decoration: none
}
.NB-story del {
background-color: #685253
}
/* Comments */
.NB-story-comments-group:last-child {

View file

@ -38,6 +38,9 @@ body {
.NB-story-permalink {
color: #111111;
}
.NB-story-toggle-changes {
color: #818776;
}
.NB-story-date {
color: #818776;
}