Commit 9b78a83f by Paktalin

Tag is added to the selected words

parent 7fb927f7
...@@ -7,13 +7,13 @@ import android.view.ViewGroup ...@@ -7,13 +7,13 @@ 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.removeFragment 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.*
class TagFragment : Fragment() { class TagFragment : Fragment() {
private lateinit var mainActivity: MainActivity private lateinit var mainActivity: MainActivity
private var selectionList = mutableListOf<Long>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_tag, container, false) return inflater.inflate(R.layout.fragment_tag, container, false)
...@@ -27,8 +27,7 @@ class TagFragment : Fragment() { ...@@ -27,8 +27,7 @@ class TagFragment : Fragment() {
} }
fun setSelection(selectionList: List<Long>) { fun setSelection(selectionList: List<Long>) {
Log.d(TAG, "selection $selectionList") this.selectionList = selectionList.toMutableList()
} }
private fun submit() { private fun submit() {
...@@ -36,7 +35,7 @@ class TagFragment : Fragment() { ...@@ -36,7 +35,7 @@ class TagFragment : Fragment() {
if (it.isBlank()) if (it.isBlank())
shortToast(mainActivity, mainActivity.getString(R.string.toast_tag_cannot_be_empty)) shortToast(mainActivity, mainActivity.getString(R.string.toast_tag_cannot_be_empty))
else else
mainActivity.vocabularyAdapter?.addTagToSelected(it) mainActivity.vocabularyAdapter?.addTagToSelected(it, selectionList)
} }
} }
......
...@@ -139,7 +139,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi ...@@ -139,7 +139,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
return vocabulary.getModified() return vocabulary.getModified()
} }
fun addTagToSelected(tag: String) { fun addTagToSelected(tag: String, selectionList: MutableList<Long>) {
vocabulary.addTag(selectionList, tag)
} }
companion object { companion object {
......
...@@ -17,7 +17,7 @@ import org.apache.commons.lang3.StringUtils ...@@ -17,7 +17,7 @@ import org.apache.commons.lang3.StringUtils
val progressFragment = ProgressFragment() val progressFragment = ProgressFragment()
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 (fragmentManager.findFragmentById(fragment.id) == null && !fragment.isAdded)
fragmentManager.beginTransaction() fragmentManager.beginTransaction()
.add(containerId, fragment.apply { arguments = arg }, tag) .add(containerId, fragment.apply { arguments = arg }, tag)
.commitAllowingStateLoss() .commitAllowingStateLoss()
......
...@@ -25,6 +25,8 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary { ...@@ -25,6 +25,8 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
(snapshot["time"] as Timestamp).toDate(), (snapshot["time"] as Timestamp).toDate(),
snapshot.id) snapshot.id)
} }
private val TAG = "VN/" + VocabSet::class.java.simpleName
} }
override fun addAll(words: MutableList<WordPojo>) { override fun addAll(words: MutableList<WordPojo>) {
...@@ -63,11 +65,22 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary { ...@@ -63,11 +65,22 @@ class VocabSet(var wordList: MutableList<WordPojo>) : Vocabulary {
return displayedVocabulary.at(position) return displayedVocabulary.at(position)
} }
fun displayedSize():Int { return displayedVocabulary.size() } fun displayedSize(): Int {
return displayedVocabulary.size()
}
fun clearDisplayed() { displayedVocabulary.clear() } fun clearDisplayed() {
displayedVocabulary.clear()
}
fun getModified(): MutableMap<WordPojo, Boolean> { fun getModified(): MutableMap<WordPojo, Boolean> {
return modifiedVocabulary.get() return modifiedVocabulary.get()
} }
fun addTag(selectionList: MutableList<Long>, tag: String) {
selectionList.forEach { position ->
displayedAt(position.toInt()).tag = tag
modifiedVocabulary.addWord(displayedAt(position.toInt()))
}
}
} }
\ No newline at end of file
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