Refresh interval string localizations

This commit is contained in:
relikd
2019-07-08 22:40:16 +02:00
parent 31e0821080
commit dda219b570
10 changed files with 75 additions and 91 deletions

View File

@@ -87,10 +87,10 @@ NS_INLINE NSTextField* GrayLabel(NSString *text) {
/// Inline button with tag equal to refresh interval. @c 16px height.
- (NSButton*)createInlineButton:(NSNumber*)num callback:(nullable id<RefreshIntervalButtonDelegate>)callback {
NSButton *button = [NSView inlineButton:[NSDate stringForInterval:num.intValue rounded:YES]];
TimeUnitType unit = [NSDate unitForInterval:num.intValue rounded:YES];
button.tag = (NSInteger)(roundf(num.floatValue / unit) * unit); // rounded interval
// TODO: accessibility title: readable interval string
NSButton *button = [NSView inlineButton: [NSDate floatStringForInterval:num.intValue]];
Interval intv = [NSDate floatToIntInterval:num.intValue]; // rounded to highest unit
button.accessibilityTitle = [NSDate intStringForInterval:intv];
button.tag = (NSInteger)intv;
if (callback) {
[button action:@selector(refreshIntervalButtonClicked:) target:callback];
} else {

View File

@@ -29,6 +29,7 @@
#import "OpmlExport.h"
#import "FeedDownload.h"
#import "SettingsFeedsView.h"
#import "NSDate+Ext.h"
@interface SettingsFeeds ()
@property (strong) SettingsFeedsView *view; // override super
@@ -37,7 +38,6 @@
@property (strong) NSUndoManager *undoManager;
@property (strong) NSTimer *timerStatusInfo;
@property (strong) NSDateComponentsFormatter *intervalFormatter;
@end
@implementation SettingsFeeds
@@ -94,9 +94,6 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
/// Initialize status info timer
- (void)viewWillAppear {
[self.dataStore rearrangeObjects]; // needed to scroll outline view to top (if prefs open on another tab)
self.intervalFormatter = [[NSDateComponentsFormatter alloc] init];
self.intervalFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort; // e.g., '30 min'
self.intervalFormatter.maximumUnitCount = 1;
self.timerStatusInfo = [NSTimer timerWithTimeInterval:NSTimeIntervalSince1970 target:self selector:@selector(keepTimerRunning) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timerStatusInfo forMode:NSRunLoopCommonModes];
// start spinner if update is in progress when preferences open
@@ -108,7 +105,6 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
// in viewWillDisappear otherwise dealloc will not be called
[self.timerStatusInfo invalidate];
self.timerStatusInfo = nil;
self.intervalFormatter = nil;
}
/// Callback method to update status info. Will be called more often when interval is getting shorter.
@@ -120,14 +116,11 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
self.view.status.stringValue = @"";
return;
}
if (nextFire > 60) { // update 1/min
nextFire = fmod(nextFire, 60); // next update will align with minute
} else {
nextFire = 1; // update 1/sec
}
NSString *str = [self.intervalFormatter stringFromTimeInterval: date.timeIntervalSinceNow];
self.view.status.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Next update in %@", nil), str];
[self.timerStatusInfo setFireDate:[NSDate dateWithTimeIntervalSinceNow: nextFire]];
self.view.status.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Next update in %@", nil),
[NSDate stringForRemainingTime:date]];
// Next update is aligned with minute (fmod) else update 1/sec
NSDate *nextUpdate = [NSDate dateWithTimeIntervalSinceNow: (nextFire > 60 ? fmod(nextFire, 60) : 1)];
[self.timerStatusInfo setFireDate:nextUpdate];
}
}

View File

@@ -93,7 +93,7 @@
NSTableColumn *colRefresh = [[NSTableColumn alloc] initWithIdentifier:CustomCellRefresh];
colRefresh.title = NSLocalizedString(@"Refresh", nil);
colRefresh.width = 50;
colRefresh.width = 60;
colRefresh.resizingMask = NSTableColumnNoResizing;
[outline addTableColumn:colRefresh];
@@ -224,15 +224,19 @@ NSUserInterfaceItemIdentifier const CustomCellRefresh = @"RefreshColumnCell";
self = [super initWithFrame:frameRect];
self.identifier = CustomCellRefresh;
self.textField = [[[[NSView label:@""] textRight] placeIn:self x:0 yTop:0] sizeToRight:0];
self.textField.accessibilityLabel = NSLocalizedString(@"Refresh interval", nil);
self.textField.accessibilityTitle = @" "; // otherwise groups and separators will say 'text'
return self;
}
- (void)setObjectValue:(FeedGroup*)fg {
NSString *str = [fg refreshString];
NSString *str = @"";
if (fg.type == FEED) {
int32_t refresh = fg.feed.meta.refresh;
str = (refresh <= 0 ? @"∞" : [NSDate intStringForInterval:refresh]); // ƒ Ø
}
self.textField.objectValue = str;
// TODO: accessibility title: readable interval string
self.textField.textColor = (str.length > 1 ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]);
self.textField.accessibilityLabel = (str.length > 1 ? NSLocalizedString(@"Refresh interval", nil) : nil);
}
@end