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
Show 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() {
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
&&
SubmitFragment
.
zeroInstances
())
{
vocabularyAdapter
.
showPopupMenu
=
false
tagFragment
.
setSelection
(
selection
.
toList
())
addFragment
(
supportFragmentManager
,
tagFragment
,
R
.
id
.
main_activity_container
)
}
else
if
(
selection
.
isEmpty
)
{
vocabularyAdapter
.
showPopupMenu
=
true
vocabularyAdapter
.
editAllowed
=
true
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.*
class
SubmitAddedFragment
:
SubmitFragment
()
{
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
mainActivity
.
vocabularyAdapter
.
editAllowed
=
false
wordEt
=
mainActivity
.
word
translationEt
=
mainActivity
.
translation
}
...
...
@@ -27,7 +27,7 @@ class SubmitAddedFragment : SubmitFragment() {
override
fun
finish
()
{
wordEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
mainActivity
.
vocabularyAdapter
.
editAllowed
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
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
import
com.paktalin.vocabularynotebook.utils.showKeyboard
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.word_item.*
class
SubmitEditedFragment
:
SubmitFragment
()
{
...
...
@@ -22,8 +21,7 @@ class SubmitEditedFragment : SubmitFragment() {
scrollToPositionWithOffset
(
recyclerViewPosition
,
2
)
isScrollEnabled
=
false
}
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
false
visible
(
mainActivity
.
clickable_view
)
mainActivity
.
vocabularyAdapter
.
editAllowed
=
false
gone
(
clickableView
)
wordEt
.
requestFocus
()
wordEt
.
setSelection
(
wordEt
.
text
.
length
)
...
...
@@ -47,9 +45,8 @@ class SubmitEditedFragment : SubmitFragment() {
wordEt
.
clearFocus
()
translationEt
.
clearFocus
()
visible
(
clickableView
)
gone
(
mainActivity
.
clickable_view
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
vocabularyAdapter
.
showPopupMenu
=
true
mainActivity
.
vocabularyAdapter
.
editAllowed
=
true
(
mainActivity
.
recyclerView
.
layoutManager
as
LockableLayoutManager
).
isScrollEnabled
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
View file @
148396ff
...
...
@@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
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
kotlinx.android.synthetic.main.fragment_tag.*
...
...
@@ -42,7 +42,7 @@ class TagFragment : Fragment() {
private
fun
cancel
()
{
mainActivity
.
vocabularyAdapter
.
selectionTracker
.
clearSelection
()
remove
TagFragment
(
mainActivity
.
supportFragmentManager
)
remove
Fragment
(
mainActivity
.
supportFragmentManager
,
this
)
}
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) {
private
val
tvWord
:
EditText
=
itemView
.
word
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
)
tvTranslation
.
setText
(
wordPojo
.
translation
)
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
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.utils.Log
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.VocabSet
import
kotlinx.android.synthetic.main.word_item.*
import
kotlinx.android.synthetic.main.word_item.view.*
class
VocabularyAdapter
(
private
val
vocabulary
:
VocabSet
,
private
val
mainActivity
:
MainActivity
)
:
RecyclerView
.
Adapter
<
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
viewHolder
:
ViewHolder
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
{
setHasStableIds
(
true
)
...
...
@@ -52,17 +60,15 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
override
fun
onBindViewHolder
(
viewHolder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
vocabulary
.
displayedAt
(
position
)
selectionTracker
.
let
{
viewHolder
.
bind
(
wordItem
,
position
,
it
.
selected
(
position
.
toLong
())
&&
showPopupMenu
)
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
}
this
.
viewHolder
=
viewHolder
//todo set click listener to menu
viewHolder
.
bind
(
vocabulary
.
displayedAt
(
position
),
position
,
selectionTracker
.
selected
(
position
.
toLong
()))
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
// TODO not allow to edit when tag is being selected
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
if
(
showPopupMenu
)
{
if
(
editAllowed
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
148396ff
...
...
@@ -12,11 +12,9 @@ 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
val
progressFragment
=
ProgressFragment
()
val
tagFragment
=
TagFragment
()
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arg
:
Bundle
?
=
null
,
tag
:
String
?
=
null
)
{
if
(!
fragment
.
isAdded
)
...
...
@@ -33,18 +31,10 @@ fun addProgressBar(fragmentManager: FragmentManager, containerId: Int) {
addFragment
(
fragmentManager
,
progressFragment
,
containerId
)
}
fun
addTagFragment
(
fragmentManager
:
FragmentManager
,
containerId
:
Int
)
{
addFragment
(
fragmentManager
,
tagFragment
,
containerId
)
}
fun
addSubmitFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
SubmitFragment
,
containerId
:
Int
)
{
if
(
SubmitFragment
.
zeroInstances
())
addFragment
(
fragmentManager
,
fragment
,
containerId
)
}
fun
removeTagFragment
(
fragmentManager
:
FragmentManager
)
{
removeFragment
(
fragmentManager
,
tagFragment
)
}
fun
removeProgressBar
(
fragmentManager
:
FragmentManager
)
{
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