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
f0081656
authored
Apr 25, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made vocabularyAdapter nullable
parent
742d65b0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
21 deletions
.idea/caches/build_file_checksums.ser
.idea/misc.xml
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
.idea/caches/build_file_checksums.ser
View file @
f0081656
No preview for this file type
.idea/misc.xml
View file @
f0081656
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
</value>
</value>
</option>
</option>
</component>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
</component>
<component
name=
"ProjectType"
>
<component
name=
"ProjectType"
>
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
f0081656
...
@@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.word_item.*
...
@@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.word_item.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
var
searchView
:
SearchView
?
=
null
var
searchView
:
SearchView
?
=
null
lateinit
var
vocabularyAdapter
:
VocabularyAdapter
var
vocabularyAdapter
:
VocabularyAdapter
?
=
null
private
var
tagFragment
=
TagFragment
()
private
var
tagFragment
=
TagFragment
()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
@@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity() {
}
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
vocabularyAdapter
.
sort
=
when
(
item
!!
.
itemId
)
{
vocabularyAdapter
?
.
sort
=
when
(
item
!!
.
itemId
)
{
R
.
id
.
sortByWord
->
Sort
.
BY_WORD
R
.
id
.
sortByWord
->
Sort
.
BY_WORD
R
.
id
.
sortByTranslation
->
Sort
.
BY_TRANSLATION
R
.
id
.
sortByTranslation
->
Sort
.
BY_TRANSLATION
else
->
Sort
.
BY_TIME
else
->
Sort
.
BY_TIME
...
@@ -66,7 +66,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -66,7 +66,7 @@ class MainActivity : AppCompatActivity() {
}
}
private
fun
refreshVocabulary
()
{
private
fun
refreshVocabulary
()
{
vocabularyAdapter
.
refresh
()
vocabularyAdapter
?
.
refresh
()
swipeRefresh
.
isRefreshing
=
false
swipeRefresh
.
isRefreshing
=
false
}
}
...
@@ -128,20 +128,22 @@ class MainActivity : AppCompatActivity() {
...
@@ -128,20 +128,22 @@ class MainActivity : AppCompatActivity() {
}
}
private
fun
setUpSelectionTracker
()
{
private
fun
setUpSelectionTracker
()
{
vocabularyAdapter
.
selectionTracker
=
MySelectionTracker
().
apply
{
vocabularyAdapter
?
.
selectionTracker
=
MySelectionTracker
().
apply
{
init
(
recyclerView
)
init
(
recyclerView
)
addObserver
{
selection
->
whenSelectionChanges
(
selection
)
}
addObserver
{
selection
->
whenSelectionChanges
(
selection
)
}
}
}
}
}
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
&&
vocabularyAdapter
.
state
.
notAddOrEdit
())
{
vocabularyAdapter
?.
let
{
vocabularyAdapter
.
state
=
State
.
TAG
if
(!
selection
.
isEmpty
&&
it
.
state
.
notAddOrEdit
())
{
tagFragment
.
setSelection
(
selection
.
toList
())
vocabularyAdapter
?.
state
=
State
.
TAG
addFragment
(
supportFragmentManager
,
tagFragment
,
R
.
id
.
main_activity_container
)
tagFragment
.
setSelection
(
selection
.
toList
())
}
else
{
addFragment
(
supportFragmentManager
,
tagFragment
,
R
.
id
.
main_activity_container
)
vocabularyAdapter
.
state
=
State
.
NONE
}
else
{
removeFragment
(
supportFragmentManager
,
tagFragment
)
vocabularyAdapter
?.
state
=
State
.
NONE
removeFragment
(
supportFragmentManager
,
tagFragment
)
}
}
}
}
}
...
@@ -149,7 +151,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -149,7 +151,7 @@ class MainActivity : AppCompatActivity() {
super
.
onPause
()
super
.
onPause
()
hideKeyboard
()
hideKeyboard
()
try
{
try
{
FirestoreManager
().
saveWords
(
vocabularyAdapter
.
getModifiedWords
())
vocabularyAdapter
?.
getModifiedWords
()
?.
let
{
FirestoreManager
().
saveWords
(
it
)
}
}
catch
(
ignored
:
Exception
)
{
}
catch
(
ignored
:
Exception
)
{
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/SubmitAddedFragment.kt
View file @
f0081656
...
@@ -8,13 +8,13 @@ import kotlinx.android.synthetic.main.word_item.*
...
@@ -8,13 +8,13 @@ import kotlinx.android.synthetic.main.word_item.*
class
SubmitAddedFragment
:
SubmitFragment
()
{
class
SubmitAddedFragment
:
SubmitFragment
()
{
override
fun
init
()
{
override
fun
init
()
{
mainActivity
.
vocabularyAdapter
.
state
=
State
.
ADD
mainActivity
.
vocabularyAdapter
?
.
state
=
State
.
ADD
wordEt
=
mainActivity
.
word
wordEt
=
mainActivity
.
word
translationEt
=
mainActivity
.
translation
translationEt
=
mainActivity
.
translation
}
}
override
fun
submit
()
{
override
fun
submit
()
{
mainActivity
.
vocabularyAdapter
.
addWord
(
WordPojo
(
wordEt
.
text
.
toString
(),
translationEt
.
text
.
toString
()))
mainActivity
.
vocabularyAdapter
?
.
addWord
(
WordPojo
(
wordEt
.
text
.
toString
(),
translationEt
.
text
.
toString
()))
wordEt
.
requestFocus
()
wordEt
.
requestFocus
()
finish
()
finish
()
return
return
...
@@ -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
=
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 @
f0081656
...
@@ -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
=
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
)
...
@@ -32,7 +32,7 @@ class SubmitEditedFragment : SubmitFragment() {
...
@@ -32,7 +32,7 @@ class SubmitEditedFragment : SubmitFragment() {
override
fun
submit
()
{
override
fun
submit
()
{
wordPojo
.
word
=
wordEt
.
text
.
toString
()
wordPojo
.
word
=
wordEt
.
text
.
toString
()
wordPojo
.
translation
=
translationEt
.
text
.
toString
()
wordPojo
.
translation
=
translationEt
.
text
.
toString
()
mainActivity
.
vocabularyAdapter
.
updateWord
(
wordPojo
)
mainActivity
.
vocabularyAdapter
?
.
updateWord
(
wordPojo
)
finish
()
finish
()
}
}
...
@@ -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
=
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/fragments/TagFragment.kt
View file @
f0081656
...
@@ -36,12 +36,12 @@ class TagFragment : Fragment() {
...
@@ -36,12 +36,12 @@ class TagFragment : Fragment() {
if
(
it
.
isBlank
())
if
(
it
.
isBlank
())
shortToast
(
mainActivity
,
mainActivity
.
getString
(
R
.
string
.
toast_tag_cannot_be_empty
))
shortToast
(
mainActivity
,
mainActivity
.
getString
(
R
.
string
.
toast_tag_cannot_be_empty
))
else
else
mainActivity
.
vocabularyAdapter
.
addTagToSelected
(
it
)
mainActivity
.
vocabularyAdapter
?
.
addTagToSelected
(
it
)
}
}
}
}
private
fun
cancel
()
{
private
fun
cancel
()
{
mainActivity
.
vocabularyAdapter
.
selectionTracker
.
clearSelection
()
mainActivity
.
vocabularyAdapter
?.
selectionTracker
?
.
clearSelection
()
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
}
}
...
...
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