public
Description:
Homepage:
Clone URL: git://github.com/Squeegy/latest-chatty.git
* Fade the last 10 posts in a thread so it's easy to see the most recent replies

* Fixed a bug that would return you to the wrong spot in the thread after coming 
back from the web view
Squeegy (author)
Fri Aug 15 00:14:05 -0700 2008
commit  0743216a0856ee7ace8560ffb036322effd8ee57
tree    bf04b8e87c9fd1f4dc959db75278582c0b1f7fda
parent  f851468cdf28b00f7a56c6ffc4682bc9d5cfca19
...
31
32
33
 
 
 
 
34
35
36
37
38
39
...
68
69
70
71
72
73
74
75
 
 
 
 
 
 
 
 
76
77
 
 
78
79
80
81
82
 
 
 
 
 
83
84
 
 
85
86
87
...
31
32
33
34
35
36
37
38
39
 
40
41
42
...
71
72
73
 
74
75
76
 
77
78
79
80
81
82
83
84
85
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
0
@@ -31,9 +31,12 @@
0
   return self;
0
 }
0
 
0
+- (void)viewDidLoad {
0
+  [self showCurrentThread];
0
+}
0
+
0
 - (void)viewWillAppear:(BOOL)animated {
0
   [super viewWillAppear:animated];
0
-  [self showCurrentThread];
0
 }
0
 
0
 
0
@@ -68,20 +71,34 @@
0
 
0
 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
0
   UITableViewCell *cell = [[UITableViewCell alloc] init];
0
-  cell.textColor = [UIColor colorWithWhite:0.7 alpha:1.0];
0
   
0
   Post *post = [currentRoot postAtIndex:indexPath.row];
0
   
0
-  cell.text = [post preview];
0
+  // Most recent 10 posts are whiter than the rest
0
+  float alpha = 0.6;
0
+  if (post.recentIndex < 10) {
0
+    alpha = alpha + ((1.0 - alpha) / 10) * (float)(10 - (post.recentIndex));
0
+  }
0
+  cell.textColor = [UIColor colorWithWhite:1.0 alpha:alpha];
0
+  
0
+  NSLog(@"alpha:%f  index:%d", alpha, post.recentIndex);
0
   
0
-  if (indexPath.row == 0) {
0
+  // the latest post is bold
0
+  if (post.recentIndex == 0) {
0
     cell.font = [UIFont boldSystemFontOfSize:14.0];
0
   } else {
0
     cell.font = [UIFont systemFontOfSize:14.0];
0
   }
0
   
0
+  
0
+  
0
+  // Set preview text
0
+  cell.text = [post preview];
0
+  
0
   return cell;
0
 }
0
+
0
+
0
 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
0
   currentPostIndex = indexPath.row;
0
   [self showPost:[currentRoot postAtIndex:currentPostIndex]];
...
24
25
26
 
27
28
29
...
36
37
38
 
 
39
40
41
...
47
48
49
 
50
51
...
24
25
26
27
28
29
30
...
37
38
39
40
41
42
43
44
...
50
51
52
53
54
55
0
@@ -24,6 +24,7 @@
0
   NSMutableArray *children;
0
   int depth;
0
   int cachedReplyCount;
0
+  int recentIndex;
0
 }
0
 
0
 - (id)initWithXmlElement:(CXMLElement *)xml parent:(Post *)aParent;
0
@@ -36,6 +37,8 @@
0
 - (Post *)postAtIndex:(int)index;
0
 - (NSString *)cleanString:(NSString *)string;
0
 
0
+- (int)compare:(Post *)otherPost;
0
+
0
 @property (readwrite, retain) Post *parent;
0
 @property (readwrite, copy) NSString *author;
0
 @property (readwrite, copy) NSString *preview;
0
@@ -47,5 +50,6 @@
0
 @property (readwrite, assign) int depth;
0
 @property (readwrite, assign) int cachedReplyCount;
0
 @property (readonly) NSString *formattedDate;
0
+@property (readwrite) int recentIndex;
0
 
0
 @end
...
21
22
23
 
24
25
26
...
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
...
165
166
167
 
 
 
 
 
 
 
 
168
...
21
22
23
24
25
26
27
...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
183
184
185
186
187
188
189
190
191
192
193
194
0
@@ -21,6 +21,7 @@
0
 @synthesize children;
0
 @synthesize depth;
0
 @synthesize cachedReplyCount;
0
+@synthesize recentIndex;
0
 
0
 - (id)init {
0
   [super init];
0
@@ -65,6 +66,23 @@
0
       [children addObject:postObject];
0
   }
0
   
0
+  // get the recent sort index
0
+  if (parent == nil) {
0
+    int i;
0
+    NSMutableArray *sortedByRecent = [[NSMutableArray alloc] initWithObjects:self, nil];
0
+    
0
+    for (i = 0; i <= cachedReplyCount; i++) {
0
+      [sortedByRecent addObject:[self postAtIndex:i]];
0
+    }
0
+    [sortedByRecent sortUsingSelector:@selector(compare:)];
0
+    
0
+    for (i = 0; i <= cachedReplyCount; i++) {
0
+      [[sortedByRecent objectAtIndex:i] setRecentIndex:i];
0
+    }
0
+    
0
+    [sortedByRecent release];
0
+  }
0
+  
0
   // Filter post
0
   if ([self.category isEqualToString:@"ontopic"]) {
0
     return YES;
0
@@ -165,4 +183,12 @@
0
   return [date descriptionWithCalendarFormat:@"%b %d, %Y %I:%M %p" timeZone:nil locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
0
 }
0
 
0
+- (int)compare:(Post *)otherPost {
0
+  if (postId < otherPost.postId) {
0
+    return NSOrderedDescending;
0
+  } else {
0
+    return NSOrderedAscending;
0
+  }
0
+}
0
+
0
 @end
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
177
178
179
 
180
181
182
...
112
113
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
116
117
...
138
139
140
141
142
143
144
0
@@ -112,45 +112,6 @@
0
   [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
0
 }
0
 
0
-/*
0
- Override if you support editing the list
0
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
0
-    
0
-  if (editingStyle == UITableViewCellEditingStyleDelete) {
0
-    // Delete the row from the data source
0
-    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
0
-  }  
0
-  if (editingStyle == UITableViewCellEditingStyleInsert) {
0
-    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
0
-  }  
0
-}
0
-*/
0
-
0
-
0
-/*
0
- Override if you support conditional editing of the list
0
-- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
0
-  // Return NO if you do not want the specified item to be editable.
0
-  return YES;
0
-}
0
-*/
0
-
0
-
0
-/*
0
- Override if you support rearranging the list
0
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
0
-}
0
-*/
0
-
0
-
0
-/*
0
- Override if you support conditional rearranging of the list
0
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
0
-  // Return NO if you do not want the item to be re-orderable.
0
-  return YES;
0
-}
0
- */ 
0
-
0
 
0
 - (void)viewWillAppear:(BOOL)animated {
0
   [super viewWillAppear:animated];
0
@@ -177,6 +138,7 @@
0
 - (void)didReceiveMemoryWarning {
0
   [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
0
   // Release anything that's not essential, such as cached data
0
+  NSLog(@"Received memory warning");
0
 }
0
 
0
 

Comments