Commit 2537be11 by Paktalin

New word is extracted to fragment

parent 6124010d
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
<option name="values"> <option name="values">
<map> <map>
<entry key="assetSourceType" value="FILE" /> <entry key="assetSourceType" value="FILE" />
<entry key="outputName" value="ic_cancel_icon" /> <entry key="outputName" value="ic_done_icon" />
<entry key="sourceFile" value="C:\Users\litak\Desktop\cancel_icon.svg" /> <entry key="sourceFile" value="C:\Users\litak\Desktop\done_icon.svg" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>
......
package com.paktalin.vocabularynotebook
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class NewWordFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_new_word, container, false)
}
}
\ No newline at end of file
...@@ -15,14 +15,5 @@ class Utils { ...@@ -15,14 +15,5 @@ class Utils {
} }
return true return true
} }
fun setEmptyEditText(et:EditText, hint:String) {
et.isClickable = true
et.isFocusable = true
et.isFocusableInTouchMode = true
et.isCursorVisible = true
et.hint = hint
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) et.background = null
}
} }
} }
\ No newline at end of file
...@@ -5,34 +5,43 @@ import android.text.Editable ...@@ -5,34 +5,43 @@ import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.EditText
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val etWord: EditText = itemView.findViewById(R.id.etWord) val tvWord: TextView = itemView.findViewById(R.id.etWord)
val etTranslation: EditText = itemView.findViewById(R.id.etTranslation) val tvTranslation: TextView = itemView.findViewById(R.id.etTranslation)
val btnPopupMenu: ImageButton = itemView.findViewById(R.id.btnContextMenu) val btnPopupMenu: ImageButton = itemView.findViewById(R.id.btnContextMenu)
val layout: LinearLayout = itemView.findViewById(R.id.tableLayout) val layout: LinearLayout = itemView.findViewById(R.id.tableLayout)
private var etWordEmpty = true
private var etTranslationEmpty = true
fun showEmptyItem() { fun showEmptyItem() {
btnPopupMenu.isClickable = false tvWord.addTextChangedListener(object : TextWatcher {
btnPopupMenu.visibility = View.INVISIBLE
Utils.setEmptyEditText(etWord, "new word")
Utils.setEmptyEditText(etTranslation, "translation")
etWord.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { } override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { } override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun afterTextChanged(editable: Editable) { override fun afterTextChanged(editable: Editable) {
if (!etWord.text.isEmpty()) showCancelButton() } if (!tvWord.text.isEmpty()) {
showCancelButton()
etWordEmpty = false
} else etWordEmpty = true
if (!etWordEmpty && !etTranslationEmpty)
showAddWordButton()
}
}) })
this.etTranslation.addTextChangedListener(object : TextWatcher { this.tvTranslation.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { } override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { } override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) { }
override fun afterTextChanged(editable: Editable) { override fun afterTextChanged(editable: Editable) {
if (!etTranslation.text.isEmpty()) showCancelButton() } if (!tvTranslation.text.isEmpty()) {
showCancelButton()
etTranslationEmpty = false
} else etTranslationEmpty = true
if (!etWordEmpty && !etTranslationEmpty)
showAddWordButton()
}
}) })
} }
...@@ -43,5 +52,9 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { ...@@ -43,5 +52,9 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
//todo add button click listener //todo add button click listener
} }
private fun showAddWordButton() {
//todo show add word button
}
companion object { private val TAG = "VN/" + ViewHolder::class.java.simpleName } companion object { private val TAG = "VN/" + ViewHolder::class.java.simpleName }
} }
\ No newline at end of file
...@@ -23,19 +23,16 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -23,19 +23,16 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if (position == 0) holder.showEmptyItem()
else {
val wordItem = wordItems[position] val wordItem = wordItems[position]
holder.etWord.setText(wordItem.pojo!!.word) holder.tvWord.text = wordItem.pojo!!.word
holder.etTranslation.setText(wordItem.pojo!!.translation) holder.tvTranslation.text = wordItem.pojo!!.translation
holder.layout.setOnClickListener{ openWordItemInfo(wordItem) } holder.layout.setOnClickListener { openWordItemInfo(wordItem) }
holder.etWord.setOnClickListener{ openWordItemInfo(wordItem) } holder.tvWord.setOnClickListener { openWordItemInfo(wordItem) }
holder.etTranslation.setOnClickListener{ openWordItemInfo(wordItem) } holder.tvTranslation.setOnClickListener { openWordItemInfo(wordItem) }
holder.btnPopupMenu.setOnClickListener { showPopupMenu(holder.btnPopupMenu, position) } holder.btnPopupMenu.setOnClickListener { showPopupMenu(holder.btnPopupMenu, position) }
//todo set click listener to menu //todo set click listener to menu
} }
}
override fun getItemCount(): Int { override fun getItemCount(): Int {
return wordItems.size return wordItems.size
...@@ -52,8 +49,11 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -52,8 +49,11 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
val inflater = popup.menuInflater val inflater = popup.menuInflater
inflater.inflate(R.menu.word_item_menu, popup.menu) inflater.inflate(R.menu.word_item_menu, popup.menu)
popup.setOnMenuItemClickListener { popup.setOnMenuItemClickListener {
if (it.itemId == R.id.item_delete) { deleteWordItem(position) } if (it.itemId == R.id.item_delete) {
true } deleteWordItem(position)
}
true
}
popup.show() popup.show()
} }
...@@ -65,7 +65,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -65,7 +65,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
this.notifyItemRangeChanged(position, wordItems.size) this.notifyItemRangeChanged(position, wordItems.size)
} }
companion object { private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName } companion object {
private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName
init { wordItems.add(0, WordItem.createEmpty()) } }
} }
\ No newline at end of file
...@@ -37,7 +37,6 @@ class VocabularyFragment : Fragment() { ...@@ -37,7 +37,6 @@ class VocabularyFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
setEmptyAdapter() setEmptyAdapter()
fabAddWord.setOnClickListener( { addWord() } )
retrieveData() retrieveData()
} }
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/etWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8"
android:background="@android:color/transparent"
android:inputType="text"
android:textSize="22sp"
android:hint="@string/hint_new_word"
tools:ignore="LabelFor" />
<EditText
android:id="@+id/etTranslation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8"
android:background="@android:color/transparent"
android:inputType="text"
android:textSize="22sp"
android:hint="@string/hint_translation"
tools:ignore="LabelFor" />
<ImageButton
android:id="@+id/btnContextMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_cancel_icon"
tools:ignore="ContentDescription" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.paktalin.vocabularynotebook.activities.VocabularyFragment"> tools:context="com.paktalin.vocabularynotebook.activities.VocabularyFragment">
<include layout="@layout/img_background"/> <include layout="@layout/img_background" />
<android.support.v7.widget.RecyclerView <fragment
android:id="@+id/recyclerView" android:id="@+id/fragment"
android:name="com.paktalin.vocabularynotebook.NewWordFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
...@@ -22,15 +23,17 @@ ...@@ -22,15 +23,17 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.FloatingActionButton <android.support.v7.widget.RecyclerView
android:id="@+id/fabAddWord" android:id="@+id/recyclerView"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginEnd="8dp"
android:layout_marginEnd="16dp" android:layout_marginLeft="8dp"
android:layout_marginRight="16dp" android:layout_marginRight="8dp"
android:src="@android:drawable/ic_input_add" android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fragment" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
...@@ -13,30 +13,20 @@ ...@@ -13,30 +13,20 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:padding="8dp"> android:padding="8dp">
<EditText <TextView
android:id="@+id/etWord" android:id="@+id/etWord"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="8" android:layout_weight="8"
android:background="@android:color/transparent"
android:cursorVisible="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="22sp" android:textSize="22sp"
tools:ignore="LabelFor" tools:ignore="LabelFor"
android:inputType="text" /> android:inputType="text" />
<EditText <TextView
android:id="@+id/etTranslation" android:id="@+id/etTranslation"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="8" android:layout_weight="8"
android:background="@android:color/transparent"
android:cursorVisible="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="22sp" android:textSize="22sp"
tools:ignore="LabelFor" tools:ignore="LabelFor"
android:inputType="text"/> android:inputType="text"/>
......
...@@ -9,4 +9,6 @@ ...@@ -9,4 +9,6 @@
<string name="tv_translation">Translation</string> <string name="tv_translation">Translation</string>
<string name="btn_save">Save</string> <string name="btn_save">Save</string>
<string name="btn_cancel">Cancel</string> <string name="btn_cancel">Cancel</string>
<string name="hint_new_word">new word</string>
<string name="hint_translation">translation</string>
</resources> </resources>
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