Commit 9f71b0c0 by Paktalin

Selection is only shown and tagFragment is added if not in edit mode

parent 6917a770
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -12,6 +12,8 @@ import androidx.appcompat.widget.SearchView ...@@ -12,6 +12,8 @@ import androidx.appcompat.widget.SearchView
import androidx.recyclerview.selection.Selection import androidx.recyclerview.selection.Selection
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.fragments.SubmitAddedFragment import com.paktalin.vocabularynotebook.ui.fragments.SubmitAddedFragment
import com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter import com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker import com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
...@@ -26,6 +28,7 @@ class MainActivity : AppCompatActivity() { ...@@ -26,6 +28,7 @@ class MainActivity : AppCompatActivity() {
var searchView: SearchView? = null var searchView: SearchView? = null
lateinit var vocabularyAdapter: VocabularyAdapter lateinit var vocabularyAdapter: VocabularyAdapter
private var tagFragment = TagFragment()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -132,13 +135,14 @@ class MainActivity : AppCompatActivity() { ...@@ -132,13 +135,14 @@ class MainActivity : AppCompatActivity() {
} }
private fun whenSelectionChanges(selection: Selection<Long>) { private fun whenSelectionChanges(selection: Selection<Long>) {
if (!selection.isEmpty) {
if (!selection.isEmpty && SubmitFragment.zeroInstances()) {
vocabularyAdapter.showPopupMenu = false vocabularyAdapter.showPopupMenu = false
Log.d(TAG, "selection ${selection.toList()}") tagFragment.setSelection(selection.toList())
addTagFragment(supportFragmentManager, R.id.main_activity_container) addFragment(supportFragmentManager, tagFragment, R.id.main_activity_container)
} else { } else if (selection.isEmpty) {
vocabularyAdapter.showPopupMenu = true vocabularyAdapter.showPopupMenu = true
removeTagFragment(supportFragmentManager) removeFragment(supportFragmentManager, tagFragment)
} }
} }
......
...@@ -46,6 +46,10 @@ abstract class SubmitFragment : Fragment() { ...@@ -46,6 +46,10 @@ abstract class SubmitFragment : Fragment() {
companion object { companion object {
private val TAG = "VN/" + SubmitFragment::class.java.simpleName private val TAG = "VN/" + SubmitFragment::class.java.simpleName
var instances: Int = 0 private var instances: Int = 0
fun zeroInstances(): Boolean {
return instances == 0
}
} }
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ import android.view.ViewGroup ...@@ -7,6 +7,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment 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.removeTagFragment import com.paktalin.vocabularynotebook.utils.removeTagFragment
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.*
...@@ -25,6 +26,11 @@ class TagFragment : Fragment() { ...@@ -25,6 +26,11 @@ class TagFragment : Fragment() {
btnCancelTag.setOnClickListener { cancel() } btnCancelTag.setOnClickListener { cancel() }
} }
fun setSelection(selectionList: List<Long>) {
Log.d(TAG, "selection $selectionList")
}
private fun submit() { private fun submit() {
tag_et.text.toString().let { tag_et.text.toString().let {
if (it.isBlank()) if (it.isBlank())
......
...@@ -54,7 +54,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -54,7 +54,8 @@ 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) val wordItem = vocabulary.displayedAt(position)
selectionTracker.let { selectionTracker.let {
viewHolder.bind(wordItem, position, it.selected(position.toLong())) { view, p -> showPopupMenu(view, p) } viewHolder.bind(wordItem, position, it.selected(position.toLong()) && showPopupMenu)
{ view, p -> showPopupMenu(view, p) }
} }
this.viewHolder = viewHolder this.viewHolder = viewHolder
//todo set click listener to menu //todo set click listener to menu
...@@ -129,7 +130,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -129,7 +130,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
} }
fun addTagToSelected(tag: String) { fun addTagToSelected(tag: String) {
} }
companion object { companion object {
......
...@@ -38,7 +38,7 @@ fun addTagFragment(fragmentManager: FragmentManager, containerId: Int) { ...@@ -38,7 +38,7 @@ fun addTagFragment(fragmentManager: FragmentManager, containerId: Int) {
} }
fun addSubmitFragment(fragmentManager: FragmentManager, fragment: SubmitFragment, containerId: Int) { fun addSubmitFragment(fragmentManager: FragmentManager, fragment: SubmitFragment, containerId: Int) {
if (SubmitFragment.instances == 0) addFragment(fragmentManager, fragment, containerId) if (SubmitFragment.zeroInstances()) addFragment(fragmentManager, fragment, containerId)
} }
fun removeTagFragment(fragmentManager: FragmentManager) { fun removeTagFragment(fragmentManager: FragmentManager) {
......
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