Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Commit

Permalink
Prevent http hang on main thread. Fix metadata encoding as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondantuma committed Mar 1, 2019
1 parent d97fe86 commit 1fe85d5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import java.util.*
internal data class UnsubscribeEvent(
val subscription_id: Long,
val device_id: String,
val datetime: Date = Date()
val datetime: Date = Date(),
val metadata: Map<String, String> = emptyMap()
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal object SubscriptionEventAdapter : JSONAdapterInterface<SubscriptionEven
.put("contact", ContactDataAdapter.toJson(obj.contact))
.put("platform", PlatformDataAdapter.toJson(obj.platform))
.put("device", DeviceDataAdapter.toJson(obj.device))
.put("metadata", encodeJsonMap(obj.metadata).toString()) // TODO remove .toString()
.put("metadata", encodeJsonMap(obj.metadata))
.put("datetime", Iso8601Utils.format(obj.datetime))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.everlytic.android.pushnotificationsdk.models.jsonadapters

import com.everlytic.android.pushnotificationsdk.database.vendor.Iso8601Utils
import com.everlytic.android.pushnotificationsdk.encodeJsonMap
import com.everlytic.android.pushnotificationsdk.models.UnsubscribeEvent
import org.json.JSONObject

Expand All @@ -18,5 +19,6 @@ internal object UnsubscribeEventAdapter : JSONAdapterInterface<UnsubscribeEvent>
.put("subscription_id", obj.subscription_id)
.put("device_id", obj.device_id)
.put("datetime", Iso8601Utils.format(obj.datetime))
.put("metadata", encodeJsonMap(obj.metadata))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ internal class EverlyticHttp(installUrl: String, apiUsername: String, apiKey: St
connectionThread.start()

try {
connectionThread.join(THREAD_TIMEOUT)
if (connectionThread.state != Thread.State.TERMINATED) {
connectionThread.interrupt()
}
// connectionThread.join(THREAD_TIMEOUT)
// if (connectionThread.state != Thread.State.TERMINATED) {
// connectionThread.interrupt()
// }

callbackThreads.firstOrNull()?.join()
} catch (e: InterruptedException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.text.InputType
import android.widget.EditText
import android.widget.Toast
import com.everlytic.android.pushnotificationsdk.EverlyticPush
import com.everlytic.android.pushnotificationsdk.OnResultReceiver
import kotlinx.android.synthetic.main.activity_sandbox.*

class Sandbox : AppCompatActivity() {
Expand All @@ -23,12 +24,12 @@ class Sandbox : AppCompatActivity() {
}

private fun alert(block: AlertDialog.Builder.() -> Unit) {
runOnUiThread {
// runOnUiThread {
AlertDialog.Builder(this).apply {
setPositiveButton(android.R.string.ok, null)
block()
}.show()
}
// }
}

private fun updateSubscriptionDisplay() {
Expand All @@ -49,7 +50,7 @@ class Sandbox : AppCompatActivity() {
setView(edit)
setPositiveButton(android.R.string.ok) { _, _ ->

EverlyticPush.subscribe(edit.text.toString()) {
EverlyticPush.subscribe(edit.text.toString(), OnResultReceiver {
if (it.isSuccessful) {
alert {
setMessage("Subscribe success!")
Expand All @@ -63,7 +64,7 @@ class Sandbox : AppCompatActivity() {
}

updateSubscriptionDisplay()
}
})
}
}
}
Expand All @@ -75,15 +76,15 @@ class Sandbox : AppCompatActivity() {
setTitle("Unsubscribe contact?")
setMessage("Unsubscribe the current contact from receiving push notifications?")
setPositiveButton(android.R.string.ok) { _, _ ->
EverlyticPush.unsubscribe {
EverlyticPush.unsubscribe( OnResultReceiver{
if (it.isSuccessful) {
alert { setMessage("Contact unsubscribed successfully") }
} else {
alert { setMessage("Failed to unsubscribe contact") }
}

updateSubscriptionDisplay()
}
})
}

setNegativeButton(android.R.string.cancel, null)
Expand Down

0 comments on commit 1fe85d5

Please sign in to comment.