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
742d65b0
authored
Apr 24, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved state change logic to vocabularyAdapter
parent
80ba4a9b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
36 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/vocabulary/Sort.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
742d65b0
...
@@ -136,11 +136,11 @@ class MainActivity : AppCompatActivity() {
...
@@ -136,11 +136,11 @@ class MainActivity : AppCompatActivity() {
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
&&
vocabularyAdapter
.
state
.
notAddOrEdit
())
{
if
(!
selection
.
isEmpty
&&
vocabularyAdapter
.
state
.
notAddOrEdit
())
{
vocabularyAdapter
.
state
.
set
(
State
.
TAG
)
vocabularyAdapter
.
state
=
State
.
TAG
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
{
}
else
{
vocabularyAdapter
.
state
.
set
(
State
.
NONE
)
vocabularyAdapter
.
state
=
State
.
NONE
removeFragment
(
supportFragmentManager
,
tagFragment
)
removeFragment
(
supportFragmentManager
,
tagFragment
)
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitAddedFragment.kt
View file @
742d65b0
...
@@ -8,7 +8,7 @@ import kotlinx.android.synthetic.main.word_item.*
...
@@ -8,7 +8,7 @@ import kotlinx.android.synthetic.main.word_item.*
class
SubmitAddedFragment
:
SubmitFragment
()
{
class
SubmitAddedFragment
:
SubmitFragment
()
{
override
fun
init
()
{
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
ADD
)
mainActivity
.
vocabularyAdapter
.
state
=
State
.
ADD
wordEt
=
mainActivity
.
word
wordEt
=
mainActivity
.
word
translationEt
=
mainActivity
.
translation
translationEt
=
mainActivity
.
translation
}
}
...
@@ -28,7 +28,7 @@ class SubmitAddedFragment : SubmitFragment() {
...
@@ -28,7 +28,7 @@ class SubmitAddedFragment : SubmitFragment() {
override
fun
finish
()
{
override
fun
finish
()
{
wordEt
.
text
.
clear
()
wordEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
translationEt
.
text
.
clear
()
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
NONE
)
mainActivity
.
vocabularyAdapter
.
state
=
State
.
NONE
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
return
return
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitEditedFragment.kt
View file @
742d65b0
...
@@ -22,7 +22,7 @@ class SubmitEditedFragment : SubmitFragment() {
...
@@ -22,7 +22,7 @@ class SubmitEditedFragment : SubmitFragment() {
scrollToPositionWithOffset
(
recyclerViewPosition
,
2
)
scrollToPositionWithOffset
(
recyclerViewPosition
,
2
)
isScrollEnabled
=
false
isScrollEnabled
=
false
}
}
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
EDIT
)
mainActivity
.
vocabularyAdapter
.
state
=
State
.
EDIT
gone
(
clickableView
)
gone
(
clickableView
)
wordEt
.
requestFocus
()
wordEt
.
requestFocus
()
wordEt
.
setSelection
(
wordEt
.
text
.
length
)
wordEt
.
setSelection
(
wordEt
.
text
.
length
)
...
@@ -47,7 +47,7 @@ class SubmitEditedFragment : SubmitFragment() {
...
@@ -47,7 +47,7 @@ class SubmitEditedFragment : SubmitFragment() {
translationEt
.
clearFocus
()
translationEt
.
clearFocus
()
visible
(
clickableView
)
visible
(
clickableView
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
vocabularyAdapter
.
state
.
set
(
State
.
NONE
)
mainActivity
.
vocabularyAdapter
.
state
=
State
.
NONE
(
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/recycler_view/State.kt
View file @
742d65b0
package
com.paktalin.vocabularynotebook.ui.recycler_view
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
{
enum
class
State
{
EDIT
,
ADD
,
TAG
,
NONE
;
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
{
fun
notAddOrEdit
():
Boolean
{
return
this
!=
ADD
&&
this
!=
EDIT
return
this
!=
ADD
&&
this
!=
EDIT
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
742d65b0
...
@@ -13,8 +13,11 @@ import com.paktalin.vocabularynotebook.ui.fragments.SubmitEditedFragment
...
@@ -13,8 +13,11 @@ 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
>()
{
...
@@ -22,20 +25,28 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
...
@@ -22,20 +25,28 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
lateinit
var
selectionTracker
:
MySelectionTracker
lateinit
var
selectionTracker
:
MySelectionTracker
var
state
=
State
.
NONE
var
state
=
State
.
NONE
set
(
state
)
{
when
(
state
)
{
State
.
EDIT
->
mainActivity
.
clickable_view
?.
let
{
visible
(
it
)
}
State
.
TAG
->
mainActivity
.
clickable_view
?.
let
{
visible
(
it
)
}
State
.
NONE
->
mainActivity
.
clickable_view
?.
let
{
gone
(
it
)
}
State
.
ADD
->
{
}
}
field
=
state
}
var
sort
:
Sort
=
Sort
.
BY_TIME
set
(
value
)
{
field
=
value
sort
()
}
init
{
init
{
setHasStableIds
(
true
)
setHasStableIds
(
true
)
state
.
setActivity
(
mainActivity
)
}
}
override
fun
getItemId
(
position
:
Int
):
Long
=
position
.
toLong
()
override
fun
getItemId
(
position
:
Int
):
Long
=
position
.
toLong
()
var
sort
:
Sort
=
Sort
.
BY_TIME
set
(
value
)
{
field
=
value
sort
()
}
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
super
.
onAttachedToRecyclerView
(
recyclerView
)
this
.
recyclerView
=
recyclerView
this
.
recyclerView
=
recyclerView
...
...
app/src/main/java/com/paktalin/vocabularynotebook/vocabulary/Sort.kt
View file @
742d65b0
package
com.paktalin.vocabularynotebook.vocabulary
package
com.paktalin.vocabularynotebook.vocabulary
enum
class
Sort
{
enum
class
Sort
{
BY_TIME
,
BY_WORD
,
BY_TRANSLATION
BY_TIME
,
BY_WORD
,
BY_TRANSLATION
;
}
}
\ No newline at end of file
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