Skip to content

Commit

Permalink
Merge pull request #6 from panicstyle/3.6
Browse files Browse the repository at this point in the history
이미지 보기 및 저장 기능 추가
  • Loading branch information
panicstyle authored Mar 18, 2017
2 parents 2b94ccf + f001617 commit 9e25c10
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 81 deletions.
12 changes: 9 additions & 3 deletions iMoojigae.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
EC2080A31C954540006305A8 /* ArticleData.m in Sources */ = {isa = PBXBuildFile; fileRef = EC2080A21C954540006305A8 /* ArticleData.m */; };
EC21A6B81E7CE33200B2D138 /* WebLinkView.m in Sources */ = {isa = PBXBuildFile; fileRef = EC21A6B71E7CE33200B2D138 /* WebLinkView.m */; };
EC3AA62F1C990865006BFE5B /* MainData.m in Sources */ = {isa = PBXBuildFile; fileRef = EC3AA62E1C990865006BFE5B /* MainData.m */; };
EC3AA6321C992861006BFE5B /* BoardData.m in Sources */ = {isa = PBXBuildFile; fileRef = EC3AA6311C992861006BFE5B /* BoardData.m */; };
EC3AA6351C993628006BFE5B /* ItemsData.m in Sources */ = {isa = PBXBuildFile; fileRef = EC3AA6341C993628006BFE5B /* ItemsData.m */; };
Expand Down Expand Up @@ -58,6 +59,8 @@
/* Begin PBXFileReference section */
EC2080A11C954540006305A8 /* ArticleData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArticleData.h; sourceTree = "<group>"; };
EC2080A21C954540006305A8 /* ArticleData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArticleData.m; sourceTree = "<group>"; };
EC21A6B61E7CE33200B2D138 /* WebLinkView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebLinkView.h; sourceTree = "<group>"; };
EC21A6B71E7CE33200B2D138 /* WebLinkView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebLinkView.m; sourceTree = "<group>"; };
EC3AA62D1C990865006BFE5B /* MainData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainData.h; sourceTree = "<group>"; };
EC3AA62E1C990865006BFE5B /* MainData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainData.m; sourceTree = "<group>"; };
EC3AA6301C992861006BFE5B /* BoardData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoardData.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,7 +170,6 @@
EC717E941C87C68800C1888B /* iMoojigae */ = {
isa = PBXGroup;
children = (
EC582ED41D8D326200B55AEA /* iMoojigae.entitlements */,
EC717F451C89313400C1888B /* AboutView.h */,
EC717F461C89313400C1888B /* AboutView.m */,
EC717E981C87C68800C1888B /* AppDelegate.h */,
Expand All @@ -185,9 +187,12 @@
EC717E9C1C87C68800C1888B /* BoardView.m */,
ECC846AC1C91588000CF47DA /* CommentWriteView.h */,
ECC846AD1C91588000CF47DA /* CommentWriteView.m */,
ECFBFF311D72DBC3004B1BFB /* EncodingOption.h */,
ECFBFF321D72DBC3004B1BFB /* EncodingOption.m */,
EC717F0E1C8811C500C1888B /* env.h */,
EC717F6D1C8AB6E600C1888B /* GoogleCalView.h */,
EC717F6E1C8AB6E600C1888B /* GoogleCalView.m */,
EC582ED41D8D326200B55AEA /* iMoojigae.entitlements */,
EC717EA61C87C68800C1888B /* Info.plist */,
EC3AA6331C993628006BFE5B /* ItemsData.h */,
EC3AA6341C993628006BFE5B /* ItemsData.m */,
Expand Down Expand Up @@ -216,8 +221,8 @@
EC717E951C87C68800C1888B /* Supporting Files */,
EC938BC21C90534E006BEF9E /* Utils.h */,
EC938BC31C90534E006BEF9E /* Utils.m */,
ECFBFF311D72DBC3004B1BFB /* EncodingOption.h */,
ECFBFF321D72DBC3004B1BFB /* EncodingOption.m */,
EC21A6B61E7CE33200B2D138 /* WebLinkView.h */,
EC21A6B71E7CE33200B2D138 /* WebLinkView.m */,
);
path = iMoojigae;
sourceTree = "<group>";
Expand Down Expand Up @@ -400,6 +405,7 @@
EC717F2D1C882F3E00C1888B /* SetInfoStorage.m in Sources */,
ECFBFF331D72DBC3004B1BFB /* EncodingOption.m in Sources */,
EC717E9A1C87C68800C1888B /* AppDelegate.m in Sources */,
EC21A6B81E7CE33200B2D138 /* WebLinkView.m in Sources */,
EC3AA62F1C990865006BFE5B /* MainData.m in Sources */,
EC717F2C1C882F3E00C1888B /* SetInfo.m in Sources */,
EC717F2B1C882F3E00C1888B /* LoginToService.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion iMoojigae/AboutView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)viewDidLoad
// NSString *version = [infoDict objectForKey:@"CFBundleShortVersionString"];
NSString *version = [infoDict objectForKey:@"CFBundleShortVersionString"];

msgAbout = [NSString stringWithFormat:@"무지개교육마을 / 아이폰\n버전 : %@\n문의메일 : panicstyle@gmail.com\n홈페이지 : http://www.panicstyle.net/?page_id=5", version];
msgAbout = [NSString stringWithFormat:@"무지개교육마을앱 for iOS\n버전 : %@\n개발자 : 호랑이\n문의메일 : panicstyle@gmail.com\n홈페이지 : http://www.panicstyle.net/?page_id=5\n소스 : https://github.com/panicstyle/iMoojigae\n\n광고수익은 공동육아 저소득기금으로 사용됩니다.", version];
textView.text = msgAbout;
}

Expand Down
47 changes: 26 additions & 21 deletions iMoojigae/ArticleData.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,20 @@ - (void)doFetch

for (int i = 0; i < [imageItems count]; i++) {
NSDictionary *jsonItem = [imageItems objectAtIndex:i];
NSString *fileName = [jsonItem valueForKey:@"fileName"];
NSString *link = [jsonItem valueForKey:@"link"];
[strImage appendString:link];
}

/* 이미지 파일목록중 파일명이 이미지인 것들만 이미지에 포함시킨다. */
fileName = [fileName lowercaseString];
if ([fileName containsString:@".jpg"]
|| [fileName containsString:@".jpeg"]
|| [fileName containsString:@".png"]
|| [fileName containsString:@".gif"]
) {
[strImage appendString:link];
}
}

