Skip to content

Commit

Permalink
Merge branch 'master' of github.com:adityapk00/zqwandroid
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Feb 22, 2019
2 parents 05f1504 + 01ec41c commit 2c8c329
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "0.0.3-beta"
versionName "0.0.5-beta5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ object ConnectionManager {

val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build()
val request = Request.Builder().url("wss://wormhole.zecqtwallet.com:443").build()
//val request = Request.Builder().url("ws://192.168.5.187:7070").build()
val listener = WebsocketClient(false)

DataModel.ws = client.newWebSocket(request, listener)
}
}

fun closeConnection() {
DataModel.ws?.close(1000, "Close requested")
}

fun sendRefreshSignal(finished: Boolean) {
val i = Intent(DATA_SIGNAL)
i.putExtra("action", "refresh")
Expand Down Expand Up @@ -134,7 +139,8 @@ object ConnectionManager {
sendErrorSignal(r.displayMsg, r.doDisconnect)

if (r.doDisconnect) {
webSocket?.close(1000, "Peer Error caused disconnect")
// We don't pass a reason here, because we already sent the error signal above
webSocket?.close(1000, null)
}

} else {
Expand All @@ -152,9 +158,9 @@ object ConnectionManager {
println("Connstatus = disconnected")

Log.i(TAG,"Closing : $code / $reason")
if (code == 1001) {
sendErrorSignal(reason, true)
}
//if (!reason.isNullOrEmpty()) {
// sendErrorSignal(reason, true)
//}
sendRefreshSignal(true)
}

Expand All @@ -166,7 +172,14 @@ object ConnectionManager {

// If the connection is direct, and there is no need to further connect, so just error out
if (t is ConnectException && (m_directConn && !allowInternet)) {
sendErrorSignal(t.localizedMessage, true)
var mesg = t.localizedMessage
if (!DataModel.getAllowInternet()) {
mesg += ": Connecting over the internet was not enabled by the desktop node."
} else if (!DataModel.getGlobalAllowInternet()) {
mesg += ": Connecting over the internet is disabled in settings."
}

sendErrorSignal(mesg, true)
sendRefreshSignal(true)
return
}
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/adityapk/zcash/zqwandroid/DataModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ object DataModel {
fun parseResponse(response: String) : ParseResponse {
val json = Parser.default().parse(StringBuilder(response)) as JsonObject

// Check if it has errored out
if (json.containsKey("error")) {
return ParseResponse(false, "Couldn't connect: ${json["error"].toString()}", true)
}

if (json.containsKey("ping")) {
return ParseResponse(false)
}

// Check if input string is encrypted
if (json.containsKey("nonce")) {
val decrypted = decrypt(json["nonce"].toString(), json["payload"].toString())
Expand All @@ -69,11 +78,6 @@ object DataModel {
return parseResponse(decrypted)
}

// Check if it has errored out
if (json.containsKey("error")) {
return ParseResponse(false, "Couldn't connect: ${json["error"].toString()}", true)
}

return when (json.string("command")) {
"getInfo" -> {
mainResponseData = Klaxon().parse<MainResponse>(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,11 @@ class MainActivity : AppCompatActivity(), TransactionItemFragment.OnFragmentInte
updateUI(updateTxns)
}
"error" -> {
val msg = intent.getStringExtra("msg") ?: "Unknown Error"
Snackbar.make(layoutConnect, msg, Snackbar.LENGTH_LONG).show()
val msg = intent.getStringExtra("msg")

if (!msg.isNullOrEmpty()) {
Snackbar.make(layoutConnect, msg, Snackbar.LENGTH_LONG).show()
}

// Also check if we need to disconnect
if (intent.getBooleanExtra("doDisconnect", false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@ class SettingsActivity : AppCompatActivity() {
btnDisconnect.setOnClickListener {
DataModel.setConnString(null, applicationContext)
DataModel.clear()
ConnectionManager.closeConnection()

updateUI()
}

chkDisallowInternet.setOnClickListener {
DataModel.setGlobalAllowInternet(chkDisallowInternet.isChecked)
DataModel.setGlobalAllowInternet(!chkDisallowInternet.isChecked)

if (chkDisallowInternet.isChecked) {
ConnectionManager.closeConnection()
}

updateUI()
}
}

fun updateUI() {
txtSettingsConnString.text = DataModel.getConnString(ZQWApp.appContext!!) ?: "Not Connected"

chkDisallowInternet.isChecked = !DataModel.getGlobalAllowInternet()

lblVersionName.text = BuildConfig.VERSION_NAME
lblServerVersion.text = DataModel.mainResponseData?.serverversion ?: "Not Connected"
}
Expand Down

0 comments on commit 2c8c329

Please sign in to comment.