A
A
Anrek2021-09-23 23:16:56
Android
Anrek, 2021-09-23 23:16:56

How to merge fragments of the same type in cicerone?

Good afternoon!

1) I have a group of identical fragments that differ only in the displayed image and caption and are called in different places of the application like this:

Screens.ProfileOne
Screens.ProfileTwo

I In object Screens they look like this:
object Screens {

object ProfileOne : SupportAppScreen() {
    override fun getFragment() = ProfileFragment(0)
  }

object ProfileTwo : SupportAppScreen() {
    override fun getFragment() =  ProfileFragment(1)
  }

}

The class from which positions in brackets (0 and 1) are taken in the fragment based on index:
enum class Items (@StringRes val title: Int, @DrawableRes val icon: Int) {

    One(R.string.one_profile, R.drawable.ic_profile_0),
    Two(R.string.two_profile, R.drawable.ic_profile_1),

How to reduce object Screens to 1 object? Because I don’t have 2, but 9, and it looks terrible.

2) I tried the data class, but in the end, because the ScreenKey is the same, the first time it works, and the second time it displays the same screen. Those. the object is not recreated. The code looked like this:
object Screens {

data class Profilу (val index: Int) : SupportAppScreen() {
    override fun getFragment() = ProfileFragment(index)
  }

Question: How can I shorten object Screens? Or what to fix in my version with non-recreating objects? I would be very grateful for any tips.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anrek, 2022-03-05
@Anrek

Decided so: to
create as compain object directly at class initialization. And for navigation use data class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question