Commit 148396ff by Paktalin

Added more editing restrictions

parent 9f71b0c0
......@@ -137,11 +137,10 @@ class MainActivity : AppCompatActivity() {
private fun whenSelectionChanges(selection: Selection<Long>) {
if (!selection.isEmpty && SubmitFragment.zeroInstances()) {
vocabularyAdapter.showPopupMenu = false
tagFragment.setSelection(selection.toList())
addFragment(supportFragmentManager, tagFragment, R.id.main_activity_container)
} else if (selection.isEmpty) {
vocabularyAdapter.showPopupMenu = true
vocabularyAdapter.editAllowed = true
removeFragment(supportFragmentManager, tagFragment)
}
}
......
......@@ -7,7 +7,7 @@ import kotlinx.android.synthetic.main.word_item.*
class SubmitAddedFragment : SubmitFragment() {
override fun init() {
mainActivity.vocabularyAdapter.showPopupMenu = false
mainActivity.vocabularyAdapter.editAllowed = false
wordEt = mainActivity.word
translationEt = mainActivity.translation
}
......@@ -27,7 +27,7 @@ class SubmitAddedFragment : SubmitFragment() {
override fun finish() {
wordEt.text.clear()
translationEt.text.clear()
mainActivity.vocabularyAdapter.showPopupMenu = true
mainActivity.vocabularyAdapter.editAllowed = true
removeFragment(mainActivity.supportFragmentManager, this)
return
}
......
......@@ -9,7 +9,6 @@ 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() {
......@@ -22,8 +21,7 @@ class SubmitEditedFragment : SubmitFragment() {
scrollToPositionWithOffset(recyclerViewPosition, 2)
isScrollEnabled = false
}
mainActivity.vocabularyAdapter.showPopupMenu = false
visible(mainActivity.clickable_view)
mainActivity.vocabularyAdapter.editAllowed = false
gone(clickableView)
wordEt.requestFocus()
wordEt.setSelection(wordEt.text.length)
......@@ -47,9 +45,8 @@ class SubmitEditedFragment : SubmitFragment() {
wordEt.clearFocus()
translationEt.clearFocus()
visible(clickableView)
gone(mainActivity.clickable_view)
mainActivity.hideKeyboardNotFromActivity(mainActivity)
mainActivity.vocabularyAdapter.showPopupMenu = true
mainActivity.vocabularyAdapter.editAllowed = true
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).isScrollEnabled = true
removeFragment(mainActivity.supportFragmentManager, this)
return
......
......@@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.utils.Log
import com.paktalin.vocabularynotebook.utils.removeTagFragment
import com.paktalin.vocabularynotebook.utils.removeFragment
import com.paktalin.vocabularynotebook.utils.shortToast
import kotlinx.android.synthetic.main.fragment_tag.*
......@@ -42,7 +42,7 @@ class TagFragment : Fragment() {
private fun cancel() {
mainActivity.vocabularyAdapter.selectionTracker.clearSelection()
removeTagFragment(mainActivity.supportFragmentManager)
removeFragment(mainActivity.supportFragmentManager, this)
}
companion object {
......
package com.paktalin.vocabularynotebook.ui.recycler_view
enum class State {
EDIT,
ADD,
TAG,
NOTHING
}
\ No newline at end of file
......@@ -13,7 +13,10 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val tvWord: EditText = itemView.word
private val tvTranslation: EditText = itemView.translation
fun bind(wordPojo: WordPojo, position: Int, isActivated: Boolean, showPopupMenu: (View, Int) -> Unit) {
fun bind(wordPojo: WordPojo,
position: Int,
isActivated: Boolean,
showPopupMenu: (View, Int) -> Unit) {
tvWord.setText(wordPojo.word)
tvTranslation.setText(wordPojo.translation)
visible(itemView.clickable_view)
......
......@@ -13,16 +13,24 @@ import com.paktalin.vocabularynotebook.ui.fragments.SubmitEditedFragment
import com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import com.paktalin.vocabularynotebook.utils.Log
import com.paktalin.vocabularynotebook.utils.addSubmitFragment
import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.visible
import com.paktalin.vocabularynotebook.vocabulary.Sort
import com.paktalin.vocabularynotebook.vocabulary.VocabSet
import kotlinx.android.synthetic.main.word_item.*
import kotlinx.android.synthetic.main.word_item.view.*
class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivity: MainActivity) : RecyclerView.Adapter<ViewHolder>() {
private lateinit var recyclerView: RecyclerView
private lateinit var viewHolder: ViewHolder
lateinit var selectionTracker: MySelectionTracker
var showPopupMenu = true
var editAllowed = true
set(value) {
if (!value) visible(mainActivity.clickable_view)
else gone(mainActivity.clickable_view)
Log.d(TAG, "editAllowed $editAllowed")
field = value
}
init {
setHasStableIds(true)
......@@ -52,17 +60,15 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val wordItem = vocabulary.displayedAt(position)
selectionTracker.let {
viewHolder.bind(wordItem, position, it.selected(position.toLong()) && showPopupMenu)
{ view, p -> showPopupMenu(view, p) }
}
this.viewHolder = viewHolder
//todo set click listener to menu
viewHolder.bind(
vocabulary.displayedAt(position),
position,
selectionTracker.selected(position.toLong())) { view, p -> showPopupMenu(view, p) }
// TODO not allow to edit when tag is being selected
}
private fun showPopupMenu(v: View, position: Int) {
if (showPopupMenu) {
if (editAllowed) {
val popup = PopupMenu(mainActivity, v)
popup.menuInflater.inflate(R.menu.word_item_menu, popup.menu)
popup.setOnMenuItemClickListener {
......
......@@ -12,11 +12,9 @@ import androidx.fragment.app.FragmentManager
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import org.apache.commons.lang3.StringUtils
val progressFragment = ProgressFragment()
val tagFragment = TagFragment()
fun addFragment(fragmentManager: FragmentManager, fragment: Fragment, containerId: Int, arg: Bundle? = null, tag: String? = null) {
if (!fragment.isAdded)
......@@ -33,18 +31,10 @@ fun addProgressBar(fragmentManager: FragmentManager, containerId: Int) {
addFragment(fragmentManager, progressFragment, containerId)
}
fun addTagFragment(fragmentManager: FragmentManager, containerId: Int) {
addFragment(fragmentManager, tagFragment, containerId)
}
fun addSubmitFragment(fragmentManager: FragmentManager, fragment: SubmitFragment, containerId: Int) {
if (SubmitFragment.zeroInstances()) addFragment(fragmentManager, fragment, containerId)
}
fun removeTagFragment(fragmentManager: FragmentManager) {
removeFragment(fragmentManager, tagFragment)
}
fun removeProgressBar(fragmentManager: FragmentManager) {
removeFragment(fragmentManager, progressFragment)
}
......
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