From 86ae17d7622f44ea20607d7616d43c6e2f220a19 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Tue, 26 Jul 2016 15:01:46 -0400 Subject: [PATCH] Container App: bookmark widget max row setting --- .../Setting/SettingWidgetBookmarksTBVC.swift | 71 +++++++++++++++++++ Kiwix-iOS/Controller/SettingTBVC.swift | 7 +- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Setting.storyboard | 50 ++++++------- Kiwix.xcodeproj/project.pbxproj | 12 ++++ 5 files changed, 114 insertions(+), 28 deletions(-) create mode 100644 Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift diff --git a/Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift b/Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift new file mode 100644 index 00000000..88a5f527 --- /dev/null +++ b/Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift @@ -0,0 +1,71 @@ +// +// SettingWidgetBookmarksTBVC.swift +// Kiwix +// +// Created by Chris Li on 7/26/16. +// Copyright © 2016 Chris. All rights reserved. +// + +import UIKit + +class SettingWidgetBookmarksTBVC: UITableViewController { + private var rowCount = 1 // widget row count + + let options = [NSLocalizedString("One Row", comment: "Setting: Bookmark Widget"), + NSLocalizedString("Two Rows", comment: "Setting: Bookmark Widget"), + NSLocalizedString("Three Rows", comment: "Setting: Bookmark Widget")] + + override func viewWillAppear(animated: Bool) { + super.viewWillAppear(animated) + + title = LocalizedStrings.bookmarks + if let defaults = NSUserDefaults(suiteName: "group.kiwix") { + rowCount = max(1, min(defaults.integerForKey("BookmarkWidgetRowCount"), 3)) + } + } + + override func viewWillDisappear(animated: Bool) { + super.viewWillDisappear(animated) + let defaults = NSUserDefaults(suiteName: "group.kiwix") + defaults?.setInteger(rowCount ?? 1, forKey: "BookmarkWidgetRowCount") + } + + // MARK: - Table view data source + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + return 1 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return options.count + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) + cell.textLabel?.text = options[indexPath.row] + cell.accessoryType = indexPath.row == (rowCount - 1) ? .Checkmark : .None + return cell + } + + override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + return NSLocalizedString("Set the maximum number of rows displayed in Bookmarks Today Widget.", comment: "Setting: Bookmark Widget") + } + + // MARK: - Table view delegate + + override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + let oldIndexPath = NSIndexPath(forItem: rowCount - 1, inSection: 0) + guard let oldCell = tableView.cellForRowAtIndexPath(oldIndexPath), + let newCell = tableView.cellForRowAtIndexPath(indexPath) else {return} + oldCell.accessoryType = .None + newCell.accessoryType = .Checkmark + rowCount = indexPath.row + 1 + tableView.deselectRowAtIndexPath(indexPath, animated: true) + } + + override func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + guard section == 0 else {return} + guard let view = view as? UITableViewHeaderFooterView else {return} + view.textLabel?.textAlignment = .Center + } +} \ No newline at end of file diff --git a/Kiwix-iOS/Controller/SettingTBVC.swift b/Kiwix-iOS/Controller/SettingTBVC.swift index 9c4365c2..db4bd692 100644 --- a/Kiwix-iOS/Controller/SettingTBVC.swift +++ b/Kiwix-iOS/Controller/SettingTBVC.swift @@ -9,10 +9,11 @@ import UIKit class SettingTBVC: UITableViewController { - private(set) var sectionHeader = [LocalizedStrings.library, LocalizedStrings.reading, LocalizedStrings.search, LocalizedStrings.misc] + private(set) var sectionHeader = [LocalizedStrings.library, LocalizedStrings.reading, LocalizedStrings.search, LocalizedStrings.widget, LocalizedStrings.misc] private(set) var cellTextlabels = [[LocalizedStrings.libraryAutoRefresh, LocalizedStrings.libraryUseCellularData, LocalizedStrings.libraryBackup], [LocalizedStrings.fontSize, LocalizedStrings.adjustLayout], [LocalizedStrings.history], + [LocalizedStrings.bookmarks], [LocalizedStrings.rateKiwix, LocalizedStrings.about]] let dateComponentsFormatter: NSDateComponentsFormatter = { @@ -124,6 +125,8 @@ class SettingTBVC: UITableViewController { performSegueWithIdentifier("AdjustLayout", sender: self) case LocalizedStrings.history: performSegueWithIdentifier("SearchHistory", sender: self) + case LocalizedStrings.bookmarks: + performSegueWithIdentifier("SettingWidgetBookmarksTBVC", sender: self) case "Boost Factor 🚀": performSegueWithIdentifier("SearchTune", sender: self) case LocalizedStrings.rateKiwix: @@ -194,6 +197,7 @@ extension LocalizedStrings { class var library: String {return NSLocalizedString("Library ", comment: "Setting: Section Header")} class var reading: String {return NSLocalizedString("Reading", comment: "Setting: Section Header")} class var search: String {return NSLocalizedString("Search", comment: "Setting: Section Header")} + class var widget: String {return NSLocalizedString("Widget", comment: "Setting: Section Header")} class var misc: String {return NSLocalizedString("Misc", comment: "Setting: Section Header")} //MARK: - Table Cell Text @@ -202,7 +206,6 @@ extension LocalizedStrings { class var libraryBackup: String {return NSLocalizedString("Backup Local Files", comment: "Setting: Backup Local Files")} class var fontSize: String {return NSLocalizedString("Font Size", comment: "Setting: Font Size")} class var adjustLayout: String {return NSLocalizedString("Adjust Layout", comment: "Setting: Adjust Layout")} - class var booksToInclude: String {return NSLocalizedString("Books To Include", comment: "Setting: Books To Include")} class var rateKiwix: String {return NSLocalizedString("Please Rate Kiwix", comment: "Setting: Others")} class var emailFeedback: String {return NSLocalizedString("Send Email Feedback", comment: "Setting: Others")} class var about: String {return NSLocalizedString("About", comment: "Setting: Others")} diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 3752cd93..b6e40b03 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.7.643 + 1.7.663 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Setting.storyboard b/Kiwix-iOS/Storyboard/Setting.storyboard index 60329dda..a334ccd4 100644 --- a/Kiwix-iOS/Storyboard/Setting.storyboard +++ b/Kiwix-iOS/Storyboard/Setting.storyboard @@ -59,35 +59,34 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -96,7 +95,7 @@ - + @@ -153,6 +152,7 @@ + diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index c68c7ad7..28945702 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -121,6 +121,7 @@ 973DD4231D3443A3009D45DB /* ExtensionAndTypealias.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4221D3443A3009D45DB /* ExtensionAndTypealias.swift */; }; 973DD4251D344558009D45DB /* ScanLocalBookOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4241D344558009D45DB /* ScanLocalBookOperation.swift */; }; 973DD4281D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4271D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift */; }; + 974F42821D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */; }; 975227821D020560001D1DDE /* Indexer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975227811D020560001D1DDE /* Indexer.storyboard */; }; 975227991D020C00001D1DDE /* indexer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975227921D020C00001D1DDE /* indexer.cpp */; settings = {COMPILER_FLAGS = "-w"; }; }; 9752279B1D020C00001D1DDE /* otherTools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975227931D020C00001D1DDE /* otherTools.cpp */; }; @@ -379,6 +380,7 @@ 97497B5C1D074FB800ECD691 /* htmlparse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = htmlparse.h; path = "Kiwix/libkiwix/C&C++/xapian/htmlparse.h"; sourceTree = ""; }; 97497B5D1D074FB800ECD691 /* myhtmlparse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = myhtmlparse.h; path = "Kiwix/libkiwix/C&C++/xapian/myhtmlparse.h"; sourceTree = ""; }; 97497B5E1D07584100ECD691 /* xapianIndexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = xapianIndexer.h; path = "Kiwix/libkiwix/C&C++/xapianIndexer.h"; sourceTree = ""; }; + 974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingWidgetBookmarksTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift"; sourceTree = SOURCE_ROOT; }; 975227811D020560001D1DDE /* Indexer.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Indexer.storyboard; path = "Kiwix-OSX/StoryBoards/Indexer.storyboard"; sourceTree = SOURCE_ROOT; }; 975227921D020C00001D1DDE /* indexer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = indexer.cpp; path = "Kiwix/libkiwix/C&C++/indexer.cpp"; sourceTree = ""; tabWidth = 2; }; 975227931D020C00001D1DDE /* otherTools.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = otherTools.cpp; path = "Kiwix/libkiwix/C&C++/otherTools.cpp"; sourceTree = ""; }; @@ -824,6 +826,14 @@ name = Bookmark; sourceTree = ""; }; + 974F42801D47E15400F8074C /* Widget */ = { + isa = PBXGroup; + children = ( + 974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */, + ); + name = Widget; + sourceTree = ""; + }; 975227A41D020C0F001D1DDE /* indexer */ = { isa = PBXGroup; children = ( @@ -902,6 +912,7 @@ 97C01FCA1C39B7F100D010E5 /* Library */, 97C01FD21C39BF4E00D010E5 /* Reading */, 970E68B31D37E1E0001E8514 /* Search */, + 974F42801D47E15400F8074C /* Widget */, ); name = Setting; sourceTree = ""; @@ -1649,6 +1660,7 @@ 978C58981C1CD86E0077AE47 /* Book.swift in Sources */, 978C58961C1CD86E0077AE47 /* Language.swift in Sources */, 971A10701D022E62007FC62C /* Network.swift in Sources */, + 974F42821D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift in Sources */, 970E68B21D37E1DD001E8514 /* SettingSearchTuneController.swift in Sources */, 971A104A1D022CBE007FC62C /* SearchResultTBVC.swift in Sources */, 971A105B1D022DAD007FC62C /* LibraryOnlineTBVC.swift in Sources */,