Skip to content

Commit

Permalink
Use Toolbar as MenuHost
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Mar 11, 2024
1 parent 9803da3 commit 542772a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder
import org.odk.collect.entities.databinding.DatasetItemLayoutBinding
import org.odk.collect.entities.databinding.ListLayoutBinding

class DatasetsFragment(private val viewModelFactory: ViewModelProvider.Factory, private val menuHost: MenuHost) : Fragment() {
class DatasetsFragment(private val viewModelFactory: ViewModelProvider.Factory, private val menuHost: () -> MenuHost) : Fragment() {

private val entitiesViewModel by viewModels<EntitiesViewModel> { viewModelFactory }

Expand All @@ -40,7 +40,7 @@ class DatasetsFragment(private val viewModelFactory: ViewModelProvider.Factory,
binding.list.adapter = DatasetsAdapter(it, findNavController())
}

menuHost.addMenuProvider(DatasetsMenuProvider(entitiesViewModel), viewLifecycleOwner)
menuHost().addMenuProvider(DatasetsMenuProvider(entitiesViewModel), viewLifecycleOwner)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EntityBrowserActivity : LocalizedActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
supportFragmentManager.fragmentFactory = FragmentFactoryBuilder()
.forClass(DatasetsFragment::class) { DatasetsFragment(viewModelFactory, this) }
.forClass(DatasetsFragment::class) { DatasetsFragment(viewModelFactory, ::getToolbar) }
.forClass(EntitiesFragment::class) { EntitiesFragment(viewModelFactory) }
.build()

Expand All @@ -42,8 +42,8 @@ class EntityBrowserActivity : LocalizedActivity() {
val navController = navHostFragment.navController

val appBarConfiguration = AppBarConfiguration(navController.graph)
val toolbar = findViewById<Toolbar>(org.odk.collect.androidshared.R.id.toolbar)
toolbar.setupWithNavController(navController, appBarConfiguration)
setSupportActionBar(toolbar)
getToolbar().setupWithNavController(navController, appBarConfiguration)
}

private fun getToolbar() = findViewById<Toolbar>(org.odk.collect.androidshared.R.id.toolbar)
}

0 comments on commit 542772a

Please sign in to comment.