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
bde85cd1
authored
Sep 14, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Words are searchable
parent
d51c6159
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
16 deletions
app/src/main/java/com/paktalin/vocabularynotebook/OnQueryTextListener.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/res/menu/options_menu.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/searchable.xml
app/src/main/java/com/paktalin/vocabularynotebook/OnQueryTextListener.kt
0 → 100644
View file @
bde85cd1
package
com.paktalin.vocabularynotebook
import
android.support.v7.widget.RecyclerView
import
android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
class
OnQueryTextListener
(
var
recyclerView
:
RecyclerView
)
:
SearchView
.
OnQueryTextListener
{
override
fun
onQueryTextSubmit
(
query
:
String
):
Boolean
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
filter
(
query
)
return
true
}
override
fun
onQueryTextChange
(
query
:
String
):
Boolean
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
filter
(
query
)
return
true
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
bde85cd1
...
@@ -15,13 +15,19 @@ import com.paktalin.vocabularynotebook.ui.EditWordFragment
...
@@ -15,13 +15,19 @@ import com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
kotlinx.android.synthetic.main.word_item.view.*
import
kotlinx.android.synthetic.main.word_item.view.*
class
VocabularyAdapter
(
private
val
vocabulary
:
Vocabulary
,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
class
VocabularyAdapter
(
internal
val
vocabulary
:
Vocabulary
,
private
val
activity
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
private
var
sortOrder
:
Int
=
0
private
var
sortOrder
:
Int
=
0
set
(
value
)
{
field
=
value
;
sort
()
}
set
(
value
)
{
field
=
value
;
sort
()
}
private
var
wordsCopy
:
MutableList
<
WordItem
>
=
mutableListOf
()
init
{
wordsCopy
.
addAll
(
vocabulary
.
words
)
}
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
super
.
onAttachedToRecyclerView
(
recyclerView
)
this
.
recyclerView
=
recyclerView
this
.
recyclerView
=
recyclerView
...
@@ -98,11 +104,40 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
...
@@ -98,11 +104,40 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val activity
(
activity
as
MainActivity
).
supportFragmentManager
.
beginTransaction
().
add
(
container
.
id
,
editWordFragment
).
commit
()
(
activity
as
MainActivity
).
supportFragmentManager
.
beginTransaction
().
add
(
container
.
id
,
editWordFragment
).
commit
()
}
}
fun
replaceAll
(
words
:
List
<
WordItem
>)
{
//vocabulary.words.beginBatchedUpdates()
for
(
i
in
vocabulary
.
words
.
size
-
1
downTo
0
)
{
val
model
=
vocabulary
.
words
[
i
]
if
(!
words
.
contains
(
model
))
{
vocabulary
.
words
.
remove
(
model
)
}
}
vocabulary
.
words
.
addAll
(
words
)
//vocabulary.words.endBatchedUpdates()
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
val
tvWord
:
TextView
=
itemView
.
word
val
tvWord
:
TextView
=
itemView
.
word
val
tvTranslation
:
TextView
=
itemView
.
translation
val
tvTranslation
:
TextView
=
itemView
.
translation
val
layout
:
LinearLayout
=
itemView
.
layout
val
layout
:
LinearLayout
=
itemView
.
layout
}
}
fun
filter
(
query
:
String
)
{
var
query
=
query
vocabulary
.
words
.
clear
()
if
(
query
.
isEmpty
())
{
vocabulary
.
words
.
addAll
(
wordsCopy
)
}
else
{
query
=
query
.
toLowerCase
()
for
(
wordCopy
in
wordsCopy
)
{
if
(
wordCopy
.
pojo
.
word
.
toLowerCase
().
contains
(
query
)
||
wordCopy
.
pojo
.
translation
.
toLowerCase
().
contains
(
query
))
{
vocabulary
.
words
.
add
(
wordCopy
)
}
}
}
notifyDataSetChanged
()
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
View file @
bde85cd1
...
@@ -10,7 +10,7 @@ class Vocabulary(words: MutableList<WordItem>) {
...
@@ -10,7 +10,7 @@ class Vocabulary(words: MutableList<WordItem>) {
}
}
var
pojo
:
Pojo
var
pojo
:
Pojo
private
var
words
:
MutableList
<
WordItem
>
var
words
:
MutableList
<
WordItem
>
class
Pojo
(
var
title
:
String
?)
{
class
Pojo
(
var
title
:
String
?)
{
init
{
init
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
bde85cd1
...
@@ -11,6 +11,7 @@ import com.paktalin.vocabularynotebook.R
...
@@ -11,6 +11,7 @@ import com.paktalin.vocabularynotebook.R
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.activity_main.*
import
android.view.WindowManager
import
android.view.WindowManager
import
android.app.Activity
import
android.app.Activity
import
android.app.SearchManager
import
android.support.v4.app.Fragment
import
android.support.v4.app.Fragment
import
android.view.Menu
import
android.view.Menu
import
android.view.MenuItem
import
android.view.MenuItem
...
@@ -20,18 +21,16 @@ import android.widget.Toast
...
@@ -20,18 +21,16 @@ import android.widget.Toast
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
android.support.v4.view.MenuItemCompat.getActionView
import
android.content.Context.SEARCH_SERVICE
import
android.support.v4.content.ContextCompat.getSystemService
import
android.app.SearchManager
import
android.content.Context
import
android.content.Context
import
android.widget.SearchView
import
android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.OnQueryTextListener
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
lateinit
var
vocabularyId
:
String
lateinit
var
vocabularyId
:
String
lateinit
var
vocabularyFragment
:
VocabularyFragment
lateinit
var
vocabularyFragment
:
VocabularyFragment
lateinit
var
searchView
:
SearchView
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -43,10 +42,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -43,10 +42,7 @@ class MainActivity : AppCompatActivity() {
override
fun
onCreateOptionsMenu
(
menu
:
Menu
?):
Boolean
{
override
fun
onCreateOptionsMenu
(
menu
:
Menu
?):
Boolean
{
menuInflater
.
inflate
(
R
.
menu
.
options_menu
,
menu
)
menuInflater
.
inflate
(
R
.
menu
.
options_menu
,
menu
)
val
searchManager
=
getSystemService
(
Context
.
SEARCH_SERVICE
)
as
SearchManager
searchView
=
menu
!!
.
findItem
(
R
.
id
.
search
).
actionView
as
SearchView
val
searchView
=
menu
!!
.
findItem
(
R
.
id
.
search
).
actionView
as
SearchView
searchView
.
setSearchableInfo
(
searchManager
.
getSearchableInfo
(
componentName
))
searchView
.
queryHint
=
resources
.
getString
(
R
.
string
.
search_hint
)
return
true
return
true
}
}
...
@@ -94,6 +90,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -94,6 +90,7 @@ class MainActivity : AppCompatActivity() {
vocabularyFragment
.
arguments
=
arguments
vocabularyFragment
.
arguments
=
arguments
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
fragment_container
,
vocabularyFragment
)
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
fragment_container
,
vocabularyFragment
)
.
commitNowAllowingStateLoss
()
.
commitNowAllowingStateLoss
()
searchView
.
setOnQueryTextListener
(
OnQueryTextListener
(
recyclerView
))
}
else
{
}
else
{
Log
.
w
(
TAG
,
"There's no collection \"vocabularies\""
)
Log
.
w
(
TAG
,
"There's no collection \"vocabularies\""
)
showToastNoWords
()
}
showToastNoWords
()
}
...
...
app/src/main/res/menu/options_menu.xml
View file @
bde85cd1
...
@@ -6,12 +6,12 @@
...
@@ -6,12 +6,12 @@
android:title=
"@string/option_search"
android:title=
"@string/option_search"
android:icon=
"@drawable/ic_search_icon"
android:icon=
"@drawable/ic_search_icon"
app:showAsAction=
"ifRoom"
app:showAsAction=
"ifRoom"
app:actionViewClass=
"android.widget.SearchView"
/>
app:actionViewClass=
"android.
support.v7.
widget.SearchView"
/>
<item
<item
android:id=
"@+id/sort"
android:id=
"@+id/sort"
android:title=
"@string/option_sort"
android:title=
"@string/option_sort"
android:icon=
"@drawable/ic_sort_icon"
android:icon=
"@drawable/ic_sort_icon"
app:showAsAction=
"ifRoom"
/>
app:showAsAction=
"ifRoom
|collapseActionView
"
/>
</menu>
</menu>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
bde85cd1
...
@@ -15,5 +15,4 @@
...
@@ -15,5 +15,4 @@
<string
name=
"menu_option_edit"
>
Edit
</string>
<string
name=
"menu_option_edit"
>
Edit
</string>
<string
name=
"option_sort"
>
Sort
</string>
<string
name=
"option_sort"
>
Sort
</string>
<string
name=
"option_search"
>
Search
</string>
<string
name=
"option_search"
>
Search
</string>
<string
name=
"search_hint"
>
Enter word
</string>
</resources>
</resources>
app/src/main/res/xml/searchable.xml
View file @
bde85cd1
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<searchable
xmlns:android=
"http://schemas.android.com/apk/res/android"
<searchable
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:label=
"@string/app_name"
/>
android:label=
"@string/app_name"
/>
\ No newline at end of file
\ 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