add material you calendar agenda widget with compose + glance
This commit is contained in:
parent
db4c6a7f63
commit
d54a7ef5eb
14 changed files with 733 additions and 54 deletions
47
app/src/main/java/space/darkest/nova/android/MainActivity.kt
Normal file
47
app/src/main/java/space/darkest/nova/android/MainActivity.kt
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package space.darkest.nova.android
|
||||
|
||||
import android.Manifest
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import space.darkest.nova.android.data.CalendarRepository
|
||||
import space.darkest.nova.android.ui.AgendaScreen
|
||||
import space.darkest.nova.android.ui.theme.NovaTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
private var agenda by mutableStateOf(emptyList<space.darkest.nova.android.data.AgendaDay>())
|
||||
|
||||
private val calendarPermission = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
if (granted) refreshAgenda()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
|
||||
calendarPermission.launch(Manifest.permission.READ_CALENDAR)
|
||||
|
||||
setContent {
|
||||
NovaTheme {
|
||||
AgendaScreen(agenda)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
refreshAgenda()
|
||||
}
|
||||
|
||||
private fun refreshAgenda() {
|
||||
agenda = CalendarRepository.getAgenda(this, 14)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue