@@ -9,6 +9,8 @@ import android.content.Intent
99import android.os.Bundle
1010import androidx.activity.compose.setContent
1111import androidx.appcompat.app.AppCompatActivity
12+ import androidx.compose.animation.core.Animatable
13+ import androidx.compose.animation.core.spring
1214import androidx.compose.foundation.background
1315import androidx.compose.foundation.border
1416import androidx.compose.foundation.clickable
@@ -34,7 +36,9 @@ import androidx.compose.runtime.*
3436import androidx.compose.runtime.livedata.observeAsState
3537import androidx.compose.ui.Alignment
3638import androidx.compose.ui.Modifier
39+ import androidx.compose.ui.draw.scale
3740import androidx.compose.ui.graphics.Color
41+ import androidx.compose.ui.graphics.graphicsLayer
3842import androidx.compose.ui.platform.LocalContext
3943import androidx.compose.ui.res.stringResource
4044import androidx.compose.ui.text.font.FontWeight
@@ -51,6 +55,7 @@ import androidx.navigation.compose.NavHost
5155import androidx.navigation.compose.composable
5256import androidx.navigation.compose.currentBackStackEntryAsState
5357import androidx.navigation.compose.rememberNavController
58+ import kotlinx.coroutines.launch
5459
5560class MainActivity : AppCompatActivity () {
5661 private lateinit var notificationHandler: NotificationHandler
@@ -91,7 +96,7 @@ fun SampleApp(viewModel: SharedViewModel = viewModel()) {
9196 launchSingleTop = true
9297 }
9398 }
94- MaterialTheme {
99+ MaterialTheme {
95100 Box (
96101 modifier = Modifier
97102 .fillMaxSize()
@@ -115,15 +120,19 @@ fun SampleApp(viewModel: SharedViewModel = viewModel()) {
115120 navigationIcon = {
116121 if (currentDestination?.route != AppRoute .HOME .route) {
117122 IconButton (onClick = { navController.navigateUp() }) {
118- Icon (Icons .AutoMirrored .Filled .ArrowBack , contentDescription = " Back" )
123+ Icon (
124+ Icons .AutoMirrored .Filled .ArrowBack ,
125+ contentDescription = " Back"
126+ )
119127 }
120128 } else {
121129 Box (modifier = Modifier .size(48 .dp))
122130 }
123131 },
124132 actions = {
125133 IconButton (onClick = {
126- val currentRoute = navController.currentBackStackEntry?.destination?.route
134+ val currentRoute =
135+ navController.currentBackStackEntry?.destination?.route
127136 if (currentRoute != null ) {
128137 when (currentRoute) {
129138 AppRoute .HOME .route -> {
@@ -132,6 +141,7 @@ fun SampleApp(viewModel: SharedViewModel = viewModel()) {
132141 launchSingleTop = true
133142 }
134143 }
144+
135145 else -> {
136146 val fragment = when (currentRoute) {
137147 AppRoute .IDENTIFICATION .route -> IdentificationFragment ()
@@ -141,8 +151,13 @@ fun SampleApp(viewModel: SharedViewModel = viewModel()) {
141151 else -> null
142152 }
143153 if (fragment != null ) {
144- val fragmentManager = (context as FragmentActivity ).supportFragmentManager
145- reloadFragment(fragmentManager, fragment, R .id.fragment_container_view)
154+ val fragmentManager =
155+ (context as FragmentActivity ).supportFragmentManager
156+ reloadFragment(
157+ fragmentManager,
158+ fragment,
159+ R .id.fragment_container_view
160+ )
146161 }
147162 }
148163 }
@@ -164,11 +179,15 @@ fun SampleApp(viewModel: SharedViewModel = viewModel()) {
164179}
165180
166181@Composable
167- fun NavHostContainer (paddingValues : PaddingValues , navController : NavHostController , viewModel : SharedViewModel ) {
182+ fun NavHostContainer (
183+ paddingValues : PaddingValues ,
184+ navController : NavHostController ,
185+ viewModel : SharedViewModel
186+ ) {
168187 NavHost (navController, startDestination = AppRoute .HOME .route) {
169188 composable(AppRoute .HOME .route) {
170189 viewModel.resetTitle()
171- HomeComposable (Modifier .padding(paddingValues), navController)
190+ HomeComposable (Modifier .padding(paddingValues), navController, viewModel )
172191 }
173192 composable(AppRoute .IDENTIFICATION .route) {
174193 viewModel.changeTitle(stringResource(R .string.identification))
@@ -190,18 +209,32 @@ fun NavHostContainer(paddingValues: PaddingValues, navController: NavHostControl
190209}
191210
192211@Composable
193- fun HomeComposable (modifier : Modifier = Modifier , navController : NavHostController ) {
212+ fun HomeComposable (
213+ modifier : Modifier = Modifier ,
214+ navController : NavHostController ,
215+ viewModel : SharedViewModel
216+ ) {
194217 val isConfigured by remember { mutableStateOf(DevRev .isConfigured) }
195218 val isUserIdentified by remember { mutableStateOf(DevRev .isUserIdentified) }
196219 val isMonitoringEnabled by remember { mutableStateOf(DevRev .isMonitoringEnabled) }
220+ val scale = remember { Animatable (1f ) }
221+ val coroutineScope = rememberCoroutineScope()
197222
198223 val buttonItems = listOf (
199224 ButtonItem (stringResource(R .string.identification)) { navController.navigate(AppRoute .IDENTIFICATION .route) },
200- ButtonItem (stringResource(R .string.support_chat)) { navController.navigate(AppRoute .SUPPORT_CHAT .route) },
225+ ButtonItem (stringResource(R .string.support_chat)) {
226+ viewModel.setInScreenTransitioning(true )
227+ navController.navigate(AppRoute .SUPPORT_CHAT .route)
228+ },
201229 ButtonItem (stringResource(R .string.push_notifications)) { navController.navigate(AppRoute .PUSH_NOTIFICATIONS .route) },
202230 ButtonItem (stringResource(R .string.session_analytics)) { navController.navigate(AppRoute .SESSION_ANALYTICS .route) }
203231 )
204232
233+ val debugButtons = listOf (
234+ ButtonItem (stringResource(R .string.anr)) { viewModel.ANR () },
235+ ButtonItem (stringResource(R .string.crash)) { viewModel.crash() }
236+ )
237+
205238 Column (
206239 modifier = modifier
207240 .fillMaxSize()
@@ -216,39 +249,31 @@ fun HomeComposable(modifier: Modifier = Modifier, navController: NavHostControll
216249 LazyColumn {
217250 items(stateItems) { (label, state) ->
218251 Row (
219- modifier = Modifier .padding(vertical = 8 .dp, horizontal = 8 .dp)
252+ modifier = Modifier
253+ .padding(vertical = 8 .dp, horizontal = 8 .dp)
220254 .fillMaxWidth(),
221255 verticalAlignment = Alignment .CenterVertically ,
222256 horizontalArrangement = Arrangement .SpaceBetween
223257 ) {
224258 Text (label)
225259 CircularCheckbox (
226260 checked = state,
227- onCheckedChange = { }
261+ onCheckedChange = { }
228262 )
229263 }
230264 }
231265 item {
232266 textRow(stringResource(R .string.feature))
233- }
234- items(buttonItems) { item ->
235- Button (
236- onClick = item.onClick,
237- modifier = Modifier
238- .fillMaxWidth()
239- .padding(vertical = 4 .dp),
240- colors = ButtonDefaults .buttonColors(
241- containerColor = Color .LightGray ,
242- contentColor = Color .Black
243- )
244- ) {
245- Box (
246- modifier = Modifier .fillMaxWidth(),
247- contentAlignment = Alignment .CenterStart
248- ) {
249- Text (item.label)
267+ ButtonsRow (buttonItems)
268+ textRow(stringResource(R .string.debug))
269+ ButtonsRow (debugButtons)
270+ textRow(stringResource(R .string.animation))
271+ Button (ButtonItem (stringResource(R .string.play_animation)) {coroutineScope.launch {
272+ repeat(4 ) {
273+ scale.animateTo(1.2f , animationSpec = spring(dampingRatio = 0.4f ))
274+ scale.animateTo(1f , animationSpec = spring(dampingRatio = 0.4f ))
250275 }
251- }
276+ } }, Modifier .scale(scale.value))
252277 }
253278 }
254279 }
@@ -304,6 +329,40 @@ fun CircularCheckbox(
304329 }
305330}
306331
332+ @Composable
333+ fun ButtonsRow (
334+ buttonList : List <ButtonItem >,
335+ modifier : Modifier = Modifier
336+ ) {
337+ Column (modifier = modifier) {
338+ buttonList.forEach { item ->
339+ Button (item)
340+ }
341+ }
342+ }
343+
344+ @Composable
345+ fun Button (item : ButtonItem , additionalModifier : Modifier = Modifier ) {
346+ Button (
347+ onClick = item.onClick,
348+ modifier = Modifier
349+ .fillMaxWidth()
350+ .padding(vertical = 4 .dp)
351+ .then(additionalModifier),
352+ colors = ButtonDefaults .buttonColors(
353+ containerColor = Color .LightGray ,
354+ contentColor = Color .Black
355+ )
356+ ) {
357+ Box (
358+ modifier = Modifier .fillMaxWidth(),
359+ contentAlignment = Alignment .CenterStart
360+ ) {
361+ Text (item.label)
362+ }
363+ }
364+ }
365+
307366private fun reloadFragment (fragmentManager : FragmentManager , fragment : Fragment , containerId : Int ) {
308367 fragmentManager.beginTransaction()
309368 .replace(containerId, fragment)
0 commit comments