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
6b2e1892
authored
Nov 11, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Empty word items may be added as well
parent
41f1256d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
28 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
app/src/main/res/layout/content_main.xml
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
6b2e1892
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.os.Bundle
import
android.text.Editable
import
android.text.TextWatcher
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.utils.*
...
...
@@ -8,13 +10,25 @@ import kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.fragment_editable_word.*
class
AddWordFragment
:
WordFragment
()
{
private
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
private
var
translationEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
word
.
setOnTouchListener
{
_
,
_
->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
translation
.
setOnTouchListener
{
_
,
_
->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
translation
.
addTextChangedListener
(
textWatcher
{
translationEmpty
=
translation
.
text
.
isEmpty
()
})
}
override
fun
cancelEditing
()
{
...
...
@@ -35,8 +49,15 @@ class AddWordFragment : WordFragment() {
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
}
override
fun
updateButtons
()
{
super
.
updateButtons
()
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
return
object
:
TextWatcher
{
override
fun
beforeTextChanged
(
charSequence
:
CharSequence
,
i
:
Int
,
i1
:
Int
,
i2
:
Int
)
{
}
override
fun
onTextChanged
(
charSequence
:
CharSequence
,
i
:
Int
,
i1
:
Int
,
i2
:
Int
)
{
}
override
fun
afterTextChanged
(
editable
:
Editable
)
{
setEmpty
()
}
}
}
private
fun
updateButtons
()
{
if
(!
wordEmpty
||
!
translationEmpty
)
visible
(
btnClear
)
if
(
wordEmpty
&&
translationEmpty
)
invisible
(
btnClear
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
View file @
6b2e1892
...
...
@@ -19,12 +19,6 @@ import kotlinx.android.synthetic.main.content_main.*
abstract
class
WordFragment
:
Fragment
()
{
protected
lateinit
var
mainActivity
:
MainActivity
internal
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
internal
var
translationEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_editable_word
,
container
,
false
)
}
...
...
@@ -34,28 +28,10 @@ abstract class WordFragment : Fragment() {
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmit
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnCancel
.
setOnClickListener
{
cancelEditing
()
}
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
translation
.
addTextChangedListener
(
textWatcher
{
translationEmpty
=
translation
.
text
.
isEmpty
()
})
btnClear
.
setOnClickListener
{
clearFields
()
}
}
open
fun
updateButtons
()
{
if
(!
wordEmpty
&&
!
translationEmpty
)
visible
(
mainActivity
.
btnSubmit
)
if
(
wordEmpty
||
translationEmpty
)
gone
(
mainActivity
.
btnSubmit
)
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
return
object
:
TextWatcher
{
override
fun
beforeTextChanged
(
charSequence
:
CharSequence
,
i
:
Int
,
i1
:
Int
,
i2
:
Int
)
{
}
override
fun
onTextChanged
(
charSequence
:
CharSequence
,
i
:
Int
,
i1
:
Int
,
i2
:
Int
)
{
}
override
fun
afterTextChanged
(
editable
:
Editable
)
{
setEmpty
()
}
}
}
fun
submitWord
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
...
...
app/src/main/res/layout/content_main.xml
View file @
6b2e1892
...
...
@@ -96,7 +96,6 @@
android:layout_gravity=
"center_vertical"
android:layout_margin=
"@dimen/small_margin"
android:background=
"@android:color/transparent"
android:visibility=
"gone"
app:srcCompat=
"@drawable/ic_done_icon"
tools:ignore=
"ContentDescription"
/>
</LinearLayout>
...
...
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