-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from code4romania/develop
Release for local elections 2020
- Loading branch information
Showing
99 changed files
with
1,952 additions
and
305 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,8 @@ | ||
# These owners will be the default owners for everything in | ||
# the repo. Unless a later match takes precedence, | ||
# they will be requested for review when someone | ||
# opens a pull request. | ||
* @CristiHabliuc | ||
|
||
# More details on creating a codeowners file: | ||
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,59 @@ | ||
// | ||
// AppLanguageManager.swift | ||
// MonitorizareVot | ||
// | ||
// Created by Cristi Habliuc on 20/09/2020. | ||
// Copyright © 2020 Code4Ro. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class AppLanguageManager: NSObject { | ||
static let shared = AppLanguageManager() | ||
|
||
private(set) var supportedLanguages: [String] = ["en"] | ||
|
||
var selectedLanguage: String? { | ||
didSet { | ||
save() | ||
} | ||
} | ||
|
||
private override init() { | ||
super.init() | ||
load() | ||
} | ||
|
||
private func load() { | ||
if let languagesInline = Bundle.main.infoDictionary?["ALLOWED_LANGUAGES"] as? String { | ||
supportedLanguages = languagesInline.components(separatedBy: ",").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | ||
} else { | ||
supportedLanguages = ["en"] // default to english | ||
} | ||
|
||
if let savedLanguage = PreferencesManager.shared.languageLocale { | ||
selectedLanguage = savedLanguage | ||
} else { | ||
// select the current system language if it's in the list | ||
let systemLanguage = Locale.current.identifier | ||
if supportedLanguages.contains(systemLanguage) { | ||
selectedLanguage = systemLanguage | ||
// also save it for later | ||
save() | ||
} | ||
} | ||
|
||
} | ||
|
||
func languageName(forIdentifier identifier: String) -> String { | ||
return Locale(identifier: identifier) | ||
.localizedString(forLanguageCode: identifier)?.capitalized ?? identifier.capitalized | ||
} | ||
|
||
func save() { | ||
guard let selectedLanguage = selectedLanguage else { return } | ||
PreferencesManager.shared.languageLocale = selectedLanguage | ||
PreferencesManager.shared.languageName = languageName(forIdentifier: selectedLanguage) | ||
} | ||
|
||
} |
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,92 @@ | ||
// | ||
// AppUpdateManager.swift | ||
// MonitorizareVot | ||
// | ||
// Created by Cristi Habliuc on 14/12/2019. | ||
// Copyright © 2019 Code4Ro. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Alamofire | ||
|
||
/// This manager's sole purpose is to check if there's a new version of the app available on the app store | ||
/// You can adjust its functionality via RemoteConfig or completely disable it using the local xcconfig setting | ||
/// `DISABLE_UPDATE_CHECK` (set it to true) | ||
class AppUpdateManager: NSObject { | ||
static let shared = AppUpdateManager() | ||
|
||
var currentVersion: String { | ||
guard let infoDict = Bundle.main.infoDictionary, | ||
let currentVer = infoDict["CFBundleShortVersionString"] as? String else { | ||
fatalError("No current ver found, this shouldn't happen") | ||
} | ||
return currentVer | ||
} | ||
|
||
var applicationURL: URL { | ||
return URL(string: "https://apps.apple.com/app/id1183063109")! | ||
} | ||
|
||
var isUpdateCheckCompletelyDisabled: Bool { | ||
if let infoDict = Bundle.main.infoDictionary, | ||
let disableFlag = infoDict["DISABLE_UPDATE_CHECK"] as? String, | ||
disableFlag == "true" { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
private override init() {} | ||
|
||
/// It's okay to have the error messages not localized, since they'll never reach the user. Debugging purposes only | ||
enum UpdateError: Error { | ||
case noResults | ||
case unknown(reason: String) | ||
|
||
var localizedDescription: String { | ||
switch self { | ||
case .noResults: return "No information on latest version" | ||
case .unknown(let reason): return reason | ||
} | ||
} | ||
} | ||
|
||
typealias NewVersionCallback = (_ isNewVersionAvailable: Bool, _ result: AppInformationResponse.ResultResponse?, _ error: UpdateError?) -> Void | ||
|
||
func checkForNewVersion(then callback: @escaping NewVersionCallback) { | ||
guard !isUpdateCheckCompletelyDisabled else { | ||
DebugLog("Update check disabled via DISABLE_UPDATE_CHECK flag. Ignoring...") | ||
return | ||
} | ||
|
||
guard let infoDict = Bundle.main.infoDictionary, | ||
let bundleId = infoDict["CFBundleIdentifier"] as? String else { | ||
fatalError("No app id found, this shouldn't happen") | ||
} | ||
|
||
let currentVer = currentVersion | ||
let urlString = "https://itunes.apple.com/lookup?bundleId=" + bundleId | ||
guard let url = URL(string: urlString) else { | ||
fatalError("Invalid check url: \(urlString)") | ||
} | ||
|
||
Alamofire | ||
.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: [:]) | ||
.response { response in | ||
if response.response?.statusCode == 200, | ||
let data = response.data { | ||
do { | ||
let response = try JSONDecoder().decode(AppInformationResponse.self, from: data) | ||
if let result = response.results.first { | ||
let isNewVersionAvailable = result.version.compare(currentVer, options: .numeric, range: nil, locale: nil) == .orderedDescending | ||
callback(isNewVersionAvailable, result, nil) | ||
return | ||
} | ||
} catch { | ||
callback(false, nil, .unknown(reason: "Couldn't decode response")) | ||
} | ||
} | ||
callback(false, nil, .unknown(reason: "Unknown reason")) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.