198 lines
4.7 KiB
Markdown
198 lines
4.7 KiB
Markdown
# ⚡ Quick Reference Guide
|
|
|
|
## 🏃 Quick Start
|
|
|
|
1. **Buka project di Android Studio**
|
|
2. **Sinkronisasi Gradle** (automatic atau `./gradlew sync`)
|
|
3. **Run aplikasi** (Shift+F10 atau tombol Run)
|
|
4. **Izinkan permissions** saat diminta
|
|
|
|
## 📋 File yang Paling Penting
|
|
|
|
| File | Fungsi |
|
|
|------|--------|
|
|
| `MainActivity.kt` | UI utama + logic absensi |
|
|
| `AttendanceConfig.kt` | **Ubah koordinat/data di sini** |
|
|
| `LocationValidator.kt` | Logic validasi lokasi |
|
|
| `N8nService.kt` | Kirim data ke server |
|
|
|
|
## 🎯 Ubah Lokasi Referensi
|
|
|
|
**File**: `app/src/main/java/id/ac/ubharajaya/sistemakademik/config/AttendanceConfig.kt`
|
|
|
|
```kotlin
|
|
// Ubah koordinat kampus
|
|
const val REFERENCE_LATITUDE = -7.0 // 👈 Ubah ini
|
|
const val REFERENCE_LONGITUDE = 110.4 // 👈 Ubah ini
|
|
|
|
// Ubah radius area (dalam meter)
|
|
const val ALLOWED_RADIUS_METERS = 100.0 // 👈 Ubah ini
|
|
|
|
// Ubah data mahasiswa
|
|
const val STUDENT_NPM = "202310715082" // 👈 Ubah ini
|
|
const val STUDENT_NAMA = "Fazri Abdurrahman" // 👈 Ubah ini
|
|
```
|
|
|
|
**Cara mendapat koordinat**:
|
|
1. Buka Google Maps
|
|
2. Klik lokasi → Koordinat muncul di atas
|
|
3. Format: -7.0035 (latitude), 110.4042 (longitude)
|
|
|
|
## 🧪 Test Webhook (Sebelum Production)
|
|
|
|
**Edit**: `MainActivity.kt` baris ~265:
|
|
```kotlin
|
|
isTest = true // 👈 Set ke true untuk test
|
|
// Setelah test sukses, ubah ke:
|
|
isTest = false // Untuk production
|
|
```
|
|
|
|
**Cek di**: https://n8n.lab.ubharajaya.ac.id/webhook-test/...
|
|
|
|
## 🐛 Debug Tips
|
|
|
|
### Check Logs
|
|
```bash
|
|
# Di Android Studio
|
|
View → Tool Windows → Logcat
|
|
Cari: N8nService atau MainActivity
|
|
```
|
|
|
|
### Test Lokasi Tertentu
|
|
```kotlin
|
|
// Di MainActivity, buat hardcoded location untuk test:
|
|
state = state.copy(
|
|
location = LocationData(
|
|
latitude = -7.0035,
|
|
longitude = 110.4042
|
|
)
|
|
)
|
|
```
|
|
|
|
### Mock GPS (di Emulator)
|
|
```
|
|
Tools → Device Manager → Extended Controls → Location
|
|
Masukkan latitude/longitude yang ingin ditest
|
|
```
|
|
|
|
## 📱 Build & Deploy
|
|
|
|
### Build APK (untuk test)
|
|
```bash
|
|
./gradlew assembleDebug
|
|
# APK ada di: app/build/outputs/apk/debug/
|
|
```
|
|
|
|
### Build Release APK (untuk production)
|
|
```bash
|
|
./gradlew assembleRelease
|
|
# APK ada di: app/build/outputs/apk/release/
|
|
```
|
|
|
|
## 🔧 Fix Umum
|
|
|
|
### "Permission denied" saat GPS
|
|
→ Buka Settings app → Izin Aplikasi → Location → Allow
|
|
|
|
### "GPS tidak berfungsi"
|
|
→ Nyalakan Location Services di device settings
|
|
|
|
### "Foto tidak muncul"
|
|
→ Izinkan Camera permission di settings
|
|
|
|
### "Server error 500"
|
|
→ Check N8n workflow di dashboard
|
|
|
|
### "Tidak bisa connect"
|
|
→ Cek internet connection & webhook URL
|
|
|
|
## 📍 Cara Kerja Validasi Lokasi
|
|
|
|
1. **Ambil GPS**: Latitude & Longitude dari device
|
|
2. **Hitung Jarak**: Formula Haversine ke referensi
|
|
3. **Compare**: Jarak vs ALLOWED_RADIUS_METERS
|
|
4. **Hasil**: Valid ✓ atau Invalid ✗
|
|
|
|
```
|
|
Contoh:
|
|
- Referensi: -7.0, 110.4
|
|
- GPS: -7.0035, 110.4042
|
|
- Jarak: ~500m
|
|
- Radius: 100m
|
|
- Hasil: INVALID (500m > 100m)
|
|
```
|
|
|
|
## 📡 API Response Codes
|
|
|
|
| Code | Arti | Action |
|
|
|------|------|--------|
|
|
| 200 | ✓ Sukses | Toast "Diterima", reset form |
|
|
| 400 | ✗ Data error | Tampilkan error message |
|
|
| 500 | ✗ Server error | Retry atau hubungi admin |
|
|
|
|
## 🎮 UI Components Cheat Sheet
|
|
|
|
### LocationStatusCard
|
|
- Tampilkan: Latitude, Longitude, Jarak, Status
|
|
- Auto update saat GPS berubah
|
|
|
|
### PhotoPreviewCard
|
|
- Preview: Foto dari camera
|
|
- Tombol: Ambil Ulang (untuk ganti foto)
|
|
|
|
### ErrorAlertCard
|
|
- Tampilkan: Error message
|
|
- Dismissable: Tombol X
|
|
|
|
### SubmitButtonWithLoader
|
|
- Loading: Spinner saat submit
|
|
- Disabled: Jika data belum lengkap
|
|
|
|
## 🔑 Key Variables
|
|
|
|
```kotlin
|
|
// State management
|
|
var state by remember { mutableStateOf(AttendanceState()) }
|
|
|
|
// Fused location
|
|
val fusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
|
|
|
|
// API service
|
|
val n8nService = remember { N8nService(activity) }
|
|
|
|
// Current location
|
|
state.location?.latitude
|
|
state.location?.longitude
|
|
|
|
// Current photo
|
|
state.foto // Bitmap
|
|
|
|
// Validation
|
|
state.validationResult.isValid
|
|
state.validationResult.message
|
|
```
|
|
|
|
## 🚀 Deploy Steps
|
|
|
|
1. **Update AttendanceConfig.kt** (koordinat, NPM, nama)
|
|
2. **Test dengan WEBHOOK_TEST** (set isTest = true)
|
|
3. **Verify di N8n dashboard**
|
|
4. **Switch ke WEBHOOK_PRODUCTION** (set isTest = false)
|
|
5. **Build APK release**: `./gradlew assembleRelease`
|
|
6. **Distribute ke device/playstore**
|
|
|
|
## 📊 Useful URLs
|
|
|
|
| Purpose | URL |
|
|
|---------|-----|
|
|
| Test Webhook | https://n8n.lab.ubharajaya.ac.id/webhook-test/... |
|
|
| Production Webhook | https://n8n.lab.ubharajaya.ac.id/webhook/... |
|
|
| N8n Dashboard | https://n8n.lab.ubharajaya.ac.id |
|
|
| Attendance Check | https://docs.google.com/spreadsheets/d/1jH15MfnNgpPGuGeid0... |
|
|
| Ntfy Monitor | https://ntfy.ubharajaya.ac.id/EAS |
|
|
|
|
---
|
|
|
|
**Perlu bantuan?** Check `DOKUMENTASI.md` untuk penjelasan lebih detail.
|
|
|