Skip to content

Commit

Permalink
Searching
Browse files Browse the repository at this point in the history
  • Loading branch information
hackfrag committed Jul 4, 2013
1 parent f29a7a6 commit b274f9e
Show file tree
Hide file tree
Showing 18 changed files with 548 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -7,3 +7,6 @@
[submodule "Lodestone/libs/SDWebImage"]
path = Lodestone/libs/SDWebImage
url = https://github.com/rs/SDWebImage.git
[submodule "Lodestone/libs/JASidePanels"]
path = Lodestone/libs/JASidePanels
url = https://github.com/gotosleep/JASidePanels.git
78 changes: 71 additions & 7 deletions Lodestone.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Lodestone/Base.lproj/Main_iPad.storyboard
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4451" systemVersion="13A461" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4457.6" systemVersion="12D78" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3676"/>
<development version="5000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3682.6"/>
</dependencies>
<scenes>
<!--class Prefix:identifier View Controller-->
<!--Detail View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="DetailViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="20" width="768" height="1004"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
Expand Down
177 changes: 170 additions & 7 deletions Lodestone/Base.lproj/Main_iPhone.storyboard

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Lodestone/CharacterCell.h
@@ -0,0 +1,17 @@
//
// CharacterCell.h
// Lodestone
//
// Created by Florian Strauss on 04.07.13.
// Copyright (c) 2013 Orlyapps Janzen & Strauß GbR. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CharacterCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *serverLabel;
@property (weak, nonatomic) IBOutlet UIImageView *thumbnailImage;

@end
15 changes: 15 additions & 0 deletions Lodestone/CharacterCell.m
@@ -0,0 +1,15 @@
//
// CharacterCell.m
// Lodestone
//
// Created by Florian Strauss on 04.07.13.
// Copyright (c) 2013 Orlyapps Janzen & Strauß GbR. All rights reserved.
//

#import "CharacterCell.h"

@implementation CharacterCell



@end
Expand Up @@ -9,9 +9,9 @@
#import <UIKit/UIKit.h>
#import "FFLodestone.h"

@interface ViewController : UIViewController
@interface DetailViewController : UIViewController

@property (weak, nonatomic) FFCharacter *character;
@property (strong, nonatomic) FFCharacter *character;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *serverLabel;
@property (weak, nonatomic) IBOutlet UIImageView *thumbnailImage;
Expand Down
20 changes: 14 additions & 6 deletions Lodestone/ViewController.m → Lodestone/DetailViewController.m
Expand Up @@ -6,31 +6,39 @@
// Copyright (c) 2013 Orlyapps Janzen & Strauß GbR. All rights reserved.
//

#import "ViewController.h"
#import "DetailViewController.h"


@interface ViewController ()
@interface DetailViewController ()

@end

@implementation ViewController
@implementation DetailViewController

