<commit_before>(ns net.nightweb.views
  (:use [neko.ui :only [make-ui]]
        [neko.ui.mapping :only [set-classname!]]
        [neko.threading :only [on-ui]]
        [neko.resource :only [get-string get-resource]]
        [net.nightweb.utils :only [full-size
                                   thumb-size
                                   uri-to-bitmap
                                   path-to-bitmap]]
        [net.nightweb.actions :only [request-files
                                     clear-attachments
                                     show-dialog
                                     show-lost-post-dialog
                                     do-send-post
                                     do-delete-post
                                     do-tile-action
                                     do-save-profile
                                     do-cancel]]
        [nightweb.db :only [limit
                            get-user-data
                            get-post-data
                            get-pic-data
                            get-single-post-data
                            get-single-fav-data
                            get-category-data]]
        [nightweb.formats :only [remove-dupes-and-nils
                                 base32-encode]]
        [nightweb.constants :only [is-me?
                                   slash
                                   get-pic-dir]]))

(set-classname! :scroll-view android.widget.ScrollView)
(set-classname! :frame-layout android.widget.FrameLayout)
(set-classname! :image-view android.widget.ImageView)
(set-classname! :view-pager android.support.v4.view.ViewPager)

(def default-text-size 20)
(def default-tile-width 160)

(defn set-text-size
  [view size]
  (.setTextSize view android.util.TypedValue/COMPLEX_UNIT_DIP size))

(defn make-dip
  [context number]
  (-> (.getResources context)
      (.getDisplayMetrics)
      (.density)
      (* number)
      (int)))

(defn get-pic-path
  [user-hash-bytes image-hash-bytes]
  (when (and user-hash-bytes image-hash-bytes)
    (str (get-pic-dir (base32-encode user-hash-bytes))
         slash
         (base32-encode image-hash-bytes))))

(defn add-last-tile
  [content results]
  (if (> (count results) limit)
    (let [next-page (-> (get content :page)
                        (or 1)
                        (+ 1))]
      (-> results
          (pop)
          (conj (assoc content
                       :title (str (get-string :page) " " next-page)
                       :add-emphasis? true
                       :page next-page))))
    results))

