mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
add thumbnail for post
This commit is contained in:
@@ -228,11 +228,11 @@
|
||||
<rect key="frame" x="0.0" y="8" width="600" height="200"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Storyname" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rFX-WH-9eA">
|
||||
<rect key="frame" x="10" y="59" width="240" height="25"/>
|
||||
<rect key="frame" x="10" y="59" width="210" height="25"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="240" id="D3y-SC-keq"/>
|
||||
<constraint firstAttribute="width" constant="210" id="D3y-SC-keq"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" name="AvenirNext-Medium" family="Avenir Next" pointSize="18"/>
|
||||
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="18"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.90000000000000002" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
@@ -245,13 +245,13 @@
|
||||
<color key="textColor" name="scrollBarColor" catalog="System" colorSpace="catalog"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2012.12.31" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6eW-Iw-LyZ">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="2012.12.31" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6eW-Iw-LyZ">
|
||||
<rect key="frame" x="10" y="21" width="64" height="21"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="21" id="1cs-Uy-WDZ"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" name="AvenirNext-Medium" family="Avenir Next" pointSize="12"/>
|
||||
<color key="textColor" red="0.70196078431372544" green="0.70196078431372544" blue="0.70196078431372544" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="12"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1天前" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WeE-f8-u0E">
|
||||
@@ -260,8 +260,8 @@
|
||||
<constraint firstAttribute="width" constant="64" id="9zs-sL-Fyb"/>
|
||||
<constraint firstAttribute="height" constant="21" id="DVs-bx-QYC"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" name="AvenirNext-Medium" family="Avenir Next" pointSize="12"/>
|
||||
<color key="textColor" red="0.70196078429999997" green="0.70196078429999997" blue="0.70196078429999997" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="12"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="royaloak" translatesAutoresizingMaskIntoConstraints="NO" id="8EG-tD-oQV">
|
||||
@@ -288,7 +288,7 @@
|
||||
<color key="textColor" name="scrollBarColor" catalog="System" colorSpace="catalog"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="StoryImage" translatesAutoresizingMaskIntoConstraints="NO" id="q6H-BE-lvk">
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Android" translatesAutoresizingMaskIntoConstraints="NO" id="q6H-BE-lvk">
|
||||
<rect key="frame" x="501" y="59" width="80" height="80"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="80" id="SeO-2b-eFu"/>
|
||||
@@ -350,6 +350,7 @@
|
||||
<connections>
|
||||
<outlet property="contextView" destination="OV8-aP-e6c" id="X1c-tG-evf"/>
|
||||
<outlet property="nameLabel" destination="rFX-WH-9eA" id="aNo-Jz-pUk"/>
|
||||
<outlet property="thumbnilImageView" destination="q6H-BE-lvk" id="2HE-KR-7Io"/>
|
||||
<segue destination="331-bv-LXb" kind="show" identifier="showWebView" id="5YF-3h-sI8"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
@@ -907,13 +908,13 @@
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="Android" width="32" height="32"/>
|
||||
<image name="Back" width="32" height="32"/>
|
||||
<image name="Camera" width="100" height="100"/>
|
||||
<image name="Home" width="32" height="32"/>
|
||||
<image name="Lightning" width="32" height="32"/>
|
||||
<image name="Menu" width="22" height="22"/>
|
||||
<image name="Python" width="32" height="32"/>
|
||||
<image name="StoryImage" width="300" height="300"/>
|
||||
<image name="UploadCloud" width="32" height="32"/>
|
||||
<image name="UserMale" width="32" height="32"/>
|
||||
<image name="icon-close" width="19" height="20"/>
|
||||
|
||||
@@ -26,7 +26,9 @@ class CreatePostViewController: UITableViewController {
|
||||
let link = self.share_link?.text
|
||||
let type = self.share_type?.text
|
||||
|
||||
let post = Post(viewedTimes: 0, title: title!, createdAt: "", type: type!, url: link!)
|
||||
let post = Post(viewedTimes: 0, title: title!,
|
||||
createdAt: "", type: type!, url: link!,
|
||||
thumbnail: "")
|
||||
|
||||
LibrxService.createPost(post) { [weak self](result) -> () in
|
||||
self!.dismissViewControllerAnimated(true, completion: nil)
|
||||
|
||||
@@ -11,7 +11,7 @@ import UIKit
|
||||
class ExploreCell: UICollectionViewCell {
|
||||
|
||||
@IBOutlet weak var nameLabel: UILabel!
|
||||
|
||||
|
||||
@IBOutlet weak var iconImage: UIImageView!
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ class ExploreCollectionViewController: UICollectionViewController, UICollectionV
|
||||
"Java","IOS","Ruby",
|
||||
"Python", "前端开发","安卓",
|
||||
"设计","资源","Github",
|
||||
"点子","工具箱","音乐"
|
||||
"点子","工具箱","音乐","程序员"
|
||||
]
|
||||
|
||||
var icons = [
|
||||
"Java", "iPhone", "Minecraft",
|
||||
"Python", "CSS", "Android",
|
||||
"Robot","Forrst", "GitHub",
|
||||
"Idea","Toolbox","Music"
|
||||
"Idea","Toolbox","Music", "Sun"
|
||||
]
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x",
|
||||
"filename" : "Sun.png"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x",
|
||||
"filename" : "Sun@2x.png"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x",
|
||||
"filename" : "Sun@3x.png"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 500 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 950 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -16,10 +16,14 @@ import JWT
|
||||
struct LibrxService {
|
||||
|
||||
private static let baseURL = "http://uat.librme.com/api/v1/"
|
||||
// private static let baseURL = "http://localhost:3000/api/v1/"
|
||||
private static let defaultEncodeToken = "493bc0c0da778dc02aeeb1914bfcf0a9"
|
||||
private static let defaultThumail = "http://7pn5d3.com1.z0.glb.clouddn.com/9050353.png"
|
||||
private static let clientID = ""
|
||||
private static let clientSecret = ""
|
||||
|
||||
private var imageCache = NSMutableDictionary()
|
||||
|
||||
private enum ResourcePath: Printable {
|
||||
|
||||
case SignIn
|
||||
@@ -75,19 +79,34 @@ struct LibrxService {
|
||||
var posts:[Post] = []
|
||||
for index in 0..<json.count {
|
||||
|
||||
print(json[index])
|
||||
|
||||
var viewTimes = json[index]["viewed_times"].int
|
||||
var title = json[index]["title"].string
|
||||
var type = json[index]["type"].string
|
||||
var created_at = json[index]["created_at"].string
|
||||
var url = json[index]["url"].string
|
||||
|
||||
var thumbnail = json[index]["thumbnail"].string
|
||||
|
||||
if thumbnail == nil {
|
||||
thumbnail = self.defaultThumail
|
||||
}
|
||||
|
||||
if title == nil{
|
||||
title = url
|
||||
}
|
||||
|
||||
|
||||
posts.append(Post(viewedTimes: viewTimes!, title: title!, createdAt: created_at!, type: type!, url: url!))
|
||||
posts.append(
|
||||
Post(viewedTimes: viewTimes!,
|
||||
title: title!,
|
||||
createdAt: created_at!,
|
||||
type: type!,
|
||||
url: url!,
|
||||
thumbnail: thumbnail!
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
response(posts)
|
||||
|
||||
+4
-1
@@ -13,19 +13,22 @@ class Post: Replyable {
|
||||
let createdAt: String
|
||||
let type: String
|
||||
let url: String
|
||||
let thumbnail: String
|
||||
|
||||
init(
|
||||
viewedTimes: Int,
|
||||
title: String,
|
||||
createdAt: String,
|
||||
type: String,
|
||||
url: String
|
||||
url: String,
|
||||
thumbnail: String
|
||||
){
|
||||
self.viewedTimes = viewedTimes
|
||||
self.title = title
|
||||
self.createdAt = createdAt
|
||||
self.type = type
|
||||
self.url = url
|
||||
self.thumbnail = thumbnail
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class StorysTableViewController: UITableViewController, MenuTransitionManagerDel
|
||||
private var loginStateChange: LoginStateHandler?
|
||||
|
||||
private var postsLoader = PostsLoader(.Default)
|
||||
var imageCache = [String:UIImage]()
|
||||
|
||||
|
||||
var posts:[Post] = [
|
||||
@@ -126,16 +127,45 @@ class StorysTableViewController: UITableViewController, MenuTransitionManagerDel
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:indexPath) as! CustomTableCell
|
||||
|
||||
var post = posts[indexPath.row]
|
||||
|
||||
// cell.contextView.layer.shadowColor = UIColor.blackColor().CGColor
|
||||
// cell.contextView.layer.shadowOffset = CGSizeZero
|
||||
// cell.contextView.layer.shadowOpacity = 0.2
|
||||
// cell.contextView.layer.shadowRadius = 2
|
||||
|
||||
// cell.contextView.layer.borderWidth = 0
|
||||
var defaultColor = cell.contextView.borderColor
|
||||
|
||||
cell.nameLabel.text = post.title
|
||||
|
||||
|
||||
var title = post.title
|
||||
|
||||
if count(title) > 30 {
|
||||
title = title.substringToIndex(advance(post.title.endIndex, -4)) + "..."
|
||||
}
|
||||
|
||||
|
||||
cell.nameLabel.text = title
|
||||
|
||||
if let img = imageCache[post.thumbnail] {
|
||||
cell.thumbnilImageView?.image = img
|
||||
}else{
|
||||
|
||||
let thumbnailUrl = NSURL(string: post.thumbnail)
|
||||
let request: NSURLRequest = NSURLRequest(URL: thumbnailUrl!)
|
||||
let mainQueue = NSOperationQueue.mainQueue()
|
||||
|
||||
NSURLConnection.sendAsynchronousRequest(request, queue: mainQueue, completionHandler: { (response, data, error) -> Void in
|
||||
if error == nil {
|
||||
// Convert the downloaded data in to a UIImage object
|
||||
let image = UIImage(data: data)
|
||||
// Store the image in to our cache
|
||||
self.imageCache[post.thumbnail] = image
|
||||
// Update the cell
|
||||
dispatch_async(dispatch_get_main_queue(), {
|
||||
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) as? CustomTableCell {
|
||||
cellToUpdate.thumbnilImageView?.image = image
|
||||
}
|
||||
})
|
||||
}
|
||||
else {
|
||||
println("Error: \(error.localizedDescription)")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return cell
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user