-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vincent
authored and
vincent
committed
Mar 11, 2016
1 parent
403dba7
commit 91f836e
Showing
4 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// CenterMessagesTableViewModel.swift | ||
// FeelingClient | ||
// | ||
// Created by vincent on 11/3/16. | ||
// Copyright © 2016 xecoder. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public class CenterMessagesListViewModel { | ||
|
||
public let context = Messages.defaultMessages | ||
public var items = [Item]() | ||
|
||
|
||
public func refresh() { | ||
items = context.msgs.map { self.itemForPayback($0) } | ||
print(items) | ||
} | ||
|
||
func itemForPayback(bean: MessageBean) -> Item { | ||
let item = Item(to: bean.to, date: bean.limitDate) | ||
return item | ||
} | ||
|
||
func removePayback(index: Int) { | ||
context.msgs.removeAtIndex(index) | ||
} | ||
|
||
|
||
public struct Item { | ||
public let to: String | ||
public let date: String | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// MessagesTableViewController.swift | ||
// FeelingClient | ||
// | ||
// Created by vincent on 11/3/16. | ||
// Copyright © 2016 xecoder. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class MessagesTableViewController: UITableViewController { | ||
|
||
let viewModel = CenterMessagesListViewModel() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
refresh() | ||
// Uncomment the following line to preserve selection between presentations | ||
// self.clearsSelectionOnViewWillAppear = false | ||
|
||
// Uncomment the following line to display an Edit button in the navigation bar for this view controller. | ||
// self.navigationItem.rightBarButtonItem = self.editButtonItem() | ||
} | ||
|
||
func refresh(){ | ||
viewModel.refresh() | ||
tableView.reloadData() | ||
} | ||
|
||
override func didReceiveMemoryWarning() { | ||
super.didReceiveMemoryWarning() | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
// MARK: - Table view data source | ||
|
||
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { | ||
// #warning Incomplete implementation, return the number of sections | ||
return 1 | ||
} | ||
|
||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
// #warning Incomplete implementation, return the number of rows | ||
return viewModel.items.count | ||
} | ||
|
||
|
||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCellWithIdentifier("message", forIndexPath: indexPath) | ||
let item = viewModel.items[indexPath.row] | ||
|
||
cell.textLabel?.text = item.to | ||
cell.detailTextLabel?.text = item.date | ||
return cell | ||
} | ||
|
||
|
||
|
||
// Override to support conditional editing of the table view. | ||
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { | ||
// Return false if you do not want the specified item to be editable. | ||
return true | ||
} | ||
|
||
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { | ||
if editingStyle == .Delete { | ||
viewModel.removePayback(indexPath.row) | ||
refresh() | ||
} | ||
} | ||
|
||
/* | ||
// Override to support editing the table view. | ||
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { | ||
if editingStyle == .Delete { | ||
// Delete the row from the data source | ||
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) | ||
} else if editingStyle == .Insert { | ||
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view | ||
} | ||
} | ||
*/ | ||
|
||
/* | ||
// Override to support rearranging the table view. | ||
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { | ||
|
||
} | ||
*/ | ||
|
||
/* | ||
// Override to support conditional rearranging of the table view. | ||
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { | ||
// Return false if you do not want the item to be re-orderable. | ||
return true | ||
} | ||
*/ | ||
|
||
/* | ||
// MARK: - Navigation | ||
|
||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | ||
// Get the new view controller using segue.destinationViewController. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters