Commit d51c6159 by Paktalin

Added SearchView to MainActivity

parent 0608c4c0
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
<option name="values"> <option name="values">
<map> <map>
<entry key="assetSourceType" value="FILE" /> <entry key="assetSourceType" value="FILE" />
<entry key="outputName" value="ic_sort_icon" /> <entry key="outputName" value="ic_search_icon" />
<entry key="sourceFile" value="C:\Users\litak\Desktop\sort_icon.svg" /> <entry key="sourceFile" value="C:\Users\litak\Desktop\search_icon.svg" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>
......
...@@ -9,15 +9,22 @@ ...@@ -9,15 +9,22 @@
<application <application
android:name=".appsetup.VocabularyApplication" android:name=".appsetup.VocabularyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:label="@string/app_name"
android:name=".ui.MainActivity" android:name=".ui.MainActivity"
android:windowSoftInputMode="adjustResize"/> android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity <activity
android:name=".ui.LogInActivity" android:name=".ui.LogInActivity"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
......
...@@ -51,7 +51,6 @@ class Vocabulary(words: MutableList<WordItem>) { ...@@ -51,7 +51,6 @@ class Vocabulary(words: MutableList<WordItem>) {
fun size():Int { return words.size } fun size():Int { return words.size }
//region Private methods
private fun sortByTime() { private fun sortByTime() {
words.sortWith(Comparator { item1, item2 -> words.sortWith(Comparator { item1, item2 ->
-item1.pojo.time!!.compareTo(item2.pojo.time) }) -item1.pojo.time!!.compareTo(item2.pojo.time) })
...@@ -64,5 +63,4 @@ class Vocabulary(words: MutableList<WordItem>) { ...@@ -64,5 +63,4 @@ class Vocabulary(words: MutableList<WordItem>) {
words.sortWith(Comparator { item1, item2 -> words.sortWith(Comparator { item1, item2 ->
item1.pojo.translation.compareTo(item2.pojo.translation) }) item1.pojo.translation.compareTo(item2.pojo.translation) })
} }
//endregion
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ class AddWordFragment : WordFragment() { ...@@ -24,7 +24,7 @@ class AddWordFragment : WordFragment() {
} }
override fun updateRecycleView(wordItem: WordItem) { override fun updateRecycleView(wordItem: WordItem) {
mainActivity.vocabularyFragment.addWordItem(wordItem) mainActivity.vocabularyFragment.addWord(wordItem)
} }
companion object { private val TAG = "VN/" + AddWordFragment::class.java.simpleName } companion object { private val TAG = "VN/" + AddWordFragment::class.java.simpleName }
......
...@@ -76,7 +76,7 @@ class EditWordFragment : WordFragment() { ...@@ -76,7 +76,7 @@ class EditWordFragment : WordFragment() {
} }
override fun updateRecycleView(wordItem: WordItem) { override fun updateRecycleView(wordItem: WordItem) {
mainActivity.vocabularyFragment.updateWordItem(wordItem) mainActivity.vocabularyFragment.updateWord(wordItem)
} }
companion object { companion object {
......
...@@ -20,6 +20,13 @@ import android.widget.Toast ...@@ -20,6 +20,13 @@ 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.widget.SearchView
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
...@@ -35,7 +42,11 @@ class MainActivity : AppCompatActivity() { ...@@ -35,7 +42,11 @@ class MainActivity : AppCompatActivity() {
} }
override fun onCreateOptionsMenu(menu: Menu?): Boolean { override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.actionbar_menu, menu) menuInflater.inflate(R.menu.options_menu, menu)
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
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
} }
......
...@@ -36,11 +36,6 @@ class VocabularyFragment : Fragment() { ...@@ -36,11 +36,6 @@ class VocabularyFragment : Fragment() {
retrieveWordsData(arguments!!["vocabularyId"] as String) retrieveWordsData(arguments!!["vocabularyId"] as String)
} }
override fun onDestroy() {
super.onDestroy()
FirebaseAuth.getInstance().signOut()
}
private fun setEmptyAdapter() { private fun setEmptyAdapter() {
val emptyList: MutableList<WordItem> = mutableListOf() val emptyList: MutableList<WordItem> = mutableListOf()
recyclerView.adapter = VocabularyAdapter(Vocabulary(emptyList), activity!!) recyclerView.adapter = VocabularyAdapter(Vocabulary(emptyList), activity!!)
...@@ -76,11 +71,8 @@ class VocabularyFragment : Fragment() { ...@@ -76,11 +71,8 @@ class VocabularyFragment : Fragment() {
recyclerView.adapter = adapter recyclerView.adapter = adapter
} }
fun addWordItem(newWord: WordItem) { fun addWord(newWord: WordItem) { (recyclerView.adapter as VocabularyAdapter).addWord(newWord) }
(recyclerView.adapter as VocabularyAdapter).addWord(newWord)
}
fun updateWordItem(updatedWord: WordItem) { fun updateWord(updatedWord: WordItem) {
(recyclerView.adapter as VocabularyAdapter).updateWord(updatedWord) (recyclerView.adapter as VocabularyAdapter).updateWord(updatedWord) }
}
} }
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
...@@ -2,12 +2,16 @@ ...@@ -2,12 +2,16 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="@string/option_search"
android:icon="@drawable/ic_search_icon"
app:showAsAction="ifRoom"
app:actionViewClass="android.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" />
</item>
</menu> </menu>
\ No newline at end of file
...@@ -14,4 +14,6 @@ ...@@ -14,4 +14,6 @@
<string name="menu_option_delete">Delete</string> <string name="menu_option_delete">Delete</string>
<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="search_hint">Enter word</string>
</resources> </resources>
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"/>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment