|
|
@ -39,6 +39,9 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_bookshelf.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_bookshelf.* |
|
|
|
import kotlinx.android.synthetic.main.view_tab_layout.* |
|
|
|
import kotlinx.android.synthetic.main.view_tab_layout.* |
|
|
|
import kotlinx.android.synthetic.main.view_title_bar.* |
|
|
|
import kotlinx.android.synthetic.main.view_title_bar.* |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
import org.jetbrains.anko.startActivity |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -99,22 +102,32 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b |
|
|
|
bookGroupLiveData = App.db.bookGroupDao().liveDataAll() |
|
|
|
bookGroupLiveData = App.db.bookGroupDao().liveDataAll() |
|
|
|
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { |
|
|
|
bookGroupLiveData?.observe(viewLifecycleOwner, Observer { |
|
|
|
viewModel.checkGroup(it) |
|
|
|
viewModel.checkGroup(it) |
|
|
|
synchronized(this) { |
|
|
|
launch { |
|
|
|
tab_layout.removeOnTabSelectedListener(this) |
|
|
|
synchronized(this) { |
|
|
|
bookGroups.clear() |
|
|
|
|
|
|
|
if (AppConfig.bookGroupAllShow) { |
|
|
|
|
|
|
|
bookGroups.add(AppConst.bookGroupAll) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (AppConfig.bookGroupLocalShow) { |
|
|
|
|
|
|
|
bookGroups.add(AppConst.bookGroupLocal) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (AppConfig.bookGroupAudioShow) { |
|
|
|
withContext(IO) { |
|
|
|
bookGroups.add(AppConst.bookGroupAudio) |
|
|
|
synchronized(this@BookshelfFragment) { |
|
|
|
|
|
|
|
tab_layout.removeOnTabSelectedListener(this@BookshelfFragment) |
|
|
|
|
|
|
|
bookGroups.clear() |
|
|
|
|
|
|
|
if (AppConfig.bookGroupAllShow) { |
|
|
|
|
|
|
|
bookGroups.add(AppConst.bookGroupAll) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (AppConfig.bookGroupLocalShow) { |
|
|
|
|
|
|
|
bookGroups.add(AppConst.bookGroupLocal) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (AppConfig.bookGroupAudioShow) { |
|
|
|
|
|
|
|
bookGroups.add(AppConst.bookGroupAudio) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (App.db.bookDao().noGroupSize > 0) { |
|
|
|
|
|
|
|
bookGroups.add(AppConst.bookGroupNone) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bookGroups.addAll(it) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
bookGroups.addAll(it) |
|
|
|
|
|
|
|
view_pager_bookshelf.adapter?.notifyDataSetChanged() |
|
|
|
view_pager_bookshelf.adapter?.notifyDataSetChanged() |
|
|
|
tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() |
|
|
|
tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() |
|
|
|
tab_layout.addOnTabSelectedListener(this) |
|
|
|
tab_layout.addOnTabSelectedListener(this@BookshelfFragment) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -129,18 +142,26 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun upGroup() { |
|
|
|
override fun upGroup() { |
|
|
|
synchronized(this) { |
|
|
|
launch { |
|
|
|
bookGroups.remove(AppConst.bookGroupAll) |
|
|
|
withContext(IO) { |
|
|
|
bookGroups.remove(AppConst.bookGroupLocal) |
|
|
|
synchronized(this@BookshelfFragment) { |
|
|
|
bookGroups.remove(AppConst.bookGroupAudio) |
|
|
|
bookGroups.remove(AppConst.bookGroupAll) |
|
|
|
if (AppConfig.bookGroupAudioShow) { |
|
|
|
bookGroups.remove(AppConst.bookGroupLocal) |
|
|
|
bookGroups.add(0, AppConst.bookGroupAudio) |
|
|
|
bookGroups.remove(AppConst.bookGroupAudio) |
|
|
|
} |
|
|
|
bookGroups.remove(AppConst.bookGroupNone) |
|
|
|
if (AppConfig.bookGroupLocalShow) { |
|
|
|
if (App.db.bookDao().noGroupSize > 0) { |
|
|
|
bookGroups.add(0, AppConst.bookGroupLocal) |
|
|
|
bookGroups.add(0, AppConst.bookGroupNone) |
|
|
|
} |
|
|
|
} |
|
|
|
if (AppConfig.bookGroupAllShow) { |
|
|
|
if (AppConfig.bookGroupAudioShow) { |
|
|
|
bookGroups.add(0, AppConst.bookGroupAll) |
|
|
|
bookGroups.add(0, AppConst.bookGroupAudio) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (AppConfig.bookGroupLocalShow) { |
|
|
|
|
|
|
|
bookGroups.add(0, AppConst.bookGroupLocal) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (AppConfig.bookGroupAllShow) { |
|
|
|
|
|
|
|
bookGroups.add(0, AppConst.bookGroupAll) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
view_pager_bookshelf.adapter?.notifyDataSetChanged() |
|
|
|
view_pager_bookshelf.adapter?.notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|