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 {
targetSdkVersion
28
versionCode
1
versionName
"1.0"
multiDexEnabled
true
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
vectorDrawables
{
useSupportLibrary
=
true
...
...
@@ -30,6 +31,7 @@ dependencies {
implementation
'com.android.support:support-annotations:28.0.0-rc02'
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-database:16.0.1'
...
...
app/src/main/java/com/paktalin/vocabularynotebook/appsetup/VocabularyApplication.java
View file @
0f261e01
package
com
.
paktalin
.
vocabularynotebook
.
appsetup
;
import
android.
app.
Application
;
import
android.
support.multidex.MultiDex
Application
;
import
com.firebase.client.Firebase
;
public
class
VocabularyApplication
extends
Application
{
public
class
VocabularyApplication
extends
MultiDex
Application
{
@Override
public
void
onCreate
()
{
super
.
onCreate
();
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
0f261e01
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.
view.View
import
android.
os.Bundle
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.utils.
FirestoreManager
import
com.paktalin.vocabularynotebook.utils.shortToast
import
com.paktalin.vocabularynotebook.utils.
*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.fragment_editable_word.*
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
)
{
val
wordPojo
=
WordItem
.
Pojo
(
word
,
translation
,
null
)
FirestoreManager
().
saveNewWord
(
...
...
@@ -17,26 +31,22 @@ class AddWordFragment : WordFragment() {
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
)
{
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
}
override
fun
updateButtons
()
{
super
.
updateButtons
()
if
(!
wordEmpty
||
!
translationEmpty
)
showClearButton
(
)
if
(
wordEmpty
&&
translationEmpty
)
hideClearButton
(
)
if
(!
wordEmpty
||
!
translationEmpty
)
visible
(
btnClear
)
if
(
wordEmpty
&&
translationEmpty
)
invisible
(
btnClear
)
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
,
vocabularyId
:
String
,
documentId
:
String
)
{
clearFields
()
mainActivity
.
removeProgressBar
()
val
wordItem
=
WordItem
(
wordPojo
,
documentId
,
vocabularyId
)
updateRecycleView
(
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/fragments/EditWordFragment.kt
View file @
0f261e01
...
...
@@ -17,11 +17,18 @@ import kotlinx.android.synthetic.main.word_item.view.*
class
EditWordFragment
:
WordFragment
()
{
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
?
{
mainActivity
=
activity
as
MainActivity
mainActivity
.
inEditMode
=
true
hidePreviousViews
(
container
)
this
.
container
=
container
hidePreviousViews
()
wordItem
=
arguments
!!
[
"wordItem"
]
as
WordItem
return
super
.
onCreateView
(
inflater
,
container
,
savedInstanceState
)
}
...
...
@@ -31,6 +38,11 @@ class EditWordFragment : WordFragment() {
setWordItemData
()
disableScrolling
(
mainActivity
)
setFocusOnWord
()
visible
(
mainActivity
.
btnSubmitLayout
)
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
mainActivity
.
vocabularyFragment
.
updateWord
(
wordItem
)
}
private
fun
setWordItemData
()
{
...
...
@@ -45,15 +57,19 @@ class EditWordFragment : WordFragment() {
imm
!!
.
toggleSoftInput
(
InputMethodManager
.
SHOW_FORCED
,
InputMethodManager
.
HIDE_IMPLICIT_ONLY
)
}
private
fun
hidePreviousViews
(
container
:
ViewGroup
?)
{
if
(
container
!=
null
)
{
container
.
line
.
visibility
=
View
.
GONE
container
.
word
.
visibility
=
View
.
GONE
container
.
translation
.
visibility
=
View
.
GONE
}
private
fun
hidePreviousViews
()
{
gone
(
container
!!
.
line
)
gone
(
container
!!
.
word
)
gone
(
container
!!
.
translation
)
}
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
)
FirestoreManager
().
updateWord
(
{
onSuccessfulSave
(
wordPojo
)
},
...
...
@@ -62,7 +78,7 @@ class EditWordFragment : WordFragment() {
}
private
fun
onSuccessfulSave
(
wordPojo
:
WordItem
.
Pojo
)
{
hideSubmitButton
(
)
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
removeProgressBar
()
wordItem
.
pojo
=
wordPojo
updateRecycleView
(
wordItem
)
...
...
@@ -77,15 +93,13 @@ class EditWordFragment : WordFragment() {
private
fun
stop
()
{
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submitWord
()
}
enableScrolling
(
mainActivity
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
enableScrolling
(
mainActivity
)
mainActivity
.
inEditMode
=
false
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
mainActivity
.
vocabularyFragment
.
updateWord
(
wordItem
)
}
companion
object
{
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
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
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.content_main.*
...
...
@@ -31,6 +33,7 @@ abstract class WordFragment : Fragment() {
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmit
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnCancel
.
setOnClickListener
{
cancelEditing
()
}
word
.
addTextChangedListener
(
textWatcher
{
wordEmpty
=
word
.
text
.
isEmpty
()
})
...
...
@@ -41,8 +44,8 @@ abstract class WordFragment : Fragment() {
}
open
fun
updateButtons
()
{
if
(!
wordEmpty
&&
!
translationEmpty
)
showSubmitButton
(
)
if
(
wordEmpty
||
translationEmpty
)
hideSubmitButton
(
)
if
(!
wordEmpty
&&
!
translationEmpty
)
visible
(
mainActivity
.
btnSubmit
)
if
(
wordEmpty
||
translationEmpty
)
gone
(
mainActivity
.
btnSubmit
)
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
...
...
@@ -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
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
val
word
=
word
.
text
.
toString
()
val
translation
=
translation
.
text
.
toString
()
...
...
@@ -75,6 +73,7 @@ abstract class WordFragment : Fragment() {
translation
.
text
.
clear
()
}
protected
abstract
fun
cancelEditing
()
protected
abstract
fun
saveToFirestore
(
word
:
String
,
translation
:
String
,
vocabularyId
:
String
)
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
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
import
android.view.View
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
...
...
@@ -52,4 +53,16 @@ fun shortToast(context: Context, text: String) {
fun
startActivity
(
context
:
Context
,
cls
:
Class
<*>)
{
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 @@
app:layout_constraintBottom_toBottomOf=
"parent"
>
<ImageButton
android:id=
"@+id/btnCancel"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:srcCompat=
"@drawable/ic_close_icon"
...
...
@@ -90,6 +91,7 @@
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>
...
...
app/src/main/res/layout/fragment_editable_word.xml
View file @
0f261e01
...
...
@@ -3,6 +3,7 @@
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/editable_word_layout"
android:layout_width=
"match_parent"
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