@@ -25,8 +25,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
2525import com.google.android.material.appbar.MaterialToolbar
2626import com.google.android.material.card.MaterialCardView
2727import com.google.android.material.color.DynamicColors
28- import com.google.android.material.switchmaterial.SwitchMaterial
29- import kotlinx.coroutines.CoroutineScope
3028import kotlinx.coroutines.Dispatchers
3129import kotlinx.coroutines.launch
3230import dev.dettmer.simplenotes.backup.BackupManager
@@ -39,7 +37,6 @@ import dev.dettmer.simplenotes.sync.NetworkMonitor
3937import dev.dettmer.simplenotes.utils.Constants
4038import dev.dettmer.simplenotes.utils.Logger
4139import dev.dettmer.simplenotes.utils.showToast
42- import java.io.File
4340import java.net.HttpURLConnection
4441import java.net.URL
4542import java.text.SimpleDateFormat
@@ -52,6 +49,7 @@ class SettingsActivity : AppCompatActivity() {
5249 private const val GITHUB_REPO_URL = " https://github.com/inventory69/simple-notes-sync"
5350 private const val GITHUB_PROFILE_URL = " https://github.com/inventory69"
5451 private const val LICENSE_URL = " https://github.com/inventory69/simple-notes-sync/blob/main/LICENSE"
52+ private const val CONNECTION_TIMEOUT_MS = 3000
5553 }
5654
5755 private lateinit var textInputLayoutServerUrl: com.google.android.material.textfield.TextInputLayout
@@ -325,7 +323,10 @@ class SettingsActivity : AppCompatActivity() {
325323 */
326324 private fun setupSyncIntervalPicker () {
327325 // Load current interval from preferences
328- val currentInterval = prefs.getLong(Constants .PREF_SYNC_INTERVAL_MINUTES , Constants .DEFAULT_SYNC_INTERVAL_MINUTES )
326+ val currentInterval = prefs.getLong(
327+ Constants .PREF_SYNC_INTERVAL_MINUTES ,
328+ Constants .DEFAULT_SYNC_INTERVAL_MINUTES
329+ )
329330
330331 // Set checked radio button based on current interval
331332 val checkedId = when (currentInterval) {
@@ -654,8 +655,8 @@ class SettingsActivity : AppCompatActivity() {
654655 try {
655656 val url = URL (serverUrl)
656657 val connection = url.openConnection() as HttpURLConnection
657- connection.connectTimeout = 3000
658- connection.readTimeout = 3000
658+ connection.connectTimeout = CONNECTION_TIMEOUT_MS
659+ connection.readTimeout = CONNECTION_TIMEOUT_MS
659660 val code = connection.responseCode
660661 connection.disconnect()
661662 code in 200 .. 299 || code == 401 // 401 = Server da, Auth fehlt
@@ -764,7 +765,10 @@ class SettingsActivity : AppCompatActivity() {
764765 .apply ()
765766
766767 updateMarkdownButtonVisibility()
767- showToast(" Markdown Auto-Sync aktiviert - Notizen werden als .md-Dateien exportiert und importiert" )
768+ showToast(
769+ " Markdown Auto-Sync aktiviert - " +
770+ " Notizen werden als .md-Dateien exportiert und importiert"
771+ )
768772 }
769773
770774 } catch (e: Exception ) {
@@ -818,11 +822,13 @@ class SettingsActivity : AppCompatActivity() {
818822 intent.data = Uri .parse(" package:$packageName " )
819823 startActivity(intent)
820824 } catch (e: Exception ) {
825+ Logger .w(TAG , " Failed to open battery optimization settings: ${e.message} " )
821826 // Fallback: Open general battery settings
822827 try {
823828 val intent = Intent (Settings .ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS )
824829 startActivity(intent)
825830 } catch (e2: Exception ) {
831+ Logger .w(TAG , " Failed to open fallback battery settings: ${e2.message} " )
826832 showToast(" Bitte Akku-Optimierung manuell deaktivieren" )
827833 }
828834 }
@@ -841,49 +847,6 @@ class SettingsActivity : AppCompatActivity() {
841847 }
842848 }
843849
844- private fun showRestoreConfirmation () {
845- android.app.AlertDialog .Builder (this )
846- .setTitle(R .string.restore_confirmation_title)
847- .setMessage(R .string.restore_confirmation_message)
848- .setPositiveButton(R .string.restore_button) { _, _ ->
849- performRestore()
850- }
851- .setNegativeButton(R .string.cancel, null )
852- .show()
853- }
854-
855- private fun performRestore () {
856- val progressDialog = android.app.ProgressDialog (this ).apply {
857- setMessage(getString(R .string.restore_progress))
858- setCancelable(false )
859- show()
860- }
861-
862- CoroutineScope (Dispatchers .Main ).launch {
863- try {
864- val webdavService = WebDavSyncService (this @SettingsActivity)
865- val result = withContext(Dispatchers .IO ) {
866- webdavService.restoreFromServer()
867- }
868-
869- progressDialog.dismiss()
870-
871- if (result.isSuccess) {
872- showToast(getString(R .string.restore_success, result.restoredCount))
873- // Refresh MainActivity's note list
874- setResult(RESULT_OK )
875- } else {
876- showToast(getString(R .string.restore_error, result.errorMessage))
877- }
878- checkServerStatus()
879- } catch (e: Exception ) {
880- progressDialog.dismiss()
881- showToast(getString(R .string.restore_error, e.message))
882- checkServerStatus()
883- }
884- }
885- }
886-
887850 override fun onOptionsItemSelected (item : MenuItem ): Boolean {
888851 return when (item.itemId) {
889852 android.R .id.home -> {
@@ -946,7 +909,6 @@ class SettingsActivity : AppCompatActivity() {
946909 }
947910
948911 // Custom View mit Radio Buttons
949- val dialogView = layoutInflater.inflate(android.R .layout.select_dialog_singlechoice, null )
950912 val radioGroup = android.widget.RadioGroup (this ).apply {
951913 orientation = android.widget.RadioGroup .VERTICAL
952914 setPadding(50 , 20 , 50 , 20 )
@@ -1039,12 +1001,12 @@ class SettingsActivity : AppCompatActivity() {
10391001 progressDialog.dismiss()
10401002
10411003 if (result.success) {
1042- val message = result.message ? : " Wiederhergestellt: ${result.imported_notes } Notizen"
1004+ val message = result.message ? : " Wiederhergestellt: ${result.importedNotes } Notizen"
10431005 showToast(" ✅ $message " )
10441006
10451007 // Refresh MainActivity's note list
10461008 setResult(RESULT_OK )
1047- broadcastNotesChanged(result.imported_notes )
1009+ broadcastNotesChanged(result.importedNotes )
10481010 } else {
10491011 showErrorDialog(" Wiederherstellung fehlgeschlagen" , result.error ? : " Unbekannter Fehler" )
10501012 }
@@ -1153,10 +1115,16 @@ class SettingsActivity : AppCompatActivity() {
11531115 progressDialog.dismiss()
11541116
11551117 // Erfolgs-Nachricht
1156- val message = " ✅ Sync abgeschlossen\n 📤 ${result.exportedCount} exportiert\n 📥 ${result.importedCount} importiert"
1118+ val message = " ✅ Sync abgeschlossen\n " +
1119+ " 📤 ${result.exportedCount} exportiert\n " +
1120+ " 📥 ${result.importedCount} importiert"
11571121 showToast(message)
11581122
1159- Logger .d(" SettingsActivity" , " Manual markdown sync: exported=${result.exportedCount} , imported=${result.importedCount} " )
1123+ Logger .d(
1124+ " SettingsActivity" ,
1125+ " Manual markdown sync: exported=${result.exportedCount} , " +
1126+ " imported=${result.importedCount} "
1127+ )
11601128
11611129 } catch (e: Exception ) {
11621130 progressDialog?.dismiss()
0 commit comments