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
dc5e6c99
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored AddWordFragment
parent
e81663b6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
78 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/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
dc5e6c99
package
com.paktalin.vocabularynotebook.ui.fragments
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.os.Bundle
import
android.os.Bundle
import
android.text.Editable
import
android.view.LayoutInflater
import
android.text.TextWatcher
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.invisible
import
com.paktalin.vocabularynotebook.utils.visible
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.fragment_editable_word.*
import
kotlinx.android.synthetic.main.fragment_editable_word.*
import
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.submit.*
class
AddWordFragment
:
WordFragment
()
{
open
class
AddWordFragment
:
Fragment
()
{
private
var
wordEmpty
:
Boolean
=
true
private
lateinit
var
mainActivity
:
MainActivity
set
(
value
)
{
field
=
value
;
updateButtons
()
}
private
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
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
submit
()
}
mainActivity
.
btnCancelWord
.
setOnClickListener
{
cancel
()
}
word
.
setOnTouchListener
{
_
,
_
->
word
.
setOnTouchListener
{
_
,
_
->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
translation
.
setOnTouchListener
{
_
,
_
->
translation
.
setOnTouchListener
{
_
,
_
->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
translation
.
addTextChangedListener
(
textWatcher
{
translationEmpty
=
translation
.
text
.
isEmpty
()
})
}
override
fun
cancel
()
{
clearFields
()
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
}
}
override
fun
save
(
word
:
String
,
translation
:
String
)
{
private
fun
submit
()
{
// TODO addAll entry point
finish
()
clearFields
()
mainActivity
.
vocabularyAdapter
.
addWord
(
WordPojo
(
word
.
text
.
toString
(),
translation
.
text
.
toString
()))
mainActivity
.
vocabularyAdapter
.
addWord
(
WordPojo
(
word
,
translation
))
this
.
word
.
requestFocus
()
this
.
word
.
requestFocus
()
return
}
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
private
fun
cancel
()
{
return
object
:
TextWatcher
{
finish
()
override
fun
beforeTextChanged
(
charSequence
:
CharSequence
,
i
:
Int
,
i1
:
Int
,
i2
:
Int
)
{
}
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
override
fun
onTextChanged
(
charSequence
:
CharSequence
,
i
:
Int
,
i1
:
Int
,
i2
:
Int
)
{
}
override
fun
afterTextChanged
(
editable
:
Editable
)
{
setEmpty
()
}
}
}
}
private
fun
updateButtons
()
{
private
fun
finish
()
{
if
(!
wordEmpty
||
!
translationEmpty
)
visible
(
btnClear
)
word
.
text
.
clear
()
if
(
wordEmpty
&&
translationEmpty
)
invisible
(
btnClear
)
translation
.
text
.
clear
()
gone
(
mainActivity
.
btnSubmitLayout
)
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
deleted
100644 → 0
View file @
e81663b6
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.gone
import
kotlinx.android.synthetic.main.fragment_editable_word.*
import
kotlinx.android.synthetic.main.submit.*
abstract
class
WordFragment
:
Fragment
()
{
protected
lateinit
var
mainActivity
:
MainActivity
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_editable_word
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
submit
()
}
mainActivity
.
btnCancelWord
.
setOnClickListener
{
cancel
()
}
btnClear
.
setOnClickListener
{
clearFields
()
}
}
private
fun
submit
()
{
gone
(
mainActivity
.
btnSubmitLayout
)
save
(
word
.
text
.
toString
(),
translation
.
text
.
toString
())
return
}
protected
fun
clearFields
()
{
word
.
text
.
clear
()
translation
.
text
.
clear
()
}
protected
abstract
fun
cancel
()
protected
abstract
fun
save
(
word
:
String
,
translation
:
String
)
}
\ No newline at end of file
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