Commit 4467b7c0 by Paktalin

Name refactoring

parent e1a5bbb4
...@@ -8,7 +8,7 @@ import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCAB ...@@ -8,7 +8,7 @@ import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCAB
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import com.paktalin.vocabularynotebook.firestoreitems.WordItem import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.shortToast import com.paktalin.vocabularynotebook.shortToast
import kotlinx.android.synthetic.main.fragment_new_word.* import kotlinx.android.synthetic.main.fragment_editable_word.*
class AddWordFragment : WordFragment() { class AddWordFragment : WordFragment() {
......
...@@ -12,11 +12,11 @@ import com.paktalin.vocabularynotebook.firestoreitems.WordItem ...@@ -12,11 +12,11 @@ import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import com.paktalin.vocabularynotebook.hide
import com.paktalin.vocabularynotebook.removeFragment import com.paktalin.vocabularynotebook.removeFragment
import com.paktalin.vocabularynotebook.shortToast import com.paktalin.vocabularynotebook.shortToast
import com.paktalin.vocabularynotebook.ui.activities.MainActivity import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import kotlinx.android.synthetic.main.fragment_new_word.* import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.word_item.view.* import kotlinx.android.synthetic.main.word_item.view.*
class EditWordFragment : WordFragment() { class EditWordFragment : WordFragment() {
...@@ -61,7 +61,7 @@ class EditWordFragment : WordFragment() { ...@@ -61,7 +61,7 @@ class EditWordFragment : WordFragment() {
.collection(WORDS).document(wordItem.id).set(wordPojo) .collection(WORDS).document(wordItem.id).set(wordPojo)
.addOnSuccessListener { .addOnSuccessListener {
Log.i(TAG, "Successfully updated the word") Log.i(TAG, "Successfully updated the word")
hide(btnSubmit) hideSubmitButton()
mainActivity.removeProgressBar() mainActivity.removeProgressBar()
wordItem.pojo = wordPojo wordItem.pojo = wordPojo
updateRecycleView(wordItem) updateRecycleView(wordItem)
...@@ -76,7 +76,7 @@ class EditWordFragment : WordFragment() { ...@@ -76,7 +76,7 @@ class EditWordFragment : WordFragment() {
private fun stop() { private fun stop() {
// set onClickListener from AddWordFragment // set onClickListener from AddWordFragment
//mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentNewWord as AddWordFragment).submitWord() } mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() }
removeFragment(mainActivity.supportFragmentManager, this) removeFragment(mainActivity.supportFragmentManager, this)
} }
......
...@@ -9,10 +9,9 @@ import android.view.View ...@@ -9,10 +9,9 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.firestoreitems.WordItem import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.hide
import com.paktalin.vocabularynotebook.show
import com.paktalin.vocabularynotebook.ui.activities.MainActivity import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import kotlinx.android.synthetic.main.fragment_new_word.* import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.content_main.*
abstract class WordFragment : Fragment() { abstract class WordFragment : Fragment() {
protected lateinit var mainActivity: MainActivity protected lateinit var mainActivity: MainActivity
...@@ -24,14 +23,13 @@ abstract class WordFragment : Fragment() { ...@@ -24,14 +23,13 @@ abstract class WordFragment : Fragment() {
set(value) { field = value; updateButtons() } set(value) { field = value; updateButtons() }
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_new_word, container, false) return inflater.inflate(R.layout.fragment_editable_word, container, false)
} }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
mainActivity = activity as MainActivity mainActivity = activity as MainActivity
mainActivity.btnSubmit.setOnClickListener { submitWord() }
btnSubmit.setOnClickListener { submitWord() }
word.addTextChangedListener(textWatcher { word.addTextChangedListener(textWatcher {
wordEmpty = word.text.isEmpty() }) wordEmpty = word.text.isEmpty() })
...@@ -42,8 +40,8 @@ abstract class WordFragment : Fragment() { ...@@ -42,8 +40,8 @@ abstract class WordFragment : Fragment() {
} }
open fun updateButtons() { open fun updateButtons() {
if (!wordEmpty && !translationEmpty) show(btnSubmit) if (!wordEmpty && !translationEmpty) showSubmitButton()
if (wordEmpty || translationEmpty) hide(btnSubmit) if (wordEmpty || translationEmpty) hideSubmitButton()
} }
private fun textWatcher(setEmpty: () -> Unit): TextWatcher { private fun textWatcher(setEmpty: () -> Unit): TextWatcher {
...@@ -54,7 +52,13 @@ abstract class WordFragment : Fragment() { ...@@ -54,7 +52,13 @@ abstract class WordFragment : Fragment() {
} }
} }
private fun submitWord() { private fun showSubmitButton() {
mainActivity.btnSubmitLayout.visibility = View.VISIBLE }
protected fun hideSubmitButton() {
mainActivity.btnSubmitLayout.visibility = View.GONE }
fun submitWord() {
mainActivity.hideKeyboardNotFromActivity(mainActivity) mainActivity.hideKeyboardNotFromActivity(mainActivity)
val word = word.text.toString() val word = word.text.toString()
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<include layout="@layout/notebook_sheet" /> <include layout="@layout/content_main" />
</FrameLayout> </FrameLayout>
<android.support.design.widget.NavigationView <android.support.design.widget.NavigationView
......
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