Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5549d08 authored by Jules Casteran's avatar Jules Casteran
Browse files

store Leon answer in class and remove dependency

parent b936b7fd
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -43,5 +43,4 @@ dependencies {
    // To create custom view
    implementation "com.xwray:groupie:2.1.0"

    implementation("org.jsoup:jsoup:1.11.3")
}
+7 −8
Original line number Diff line number Diff line
@@ -13,13 +13,12 @@ import io.socket.client.Socket
import io.socket.emitter.Emitter
import kotlinx.android.synthetic.main.activity_chat.*
import org.json.JSONObject
import org.jsoup.Jsoup

class ChatActivity : AppCompatActivity() {

    private val adapter = GroupAdapter<ViewHolder>()
    private var list = ArrayList<String>()
    private var socket: Socket = IO.socket("http://192.168.0.14:1337")
    private var socket: Socket = IO.socket("http://192.168.1.30:1337")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
@@ -40,13 +39,13 @@ class ChatActivity : AppCompatActivity() {
        })

        socket.on("answer", Emitter.Listener {  args ->
            var headers:String = args[0].toString()
            var resp: LeonMessage
            if (args.size == 1 && args[0] is JSONObject)
                resp = LeonMessage(args[0] as JSONObject)
            else
                resp = LeonMessage("Invalid response", "none")

            headers = Jsoup.parse(headers).text();
            Log.d("ChatActivity", "${headers}")

            // Adding HARDCODE text
            list.add(headers)
            list.add(resp.msg)

            // Adding text to RecyclerView on UI
            runOnUiThread {
+23 −0
Original line number Diff line number Diff line
package com.poc.leonapp

import org.json.JSONException
import org.json.JSONObject
import java.lang.Exception

class LeonMessage {
    var msg: String
    var action: String
    constructor(obj: JSONObject) {
        try {
            msg = obj.getString("msg")
            action = obj.getString("action")
        } catch (e: JSONException) {
            msg = "Response not valid"
            action = ""
        }
    }
    constructor(msg: String, action: String) {
        this.msg = msg
        this.action = action
    }
}
 No newline at end of file