Skip to content

Commit

Permalink
Merge pull request ltransun-asterisk#6 from ltranframgia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Tran Hai Linh authored Jun 25, 2017
2 parents 963d687 + 1b7f3bb commit b6e3717
Show file tree
Hide file tree
Showing 34 changed files with 831 additions and 140 deletions.
230 changes: 145 additions & 85 deletions BaseMVC.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions BaseMVC/Sources/Controllers/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class BaseViewController: UIViewController, UIGestureRecognizerDelegate {
// MARK: - IBOutlet

// MARK: - Varialbes
lazy var mainTabBarViewController: MainTabBarController? = {
if let _tabBarController = self.tabBarController as? MainTabBarController {
return _tabBarController
}

return self.view.window?.rootViewController as? MainTabBarController
}()

// MARK: - View Lifecycle
override func viewDidLoad() {
Expand Down
72 changes: 72 additions & 0 deletions BaseMVC/Sources/Controllers/LoginViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// LoginViewController.swift
// BaseMVC
//
// Created by Henry Tran on 6/21/17.
// Copyright © 2017 THL. All rights reserved.
//

import UIKit

class LoginViewController: BaseViewController {

// MARK: - IBOutlet

// MARK: - Varialbes

// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
self.addBtnRightNavWithTitle(title: "Setting")
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

// MARK: - Setup View

// MARK: - Call Api

// MARK: - Actions
@IBAction func actionTouchBtnLogin(_ sender: Any) {
self.mainTabBarViewController?.setupMainApp()
self.dismiss(animated: true, completion: nil)
}

override func actionTouchBtnRight() {
let userSettingVC = LoginViewController.getViewControllerFromStoryboard(Storyboard.User.name)
let navigationVC = UINavigationController(rootViewController: userSettingVC)

// create animator for present
// let animator = Animator(presentedType: .push, dismissedType: .push)
// self.menuViewController?.animator = animator
//
// navigationVC.transitioningDelegate = self.menuViewController

// present
self.present(navigationVC, animated: true, completion: nil)
}

// MARK: - Functions

}
95 changes: 95 additions & 0 deletions BaseMVC/Sources/Controllers/MainTabBarController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import UIKit

enum TabBarType: String {
case timeline
case message
case more
}

class MainTabBarController: UITabBarController {

// MARK: - Varialbes

// MARK: - View Lifecycle
override func awakeFromNib() {
super.awakeFromNib()

// setup
self.setupStartApp()
}

override func viewDidLoad() {
super.viewDidLoad()

// self.view.alpha = 0.0
// setup view
self.setupView()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

// animate when appear
UIView.animate(withDuration: 0.5) {
self.view.alpha = 1.0
}
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Setup View
private func setupView() {

}

func hideTabbar(hide: Bool?, animated: Bool = false) {
self.tabBar.isHidden = hide ?? false
}

// MARK: - Actions

// MARK: - Call Api

// MARK: - Functions
private func setupStartApp() {
let startViewController = StartViewController.getViewControllerFromStoryboard(Storyboard.Main.name)
// set list childs controller to tabbar
let controllers = [startViewController]
self.viewControllers = controllers
self.hideTabbar(hide: true)
}

func setupMainApp() {

// Timeline
let navigationTimeline = UIStoryboard(name: Storyboard.Timeline.name, bundle: nil).instantiateInitialViewController()!
let tabBarItemTimeline = UITabBarItem(tabBarSystemItem: .contacts, tag: 10)
navigationTimeline.tabBarItem = tabBarItemTimeline

// Message
let navigationMessage = UIStoryboard(name: Storyboard.Message.name, bundle: nil).instantiateInitialViewController()!
let tabBarItemMessage = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 20)
navigationMessage.tabBarItem = tabBarItemMessage

// User
let navigationUser = UIStoryboard(name: Storyboard.User.name, bundle: nil).instantiateInitialViewController()!
let tabBarItemUser = UITabBarItem(tabBarSystemItem: .more, tag: 30)
navigationUser.tabBarItem = tabBarItemUser

// set list childs controller to tabbar
let controllers = [navigationTimeline, navigationMessage, navigationUser]
self.viewControllers = controllers
self.hideTabbar(hide: false)
}
}
24 changes: 21 additions & 3 deletions BaseMVC/Sources/Controllers/StartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class StartViewController: BaseViewController {

// MARK: - IBOutlet

@IBOutlet weak var tableView: UITableView!

// MARK: - Varialbes

// MARK: - View Lifecycle
Expand Down Expand Up @@ -47,9 +45,29 @@ class StartViewController: BaseViewController {

// MARK: - Functions
private func checkApp() {

// User module (login, register, ...)
self.perform(#selector(StartViewController.gotoUser), with: nil, afterDelay: 1)

// Main app
// self.perform(#selector(StartViewController.gotoMainApp), with: nil, afterDelay: 1)
}

func gotoMainApp() {
func gotoUser() {
let userSettingVC = LoginViewController.getViewControllerFromStoryboard(Storyboard.User.name)
let navigationVC = UINavigationController(rootViewController: userSettingVC)

// create animator for present
// let animator = Animator(presentedType: .push, dismissedType: .push)
// self.menuViewController?.animator = animator
//
// navigationVC.transitioningDelegate = self.menuViewController

// present
self.present(navigationVC, animated: true, completion: nil)
}

func gotoMainApp() {
self.mainTabBarViewController?.setupMainApp()
}
}
13 changes: 13 additions & 0 deletions BaseMVC/Sources/Dao/UserDao.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UserDao.swift
// Project
//
// Created by Henry Tran on 6/24/17.
// Copyright © 2017 THL. All rights reserved.
//

import RealmSwift

struct UserDao {

}
6 changes: 0 additions & 6 deletions BaseMVC/Sources/Helpers/Config.swift

This file was deleted.

8 changes: 8 additions & 0 deletions BaseMVC/Sources/Helpers/Define/Config.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct Config {
static let baseUrl = "https://dev.mvc.vn"
static let clientId = "MVC"
static let clientSecrect = "secret"
static let dataVersion = 1
static let appId = "12345678"
static let platform = "iOS"
}
File renamed without changes.
9 changes: 9 additions & 0 deletions BaseMVC/Sources/Helpers/Define/EnumDefine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
enum DateFormat: String {
case yyyyssDash = "yyyy-MM-dd'T'HH:mm:ss"
case ddmmSlash = "dd/MM/yyyy HH:mm"
case ddMMyyyy = "dd/MM/yyyy"
case yyyyMMddDash = "yyyy-MM-dd"
case MMyyyy = "MM/yyyy"
case yyyyssSSSZZZZZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions BaseMVC/Sources/Helpers/Define/StructDefine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public struct GroupItem<Group, Item> {
public var group: Group
public var items: [Item]

public init(group: Group, items: [Item]) {
self.group = group
self.items = items
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ struct Storyboard {
static let name = "Main"
static let startViewController = "StartViewController"
}

struct User {
static let name = "User"
static let loginViewController = "LoginViewController"
}

struct Timeline {
static let name = "Timeline"
}

struct Message {
static let name = "Message"
}
}

struct ReuseView {
Expand Down
1 change: 0 additions & 1 deletion BaseMVC/Sources/Helpers/EnumDefine.swift

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ import Foundation
extension Date {

// MARK: - Date
static func convertDateToString(fromDate: Date?, format: String) -> String? {
static func convertDateToString(fromDate: Date?, format: DateFormat) -> String? {
if let convertDate = fromDate {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone.default
dateFormatter.locale = NSLocale(localeIdentifier: Constant.defaultDateLocale) as Locale!
dateFormatter.dateFormat = format
dateFormatter.dateFormat = format.rawValue
return dateFormatter.string(from: convertDate)
} else {
return nil
}
}

static func convertStringToDate(fromString: String?, format: String) -> Date? {
static func convertStringToDate(fromString: String?, format: DateFormat) -> Date? {
if let dateString = fromString {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone.default
dateFormatter.locale = NSLocale(localeIdentifier: Constant.defaultDateLocale) as Locale!
dateFormatter.dateFormat = format
dateFormatter.dateFormat = format.rawValue
return dateFormatter.date(from: dateString)
} else {
return nil
}
}

static func convertStringDateToString(fromString: String?, fromFormat: String, toFormat: String) -> String? {
static func convertStringDateToString(fromString: String?, fromFormat: DateFormat, toFormat: DateFormat) -> String? {
if let dateString = fromString {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone.default
dateFormatter.locale = NSLocale(localeIdentifier: Constant.defaultDateLocale) as Locale!
dateFormatter.dateFormat = fromFormat
dateFormatter.dateFormat = fromFormat.rawValue
guard let date = dateFormatter.date(from: dateString) else {
return nil
}
dateFormatter.dateFormat = toFormat
dateFormatter.dateFormat = toFormat.rawValue
return dateFormatter.string(from: date)
} else {
return nil
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b6e3717

Please sign in to comment.