61 lines
1.7 KiB
Kotlin
61 lines
1.7 KiB
Kotlin
package xyz.pixelatedw.recipe
|
|
|
|
import android.os.Bundle
|
|
import android.view.WindowManager
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.activity.enableEdgeToEdge
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
import androidx.activity.viewModels
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.material3.Scaffold
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.room.Room
|
|
import xyz.pixelatedw.recipe.data.AppDatabase
|
|
import xyz.pixelatedw.recipe.data.RecipesView
|
|
import xyz.pixelatedw.recipe.ui.components.MainScreen
|
|
import xyz.pixelatedw.recipe.ui.theme.RecipeTheme
|
|
import xyz.pixelatedw.recipe.utils.getRecipes
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
private val recipeView: RecipesView by viewModels()
|
|
lateinit var db: AppDatabase
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
db = Room.databaseBuilder(
|
|
this,
|
|
AppDatabase::class.java, "recipes"
|
|
).allowMainThreadQueries().build()
|
|
|
|
val recipes = db.recipeWithTagsDao().getAll()
|
|
recipeView.setRecipes(recipes)
|
|
|
|
enableEdgeToEdge()
|
|
|
|
setContent {
|
|
RecipeTheme {
|
|
Surface {
|
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
|
MainScreen(this, innerPadding, recipeView)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
val sourceChooser =
|
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
if (result.resultCode == RESULT_OK) {
|
|
result.data?.data?.let { uri ->
|
|
getRecipes(this, db, uri)
|
|
|
|
val recipes = db.recipeWithTagsDao().getAll()
|
|
recipeView.setRecipes(recipes)
|
|
}
|
|
}
|
|
}
|
|
}
|