- (void)viewDidLoad
{
[super viewDidLoad];



}
- (void)setCharacter:(FFCharacter *)character {


[self loading:YES];
[[FFLodestone sharedInstance] fetchCharacterWithId:@"1674571" completionHandler:^(FFCharacter *character, NSError *error) {
[[FFLodestone sharedInstance] fetchCharacterWithId:character.identifier completionHandler:^(FFCharacter *character, NSError *error) {

if(error != nil) {
[self displayError:error];
return;
}

[self loading:NO];
self.character = character;
_character = character;
[self setupContent];
}];

}

- (void)setupContent {
self.title = self.character.name;
self.nameLabel.text = self.character.name;
Expand Down
4 changes: 2 additions & 2 deletions Lodestone/FFCharacter.h
Expand Up @@ -14,20 +14,20 @@

@interface FFCharacter : NSObject

@property (nonatomic, strong) NSString *identifier;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *server;
@property (nonatomic, strong) NSString *mainLVL;
@property (nonatomic, strong) NSString *region;
@property (nonatomic, strong) NSString *race;
@property (nonatomic, strong) NSString *nameday;
@property (nonatomic, strong) NSString *guardian;
@property (nonatomic, strong) NSString *cityState;
@property (nonatomic, strong) NSString *grandCompany; // TODO
@property (nonatomic, strong) NSString *gcRank; // TODO
@property (nonatomic, strong) NSString *freeCompany; // TODO

@property (nonatomic, strong) NSURL *picture;
@property (nonatomic, strong) NSURL *thumbnail;

@property (nonatomic, strong) NSDictionary *stats;
@property (nonatomic, strong) NSDictionary *attributes;
@property (nonatomic, strong) NSDictionary *elements;
Expand Down
4 changes: 4 additions & 0 deletions Lodestone/FFCharacter.m
Expand Up @@ -132,5 +132,9 @@ + (id)characterWithData:(NSData *)data {
return character;
}

- (NSString *)description {
return [NSString stringWithFormat:@"%@ - %@", self.name, self.server];
}


@end
7 changes: 6 additions & 1 deletion Lodestone/FFLodestone.h
Expand Up @@ -14,13 +14,18 @@
#define kFFLodestoneUserAgent @"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36"

typedef void(^FFLodestoneCharacterHandler)(FFCharacter *character, NSError *error);
typedef void(^FFLodestoneCharacterSearchHandler)(NSArray *characters, NSError *error);

@interface FFLodestone : NSObject

@property (nonatomic, strong) NSString *region;

+ (FFLodestone *)sharedInstance;

- (void)fetchCharacterWithId:(NSString *)characterID completionHandler:(FFLodestoneCharacterHandler)handler;
- (AFHTTPRequestOperation *)fetchCharacterWithId:(NSString *)characterID
completionHandler:(FFLodestoneCharacterHandler)handler;

- (AFHTTPRequestOperation *)searchCharacterWithName:(NSString *)name worldName:(NSString *)world
classjob:(NSString *)classjob completionHandler:(FFLodestoneCharacterSearchHandler)handler;

@end
63 changes: 62 additions & 1 deletion Lodestone/FFLodestone.m
Expand Up @@ -8,6 +8,7 @@

#import "FFLodestone.h"
#import "FFCharacter.h"
#import "TFHpple.h"


@interface FFLodestone()
Expand Down Expand Up @@ -47,7 +48,7 @@ - (id)init
return self;
}

- (void)fetchCharacterWithId:(NSString *)characterID completionHandler:(FFLodestoneCharacterHandler)handler {
- (AFHTTPRequestOperation *)fetchCharacterWithId:(NSString *)characterID completionHandler:(FFLodestoneCharacterHandler)handler {


NSURLRequest *request = [self.client requestWithMethod:@"GET"
Expand All @@ -66,6 +67,66 @@ - (void)fetchCharacterWithId:(NSString *)characterID completionHandler:(FFLodest
}];
[operation start];

return operation;
}

- (AFHTTPRequestOperation *)searchCharacterWithName:(NSString *)name worldName:(NSString *)world
classjob:(NSString *)classjob completionHandler:(FFLodestoneCharacterSearchHandler)handler {

if(world == nil) world = @"";
if(classjob == nil) classjob = @"";

NSURLRequest *request = [self.client requestWithMethod:@"GET"
path:[NSString stringWithFormat:@"%@",kFFLodestoneCharacterURLPath, nil]
parameters:@{@"q": name, @"worldname" : world, @"classjob": classjob}];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

NSData *data = (NSData *)responseObject;


NSMutableArray *result = [NSMutableArray array];

TFHpple *page = [TFHpple hppleWithHTMLData:data];

NSArray *characters = [page searchWithXPathQuery:@"//div[@class='table_black_border_bottom']//tr"];

for (TFHppleElement *characterElement in characters) {

NSData *characterData = [characterElement.raw dataUsingEncoding:NSUTF8StringEncoding];
TFHpple *characterRow = [TFHpple hppleWithHTMLData:characterData];

TFHppleElement *nameElement = [[characterRow searchWithXPathQuery:@"//a"] objectAtIndex:0];

TFHppleElement *serverElement = [[characterRow searchWithXPathQuery:@"//h4/span"] objectAtIndex:0];
NSCharacterSet *delimiters = [NSCharacterSet characterSetWithCharactersInString:@"()"];
NSArray *serverStringArray = [[serverElement text] componentsSeparatedByCharactersInSet:delimiters];

TFHppleElement *thumbnailElement = [[characterRow searchWithXPathQuery:@"//div[@class='thumb_cont_black_50']/img"] objectAtIndex:0];

TFHppleElement *regionElement = [[characterRow searchWithXPathQuery:@"//div[@class='player_name_area']/span"] objectAtIndex:0];

FFCharacter *character = [FFCharacter new];
character.name = nameElement.text;
character.server = [serverStringArray objectAtIndex:1];
character.thumbnail = [NSURL URLWithString:[thumbnailElement objectForKey:@"src"]];
character.region = regionElement.text;
character.identifier = [[nameElement objectForKey:@"href"] stringByReplacingOccurrencesOfString:kFFLodestoneCharacterURLPath withString:@""];
character.identifier = [character.identifier stringByReplacingOccurrencesOfString:@"/" withString:@""];
[result addObject:character];
}

handler(result, nil);



} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
handler(nil, error);
}];
[operation start];

return operation;
}

