Commit e4b2ce0c authored by Ignamarte's avatar Ignamarte

Fix 422 errors and remove useless imports

parent e6cdc2aa
Pipeline #110872688 passed with stage
in 3 minutes and 12 seconds
package tress
import api.webserver.WebServer
import errors.APIError
import gui.MainWindow
import gui.panels.MainPanel
import gui.widgets.alert.ErrorAlert
import scalafx.application.{JFXApp, Platform}
import util.config.UserConfig
import scalafx.application.JFXApp
object Tress extends JFXApp {
stage = MainWindow
......
......@@ -7,7 +7,6 @@ import util.config.APIConfig
import scala.collection.mutable.ListBuffer
import pureconfig.generic.auto._
import util.config.APIConfig
object RESTClient {
......
package api.types
import api.types.collection.Streams
case class Follow(
from_id: String,
from_name: String,
......
......@@ -2,7 +2,6 @@ package api.types
import api.RESTClient
import api.types.collection.Games
import play.api.libs.json.{Json, Reads}
import scala.collection.mutable
......
......@@ -14,7 +14,7 @@ case class Stream(
started_at: String,
language: String,
thumbnail_url: String,
tag_ids: List[String],
tag_ids: Option[List[String]],
user_login: Option[String]
) {
def getThumbnail(width: Int, height: Int): String = {
......
......@@ -3,7 +3,7 @@ package api.types
import java.time._
import api.RESTClient
import api.types.collection.{Follows, Users}
import api.types.collection.Users
import errors.{APIError, NotLoggedInError}
import play.api.libs.json.{Json, Reads}
......
package api.types.collection
import api.types.Pagination
import api.types.Pagination._
import errors.APIError
import play.api.libs.json._
import play.api.libs.json.Reads._
......
......@@ -4,7 +4,6 @@ import api.RESTClient
import api.types.{Follow, Pagination, User}
import play.api.libs.json.{Json, Reads}
import util.config.APIConfig
import util.config.UserConfig.Config
class Follows(_follows: List[Follow], _cursor: String)
extends APICollection[Follow]{
......@@ -12,8 +11,6 @@ class Follows(_follows: List[Follow], _cursor: String)
def objects: List[Follow] = _follows
def cursor: String = _cursor
private val TWITCH_MAX_ID_PER_REQUEST = APIConfig.getmaxIDCount
override def toString: String = _follows.map(follow => follow.to_name)
.mkString(start=" - ", sep="\n - ", end="" )
......
package api.types.collection
import api.RESTClient
import api.types.{Follow, Game, Pagination}
import api.types.{Game, Pagination}
import play.api.libs.json.{Json, Reads}
class Games(_games: List[Game], _cursor: String) extends APICollection[Game]{
......
package api.types.collection
import api.RESTClient
import api.types.{Follow, Pagination, Stream}
import play.api.libs.json.{Json, OFormat, Reads}
import api.types.{Pagination, Stream}
import play.api.libs.json.{Json, Reads}
/** A list of streams objects
*
......@@ -55,6 +55,6 @@ object Streams extends APICollectionObject[Stream] {
): Streams = {
val result = RESTClient.getTopStreams(gameID, page, users)
val (streams_ , cursor_) = extractFromJson(result._1, result._2)
new Streams(streams_.toList, cursor_)
new Streams(streams_, cursor_)
}
}
package api.types.collection
import api.RESTClient
import api.types.{Game, User}
import api.types.User
import play.api.libs.json.{Json, Reads}
class Users(_users: List[User]) extends APICollection[User]{
......
......@@ -9,7 +9,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
object WebServer {
private var port = 33245
private val port = 33245
private var server: Server = _
def init(): Unit = {
......
......@@ -4,9 +4,6 @@ import api.webserver.WebServer
import errors.APIError
import gui.panels._
import gui.widgets.alert.ErrorAlert
import javafx.beans.property.ObjectProperty
import javafx.event.EventHandler
import javafx.stage.WindowEvent
import org.controlsfx.control.NotificationPane
import scalafx.Includes._
import scalafx.application.JFXApp.PrimaryStage
......
package gui.panels
import api.types.collection.{Follows, Streams, Users}
import api.types.collection.{Follows, Users}
import api.types.{Pagination, User}
import gui.widgets.{StreamCard, UserCard}
import gui.widgets.UserCard
import scalafx.application.Platform
......
package gui.panels
import api.types.collection.{Games, Streams}
import api.types.collection.Games
import api.types.{Game, Pagination}
import gui.widgets.GameCard
import scalafx.application.Platform
......
......@@ -93,7 +93,7 @@ abstract class ListPanel[A](
topMenu.children.clear()
val constraint = new ColumnConstraints()
constraint.setPercentWidth(100/cols)
constraint.percentWidth = 100/cols
constraint.halignment = HPos.Center
grid.columnConstraints = List.fill(cols)(constraint)
topMenu.columnConstraints = List.fill(7)(constraint)
......
package gui.panels
import gui.widgets.control.LoginButton
import scalafx.geometry.Pos
import scalafx.geometry.Pos.Center
import scalafx.scene.control.{Button, Label}
import scalafx.scene.layout.Priority.Always
import scalafx.scene.control.Label
import scalafx.scene.layout.VBox
import util.LoginManager
......
......@@ -3,7 +3,6 @@ package gui.panels
import api.types.User
import errors.NotLoggedInError
import scalafx.application.Platform
import scalafx.scene.control.ProgressIndicator
import scalafx.scene.layout.Pane
trait LoginRequired extends Pane {
......
package gui.panels
import gui.widgets.transitions.FadeIn
import scalafx.geometry.Insets
import scalafx.scene.Node
import scalafx.scene.control.ScrollPane
import scalafx.scene.control.ScrollPane.ScrollBarPolicy.Never
import scalafx.scene.layout.AnchorPane
object MainPanel extends AnchorPane {
......
......@@ -7,7 +7,6 @@ import scalafx.geometry.Pos.Center
import scalafx.scene.Node
import scalafx.scene.control.{Label, ProgressIndicator}
import scalafx.scene.image.{Image, ImageView}
import scalafx.scene.input.MouseButton.Primary
import scalafx.scene.layout.Priority.Always
import scalafx.scene.layout.VBox
......
package gui.widgets
import api.types.{Stream, User}
import api.types.Stream
import errors.StreamLinkMissingError
import gui.MainWindow
import gui.panels.MainPanel
import gui.widgets.alert.ErrorAlert
import gui.widgets.jfx2sfx.{FAGlyphIcon, Overlay}
import gui.widgets.popover.StreamPopover
import gui.widgets.transitions.FadeIn
import javafx.scene.input.MouseButton
import org.controlsfx.control.PopOver
import org.controlsfx.glyphfont.FontAwesome
import scalafx.geometry.Insets
import scalafx.geometry.Pos.Center
import scalafx.scene.control._
import scalafx.scene.image.{Image, ImageView}
import scalafx.scene.layout.Priority.Always
import scalafx.scene.layout.{HBox, Region, VBox}
import util.{Browser, StreamLink}
import util.StreamLink
class StreamCard(stream: Stream, followed: Boolean) extends VBox {
......@@ -25,6 +22,27 @@ class StreamCard(stream: Stream, followed: Boolean) extends VBox {
hgrow = Always
alignment = Center
// Launch the stream
private def launchStream(): Unit = {
// Display a notification to the user the user
MainWindow.displayNotification(
message = f"Now playing: ${stream.user_name}",
new ImageView(image){fitWidth = 50; preserveRatio = true}
)
try {
val message = "It looks like streamlink failed to load your stream."
StreamLink.launch(
stream.user_login.get,
_ => new ErrorAlert(message, _) // Display error on fail
)
} catch {
case _:StreamLinkMissingError => new ErrorAlert(
"StreamLink is missing, please check your configuration.",
"StreamLink binary is missing from the configuration file."
)
}
}
// Stream image
private val image = new Image(stream.getThumbnail(480, 270), true)
......@@ -84,25 +102,7 @@ class StreamCard(stream: Stream, followed: Boolean) extends VBox {
overlay.onMouseClicked = e => {
e.getButton match {
case MouseButton.PRIMARY => {
MainWindow.displayNotification(
f"Now playing: ${stream.user_name}",
new ImageView(image){
fitWidth = 50
preserveRatio = true
}
)
try {
val message = "It looks like streamlink failed to load your stream."
StreamLink.launch(stream.user_login.get, (m: String) =>
new ErrorAlert(message=message, _))
} catch {
case e:StreamLinkMissingError => new ErrorAlert(
"StreamLink is missing, please check your configuration.",
"StreamLink binary is missing from the configuration file."
)
}
}
case MouseButton.PRIMARY => launchStream()
case MouseButton.SECONDARY => contextMenu.show(overlay)
case _ =>
}
......
package gui.widgets
import api.types.User
import org.controlsfx.control.PopOver
import errors.NotLoggedInError
import javafx.scene.input.MouseButton
import javafx.scene.paint.ImagePattern
import scalafx.geometry.Insets
import scalafx.scene.control.Button
import org.controlsfx.control.PopOver
import scalafx.scene.image.Image
import scalafx.scene.layout.Priority.Always
import scalafx.scene.layout.VBox
import scalafx.scene.shape.Circle
import util.LoginManager
class UserAvatar extends Circle {
......
package gui.widgets
import api.types.User
import gui.panels.MainPanel
import gui.widgets.popover.UserPopover
import gui.widgets.transitions.FadeIn
import javafx.scene.input.MouseButton
import scalafx.geometry.Pos.Center
import scalafx.scene.Node
import scalafx.scene.control.{Label, ProgressIndicator}
import scalafx.scene.image.{Image, ImageView}
import scalafx.scene.layout.Priority.Always
......
......@@ -5,7 +5,6 @@ import errors.NotLoggedInError
import gui.panels.{MainPanel, SideMenu}
import org.controlsfx.control.PopOver
import scalafx.geometry.Insets
import scalafx.geometry.Pos.Center
import scalafx.scene.control.Label
import scalafx.scene.layout.Priority.Always
import scalafx.scene.layout.VBox
......
......@@ -12,7 +12,6 @@ class FileDialogButton(
styleClass.add("purple")
private val selectedFile = text
private val fileChooser: FileChooser = new FileChooser{
title = dialogTitle
}
......
package gui.widgets.jfx2sfx
import org.controlsfx.glyphfont.{FontAwesome, Glyph, GlyphFont}
import org.controlsfx.glyphfont.{FontAwesome, Glyph}
import scalafx.scene.Node
import scala.io.Source
class FAGlyphIcon(override val delegate: Glyph = new Glyph)
extends Node(delegate) {
......
package gui.widgets.popover
import api.types.{Stream, User}
import api.types.User
import gui.MainWindow
import gui.panels.MainPanel
import org.controlsfx.control.PopOver
......@@ -55,7 +55,7 @@ abstract class ChannelPopover(followed: Boolean, image: Image) extends PopOver {
text = "Channel Page"
prefWidth <== content.width
onAction = _ => {
val url = f"https://www.twitch.tv/${userLogin}"
val url = f"https://www.twitch.tv/$userLogin"
Browser.openURL(url)
}
}
......@@ -69,11 +69,11 @@ abstract class ChannelPopover(followed: Boolean, image: Image) extends PopOver {
val msg: String = if (followed) {
User.authenticatedUser.unfollow(userID)
MainPanel.displayFollowedPanel()
f"You are not following ${userName} anymore."
f"You are not following $userName anymore."
}
else {
User.authenticatedUser.follow(userID)
f"You are now following ${userName}."
f"You are now following $userName."
}
MainWindow.displayNotification(
msg,
......
package gui.widgets.popover
import api.types.Stream
import errors.APIError
import scalafx.application.Platform
import scalafx.scene.control.{Button, Label, ProgressIndicator}
import scalafx.scene.image.Image
......
package gui.widgets.popover
import api.types.{Stream, User}
import api.types.User
import scalafx.scene.control.Label
import scalafx.scene.image.Image
......
package util
import java.awt.Desktop
// TODO: Do something when browsing isn't supported
object Browser {
......
......@@ -3,10 +3,8 @@ package util
import api.RESTClient
import api.types.User
import api.webserver.WebServer
import errors.APIConfigError
import gui.MainWindow
import gui.panels.{MainPanel, SideMenu}
import pureconfig.generic.auto._
import scalafx.application.Platform
import util.config.APIConfig
......
package util
import api.types.Stream
import errors.StreamLinkMissingError
import scalafx.application.Platform
import util.config.UserConfig
import scala.collection.immutable.ListMap
import scala.sys.process._
import java.io.IOException
object StreamLink {
......@@ -27,7 +25,7 @@ object StreamLink {
)
def getStreamQualities: List[String] = {
qualityExclusion map {case (key, _: Any) => key} toList
qualityExclusion.map({case (key, _: Any) => key}).toList
}
def launch(user_login: String, onRuntimeErrorCallback: String => Unit): Unit = {
......@@ -45,7 +43,7 @@ object StreamLink {
// or the worst of what's been excluded if nothing remains.
val fakeQuality = qualityExclusion.getOrElse(quality, defaultQuality) match {
case `defaultQualityExclusion` => quality
case s:String => "best, worst-unfiltered, best-unfiltered"
case _:String => "best, worst-unfiltered, best-unfiltered"
}
val playerOption = player match {
......
......@@ -91,7 +91,7 @@ class StreamsTest extends FunSuite with PrivateMethodTester {
assert(streams.head.started_at === started_at)
assert(streams.head.language === language)
assert(streams.head.thumbnail_url === thumbnail_url)
assert(streams.head.tag_ids.length === 2)
assert(streams.head.tag_ids.get.length === 2)
assert(cursor === cursor_string)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment