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
a046a823
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug with wrong clickListener
parent
d14cc276
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
34 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
a046a823
...
...
@@ -90,11 +90,11 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
}
else
container
.
id
=
18071999
// start EditWordFragment
val
wordInfo
Fragment
=
EditWordFragment
()
val
editWord
Fragment
=
EditWordFragment
()
val
arguments
=
Bundle
()
arguments
.
putSerializable
(
"wordItem"
,
wordItem
)
wordInfo
Fragment
.
arguments
=
arguments
(
activity
as
MainActivity
).
supportFragmentManager
.
beginTransaction
().
add
(
container
.
id
,
wordInfo
Fragment
).
commit
()
editWord
Fragment
.
arguments
=
arguments
(
activity
as
MainActivity
).
supportFragmentManager
.
beginTransaction
().
add
(
container
.
id
,
editWord
Fragment
).
commit
()
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
View file @
a046a823
...
...
@@ -13,10 +13,6 @@ class WordItem(word: String, translation: String, time: Date?, var id: String, p
init
{
if
(
time
==
null
)
time
=
Date
(
System
.
currentTimeMillis
())
}
fun
print
():
String
{
return
"word: $word; translation: $translation; time: $time"
}
}
constructor
(
pojo
:
Pojo
,
id
:
String
,
vocabularyId
:
String
)
...
...
@@ -24,7 +20,7 @@ class WordItem(word: String, translation: String, time: Date?, var id: String, p
fun
delete
()
{
ConfiguredFirestore
.
instance
.
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"
WORDS
"
).
document
(
id
).
delete
()
.
collection
(
"
words
"
).
document
(
id
).
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
View file @
a046a823
package
com.paktalin.vocabularynotebook.ui
import
android.os.Bundle
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
class
AddWordFragment
:
WordFragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
mainActivity
=
activity
as
MainActivity
return
inflater
.
inflate
(
R
.
layout
.
fragment_new_word
,
container
,
false
)
}
override
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
mainActivity
.
showProgressBar
()
ConfiguredFirestore
.
instance
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
a046a823
...
...
@@ -7,6 +7,7 @@ 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
...
...
@@ -22,7 +23,7 @@ class EditWordFragment : WordFragment() {
mainActivity
=
activity
as
MainActivity
hidePreviousViews
(
container
)
wordItem
=
arguments
!!
[
"wordItem"
]
as
WordItem
return
inflater
.
inflate
(
R
.
layout
.
fragment_new_word
,
container
,
fals
e
)
return
super
.
onCreateView
(
inflater
,
container
,
savedInstanceStat
e
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -60,7 +61,12 @@ class EditWordFragment : WordFragment() {
hideSubmitButton
()
mainActivity
.
hideProgressBar
()
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
}
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
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
mainActivity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
a046a823
...
...
@@ -11,6 +11,7 @@ import com.paktalin.vocabularynotebook.R
import
kotlinx.android.synthetic.main.activity_main.*
import
android.view.WindowManager
import
android.app.Activity
import
android.support.v4.app.Fragment
import
android.view.Menu
import
android.view.MenuItem
import
android.view.View
...
...
@@ -80,7 +81,8 @@ class MainActivity : AppCompatActivity() {
val
arguments
=
Bundle
()
arguments
.
putString
(
"vocabularyId"
,
vocabularyId
)
vocabularyFragment
.
arguments
=
arguments
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
fragment_container
,
vocabularyFragment
).
commitNowAllowingStateLoss
()
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
fragment_container
,
vocabularyFragment
)
.
commitNowAllowingStateLoss
()
}
else
{
Log
.
w
(
TAG
,
"There's no collection \"vocabularies\""
)
showToastNoWords
()
}
...
...
@@ -94,9 +96,7 @@ class MainActivity : AppCompatActivity() {
fun
hideKeyboardNotFromActivity
(
activity
:
Activity
)
{
val
imm
=
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
var
view
=
activity
.
currentFocus
if
(
view
==
null
)
{
view
=
View
(
activity
)
}
if
(
view
==
null
)
{
view
=
View
(
activity
)
}
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
...
...
@@ -106,7 +106,11 @@ class MainActivity : AppCompatActivity() {
fun
showToastNoWords
()
{
Toast
.
makeText
(
this
@MainActivity
,
"You don't have any WORDS yet. Add your fist one!"
,
Toast
.
LENGTH_SHORT
).
show
()
"You don't have any words yet. Add your fist one!"
,
Toast
.
LENGTH_SHORT
).
show
()
}
fun
removeFragment
(
fragment
:
Fragment
)
{
supportFragmentManager
.
beginTransaction
().
remove
(
fragment
).
commitAllowingStateLoss
()
}
override
fun
onPause
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
a046a823
...
...
@@ -30,7 +30,6 @@ class VocabularyFragment : Fragment() {
return
inflater
.
inflate
(
R
.
layout
.
fragment_vocabulary
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
setEmptyAdapter
()
...
...
@@ -57,7 +56,7 @@ class VocabularyFragment : Fragment() {
if
(
it
.
documents
.
size
!=
0
)
setVocabularyAdapter
(
it
.
documents
,
vocabularyId
)
else
{
Log
.
i
(
TAG
,
"There are no documents in collection \"
WORDS
\""
)
Log
.
i
(
TAG
,
"There are no documents in collection \"
words
\""
)
(
activity
as
MainActivity
).
showToastNoWords
()
}}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
a046a823
...
...
@@ -4,7 +4,9 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.text.Editable
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
...
...
@@ -18,6 +20,7 @@ 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
()
}
...
...
@@ -25,8 +28,14 @@ abstract class WordFragment : Fragment() {
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_new_word
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
findViewById
<
ImageButton
>(
R
.
id
.
btnAddWord
).
setOnClickListener
{
submitWord
()
}
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
...
...
@@ -34,10 +43,8 @@ abstract class WordFragment : Fragment() {
translationEmpty
=
translation
.
text
.
isEmpty
()
})
btnClear
.
setOnClickListener
{
clearFields
()
}
activity
!!
.
findViewById
<
ImageButton
>(
R
.
id
.
btnAddWord
).
setOnClickListener
{
submitWord
()
}
}
private
fun
updateButtons
()
{
if
(!
wordEmpty
||
!
translationEmpty
)
showClearButton
()
...
...
@@ -58,24 +65,25 @@ abstract class WordFragment : Fragment() {
}
private
fun
showSubmitButton
()
{
activity
!!
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
).
visibility
=
View
.
VISIBLE
}
mainActivity
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
).
visibility
=
View
.
VISIBLE
}
protected
fun
hideSubmitButton
()
{
activity
!!
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
).
visibility
=
View
.
GONE
}
mainActivity
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
).
visibility
=
View
.
GONE
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
private
fun
submitWord
()
{
(
activity
as
MainActivity
).
hideKeyboardNotFromActivity
(
activity
as
M
ainActivity
)
fun
submitWord
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
m
ainActivity
)
val
word
=
word
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
val
vocabularyId
=
(
activity
as
MainActivity
)
.
vocabularyId
val
vocabularyId
=
mainActivity
.
vocabularyId
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
null
)
saveToFirestore
(
wordPojo
,
vocabularyId
)
return
}
protected
fun
clearFields
()
{
...
...
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