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
08e99dc1
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved word submission logic to SubmitFragment
parent
b0095744
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
52 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/res/layout/content_main.xml
app/src/main/res/layout/submit.xml
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
08e99dc1
...
@@ -46,13 +46,11 @@ class MainActivity : AppCompatActivity() {
...
@@ -46,13 +46,11 @@ class MainActivity : AppCompatActivity() {
}
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
if
(
item
!!
.
itemId
==
R
.
id
.
sortByTime
)
vocabularyAdapter
.
sort
=
when
(
item
!!
.
itemId
)
{
vocabularyAdapter
.
sort
=
Sort
.
BY_TIME
R
.
id
.
sortByWord
->
Sort
.
BY_WORD
if
(
item
.
itemId
==
R
.
id
.
sortByWord
)
R
.
id
.
sortByTranslation
->
Sort
.
BY_TRANSLATION
vocabularyAdapter
.
sort
=
Sort
.
BY_WORD
else
->
Sort
.
BY_TIME
if
(
item
.
itemId
==
R
.
id
.
sortByTranslation
)
}
vocabularyAdapter
.
sort
=
Sort
.
BY_TRANSLATION
return
super
.
onOptionsItemSelected
(
item
)
return
super
.
onOptionsItemSelected
(
item
)
}
}
...
@@ -69,9 +67,8 @@ class MainActivity : AppCompatActivity() {
...
@@ -69,9 +67,8 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpNavigationView
()
{
private
fun
setUpNavigationView
()
{
navigationView
.
setNavigationItemSelectedListener
{
menuItem
->
navigationView
.
setNavigationItemSelectedListener
{
menuItem
->
menuItem
.
isChecked
=
true
menuItem
.
isChecked
=
true
if
(
menuItem
.
itemId
==
R
.
id
.
logOut
)
{
if
(
menuItem
.
itemId
==
R
.
id
.
logOut
)
logOut
()
logOut
()
}
drawerLayout
!!
.
closeDrawers
()
drawerLayout
!!
.
closeDrawers
()
true
true
}
}
...
@@ -83,7 +80,6 @@ class MainActivity : AppCompatActivity() {
...
@@ -83,7 +80,6 @@ class MainActivity : AppCompatActivity() {
}
}
private
fun
setUpVocabularyAdapter
()
{
private
fun
setUpVocabularyAdapter
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
FirestoreManager
().
extractVocabularyId
({
FirestoreManager
().
extractVocabularyId
({
FirestoreManager
().
extractVocabulary
{
querySnapshot
->
FirestoreManager
().
extractVocabulary
{
querySnapshot
->
...
@@ -106,10 +102,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -106,10 +102,7 @@ class MainActivity : AppCompatActivity() {
fun
hideKeyboardNotFromActivity
(
activity
:
Activity
)
{
fun
hideKeyboardNotFromActivity
(
activity
:
Activity
)
{
val
imm
=
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
val
imm
=
activity
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
)
as
InputMethodManager
var
view
=
activity
.
currentFocus
val
view
=
activity
.
currentFocus
?:
View
(
activity
)
if
(
view
==
null
)
{
view
=
View
(
activity
)
}
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
08e99dc1
...
@@ -9,7 +9,6 @@ import com.paktalin.vocabularynotebook.R
...
@@ -9,7 +9,6 @@ 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.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.word_item.*
import
kotlinx.android.synthetic.main.word_item.*
...
@@ -23,13 +22,13 @@ open class AddWordFragment : Fragment() {
...
@@ -23,13 +22,13 @@ open class AddWordFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
submit
()
}
/*
mainActivity.btnSubmitWord.setOnClickListener { submit() }
mainActivity.btnCancelWord.setOnClickListener { cancel() }
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 }
*/
}
}
private
fun
submit
()
{
private
fun
submit
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitFragment.kt
0 → 100644
View file @
08e99dc1
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.EditText
import
androidx.fragment.app.Fragment
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.removeFragment
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.submit.*
class
SubmitFragment
:
Fragment
()
{
private
lateinit
var
mainActivity
:
MainActivity
private
lateinit
var
wordEt
:
EditText
private
lateinit
var
translationEt
:
EditText
private
var
clickableView
:
View
?
=
null
private
lateinit
var
wordPojo
:
WordPojo
private
var
edit
:
Boolean
=
false
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
submit
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
btnSubmitWord
.
setOnClickListener
{
submit
()
}
btnCancelWord
.
setOnClickListener
{
cancel
()
}
if
(
edit
)
{
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
clickableView
?.
let
{
gone
(
it
)
}
wordEt
.
requestFocus
()
showKeyboard
(
mainActivity
)
}
}
private
fun
submit
()
{
wordPojo
.
word
=
wordEt
.
text
.
toString
()
wordPojo
.
translation
=
translationEt
.
text
.
toString
()
mainActivity
.
vocabularyAdapter
.
updateWord
(
wordPojo
)
finish
()
}
private
fun
cancel
()
{
wordEt
.
setText
(
wordPojo
.
word
)
translationEt
.
setText
(
wordPojo
.
translation
)
finish
()
}
private
fun
finish
()
{
if
(
edit
)
{
wordEt
.
clearFocus
()
translationEt
.
clearFocus
()
clickableView
?.
let
{
visible
(
it
)
}
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
}
else
wordEt
.
requestFocus
()
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
}
fun
setData
(
wordEt
:
EditText
,
translationEt
:
EditText
,
edit
:
Boolean
,
wordPojo
:
WordPojo
?
=
null
,
clickableView
:
View
?
=
null
)
{
this
.
wordEt
=
wordEt
this
.
translationEt
=
translationEt
this
.
edit
=
edit
this
.
wordPojo
=
wordPojo
?:
WordPojo
(
""
,
""
)
this
.
clickableView
=
clickableView
}
companion
object
{
private
val
TAG
=
"VN/"
+
SubmitFragment
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
View file @
08e99dc1
...
@@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.fragment_tag.*
...
@@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.fragment_tag.*
class
TagFragment
:
Fragment
()
{
class
TagFragment
:
Fragment
()
{
private
lateinit
var
mainActivity
:
MainActivity
private
lateinit
var
mainActivity
:
MainActivity
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_tag
,
container
,
false
)
return
inflater
.
inflate
(
R
.
layout
.
fragment_tag
,
container
,
false
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
08e99dc1
...
@@ -9,14 +9,12 @@ import androidx.recyclerview.widget.RecyclerView
...
@@ -9,14 +9,12 @@ import androidx.recyclerview.widget.RecyclerView
import
com.paktalin.vocabularynotebook.R
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.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.visible
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.word_item.view.*
import
kotlinx.android.synthetic.main.word_item.view.*
class
VocabularyAdapter
(
private
val
vocabulary
:
VocabSet
,
private
val
mainActivity
:
MainActivity
)
:
RecyclerView
.
Adapter
<
ViewHolder
>()
{
class
VocabularyAdapter
(
private
val
vocabulary
:
VocabSet
,
private
val
mainActivity
:
MainActivity
)
:
RecyclerView
.
Adapter
<
ViewHolder
>()
{
...
@@ -94,6 +92,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
...
@@ -94,6 +92,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
this
.
sort
()
this
.
sort
()
}
}
fun
updateWord
(
wordPojo
:
WordPojo
)
{
vocabulary
.
updateWord
(
wordPojo
)
this
.
sort
()
}
private
fun
sort
()
{
private
fun
sort
()
{
vocabulary
.
sort
(
sort
)
vocabulary
.
sort
(
sort
)
this
.
notifyDataSetChanged
()
this
.
notifyDataSetChanged
()
...
@@ -101,34 +104,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
...
@@ -101,34 +104,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
@SuppressLint
(
"ResourceType"
)
@SuppressLint
(
"ResourceType"
)
private
fun
editWord
(
container
:
View
,
wordPojo
:
WordPojo
)
{
private
fun
editWord
(
container
:
View
,
wordPojo
:
WordPojo
)
{
showPopupMenu
=
false
addFragment
(
mainActivity
.
supportFragmentManager
,
gone
(
container
.
clickable_view
)
SubmitFragment
().
apply
{
container
.
word
.
requestFocus
()
setData
(
container
.
word
,
container
.
translation
,
true
,
wordPojo
,
container
.
clickable_view
)
showKeyboard
(
mainActivity
)
},
visible
(
mainActivity
.
btnSubmitLayout
)
R
.
id
.
main_activity_container
)
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
vocabulary
.
updateWord
(
wordPojo
.
apply
{
wordPojo
.
word
=
container
.
word
.
text
.
toString
()
wordPojo
.
translation
=
container
.
translation
.
text
.
toString
()
})
this
.
sort
()
gone
(
mainActivity
.
btnSubmitLayout
)
container
.
word
.
clearFocus
()
container
.
translation
.
clearFocus
()
visible
(
container
.
clickable_view
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
showPopupMenu
=
true
}
mainActivity
.
btnCancelWord
.
setOnClickListener
{
container
.
word
.
setText
(
wordPojo
.
word
)
container
.
translation
.
setText
(
wordPojo
.
translation
)
gone
(
mainActivity
.
btnSubmitLayout
)
container
.
word
.
clearFocus
()
container
.
translation
.
clearFocus
()
visible
(
container
.
clickable_view
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
showPopupMenu
=
true
}
}
}
fun
filter
(
query
:
String
)
{
fun
filter
(
query
:
String
)
{
...
...
app/src/main/res/layout/content_main.xml
View file @
08e99dc1
...
@@ -42,6 +42,6 @@
...
@@ -42,6 +42,6 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</LinearLayout>
<
include
layout=
"@layout/submit"
/
>
<
!--<include layout="@layout/submit" />--
>
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
app/src/main/res/layout/submit.xml
View file @
08e99dc1
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
android:layout_alignParentBottom=
"true"
android:layout_alignParentBottom=
"true"
android:background=
"@color/colorPrimary"
android:background=
"@color/colorPrimary"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
android:visibility=
"
gon
e"
>
android:visibility=
"
visibl
e"
>
<ImageButton
<ImageButton
android:id=
"@+id/btnCancelWord"
android:id=
"@+id/btnCancelWord"
...
...
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