Browse Source

Added Load next functionality.

Thomas Buck 10 years ago
parent
commit
54c9087189

+ 2
- 1
RedditBar/AppDelegate.h View File

35
 
35
 
36
 @property (atomic, retain) IBOutlet NSMenu *statusMenu;
36
 @property (atomic, retain) IBOutlet NSMenu *statusMenu;
37
 @property (atomic, retain) IBOutlet NSApplication *application;
37
 @property (atomic, retain) IBOutlet NSApplication *application;
38
-@property (weak) IBOutlet NSMenuItem *firstMenuItem;
38
+@property (atomic, retain) IBOutlet NSMenuItem *firstMenuItem;
39
 
39
 
40
 @property (atomic, retain) NSStatusItem *statusItem;
40
 @property (atomic, retain) NSStatusItem *statusItem;
41
 @property (atomic, retain) NSImage *statusImage;
41
 @property (atomic, retain) NSImage *statusImage;
45
 @property (atomic, retain) Reddit *api;
45
 @property (atomic, retain) Reddit *api;
46
 @property (atomic, retain) NSArray *menuItems;
46
 @property (atomic, retain) NSArray *menuItems;
47
 @property (atomic, retain) NSArray *redditItems;
47
 @property (atomic, retain) NSArray *redditItems;
48
+@property (atomic, retain) NSString *lastFullName;
48
 
49
 
49
 -(IBAction)showPreferences:(id)sender;
50
 -(IBAction)showPreferences:(id)sender;
50
 -(IBAction)showAbout:(id)sender;
51
 -(IBAction)showAbout:(id)sender;

+ 8
- 4
RedditBar/AppDelegate.m View File

30
 
30
 
31
 @implementation AppDelegate
31
 @implementation AppDelegate
32
 
32
 
33
-@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, prefWindow, currentState, application, api, firstMenuItem, menuItems, redditItems;
33
+@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, prefWindow, currentState, application, api, firstMenuItem, menuItems, redditItems, lastFullName;
34
 
34
 
35
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
35
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
36
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
36
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
42
     [statusItem setMenu:statusMenu];
42
     [statusItem setMenu:statusMenu];
43
     [statusItem setToolTip:NSLocalizedString(@"RedditBar", @"Main Menuitem Tooltip")];
43
     [statusItem setToolTip:NSLocalizedString(@"RedditBar", @"Main Menuitem Tooltip")];
44
     [statusItem setHighlightMode:YES];
44
     [statusItem setHighlightMode:YES];
45
+    lastFullName = nil;
45
     currentState = [[StateModel alloc] init];
46
     currentState = [[StateModel alloc] init];
46
     [self defaultPreferences];
47
     [self defaultPreferences];
47
     [self loadPreferences];
48
     [self loadPreferences];
90
         [firstMenuItem setHidden:NO];
91
         [firstMenuItem setHidden:NO];
91
         return;
92
         return;
92
     }
93
     }
94
+    lastFullName = [items objectAtIndex:[items count] - 1]; // last link fullname is at end of array
95
+    items = [items subarrayWithRange:NSMakeRange(0, [items count] - 1)]; // Remove last item
93
     redditItems = items;
96
     redditItems = items;
94
     [self clearMenuItems];
97
     [self clearMenuItems];
95
     [firstMenuItem setHidden:YES];
98
     [firstMenuItem setHidden:YES];
103
         [firstMenuItem setHidden:NO];
106
         [firstMenuItem setHidden:NO];
104
         return;
107
         return;
105
     }
108
     }
109
+    lastFullName = [items objectAtIndex:[items count] - 1]; // last link fullname is at end of array
110
+    items = [items subarrayWithRange:NSMakeRange(0, [items count] - 1)]; // Remove last item
106
     redditItems = items;
111
     redditItems = items;
107
     [self clearMenuItems];
112
     [self clearMenuItems];
108
     [firstMenuItem setHidden:YES];
113
     [firstMenuItem setHidden:YES];
135
     [firstMenuItem setTitle:NSLocalizedString(@"Loading...", @"Statusitem when user clicks reload")];
140
     [firstMenuItem setTitle:NSLocalizedString(@"Loading...", @"Statusitem when user clicks reload")];
136
     [self clearMenuItems];
141
     [self clearMenuItems];
137
     [firstMenuItem setHidden:NO];
142
     [firstMenuItem setHidden:NO];
143
+    lastFullName = nil; // reload from start
138
     [self reloadListWithOptions];
