Skip to content

Commit

Permalink
Add more test features to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaslogen committed Sep 5, 2024
1 parent b109708 commit 33f201c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ package com.sebaslogen.resacaapp.sample
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import com.sebaslogen.resacaapp.sample.ui.main.ComposeActivity
Expand Down Expand Up @@ -48,18 +56,26 @@ class MainActivity : AppCompatActivity() {
}
}

@Composable
fun CreateActivityComposeContent(clickListener: () -> Unit) {
Surface(color = MaterialTheme.colors.background.copy(alpha = 0.5f)) {
Column(Modifier.fillMaxWidth()) {
IconButton( // Recreate Activity on Refresh button pressed to test scoped objects
modifier = Modifier.align(Alignment.End),
onClick = { recreate() }
) {
Icon(Icons.Filled.Refresh, contentDescription = "Recreate Activity")
}
DemoScreenInActivity(clickListener)
}
}
}

private fun navigateToComposeActivity() {
startActivity(Intent(this, ComposeActivity::class.java))
}

fun navigateToFragmentTwo() {
supportFragmentManager.navigateToFragmentTwo()
}
}

@Composable
fun CreateActivityComposeContent(clickListener: () -> Unit) {
Surface(color = MaterialTheme.colors.background.copy(alpha = 0.5f)) {
DemoScreenInActivity(clickListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand All @@ -14,9 +18,13 @@ import com.sebaslogen.resacaapp.sample.ui.main.compose.examples.DemoScopedViewMo

@Composable
fun DemoScreenInActivity(clickListener: () -> Unit) {
var contentKey by rememberSaveable { mutableStateOf(false) }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
DemoScopedObjectComposable()
DemoScopedViewModelComposable()
DemoScopedViewModelComposable(key = contentKey.toString())
Button(onClick = { contentKey = !contentKey }) {
Text("Get a new instance of the FakeScopedViewModel")
}
ComposeActivityButton(clickListener)
}
}
Expand Down

0 comments on commit 33f201c

Please sign in to comment.