NSMutableString *strAttach = [[NSMutableString alloc]init];
[strAttach appendString:@""];

Expand Down Expand Up @@ -190,20 +200,16 @@ - (void)doFetch
[m_arrayItems addObject:currItem];
}

/* NSString *strHeader = @"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-kr\"></head><body>";
NSString *strBottom = @"</table></body></html>";
NSString *strResize = @"<script>function resizeImage2(mm){var width = eval(mm.width);var height = eval(mm.height);if( width > 300 ){var p_height = 300 / width;var new_height = height * p_height;eval(mm.width = 300);eval(mm.height = new_height);}} function image_open(src, mm) { var width = eval(mm.width); window.open(src,'image');}</script>";
NSString *cssStr = @"<link href=\"./css/default.css\" rel=\"stylesheet\">";
NSString *strBody = @"<body><table border=0 width=100%>";
NSString *strBody2 = @"</table><table border=0 width=100%>";
*/
NSMutableString *strHeader = [[NSMutableString alloc] init];
[strHeader appendString:@"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"];
[strHeader appendString:@"<html><head>"];
[strHeader appendString:@"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-kr\">"];
[strHeader appendString:@"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi\">"];
[strHeader appendString:@"<style>body {font-family:\"고딕\";font-size:medium;}.title{text-margin:10px 0px;font-size:large}.name{color:gray;margin:10px 0px;font-size:small}.content{}.profile {text-align:left;color:gray;margin:10px 0px;font-size:small}.comment_header{text-align:left;color:white;background: lightgray;padding:20px 0px 10px 10px;font-size:small}.reply{border-bottom:1px solid gray;margin:10px 0px}.reply_header {color:gray;;font-size:small}.reply_content {margin:10px 0px}.re_reply{border-bottom:1px solid gray;margin:10px 0px 0px 20px;background:lightgray}</style>"];
[strHeader appendString:@"<script> \
[strHeader appendString:@"<script>function myapp_clickImg(obj){window.location=\"jscall://\"+encodeURIComponent(obj.src);}</script>"];
[strHeader appendString:@"</head>"];

// [strHeader appendString:@"<script> \
function imageResize() { \
var boardWidth = window.innerWidth - 30; \
if (document.cashcow && document.cashcow.boardWidth) \
Expand All @@ -214,22 +220,21 @@ function imageResize() { \
obj[i].width = boardWidth; \
} \
}</script>"];
[strHeader appendString:@"<script>window.onload=imageResize;</script></head>"];
// [strHeader appendString:@"<script>window.onload=imageResize;</script></head>"];
NSString *strBottom = @"</body></html>";
// String cssStr = "<link href=\"./css/default.css\" rel=\"stylesheet\">";
NSString *strBody = @"<body>";

/* 이미지 테크에 width 값과 click 시 javascript 를 호출하도록 수정한다. */
m_strContent = [[NSString alloc] initWithFormat:@"%@%@%@%@%@%@%@",
strHeader,
strBody,
[strContent stringByReplacingOccurrencesOfString:@"<img " withString:@"<img onclick=\"myapp_clickImg(this)\" width=300 "],
[strImage stringByReplacingOccurrencesOfString:@"<img " withString:@"<img onclick=\"myapp_clickImg(this)\" width=300 "],
strAttach,
strProfile,
strBottom];

m_strContent = [[NSString alloc] initWithFormat:@"%@%@%@%@%@%@%@", strHeader, strBody, strContent, strImage, strAttach, strProfile, strBottom];

/*
CGRect rectScreen = m_webView.frame;
m_lContentHeight = rectScreen.size.height;
CGRect contentRect = m_contentCell.frame;
contentRect.size.height = m_lContentHeight;
m_contentCell.frame = contentRect;
*/
[target performSelector:selector withObject:[NSNumber numberWithInt:RESULT_OK] afterDelay:0];
return;
}
Expand Down
62 changes: 49 additions & 13 deletions iMoojigae/ArticleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "env.h"
#import "Utils.h"
#import "ArticleData.h"
#import "WebLinkView.h"

