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
f08675b2
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split SubmitFragment into Add and Edit Fragments
parent
08e99dc1
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
136 additions
and
121 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/SubmitAddedFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitEditedFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
app/src/main/res/layout/content_main.xml
app/src/main/res/layout/word_item.xml
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
f08675b2
...
...
@@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.widget.SearchView
import
androidx.recyclerview.selection.Selection
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitAddedFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
...
...
@@ -19,6 +20,7 @@ import com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.word_item.*
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -33,6 +35,7 @@ class MainActivity : AppCompatActivity() {
recyclerView
.
layoutManager
=
LockableLayoutManager
(
this
@MainActivity
)
setUpSwipeRefresh
()
setUpNavigationView
()
setUpAddWordTouchListeners
()
hideKeyboard
()
}
...
...
@@ -96,6 +99,17 @@ class MainActivity : AppCompatActivity() {
{
removeProgressBar
(
supportFragmentManager
)
},
this
)
}
private
fun
setUpAddWordTouchListeners
()
{
word
.
setOnTouchListener
{
_
,
_
->
addSubmitFragment
(
supportFragmentManager
,
SubmitAddedFragment
(),
R
.
id
.
main_activity_container
)
false
}
translation
.
setOnTouchListener
{
_
,
_
->
addSubmitFragment
(
supportFragmentManager
,
SubmitAddedFragment
(),
R
.
id
.
main_activity_container
)
false
}
}
private
fun
hideKeyboard
()
{
window
.
setSoftInputMode
(
WindowManager
.
LayoutParams
.
SOFT_INPUT_STATE_HIDDEN
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
deleted
100644 → 0
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
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
kotlinx.android.synthetic.main.submit.*
import
kotlinx.android.synthetic.main.word_item.*
open
class
AddWordFragment
:
Fragment
()
{
private
lateinit
var
mainActivity
:
MainActivity
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
word_item
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
/*mainActivity.btnSubmitWord.setOnClickListener { submit() }
mainActivity.btnCancelWord.setOnClickListener { cancel() }
word.setOnTouchListener { _, _ ->
visible(mainActivity.btnSubmitLayout);false }
translation.setOnTouchListener { _, _ ->
visible(mainActivity.btnSubmitLayout); false }*/
}
private
fun
submit
()
{
finish
()
mainActivity
.
vocabularyAdapter
.
addWord
(
WordPojo
(
word
.
text
.
toString
(),
translation
.
text
.
toString
()))
this
.
word
.
requestFocus
()
return
}
private
fun
cancel
()
{
finish
()
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
}
private
fun
finish
()
{
word
.
text
.
clear
()
translation
.
text
.
clear
()
gone
(
mainActivity
.
btnSubmitLayout
)
}
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/SubmitAddedFragment.kt
0 → 100644
View file @
f08675b2
package
com.paktalin.vocabularynotebook.ui.fragments
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.utils.removeFragment
import
kotlinx.android.synthetic.main.word_item.*
class
SubmitAddedFragment
:
SubmitFragment
()
{
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
wordEt
=
mainActivity
.
word
translationEt
=
mainActivity
.
translation
}
override
fun
submit
()
{
mainActivity
.
vocabularyAdapter
.
addWord
(
WordPojo
(
wordEt
.
text
.
toString
(),
translationEt
.
text
.
toString
()))
wordEt
.
requestFocus
()
finish
()
return
}
override
fun
cancel
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
finish
()
}
override
fun
finish
()
{
wordEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitEditedFragment.kt
0 → 100644
View file @
f08675b2
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.view.View
import
android.widget.EditText
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.removeFragment
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.visible
class
SubmitEditedFragment
:
SubmitFragment
()
{
private
lateinit
var
clickableView
:
View
private
lateinit
var
wordPojo
:
WordPojo
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
// visible(mainActivity.clickable_view)
gone
(
clickableView
)
wordEt
.
requestFocus
()
showKeyboard
(
mainActivity
)
}
override
fun
submit
()
{
wordPojo
.
word
=
wordEt
.
text
.
toString
()
wordPojo
.
translation
=
translationEt
.
text
.
toString
()
mainActivity
.
vocabularyAdapter
.
updateWord
(
wordPojo
)
finish
()
}
override
fun
cancel
()
{
wordEt
.
setText
(
wordPojo
.
word
)
translationEt
.
setText
(
wordPojo
.
translation
)
finish
()
}
override
fun
finish
()
{
wordEt
.
clearFocus
()
translationEt
.
clearFocus
()
visible
(
clickableView
)
// gone(mainActivity.clickable_view)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
}
fun
setData
(
wordEt
:
EditText
,
translationEt
:
EditText
,
wordPojo
:
WordPojo
,
clickableView
:
View
)
{
this
.
wordEt
=
wordEt
this
.
translationEt
=
translationEt
this
.
wordPojo
=
wordPojo
this
.
clickableView
=
clickableView
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitFragment.kt
View file @
f08675b2
package
com.paktalin.vocabularynotebook.ui.fragments
import
android.content.Context
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
...
...
@@ -7,23 +8,19 @@ 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
abstract
class
SubmitFragment
:
Fragment
()
{
pr
ivate
lateinit
var
wordEt
:
EditText
pr
ivate
lateinit
var
translation
Et
:
EditText
pr
ivate
var
clickableView
:
View
?
=
null
pr
otected
lateinit
var
mainActivity
:
MainActivity
pr
otected
lateinit
var
word
Et
:
EditText
pr
otected
lateinit
var
translationEt
:
EditText
private
lateinit
var
wordPojo
:
WordPojo
private
var
edit
:
Boolean
=
false
override
fun
onAttach
(
context
:
Context
?)
{
super
.
onAttach
(
context
)
instances
++
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
submit
,
container
,
false
)
...
...
@@ -34,55 +31,21 @@ class SubmitFragment : Fragment() {
mainActivity
=
activity
as
MainActivity
btnSubmitWord
.
setOnClickListener
{
submit
()
}
btnCancelWord
.
setOnClickListener
{
cancel
()
}
if
(
edit
)
{
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
clickableView
?.
let
{
gone
(
it
)
}
wordEt
.
requestFocus
()
showKeyboard
(
mainActivity
)
}
init
()
}
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
}
abstract
fun
finish
()
abstract
fun
init
()
abstract
fun
submit
()
abstract
fun
cancel
()
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
override
fun
onDetach
()
{
super
.
onDetach
()
instances
--
}
companion
object
{
private
val
TAG
=
"VN/"
+
SubmitFragment
::
class
.
java
.
simpleName
var
instances
:
Int
=
0
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
f08675b2
...
...
@@ -9,10 +9,10 @@ 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.fragments.Submit
Edited
Fragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.utils.add
Submit
Fragment
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
kotlinx.android.synthetic.main.word_item.view.*
...
...
@@ -104,9 +104,9 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
@SuppressLint
(
"ResourceType"
)
private
fun
editWord
(
container
:
View
,
wordPojo
:
WordPojo
)
{
addFragment
(
mainActivity
.
supportFragmentManager
,
SubmitFragment
().
apply
{
setData
(
container
.
word
,
container
.
translation
,
true
,
wordPojo
,
container
.
clickable_view
)
add
Submit
Fragment
(
mainActivity
.
supportFragmentManager
,
Submit
Edited
Fragment
().
apply
{
setData
(
container
.
word
,
container
.
translation
,
wordPojo
,
container
.
clickable_view
)
},
R
.
id
.
main_activity_container
)
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
f08675b2
...
...
@@ -11,6 +11,7 @@ import androidx.fragment.app.Fragment
import
androidx.fragment.app.FragmentManager
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import
com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import
org.apache.commons.lang3.StringUtils
...
...
@@ -36,6 +37,10 @@ fun addTagFragment(fragmentManager: FragmentManager, containerId: Int) {
addFragment
(
fragmentManager
,
tagFragment
,
containerId
)
}
fun
addSubmitFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
SubmitFragment
,
containerId
:
Int
)
{
if
(
SubmitFragment
.
instances
==
0
)
addFragment
(
fragmentManager
,
fragment
,
containerId
)
}
fun
removeTagFragment
(
fragmentManager
:
FragmentManager
)
{
removeFragment
(
fragmentManager
,
tagFragment
)
}
...
...
app/src/main/res/layout/content_main.xml
View file @
f08675b2
...
...
@@ -12,9 +12,8 @@
android:layout_margin=
"@dimen/small_margin"
android:orientation=
"vertical"
>
<fragment
android:id=
"@+id/fragmentAddWord"
android:name=
"com.paktalin.vocabularynotebook.ui.fragments.AddWordFragment"
<include
layout=
"@layout/word_item"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"@dimen/small_margin"
...
...
@@ -42,6 +41,4 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
<!--<include layout="@layout/submit" />-->
</RelativeLayout>
\ No newline at end of file
app/src/main/res/layout/word_item.xml
View file @
f08675b2
...
...
@@ -72,7 +72,7 @@
android:id=
"@+id/clickable_view"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@android:color/
transparent
"
android:background=
"@android:color/
holo_green_dark
"
android:clickable=
"true"
android:focusable=
"true"
android:visibility=
"gone"
/>
...
...
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