-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
17 changed files
with
784 additions
and
139 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
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,66 @@ | ||
// | ||
// AzkarsViewController.swift | ||
// MuslimData_Example | ||
// | ||
// Created by Kosrat D. Ahmad on 11/3/18. | ||
// Copyright © 2018 CocoaPods. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import MuslimData | ||
|
||
class AzkarChaptersViewController: UIViewController { | ||
|
||
// MARK: - Outlets | ||
|
||
@IBOutlet weak var chaptersTable: UITableView! | ||
|
||
// MARK: - Properties | ||
|
||
var chapters: [AzkarChapter] = [] | ||
|
||
// MARK: - View Lifecycles | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
chaptersTable.delegate = self | ||
chaptersTable.dataSource = self | ||
|
||
// Get azkar chapters from MuslimData library. | ||
Azkars.azkarChapters(language: .en) { chapters, error in | ||
guard error == nil else { | ||
return | ||
} | ||
self.chapters = chapters! | ||
self.chaptersTable.reloadData() | ||
} | ||
} | ||
} | ||
|
||
// MARK: - UITableViewDelegate | ||
|
||
extension AzkarChaptersViewController: UITableViewDelegate { | ||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
let controller = storyboard?.instantiateViewController(withIdentifier: "azkarController") as? AzkarDetailViewController | ||
controller?.azkarChapter = chapters[indexPath.row] | ||
navigationController?.pushViewController(controller!, animated: true) | ||
tableView.deselectRow(at: indexPath, animated: true) | ||
} | ||
} | ||
|
||
// MARK: - UITableViewDataSource | ||
|
||
extension AzkarChaptersViewController: UITableViewDataSource { | ||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return chapters.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "chapterCell", for: indexPath) | ||
let chapter = chapters[indexPath.row] | ||
cell.textLabel?.text = chapter.name | ||
|
||
return cell | ||
} | ||
} |
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,58 @@ | ||
// | ||
// AzkarDetailViewController.swift | ||
// MuslimData_Example | ||
// | ||
// Created by Kosrat D. Ahmad on 11/3/18. | ||
// Copyright © 2018 CocoaPods. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import MuslimData | ||
|
||
class AzkarDetailViewController: UIViewController { | ||
// MARK: - Outlets | ||
|
||
@IBOutlet weak var azkarTable: UITableView! | ||
|
||
// MARK: - Properties | ||
|
||
var azkarChapter: AzkarChapter? | ||
var azkars: [AzkarItem] = [] | ||
|
||
// MARK: - View Lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
title = azkarChapter!.name | ||
|
||
azkarTable.dataSource = self | ||
azkarTable.tableFooterView = UIView() | ||
|
||
// Get azkar items from MuslimData library. | ||
Azkars.azkarItems(language: .en, chapterId: azkarChapter!.id) { azkars, error in | ||
guard error == nil else { | ||
return | ||
} | ||
self.azkars = azkars! | ||
self.azkarTable.reloadData() | ||
} | ||
} | ||
} | ||
|
||
// MARK: - UITableViewDataSource | ||
|
||
extension AzkarDetailViewController: UITableViewDataSource { | ||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return azkars.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "azkarCell", for: indexPath) | ||
let azkar = azkars[indexPath.row] | ||
cell.textLabel?.text = azkar.item | ||
cell.detailTextLabel?.text = "\(azkar.translation) \n\nReference: \(azkar.reference)" | ||
|
||
return cell | ||
} | ||
} |
Oops, something went wrong.