final Praktikum 2
This commit is contained in:
parent
5b8e28d6ee
commit
f88e15d646
@ -1,7 +1,7 @@
|
||||
package id.ac.ubharajaya.panicbutton
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent // <-- TAMBAHKAN IMPORT INI
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
@ -48,13 +48,17 @@ fun MyApp() {
|
||||
var selectedConditions by remember { mutableStateOf(mutableSetOf<String>()) }
|
||||
var additionalNotes by remember { mutableStateOf(TextFieldValue("")) }
|
||||
|
||||
// PERMINTAAN 2: Buat Map untuk memetakan kondisi ke emoji tags
|
||||
// ▼▼▼ PERUBAHAN 1: Sesuaikan Map dengan gambar terakhir ▼▼▼
|
||||
val conditionToTagMap = mapOf(
|
||||
"Kebakaran" to "fire",
|
||||
"Banjir" to "cloud_with_rain",
|
||||
"Tsunami" to "ocean",
|
||||
"Gunung Meletus" to "volcano",
|
||||
"Gempa Bumi" to "earth_asia",
|
||||
"Huru hara/Demonstrasi" to "imp",
|
||||
"Lainnya" to "grey_question"
|
||||
"Huru Hara" to "imp",
|
||||
"Binatang Buas" to "snake",
|
||||
"Radiasi Nuklir" to "radioactive",
|
||||
"Biohazard" to "biohazard"
|
||||
)
|
||||
|
||||
Column(
|
||||
@ -64,18 +68,21 @@ fun MyApp() {
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
// PERMINTAAN 1: Judul diperbesar dan dibuat bold
|
||||
// Judul (tidak ada perubahan)
|
||||
Text(
|
||||
text = "Terjadi Kondisi Darurat",
|
||||
fontSize = 24.sp, // Ukuran font diperbesar
|
||||
fontWeight = FontWeight.Bold, // Teks dibuat bold
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Red,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
|
||||
|
||||
// Pilihan checkbox (tidak ada perubahan)
|
||||
listOf("Kebakaran", "Banjir", "Gempa Bumi", "Huru hara/Demonstrasi", "Lainnya").forEach { condition ->
|
||||
// ▼▼▼ PERUBAHAN 2: Sesuaikan daftar Checkbox dengan gambar terakhir ▼▼▼
|
||||
listOf(
|
||||
"Kebakaran", "Banjir", "Tsunami", "Gunung Meletus", "Gempa Bumi",
|
||||
"Huru Hara", "Binatang Buas", "Radiasi Nuklir", "Biohazard"
|
||||
).forEach { condition ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -120,19 +127,14 @@ fun MyApp() {
|
||||
)
|
||||
|
||||
|
||||
// Tombol Kirim
|
||||
// Tombol Kirim (tidak ada perubahan)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Button(
|
||||
onClick = {
|
||||
// PERMINTAAN 2: Logika untuk mendapatkan tags dari kondisi yang dipilih
|
||||
val notes = additionalNotes.text
|
||||
val conditionsText = selectedConditions.joinToString(", ")
|
||||
val report = "Kondisi: $conditionsText\nCatatan: $notes"
|
||||
|
||||
// Dapatkan tags dari kondisi yang dipilih menggunakan Map
|
||||
val tags = selectedConditions.mapNotNull { conditionToTagMap[it] }.joinToString(",")
|
||||
|
||||
// Kirim report dan tags ke fungsi notifikasi
|
||||
sendNotification(report, tags) { response ->
|
||||
message = response
|
||||
}
|
||||
@ -143,13 +145,13 @@ fun MyApp() {
|
||||
}
|
||||
|
||||
|
||||
// PERMINTAAN 1: Keterangan dibuat bold
|
||||
// Keterangan (tidak ada perubahan)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = "“JANGAN PANIK! SEGERA EVAKUASI\nDIRI ANDA KE TITIK KUMPUL”",
|
||||
color = Color.Red,
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.Bold // Teks dibuat bold
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
|
||||
@ -157,21 +159,18 @@ fun MyApp() {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(text = message, Modifier.padding(top = 16.dp))
|
||||
|
||||
// Spacer untuk mendorong tombol ke bagian bawah layar
|
||||
// Spacer (tidak ada perubahan)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
// PERMINTAAN 1: Tambahkan tombol Lihat Jalur Evakuasi dan Tutup
|
||||
// Tombol Lihat Jalur Evakuasi dan Tutup (tidak ada perubahan)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween // Agar tombol merapat ke sisi
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
// ▼▼▼ PERUBAHAN DI SINI ▼▼▼
|
||||
// Membuat Intent untuk memulai JalurEvakuasiActivity
|
||||
val intent = Intent(context, JalurEvakuasiActivity::class.java)
|
||||
context.startActivity(intent)
|
||||
// ▲▲▲ AKHIR DARI PERUBAHAN ▲▲▲
|
||||
}
|
||||
) {
|
||||
Text(text = "Lihat Jalur Evakuasi")
|
||||
@ -179,7 +178,6 @@ fun MyApp() {
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
// Logika untuk menutup aplikasi
|
||||
(context as? Activity)?.finish()
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.Gray)
|
||||
@ -191,7 +189,7 @@ fun MyApp() {
|
||||
}
|
||||
|
||||
|
||||
// PERMINTAAN 2: Ubah fungsi `sendNotification` untuk menerima parameter tags
|
||||
// Fungsi sendNotification (tidak ada perubahan)
|
||||
fun sendNotification(report: String, tags: String, onResult: (String) -> Unit) {
|
||||
val client = OkHttpClient()
|
||||
val url = "https://ntfy.ubharajaya.ac.id/panic-button"
|
||||
@ -206,7 +204,7 @@ fun sendNotification(report: String, tags: String, onResult: (String) -> Unit) {
|
||||
.url(url)
|
||||
.addHeader("Title", "Alert")
|
||||
.addHeader("Priority", "urgent")
|
||||
.addHeader("Tags", tags) // Gunakan tags dinamis dari parameter
|
||||
.addHeader("Tags", tags)
|
||||
.post(requestBody)
|
||||
.build()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user