Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

bugfix for offline game #356

Merged
merged 1 commit into from
May 27, 2022
Merged
Changes from all commits
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
27 changes: 15 additions & 12 deletions app/src/main/java/ch/sdp/vibester/fragment/GameSetupFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,22 @@ class GameSetupFragment : Fragment(R.layout.fragment_layout_game_setup), Adapter
* @param uri: contains all Lastfm query parameters (method, artist, tag)
*/
private fun setGameSongList(uri: LastfmUri, playOffline: Boolean = false) {
val service = LastfmApiInterface.createLastfmService()
val call = service.getSongList(uri.convertToHashmap())
call.enqueue(object : Callback<Any> {
override fun onFailure(call: Call<Any>, t: Throwable?) {}
override fun onResponse(call: Call<Any>, response: Response<Any>) {

val external = vmGameSetup.ctx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
if (external != null) {
gameManager.setOffline(external, !playOffline)
}
gameManager.setGameSongList(Gson().toJson(response.body()), uri.method)
if (playOffline) {
val external = vmGameSetup.ctx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
if (external != null) {
gameManager.setOffline(external, !playOffline)
gameManager.setGameSongList(Gson().toJson(""), uri.method)
}
})
} else {
val service = LastfmApiInterface.createLastfmService()
val call = service.getSongList(uri.convertToHashmap())
call.enqueue(object : Callback<Any> {
override fun onFailure(call: Call<Any>, t: Throwable?) {}
override fun onResponse(call: Call<Any>, response: Response<Any>) {
gameManager.setGameSongList(Gson().toJson(response.body()), uri.method)
}
})
}
}

/**
Expand Down