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