<commit_before>//
//  SettingController.swift
//  MyReader
//
//  Created by RN-079 on 2017/03/08.
//  Copyright © 2017年 RN-079. All rights reserved.
//

import UIKit

class SettingController: ViewController {
    @IBOutlet weak var topView: UIView!
    @IBOutlet weak var backBtn: UIButton!
    @IBOutlet weak var titleLbl: UILabel!
    @IBOutlet weak var bottomView : UIView!
    @IBOutlet weak var chapterLbl: UILabel!
    @IBOutlet weak var preBtn: UIButton!
    @IBOutlet weak var nextBtn: UIButton!
    @IBOutlet weak var slider: UISlider!
    @IBOutlet weak var listBtn: UIButton!
    @IBOutlet weak var bookmarkBtn: UIButton!
    @IBOutlet weak var lightBtn: UIButton!
    @IBOutlet weak var fontBtn: UIButton!
    @IBOutlet weak var addBookmarkBtn: UIButton!
    
    // params.
    var bookInfo : LocalBookInfo!
    var chapterInfos = [ChapterInfo]()
    var pageContents = [NSMutableAttributedString]()
    
    @IBAction func doClose() {
        self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
    }
    
    @IBAction func doAddBookmark() {
        let storyboard = UIStoryboard(name: "AddBookmark", bundle: nil)
        guard let next = storyboard.instantiateInitialViewController() as? AddBookmarkController else {
            return
        }
        
        next.bookId = bookInfo.bookId
        let pageNumber = AppUtility.getCurrentPage(bookId: bookInfo.bookId)
        next.pageNumber = pageNumber
        next.content = self.pageContents[pageNumber].string
        
        self.present(next, animated: true, completion: nil)
    }
    
    @IBAction func doShowChapters() {
        let storyboard = UIStoryboard(name: "Chapter", bundle: nil)
        guard let next = storyboard.instantiateInitialViewController() as? NavigationController else {
            return
        }
        
        guard let chapterController = next.viewControllers.first as? ChapterController else {
            return
        }
        
        chapterController.chapterInfos = self.chapterInfos
        self.present(next, animated: true, completion: nil)
    }
    
    @IBAction func doShowBookmarks() {
        let storyboard = UIStoryboard(name: "Bookmark", bundle: nil)
        guard let next = storyboard.instantiateInitialViewController() else {
            return
        }
        
        self.present(next, animated: true, completion: nil)
    }
    
    @IBAction func itemSlider(slider: UISlider, event: UIEvent) {
        guard let touch = event.allTouches?.first else {return}
        if (touch.phase != .moved && touch.phase != .began) {
            guard let currentChapter = AppUtility.getCurrentChapter(bookId: bookInfo.bookId, chapterInfos: chapterInfos) else {
                return
            }
            
            let pageIndex = currentChapter.startPage + Int(ceil(slider.value))
            
            // 画面の通知を実施する.
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "test"), object: nil)
            
            AppUtility.saveCurrentPage(bookId: bookInfo.bookId, pageIndex: pageIndex)
            
            self.dismiss(animated: true, completion: nil)
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }<commit_msg>content<commit_after>//
//  SettingController.swift
//  MyReader
//
//  Created by RN-079 on 2017/03/08.
//  Copyright © 2017年 RN-079. All rights reserved.
//

import UIKit

class SettingController: ViewController {
    @IBOutlet weak var topView: UIView!
    @IBOutlet weak var backBtn: UIButton!
    @IBOutlet weak var titleLbl: UILabel!
    @IBOutlet weak var bottomView : UIView!
    @IBOutlet weak var chapterLbl: UILabel!
    @IBOutlet weak var preBtn: UIButton!
    @IBOutlet weak var nextBtn: UIButton!
    @IBOutlet weak var slider: UISlider!
    @IBOutlet weak var listBtn: UIButton!
    @IBOutlet weak var bookmarkBtn: UIButton!
    @IBOutlet weak var lightBtn: UIButton!
    @IBOutlet weak var fontBtn: UIButton!
    @IBOutlet weak var addBookmarkBtn: UIButton!
    
    // params.
    var bookInfo : LocalBookInfo!
    var chapterInfos = [ChapterInfo]()
    var pageContents = [NSMutableAttributedString]()
    
    @IBAction func doClose() {
        self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
    }
    
    @IBAction func doAddBookmark() {
        let storyboard = UIStoryboard(name: "AddBookmark", bundle: nil)
        guard let next = storyboard.instantiateInitialViewController() as? AddBookmarkController else {
            return
        }
        
        next.bookId = bookInfo.bookId
        let pageNumber = AppUtility.getCurrentPage(bookId: bookInfo.bookId)
        next.pageNumber = pageNumber
        next.content = self.pageContents[pageNumber].string
        
        self.present(next, animated: true, completion: nil)
    }
    
    @IBAction func doShowChapters() {
        let storyboard = UIStoryboard(name: "Chapter", bundle: nil)
        guard let next = storyboard.instantiateInitialViewController() as? NavigationController else {
            return
        }
        
        guard let chapterController = next.viewControllers.first as? ChapterController else {
            return
        }
        
        chapterController.chapterInfos = self.chapterInfos
        self.present(next, animated: true, completion: nil)
    }
    
    @IBAction func doShowBookmarks() {
        let storyboard = UIStoryboard(name: "Bookmark", bundle: nil)
        guard let next = storyboard.instantiateInitialViewController() else {
            return
        }
        
        self.present(next, animated: true, completion: nil)
    }
    
    @IBAction func itemSlider(slider: UISlider, event: UIEvent) {
        guard let touch = event.allTouches?.first else {return}
        if (touch.phase != .moved && touch.phase != .began) {
            guard let currentChapter = AppUtility.getCurrentChapter(bookId: bookInfo.bookId, chapterInfos: chapterInfos) else {
                return
            }
            
            let pageIndex = currentChapter.startPage + Int(ceil(slider.value))
            AppUtility.saveCurrentPage(bookId: bookInfo.bookId, pageIndex: pageIndex)
            
            // 画面の通知を実施する.
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "test"), object: nil)
            self.dismiss(animated: true, completion: nil)
        }
        
//        guard let touch = event.allTouches?.first else {return}
//        if (touch.phase != .moved && touch.phase != .began) {
//            guard let currentChapter = AppUtility.getCurrentChapter(bookId: bookInfo.bookId, chapterInfos: chapterInfos) else {
//                return
//            }
//            
//            let pageIndex = currentChapter.startPage + Int(ceil(slider.value))
//            
//            // 画面の通知を実施する.
//            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "test"), object: nil)
//            
//            AppUtility.saveCurrentPage(bookId: bookInfo.bookId, pageIndex: pageIndex)
//            
//            self.dismiss(animated: true, completion: nil)
//        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
{'fraction_non_alphanumeric': 0.09165105699759166, 'fraction_numerical': 0.004816697886004816, 'mean_word_length': 2.374717832957111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263885', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2105, 'n_words': 516}