2

I'm missing something. I layered a few ExpandableGroup Items and the first two layers work fine, but when I try to access the third layer, nothing happens. I looked through the debugger, and the items are collected, but they don't show up in the view. They show up if I put the section.add in the outermost ExpandableGroup, but they should up in the outermost group, if I add the group anywhere else, it adds another group to the bottom of the list, which it should.

What I'm Looking for is

Item
    SubItem
       SubSubItem <- This one is a clickable item, which works if it's added to the Item group. 

class Stores : AppCompatActivity() {
    private lateinit var userListenerRegistration: ListenerRegistration
    private var shouldInitCategoryRecyclerView = true

    private val groupAdapter = GroupAdapter<GroupieViewHolder>()

    private var storeSection = Section()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_stores)

        userListenerRegistration =
            FirestoreUtil.addCategoryListener(this::updateCategoryRecyclerView)
    }

    override fun onDestroy() {
        super.onDestroy()
        FirestoreUtil.removeListener(userListenerRegistration)
        shouldInitCategoryRecyclerView = true
    }


    private fun updateCategoryRecyclerView(items: List<Item>) {

        fun init() {
            recycler_view_categories.apply {
                layoutManager = LinearLayoutManager(this@Stores)
                adapter = groupAdapter.apply {
                    setOnItemClickListener(onItemClick)
                }
            }

            for (item in items) {
                if (item is CategoryItem) {
                    ExpandableGroup(item, false).apply {

                        userListenerRegistration =
                            FirestoreUtil.addSubCategoriesListener(
                                item.category.categoryName
                            ) { subCategories ->
                                for (subCategory in subCategories) {
                                    if (subCategory is SubCategoryItem) {
                                        add(Section(subCategory))
                                        ExpandableGroup(subCategory, false).apply {

                                            userListenerRegistration =
                                                FirestoreUtil.addStoreListener(
                                                    item.category.categoryName,
                                                    subCategory.subCategory.subCategoryName,
                                                    this@Stores
                                                ) { stores ->
                                                    for (store in stores) {
                                                        if (store is StoreItem) {
                                                            add(Section(store))
                                                        }
                                                    }
                                                }
                                        }
                                    }
                                }
                            }
                        groupAdapter.add(this)
                    }
                }
            }
            shouldInitCategoryRecyclerView = false
        }

        fun updateItems() = storeSection.update(items)

        if (shouldInitCategoryRecyclerView)
            init()
        else
            updateItems()
    }

    private val onItemClick = OnItemClickListener { item, view ->
        if (item is StoreItem) {
            Toast.makeText(this, item.store.storeName, Toast.LENGTH_SHORT).show()
        }
    }


}

The FirestoreUtil calls, get data from Firestore, and display it, I got it to work like I wanted to, but the last call, stores doesn't return a value that is visible in the app. It seems to get the data but it doesn't display it.This is what the view looks like This second one has a highlighted Item in blue. That should trigger it to display the stores, but it doesn't

DJ. Aduvanchik
  • 332
  • 5
  • 17

0 Answers0