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
Hide 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() {
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
if
(
item
!!
.
itemId
==
R
.
id
.
sortByTime
)
vocabularyAdapter
.
sort
=
Sort
.
BY_TIME
if
(
item
.
itemId
==
R
.
id
.
sortByWord
)
vocabularyAdapter
.
sort
=
Sort
.
BY_WORD
if
(
item
.
itemId
==
R
.
id
.
sortByTranslation
)
vocabularyAdapter
.
sort
=
Sort
.
BY_TRANSLATION
vocabularyAdapter
.
sort
=
when
(
item
!!
.
itemId
)
{
R
.
id
.
sortByWord
->
Sort
.
BY_WORD
R
.
id
.
sortByTranslation
->
Sort
.
BY_TRANSLATION
else
->
Sort
.
BY_TIME
}
return
super
.
onOptionsItemSelected
(
item
)
}
...
...
@@ -69,9 +67,8 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpNavigationView
()
{
navigationView
.
setNavigationItemSelectedListener
{
menuItem
->
menuItem
.
isChecked
=
true
if
(
menuItem
.
itemId
==
R
.
id
.
logOut
)
{
if
(
menuItem
.
itemId
==
R
.
id
.
logOut
)
logOut
()
}
drawerLayout
!!
.
closeDrawers
()
true
}
...
...
@@ -83,7 +80,6 @@ class MainActivity : AppCompatActivity() {
}
private
fun
setUpVocabularyAdapter
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
FirestoreManager
().
extractVocabularyId
({
FirestoreManager
().
extractVocabulary
{
querySnapshot
->
...
...
@@ -106,10 +102,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
)
}
val
view
=
activity
.
currentFocus
?:
View
(
activity
)
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
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.word_item.*
...
...
@@ -23,13 +22,13 @@ open class AddWordFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
submit
()
}
/*
mainActivity.btnSubmitWord.setOnClickListener { submit() }
mainActivity.btnCancelWord.setOnClickListener { cancel() }
word.setOnTouchListener { _, _ ->
visible(mainActivity.btnSubmitLayout);false }
translation.setOnTouchListener { _, _ ->
visible
(
mainActivity
.
btnSubmitLayout
);
false
}
visible(mainActivity.btnSubmitLayout); false }
*/
}
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.*
class
TagFragment
:
Fragment
()
{
private
lateinit
var
mainActivity
:
MainActivity
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
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
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
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.utils.Log
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.visible
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.word_item.view.*
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
this
.
sort
()
}
fun
updateWord
(
wordPojo
:
WordPojo
)
{
vocabulary
.
updateWord
(
wordPojo
)
this
.
sort
()
}
private
fun
sort
()
{
vocabulary
.
sort
(
sort
)
this
.
notifyDataSetChanged
()
...
...
@@ -101,34 +104,11 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
@SuppressLint
(
"ResourceType"
)
private
fun
editWord
(
container
:
View
,
wordPojo
:
WordPojo
)
{
showPopupMenu
=
false
gone
(
container
.
clickable_view
)
container
.
word
.
requestFocus
()
showKeyboard
(
mainActivity
)
visible
(
mainActivity
.
btnSubmitLayout
)
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
}
addFragment
(
mainActivity
.
supportFragmentManager
,
SubmitFragment
().
apply
{
setData
(
container
.
word
,
container
.
translation
,
true
,
wordPojo
,
container
.
clickable_view
)
},
R
.
id
.
main_activity_container
)
}
fun
filter
(
query
:
String
)
{
...
...
app/src/main/res/layout/content_main.xml
View file @
08e99dc1
...
...
@@ -42,6 +42,6 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
<
include
layout=
"@layout/submit"
/
>
<
!--<include layout="@layout/submit" />--
>
</RelativeLayout>
\ No newline at end of file
app/src/main/res/layout/submit.xml
View file @
08e99dc1
...
...
@@ -8,7 +8,7 @@
android:layout_alignParentBottom=
"true"
android:background=
"@color/colorPrimary"
android:orientation=
"horizontal"
android:visibility=
"
gon
e"
>
android:visibility=
"
visibl
e"
>
<ImageButton
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