-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5cb647
commit 5236326
Showing
14 changed files
with
164 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/gmail/miloszwasacz/tictactoe9x9/EchoWebSocketListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.gmail.miloszwasacz.tictactoe9x9 | ||
|
||
import android.util.Log | ||
import com.google.gson.Gson | ||
import okhttp3.Response | ||
import okhttp3.WebSocket | ||
import okhttp3.WebSocketListener | ||
|
||
|
||
class EchoWebSocketListener(private val viewModel: CommunicationViewModel, private val room: String): WebSocketListener() { | ||
override fun onOpen(webSocket: WebSocket, response: Response) { | ||
val packet = Gson().toJson(PacketJON(params = ParamsJON(room), time = (System.currentTimeMillis()/1000L).toInt())) | ||
webSocket.send(packet) | ||
} | ||
|
||
override fun onMessage(webSocket: WebSocket, text: String) { | ||
val task = InterpretationTask(viewModel, text) | ||
viewModel.interpretationTaskList.add(task) | ||
task.execute() | ||
//Log.i("Receiving", text) | ||
} | ||
|
||
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { | ||
webSocket.close(viewModel.NORMAL_CLOSURE_STATUS, null) | ||
Log.i("Closing", "$code / $reason") | ||
} | ||
|
||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { | ||
Log.i("Error", t.message) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/gmail/miloszwasacz/tictactoe9x9/InterpretationTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.gmail.miloszwasacz.tictactoe9x9 | ||
|
||
import android.os.AsyncTask | ||
import android.util.Log | ||
|
||
class InterpretationTask(private val viewModel: CommunicationViewModel, private val inputPacket: String): AsyncTask<Void, Void?, Packet>() { | ||
|
||
override fun doInBackground(vararg arg0: Void): Packet { | ||
return if(!isCancelled) { | ||
viewModel.deserializePacketFromServer(inputPacket) | ||
} | ||
else PacketBadErrDbgUin(method = "DBG", params = ParamsBadErrDbgUin("Task cancelled"), time = (System.currentTimeMillis()/1000L).toInt()) | ||
} | ||
|
||
override fun onPostExecute(resultPacket: Packet) { | ||
if(!isCancelled) { | ||
when(resultPacket) { | ||
//Odbieranie planszy | ||
is PacketSTT -> { | ||
viewModel.dialogId.value = Event(viewModel.removeDialog) | ||
viewModel.currentGameState.value = Event(viewModel.createBoardState(resultPacket)) | ||
} | ||
//Wysłanie odpowiedzi na pakiet "PNG" | ||
is PacketGetPngPog -> { | ||
if(resultPacket.method == "PNG") { | ||
viewModel.sendPOG() | ||
} | ||
} | ||
//Wyświetlanie info o oprogramowaniu | ||
is PacketVER -> { | ||
viewModel.versionPacket = resultPacket | ||
viewModel.dialogId.value = Event(viewModel.versionDialogId) | ||
} | ||
//Zapisywanie błędów itp. w Log'u | ||
else -> { | ||
Log.i("packetMSG", (resultPacket as PacketBadErrDbgUin).params.msg) | ||
} | ||
} | ||
} | ||
else { | ||
Log.i("state", (resultPacket as PacketBadErrDbgUin).params.msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.