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
import android.view.View
import android.widget.EditText
import com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.removeFragment
import com.paktalin.vocabularynotebook.utils.showKeyboard
import com.paktalin.vocabularynotebook.utils.visible
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.word_item.*
class SubmitEditedFragment : SubmitFragment() {
private lateinit var clickableView: View
private lateinit var wordPojo: WordPojo
private var recyclerViewPosition: Int = 0
override fun init() {
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).apply {
scrollToPositionWithOffset(recyclerViewPosition, 2)
isScrollEnabled = false
}
mainActivity.vocabularyAdapter.showPopupMenu = false
visible(mainActivity.clickable_view)
gone(clickableView)
......@@ -42,14 +49,20 @@ class SubmitEditedFragment : SubmitFragment() {
gone(mainActivity.clickable_view)
mainActivity.hideKeyboardNotFromActivity(mainActivity)
mainActivity.vocabularyAdapter.showPopupMenu = true
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).isScrollEnabled = true
removeFragment(mainActivity.supportFragmentManager, this)
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.translationEt = translationEt
this.wordPojo = wordPojo
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
popup.setOnMenuItemClickListener {
when (it.itemId) {
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
}
......@@ -103,10 +103,14 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
@SuppressLint("ResourceType")
private fun editWord(container: View, wordPojo: WordPojo) {
private fun editWord(container: View, wordPosition: Int) {
addSubmitFragment(mainActivity.supportFragmentManager,
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)
}
......
......@@ -4,7 +4,7 @@ import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
class LockableLayoutManager(context: Context) : LinearLayoutManager(context) {
private var isScrollEnabled = true
var isScrollEnabled = true
override fun canScrollVertically(): Boolean {
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