Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / whatsapp / WhatsAppRepository.kt

WhatsAppRepository.kt30 lines · 1.2 KiBRaw
1package com.vayunmathur.communicate.data.whatsapp
2
3import android.content.Context
4import com.vayunmathur.library.room.RoomRepository
5
6/**
7 * Single owner of [WhatsAppDatabase] (communicate_whatsapp.db).
8 *
9 * The single `buildDatabase` call site now lives here (via [RoomRepository.db]);
10 * [WhatsAppDatabase.getDatabase] delegates to this repository so existing consumers
11 * keep compiling unchanged. E2E `runBlocking` store bridges keep working — they
12 * now obtain DAOs via this repository's database.
13 */
14class WhatsAppRepository private constructor(context: Context) :
15 RoomRepository<WhatsAppDatabase>(context, WhatsAppDatabase::class, "communicate_whatsapp.db") {
16
17 /** Direct database access for legacy `runBlocking` bridges; prefer suspend wrappers for new code. */
18 fun database(): WhatsAppDatabase = db
19
20 /** The singleton [WhatsAppRepository] instance holder. */
21 companion object {
22 @Volatile
23 private var instance: WhatsAppRepository? = null
24
25 fun get(context: Context): WhatsAppRepository =
26 instance ?: synchronized(this) {
27 instance ?: WhatsAppRepository(context).also { instance = it }
28 }
29 }
30}