1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
105
106
107
108
109
110
111
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
157
158
159
160
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UIPushButton.h>
#import <UIKit/UIThreePartButton.h>
#import <UIKit/UINavigationBar.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIView-Hierarchy.h>
#import <UIKit/UIHardware.h>
#import <UIKit/UITable.h>
#import <UIKit/UISectionList.h>
#import <UIKit/UITableCell.h>
#import <UIKit/UITableColumn.h>
#import <UIKit/UITextView.h>
#import <UIKit/UISegmentedControl.h>
#import "HelloApplication.h"


@implementation HelloApplication

- (BOOL)respondsToSelector:(SEL)selector {
  NSLog(@"respondsToSelector: %s", selector);
  return [super respondsToSelector:selector];
}

- (BOOL) table: (UITable *)table showDisclosureForRow: (int)row
{
    return YES;
}

- (int)numberOfSectionsInSectionList:(UISectionList *)aSectionList {
    return 1;
}

- (NSString *)sectionList:(UISectionList *)aSectionList titleForSection:(int)row {
    return @"Hi";
}

- (int)sectionList:(UISectionList *)aSectionList rowForSection:(int)row {
    return 1;
}

- (int) numberOfRowsInTable: (UITable *)table
{
    return [fileArray count];
}

- (UITableCell *) table: (UITable *)table cellForRow: (int)row column: (int)col
{
    return [fileArray objectAtIndex: row]; 
}

- (UITableCell *) table: (UITable *)table cellForRow: (int)row column: (int)col
    reusing: (BOOL) reusing
{
    // return pbCell; 
    return [fileArray objectAtIndex: row]; 
}

- (void) segmentedControl: (UISegmentedControl *)segment selectedSegmentChanged: (int)seg
{
    NSLog(@"Selected segement: %i", seg);
}

- (void) applicationDidFinishLaunching: (id) unused
{
    fileArray = [[NSMutableArray alloc]initWithCapacity:999];
    
    NSString *imagePath = @"/var/root/Media/DCIM/100APPLE/";
    NSArray *myPhotos = [[NSFileManager defaultManager]directoryContentsAtPath: imagePath];
    
    UIWindow *window;

    window = [[UIWindow alloc] initWithContentRect: [UIHardware fullScreenApplicationContentRect]];
   
    struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
    rect.origin.x = rect.origin.y = 0.0f;

    UIView *mainView;
    mainView = [[UIView alloc] initWithFrame: rect];
    
    UITextView *textView = [[UITextView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 330.0f, 480.0f)];

    // UIImage *fun = [[UIImage alloc]initWithContentsOfFile:@"/var/root/Media/DCIM/100APPLE/IMG_0063.JPG"];
    // UIImageView *funView = [[UIImageView alloc] initWithFrame: rect];
    // [funView setImage:fun];
    // [funView setAlpha:1.0];
    
    float segWidth = 200.0f;
    
    UISegmentedControl *modeSwitch = [[UISegmentedControl alloc] initWithFrame:CGRectMake(320.0f / 2.0f - (segWidth / 2.0f), 6.0f, segWidth, 30.0f) withStyle:2 withItems:nil];
    [modeSwitch insertSegment:0 withTitle:@"Mine" animated:NO];
    [modeSwitch insertSegment:1 withTitle:@"Flickr" animated:NO];
    [modeSwitch insertSegment:2 withTitle:@"Popular" animated:NO];
    [modeSwitch selectSegment:0];
    [modeSwitch setDelegate:self];

    UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 43.0f)];

    // UIListView *listView = [[UIListView alloc]initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
    
    NSEnumerator *enumerator = [myPhotos objectEnumerator];
    id anObject;
    NSDictionary *file;

    while (anObject = [enumerator nextObject]) {

        if ([anObject hasSuffix:@".THM"]) {
            NSString *filePath = [NSString localizedStringWithFormat:@"%@%@", imagePath, anObject];

            // file = [[NSFileManager defaultManager] fileAttributesAtPath: filePath traverseLink:NO];
            // 
            // NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
            //  anObject, @"name",
            //  [file objectForKey:@"NSFileModificationDate"], @"date",
            //  nil];
            // NSLog(@"object: %@", dict);

            UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath cache:YES];
            
            imCell = [[UIImageAndTextTableCell alloc] init];
            [imCell setTitle: anObject];
            [imCell setImage: img];
            
            [fileArray addObject:imCell];
        }

    }


    // List view table
    UISectionList *sectionList = [[UISectionList alloc] initWithFrame:CGRectMake(0.0f, 48.0f, 320.0f, 480.0f - 16.0f - 32.0f) showSectionIndex:NO];
    [sectionList setDataSource:self];
    [sectionList reloadData];
    [textView addSubview:sectionList];
    
    UITable *table = [sectionList table];
    // [table setShouldHideHeaderInShortLists:YES];
    UITableColumn * packageColumn = [[UITableColumn alloc] initWithTitle:@"Title" identifier:@"title" width:320.0f];
    
    [table addTableColumn:packageColumn];
    [table setSeparatorStyle:1];
    [table setRowHeight:105.0f];
    [table setDelegate:self];

    [window orderFront: self];
    [window makeKey: self];
    [window _setHidden: NO];
     
    [window setContentView: mainView];
    
    [mainView addSubview: textView];

    // [mainView addSubview: sectionList];
    [mainView addSubview: bar];
    [mainView addSubview: modeSwitch];
    
}

@end