Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 7.34 KB | None | 0 0
  1. package io.github.ranolp.musikt.view
  2.  
  3. import io.github.ranolp.musikt.controller.MusicPlayerController
  4. import io.github.ranolp.musikt.util.SystemResourceLookup
  5. import io.github.ranolp.musikt.util.javafx.circular
  6. import io.github.ranolp.musikt.util.javafx.icon
  7. import io.github.ranolp.musikt.util.javafx.margin
  8. import io.github.ranolp.musikt.util.javafx.size
  9. import javafx.beans.property.StringProperty
  10. import javafx.geometry.Pos
  11. import javafx.scene.layout.Priority
  12. import javafx.scene.text.FontWeight
  13. import org.kordamp.ikonli.feather.Feather
  14. import org.kordamp.ikonli.ionicons4.Ionicons4IOS
  15. import tornadofx.*
  16.  
  17. class MusicPlayer : View() {
  18.     val controller: MusicPlayerController by inject()
  19.  
  20.     override val root = vbox {
  21.         val root = this
  22.         addClass(Style.realRoot)
  23.  
  24.         imageview {
  25.             vboxConstraints {
  26.                 alignment = Pos.CENTER
  27.             }
  28.             margin(8.px)
  29.  
  30.             isPreserveRatio = true
  31.  
  32.             val hMargin = 16 * 2
  33.             val vMargin = 64 + 40 + 92 + 16 * 3
  34.  
  35.             root.heightProperty().onChange {
  36.                 isVisible = it > vMargin + 64
  37.             }
  38.  
  39.             image = SystemResourceLookup.image("mockup/mockup.png")
  40.  
  41.             managedProperty().bind(visibleProperty())
  42.  
  43.             fitWidthProperty().bind(root.widthProperty().subtract(hMargin))
  44.             fitHeightProperty().bind(root.heightProperty().subtract(vMargin))
  45.  
  46.             isVisible = false
  47.         }
  48.  
  49.         alignment = Pos.BOTTOM_CENTER
  50.  
  51.         hbox {
  52.             margin(8.px)
  53.  
  54.  
  55.             minHeight = 64.0
  56.             button {
  57.                 addClass(Style.bordered)
  58.                 margin(8.px)
  59.                 circular(48)
  60.  
  61.                 icon(Feather.FTH_PLUS)
  62.             }
  63.             vbox {
  64.                 hboxConstraints {
  65.                     hgrow = Priority.ALWAYS
  66.                 }
  67.                 alignment = Pos.CENTER
  68.  
  69.                 label("Ylvis") {
  70.                     style {
  71.                         fontWeight = FontWeight.BLACK
  72.                         fontSize = 20.px
  73.                     }
  74.                 }
  75.  
  76.                 label("The fox") {
  77.                     style {
  78.                         fontWeight = FontWeight.LIGHT
  79.                         fontSize = 12.px
  80.                     }
  81.                 }
  82.             }
  83.             button {
  84.                 addClass(Style.bordered)
  85.                 margin(8.px)
  86.                 circular(48)
  87.  
  88.                 icon(Feather.FTH_ELLIPSIS)
  89.             }
  90.         }
  91.         vbox {
  92.             margin(8.px)
  93.  
  94.             lateinit var currentProperty: StringProperty
  95.             lateinit var maxProperty: StringProperty
  96.  
  97.             hbox {
  98.                 minHeight = 20.0
  99.                 currentProperty = label().textProperty()
  100.  
  101.                 anchorpane {
  102.                     hgrow = Priority.ALWAYS
  103.                 }
  104.  
  105.                 maxProperty = label().textProperty()
  106.             }
  107.             stackpane {
  108.                 val parent = this
  109.  
  110.                 val progress = progressbar(0.0) {
  111.                     addClass(Style.sliderProgressBar)
  112.                     prefWidthProperty().bind(parent.widthProperty().subtract(16))
  113.  
  114.  
  115.                     style = """
  116.                        -fx-accent: ${Style.musiktThemeLight.brighter().css};
  117.                        -fx-control-inner-background: ${Style.papertic.css};
  118.                    """.trimIndent()
  119.  
  120.                 }.progressProperty()
  121.  
  122.                 slider {
  123.                     prefWidthProperty().bind(parent.widthProperty().subtract(16 + 64))
  124.                     minHeight = 20.0
  125.  
  126.                     progress.bind(valueProperty().divide(maxProperty()))
  127.  
  128.                     valueProperty().onChange {
  129.                         val hour = it.toInt() / 60 / 60
  130.                         val minute = (it.toInt() / 60 % 60).toString().padStart(2, '0')
  131.                         val second = (it.toInt() % 60).toString().padStart(2, '0')
  132.                         val label = if (hour > 0) {
  133.                             "${hour.toString().padStart(2, '0')}:$minute:$second"
  134.                         } else {
  135.                             "$minute:$second"
  136.                         }
  137.                         currentProperty.set(label)
  138.                     }
  139.  
  140.                     maxProperty().onChange {
  141.                         val hour = it.toInt() / 60 / 60
  142.                         val minute = (it.toInt() / 60 % 60).toString().padStart(2, '0')
  143.                         val second = (it.toInt() % 60).toString().padStart(2, '0')
  144.                         val label = if (hour > 0) {
  145.                             "${hour.toString().padStart(2, '0')}:$minute:$second"
  146.                         } else {
  147.                             "$minute:$second"
  148.                         }
  149.                         maxProperty.set(label)
  150.                     }
  151.  
  152.                     max = 3 * 60.0 + 25.0
  153.                     value = 60 + 30.0
  154.  
  155.                     style = """
  156.                        -fx-control-inner-background: transparent;
  157.                        -fx-background: null;
  158.                    """.trimIndent()
  159.                 }
  160.             }
  161.         }
  162.         hbox {
  163.             vboxConstraints {
  164.                 alignment = Pos.BOTTOM_CENTER
  165.             }
  166.             margin(8.px)
  167.  
  168.             minHeight = 92.0
  169.  
  170.             hboxConstraints {
  171.                 hgrow = Priority.ALWAYS
  172.             }
  173.             alignment = Pos.CENTER
  174.             button {
  175.                 margin(8.px)
  176.                 size(64.0)
  177.  
  178.                 val btn = icon(Feather.FTH_SHUFFLE)
  179.  
  180.                 action {
  181.                     if (controller.isShuffleModeEnabled) {
  182.                         controller.disableShuffleMode()
  183.                         btn.iconColor = Style.papertic
  184.                     } else {
  185.                         controller.enableShuffleMode()
  186.                         btn.iconColor = Style.greeny
  187.                     }
  188.                 }
  189.             }
  190.             button {
  191.                 margin(8.px)
  192.                 size(76)
  193.  
  194.                 icon(Feather.FTH_SKIP_BACK, 24)
  195.  
  196.             }
  197.             button {
  198.                 addClass(Style.bordered)
  199.  
  200.                 margin(8.px)
  201.                 circular(76)
  202.  
  203.                 val btn = icon(Ionicons4IOS.PLAY, 24)
  204.  
  205.                 action {
  206.                     if (controller.isPlaying) {
  207.                         btn.iconCode = Ionicons4IOS.PLAY
  208.                         controller.pauseSong()
  209.                     } else {
  210.                         btn.iconCode = Ionicons4IOS.PAUSE
  211.                         controller.startSong()
  212.                     }
  213.                 }
  214.             }
  215.             button {
  216.                 margin(8.px)
  217.                 size(76.0)
  218.  
  219.                 icon(Feather.FTH_SKIP_FORWARD, 24)
  220.             }
  221.             button {
  222.                 margin(8.px)
  223.                 size(64.0)
  224.  
  225.                 val btn = icon(Feather.FTH_REPEAT)
  226.  
  227.                 action {
  228.                     if (controller.isRepeatModeEnabled) {
  229.                         controller.disableRepeatMode()
  230.                         btn.iconColor = Style.papertic
  231.                     } else {
  232.                         controller.enableRepeatMode()
  233.                         btn.iconColor = Style.greeny
  234.                     }
  235.                 }
  236.             }
  237.         }
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement