Add Application-level NetworkMonitor with extensive logging
- Create SimpleNotesApplication class for app-level lifecycle - Move NetworkMonitor from Activity to Application context - Add comprehensive logging to NetworkMonitor (all callbacks) - Add logging to SyncWorker for debugging - Remove NetworkMonitor from MainActivity (now in Application) - Add Battery Optimization dialog in SettingsActivity - Improve Notifications (showSyncInProgress, showSyncSuccess, showSyncError) This should fix background sync issues - NetworkMonitor now runs with Application context instead of Activity context, which should survive when app is in background. Debug with: adb logcat | grep -E 'NetworkMonitor|SyncWorker|SimpleNotesApp'
This commit is contained in:
@@ -17,6 +17,11 @@ import dev.dettmer.simplenotes.storage.NotesStorage
|
||||
import dev.dettmer.simplenotes.utils.NotificationHelper
|
||||
import dev.dettmer.simplenotes.utils.showToast
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import dev.dettmer.simplenotes.sync.WebDavSyncService
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@@ -36,9 +41,6 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// Notification Channel erstellen
|
||||
NotificationHelper.createNotificationChannel(this)
|
||||
|
||||
// Permission für Notifications (Android 13+)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
requestNotificationPermission()
|
||||
@@ -106,6 +108,31 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
}
|
||||
|
||||
private fun triggerManualSync() {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
showToast("Starte Synchronisation...")
|
||||
|
||||
// Start sync
|
||||
val syncService = WebDavSyncService(this@MainActivity)
|
||||
val result = withContext(Dispatchers.IO) {
|
||||
syncService.syncNotes()
|
||||
}
|
||||
|
||||
// Show result
|
||||
if (result.isSuccess) {
|
||||
showToast("Sync erfolgreich: ${result.syncedCount} Notizen")
|
||||
loadNotes() // Reload notes
|
||||
} else {
|
||||
showToast("Sync Fehler: ${result.errorMessage}")
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
showToast("Sync Fehler: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
return true
|
||||
@@ -118,8 +145,7 @@ class MainActivity : AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
R.id.action_sync -> {
|
||||
// Manual sync trigger could be added here
|
||||
showToast("Sync wird in den Einstellungen gestartet")
|
||||
triggerManualSync()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
|
||||
Reference in New Issue
Block a user