Compare commits
No commits in common. "2e35f8bcd622a682f9ad4727e4e7c9a36a7707b4" and "1f7adae6f4b118ac59a8fadc5eda76f759530a67" have entirely different histories.
2e35f8bcd6
...
1f7adae6f4
@ -25,10 +25,4 @@ Repository ini digunakan untuk praktikum perkuliahan pemrograman mobile.
|
|||||||
- 14. Nabila suwandira (202310715066)
|
- 14. Nabila suwandira (202310715066)
|
||||||
- 15. Indris Alpasela (202310715200)
|
- 15. Indris Alpasela (202310715200)
|
||||||
- 16. Raihan Ariq Muzakki (202310715297)
|
- 16. Raihan Ariq Muzakki (202310715297)
|
||||||
- 17. Dirson Ali Wardana (202310715246)
|
- 17. Dirson Ali Wardana (202310715246)
|
||||||
- 18. Dimas Hendri Pamungkas (202310715274)
|
|
||||||
- 19. Fadhlul Wafi (202310715188)
|
|
||||||
- 20. Muhammad Yusron Amrullah (202310715060)
|
|
||||||
- 21. Muhammad Fadillah (202310715213)
|
|
||||||
- 22. Hadi Guna Prakoso (202310715312)
|
|
||||||
- 23. Muhammad Rafi (202310715191)
|
|
||||||
@ -57,8 +57,4 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||||
//praktikum 1
|
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.11.0")
|
|
||||||
implementation("androidx.compose.material3:material3:1.1.1")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -23,5 +23,5 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@ -3,90 +3,45 @@ package id.ac.ubharajaya.panicbutton
|
|||||||
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
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import id.ac.ubharajaya.panicbutton.ui.theme.PanicButtonTheme
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.Request
|
|
||||||
import okhttp3.RequestBody
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
MyApp()
|
PanicButtonTheme {
|
||||||
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
||||||
|
Greeting(
|
||||||
|
name = "Android",
|
||||||
|
modifier = Modifier.padding(innerPadding)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MyApp() {
|
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
||||||
// State untuk menampilkan hasil request
|
Text(
|
||||||
var message by remember { mutableStateOf("Klik tombol untuk mengirim notifikasi") }
|
text = "Hello $name!",
|
||||||
|
modifier = modifier
|
||||||
|
)
|
||||||
// UI
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
Text(text = message, Modifier.padding(bottom = 16.dp))
|
|
||||||
Button(onClick = {
|
|
||||||
// Kirim HTTP request saat tombol ditekan
|
|
||||||
sendNotification { response ->
|
|
||||||
message = response
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Text(text = "Kirim Alert")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true)
|
||||||
// Fungsi untuk mengirimkan HTTP request
|
@Composable
|
||||||
fun sendNotification(onResult: (String) -> Unit) {
|
fun GreetingPreview() {
|
||||||
val client = OkHttpClient()
|
PanicButtonTheme {
|
||||||
val url = "https://ntfy.ubharajaya.ac.id/panic-button" // Ganti <your-topic> dengan topik Anda
|
Greeting("Android")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val requestBody = RequestBody.create(
|
|
||||||
"text/plain".toMediaType(), // Mengirim plain text
|
|
||||||
"Notifikasi dari Nuryuda Maulana (202310715038)!" // Pesan yang akan tampil
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
val request = Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.addHeader("Title", "Alert")
|
|
||||||
.addHeader("Priority", "urgent")
|
|
||||||
.addHeader("Tags", "alert warning,rotating_light")
|
|
||||||
.post(requestBody)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Eksekusi request di thread terpisah
|
|
||||||
Thread {
|
|
||||||
try {
|
|
||||||
val response = client.newCall(request).execute()
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
onResult("Notifikasi berhasil dikirim!")
|
|
||||||
} else {
|
|
||||||
onResult("Gagal mengirim notifikasi: ${response.code}")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
onResult("Error: ${e.message}")
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user