Compare commits
34 Commits
59a5f2b68a
...
cebaf14306
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cebaf14306 | ||
|
|
179b2cf0ce | ||
|
|
55b7a311cc | ||
|
|
024a147fbd | ||
|
|
82212b9cc7 | ||
| 08c24bdfdd | |||
| d3c1410a11 | |||
| 1ce89ad197 | |||
| 228d9f8f77 | |||
| 5dffb47576 | |||
| 992c0d627c | |||
| 4f1f8577bc | |||
| 6370eba0da | |||
| c4aee9ee3c | |||
| 5cccdf5368 | |||
| b73d429200 | |||
| 89c60eb81e | |||
| 6fcbb52b90 | |||
| cd156ca010 | |||
| 4488dfd0cb | |||
| 4281e24379 | |||
| 5170efe60e | |||
| 4ac1678d48 | |||
| 357a25744c | |||
| cf5adbd923 | |||
| d77a9409de | |||
| a115da0783 | |||
| 8f9ca68257 | |||
| 83fabde258 | |||
| 8f24ef2640 | |||
| 3e3da371dc | |||
| 6d30bb4a88 | |||
|
|
ae1ae8cd80 | ||
| 55d17abb93 |
@ -27,8 +27,16 @@ Repository ini digunakan untuk praktikum perkuliahan pemrograman mobile.
|
|||||||
- 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)
|
||||||
|
<<<<<<< HEAD
|
||||||
|
- 18. Dimas Hendri Pamungkas (202310715274)
|
||||||
|
- 19. Fadhlul Wafi (202310715188)
|
||||||
|
- 20. Muhammad Yusron Amrullah (202310715060)
|
||||||
|
- 21. Muhammad Fadillah (202310715213)
|
||||||
|
- 21. Hadi Guna Prakoso (202310715312)
|
||||||
|
=======
|
||||||
=======
|
=======
|
||||||
- Fadlan Rivaldi (202310715280)
|
- Fadlan Rivaldi (202310715280)
|
||||||
- B
|
- B
|
||||||
- C
|
- C
|
||||||
>>>>>>> d4f073d (First Commit)
|
>>>>>>> d4f073d (First Commit)
|
||||||
|
>>>>>>> 59a5f2b68a9a33028bb744220857c043749c6949
|
||||||
|
|||||||
@ -57,4 +57,11 @@ 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)
|
||||||
|
implementation("com.squareup.okhttp3:okhttp:4.11.0")
|
||||||
|
implementation("androidx.compose.material3:material3:1.1.1")
|
||||||
|
|
||||||
|
//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,45 +3,90 @@ 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.activity.enableEdgeToEdge
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.material3.Button
|
||||||
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.Composable
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.unit.dp
|
||||||
import id.ac.ubharajaya.panicbutton.ui.theme.PanicButtonTheme
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
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 {
|
||||||
PanicButtonTheme {
|
MyApp()
|
||||||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
|
||||||
Greeting(
|
|
||||||
name = "Android",
|
|
||||||
modifier = Modifier.padding(innerPadding)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
|
||||||
Text(
|
|
||||||
text = "Hello $name!",
|
|
||||||
modifier = modifier
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GreetingPreview() {
|
fun MyApp() {
|
||||||
PanicButtonTheme {
|
// State untuk menampilkan hasil request
|
||||||
Greeting("Android")
|
var message by remember { mutableStateOf("Klik tombol untuk mengirim notifikasi") }
|
||||||
|
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Fungsi untuk mengirimkan HTTP request
|
||||||
|
fun sendNotification(onResult: (String) -> Unit) {
|
||||||
|
val client = OkHttpClient()
|
||||||
|
val url = "https://ntfy.ubharajaya.ac.id/panic-button" // Ganti <your-topic> dengan topik Anda
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val requestBody = RequestBody.create(
|
||||||
|
"text/plain".toMediaType(), // Mengirim plain text
|
||||||
|
"Notifikasi dari Haga Dalpinto Ginting 202310715176" // 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