Remove unnecessary data class

This commit is contained in:
davidoskky 2022-09-30 15:07:17 +02:00
parent dc8381b661
commit 713ceb05bf

View File

@ -95,8 +95,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
private val repository : Repository by instance() private val repository : Repository by instance()
private val appSettingsService : AppSettingsService by instance() private val appSettingsService : AppSettingsService by instance()
data class DrawerData(val tags: List<SelfossModel.Tag>, val sources: List<SelfossModel.Source>)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityHomeBinding.inflate(layoutInflater) binding = ActivityHomeBinding.inflate(layoutInflater)
@ -349,14 +347,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
) )
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val drawerData = DrawerData(repository.getTags(), repository.getSources()) val tags = repository.getTags()
val sources = repository.getSources()
runOnUiThread { runOnUiThread {
handleDrawerData(drawerData) handleDrawerData(tags, sources)
} }
} }
} }
private fun handleDrawerData(drawerData: DrawerData) { private fun handleDrawerData(tags: List<SelfossModel.Tag>, sources: List<SelfossModel.Source>) {
binding.mainDrawer.itemAdapter.clear() binding.mainDrawer.itemAdapter.clear()
// Filters title with clear action // Filters title with clear action
@ -370,24 +369,24 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
} }
// Hidden tags // Hidden tags
if (drawerData.tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) { if (tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) {
secondaryItem( secondaryItem(
withDivider = true, withDivider = true,
R.string.drawer_item_hidden_tags, R.string.drawer_item_hidden_tags,
DRAWER_ID_HIDDEN_TAGS DRAWER_ID_HIDDEN_TAGS
) )
handleHiddenTags(drawerData.tags) handleHiddenTags(tags)
} }
// Tags // Tags
secondaryItem(withDivider = true, R.string.drawer_item_tags, DRAWER_ID_TAGS) secondaryItem(withDivider = true, R.string.drawer_item_tags, DRAWER_ID_TAGS)
if (drawerData.tags.isEmpty()) { if (tags.isEmpty()) {
binding.mainDrawer.itemAdapter.add( binding.mainDrawer.itemAdapter.add(
SecondaryDrawerItem() SecondaryDrawerItem()
.apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false } .apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false }
) )
} else { } else {
handleTags(drawerData.tags) handleTags(tags)
} }
// Sources // Sources
@ -395,7 +394,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
startActivity(Intent(v!!.context, SourcesActivity::class.java)) startActivity(Intent(v!!.context, SourcesActivity::class.java))
false false
} }
if (drawerData.sources.isEmpty()) { if (sources.isEmpty()) {
binding.mainDrawer.itemAdapter.add( binding.mainDrawer.itemAdapter.add(
SecondaryDrawerItem().apply { SecondaryDrawerItem().apply {
nameRes = R.string.drawer_error_loading_sources nameRes = R.string.drawer_error_loading_sources
@ -403,7 +402,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
} }
) )
} else { } else {
handleSources(drawerData.sources) handleSources(sources)
} }
// About action // About action