Commit 9cb76de7 by Paktalin

Scroll to the edited position; freeze layout while editing

parent 40e11f55
...@@ -3,18 +3,25 @@ package com.paktalin.vocabularynotebook.ui.fragments ...@@ -3,18 +3,25 @@ package com.paktalin.vocabularynotebook.ui.fragments
import android.view.View import android.view.View
import android.widget.EditText import android.widget.EditText
import com.paktalin.vocabularynotebook.firestoreitems.WordPojo import com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import com.paktalin.vocabularynotebook.utils.gone import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.removeFragment import com.paktalin.vocabularynotebook.utils.removeFragment
import com.paktalin.vocabularynotebook.utils.showKeyboard import com.paktalin.vocabularynotebook.utils.showKeyboard
import com.paktalin.vocabularynotebook.utils.visible import com.paktalin.vocabularynotebook.utils.visible
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.word_item.* import kotlinx.android.synthetic.main.word_item.*
class SubmitEditedFragment : SubmitFragment() { class SubmitEditedFragment : SubmitFragment() {
private lateinit var clickableView: View private lateinit var clickableView: View
private lateinit var wordPojo: WordPojo private lateinit var wordPojo: WordPojo
private var recyclerViewPosition: Int = 0
override fun init() { override fun init() {
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).apply {
scrollToPositionWithOffset(recyclerViewPosition, 2)
isScrollEnabled = false
}
mainActivity.vocabularyAdapter.showPopupMenu = false mainActivity.vocabularyAdapter.showPopupMenu = false
visible(mainActivity.clickable_view) visible(mainActivity.clickable_view)
gone(clickableView) gone(clickableView)
...@@ -42,14 +49,20 @@ class SubmitEditedFragment : SubmitFragment() { ...@@ -42,14 +49,20 @@ class SubmitEditedFragment : SubmitFragment() {
gone(mainActivity.clickable_view) gone(mainActivity.clickable_view)
mainActivity.hideKeyboardNotFromActivity(mainActivity) mainActivity.hideKeyboardNotFromActivity(mainActivity)
mainActivity.vocabularyAdapter.showPopupMenu = true mainActivity.vocabularyAdapter.showPopupMenu = true
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).isScrollEnabled = true
removeFragment(mainActivity.supportFragmentManager, this) removeFragment(mainActivity.supportFragmentManager, this)
return return
} }
fun setData(wordEt: EditText, translationEt: EditText, wordPojo: WordPojo, clickableView: View) { fun setData(wordEt: EditText,
translationEt: EditText,
wordPojo: WordPojo,
clickableView: View,
recyclerViewPosition: Int) {
this.wordEt = wordEt this.wordEt = wordEt
this.translationEt = translationEt this.translationEt = translationEt
this.wordPojo = wordPojo this.wordPojo = wordPojo
this.clickableView = clickableView this.clickableView = clickableView
this.recyclerViewPosition = recyclerViewPosition
} }
} }
\ No newline at end of file
...@@ -67,7 +67,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -67,7 +67,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
popup.setOnMenuItemClickListener { popup.setOnMenuItemClickListener {
when (it.itemId) { when (it.itemId) {
R.id.option_delete -> deleteWord(vocabulary.displayedAt(position), position) R.id.option_delete -> deleteWord(vocabulary.displayedAt(position), position)
R.id.option_edit -> editWord(v, vocabulary.displayedAt(position)) R.id.option_edit -> editWord(v, position)
} }
true true
} }
...@@ -103,10 +103,14 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -103,10 +103,14 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
} }
@SuppressLint("ResourceType") @SuppressLint("ResourceType")
private fun editWord(container: View, wordPojo: WordPojo) { private fun editWord(container: View, wordPosition: Int) {
addSubmitFragment(mainActivity.supportFragmentManager, addSubmitFragment(mainActivity.supportFragmentManager,
SubmitEditedFragment().apply { SubmitEditedFragment().apply {
setData(container.word, container.translation, wordPojo, container.clickable_view) setData(container.word,
container.translation,
vocabulary.displayedAt(wordPosition),
container.clickable_view,
wordPosition)
}, },
R.id.main_activity_container) R.id.main_activity_container)
} }
......
...@@ -4,7 +4,7 @@ import android.content.Context ...@@ -4,7 +4,7 @@ import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
class LockableLayoutManager(context: Context) : LinearLayoutManager(context) { class LockableLayoutManager(context: Context) : LinearLayoutManager(context) {
private var isScrollEnabled = true var isScrollEnabled = true
override fun canScrollVertically(): Boolean { override fun canScrollVertically(): Boolean {
return isScrollEnabled && super.canScrollVertically() return isScrollEnabled && super.canScrollVertically()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment