Commit 148396ff by Paktalin

Added more editing restrictions

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