Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Added new DataStoreManager handling to LogsVC and KeysVC, Fixed issue…
Browse files Browse the repository at this point in the history
… with Delete alert not hiding in LogInfoVC
  • Loading branch information
soulfoodz committed Jul 21, 2020
1 parent 5adb281 commit 0d998cb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 144 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
class AppInfo {
let version: String
let build: String
let gitCommitSHA: String = "53e5fff"
let gitCommitSHA: String = "5adb281"

init?() {
guard let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
Expand Down
5 changes: 5 additions & 0 deletions Super Gluu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -945,6 +946,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VALIDATE_PRODUCT = YES;
};
name = Testing;
Expand Down Expand Up @@ -1051,6 +1053,7 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
Expand Down Expand Up @@ -1079,6 +1082,7 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -1088,6 +1092,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
12 changes: 7 additions & 5 deletions super-gluu/ViewControllers/KeysViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class KeysViewController: BaseViewController, UITableViewDataSource, UITableView

func loadKeyHandlesFromDatabase() {

if let tokenEnts = DataStoreManager.sharedInstance().getTokenEntities() as? [TokenEntity] {
keyHandleArray = tokenEnts
keyHandleArray = [TokenEntity]()

if let tokens = DataStoreManager.sharedInstance()?.keys() as? [TokenEntity] {
keyHandleArray = tokens
keyHandleTableView.reloadData()
}

Expand Down Expand Up @@ -182,13 +184,13 @@ class KeyHandler: NSObject {

func deleteToken(token: TokenEntity, tokenDeleted: @escaping ()->Void) {

DataStoreManager.sharedInstance()?.deleteTokenEntity(forApplication: token.application, userName: token.userName)

// check in mainViewController for matching code. we use the token issuer combined with the username
let keyId = token.application ?? "" + (token.userName ?? "")

// whether the key is licensed or not, call remove to be sure
GluuUserDefaults.removeLicensedKey(keyId)

DataStoreManager.sharedInstance()?.delete(token)

tokenDeleted()
}
Expand All @@ -208,7 +210,7 @@ class KeyHandler: NSObject {

if DataStoreManager.sharedInstance().isUniqueTokenName(newName) {

DataStoreManager.sharedInstance()?.editTokenName(token, name: newName)
DataStoreManager.sharedInstance()?.editToken(token, name: newName)

didEdit()
alert.hideView()
Expand Down
8 changes: 3 additions & 5 deletions super-gluu/ViewControllers/LogDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ class LogDetailViewController: UIViewController {
@IBOutlet var logoImageView: UIImageView!
@IBOutlet var titleLabels: [UILabel]!


var userInfo: UserLoginInfo?

private var alertView: SCLAlertView?


override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -146,7 +144,8 @@ class LogDetailViewController: UIViewController {
self.deleteLog(self.userInfo!)
}

alert.dismiss(animated: true, completion: nil)
alert.hideView()
self.navigationController?.popViewController(animated: true)
})

alert.showCustom(AlertConstants.delete,
Expand All @@ -160,8 +159,7 @@ class LogDetailViewController: UIViewController {
func deleteLog(_ log: UserLoginInfo?) {
// Eric
DataStoreManager.sharedInstance().deleteLog(log)

navigationController?.popViewController(animated: true)

}

}
Expand Down
159 changes: 26 additions & 133 deletions super-gluu/ViewControllers/LogsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import ox_push3

class LogsViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate {

// @IBOutlet var topView: UIView!
// @IBOutlet var topIconView: UIImageView!
@IBOutlet var logsTableView: UITableView!
// @IBOutlet var editLogsButton: UIButton!
// @IBOutlet var cancelButton: UIButton!
@IBOutlet var noLogsLabel: UILabel!
@IBOutlet var contentView: UIView!
@IBOutlet var selectAllButton: UIButton!
Expand Down Expand Up @@ -55,132 +51,37 @@ class LogsViewController: BaseViewController, UITableViewDataSource, UITableView
tabBarController?.selectedIndex = 0
}

func getLogs() {
func updateLogs() {
logsArray = [UserLoginInfo]()
logsArray = DataStoreManager.sharedInstance().getUserLoginInfo() as! [UserLoginInfo]
if let arry = DataStoreManager.sharedInstance()?.userLogs() as? [UserLoginInfo] {
logsArray = arry
}

logsTableView.reloadData()

}

func deleteLog(_ log: UserLoginInfo?) {
func deleteLog(_ log: UserLoginInfo) {
// eric
print(log)
DataStoreManager.sharedInstance().deleteLog(log)
updateLogs()
}

func deleteLogs(_ logs: [Any]?) {
// eric
DataStoreManager.sharedInstance().deleteLogs(logs)
updateLogs()
selectAllView.isHidden = true
}

func updateLogs() {
getLogs()
logsTableView.setEditing(false, animated: true)
}

@IBAction func editCleanLogs(_ sender: Any) {
/*
if editLogsButton.tag == 1 {
//Editing table
logsTableView.setEditing(true, animated: true)
cancelButton.isHidden = false
editLogsButton.tag = 2
editLogsButton.setTitle("Delete", for: .normal)
selectAllView.isHidden = false
} else {
//Deleting logs
var logsForDeleteArray = getLogsForDelete()
if logsForDeleteArray?.count == 0 {
showNoLogsToDeleteAlert()
} else {
deleteLogsAlert(nil, array: logsForDeleteArray)
}
editLogsButton.tag = 1
}
*/
}

@IBAction func cancelEditLogs(_ sender: Any) {
/*
cancelButton.isHidden = true
logsTableView.setEditing(false, animated: true)
editLogsButton.tag = 1
updateButtons()
selectAllView.isHidden = true
deselectAllLogs()
*/
}

// ** Local Text
@IBAction func selectAllClick(_ sender: Any) {
let tag = Int((sender as? UIButton)?.tag ?? 0)
if tag == 1 {
//select all
selectAllLogs(true)
selectAllButton.tag = 2
selectAllButton.setTitle(LocalString.Unselect_All.localized, for: .normal)
} else {
//deselect all
deselectAllLogs()
}
}

func deselectAllLogs() {
selectAllLogs(false)
selectAllButton.tag = 1
selectAllButton.setTitle(LocalString.Select_All.localized, for: .normal)
}


func selectAllLogs(_ isSelect: Bool) {
/*
for i in 0..<logsTableView.numberOfSections {
for j in 0..<logsTableView.numberOfRows(inSection: i) {
let ints = [i, j]
let indexPath = IndexPath(indexes: &ints, length: 2)
if isSelect {
logsTableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
} else {
logsTableView.deselectRow(at: indexPath, animated: true)
}
//Here is your code
}
}
*/
}


func updateButtons() {
/*
let title = editLogsButton.tag == 2 ? "Delete" : "Edit"
editLogsButton.setTitle(title, for: .normal)
*/
}

func deleteLogsAlert(_ log: UserLoginInfo?, array logs: [Any]?) {
func showDeleteLogAlert(log: UserLoginInfo) {
let alert = SCLAlertView(autoDismiss: false, horizontalButtons: true)

print(log)
alert.addButton(AlertConstants.yes, backgroundColor: .red) {
print("YES clicked")

if log != nil {
self.deleteLog(log)
} else if logs != nil || (logs?.count ?? 0) > 0 {
self.deleteLogs(logs)
} else {
return
}

self.deleteLog(log)

alert.hideView()
}

let subText = logs != nil || (logs?.count ?? 0) > 0 ? LocalString.Clear_Logs.localized : LocalString.Clear_Log.localized
let subtext = LocalString.Clear_Log.localized

alert.showCustom(AlertConstants.delete,
subTitle: subText,
subTitle: subtext,
color: AppConfiguration.systemColor,
closeButtonTitle: AlertConstants.no,
circleIconImage: UIImage(named: "icon_trashcan_large")!)
Expand Down Expand Up @@ -218,7 +119,7 @@ class LogsViewController: BaseViewController, UITableViewDataSource, UITableView

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if logsTableView.isEditing != true {
showLogDetail(indexPath.row)
showLogDetail(logsArray[indexPath.row])
}
}

Expand All @@ -233,48 +134,40 @@ class LogsViewController: BaseViewController, UITableViewDataSource, UITableView
deleteButton.backgroundColor = UIColor(red: 1.0, green: 0.231, blue: 0.188, alpha: 1.0)

return [viewButton, deleteButton]

}

func swipeableTableViewCell(_ cell: SWTableViewCell?, didTriggerLeftUtilityButtonWith index: Int) {
}

func swipeableTableViewCell(_ cell: SWTableViewCell?, didTriggerRightUtilityButtonWith index: Int) {

guard
let cell = cell,
let ip = self.logsTableView.indexPath(for: cell),
ip.row < logsArray.count else { return }

let log = logsArray[ip.row]

switch index {
case 0:
print("More button was pressed")
showLogDetail(Int(cell?.tag ?? 0))
showLogDetail(log)
case 1:
// Delete button was pressed
print("Delete button was pressed")
let log = logsArray[cell?.tag ?? 0] as? UserLoginInfo
deleteLogsAlert(log, array: nil)
showDeleteLogAlert(log: log)
default:
break
}
}

//------------------ END --------------------------------
func showLogDetail(_ index: Int) {
func showLogDetail(_ log: UserLoginInfo) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let logVC = storyboard.instantiateViewController(withIdentifier: "LogDetailViewController") as! LogDetailViewController

let userInfo = logsArray[index] as UserLoginInfo
logVC.userInfo = userInfo
logVC.userInfo = log
navigationController?.pushViewController(logVC, animated: true)
}

func getLogsForDelete() -> [AnyHashable]? {
let selectedCells = logsTableView.indexPathsForSelectedRows
var updatedLogsArray: [AnyHashable] = []
for indexParh: IndexPath? in selectedCells ?? [] {
let log = logsArray[indexParh?.row ?? 0] as UserLoginInfo
// if let aLog = log {
// updatedLogsArray.append(aLog)
// }
updatedLogsArray.append(log)
}

return updatedLogsArray
}
}

0 comments on commit 0d998cb

Please sign in to comment.