Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c4329ccd
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
a046a823
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
25 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/res/layout/notebook_sheet.xml
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
c4329ccd
...
...
@@ -13,6 +13,7 @@ import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
kotlinx.android.synthetic.main.word_item.view.*
class
VocabularyAdapter
(
private
val
vocabulary
:
Vocabulary
,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
...
...
@@ -98,9 +99,9 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
val
tvWord
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
word
)
val
tvTranslation
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
translation
)
val
layout
:
LinearLayout
=
itemView
.
findViewById
(
R
.
id
.
layout
)
val
tvWord
:
TextView
=
itemView
.
word
val
tvTranslation
:
TextView
=
itemView
.
translation
val
layout
:
LinearLayout
=
itemView
.
layout
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
c4329ccd
...
...
@@ -7,14 +7,12 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.inputmethod.InputMethodManager
import
android.widget.ImageButton
import
android.widget.ImageView
import
android.widget.TextView
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
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
()
{
private
lateinit
var
wordItem
:
WordItem
...
...
@@ -45,9 +43,9 @@ class EditWordFragment : WordFragment() {
private
fun
hidePreviousViews
(
container
:
ViewGroup
?)
{
if
(
container
!=
null
)
{
container
.
findViewById
<
ImageView
>(
R
.
id
.
line
)
.
visibility
=
View
.
GONE
container
.
findViewById
<
TextView
>(
R
.
id
.
word
)
.
visibility
=
View
.
GONE
container
.
findViewById
<
TextView
>(
R
.
id
.
translation
)
.
visibility
=
View
.
GONE
container
.
line
.
visibility
=
View
.
GONE
container
.
word
.
visibility
=
View
.
GONE
container
.
translation
.
visibility
=
View
.
GONE
}
}
...
...
@@ -62,18 +60,26 @@ class EditWordFragment : WordFragment() {
mainActivity
.
hideProgressBar
()
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
// set onClickListener from AddWordFragment
mainActivity
.
findViewById
<
ImageButton
>(
R
.
id
.
btnAddWord
).
setOnClickListener
{
(
mainActivity
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_new_word
)
as
AddWordFragment
).
submitWord
()}
mainActivity
.
removeFragment
(
this
@EditWordFragment
)
}
stop
()
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
mainActivity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
Toast
.
makeText
(
mainActivity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()
stop
()
}
}
private
fun
stop
()
{
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragmentNewWord
as
AddWordFragment
).
submitWord
()
}
mainActivity
.
removeFragment
(
this
)
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
mainActivity
.
vocabularyFragment
.
updateWordItem
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
EditWordFragment
::
class
.
java
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
EditWordFragment
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
c4329ccd
...
...
@@ -7,11 +7,10 @@ import android.text.TextWatcher
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.FrameLayout
import
android.widget.ImageButton
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
kotlinx.android.synthetic.main.fragment_new_word.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
abstract
class
WordFragment
:
Fragment
()
{
...
...
@@ -20,7 +19,6 @@ abstract class WordFragment : Fragment() {
const
val
WORDS
=
"words"
}
protected
lateinit
var
mainActivity
:
MainActivity
open
var
TAG
=
WordFragment
::
class
.
simpleName
private
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
...
...
@@ -35,7 +33,7 @@ abstract class WordFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
findViewById
<
ImageButton
>(
R
.
id
.
btnAddWord
)
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnSubmit
.
setOnClickListener
{
submitWord
()
}
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
...
...
@@ -65,10 +63,10 @@ abstract class WordFragment : Fragment() {
}
private
fun
showSubmitButton
()
{
mainActivity
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
)
.
visibility
=
View
.
VISIBLE
}
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
VISIBLE
}
protected
fun
hideSubmitButton
()
{
mainActivity
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
)
.
visibility
=
View
.
GONE
}
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
GONE
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
...
...
app/src/main/res/layout/notebook_sheet.xml
View file @
c4329ccd
...
...
@@ -25,7 +25,7 @@
android:orientation=
"vertical"
>
<fragment
android:id=
"@+id/fragment
_new_w
ord"
android:id=
"@+id/fragment
NewW
ord"
android:name=
"com.paktalin.vocabularynotebook.ui.AddWordFragment"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
...
...
@@ -44,7 +44,7 @@
app:layout_constraintBottom_toBottomOf=
"parent"
>
<ImageButton
android:id=
"@+id/btn
AddWord
"
android:id=
"@+id/btn
Submit
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"end"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment