Skip to content

Commit

Permalink
add city & language
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
cywd committed Sep 20, 2018
1 parent bcab91b commit 84b39d7
Show file tree
Hide file tree
Showing 15 changed files with 759 additions and 79 deletions.
8 changes: 8 additions & 0 deletions FitHub/FitHub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
E7B347A11FECF1B500A114E9 /* FitHud.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B347A01FECF1B500A114E9 /* FitHud.swift */; };
E7B635271FFF4E130085CF9A /* OrgsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B635261FFF4E130085CF9A /* OrgsViewController.swift */; };
E7B635291FFF4E1F0085CF9A /* OrgsViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E7B635281FFF4E1F0085CF9A /* OrgsViewController.storyboard */; };
E7CB5851215344320096CD79 /* location.json in Resources */ = {isa = PBXBuildFile; fileRef = E7CB5850215344310096CD79 /* location.json */; };
E7CB5853215344650096CD79 /* Locations.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7CB5852215344650096CD79 /* Locations.swift */; };
E7D3CD6A1FD69CF500F96B99 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7D3CD691FD69CF500F96B99 /* AboutViewController.swift */; };
E7D3CD6C1FD69D0300F96B99 /* AboutViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E7D3CD6B1FD69D0300F96B99 /* AboutViewController.storyboard */; };
E7DB97A8202AE4C300948683 /* FitBadgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7DB97A7202AE4C300948683 /* FitBadgeView.swift */; };
Expand Down Expand Up @@ -234,6 +236,8 @@
E7B347A01FECF1B500A114E9 /* FitHud.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FitHud.swift; sourceTree = "<group>"; };
E7B635261FFF4E130085CF9A /* OrgsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrgsViewController.swift; sourceTree = "<group>"; };
E7B635281FFF4E1F0085CF9A /* OrgsViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = OrgsViewController.storyboard; sourceTree = "<group>"; };
E7CB5850215344310096CD79 /* location.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = location.json; sourceTree = "<group>"; };
E7CB5852215344650096CD79 /* Locations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Locations.swift; sourceTree = "<group>"; };
E7D3CD691FD69CF500F96B99 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
E7D3CD6B1FD69D0300F96B99 /* AboutViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AboutViewController.storyboard; sourceTree = "<group>"; };
E7DB97A7202AE4C300948683 /* FitBadgeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FitBadgeView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -316,6 +320,7 @@
E7F064E11FF4EA9700E3C7A8 /* SVGImage.swift */,
E7DB97A7202AE4C300948683 /* FitBadgeView.swift */,
E7F064E31FF4F51A00E3C7A8 /* Languages.swift */,
E7CB5852215344650096CD79 /* Locations.swift */,
E720B75E203FA3C300286DAA /* Themes.swift */,
E767ED502008A32C00BEC867 /* UserSessionManager.swift */,
E746085A1FC541FF00951AEF /* NetworkManager.swift */,
Expand Down Expand Up @@ -427,6 +432,7 @@
E720B762203FE2D400286DAA /* icons */,
E77CE54E1FBEC04500A120B2 /* Info.plist */,
E710529D2068B184001F2911 /* colors.json */,
E7CB5850215344310096CD79 /* location.json */,
);
path = FitHub;
sourceTree = "<group>";
Expand Down Expand Up @@ -671,6 +677,7 @@
E72D4A1320049DC400F2F0D0 /* LicenseViewController.storyboard in Resources */,
E7D3CD6C1FD69D0300F96B99 /* AboutViewController.storyboard in Resources */,
E742A5B91FCBB190002E8C0A /* UserDetailViewController.storyboard in Resources */,
E7CB5851215344320096CD79 /* location.json in Resources */,
E720B765203FE2E500286DAA /* [email protected] in Resources */,
11F41AE71FDC3BE700DD047E /* Localizable.strings in Resources */,
E76746F11FC6CBB30087A2DF /* RepositoriesTableViewCell.xib in Resources */,
Expand Down Expand Up @@ -800,6 +807,7 @@
E746085D1FC551D100951AEF /* UserModel.swift in Sources */,
E796457B1FCD2E77006C9C1B /* LoginViewController.swift in Sources */,
E72D4A0D200499BE00F2F0D0 /* LicenseModel.swift in Sources */,
E7CB5853215344650096CD79 /* Locations.swift in Sources */,
E74608571FC51D1300951AEF /* UITableView+FitHub.swift in Sources */,
E74608601FC5769800951AEF /* UserTableViewCell.swift in Sources */,
E73011BA200F301700B43C68 /* OrgsTableViewCell.swift in Sources */,
Expand Down
94 changes: 49 additions & 45 deletions FitHub/FitHub/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

return true
}

