Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-26 18:52:02 +04:00
parent 8971ebef55
commit 96478230a0
9 changed files with 112 additions and 4 deletions

View file

@ -49,6 +49,7 @@ dependencies {
implementation(deps.arrow.core)
implementation(deps.kotlin.immutable.collections)
implementation(deps.timber)
implementation(deps.surveysparrow)
/** Core modules */
implementation(projects.core.datasource)

View file

@ -1,5 +1,6 @@
package com.tangem.feature.tester.presentation
import android.widget.Toast
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@ -17,6 +18,7 @@ import com.tangem.core.navigation.finisher.AppFinisher
import com.tangem.core.ui.UiDependencies
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.screen.ComposeActivity
import com.tangem.datasource.local.config.environment.EnvironmentConfig
import com.tangem.feature.tester.presentation.accounts.ui.AccountsScreen
import com.tangem.feature.tester.presentation.accounts.viewmodel.TesterAccountsViewModel
import com.tangem.feature.tester.presentation.actions.TesterActionsScreen
@ -35,9 +37,10 @@ import com.tangem.feature.tester.presentation.menu.ui.TesterMenuScreen
import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter
import com.tangem.feature.tester.presentation.navigation.TesterScreen
import com.tangem.feature.tester.presentation.providers.ui.BlockchainProvidersScreen
import com.tangem.feature.tester.presentation.providers.viewmodel.BlockchainProvidersViewModel
import com.tangem.feature.tester.presentation.storybook.ui.StoryBookScreen
import com.tangem.feature.tester.presentation.storybook.viewmodel.StoryBookViewModel
import com.tangem.feature.tester.presentation.providers.viewmodel.BlockchainProvidersViewModel
import com.tangem.feature.tester.presentation.surveysparrow.SurveySparrowManager
import com.tangem.feature.tester.presentation.testpush.ui.TestPushScreen
import com.tangem.feature.tester.presentation.testpush.viewmodel.TestPushViewModel
import dagger.hilt.android.AndroidEntryPoint
@ -60,6 +63,9 @@ internal class TesterActivity : ComposeActivity() {
@Inject
lateinit var appRouter: AppRouter
@Inject
lateinit var environmentConfig: EnvironmentConfig
@Composable
override fun ScreenContent(modifier: Modifier) {
val systemBarsColor = TangemTheme.colors.background.secondary
@ -89,6 +95,7 @@ internal class TesterActivity : ComposeActivity() {
ButtonUM.ACCOUNTS,
ButtonUM.ADDRESSES_INFO,
ButtonUM.STORY_BOOK,
ButtonUM.SURVEY_SPARROW,
),
onButtonClick = { buttonUM ->
val route = when (buttonUM) {
@ -101,6 +108,7 @@ internal class TesterActivity : ComposeActivity() {
ButtonUM.ACCOUNTS -> TesterScreen.ACCOUNTS
ButtonUM.ADDRESSES_INFO -> TesterScreen.ADDRESSES_INFO
ButtonUM.STORY_BOOK -> TesterScreen.STORY_BOOK
ButtonUM.SURVEY_SPARROW -> TesterScreen.SURVEY_SPARROW
}
innerTesterRouter.open(route)
@ -192,6 +200,42 @@ internal class TesterActivity : ComposeActivity() {
StoryBookScreen(state)
}
composable(route = TesterScreen.SURVEY_SPARROW.name) {
LaunchedEffect(Unit) {
val isSuccess = startSurveySparrow()
if (isSuccess) {
innerTesterRouter.back()
}
}
}
}
}
private fun startSurveySparrow(): Boolean {
val domain = environmentConfig.surveySparrowDomain
val token = environmentConfig.surveySparrowToken
if (domain.isNullOrEmpty() || token.isNullOrEmpty()) {
val toast = Toast.makeText(
this,
"Survey Sparrow is not configured. Domain or token is missing.",
Toast.LENGTH_LONG,
)
toast.show()
return false
}
SurveySparrowManager(domain = domain, token = token).startSurveyForResult(
activity = this,
requestCode = SURVEY_SPARROW_REQUEST_CODE,
)
return true
}
private companion object {
const val SURVEY_SPARROW_REQUEST_CODE = 1001
}
}

View file

@ -27,5 +27,6 @@ data class TesterMenuUM(
ACCOUNTS(R.string.accounts),
ADDRESSES_INFO(R.string.addresses_info),
STORY_BOOK(R.string.story_book),
SURVEY_SPARROW(R.string.survey_sparrow),
}
}

View file

@ -16,4 +16,5 @@ internal enum class TesterScreen {
ACCOUNTS,
ADDRESSES_INFO,
STORY_BOOK,
SURVEY_SPARROW,
}

View file

@ -0,0 +1,55 @@
package com.tangem.feature.tester.presentation.surveysparrow
import android.app.Activity
import com.surveysparrow.ss_android_sdk.SsSurvey
import com.surveysparrow.ss_android_sdk.SurveySparrow
import timber.log.Timber
/**
* Manager for Survey Sparrow SDK.
*
* @param domain Survey Sparrow domain (e.g., "yourcompany")
* @param token Survey Sparrow SDK token
*/
class SurveySparrowManager(
private val domain: String,
private val token: String,
) {
/**
* Create a SurveySparrow instance to start a survey.
*
* @param activity The activity context
* @param customVariables Optional custom variables to pass to the survey
* @return SurveySparrow instance ready to start
*/
fun createSurvey(activity: Activity, customVariables: Map<String, String>? = null): SurveySparrow? {
return try {
val survey = SsSurvey(domain, token).apply {
customVariables?.forEach { (key, value) ->
addCustomParam(key, value)
}
}
SurveySparrow(activity, survey)
} catch (e: Exception) {
Timber.e(e, "Failed to create SurveySparrow survey")
null
}
}
/**
* Start a survey for result.
*
* @param activity The activity context
* @param requestCode The request code for onActivityResult
* @param customVariables Optional custom variables to pass to the survey
*/
fun startSurveyForResult(activity: Activity, requestCode: Int, customVariables: Map<String, String>? = null) {
val surveySparrow = createSurvey(activity, customVariables)
if (surveySparrow != null) {
surveySparrow.startSurveyForResult(requestCode)
Timber.d("SurveySparrow survey started with requestCode: $requestCode")
}
}
}

View file

@ -23,4 +23,5 @@
<string name="news_details_bottom_sheet" translatable="false">News details (Bottom Sheet)</string>
<string name="addresses_info" translatable="false">Addresses info</string>
<string name="story_book" translatable="false">Story book</string>
<string name="survey_sparrow" translatable="false">Survey Sparrow</string>
</resources>