Commit 472ba8eb by Paktalin

Only one word can be edited in a time

parent c4e730c5
......@@ -6,7 +6,9 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.text.TextUtils
import android.widget.Toast
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import kotlinx.android.synthetic.main.content_main.*
val progressFragment: Fragment = ProgressFragment()
......@@ -35,6 +37,14 @@ fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context:
return true
}
fun disableScrolling(mainActivity: MainActivity) {
mainActivity.scrollView!!.setScrollingEnabled(false)
}
fun enableScrolling(mainActivity: MainActivity) {
mainActivity.scrollView!!.setScrollingEnabled(true)
}
fun shortToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
\ No newline at end of file
package com.paktalin.vocabularynotebook;
public class Random {
}
......@@ -62,7 +62,7 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
if (it.itemId == R.id.option_edit) { editWord(v, displayedVocabulary.getAt(position)) }
true
}
popup.show()
if (EditWordFragment.notInEditMode) popup.show()
}
private fun deleteWord(position: Int) {
......@@ -95,15 +95,17 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
@SuppressLint("ResourceType")
private fun editWord(container: View, wordItem: WordItem) {
//set container id
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
container.id = View.generateViewId()
} else container.id = 18071999
// start EditWordFragment
val arguments = Bundle()
arguments.putSerializable("wordItem", wordItem)
addFragment(mainActivity.supportFragmentManager, EditWordFragment(), container.id, arguments)
if (EditWordFragment.notInEditMode) {
//set container id
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
container.id = View.generateViewId()
} else container.id = 18071999
// start EditWordFragment
val arguments = Bundle()
arguments.putSerializable("wordItem", wordItem)
addFragment(mainActivity.supportFragmentManager, EditWordFragment(), container.id, arguments)
}
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
......
......@@ -7,13 +7,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.*
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import com.paktalin.vocabularynotebook.removeFragment
import com.paktalin.vocabularynotebook.shortToast
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.content_main.*
......@@ -23,6 +21,7 @@ class EditWordFragment : WordFragment() {
private lateinit var wordItem: WordItem
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
notInEditMode = false
mainActivity = activity as MainActivity
hidePreviousViews(container)
wordItem = arguments!!["wordItem"] as WordItem
......@@ -32,6 +31,7 @@ class EditWordFragment : WordFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setWordItemData()
disableScrolling(mainActivity)
setFocusOnWord()
}
......@@ -39,7 +39,6 @@ class EditWordFragment : WordFragment() {
word.setText(wordItem.pojo.word)
translation.setText(wordItem.pojo.translation)
editable_word.setBackgroundColor(resources.getColor(R.color.green_highlight))
disableScrolling()
}
private fun setFocusOnWord() {
......@@ -79,11 +78,9 @@ class EditWordFragment : WordFragment() {
private fun stop() {
// set onClickListener from AddWordFragment
mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() }
enableScrolling(mainActivity)
removeFragment(mainActivity.supportFragmentManager, this)
}
private fun disableScrolling() {
mainActivity.scrollView!!.setScrollingEnabled(false)
notInEditMode = true
}
override fun updateRecycleView(wordItem: WordItem) {
......@@ -92,5 +89,6 @@ class EditWordFragment : WordFragment() {
companion object {
private val TAG = "VN/" + EditWordFragment::class.java.simpleName
var notInEditMode = true
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCAB
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import kotlinx.android.synthetic.main.fragment_vocabulary.*
class VocabularyFragment : Fragment() {
......
package com.paktalin.vocabularynotebook
package com.paktalin.vocabularynotebook.ui.views
import android.content.Context
import android.support.v7.widget.LinearLayoutManager
......
package com.paktalin.vocabularynotebook
package com.paktalin.vocabularynotebook.ui.views
import android.content.Context
import android.util.AttributeSet
......
......@@ -31,7 +31,7 @@
android:layout_height="wrap_content"/>
</FrameLayout>
<com.paktalin.vocabularynotebook.LockableScrollView
<com.paktalin.vocabularynotebook.ui.views.LockableScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
......@@ -58,7 +58,7 @@
android:paddingBottom="@dimen/small_padding">
</LinearLayout>
</com.paktalin.vocabularynotebook.LockableScrollView>
</com.paktalin.vocabularynotebook.ui.views.LockableScrollView>
<LinearLayout
android:id="@+id/btnSubmitLayout"
......
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