func getTheLaunchImage() -> UIImage? {

let viewSize = UIScreen.main.bounds.size;

var viewOrientation: String?
if ((UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.portraitUpsideDown) || (UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.portrait)) {
viewOrientation = "Portrait";
} else {
viewOrientation = "Landscape";
}

var launchImage: String! = ""

let imagesDict = Bundle.main.infoDictionary!["UILaunchImages"] as! [Any]
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

for dic in imagesDict {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

let dict = dic as! [String : Any]
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

let imageSize = NSCoder.cgSize(for: dict["UILaunchImageSize"] as! String)
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

if (imageSize.equalTo(viewSize) && (viewOrientation == dict["UILaunchImageOrientation"] as? String))
{
launchImage = (dict["UILaunchImageName"] as! String)
}
}
return UIImage(named: launchImage)
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

extension AppDelegate {

private func initShortItems() {

var shortcutItems = [UIApplicationShortcutItem]()
Expand All @@ -80,29 +77,37 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

UIApplication.shared.shortcutItems = shortcutItems
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

func getTheLaunchImage() -> UIImage? {

let viewSize = UIScreen.main.bounds.size;

var viewOrientation: String?
if ((UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.portraitUpsideDown) || (UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.portrait)) {
viewOrientation = "Portrait";
} else {
viewOrientation = "Landscape";
}

var launchImage: String! = ""

let imagesDict = Bundle.main.infoDictionary!["UILaunchImages"] as! [Any]

for dic in imagesDict {

let dict = dic as! [String : Any]

let imageSize = NSCoder.cgSize(for: dict["UILaunchImageSize"] as! String)

if (imageSize.equalTo(viewSize) && (viewOrientation == dict["UILaunchImageOrientation"] as? String))
{
launchImage = (dict["UILaunchImageName"] as! String)
}
}
return UIImage(named: launchImage)
}


func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {

if shortcutItem.type == "com.cy.events" {
Expand All @@ -128,5 +133,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}

}
23 changes: 23 additions & 0 deletions FitHub/FitHub/Assets.xcassets/icon_blackbg.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion FitHub/FitHub/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.1.1</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
30 changes: 23 additions & 7 deletions FitHub/FitHub/Main/CityViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import UIKit

class CityViewController: BaseViewController {


var selectString: String?
var backHandler: (()->())?

var items: [String] {
get {

return ["China",
"Beijing", "Shanghai", "Shenzhen",
"Hangzhou", "Guangzhou", "Chengdu",
"Nanjing", "Wuhan", "Xiamen",
"Tianjin", "Chongqing", "Changsha", "Shenyang"]
return Locations.locations()

// return ["China",
// "Beijing", "Shanghai", "Shenzhen",
// "Hangzhou", "Guangzhou", "Chengdu",
// "Nanjing", "Wuhan", "Xiamen",
// "Tianjin", "Chongqing", "Changsha", "Shenyang"]
}
}

Expand All @@ -46,6 +48,12 @@ class CityViewController: BaseViewController {
self.tableView.frame = self.view.bounds

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "locationCell")
if let loccation = selectString {
let index = items.firstIndex(of: loccation)
let indexPath = IndexPath(row: index!, section: 0)
tableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.top, animated: true)
}


}

Expand Down Expand Up @@ -75,8 +83,16 @@ extension CityViewController: UITableViewDataSource, UITableViewDelegate {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let string = items[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell")
cell?.textLabel?.text = items[indexPath.row]
cell?.textLabel?.text = string

if string == self.selectString {
cell?.textLabel?.textColor = UIColor.red
} else {
cell?.textLabel?.textColor = nil
}

return cell!
}

Expand Down
12 changes: 12 additions & 0 deletions FitHub/FitHub/Main/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ class HomeViewController: BaseViewController {

@IBAction func cityItemTap(_ sender: UIBarButtonItem) {
let vc = CityViewController()

var location = UserDefaults.standard.object(forKey: "location") as? String
if location == nil || location == "" {
location = "China"
}
vc.selectString = location
vc.backHandler = {
self.tableView.fr.headerView?.beginRefreshing()
}
Expand All @@ -124,6 +130,12 @@ class HomeViewController: BaseViewController {

@IBAction func languageItemTap(_ sender: UIBarButtonItem) {
let vc = LanguageViewController.loadStoryboard()

var language = UserDefaults.standard.object(forKey: "language") as? String
if language == nil || language == "" {
language = NSLocalizedString("ALL_LANGUAGE", comment: "所有语言")
}
vc.selectString = language
vc.backHandler = {
self.tableView.fr.headerView?.beginRefreshing()
}
Expand Down
34 changes: 27 additions & 7 deletions FitHub/FitHub/Main/LanguageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@
import UIKit

class LanguageViewController: BaseViewController, StoryboardLoadable {

@IBOutlet weak var tableView: UITableView!

var selectString: String?
var backHandler: (()->())?

var items: [String] {
get {
let allLanguageStr = NSLocalizedString("ALL_LANGUAGE", comment: "所有语言")
var arr = Languages.languages()
for str in arr {
if str == "C++" {
let index = arr.index(of: str)!
arr[index] = "CPP"
}
}
// for str in arr {
// if str == "C++" {
// let index = arr.index(of: str)!
// arr[index] = "CPP"
// }
// }
arr.insert(allLanguageStr, at: 0)
return arr
// return [allLanguageStr,
Expand All @@ -40,6 +42,16 @@ class LanguageViewController: BaseViewController, StoryboardLoadable {

let allLanguageStr = NSLocalizedString("CODE_LANGUAGE", comment: "编程语言")
self.title = allLanguageStr


tableView.register(UITableViewCell.self, forCellReuseIdentifier: "locationCell")

if let language = selectString {
let index = items.firstIndex(of: language)
let indexPath = IndexPath(row: index!, section: 0)
tableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.top, animated: true)
}

}

override func didReceiveMemoryWarning() {
Expand Down Expand Up @@ -69,8 +81,16 @@ extension LanguageViewController: UITableViewDataSource, UITableViewDelegate {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let string = items[indexPath.row]

let cell = tableView.dequeueReusableCell(withIdentifier: "languageCell")
cell?.textLabel?.text = items[indexPath.row]
cell?.textLabel?.text = string

if string == self.selectString {
cell?.textLabel?.textColor = UIColor.red
} else {
cell?.textLabel?.textColor = nil
}
return cell!
}

Expand Down
Loading

0 comments on commit 84b39d7

Please sign in to comment.