(defn set-grid-view-tiles
  [context content view]
  (let [num-columns (.getNumColumns view)
        width (.getWidth view)
        tile-view-width (if (and (> width 0) (> num-columns 0))
                          (int (/ width num-columns))
                          (make-dip context default-tile-width))
        layout-params (android.widget.AbsListView$LayoutParams.
                                                  tile-view-width
                                                  tile-view-width)]
    (.setAdapter
      view
      (proxy [android.widget.BaseAdapter] []
        (getItem [position] (get content position))
        (getItemId [position] 0)
        (getCount [] (count content))
        (getView [position convert-view parent]
          (let [white android.graphics.Color/WHITE
                not-initialized (nil? convert-view)
                tile-view (if not-initialized
                            (make-ui context
                                     [:frame-layout {}
                                      [:image-view {}]
                                      [:linear-layout {:orientation 1}
                                       [:text-view {:text-color white
                                                    :layout-height 0
                                                    :layout-width :fill
                                                    :layout-weight 1}]
                                       [:text-view {:text-color white}]]])
                            convert-view)
                item (get content position)
                image-view (.getChildAt tile-view 0)
                linear-layout (.getChildAt tile-view 1)
                text-top (.getChildAt linear-layout 0)
                text-bottom (.getChildAt linear-layout 1)]
            (when not-initialized
              (.setScaleType image-view
                             android.widget.ImageView$ScaleType/CENTER_CROP)
              (set-text-size text-top default-text-size)
              (set-text-size text-bottom default-text-size)
              (.setLayoutParams tile-view layout-params)
              (let [pad (make-dip context 5)
                    radius (make-dip context 10)
                    black android.graphics.Color/BLACK]
                (.setPadding linear-layout pad pad pad pad)
                (.setShadowLayer text-top radius 0 0 black)
                (.setShadowLayer text-bottom radius 0 0 black)))
            (when (get item :add-emphasis?)
              (.setTypeface text-top android.graphics.Typeface/DEFAULT_BOLD)
              (.setGravity text-top android.view.Gravity/CENTER_HORIZONTAL))
            (when-not (get item :add-emphasis?)
              (.setTypeface text-top android.graphics.Typeface/DEFAULT)
              (.setGravity text-top android.view.Gravity/LEFT))
            (if-let [background (get item :background)]
              (.setBackgroundResource image-view background)
              (.setBackground image-view nil))
            (let [pic-hash-str (base32-encode (get item :pichash))]
              (.setTag image-view pic-hash-str)
              (.setImageBitmap image-view nil)
              (when pic-hash-str
                (future
                  (let [image-bitmap (-> (get-pic-path (get item :userhash)
                                                       (get item :pichash))
                                         (path-to-bitmap thumb-size))]
                    (on-ui
                      (when (= pic-hash-str (.getTag image-view))
                        (.setImageBitmap image-view image-bitmap)))))))
            (if-let [title (get item :title)]
              (.setText text-top title)
              (.setText text-top (get item :body)))
            (.setText text-bottom (get item :subtitle))
            tile-view))))<commit_msg>Hide subtitle if not used<commit_after>(ns net.nightweb.views
  (:use [neko.ui :only [make-ui]]
        [neko.ui.mapping :only [set-classname!]]
        [neko.threading :only [on-ui]]
        [neko.resource :only [get-string get-resource]]
        [net.nightweb.utils :only [full-size
                                   thumb-size
                                   uri-to-bitmap
                                   path-to-bitmap]]
        [net.nightweb.actions :only [request-files
                                     clear-attachments
                                     show-dialog
                                     show-lost-post-dialog
                                     do-send-post
                                     do-delete-post
                                     do-tile-action
                                     do-save-profile
                                     do-cancel]]
        [nightweb.db :only [limit
                            get-user-data
                            get-post-data
                            get-pic-data
                            get-single-post-data
                            get-single-fav-data
                            get-category-data]]
        [nightweb.formats :only [remove-dupes-and-nils
                                 base32-encode]]
        [nightweb.constants :only [is-me?
                                   slash
                                   get-pic-dir]]))

(set-classname! :scroll-view android.widget.ScrollView)
(set-classname! :frame-layout android.widget.FrameLayout)
(set-classname! :image-view android.widget.ImageView)
(set-classname! :view-pager android.support.v4.view.ViewPager)

(def default-text-size 20)
(def default-tile-width 160)

(defn set-text-size
  [view size]
  (.setTextSize view android.util.TypedValue/COMPLEX_UNIT_DIP size))

(defn make-dip
  [context number]
  (-> (.getResources context)
      (.getDisplayMetrics)
      (.density)
      (* number)
      (int)))

(defn get-pic-path
  [user-hash-bytes image-hash-bytes]
  (when (and user-hash-bytes image-hash-bytes)
    (str (get-pic-dir (base32-encode user-hash-bytes))
         slash
         (base32-encode image-hash-bytes))))

(defn add-last-tile
  [content results]
  (if (> (count results) limit)
    (let [next-page (-> (get content :page)
                        (or 1)
                        (+ 1))]
      (-> results
          (pop)
          (conj (assoc content
                       :title (str (get-string :page) " " next-page)
                       :add-emphasis? true
                       :page next-page))))
    results))

(defn set-grid-view-tiles
  [context content view]
  (let [num-columns (.getNumColumns view)
        width (.getWidth view)
        tile-view-width (if (and (> width 0) (> num-columns 0))
                          (int (/ width num-columns))
                          (make-dip context default-tile-width))
        layout-params (android.widget.AbsListView$LayoutParams.
                                                  tile-view-width
                                                  tile-view-width)]
    (.setAdapter
      view
      (proxy [android.widget.BaseAdapter] []
        (getItem [position] (get content position))
        (getItemId [position] 0)
        (getCount [] (count content))
        (getView [position convert-view parent]
          (let [white android.graphics.Color/WHITE
                not-initialized (nil? convert-view)
                tile-view (if not-initialized
                            (make-ui context
                                     [:frame-layout {}
                                      [:image-view {}]
                                      [:linear-layout {:orientation 1}
                                       [:text-view {:text-color white
                                                    :layout-height 0
                                                    :layout-width :fill
                                                    :layout-weight 1}]
                                       [:text-view {:text-color white}]]])
                            convert-view)
                item (get content position)
                image-view (.getChildAt tile-view 0)
                linear-layout (.getChildAt tile-view 1)
                text-top (.getChildAt linear-layout 0)
                text-bottom (.getChildAt linear-layout 1)]
            (when not-initialized
              (.setScaleType image-view
                             android.widget.ImageView$ScaleType/CENTER_CROP)
              (set-text-size text-top default-text-size)
              (set-text-size text-bottom default-text-size)
              (.setLayoutParams tile-view layout-params)
              (let [pad (make-dip context 5)
                    radius (make-dip context 10)
                    black android.graphics.Color/BLACK]
                (.setPadding linear-layout pad pad pad pad)
                (.setShadowLayer text-top radius 0 0 black)
                (.setShadowLayer text-bottom radius 0 0 black)))
            (when (get item :add-emphasis?)
              (.setTypeface text-top android.graphics.Typeface/DEFAULT_BOLD)
              (.setGravity text-top android.view.Gravity/CENTER_HORIZONTAL))
            (when-not (get item :add-emphasis?)
              (.setTypeface text-top android.graphics.Typeface/DEFAULT)
              (.setGravity text-top android.view.Gravity/LEFT))
            (if-let [background (get item :background)]
              (.setBackgroundResource image-view background)
              (.setBackground image-view nil))
            (let [pic-hash-str (base32-encode (get item :pichash))]
              (.setTag image-view pic-hash-str)
              (.setImageBitmap image-view nil)
              (when pic-hash-str
                (future
                  (let [image-bitmap (-> (get-pic-path (get item :userhash)
                                                       (get item :pichash))
                                         (path-to-bitmap thumb-size))]
                    (on-ui
                      (when (= pic-hash-str (.getTag image-view))
                        (.setImageBitmap image-view image-bitmap)))))))
            (if-let [title (get item :title)]
              (.setText text-top title)
              (.setText text-top (get item :body)))
            (if-let [subtitle (get item :subtitle)]
              (.setText text-bottom subtitle)
              (.setVisibility text-bottom android.view.View/GONE))
            tile-view))))
{'fraction_non_alphanumeric': 0.10289240262244505, 'fraction_numerical': 0.005090628615503278, 'mean_word_length': 1.1541784349559727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678393', 'n_tokens_mistral': 3410, 'n_tokens_neox': 3182, 'n_words': 723}