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
f33592da
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Words can be edited
parent
685ba537
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
176 additions
and
110 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.kt
app/src/main/java/com/paktalin/vocabularynotebook/appsetup/ConfiguredFirestore.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/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/NewWordFragment.kt → app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/res/layout/editable_word_item.xml
app/src/main/res/layout/fragment_new_word.xml
app/src/main/res/layout/notebook_sheet.xml
app/src/main/res/layout/word_item.xml
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
f33592da
...
...
@@ -62,6 +62,12 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
this
.
notifyItemInserted
(
0
)
}
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
val
updatedItemId
=
wordItems
.
indexOf
(
updatedWordItem
)
wordItems
[
updatedItemId
]
=
updatedWordItem
this
.
notifyDataSetChanged
()
}
@SuppressLint
(
"ResourceType"
)
private
fun
editWordItem
(
container
:
View
,
wordItem
:
WordItem
)
{
//set container id
...
...
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.kt
View file @
f33592da
...
...
@@ -6,15 +6,15 @@ import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
java.io.Serializable
class
WordItem
(
word
:
String
,
translation
:
String
,
var
id
:
String
,
private
val
vocabularyId
:
String
)
:
Serializable
{
var
pojo
:
WordItem
Pojo
?
=
null
var
pojo
:
Pojo
?
=
null
class
WordItem
Pojo
(
var
word
:
String
?,
var
translation
:
String
?)
:
Serializable
class
Pojo
(
var
word
:
String
?,
var
translation
:
String
?)
:
Serializable
init
{
this
.
pojo
=
WordItem
Pojo
(
word
,
translation
)
this
.
pojo
=
Pojo
(
word
,
translation
)
}
constructor
(
pojo
:
WordItem
Pojo
,
id
:
String
,
vocabularyId
:
String
)
constructor
(
pojo
:
Pojo
,
id
:
String
,
vocabularyId
:
String
)
:
this
(
pojo
.
word
!!
,
pojo
.
translation
!!
,
id
,
vocabularyId
)
fun
delete
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/appsetup/ConfiguredFirestore.kt
0 → 100644
View file @
f33592da
package
com.paktalin.vocabularynotebook.appsetup
import
com.google.firebase.firestore.FirebaseFirestore
import
com.google.firebase.firestore.FirebaseFirestoreSettings
object
ConfiguredFirestore
{
val
instance
:
FirebaseFirestore
get
()
{
val
firestore
=
FirebaseFirestore
.
getInstance
()
val
settings
=
FirebaseFirestoreSettings
.
Builder
()
.
setTimestampsInSnapshotsEnabled
(
true
)
.
build
()
firestore
.
firestoreSettings
=
settings
return
firestore
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
0 → 100644
View file @
f33592da
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.WordItem
class
AddWordFragment
:
WordFragment
()
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_new_word
,
container
,
false
)
}
override
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
ConfiguredFirestore
.
instance
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
.
collection
(
WORDS
).
add
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
clearFields
()
val
wordItem
=
WordItem
(
wordPojo
,
it
.
id
,
vocabularyId
)
updateRecycleView
(
wordItem
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
activity
,
"Couldn't add the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
val
vocabularyFragment
=
activity
!!
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
vocabularyFragment
.
addWordItem
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
f33592da
...
...
@@ -2,51 +2,74 @@ package com.paktalin.vocabularynotebook.ui
import
android.content.Context
import
android.os.Bundle
import
android.
support.v4.app.Fragment
import
android.
util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.WindowManager
import
android.view.inputmethod.InputMethodManager
import
android.widget.
EditText
import
android.widget.
ImageView
import
android.widget.TextView
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_new_word.*
class
EditWordFragment
:
Fragment
()
{
class
EditWordFragment
:
WordFragment
()
{
private
lateinit
var
wordItem
:
WordItem
private
lateinit
var
etWord
:
EditText
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
hidePreviousViews
(
container
)
wordItem
=
arguments
!!
[
"wordItem"
]
as
WordItem
return
inflater
.
inflate
(
R
.
layout
.
editable_word_item
,
container
,
false
)
return
inflater
.
inflate
(
R
.
layout
.
fragment_new_word
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
etWord
=
view
!!
.
findViewById
(
R
.
id
.
word
)
setWordItemData
()
setFocusOnWord
()
}
private
fun
setWordItemData
()
{
etW
ord
.
setText
(
wordItem
.
pojo
!!
.
word
)
view
!!
.
findViewById
<
EditText
>(
R
.
id
.
translation
)
.
setText
(
wordItem
.
pojo
!!
.
translation
)
w
ord
.
setText
(
wordItem
.
pojo
!!
.
word
)
translation
.
setText
(
wordItem
.
pojo
!!
.
translation
)
}
private
fun
setFocusOnWord
()
{
activity
!!
.
window
.
setSoftInputMode
(
WindowManager
.
LayoutParams
.
SOFT_INPUT_STATE_VISIBLE
)
;
etW
ord
.
requestFocus
()
activity
!!
.
window
.
setSoftInputMode
(
WindowManager
.
LayoutParams
.
SOFT_INPUT_STATE_VISIBLE
)
w
ord
.
requestFocus
()
val
imm
=
activity
!!
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
?
imm
!!
.
toggleSoftInput
(
InputMethodManager
.
SHOW_FORCED
,
InputMethodManager
.
HIDE_IMPLICIT_ONLY
)
}
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
}
}
override
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
{
ConfiguredFirestore
.
instance
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
.
collection
(
WORDS
).
document
(
wordItem
.
id
).
set
(
wordPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully updated the word"
)
hideSubmitButton
()
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"updateExistingWord:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
activity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
val
vocabularyFragment
=
activity
!!
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
vocabularyFragment
.
updateWordItem
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
EditWordFragment
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
f33592da
...
...
@@ -63,4 +63,8 @@ class VocabularyFragment : Fragment() {
fun
addWordItem
(
newWordItem
:
WordItem
)
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
addWordItem
(
newWordItem
)
}
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
updateWordItem
(
updatedWordItem
)
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/
New
WordFragment.kt
→
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
f33592da
...
...
@@ -4,20 +4,16 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.text.Editable
import
android.text.TextWatcher
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.FrameLayout
import
android.widget.ImageButton
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
kotlinx.android.synthetic.main.editable_word_item.*
import
kotlinx.android.synthetic.main.fragment_new_word.*
class
NewWordFragment
:
Fragment
()
{
abstract
class
WordFragment
:
Fragment
()
{
protected
val
VOCABULARIES
=
"vocabularies"
protected
val
WORDS
=
"words"
private
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
...
...
@@ -25,10 +21,6 @@ class NewWordFragment : 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
)
word
.
addTextChangedListener
(
textWatcher
{
...
...
@@ -37,72 +29,56 @@ class NewWordFragment : Fragment() {
translation
.
addTextChangedListener
(
textWatcher
{
translationEmpty
=
translation
.
text
.
isEmpty
()
})
btnClear
.
setOnClickListener
{
word
.
text
.
clear
()
translation
.
text
.
clear
()
}
activity
!!
.
findViewById
<
ImageButton
>(
R
.
id
.
btnAddWord
).
setOnClickListener
{
addWord
()
}
btnClear
.
setOnClickListener
{
clearFields
()
}
activity
!!
.
findViewById
<
ImageButton
>(
R
.
id
.
btnAddWord
).
setOnClickListener
{
submitWord
()
}
}
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
)
showClearButton
()
if
(!
wordEmpty
&&
!
translationEmpty
)
show
AddWord
Button
()
show
Submit
Button
()
if
(
wordEmpty
||
translationEmpty
)
hide
AddWord
Button
()
hide
Submit
Button
()
if
(
wordEmpty
&&
translationEmpty
)
hideClearButton
()
}
private
fun
showAddWordButton
()
{
activity
!!
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnAddWordLayout
).
visibility
=
View
.
VISIBLE
}
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
showSubmitButton
()
{
activity
!!
.
findViewById
<
FrameLayout
>(
R
.
id
.
btnSubmitLayout
).
visibility
=
View
.
VISIBLE
}
pr
ivate
fun
hideAddWord
Button
()
{
activity
!!
.
findViewById
<
FrameLayout
>(
R
.
id
.
btn
AddWord
Layout
).
visibility
=
View
.
GONE
}
pr
otected
fun
hideSubmit
Button
()
{
activity
!!
.
findViewById
<
FrameLayout
>(
R
.
id
.
btn
Submit
Layout
).
visibility
=
View
.
GONE
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
private
fun
add
Word
()
{
private
fun
submit
Word
()
{
(
activity
as
MainActivity
).
hideKeyboardNotFromActivity
(
activity
as
MainActivity
)
val
word
=
word
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
val
vocabularyId
=
(
activity
as
MainActivity
).
vocabularyId
val
newWordItemPojo
=
WordItem
.
WordItemPojo
(
word
,
translation
)
ConfiguredFirestore
.
instance
.
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"words"
).
add
(
newWordItemPojo
)
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word"
)
clearFields
()
val
wordItem
=
WordItem
(
newWordItemPojo
,
it
.
id
,
vocabularyId
)
updateRecycleView
(
wordItem
)
}
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Toast
.
makeText
(
activity
,
"Couldn't add the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
)
saveToFirestore
(
wordPojo
,
vocabularyId
)
}
pr
ivate
fun
clearFields
()
{
pr
otected
fun
clearFields
()
{
word
.
text
.
clear
()
translation
.
text
.
clear
()
}
private
fun
updateRecycleView
(
newWordItem
:
WordItem
)
{
(
activity
!!
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
)
.
addWordItem
(
newWordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
NewWordFragment
::
class
.
java
.
simpleName
}
protected
abstract
fun
saveToFirestore
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
)
protected
abstract
fun
updateRecycleView
(
wordItem
:
WordItem
)
}
\ No newline at end of file
app/src/main/res/layout/editable_word_item.xml
deleted
100644 → 0
View file @
685ba537
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:orientation=
"horizontal"
android:paddingLeft=
"16dp"
android:paddingStart=
"16dp"
android:paddingRight=
"16dp"
android:paddingEnd=
"16dp"
android:paddingTop=
"8dp"
android:paddingBottom=
"8dp"
android:background=
"@android:color/transparent"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<EditText
android:id=
"@+id/word"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:background=
"@android:color/transparent"
android:hint=
"@string/hint_new_word"
android:inputType=
"text"
android:textSize=
"22sp"
app:fontFamily=
"@font/neucha"
android:textColor=
"#000F55"
tools:ignore=
"LabelFor"
/>
<EditText
android:id=
"@+id/translation"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:background=
"@android:color/transparent"
android:hint=
"@string/hint_translation"
android:inputType=
"text"
android:textSize=
"22sp"
app:fontFamily=
"@font/neucha"
android:textColor=
"#000F55"
tools:ignore=
"LabelFor"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_new_word.xml
View file @
f33592da
...
...
@@ -20,7 +20,44 @@
android:layout_marginStart=
"8dp"
tools:ignore=
"ContentDescription"
/>
<include
layout=
"@layout/editable_word_item"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:paddingLeft=
"16dp"
android:paddingStart=
"16dp"
android:paddingRight=
"16dp"
android:paddingEnd=
"16dp"
android:paddingTop=
"8dp"
android:paddingBottom=
"8dp"
android:background=
"@android:color/transparent"
>
<EditText
android:id=
"@+id/word"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:background=
"@android:color/transparent"
android:hint=
"@string/hint_new_word"
android:inputType=
"text"
android:textSize=
"22sp"
app:fontFamily=
"@font/neucha"
android:textColor=
"#000F55"
tools:ignore=
"LabelFor"
/>
<EditText
android:id=
"@+id/translation"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:background=
"@android:color/transparent"
android:hint=
"@string/hint_translation"
android:inputType=
"text"
android:textSize=
"22sp"
app:fontFamily=
"@font/neucha"
android:textColor=
"#000F55"
tools:ignore=
"LabelFor"
/>
</LinearLayout>
<ImageButton
android:id=
"@+id/btnClear"
...
...
app/src/main/res/layout/notebook_sheet.xml
View file @
f33592da
...
...
@@ -25,7 +25,7 @@
<fragment
android:id=
"@+id/fragment_new_word"
android:name=
"com.paktalin.vocabularynotebook.ui.
New
WordFragment"
android:name=
"com.paktalin.vocabularynotebook.ui.
Add
WordFragment"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
/>
...
...
@@ -40,7 +40,7 @@
</ScrollView>
<FrameLayout
android:id=
"@+id/btn
AddWord
Layout"
android:id=
"@+id/btn
Submit
Layout"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@color/colorPrimary"
...
...
app/src/main/res/layout/word_item.xml
View file @
f33592da
...
...
@@ -8,6 +8,7 @@
android:layout_height=
"wrap_content"
>
<ImageView
android:id=
"@+id/line"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:src=
"@drawable/line"
...
...
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