Skip to content

Commit

Permalink
[FIX] initial view size in Today Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrey committed Jun 12, 2019
1 parent 4abe638 commit 35fd7de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
7 changes: 3 additions & 4 deletions OwnTracks/OwnTracksToday/Base.lproj/MainInterface.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<device id="retina3_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -107,7 +107,6 @@
<constraint firstItem="6cp-b0-7ip" firstAttribute="top" secondItem="S3S-Oj-5AN" secondAttribute="top" id="NQ6-5m-TWw"/>
<constraint firstItem="B1p-y7-Qo8" firstAttribute="leading" secondItem="wOM-J5-pkE" secondAttribute="trailing" constant="8" symbolic="YES" id="NjC-ay-qvY"/>
<constraint firstItem="wOM-J5-pkE" firstAttribute="top" secondItem="Ft6-oW-KC0" secondAttribute="bottom" id="Zg9-6W-RKH"/>
<constraint firstAttribute="trailing" secondItem="6cp-b0-7ip" secondAttribute="trailing" constant="20" symbolic="YES" id="eRp-01-jke"/>
<constraint firstAttribute="trailing" secondItem="6cp-b0-7ip" secondAttribute="trailing" id="gCX-Ib-WUO"/>
<constraint firstItem="Hk7-3Z-JeF" firstAttribute="top" secondItem="Ft6-oW-KC0" secondAttribute="bottom" constant="22" id="jKi-iS-6HA"/>
<constraint firstItem="Hk7-3Z-JeF" firstAttribute="leading" secondItem="S3S-Oj-5AN" secondAttribute="leading" id="lSX-XI-lid"/>
Expand All @@ -133,7 +132,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="516" y="285"/>
<point key="canvasLocation" x="747.82608695652175" y="190.84821428571428"/>
</scene>
</scenes>
<resources>
Expand Down
4 changes: 2 additions & 2 deletions OwnTracks/OwnTracksToday/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>12.0.4</string>
<string>12.0.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>12.0.4</string>
<string>12.0.5</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
Expand Down
22 changes: 14 additions & 8 deletions OwnTracks/OwnTracksToday/TodayViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ @interface TodayViewController () <NCWidgetProviding>
@property (nonatomic) NSInteger monitoring;
@property (nonatomic) unsigned long offset;
@property (nonatomic) unsigned long page;
@property (nonatomic) CGSize maxSize;
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UIButton *backward;
@property (weak, nonatomic) IBOutlet UIButton *forward;
Expand Down Expand Up @@ -47,14 +48,13 @@ - (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode
maxSize.width,
maxSize.height);

self.offset = 0;
self.page = MAX(MIN((long)((maxSize.height - TOP) / ROW), self.sharedFriends.count - self.offset), 2);
self.maxSize = maxSize;

if (activeDisplayMode == NCWidgetDisplayModeExpanded) {
self.preferredContentSize = CGSizeMake(maxSize.width, self.page * ROW + TOP);
} else if (activeDisplayMode == NCWidgetDisplayModeCompact) {
self.preferredContentSize = CGSizeMake(maxSize.width, self.page * ROW + TOP);;
}
self.offset = 0;
self.page = MAX(MIN((long)((maxSize.height - TOP) / ROW),
self.sharedFriends.count),
2);
self.preferredContentSize = CGSizeMake(maxSize.width, self.page * ROW + TOP);
[self.view setNeedsLayout];
[self.view setNeedsDisplay];
}
Expand All @@ -67,10 +67,16 @@ - (void)viewDidLayoutSubviews {
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.org.owntracks.Owntracks"];
self.sharedFriends = [shared dictionaryForKey:@"sharedFriends"];
NSLog(@"sharedFriends: %@", self.sharedFriends);
NSLog(@"sharedFriends: %ld", self.sharedFriends.count);
self.monitoring = [shared integerForKey:@"monitoring"];
NSLog(@"monitoring: %ld", (long)self.monitoring);
self.offset = 0;
self.page = MAX(MIN((long)((self.maxSize.height - TOP) / ROW),
self.sharedFriends.count),
2);
self.preferredContentSize = CGSizeMake(self.maxSize.width, self.page * ROW + TOP);
[self.view setNeedsLayout];
[self.view setNeedsDisplay];
[self show];
[self.tableView reloadData];

Expand Down

0 comments on commit 35fd7de

Please sign in to comment.