Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Emptiness module programmatically #18

Closed
francescogatto opened this issue Feb 2, 2020 · 9 comments
Closed

Get Emptiness module programmatically #18

francescogatto opened this issue Feb 2, 2020 · 9 comments
Labels

Comments

@francescogatto
Copy link

Hi! very nice library
I'm trying to change programmatically text and lottieview of the emptiness module. This is my flow:

  1. show emptiness module
  2. loading some data in recycler view
  3. swipe to refresh and data now is empty
  4. emptiness module is not showing

or

  1. show emptiness module
  2. loading some data in recycler view
  3. search for some data
  4. data is empty
  5. show emptiness module with a text like "Nothing found during the research"

Thanks!

@francescogatto
Copy link
Author

francescogatto commented Feb 2, 2020

i also tried:

emptinessModule.currentText = "text" prodAdapter.clear()

clear doesn't call the binding method of emptiness module :(

@idanatz
Copy link
Collaborator

idanatz commented Feb 2, 2020

The Emptiness Module is very simple, you will get an onBind call what the adapter is empty.
If you call clear() you will get the onBind call.

If the behavior is different in your project perhaps you are doing something wrong? Have you looked at the sample project?
https://github.com/ironSource/OneAdapter/blob/master/sample/app/src/main/java/com/idanatz/sample/examples/features/EmptinessModuleActivity.kt
I'm using the module in several projects and it works as expected.

Please add full code examples

@francescogatto
Copy link
Author

francescogatto commented Feb 2, 2020

Hey @idanatz , the problem is this Scenario:

  1. init of adapter
    prodAdapter = OneAdapter(prodRecyclerView).attachItemModule(ProdModule()) emptinessModule = EmptinessModuleImpl("Effettua una ricerca per trovare i prodotti vicino a te", R.raw.radar) prodAdapter.attachEmptinessModule(emptinessModule)

  2. call the service and get the result:
    imageSearchButton.setSafeOnClickListener { viewModel.getProducts(lng, lat, radius).observeKt { when (it) { is Result.Success -> { if (it.data.isEmpty()) { prodAdapter.add(emptyList()) emptinessModule.currentText = "text" prodAdapter.clear() } else { prodAdapter.add(it.data) } } else -> { } } } }

  3. if the result is always empty, clear never call the unbind method of the emptiness module.
    Here the code of the module
    `class EmptinessModuleImpl(val text: String, val lottieResourse: Int = R.raw.empty_list) : EmptinessModule() {

    var currentText = ""
    init {
    currentText = text
    }
    override fun provideModuleConfig(): EmptinessModuleConfig = object : EmptinessModuleConfig() {
    override fun withLayoutResource() = R.layout.empty_state
    }

    override fun onBind(viewBinder: ViewBinder) {
    val animation = viewBinder.findViewById(R.id.animation_view)
    animation.setAnimation(lottieResourse)
    animation.playAnimation()
    viewBinder.findViewById(R.id.textView).text = currentText
    }

    override fun onUnbind(viewBinder: ViewBinder) {
    val animation = viewBinder.findViewById(R.id.animation_view)
    animation.pauseAnimation()
    }

}`

@idanatz
Copy link
Collaborator

idanatz commented Feb 2, 2020

why are you adding an empty list into the adapter?
prodAdapter.add(emptyList())

because of this line, the adapter is not really empty (it has an empty list inside as an item)
so the emptiness module is not being used.

remove this line and just call:
emptinessModule.currentText = "text"
prodAdapter.clear()

@francescogatto
Copy link
Author

francescogatto commented Feb 2, 2020

I did it, but didn't work. I think the problem is in updateData, because the diffutils doesn't see any change(?)

@idanatz
Copy link
Collaborator

idanatz commented Feb 2, 2020

Oh, I think i see your problem.
The Adapter was already empty and you want it to call onBind again when you call clear() ?

@francescogatto
Copy link
Author

Exactly, in this way, I can use Emptiness module to show the user errors from the server or just advice that the result is empty :)

@idanatz
Copy link
Collaborator

idanatz commented Feb 2, 2020

I got it, did not think to use the module in this way.
Will be fixed in the next version 👍

@idanatz idanatz added bug Something isn't working resolved in the next version labels Feb 2, 2020
@idanatz
Copy link
Collaborator

idanatz commented Feb 9, 2020

Version 1.5.0 is out with the fix.
Please notice that there are breaking changes in the modules API due to other requests.
The sample project is updated as well for reference.

@idanatz idanatz closed this as completed Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants