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
0f261e01
authored
Nov 11, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Word editing/addition can be cancelled
parent
15af5219
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
83 additions
and
39 deletions
.idea/caches/build_file_checksums.ser
app/build.gradle
app/src/main/java/com/paktalin/vocabularynotebook/appsetup/VocabularyApplication.java
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
app/src/main/res/layout/content_main.xml
app/src/main/res/layout/fragment_editable_word.xml
.idea/caches/build_file_checksums.ser
View file @
0f261e01
No preview for this file type
app/build.gradle
View file @
0f261e01
...
@@ -8,6 +8,7 @@ android {
...
@@ -8,6 +8,7 @@ android {
targetSdkVersion
28
targetSdkVersion
28
versionCode
1
versionCode
1
versionName
"1.0"
versionName
"1.0"
multiDexEnabled
true
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
vectorDrawables
{
vectorDrawables
{
useSupportLibrary
=
true
useSupportLibrary
=
true
...
@@ -30,6 +31,7 @@ dependencies {
...
@@ -30,6 +31,7 @@ dependencies {
implementation
'com.android.support:support-annotations:28.0.0-rc02'
implementation
'com.android.support:support-annotations:28.0.0-rc02'
implementation
"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation
"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation
'com.android.support:multidex:1.0.3'
implementation
'com.google.firebase:firebase-core:16.0.3'
implementation
'com.google.firebase:firebase-core:16.0.3'
implementation
'com.google.firebase:firebase-database:16.0.1'
implementation
'com.google.firebase:firebase-database:16.0.1'
...
...
app/src/main/java/com/paktalin/vocabularynotebook/appsetup/VocabularyApplication.java
View file @
0f261e01
package
com
.
paktalin
.
vocabularynotebook
.
appsetup
;
package
com
.
paktalin
.
vocabularynotebook
.
appsetup
;
import
android.
app.
Application
;
import
android.
support.multidex.MultiDex
Application
;
import
com.firebase.client.Firebase
;
import
com.firebase.client.Firebase
;
public
class
VocabularyApplication
extends
Application
{
public
class
VocabularyApplication
extends
MultiDex
Application
{
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
0f261e01
package
com.paktalin.vocabularynotebook.ui.fragments
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.
view.View
import
android.
os.Bundle
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.utils.
FirestoreManager
import
com.paktalin.vocabularynotebook.utils.
*
import
com.paktalin.vocabularynotebook.utils.shortToast
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.fragment_editable_word.*
import
kotlinx.android.synthetic.main.fragment_editable_word.*
class
AddWordFragment
:
WordFragment
()
{
class
AddWordFragment
:
WordFragment
()
{
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
word
.
setOnTouchListener
{
_
,
_
->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
translation
.
setOnTouchListener
{
_
,
_
->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
}
override
fun
cancelEditing
()
{
clearFields
()
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
}
override
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
{
override
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
{
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
null
)
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
null
)
FirestoreManager
().
saveNewWord
(
FirestoreManager
().
saveNewWord
(
...
@@ -17,26 +31,22 @@ class AddWordFragment : WordFragment() {
...
@@ -17,26 +31,22 @@ class AddWordFragment : WordFragment() {
wordPojo
,
vocabularyId
)
wordPojo
,
vocabularyId
)
}
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
,
documentId
:
String
)
{
clearFields
()
mainActivity
.
removeProgressBar
()
val
wordItem
=
WordItem
(
wordPojo
,
documentId
,
vocabularyId
)
updateRecycleView
(
wordItem
)
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
}
}
override
fun
updateButtons
()
{
override
fun
updateButtons
()
{
super
.
updateButtons
()
super
.
updateButtons
()
if
(!
wordEmpty
||
!
translationEmpty
)
showClearButton
(
)
if
(!
wordEmpty
||
!
translationEmpty
)
visible
(
btnClear
)
if
(
wordEmpty
&&
translationEmpty
)
hideClearButton
(
)
if
(
wordEmpty
&&
translationEmpty
)
invisible
(
btnClear
)
}
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
,
documentId
:
String
)
{
clearFields
()
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
mainActivity
.
removeProgressBar
()
val
wordItem
=
WordItem
(
wordPojo
,
documentId
,
vocabularyId
)
updateRecycleView
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
0f261e01
...
@@ -17,11 +17,18 @@ import kotlinx.android.synthetic.main.word_item.view.*
...
@@ -17,11 +17,18 @@ import kotlinx.android.synthetic.main.word_item.view.*
class
EditWordFragment
:
WordFragment
()
{
class
EditWordFragment
:
WordFragment
()
{
private
lateinit
var
wordItem
:
WordItem
private
lateinit
var
wordItem
:
WordItem
private
var
container
:
ViewGroup
?
=
null
override
fun
cancelEditing
()
{
stop
()
showPreviousViews
()
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
mainActivity
=
activity
as
MainActivity
mainActivity
=
activity
as
MainActivity
mainActivity
.
inEditMode
=
true
mainActivity
.
inEditMode
=
true
hidePreviousViews
(
container
)
this
.
container
=
container
hidePreviousViews
()
wordItem
=
arguments
!!
[
"wordItem"
]
as
WordItem
wordItem
=
arguments
!!
[
"wordItem"
]
as
WordItem
return
super
.
onCreateView
(
inflater
,
container
,
savedInstanceState
)
return
super
.
onCreateView
(
inflater
,
container
,
savedInstanceState
)
}
}
...
@@ -31,6 +38,11 @@ class EditWordFragment : WordFragment() {
...
@@ -31,6 +38,11 @@ class EditWordFragment : WordFragment() {
setWordItemData
()
setWordItemData
()
disableScrolling
(
mainActivity
)
disableScrolling
(
mainActivity
)
setFocusOnWord
()
setFocusOnWord
()
visible
(
mainActivity
.
btnSubmitLayout
)
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
mainActivity
.
vocabularyFragment
.
updateWord
(
wordItem
)
}
}
private
fun
setWordItemData
()
{
private
fun
setWordItemData
()
{
...
@@ -45,15 +57,19 @@ class EditWordFragment : WordFragment() {
...
@@ -45,15 +57,19 @@ class EditWordFragment : WordFragment() {
imm
!!
.
toggleSoftInput
(
InputMethodManager
.
SHOW_FORCED
,
InputMethodManager
.
HIDE_IMPLICIT_ONLY
)
imm
!!
.
toggleSoftInput
(
InputMethodManager
.
SHOW_FORCED
,
InputMethodManager
.
HIDE_IMPLICIT_ONLY
)
}
}
private
fun
hidePreviousViews
(
container
:
ViewGroup
?)
{
private
fun
hidePreviousViews
()
{
if
(
container
!=
null
)
{
gone
(
container
!!
.
line
)
container
.
line
.
visibility
=
View
.
GONE
gone
(
container
!!
.
word
)
container
.
word
.
visibility
=
View
.
GONE
gone
(
container
!!
.
translation
)
container
.
translation
.
visibility
=
View
.
GONE
}
}
}
override
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
{
private
fun
showPreviousViews
()
{
visible
(
container
!!
.
line
)
visible
(
container
!!
.
word
)
visible
(
container
!!
.
translation
)
}
override
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
{
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
wordItem
.
pojo
.
time
)
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
wordItem
.
pojo
.
time
)
FirestoreManager
().
updateWord
(
FirestoreManager
().
updateWord
(
{
onSuccessfulSave
(
wordPojo
)
},
{
onSuccessfulSave
(
wordPojo
)
},
...
@@ -62,7 +78,7 @@ class EditWordFragment : WordFragment() {
...
@@ -62,7 +78,7 @@ class EditWordFragment : WordFragment() {
}
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
)
{
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
)
{
hideSubmitButton
(
)
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
removeProgressBar
()
mainActivity
.
removeProgressBar
()
wordItem
.
pojo
=
wordPojo
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
updateRecycleView
(
wordItem
)
...
@@ -77,15 +93,13 @@ class EditWordFragment : WordFragment() {
...
@@ -77,15 +93,13 @@ class EditWordFragment : WordFragment() {
private
fun
stop
()
{
private
fun
stop
()
{
// set onClickListener from AddWordFragment
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submitWord
()
}
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submitWord
()
}
enableScrolling
(
mainActivity
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
enableScrolling
(
mainActivity
)
mainActivity
.
inEditMode
=
false
mainActivity
.
inEditMode
=
false
}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
mainActivity
.
vocabularyFragment
.
updateWord
(
wordItem
)
}
companion
object
{
companion
object
{
private
val
TAG
=
"VN/"
+
EditWordFragment
::
class
.
java
.
simpleName
private
val
TAG
=
"VN/"
+
EditWordFragment
::
class
.
java
.
simpleName
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
View file @
0f261e01
...
@@ -11,6 +11,8 @@ import com.paktalin.vocabularynotebook.R
...
@@ -11,6 +11,8 @@ import com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.FirestoreManager
import
com.paktalin.vocabularynotebook.utils.FirestoreManager
import
com.paktalin.vocabularynotebook.utils.gone
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.content_main.*
import
kotlinx.android.synthetic.main.content_main.*
...
@@ -31,6 +33,7 @@ abstract class WordFragment : Fragment() {
...
@@ -31,6 +33,7 @@ abstract class WordFragment : Fragment() {
super
.
onActivityCreated
(
savedInstanceState
)
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmit
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnSubmit
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnCancel
.
setOnClickListener
{
cancelEditing
()
}
word
.
addTextChangedListener
(
textWatcher
{
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
wordEmpty
=
word
.
text
.
isEmpty
()
})
...
@@ -41,8 +44,8 @@ abstract class WordFragment : Fragment() {
...
@@ -41,8 +44,8 @@ abstract class WordFragment : Fragment() {
}
}
open
fun
updateButtons
()
{
open
fun
updateButtons
()
{
if
(!
wordEmpty
&&
!
translationEmpty
)
showSubmitButton
(
)
if
(!
wordEmpty
&&
!
translationEmpty
)
visible
(
mainActivity
.
btnSubmit
)
if
(
wordEmpty
||
translationEmpty
)
hideSubmitButton
(
)
if
(
wordEmpty
||
translationEmpty
)
gone
(
mainActivity
.
btnSubmit
)
}
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
...
@@ -53,14 +56,9 @@ abstract class WordFragment : Fragment() {
...
@@ -53,14 +56,9 @@ abstract class WordFragment : Fragment() {
}
}
}
}
private
fun
showSubmitButton
()
{
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
VISIBLE
}
protected
fun
hideSubmitButton
()
{
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
GONE
}
fun
submitWord
()
{
fun
submitWord
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
val
word
=
word
.
text
.
toString
()
val
word
=
word
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
...
@@ -75,6 +73,7 @@ abstract class WordFragment : Fragment() {
...
@@ -75,6 +73,7 @@ abstract class WordFragment : Fragment() {
translation
.
text
.
clear
()
translation
.
text
.
clear
()
}
}
protected
abstract
fun
cancelEditing
()
protected
abstract
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
protected
abstract
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
protected
abstract
fun
updateRecycleView
(
wordItem
:
WordItem
)
protected
abstract
fun
updateRecycleView
(
wordItem
:
WordItem
)
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
0f261e01
...
@@ -6,6 +6,7 @@ import android.os.Bundle
...
@@ -6,6 +6,7 @@ import android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
import
android.text.TextUtils
import
android.view.View
import
android.widget.Toast
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
...
@@ -52,4 +53,16 @@ fun shortToast(context: Context, text: String) {
...
@@ -52,4 +53,16 @@ fun shortToast(context: Context, text: String) {
fun
startActivity
(
context
:
Context
,
cls
:
Class
<*>)
{
fun
startActivity
(
context
:
Context
,
cls
:
Class
<*>)
{
context
.
startActivity
(
Intent
(
context
,
cls
))
context
.
startActivity
(
Intent
(
context
,
cls
))
}
fun
visible
(
view
:
View
)
{
view
.
visibility
=
View
.
VISIBLE
}
fun
invisible
(
view
:
View
)
{
view
.
visibility
=
View
.
INVISIBLE
}
fun
gone
(
view
:
View
)
{
view
.
visibility
=
View
.
GONE
}
}
\ No newline at end of file
app/src/main/res/layout/content_main.xml
View file @
0f261e01
...
@@ -70,6 +70,7 @@
...
@@ -70,6 +70,7 @@
app:layout_constraintBottom_toBottomOf=
"parent"
>
app:layout_constraintBottom_toBottomOf=
"parent"
>
<ImageButton
<ImageButton
android:id=
"@+id/btnCancel"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
app:srcCompat=
"@drawable/ic_close_icon"
app:srcCompat=
"@drawable/ic_close_icon"
...
@@ -90,6 +91,7 @@
...
@@ -90,6 +91,7 @@
android:layout_gravity=
"center_vertical"
android:layout_gravity=
"center_vertical"
android:layout_margin=
"@dimen/small_margin"
android:layout_margin=
"@dimen/small_margin"
android:background=
"@android:color/transparent"
android:background=
"@android:color/transparent"
android:visibility=
"gone"
app:srcCompat=
"@drawable/ic_done_icon"
app:srcCompat=
"@drawable/ic_done_icon"
tools:ignore=
"ContentDescription"
/>
tools:ignore=
"ContentDescription"
/>
</LinearLayout>
</LinearLayout>
...
...
app/src/main/res/layout/fragment_editable_word.xml
View file @
0f261e01
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/editable_word_layout"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
android:layout_height=
"wrap_content"
>
...
...
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