Skip to content

Commit

Permalink
feat: view model
Browse files Browse the repository at this point in the history
  • Loading branch information
GM7Avila committed Jul 1, 2024
1 parent 7a55651 commit c88e028
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion app/src/main/java/com/example/apptempo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModelProvider
import com.example.apptempo.ui.theme.AppTempoTheme

class MainActivity : ComponentActivity() {

private lateinit var weatherViewModel: WeatherViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
weatherViewModel = ViewModelProvider(this)[WeatherViewModel::class.java]

setContent {
AppTempoTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
WeatherPage()
WeatherPage(weatherViewModel)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/example/apptempo/WeatherPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun WeatherPage() {
fun WeatherPage(viewModel: WeatherViewModel) {
var city by remember { mutableStateOf("") }

Column(
Expand All @@ -39,7 +39,9 @@ fun WeatherPage() {
onValueChange = { city = it },
label = { Text(text = "Pesquisar") }
)
IconButton(onClick = { /*TODO*/ }) {
IconButton(onClick = {
viewModel.getData(city)
}) {
Icon(imageVector = Icons.Default.Search,
contentDescription = "Pesquise por uma cidade")
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/example/apptempo/WeatherViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.apptempo

import android.util.Log
import androidx.lifecycle.ViewModel

class WeatherViewModel : ViewModel(){

fun getData(city: String){
Log.i("City name: ", city)
}

}

0 comments on commit c88e028

Please sign in to comment.