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

Modern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / signal / SignalRepository.kt

SignalRepository.kt30 lines · 1.1 KiBRaw
1package com.vayunmathur.communicate.data.signal
2
3import android.content.Context
4import com.vayunmathur.library.room.RoomRepository
5
6/**
7 * Single owner of [SignalDatabase] (communicate_signal.db).
8 *
9 * The single `buildDatabase` call site now lives here (via [RoomRepository.db]);
10 * [SignalDatabase.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 SignalRepository private constructor(context: Context) :
15 RoomRepository<SignalDatabase>(context, SignalDatabase::class, "communicate_signal.db") {
16
17 /** Direct database access for legacy `runBlocking` bridges; prefer suspend wrappers for new code. */
18 fun database(): SignalDatabase = db
19
20 /** The singleton [SignalRepository] instance holder. */
21 companion object {
22 @Volatile
23 private var instance: SignalRepository? = null
24
25 fun get(context: Context): SignalRepository =
26 instance ?: synchronized(this) {
27 instance ?: SignalRepository(context).also { instance = it }
28 }
29 }
30}