Commit e1a5bbb4 by Paktalin

Refactoring in layouts

parent b1ca71d2
......@@ -5,6 +5,7 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
......@@ -37,4 +38,12 @@ fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context:
fun shortToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
fun show(view: View) {
view.visibility = View.VISIBLE
}
fun hide(view: View) {
view.visibility = View.INVISIBLE
}
\ No newline at end of file
......@@ -18,9 +18,9 @@ class LogInActivity : AppCompatActivity() {
setContentView(R.layout.activity_log_in)
mAuth = FirebaseAuth.getInstance()
btnLogIn!!.setOnClickListener({ logIn() })
btnSignUp!!.setOnClickListener({ signUp() })
btnRandomUser!!.setOnClickListener({ createRandomUser() })
btnLogIn!!.setOnClickListener { logIn() }
btnSignUp!!.setOnClickListener { signUp() }
btnRandomUser!!.setOnClickListener { createRandomUser() }
}
override fun onStart() {
......
......@@ -101,7 +101,7 @@ class MainActivity : AppCompatActivity() {
}
fun addProgressBar() {
addProgressBar(supportFragmentManager, R.id.container_main)
addProgressBar(supportFragmentManager, R.id.container_new_word)
}
fun removeProgressBar() {
......
......@@ -12,11 +12,11 @@ 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.hide
import com.paktalin.vocabularynotebook.removeFragment
import com.paktalin.vocabularynotebook.shortToast
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import kotlinx.android.synthetic.main.fragment_new_word.*
import kotlinx.android.synthetic.main.notebook_sheet.*
import kotlinx.android.synthetic.main.word_item.view.*
class EditWordFragment : WordFragment() {
......@@ -61,7 +61,7 @@ class EditWordFragment : WordFragment() {
.collection(WORDS).document(wordItem.id).set(wordPojo)
.addOnSuccessListener {
Log.i(TAG, "Successfully updated the word")
hideSubmitButton()
hide(btnSubmit)
mainActivity.removeProgressBar()
wordItem.pojo = wordPojo
updateRecycleView(wordItem)
......@@ -76,7 +76,7 @@ class EditWordFragment : WordFragment() {
private fun stop() {
// set onClickListener from AddWordFragment
mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() }
//mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentNewWord as AddWordFragment).submitWord() }
removeFragment(mainActivity.supportFragmentManager, this)
}
......
......@@ -9,9 +9,10 @@ import android.view.View
import android.view.ViewGroup
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.hide
import com.paktalin.vocabularynotebook.show
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import kotlinx.android.synthetic.main.fragment_new_word.*
import kotlinx.android.synthetic.main.notebook_sheet.*
abstract class WordFragment : Fragment() {
protected lateinit var mainActivity: MainActivity
......@@ -29,7 +30,8 @@ abstract class WordFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
mainActivity = activity as MainActivity
mainActivity.btnSubmit.setOnClickListener { submitWord() }
btnSubmit.setOnClickListener { submitWord() }
word.addTextChangedListener(textWatcher {
wordEmpty = word.text.isEmpty() })
......@@ -40,8 +42,8 @@ abstract class WordFragment : Fragment() {
}
open fun updateButtons() {
if (!wordEmpty && !translationEmpty) showSubmitButton()
if (wordEmpty || translationEmpty) hideSubmitButton()
if (!wordEmpty && !translationEmpty) show(btnSubmit)
if (wordEmpty || translationEmpty) hide(btnSubmit)
}
private fun textWatcher(setEmpty: () -> Unit): TextWatcher {
......@@ -52,13 +54,7 @@ abstract class WordFragment : Fragment() {
}
}
private fun showSubmitButton() {
mainActivity.btnSubmitLayout.visibility = View.VISIBLE }
protected fun hideSubmitButton() {
mainActivity.btnSubmitLayout.visibility = View.GONE }
fun submitWord() {
private fun submitWord() {
mainActivity.hideKeyboardNotFromActivity(mainActivity)
val word = word.text.toString()
......
......@@ -9,7 +9,7 @@
android:background="#66330E">
<FrameLayout
android:id="@+id/container_main"
android:id="@+id/container_new_word"
android:layout_width="match_parent"
android:layout_height="match_parent">
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent">
<ImageView
<android.support.constraint.ConstraintLayout
android:id="@+id/container_new_word"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
tools:ignore="ContentDescription" />
android:layout_marginEnd="@dimen/small_margin"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginTop="@dimen/small_margin"
android:paddingStart="@dimen/small_padding"
android:paddingLeft="@dimen/small_padding"
android:paddingEnd="@dimen/small_padding"
android:paddingRight="@dimen/small_padding"
android:paddingTop="@dimen/small_padding"
android:background="@drawable/sheet_top"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="@android:color/transparent">
<ImageView
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:src="@drawable/line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="ContentDescription" />
<EditText
android:id="@+id/word"
android:layout_width="0dp"
<ImageButton
android:id="@+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
android:hint="@string/hint_new_word"
android:inputType="text"
android:textSize="22sp"
app:fontFamily="@font/neucha"
android:textColor="#000F55"
tools:ignore="LabelFor" />
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close_icon"
tools:ignore="ContentDescription" />
<EditText
android:id="@+id/translation"
android:layout_width="0dp"
<LinearLayout
android:id="@+id/word_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="@string/hint_translation"
android:inputType="text"
android:textSize="22sp"
app:fontFamily="@font/neucha"
android:textColor="#000F55"
tools:ignore="LabelFor" />
</LinearLayout>
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="@android:color/transparent">
<ImageButton
android:id="@+id/btnClear"
android:layout_width="wrap_content"
<EditText
android:id="@+id/word"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="@string/hint_new_word"
android:inputType="text"
android:textSize="22sp"
app:fontFamily="@font/neucha"
android:textColor="#000F55"
tools:ignore="LabelFor" />
<EditText
android:id="@+id/translation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="@string/hint_translation"
android:inputType="text"
android:textSize="22sp"
app:fontFamily="@font/neucha"
android:textColor="#000F55"
tools:ignore="LabelFor" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/btnSubmitLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close_icon"
tools:ignore="ContentDescription" />
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent">
<ImageButton
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_margin="@dimen/small_margin"
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_done_icon"
tools:ignore="ContentDescription" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container_notebook_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/container_main"
<fragment
android:id="@+id/fragmentNewWord"
android:name="com.paktalin.vocabularynotebook.ui.fragments.AddWordFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/small_margin"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginTop="@dimen/small_margin"
android:paddingStart="@dimen/small_padding"
android:paddingLeft="@dimen/small_padding"
android:paddingEnd="@dimen/small_padding"
android:paddingRight="@dimen/small_padding"
android:paddingTop="@dimen/small_padding"
android:background="@drawable/sheet_top"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<fragment
android:id="@+id/fragmentAddWord"
android:name="com.paktalin.vocabularynotebook.ui.fragments.AddWordFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
android:layout_height="match_parent"/>
<ScrollView
android:layout_width="match_parent"
......@@ -42,7 +22,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/container_main"
app:layout_constraintTop_toBottomOf="@+id/container_new_word"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
......@@ -60,23 +40,4 @@
</ScrollView>
<FrameLayout
android:id="@+id/btnSubmitLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent">
<ImageButton
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_margin="@dimen/small_margin"
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_done_icon"
tools:ignore="ContentDescription" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
\ 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