Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Code Cleanup #12

Merged
merged 10 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
syntax cleanup
  • Loading branch information
aferditamuriqi committed Jul 19, 2018
commit 6e5eb5a81bc70771834783b4cd55a8bccf0e126e
3 changes: 1 addition & 2 deletions r2-shared/src/main/java/org/readium/r2/shared/Properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class Properties : JSONable, Serializable {

override fun getJSON(): JSONObject {
val json = JSONObject()
if (contains.isNotEmpty())
json.put("contains", getStringArray(contains))
if (contains.isNotEmpty()) json.put("contains", getStringArray(contains))
json.putOpt("mediaOverlay", mediaOverlay)
json.putOpt("encryption", encryption)
json.putOpt("layout", layout)
Expand Down
18 changes: 7 additions & 11 deletions r2-shared/src/main/java/org/readium/r2/shared/UserProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import java.io.Serializable
sealed class UserProperty(var ref: String, var name: String) {

private var value: String = ""
get() = this.toString()
get() = this.toString()

abstract override fun toString(): String
fun getJson(): String {
return """{name:"$name",value:"${this}"}"""
Expand All @@ -22,9 +23,7 @@ sealed class UserProperty(var ref: String, var name: String) {

// TODO add here your new Subclasses of UserPreference. It has to be an abstract class inheriting from UserSetting.

class Enumerable(var index: Int, private val values: List<String>, ref: String, name: String) :
UserProperty(ref, name) {

class Enumerable(var index: Int, private val values: List<String>, ref: String, name: String) : UserProperty(ref, name) {
override fun toString() = values[index]
}

Expand All @@ -34,11 +33,10 @@ class Incremental(var value: Float,
private val step: Float,
private val suffix: String,
ref: String,
name: String) :
UserProperty(ref, name) {
name: String) : UserProperty(ref, name) {

fun increment() {
value += (if (value + step <= max) step else 0.0f)
value += (if (value + step <= max) step else 0.0f)
}

fun decrement() {
Expand All @@ -48,9 +46,7 @@ class Incremental(var value: Float,
override fun toString() = value.toString() + suffix
}

class Switchable(onValue: String, offValue: String, var on: Boolean,
ref: String, name: String) :
UserProperty(ref, name) {
class Switchable(onValue: String, offValue: String, var on: Boolean, ref: String, name: String) : UserProperty(ref, name) {

private val values = mapOf(true to onValue, false to offValue)

Expand Down Expand Up @@ -78,7 +74,7 @@ class UserProperties : Serializable {
properties.add(Enumerable(index, values, ref, name))
}

fun <T : UserProperty>getByRef(ref: String) = properties.firstOrNull {
fun <T : UserProperty> getByRef(ref: String) = properties.firstOrNull {
it.ref == ref
}!! as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.io.Serializable

data class Group(val title: String): Serializable {
var metadata: OpdsMetadata = OpdsMetadata(title = title)
var links = mutableListOf<Link>()
var links = mutableListOf<Link>()
var publications = mutableListOf<Publication>()
var navigation = mutableListOf<Link>()

Expand Down