@end
15 changes: 15 additions & 0 deletions Lodestone/SearchViewController.h
@@ -0,0 +1,15 @@
//
// SearchViewController.h
// Lodestone
//
// Created by Florian Strauss on 04.07.13.
// Copyright (c) 2013 Orlyapps Janzen & Strauß GbR. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SearchViewController : UITableViewController <UISearchBarDelegate>

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;

@end
91 changes: 91 additions & 0 deletions Lodestone/SearchViewController.m
@@ -0,0 +1,91 @@
//
// SearchViewController.m
// Lodestone
//
// Created by Florian Strauss on 04.07.13.
// Copyright (c) 2013 Orlyapps Janzen & Strauß GbR. All rights reserved.
//

#import "SearchViewController.h"
#import "DetailViewController.h"

#import "CharacterCell.h"
#import "FFLodestone.h"

@interface SearchViewController ()

@property (strong, nonatomic) NSArray *characters;
@property (strong, nonatomic) AFHTTPRequestOperation *operation;


@end

@implementation SearchViewController


- (void)viewDidLoad
{
[super viewDidLoad];

self.characters = [NSArray array];

self.clearsSelectionOnViewWillAppear = NO;

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [self.characters count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CharacterCell";
CharacterCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

FFCharacter *character = [self.characters objectAtIndex:indexPath.row];

cell.nameLabel.text = character.name;
cell.serverLabel.text = character.server;
[cell.thumbnailImage setImageWithURL:character.thumbnail
placeholderImage:nil];

return cell;
}



#pragma mark - Navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
FFCharacter *character = [self.characters objectAtIndex:path.row];

[segue.destinationViewController setCharacter:character];
}


#pragma mark - UISearchBar delegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

// Stop old operation
if(self.operation != nil) {
[self.operation cancel];
}
self.operation = [[FFLodestone sharedInstance] searchCharacterWithName:searchText worldName:nil classjob:nil completionHandler:^(NSArray *characters, NSError *error) {
self.characters = characters;
[self.tableView reloadData];
}];
}


@end
13 changes: 13 additions & 0 deletions Lodestone/SidePanelViewController.h
@@ -0,0 +1,13 @@
//
// SidePanelViewController.h
// Lodestone
//
// Created by Florian Strauss on 04.07.13.
// Copyright (c) 2013 Orlyapps Janzen & Strauß GbR. All rights reserved.
//

#import "JASidePanelController.h"

@interface SidePanelViewController : JASidePanelController

@end

0 comments on commit b274f9e

Please sign in to comment.