diff --git a/app-common/src/main/java/eu/darken/octi/common/preferences/CleanInputEditTextPreference.kt b/app-common/src/main/java/eu/darken/octi/common/preferences/CleanInputEditTextPreference.kt new file mode 100644 index 00000000..13ed9499 --- /dev/null +++ b/app-common/src/main/java/eu/darken/octi/common/preferences/CleanInputEditTextPreference.kt @@ -0,0 +1,39 @@ +package eu.darken.octi.common.preferences + +import android.content.Context +import android.text.InputFilter +import android.util.AttributeSet +import android.view.inputmethod.EditorInfo +import androidx.preference.EditTextPreference + +class CleanInputEditTextPreference @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = androidx.preference.R.attr.editTextPreferenceStyle +) : EditTextPreference(context, attrs, defStyleAttr) { + + init { + setOnBindEditTextListener { editText -> + editText.apply { + isSingleLine = true + maxLines = 1 + imeOptions = EditorInfo.IME_ACTION_DONE + filters = arrayOf( + InputFilter { source, start, end, dest, dstart, dend -> + for (i in start until end) { + if (source[i] == '\n' || source[i] == '\r') { + return@InputFilter "" + } + } + null + } + ) + } + } + } + + override fun persistString(value: String?): Boolean { + val trimmedValue = value?.trim() + return super.persistString(trimmedValue) + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/darken/octi/sync/ui/settings/SyncSettingsFragment.kt b/app/src/main/java/eu/darken/octi/sync/ui/settings/SyncSettingsFragment.kt index 4addfb48..aa3cf855 100644 --- a/app/src/main/java/eu/darken/octi/sync/ui/settings/SyncSettingsFragment.kt +++ b/app/src/main/java/eu/darken/octi/sync/ui/settings/SyncSettingsFragment.kt @@ -9,6 +9,7 @@ import androidx.preference.Preference import dagger.hilt.android.AndroidEntryPoint import eu.darken.octi.R import eu.darken.octi.common.uix.PreferenceFragment3 +import eu.darken.octi.sync.core.SyncSettings import javax.inject.Inject @Keep @@ -17,8 +18,8 @@ class SyncSettingsFragment : PreferenceFragment3() { override val vm: SyncSettingsVM by viewModels() - @Inject lateinit var _syncSettings: eu.darken.octi.sync.core.SyncSettings - override val settings: eu.darken.octi.sync.core.SyncSettings by lazy { _syncSettings } + @Inject lateinit var _syncSettings: SyncSettings + override val settings: SyncSettings by lazy { _syncSettings } override val preferenceFile: Int = R.xml.preferences_sync override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/res/xml/preferences_sync.xml b/app/src/main/res/xml/preferences_sync.xml index 67fab54f..64cf664d 100644 --- a/app/src/main/res/xml/preferences_sync.xml +++ b/app/src/main/res/xml/preferences_sync.xml @@ -2,7 +2,7 @@ -