Commit 8807a572 by Paktalin

Fixed sort buttons

parent f19befb0
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="imageWizard">
<value>
<PersistentState />
</value>
</entry>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="assetSourceType" value="FILE" />
<entry key="outputName" value="ic_time" />
<entry key="sourceFile" value="C:\Users\litak\Desktop\baseline-access_time-24px.svg" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
...@@ -15,9 +15,9 @@ class Vocabulary() { ...@@ -15,9 +15,9 @@ class Vocabulary() {
companion object { companion object {
private val TAG = "VN/" + Vocabulary::class.java.simpleName private val TAG = "VN/" + Vocabulary::class.java.simpleName
private const val SORT_BY_TIME = 0 const val SORT_BY_TIME = 0
private const val SORT_BY_WORD = 1 const val SORT_BY_WORD = 1
private const val SORT_BY_TRANSLATION = 2 const val SORT_BY_TRANSLATION = 2
} }
fun sort(sortOrder:Int) { fun sort(sortOrder:Int) {
...@@ -78,10 +78,10 @@ class Vocabulary() { ...@@ -78,10 +78,10 @@ class Vocabulary() {
} }
private fun sortByWord() { private fun sortByWord() {
words.sortWith(Comparator { item1, item2 -> words.sortWith(Comparator { item1, item2 ->
item1.pojo.word.compareTo(item2.pojo.word) }) item1.pojo.word.toLowerCase().compareTo(item2.pojo.word.toLowerCase()) })
} }
private fun sortByTranslation() { private fun sortByTranslation() {
words.sortWith(Comparator { item1, item2 -> words.sortWith(Comparator { item1, item2 ->
item1.pojo.translation.compareTo(item2.pojo.translation) }) item1.pojo.translation.toLowerCase().compareTo(item2.pojo.translation.toLowerCase()) })
} }
} }
\ No newline at end of file
...@@ -18,7 +18,7 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val ...@@ -18,7 +18,7 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
private var sortOrder: Int = 0 var sortOrder: Int = 0
set(value) { set(value) {
field = value; sort() field = value; sort()
} }
...@@ -91,11 +91,6 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val ...@@ -91,11 +91,6 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
this.sort() this.sort()
} }
fun updateSortOrder() {
if (sortOrder == 2) sortOrder = 0
else sortOrder++
}
private fun sort() { private fun sort() {
displayedVocabulary.sort(sortOrder) displayedVocabulary.sort(sortOrder)
this.notifyDataSetChanged() this.notifyDataSetChanged()
......
...@@ -11,17 +11,21 @@ import android.view.View ...@@ -11,17 +11,21 @@ import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import kotlinx.android.synthetic.main.fragment_vocabulary.* import kotlinx.android.synthetic.main.fragment_vocabulary.*
import android.support.v7.widget.SearchView import android.support.v7.widget.SearchView
import android.util.Log
import android.view.WindowManager import android.view.WindowManager
import com.paktalin.vocabularynotebook.* import com.paktalin.vocabularynotebook.*
import com.paktalin.vocabularynotebook.Vocabulary.Companion.SORT_BY_TIME
import com.paktalin.vocabularynotebook.Vocabulary.Companion.SORT_BY_TRANSLATION
import com.paktalin.vocabularynotebook.Vocabulary.Companion.SORT_BY_WORD
import com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment import com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
import com.paktalin.vocabularynotebook.utils.* import com.paktalin.vocabularynotebook.utils.*
import kotlinx.android.synthetic.main.content_main.* import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.fragment_editable_word.view.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
lateinit var vocabularyFragment: VocabularyFragment lateinit var vocabularyFragment: VocabularyFragment
lateinit var searchView: SearchView lateinit var searchView: SearchView
lateinit var optionsMenu: Menu
var inEditMode = false var inEditMode = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
...@@ -35,14 +39,33 @@ class MainActivity : AppCompatActivity() { ...@@ -35,14 +39,33 @@ class MainActivity : AppCompatActivity() {
} }
override fun onCreateOptionsMenu(menu: Menu?): Boolean { override fun onCreateOptionsMenu(menu: Menu?): Boolean {
optionsMenu = menu!!
menuInflater.inflate(R.menu.options_menu, menu) menuInflater.inflate(R.menu.options_menu, menu)
searchView = menu!!.findItem(R.id.search).actionView as SearchView searchView = menu.findItem(R.id.search).actionView as SearchView
optionsMenu.findItem(R.id.sortByWord).isVisible = false
optionsMenu.findItem(R.id.sortByTranslation).isVisible = false
return true return true
} }
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
if (item!!.itemId == R.id.sort) val vocabularyAdapter = recyclerView.adapter as VocabularyAdapter
(recyclerView.adapter as VocabularyAdapter).updateSortOrder() if (item!!.itemId == R.id.sortByTime) {
vocabularyAdapter.sortOrder = SORT_BY_WORD
hideMenuItem(optionsMenu, false, true, false)
highlight(fragmentAddWord.view!!.word)
}
if (item.itemId == R.id.sortByWord) {
vocabularyAdapter.sortOrder = SORT_BY_TRANSLATION
hideMenuItem(optionsMenu, false, false, true)
transparent(fragmentAddWord.view!!.word)
highlight(fragmentAddWord.view!!.translation)
}
if (item.itemId == R.id.sortByTranslation) {
vocabularyAdapter.sortOrder = SORT_BY_TIME
hideMenuItem(optionsMenu, true, false, false)
transparent(fragmentAddWord.view!!.translation)
}
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
......
...@@ -6,11 +6,13 @@ import android.os.Bundle ...@@ -6,11 +6,13 @@ import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
import android.text.TextUtils import android.text.TextUtils
import android.view.Menu
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import com.paktalin.vocabularynotebook.ui.activities.MainActivity import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment import com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import kotlinx.android.synthetic.main.content_main.* import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.fragment_editable_word.view.*
val progressFragment: Fragment = ProgressFragment() val progressFragment: Fragment = ProgressFragment()
...@@ -57,4 +59,18 @@ fun invisible(view: View) { ...@@ -57,4 +59,18 @@ fun invisible(view: View) {
fun gone(view: View) { fun gone(view: View) {
view.visibility = View.GONE view.visibility = View.GONE
}
fun hideMenuItem(menu: Menu, time: Boolean, word: Boolean, translation: Boolean) {
menu.findItem(R.id.sortByTime).isVisible = time
menu.findItem(R.id.sortByWord).isVisible = word
menu.findItem(R.id.sortByTranslation).isVisible = translation
}
fun highlight(view: View) {
view.setBackgroundResource(R.color.green_highlight)
}
fun transparent(view: View) {
view.setBackgroundResource(android.R.color.transparent)
} }
\ No newline at end of file
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
android:viewportHeight="24"> android:viewportHeight="24">
<path <path
android:fillColor="#FF000000" android:fillColor="#FF000000"
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/> android:pathData="M14.94,4.66h-4.72l2.36,-2.36zM10.25,19.37h4.66l-2.33,2.33zM6.1,6.27L1.6,17.73h1.84l0.92,-2.45h5.11l0.92,2.45h1.84L7.74,6.27L6.1,6.27zM4.97,13.64l1.94,-5.18 1.94,5.18L4.97,13.64zM15.73,16.14h6.12v1.59h-8.53v-1.29l5.92,-8.56h-5.88v-1.6h8.3v1.26l-5.93,8.6z"/>
</vector> </vector>
<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="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
<path
android:fillColor="#FF000000"
android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
</vector>
...@@ -9,9 +9,21 @@ ...@@ -9,9 +9,21 @@
app:actionViewClass="android.support.v7.widget.SearchView" /> app:actionViewClass="android.support.v7.widget.SearchView" />
<item <item
android:id="@+id/sort" android:id="@+id/sortByTime"
android:title="@string/option_sort"
android:icon="@drawable/ic_time"
app:showAsAction="always" />
<item
android:id="@+id/sortByWord"
android:title="@string/option_sort"
android:icon="@drawable/ic_sort_az"
app:showAsAction="always" />
<item
android:id="@+id/sortByTranslation"
android:title="@string/option_sort" android:title="@string/option_sort"
android:icon="@drawable/ic_sort_icon" android:icon="@drawable/ic_sort_az"
app:showAsAction="always" /> app:showAsAction="always" />
</menu> </menu>
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<string name="tv_translation">Translation</string> <string name="tv_translation">Translation</string>
<string name="btn_save">Save</string> <string name="btn_save">Save</string>
<string name="btn_cancel">Cancel</string> <string name="btn_cancel">Cancel</string>
<string name="hint_new_word">new word</string> <string name="hint_new_word">word</string>
<string name="hint_translation">translation</string> <string name="hint_translation">translation</string>
<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>
......
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