Просмотр исходного кода

Added Load next functionality.

Thomas Buck 11 лет назад
Родитель
Сommit
54c9087189

+ 2
- 1
RedditBar/AppDelegate.h Просмотреть файл

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

+ 8
- 4
RedditBar/AppDelegate.m Просмотреть файл

@@ -30,7 +30,7 @@
30 30
 
31 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 35
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
36 36
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
@@ -42,6 +42,7 @@
42 42
     [statusItem setMenu:statusMenu];
43 43
     [statusItem setToolTip:NSLocalizedString(@"RedditBar", @"Main Menuitem Tooltip")];
44 44
     [statusItem setHighlightMode:YES];
45
+    lastFullName = nil;
45 46
     currentState = [[StateModel alloc] init];
46 47
     [self defaultPreferences];
47 48
     [self loadPreferences];
@@ -90,6 +91,8 @@
90 91
         [firstMenuItem setHidden:NO];
91 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 96
     redditItems = items;
94 97
     [self clearMenuItems];
95 98
     [firstMenuItem setHidden:YES];
@@ -103,6 +106,8 @@
103 106
         [firstMenuItem setHidden:NO];
104 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 111
     redditItems = items;
107 112
     [self clearMenuItems];
108 113
     [firstMenuItem setHidden:YES];
@@ -135,6 +140,7 @@
135 140
     [firstMenuItem setTitle:NSLocalizedString(@"Loading...", @"Statusitem when user clicks reload")];
136 141
     [self clearMenuItems];
137 142
     [firstMenuItem setHidden:NO];
143
+    lastFullName = nil; // reload from start
138 144
     [self reloadListWithOptions];
139 145
 }
140 146
 
@@ -142,9 +148,7 @@
142 148
     [firstMenuItem setTitle:NSLocalizedString(@"Loading...", nil)];
143 149
     [self clearMenuItems];
144 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 154
 -(IBAction)linkToOpen:(id)sender {

+ 21
- 2
RedditBar/Reddit.m Просмотреть файл

@@ -127,13 +127,25 @@ NSString *replaceTextForTitle = @"...";
127 127
         RedditItem *r = [RedditItem itemWithName:name Link:link Comments:comments Self:isSelf];
128 128
         [r setFullName:[current valueForKey:@"title"]];
129 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 136
     return array;
132 137
 }
133 138
 
134 139
 -(void)readFrontpage:(id)parent {
135 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 149
     NSData *data = [self queryAPI:url withResponse:&response];
138 150
     if ((data == nil) || ([response statusCode] != 200)) {
139 151
         [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:nil waitUntilDone:false];
@@ -150,7 +162,14 @@ NSString *replaceTextForTitle = @"...";
150 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 173
     NSHTTPURLResponse *response;
155 174
     NSData *data = [self queryAPI:url withResponse:&response];
156 175
     if ((data == nil) || ([response statusCode] != 200)) {

+ 1
- 1
RedditBar/RedditBar-Info.plist Просмотреть файл

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

+ 1
- 1
RedditBar/de.lproj/MainMenu.strings Просмотреть файл

@@ -5,7 +5,7 @@
5 5
 "4ah-qP-9eP.title" = "About RedditBar";
6 6
 
7 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 10
 /* Class = "NSMenuItem"; title = "Load next"; ObjectID = "e8u-nc-P6x"; */
11 11
 "e8u-nc-P6x.title" = "Mehr laden";

Загрузка…
Отмена
Сохранить