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
148396ff
authored
Apr 22, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more editing restrictions
parent
9f71b0c0
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
32 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.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/TagFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/State.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/ViewHolder.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/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
148396ff
...
@@ -137,11 +137,10 @@ class MainActivity : AppCompatActivity() {
...
@@ -137,11 +137,10 @@ class MainActivity : AppCompatActivity() {
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
&&
SubmitFragment
.
zeroInstances
())
{
if
(!
selection
.
isEmpty
&&
SubmitFragment
.
zeroInstances
())
{
vocabularyAdapter
.
showPopupMenu
=
false
tagFragment
.
setSelection
(
selection
.
toList
())
tagFragment
.
setSelection
(
selection
.
toList
())
addFragment
(
supportFragmentManager
,
tagFragment
,
R
.
id
.
main_activity_container
)
addFragment
(
supportFragmentManager
,
tagFragment
,
R
.
id
.
main_activity_container
)
}
else
if
(
selection
.
isEmpty
)
{
}
else
if
(
selection
.
isEmpty
)
{
vocabularyAdapter
.
showPopupMenu
=
true
vocabularyAdapter
.
editAllowed
=
true
removeFragment
(
supportFragmentManager
,
tagFragment
)
removeFragment
(
supportFragmentManager
,
tagFragment
)
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitAddedFragment.kt
View file @
148396ff
...
@@ -7,7 +7,7 @@ import kotlinx.android.synthetic.main.word_item.*
...
@@ -7,7 +7,7 @@ import kotlinx.android.synthetic.main.word_item.*
class
SubmitAddedFragment
:
SubmitFragment
()
{
class
SubmitAddedFragment
:
SubmitFragment
()
{
override
fun
init
()
{
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
mainActivity
.
vocabularyAdapter
.
editAllowed
=
false
wordEt
=
mainActivity
.
word
wordEt
=
mainActivity
.
word
translationEt
=
mainActivity
.
translation
translationEt
=
mainActivity
.
translation
}
}
...
@@ -27,7 +27,7 @@ class SubmitAddedFragment : SubmitFragment() {
...
@@ -27,7 +27,7 @@ class SubmitAddedFragment : SubmitFragment() {
override
fun
finish
()
{
override
fun
finish
()
{
wordEt
.
text
.
clear
()
wordEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
mainActivity
.
vocabularyAdapter
.
editAllowed
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
return
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitEditedFragment.kt
View file @
148396ff
...
@@ -9,7 +9,6 @@ import com.paktalin.vocabularynotebook.utils.removeFragment
...
@@ -9,7 +9,6 @@ import com.paktalin.vocabularynotebook.utils.removeFragment
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.visible
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.word_item.*
class
SubmitEditedFragment
:
SubmitFragment
()
{
class
SubmitEditedFragment
:
SubmitFragment
()
{
...
@@ -22,8 +21,7 @@ class SubmitEditedFragment : SubmitFragment() {
...
@@ -22,8 +21,7 @@ class SubmitEditedFragment : SubmitFragment() {
scrollToPositionWithOffset
(
recyclerViewPosition
,
2
)
scrollToPositionWithOffset
(
recyclerViewPosition
,
2
)
isScrollEnabled
=
false
isScrollEnabled
=
false
}
}
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
mainActivity
.
vocabularyAdapter
.
editAllowed
=
false
visible
(
mainActivity
.
clickable_view
)
gone
(
clickableView
)
gone
(
clickableView
)
wordEt
.
requestFocus
()
wordEt
.
requestFocus
()
wordEt
.
setSelection
(
wordEt
.
text
.
length
)
wordEt
.
setSelection
(
wordEt
.
text
.
length
)
...
@@ -47,9 +45,8 @@ class SubmitEditedFragment : SubmitFragment() {
...
@@ -47,9 +45,8 @@ class SubmitEditedFragment : SubmitFragment() {
wordEt
.
clearFocus
()
wordEt
.
clearFocus
()
translationEt
.
clearFocus
()
translationEt
.
clearFocus
()
visible
(
clickableView
)
visible
(
clickableView
)
gone
(
mainActivity
.
clickable_view
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
mainActivity
.
vocabularyAdapter
.
editAllowed
=
true
(
mainActivity
.
recyclerView
.
layoutManager
as
LockableLayoutManager
).
isScrollEnabled
=
true
(
mainActivity
.
recyclerView
.
layoutManager
as
LockableLayoutManager
).
isScrollEnabled
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
return
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
View file @
148396ff
...
@@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment
...
@@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.remove
Tag
Fragment
import
com.paktalin.vocabularynotebook.utils.removeFragment
import
com.paktalin.vocabularynotebook.utils.shortToast
import
com.paktalin.vocabularynotebook.utils.shortToast
import
kotlinx.android.synthetic.main.fragment_tag.*
import
kotlinx.android.synthetic.main.fragment_tag.*
...
@@ -42,7 +42,7 @@ class TagFragment : Fragment() {
...
@@ -42,7 +42,7 @@ class TagFragment : Fragment() {
private
fun
cancel
()
{
private
fun
cancel
()
{
mainActivity
.
vocabularyAdapter
.
selectionTracker
.
clearSelection
()
mainActivity
.
vocabularyAdapter
.
selectionTracker
.
clearSelection
()
remove
TagFragment
(
mainActivity
.
supportFragmentManager
)
remove
Fragment
(
mainActivity
.
supportFragmentManager
,
this
)
}
}
companion
object
{
companion
object
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/State.kt
0 → 100644
View file @
148396ff
package
com.paktalin.vocabularynotebook.ui.recycler_view
enum
class
State
{
EDIT
,
ADD
,
TAG
,
NOTHING
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/ViewHolder.kt
View file @
148396ff
...
@@ -13,7 +13,10 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
...
@@ -13,7 +13,10 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private
val
tvWord
:
EditText
=
itemView
.
word
private
val
tvWord
:
EditText
=
itemView
.
word
private
val
tvTranslation
:
EditText
=
itemView
.
translation
private
val
tvTranslation
:
EditText
=
itemView
.
translation
fun
bind
(
wordPojo
:
WordPojo
,
position
:
Int
,
isActivated
:
Boolean
,
showPopupMenu
:
(
View
,
Int
)
->
Unit
)
{
fun
bind
(
wordPojo
:
WordPojo
,
position
:
Int
,
isActivated
:
Boolean
,
showPopupMenu
:
(
View
,
Int
)
->
Unit
)
{
tvWord
.
setText
(
wordPojo
.
word
)
tvWord
.
setText
(
wordPojo
.
word
)
tvTranslation
.
setText
(
wordPojo
.
translation
)
tvTranslation
.
setText
(
wordPojo
.
translation
)
visible
(
itemView
.
clickable_view
)
visible
(
itemView
.
clickable_view
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
148396ff
...
@@ -13,16 +13,24 @@ import com.paktalin.vocabularynotebook.ui.fragments.SubmitEditedFragment
...
@@ -13,16 +13,24 @@ import com.paktalin.vocabularynotebook.ui.fragments.SubmitEditedFragment
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.addSubmitFragment
import
com.paktalin.vocabularynotebook.utils.addSubmitFragment
import
com.paktalin.vocabularynotebook.utils.gone
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.word_item.*
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
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
viewHolder
:
ViewHolder
lateinit
var
selectionTracker
:
MySelectionTracker
lateinit
var
selectionTracker
:
MySelectionTracker
var
showPopupMenu
=
true
var
editAllowed
=
true
set
(
value
)
{
if
(!
value
)
visible
(
mainActivity
.
clickable_view
)
else
gone
(
mainActivity
.
clickable_view
)
Log
.
d
(
TAG
,
"editAllowed $editAllowed"
)
field
=
value
}
init
{
init
{
setHasStableIds
(
true
)
setHasStableIds
(
true
)
...
@@ -52,17 +60,15 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
...
@@ -52,17 +60,15 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
}
override
fun
onBindViewHolder
(
viewHolder
:
ViewHolder
,
position
:
Int
)
{
override
fun
onBindViewHolder
(
viewHolder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
vocabulary
.
displayedAt
(
position
)
viewHolder
.
bind
(
selectionTracker
.
let
{
vocabulary
.
displayedAt
(
position
),
viewHolder
.
bind
(
wordItem
,
position
,
it
.
selected
(
position
.
toLong
())
&&
showPopupMenu
)
position
,
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
selectionTracker
.
selected
(
position
.
toLong
()))
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
}
// TODO not allow to edit when tag is being selected
this
.
viewHolder
=
viewHolder
//todo set click listener to menu
}
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
if
(
showPopupMenu
)
{
if
(
editAllowed
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
val
popup
=
PopupMenu
(
mainActivity
,
v
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
popup
.
setOnMenuItemClickListener
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
148396ff
...
@@ -12,11 +12,9 @@ import androidx.fragment.app.FragmentManager
...
@@ -12,11 +12,9 @@ import androidx.fragment.app.FragmentManager
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import
com.paktalin.vocabularynotebook.ui.fragments.SubmitFragment
import
com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import
org.apache.commons.lang3.StringUtils
import
org.apache.commons.lang3.StringUtils
val
progressFragment
=
ProgressFragment
()
val
progressFragment
=
ProgressFragment
()
val
tagFragment
=
TagFragment
()
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arg
:
Bundle
?
=
null
,
tag
:
String
?
=
null
)
{
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arg
:
Bundle
?
=
null
,
tag
:
String
?
=
null
)
{
if
(!
fragment
.
isAdded
)
if
(!
fragment
.
isAdded
)
...
@@ -33,18 +31,10 @@ fun addProgressBar(fragmentManager: FragmentManager, containerId: Int) {
...
@@ -33,18 +31,10 @@ fun addProgressBar(fragmentManager: FragmentManager, containerId: Int) {
addFragment
(
fragmentManager
,
progressFragment
,
containerId
)
addFragment
(
fragmentManager
,
progressFragment
,
containerId
)
}
}
fun
addTagFragment
(
fragmentManager
:
FragmentManager
,
containerId
:
Int
)
{
addFragment
(
fragmentManager
,
tagFragment
,
containerId
)
}
fun
addSubmitFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
SubmitFragment
,
containerId
:
Int
)
{
fun
addSubmitFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
SubmitFragment
,
containerId
:
Int
)
{
if
(
SubmitFragment
.
zeroInstances
())
addFragment
(
fragmentManager
,
fragment
,
containerId
)
if
(
SubmitFragment
.
zeroInstances
())
addFragment
(
fragmentManager
,
fragment
,
containerId
)
}
}
fun
removeTagFragment
(
fragmentManager
:
FragmentManager
)
{
removeFragment
(
fragmentManager
,
tagFragment
)
}
fun
removeProgressBar
(
fragmentManager
:
FragmentManager
)
{
fun
removeProgressBar
(
fragmentManager
:
FragmentManager
)
{
removeFragment
(
fragmentManager
,
progressFragment
)
removeFragment
(
fragmentManager
,
progressFragment
)
}
}
...
...
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