This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// case ketika request reminder sebelum waktu jadwal 2x - 6jam | |
// setelah itu reminder terakhir sebelum waktu jadwal 1.5jam | |
val reminderData = Data.Builder() | |
.putLong(DELAY, <Input Delay : Long>) | |
.putLong(INTERVAL, <Input Interval : Long>) | |
.build() | |
val reminderConstraints = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.CONNECTED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ENUM CLASS | |
// Definisi Resource dengan enum class | |
enum class Status { | |
SUCCESS, | |
ERROR, | |
LOADING | |
} | |
data class Resource(val status: Status, val data: String? = null, val message: String? = null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 4. Room Database (Data Layer) | |
@Database(entities = [Note::class], version = 1) | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun noteDao(): NoteDao | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 3. Repository Implementation (Data Layer) | |
class FirestoreNotesRepository @Inject constructor() : NotesRepository { | |
private val db = FirebaseFirestore.getInstance() | |
private val notesCollection = db.collection("notes") | |
override fun getNotes(): Flow<Resource> = flow { | |
emit(Resource.Loading) | |
try { | |
notesCollection.addSnapshotListener { snapshot, exception -> | |
if (exception != null || snapshot == null) { |