Skip to content

Commit

Permalink
fix(PresetFragment): keep field name for json serialization from 0.2.7
Browse files Browse the repository at this point in the history
See #110 for details
  • Loading branch information
ashutoshgngwr committed Mar 29, 2020
1 parent f3d3707 commit 4b34687
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.github.ashutoshgngwr.noice.sound.PlaybackControlEvents
import com.google.android.material.snackbar.Snackbar
import com.google.gson.GsonBuilder
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import kotlinx.android.synthetic.main.fragment_preset_list.view.*
import kotlinx.android.synthetic.main.layout_list_item__preset.view.*
import org.greenrobot.eventbus.EventBus
Expand Down Expand Up @@ -163,7 +164,12 @@ class PresetFragment : Fragment() {
}
}

data class Preset(@Expose var name: String, @Expose val playbackStates: Array<Playback>) {
// curious about the weird serialized names? see https://github.com/ashutoshgngwr/noice/issues/110
// and https://github.com/ashutoshgngwr/noice/pulls/117
data class Preset(
@Expose @SerializedName("a") var name: String,
@Expose @SerializedName("b") val playbackStates: Array<Playback>
) {

init {
playbackStates.sortBy { T -> T.soundKey }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.google.android.exoplayer2.upstream.DataSource
import com.google.gson.*
import com.google.gson.annotations.Expose
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import java.lang.reflect.Type
import kotlin.random.Random.Default.nextInt

Expand Down Expand Up @@ -70,19 +71,23 @@ class Playback(

}


// curious about the weird serialized names? see https://github.com/ashutoshgngwr/noice/issues/110
// and https://github.com/ashutoshgngwr/noice/pulls/117
@Expose
@SerializedName("b")
@JsonAdapter(value = VolumeSerializer::class)
var volume = DEFAULT_VOLUME
private set

@Expose
@SerializedName("c")
var timePeriod = DEFAULT_TIME_PERIOD

var isPlaying = false
private set

@Expose
@SerializedName("a")
val soundKey = sound.key

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Expand Down

0 comments on commit 4b34687

Please sign in to comment.