(unless (string-equal system-type "android")
  (unless (string-equal user-login-name "3055822")

    (require 'org-capture)

    (defun findread ()
      "Find or create heading for read books"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** read" nil t))
          (if (not (search-forward "* books" nil t))
              (progn
                (goto-char (point-max))
                (insert "* books\n** read"))
            (insert "\n** read"))))

    (defun findacquired ()
      "Find or create heading for acquired books"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** obtained" nil t))
          (if (not (search-forward "* books" nil t))
              (progn
                (goto-char (point-max))
                (insert "* books\n** obtained"))
            (insert "\n** obtained"))))

    (defun findreading ()
      "Find or create heading for reading progress"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** progress" nil t))
          (if (not (search-forward "* books" nil t))
              (progn
                (goto-char (point-max))
                (insert "* books\n** progress"))
            (insert "\n** progress"))))

    (defun findbeaten ()
      "Find or create heading for beaten games"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** beaten" nil t))
          (if (not (search-forward "* games" nil t))
              (progn
                (goto-char (point-max))
                (insert "* games\n** beaten"))
            (insert "\n** beaten"))))

    (defun findhundred ()
      "Find or create heading for completed games"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** completed" nil t))
          (if (not (search-forward "* games" nil t))
              (progn
                (goto-char (point-max))
                (insert "* games\n** completed"))
            (insert "\n** completed"))))

    (defun findobtained ()
      "Find or create heading for acquired games"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** acquired" nil t))
          (if (not (search-forward "* games" nil t))
              (progn
                (goto-char (point-max))
                (insert "* games\n** acquired"))
            (insert "\n** acquired"))))

    (defun findgaming ()
      "Find or create heading for gaming progress"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** gameplay" nil t))
          (if (not (search-forward "* games" nil t))
              (progn
                (goto-char (point-max))
                (insert "* games\n** gameplay"))
            (insert "\n** gameplay"))))

    (defun findwatched ()
      "Find or create heading for watched films"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** watched" nil t))
          (if (not (search-forward "* films" nil t))
              (progn
                (goto-char (point-max))
                (insert "* films\n** watched"))
            (insert "\n** watched"))))

    (defun findvisited ()
      "Find or create heading for visited places"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "** visited" nil t))
          (if (not (search-forward "* places" nil t))
              (progn
                (goto-char (point-max))
                (insert "* places\n** visited"))
            (insert "\n** visited"))))

    (defun findweb ()
      "Find or create heading for website posts"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "* post" nil t))
          (progn
            (goto-char (point-max))
            (insert "* post"))))

    (defun therating ()
      "Rate some media"
      (setq therating nil)
      (setq ratingreturn "")
      (setq therating (completing-read "Rating: " '("1" "2" "3" "4" "5")))
      (when (equal therating "1")
        (setq ratingreturn " and rated ★"))
      (when (equal therating "2")
        (setq ratingreturn " and rated ★★"))
      (when (equal therating "3")
        (setq ratingreturn " and rated ★★★"))
      (when (equal therating "4")
        (setq ratingreturn " and rated ★★★★"))
      (when (equal therating "5")
        (setq ratingreturn " and rated ★★★★★"))
      ratingreturn)

    (defun theworkbook ()
      "Mark a book as work-related"
      (setq workbookreturn "")
      (setq queryworkbook (y-or-n-p "Work-related?"))
      (if queryworkbook
          (setq workbookreturn " :work:"))
      workbookreturn)

    (defun thevisitdate ()
      "Add dates for a visit"
      (setq visitreturn "")
      (setq visitstart (read-string "Start date (YYYY-MM-DD): " ))
      (unless (equal visitstart "")
        (setq visitend (read-string "End date (YYYY-MM-DD): " ))
        (setq visitreturn (concat " <" visitstart ">--<" visitend ">")))
      visitreturn)

    (defun findperf ()
      "Find or create heading for performances"
      (filedate)
      (goto-char (point-min))
      (if (not (search-forward "* performances" nil t))
          (progn
            (goto-char (point-max))
            (insert "* performances"))))

    (defun setensemble ()
      "Get the ensemble performed with"
      (setq ensembles (s-split "\n" (f-read "~/Documents/drive/admin/emacs/ensembles.txt") t))
      (setq theensemble (completing-read "Ensemble: " ensembles))
      theensemble)

    (defun setvenue ()
      "Get the venue where a performance happened"
      (setq venues (s-split "\n" (f-read "~/Documents/drive/admin/emacs/venues.txt") t))
      (setq thevenue (completing-read "Venue: " venues))
      thevenue)

    (defun setconsole ()
      "Get the console a game is played on"
      (setq consoles (s-split "\n" (f-read "~/Documents/drive/admin/emacs/consoles.txt") t))
      (setq theconsole (completing-read "Console: " consoles))
      theconsole)

    (defun bookcalc ()
      "Read in or calculate position in book"
      (setq ispageno (y-or-n-p "Calculate percentage from page number?"))
      (if ispageno
          (progn
            (setq reachedpage (string-to-number (concat (read-string "Page reached: ") ".0")))
            (setq totalpages (string-to-number (concat (read-string "Total pages: ") ".0")))
            (setq bookprogress (number-to-string (truncate (* 100 (/ reachedpage totalpages))))))
        (setq bookprogress (read-string "Progress (%): ")))
      (setq returnprogress (concat "*" bookprogress "%.* "))
      returnprogress)
    
    (setq org-default-notes-file (concat "~/Documents/drive/org/journal/" (format-time-string "%Y/%m/%Y-%m-%d") ".org"))
    
    (setq org-capture-templates
          '(("a" "Acquired book" entry
             (file+function "" findacquired)
             "* %^{Author} /%^{Title}/ (%^{Acquisition method})%(theworkbook)"
             :jump-to-captured t)
            ("b" "Finished book" entry
             (file+function "" findread)
             "* %^{Author} /%^{Title}/%(therating)%(theworkbook)"
             :jump-to-captured t)
            ("f" "Watched film" entry
             (file+function "" findwatched)
             "* %^{Title} (%^{Year})%(therating)"
             :jump-to-captured t)
            ("g" "Beat game" entry
             (file+function "" findbeaten)
             "* %^{Title} (%setconsole)"
             :jump-to-captured t)
            ("m" "Musical performance" entry
             (file+function "" findperf)
             "* %(setensemble)\n** %^{Performance name} (%(setvenue))\n%?"
             :jump-to-captured t)
            ("n" "Gameplay progress" entry
             (file+function "" findgaming)
             "* %^{Title} (%(setconsole))\n%?"
             :jump-to-captured t)
            ("o" "Obtained game" entry
             (file+function "" findobtained)
             "* %^{Title} (%(setconsole))"
             :jump-to-captured t)
            ("p" "Visited place" entry
             (file+function "" findvisited)
             "* %^{Place}%(thevisitdate)"
             :jump-to-captured t)
            ("r" "Reading progress" entry
             (file+function "" findreading)
             "* %^{Author} /%^{Title}/%(theworkbook)\n%(bookcalc)%?"
             :jump-to-captured t)
            ("w" "Website post" entry
             (file+function "" findweb)
             "* %^{Title}\n%?"
             :jump-to-captured t)
            ("1" "Completed game" entry
             (file+function "" findhundred)
             "* %^{Title} (%setconsole)"
             :jump-to-captured t)))

    (global-set-key (kbd "C-c c") #'org-capture)))