144
     [self reloadListWithOptions];
139
 }
145
 }
140
 
146
 
142
     [firstMenuItem setTitle:NSLocalizedString(@"Loading...", nil)];
148
     [firstMenuItem setTitle:NSLocalizedString(@"Loading...", nil)];
143
     [self clearMenuItems];
149
     [self clearMenuItems];
144
     [firstMenuItem setHidden:NO];
150
     [firstMenuItem setHidden:NO];
145
-    
146
-    // TODO on list load, store after cookie??
147
-    // then use it here to load the list after the last item
151
+    [self reloadListWithOptions];
148
 }
152
 }
149
 
153
 
150
 -(IBAction)linkToOpen:(id)sender {
154
 -(IBAction)linkToOpen:(id)sender {

+ 21
- 2
RedditBar/Reddit.m View File

127
         RedditItem *r = [RedditItem itemWithName:name Link:link Comments:comments Self:isSelf];
127
         RedditItem *r = [RedditItem itemWithName:name Link:link Comments:comments Self:isSelf];
128
         [r setFullName:[current valueForKey:@"title"]];
128
         [r setFullName:[current valueForKey:@"title"]];
129
         [array insertObject:r atIndex:i];
129
         [array insertObject:r atIndex:i];
130
+        
131
+        if (i == ([children count] - 1)) {
132
+            NSString *name = [NSString stringWithFormat:@"%@_%@", [child valueForKey:@"kind"], [current valueForKey:@"id"]];
133
+            [array insertObject:name atIndex:i + 1];
134
+        }
130
     }
135
     }
131
     return array;
136
     return array;
132
 }
137
 }
133
 
138
 
134
 -(void)readFrontpage:(id)parent {
139
 -(void)readFrontpage:(id)parent {
135
     NSHTTPURLResponse *response;
140
     NSHTTPURLResponse *response;
136
-    NSString *url = [NSString stringWithFormat:@"hot.json?limit=%ld", (long)length];
141
+    
142
+    NSString *after = ((AppDelegate *)parent).lastFullName;
143
+    NSString *url;
144
+    if (after == nil)
145
+        url = [NSString stringWithFormat:@"hot.json?limit=%ld", (long)length];
146
+    else
147
+        url = [NSString stringWithFormat:@"hot.json?limit=%ld&after=%@", (long)length, after];
148
+        
137
     NSData *data = [self queryAPI:url withResponse:&response];
149
     NSData *data = [self queryAPI:url withResponse:&response];
138
     if ((data == nil) || ([response statusCode] != 200)) {
150
     if ((data == nil) || ([response statusCode] != 200)) {
139
         [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:nil waitUntilDone:false];
151
         [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:nil waitUntilDone:false];
150
             [subs appendString:@"+"];
162
             [subs appendString:@"+"];
151
         }
163
         }
152
     }
164
     }
153
-    NSString *url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld", subs, (long)length];
165
+    
166
+    NSString *after = ((AppDelegate *)parent).lastFullName;
167
+    NSString *url;
168
+    if (after == nil)
169
+        url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld", subs, (long)length];
170
+    else
171
+        url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld&after=%@", subs, (long)length, after];
172
+    
154
     NSHTTPURLResponse *response;
173
     NSHTTPURLResponse *response;
155
     NSData *data = [self queryAPI:url withResponse:&response];
174
     NSData *data = [self queryAPI:url withResponse:&response];
156
     if ((data == nil) || ([response statusCode] != 200)) {
175
     if ((data == nil) || ([response statusCode] != 200)) {

+ 1
- 1
RedditBar/RedditBar-Info.plist View File

21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>169</string>
24
+	<string>174</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

+ 1
- 1
RedditBar/de.lproj/MainMenu.strings View File

5
 "4ah-qP-9eP.title" = "About RedditBar";
5
 "4ah-qP-9eP.title" = "About RedditBar";
6
 
6
 
7
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
7
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
8
-"bQG-wq-9Zw.title" = "Aktualisieren";
8
+"bQG-wq-9Zw.title" = "Neu laden";
9
 
9
 
10
 /* Class = "NSMenuItem"; title = "Load next"; ObjectID = "e8u-nc-P6x"; */
10
 /* Class = "NSMenuItem"; title = "Load next"; ObjectID = "e8u-nc-P6x"; */
11
 "e8u-nc-P6x.title" = "Mehr laden";
11
 "e8u-nc-P6x.title" = "Mehr laden";

Loading…
Cancel
Save