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
80ba4a9b
authored
Apr 24, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added state behavior
parent
148396ff
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
25 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/recycler_view/State.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
80ba4a9b
...
...
@@ -12,8 +12,8 @@ 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.fragments.SubmitFragment
import
com.paktalin.vocabularynotebook.ui.fragments.TagFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.State
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
...
...
@@ -135,12 +135,12 @@ class MainActivity : AppCompatActivity() {
}
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
&&
SubmitFragment
.
zeroInstances
())
{
if
(!
selection
.
isEmpty
&&
vocabularyAdapter
.
state
.
notAddOrEdit
())
{
vocabularyAdapter
.
state
.
set
(
State
.
TAG
)
tagFragment
.
setSelection
(
selection
.
toList
())
addFragment
(
supportFragmentManager
,
tagFragment
,
R
.
id
.
main_activity_container
)
}
else
if
(
selection
.
isEmpty
)
{
vocabularyAdapter
.
editAllowed
=
true
}
else
{
vocabularyAdapter
.
state
.
set
(
State
.
NONE
)
removeFragment
(
supportFragmentManager
,
tagFragment
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitAddedFragment.kt
View file @
80ba4a9b
package
com.paktalin.vocabularynotebook.ui.fragments
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.recycler_view.State
import
com.paktalin.vocabularynotebook.utils.removeFragment
import
kotlinx.android.synthetic.main.word_item.*
class
SubmitAddedFragment
:
SubmitFragment
()
{
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
editAllowed
=
false
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
ADD
)
wordEt
=
mainActivity
.
word
translationEt
=
mainActivity
.
translation
}
...
...
@@ -27,7 +28,7 @@ class SubmitAddedFragment : SubmitFragment() {
override
fun
finish
()
{
wordEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
mainActivity
.
vocabularyAdapter
.
editAllowed
=
true
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
NONE
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitEditedFragment.kt
View file @
80ba4a9b
...
...
@@ -3,6 +3,7 @@ package com.paktalin.vocabularynotebook.ui.fragments
import
android.view.View
import
android.widget.EditText
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.recycler_view.State
import
com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.removeFragment
...
...
@@ -21,7 +22,7 @@ class SubmitEditedFragment : SubmitFragment() {
scrollToPositionWithOffset
(
recyclerViewPosition
,
2
)
isScrollEnabled
=
false
}
mainActivity
.
vocabularyAdapter
.
editAllowed
=
false
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
EDIT
)
gone
(
clickableView
)
wordEt
.
requestFocus
()
wordEt
.
setSelection
(
wordEt
.
text
.
length
)
...
...
@@ -46,7 +47,7 @@ class SubmitEditedFragment : SubmitFragment() {
translationEt
.
clearFocus
()
visible
(
clickableView
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
vocabularyAdapter
.
editAllowed
=
true
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
NONE
)
(
mainActivity
.
recyclerView
.
layoutManager
as
LockableLayoutManager
).
isScrollEnabled
=
true
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/State.kt
View file @
80ba4a9b
package
com.paktalin.vocabularynotebook.ui.recycler_view
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.word_item.*
enum
class
State
{
EDIT
,
ADD
,
TAG
,
NOTHING
EDIT
,
ADD
,
TAG
,
NONE
;
var
mainActivity
:
MainActivity
?
=
null
fun
setActivity
(
mainActivity
:
MainActivity
)
{
this
.
mainActivity
=
mainActivity
set
(
this
)
}
fun
set
(
state
:
State
)
{
when
(
state
)
{
EDIT
->
mainActivity
?.
clickable_view
?.
let
{
visible
(
it
)
}
TAG
->
mainActivity
?.
clickable_view
?.
let
{
visible
(
it
)
}
NONE
->
mainActivity
?.
clickable_view
?.
let
{
gone
(
it
)
}
ADD
->
{
}
}
}
fun
notAddOrEdit
():
Boolean
{
return
this
!=
ADD
&&
this
!=
EDIT
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
80ba4a9b
...
...
@@ -13,27 +13,19 @@ 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
lateinit
var
selectionTracker
:
MySelectionTracker
var
editAllowed
=
true
set
(
value
)
{
if
(!
value
)
visible
(
mainActivity
.
clickable_view
)
else
gone
(
mainActivity
.
clickable_view
)
Log
.
d
(
TAG
,
"editAllowed $editAllowed"
)
field
=
value
}
var
state
=
State
.
NONE
init
{
setHasStableIds
(
true
)
state
.
setActivity
(
mainActivity
)
}
override
fun
getItemId
(
position
:
Int
):
Long
=
position
.
toLong
()
...
...
@@ -63,12 +55,13 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
viewHolder
.
bind
(
vocabulary
.
displayedAt
(
position
),
position
,
selectionTracker
.
selected
(
position
.
toLong
()))
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
(
selectionTracker
.
selected
(
position
.
toLong
()))
&&
state
.
notAddOrEdit
())
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
// TODO not allow to edit when tag is being selected
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
if
(
editAllowed
)
{
if
(
state
==
State
.
NONE
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
...
...
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