._.
This commit is contained in:
parent
dcef23b404
commit
7eda0718a8
@ -1,7 +1,9 @@
|
|||||||
package com.example.russionroadsapp
|
package com.example.russionroadsapp
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.provider.CalendarContract
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@ -99,7 +101,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EventCard(event: Map<String, String>) {
|
fun EventCard(event: Map<String, String>, context: Context) {
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.clip(RoundedCornerShape(10.dp))
|
.clip(RoundedCornerShape(10.dp))
|
||||||
@ -118,7 +120,10 @@ fun EventCard(event: Map<String, String>) {
|
|||||||
event["title"]?.let { Text(it) }
|
event["title"]?.let { Text(it) }
|
||||||
event["description"]?.let { Text(it) }
|
event["description"]?.let { Text(it) }
|
||||||
}
|
}
|
||||||
Icon(Icons.Default.Star, contentDescription = "")
|
Icon(Icons.Default.Star, contentDescription = "Добавить в календарь",
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
addEventToCalendar(context, event)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Row(
|
Row(
|
||||||
Modifier.fillMaxWidth(),
|
Modifier.fillMaxWidth(),
|
||||||
@ -130,6 +135,19 @@ fun EventCard(event: Map<String, String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addEventToCalendar(context: Context, event: Map<String, String>) {
|
||||||
|
val intent = Intent(Intent.ACTION_INSERT).apply {
|
||||||
|
data = CalendarContract.Events.CONTENT_URI
|
||||||
|
putExtra(CalendarContract.Events.TITLE, event["title"])
|
||||||
|
putExtra(CalendarContract.Events.DESCRIPTION, event["description"])
|
||||||
|
putExtra(
|
||||||
|
CalendarContract.EXTRA_EVENT_BEGIN_TIME,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
) // Можно заменить на конкретную дату
|
||||||
|
}
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EventsPage(localContext: Context, setPageNews: () -> Unit, setPageEvents: () -> Unit) {
|
fun EventsPage(localContext: Context, setPageNews: () -> Unit, setPageEvents: () -> Unit) {
|
||||||
|
|
||||||
@ -267,7 +285,7 @@ fun EventsPage(localContext: Context, setPageNews: () -> Unit, setPageEvents: ()
|
|||||||
verticalArrangement = Arrangement.spacedBy(20.dp)
|
verticalArrangement = Arrangement.spacedBy(20.dp)
|
||||||
) {
|
) {
|
||||||
items(eventsList.size) { index ->
|
items(eventsList.size) { index ->
|
||||||
EventCard(eventsList[index])
|
EventCard(eventsList[index], localContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user