@ -115,6 +115,12 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
sort = 4
initLiveDataBookSource ( search _view . query ?. toString ( ) )
}
R . id . menu _enabled _group -> {
search _view . setQuery ( getString ( R . string . enabled ) , true )
}
R . id . menu _disabled _group -> {
search _view . setQuery ( getString ( R . string . disabled ) , true )
}
}
if ( item . groupId == R . id . source _group ) {
search _view . setQuery ( item . title , true )
@ -166,10 +172,19 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private fun initLiveDataBookSource ( searchKey : String ? = null ) {
bookSourceLiveDate ?. removeObservers ( this )
bookSourceLiveDate = if ( searchKey . isNullOrEmpty ( ) ) {
App . db . bookSourceDao ( ) . liveDataAll ( )
} else {
App . db . bookSourceDao ( ) . liveDataSearch ( " % $searchKey % " )
bookSourceLiveDate = when {
searchKey . isNullOrEmpty ( ) -> {
App . db . bookSourceDao ( ) . liveDataAll ( )
}
searchKey == getString ( R . string . enabled ) -> {
App . db . bookSourceDao ( ) . liveDataEnabled ( )
}
searchKey == getString ( R . string . disabled ) -> {
App . db . bookSourceDao ( ) . liveDataDisabled ( )
}
else -> {
App . db . bookSourceDao ( ) . liveDataSearch ( " % $searchKey % " )
}
}
bookSourceLiveDate ?. observe ( this , Observer { data ->
val sourceList = when ( sort ) {