From 176afcff39d7d68b50b5e91bcd5db5c9987e92e5 Mon Sep 17 00:00:00 2001 From: Alexyz Date: Mon, 28 Sep 2026 12:04:38 +0500 Subject: [PATCH] feat(mobile): add automatic background cloud sync to NotesRepository pointing to Coolify server --- .../example/avtex/notes/NotesRepository.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/mobile/app/src/main/java/com/example/avtex/notes/NotesRepository.kt b/apps/mobile/app/src/main/java/com/example/avtex/notes/NotesRepository.kt index 20e081a..38bc6a9 100644 --- a/apps/mobile/app/src/main/java/com/example/avtex/notes/NotesRepository.kt +++ b/apps/mobile/app/src/main/java/com/example/avtex/notes/NotesRepository.kt @@ -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>(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,