@interface ArticleView ()
{
Expand Down Expand Up @@ -47,6 +48,10 @@ @interface ArticleView ()
NSString *m_strEditableContent;

NSURLConnection *conn;

NSString *m_strWebLink;
int m_nFileType;

}
@end

Expand Down Expand Up @@ -411,18 +416,45 @@ - (void) webViewDidFinishLoad:(UIWebView *)sender {

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

// if (navigationType == UIWebViewNavigationTypeLinkClicked) {

NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSLog(@"request = %@", urlString);
NSString *key = [Utils findStringRegex:urlString regex:@"(?<=&c=).*?(?=&)"];
NSString *fileName = [m_dicAttach valueForKey:key];

if (navigationType == UIWebViewNavigationTypeLinkClicked) {
// URLEncoding 되어 있지 않음.
// fileName = [fileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSLog(@"request = %@", urlString);
NSString *key = [Utils findStringRegex:urlString regex:@"(?<=&c=).*?(?=&)"];
NSString *fileName = [m_dicAttach valueForKey:key];
// URLEncoding 되어 있지 않음.
// fileName = [fileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([fileName hasSuffix:@"png"] || [fileName hasSuffix:@"jpg"]
|| [fileName hasSuffix:@"jpeg"]|| [fileName hasSuffix:@"gif"]) {
m_nFileType = FILE_TYPE_IMAGE;
m_strWebLink = urlString;
[self performSegueWithIdentifier:@"WebLink" sender:self];
} else {
[[UIApplication sharedApplication] openURL:[request URL]];
}

return NO;
} else if (navigationType == UIWebViewNavigationTypeOther) {

if ([fileName hasSuffix:@".hwp"] || [fileName hasSuffix:@".pdf"]) {
if ([[[request URL] absoluteString] hasPrefix:@"jscall:"]) {

NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@"://"];
NSString *functionName = [components objectAtIndex:1];

NSLog(@"requestString = [%@]", requestString);
NSLog(@"functionName = [%@]", functionName);

NSString *fileName = [functionName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"fileName = [%@]", fileName);

m_nFileType = FILE_TYPE_IMAGE;
m_strWebLink = fileName;
[self performSegueWithIdentifier:@"WebLink" sender:self];
return NO;
} else if ([fileName hasSuffix:@".hwp"] || [fileName hasSuffix:@".pdf"]) {
NSData *tempData = [NSData dataWithContentsOfURL:url];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
Expand All @@ -438,11 +470,11 @@ -(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)req
self.doic = [UIDocumentInteractionController interactionControllerWithURL:resultURL];
self.doic.delegate = self;
[self.doic presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
return NO;
} else {

return YES;
}

// }
}
return YES;
}

Expand Down Expand Up @@ -723,6 +755,10 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
view.m_strContent = m_strEditableContent;
view.target = self;
view.selector = @selector(didWrite:);
} else if ([[segue identifier] isEqualToString:@"WebLink"]) {
WebLinkView *view = [segue destinationViewController];
view.m_nFileType = [NSNumber numberWithInt:m_nFileType];
view.m_strLink = m_strWebLink;
}
}

Expand Down
Loading

0 comments on commit 9e25c10

Please sign in to comment.