Skip to content

Commit

Permalink
fix: Events are executed by the IO threads
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Nov 26, 2024
1 parent afee6e5 commit d8015aa
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class UIInteractionTests {
private const val EXTOLE_APP_PACKAGE = "com.extole"
private const val LAUNCH_TIMEOUT = 5000L
private val WAIT_FOR_ELEMENT_TIMEOUT = TimeUnit.SECONDS.toMillis(30L)

}

private lateinit var uiDevice: UiDevice
Expand Down Expand Up @@ -105,7 +104,7 @@ class UIInteractionTests {
@Test
fun testNativeSharingUsingEvents() {
val customMenuItem =
uiDevice.findObject(UiSelector().resourceId("$EXTOLE_APP_PACKAGE:id/menu_item"))
uiDevice.findObject(UiSelector().resourceId("$EXTOLE_APP_PACKAGE:id/native_share"))
customMenuItem.waitForExists(WAIT_FOR_ELEMENT_TIMEOUT)
customMenuItem.click()

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/extole/mobile/SdkActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SdkActivity : AppCompatActivity() {
}
ctaZone?.viewed()

findViewById<Button>(R.id.menu_item).setOnClickListener {
findViewById<Button>(R.id.native_share).setOnClickListener {
GlobalScope.launch {
ctaZone?.tap()
}
Expand Down
156 changes: 82 additions & 74 deletions app/src/main/res/layout/activity_sdk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@
tools:context="com.extole.mobile.SdkActivity">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/email"
tools:ignore="SpeakableTextPresentCheck" />
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
tools:ignore="SpeakableTextPresentCheck" />

<Button
android:text="Identify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/identify"
android:textColor="#000000" />
android:id="@+id/identify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Identify"
android:textColor="#000000" />

<TextView
android:text="Share link:...."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/share_link" />
android:id="@+id/share_link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Share link:...." />

<Button
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="..."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/apply_for_card" />
android:id="@+id/apply_for_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="..."
android:textColor="@android:color/black" />

<Button
android:id="@+id/menu_item"
Expand All @@ -53,65 +53,73 @@
android:text="Logout"
android:textColor="@android:color/black" />

<Button
android:id="@+id/native_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="Native Share"
android:textColor="@android:color/black" />

<ImageView
android:layout_width="match_parent"
android:layout_height="169dp"
android:id="@+id/share_image" />
android:id="@+id/share_image"
android:layout_width="match_parent"
android:layout_height="169dp" />

<EditText
android:background="@android:color/white"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/email_address"
android:hint="Enter email"
android:minHeight="48dp" />
android:id="@+id/email_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:ems="10"
android:hint="Enter email"
android:inputType="textEmailAddress"
android:minHeight="48dp"
android:textColor="@android:color/black" />

<EditText
android:background="@android:color/white"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="104dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/email_message"
android:hint="Share message"
android:lines="8"
android:minLines="6"
android:gravity="top|left"
android:maxLines="10"
android:scrollbars="vertical"
android:singleLine="false" />
android:id="@+id/email_message"
android:layout_width="match_parent"
android:layout_height="104dp"
android:background="@android:color/white"
android:ems="10"
android:gravity="top|left"
android:hint="Share message"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="10"
android:minLines="6"
android:scrollbars="vertical"
android:singleLine="false"
android:textColor="@android:color/black" />

<Button
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="Email Share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/email_share" />
android:id="@+id/email_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="Email Share"
android:textColor="@android:color/black" />

<TextView
android:text="..."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/copyright" />
android:id="@+id/copyright"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="..." />

<Button
android:text="Open Main View"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_view" />
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open Main View" />

<EditText
android:layout_width="match_parent"
android:layout_height="110dp"
android:inputType="textMultiLine"
android:gravity="start|top"
android:ems="10"
android:id="@+id/deeplink_text" />
android:id="@+id/deeplink_text"
android:layout_width="match_parent"
android:layout_height="110dp"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine" />
</LinearLayout>

</ScrollView>
21 changes: 6 additions & 15 deletions mobile-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 34
versionCode 53
versionName "1.0.55"
versionCode 54
versionName "1.0.56"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -60,25 +60,16 @@ dependencies {
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.20")
//noinspection GradleDependency
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9', optional
embed('com.google.code.gson:gson:2.9.0') {
exclude(group:'androidx.annotation', module:'annotation')
}
embed('org.greenrobot:eventbus:3.3.1') {
exclude(group:'androidx.annotation', module:'annotation')
}
embed('com.orhanobut:logger:2.2.0') {
exclude(group:'androidx.annotation', module:'annotation')
}
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.greenrobot:eventbus:3.3.1'

api 'com.orhanobut:logger:2.2.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'org.assertj:assertj-core:3.21.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
}

fataar {
transitive = true
}

dokkaHtml.configure {
dokkaSourceSets {
named("main") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.extole.android.sdk.impl.app

import com.extole.android.sdk.impl.ExtoleInternal
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.util.LinkedList
Expand All @@ -24,8 +26,8 @@ object App {
}
while (eventCanBeProcessed(appEvent)) {
val queuedEvent = eventsQueue.poll()
runBlocking {
extole.getLogger().debug("Received event $queuedEvent")
extole.getLogger().debug("Received event $queuedEvent")
CoroutineScope(Dispatchers.IO).launch {
if (queuedEvent != null) {
AppEngine(extole.getOperations()).execute(queuedEvent, extole)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.extole.android.sdk.Operation
import com.extole.android.sdk.impl.ExtoleInternal

class OperationImpl(
private val conditions: List<Condition>,
private val actions: List<Action>
private val conditions: List<Condition>?,
private val actions: List<Action>?
) : Operation {

override suspend fun executeActions(event: AppEvent, extole: ExtoleInternal) {
Expand All @@ -25,19 +25,19 @@ class OperationImpl(
event: AppEvent,
extole: ExtoleInternal
): List<Condition> {
return conditions.filter { it.passes(event, extole) }
return conditions?.filter { it.passes(event, extole) }.orEmpty()
}

override fun actionsToExecute(event: AppEvent, extole: ExtoleInternal): List<Action> {
if (passingConditions(event, extole).size == conditions.size) {
return actions
if (passingConditions(event, extole).size == conditions?.size) {
return actions.orEmpty()
}
return emptyList()
}

override fun getActions(): List<Action> = actions
override fun getActions(): List<Action> = actions.orEmpty()

override fun getConditions(): List<Condition> = conditions
override fun getConditions(): List<Condition> = conditions.orEmpty()

override fun toString(): String {
return "Operation Conditions: $conditions, Actions: $actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import com.extole.android.sdk.Action.ActionType.PROMPT
import com.extole.android.sdk.impl.ExtoleInternal
import com.extole.android.sdk.impl.app.AppEvent
import com.google.gson.annotations.SerializedName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

data class PromptAction(@SerializedName("message") val message: String) : Action {

override suspend fun execute(event: AppEvent, extole: ExtoleInternal) {
extole.getLogger().debug("ActionPrompt executor, message=$message")
Toast.makeText(
extole.getContext().getAppContext(),
message,
Toast.LENGTH_LONG
).show()
CoroutineScope(Dispatchers.Main).launch {
Toast.makeText(
extole.getContext().getAppContext(),
message,
Toast.LENGTH_LONG
).show()
}
}

override fun getType(): Action.ActionType = PROMPT
Expand Down

0 comments on commit d8015aa

Please sign in to comment.