mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-29 04:39:54 +00:00
Fix back pressing re-focus Search EditText
This commit is contained in:
parent
8d6b318e3b
commit
ffeecdf1ca
4 changed files with 10 additions and 21 deletions
|
@ -178,7 +178,7 @@ afterEvaluate {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
val navVersion = "2.3.5"
|
val navVersion = "2.8.9"
|
||||||
val roomVersion = "2.6.1"
|
val roomVersion = "2.6.1"
|
||||||
|
|
||||||
implementation("androidx.navigation:navigation-fragment-ktx:$navVersion")
|
implementation("androidx.navigation:navigation-fragment-ktx:$navVersion")
|
||||||
|
|
|
@ -31,8 +31,6 @@ import com.philkes.notallyx.R
|
||||||
import com.philkes.notallyx.data.NotallyDatabase
|
import com.philkes.notallyx.data.NotallyDatabase
|
||||||
import com.philkes.notallyx.data.model.BaseNote
|
import com.philkes.notallyx.data.model.BaseNote
|
||||||
import com.philkes.notallyx.data.model.Folder
|
import com.philkes.notallyx.data.model.Folder
|
||||||
import com.philkes.notallyx.data.model.Type
|
|
||||||
import com.philkes.notallyx.data.model.toText
|
|
||||||
import com.philkes.notallyx.databinding.ActivityMainBinding
|
import com.philkes.notallyx.databinding.ActivityMainBinding
|
||||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||||
import com.philkes.notallyx.presentation.activity.main.fragment.DisplayLabelFragment.Companion.EXTRA_DISPLAYED_LABEL
|
import com.philkes.notallyx.presentation.activity.main.fragment.DisplayLabelFragment.Companion.EXTRA_DISPLAYED_LABEL
|
||||||
|
@ -40,7 +38,6 @@ import com.philkes.notallyx.presentation.activity.main.fragment.NotallyFragment
|
||||||
import com.philkes.notallyx.presentation.activity.note.EditListActivity
|
import com.philkes.notallyx.presentation.activity.note.EditListActivity
|
||||||
import com.philkes.notallyx.presentation.activity.note.EditNoteActivity
|
import com.philkes.notallyx.presentation.activity.note.EditNoteActivity
|
||||||
import com.philkes.notallyx.presentation.add
|
import com.philkes.notallyx.presentation.add
|
||||||
import com.philkes.notallyx.presentation.applySpans
|
|
||||||
import com.philkes.notallyx.presentation.getQuantityString
|
import com.philkes.notallyx.presentation.getQuantityString
|
||||||
import com.philkes.notallyx.presentation.movedToResId
|
import com.philkes.notallyx.presentation.movedToResId
|
||||||
import com.philkes.notallyx.presentation.setCancelButton
|
import com.philkes.notallyx.presentation.setCancelButton
|
||||||
|
@ -78,7 +75,7 @@ class MainActivity : LockedActivity<ActivityMainBinding>() {
|
||||||
var getCurrentFragmentNotes: (() -> Collection<BaseNote>?)? = null
|
var getCurrentFragmentNotes: (() -> Collection<BaseNote>?)? = null
|
||||||
|
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
return navController.navigateUp(configuration)
|
return navController.navigateUp(configuration) || super.onSupportNavigateUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -489,7 +486,7 @@ class MainActivity : LockedActivity<ActivityMainBinding>() {
|
||||||
popExit = androidx.navigation.ui.R.anim.nav_default_pop_exit_anim
|
popExit = androidx.navigation.ui.R.anim.nav_default_pop_exit_anim
|
||||||
popEnter = androidx.navigation.ui.R.anim.nav_default_pop_enter_anim
|
popEnter = androidx.navigation.ui.R.anim.nav_default_pop_enter_anim
|
||||||
}
|
}
|
||||||
popUpTo(navController.graph.startDestination) { inclusive = false }
|
popUpTo(navController.graph.startDestinationId) { inclusive = false }
|
||||||
}
|
}
|
||||||
navController.navigate(id, null, options)
|
navController.navigate(id, null, options)
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,16 +208,6 @@ abstract class NotallyFragment : Fragment(), ItemListener {
|
||||||
navController.navigate(R.id.Search, bundle)
|
navController.navigate(R.id.Search, bundle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setOnFocusChangeListener { v, hasFocus ->
|
|
||||||
if (hasFocus && navController.currentDestination?.id != R.id.Search) {
|
|
||||||
val bundle =
|
|
||||||
Bundle().apply {
|
|
||||||
putSerializable(EXTRA_INITIAL_FOLDER, model.folder.value)
|
|
||||||
putSerializable(EXTRA_INITIAL_LABEL, model.currentLabel)
|
|
||||||
}
|
|
||||||
navController.navigate(R.id.Search, bundle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,28 +49,30 @@ open class EditTextWithWatcher(context: Context, attrs: AttributeSet) :
|
||||||
replaceWith = ReplaceWith("changeText/applyWithoutTextWatcher/..."),
|
replaceWith = ReplaceWith("changeText/applyWithoutTextWatcher/..."),
|
||||||
)
|
)
|
||||||
override fun getText(): Editable? {
|
override fun getText(): Editable? {
|
||||||
return super.getText()
|
return getTextSafe()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTextClone(): Editable {
|
fun getTextClone(): Editable {
|
||||||
return super.getText()!!.clone()
|
return getTextSafe().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun applyWithoutTextWatcher(
|
fun applyWithoutTextWatcher(
|
||||||
callback: EditTextWithWatcher.() -> Unit
|
callback: EditTextWithWatcher.() -> Unit
|
||||||
): Pair<Editable, Editable> {
|
): Pair<Editable, Editable> {
|
||||||
val textBefore = super.getText()!!.clone()
|
val textBefore = getTextClone()
|
||||||
val editTextWatcher = textWatcher
|
val editTextWatcher = textWatcher
|
||||||
editTextWatcher?.let { removeTextChangedListener(it) }
|
editTextWatcher?.let { removeTextChangedListener(it) }
|
||||||
callback()
|
callback()
|
||||||
editTextWatcher?.let { addTextChangedListener(it) }
|
editTextWatcher?.let { addTextChangedListener(it) }
|
||||||
return Pair(textBefore, super.getText()!!.clone())
|
return Pair(textBefore, getTextClone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeText(callback: (text: Editable) -> Unit): Pair<Editable, Editable> {
|
fun changeText(callback: (text: Editable) -> Unit): Pair<Editable, Editable> {
|
||||||
return applyWithoutTextWatcher { callback(super.getText()!!) }
|
return applyWithoutTextWatcher { callback(getTextSafe()!!) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getTextSafe() = super.getText() ?: Editable.Factory.getInstance().newEditable("")
|
||||||
|
|
||||||
fun focusAndSelect(
|
fun focusAndSelect(
|
||||||
start: Int = selectionStart,
|
start: Int = selectionStart,
|
||||||
end: Int = selectionEnd,
|
end: Int = selectionEnd,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue