feat(mobile): add automatic background cloud sync to NotesRepository pointing to Coolify server
This commit is contained in:
@@ -2,6 +2,7 @@ package com.example.avtex.notes
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -11,9 +12,10 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.UUID
|
||||
|
||||
class NotesRepository(context: Context) {
|
||||
class NotesRepository(private val context: Context) {
|
||||
|
||||
private val dbHelper = XFlowDatabaseHelper(context)
|
||||
private val syncClient = XFlowSyncClient(context)
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
|
||||
private val _listsFlow = MutableStateFlow<List<NoteList>>(emptyList())
|
||||
@@ -153,6 +155,26 @@ class NotesRepository(context: Context) {
|
||||
|
||||
reload()
|
||||
|
||||
// Фоновая отправка в XFlow Cloud (Coolify)
|
||||
scope.launch {
|
||||
try {
|
||||
val prefs = context.getSharedPreferences("xflow_prefs", Context.MODE_PRIVATE)
|
||||
val serverUrl = prefs.getString("xflow_server_url", "https://xflow.controlsystem.kz")
|
||||
?: "https://xflow.controlsystem.kz"
|
||||
|
||||
if (serverUrl.isNotBlank()) {
|
||||
syncClient.syncItemToServer(
|
||||
serverUrl = serverUrl,
|
||||
title = title.trim(),
|
||||
listTitle = listTitle.trim(),
|
||||
category = category
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("NotesRepository", "Background cloud sync failed: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
NoteItem(
|
||||
id = newItemId,
|
||||
listId = targetListId,
|
||||
|
||||
Reference in New Issue
Block a user