Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Properly mark not downloadable releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerus committed Jan 20, 2019
1 parent 789a5be commit dcdf132
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
60 changes: 43 additions & 17 deletions src/main/xerus/monstercat/downloader/SongView.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package xerus.monstercat.downloader

import javafx.beans.value.ObservableValue
import javafx.scene.control.*
import javafx.collections.ListChangeListener
import javafx.scene.Node
import javafx.scene.control.CheckBox
import javafx.scene.control.CheckBoxTreeItem
import javafx.scene.control.ContextMenu
import javafx.scene.control.Tooltip
import javafx.scene.control.TreeCell
import javafx.scene.control.TreeView
import javafx.scene.control.cell.CheckBoxTreeCell
import javafx.scene.image.Image
import javafx.scene.image.ImageView
Expand All @@ -13,9 +20,15 @@ import xerus.ktutil.javafx.MenuItem
import xerus.ktutil.javafx.controlsfx.FilterableCheckTreeView
import xerus.ktutil.javafx.expandAll
import xerus.ktutil.javafx.onFx
import xerus.ktutil.javafx.properties.*
import xerus.ktutil.javafx.properties.SimpleObservable
import xerus.ktutil.javafx.properties.addOneTimeListener
import xerus.ktutil.javafx.properties.dependOn
import xerus.ktutil.javafx.properties.listen
import xerus.ktutil.javafx.ui.FilterableTreeItem
import xerus.monstercat.api.*
import xerus.monstercat.api.APIConnection
import xerus.monstercat.api.Cache
import xerus.monstercat.api.ConnectValidity
import xerus.monstercat.api.Player
import xerus.monstercat.api.response.MusicItem
import xerus.monstercat.api.response.Release
import xerus.monstercat.api.response.Track
Expand All @@ -29,24 +42,32 @@ class SongView(private val sorter: ObservableValue<ReleaseSorting>) :
val roots = HashMap<String, FilterableTreeItem<MusicItem>>()

private val checkCellFactory: Callback<TreeView<MusicItem>, TreeCell<MusicItem>> = Callback {
CheckBoxTreeCell<MusicItem>().also { cell ->
cell.itemProperty().listen { item ->
if((item as? Release)?.downloadable == false ||
(item is Track && (cell.treeItem.parent.value as? Release)?.downloadable == false)) {
if(cell.tooltip == null) {
cell.styleClass.add("not-downloadable")
cell.tooltip = Tooltip("This Release is currently not downloadable")
}
} else {
if(cell.tooltip != null) {
cell.styleClass.remove("not-downloadable")
cell.tooltip = null
object : CheckBoxTreeCell<MusicItem>() {
var listener = ListChangeListener<Node> { children.filterIsInstance<CheckBox>().firstOrNull()?.isDisable = true }

init {
itemProperty().listen { item ->
if((item as? Release)?.downloadable == false ||
(item is Track && (treeItem.parent.value as? Release)?.downloadable == false)) {
if(tooltip == null) {
listener.onChanged(null)
children.addListener(listener)
styleClass.add("not-downloadable")
tooltip = Tooltip("This Release is currently not downloadable")
}
} else {
if(tooltip != null) {
children.removeListener(listener)
children.filterIsInstance<CheckBox>().firstOrNull()?.isDisable = false
styleClass.remove("not-downloadable")
tooltip = null
}
}
}
}
}
}
private val treeCellFactory: Callback<TreeView<MusicItem>, TreeCell<MusicItem>> = Callback {
private val loadingCellFactory: Callback<TreeView<MusicItem>, TreeCell<MusicItem>> = Callback {
val loadingGif = ImageView(Image("img/loading-16.gif"))
object : TreeCell<MusicItem>() {
init {
Expand Down Expand Up @@ -105,7 +126,7 @@ class SongView(private val sorter: ObservableValue<ReleaseSorting>) :

private fun showRoot(show: Boolean, text: String? = null) {
if(show) {
cellFactory = treeCellFactory
cellFactory = loadingCellFactory
if(text != null)
root.value = RootMusicItem(text)
isShowRoot = true
Expand All @@ -131,7 +152,12 @@ class SongView(private val sorter: ObservableValue<ReleaseSorting>) :
if(notDownloadable < 5)
logger.trace("Not downloadable: $release")
notDownloadable++
treeItem.selectedProperty().listen {
if(it)
treeItem.isSelected = false
}
}

roots.getOrPut(release.type) {
FilterableTreeItem(RootMusicItem(release.type))
}.internalChildren.add(treeItem)
Expand Down
2 changes: 1 addition & 1 deletion src/resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/* highlight non-downloadable releases red */
/*noinspection CssInvalidFunction*/
.tree-cell.not-downloadable {
myText: ladder(#888, -fx-text-background-color, hsb(0, 90%, 100%));
myText: ladder(#444, -fx-text-background-color, hsb(0, 90%, 100%));
}

.button, .button:focused {
Expand Down

0 comments on commit dcdf132

Please sign in to comment.