Fetch sections from blocks
Setting the specific block_id, it is possible to obtain the corresponding section’s data.
If you want, you can include whether or not you want to filter the elements of the section by adding an array of filters.
The process to reach the result is the same as the blocks’ example:
    Create, initialize and pause the BroadcastReceiver (using “forSections” method).
    Call the task.
    Fetch the sections from the response of onApiResult.
Your code should be like this:
1
override fun onResume() {
2
super.onResume()
3
/**Create your sections’ receiver**/
4
bRec = MBurgerApiActionInitializer.initializeNookoReceiverForSections(this, this)
5
6
/**Add custom filters to the API call or leave it null**/
7
val arrayOfFilters : ArrayList<Any> = null
8
9
/**Id of the block you wish to retrieve sections**/
10
val block_id = block.getId()
11
12
/**Inside the sections the “elements” field will be valorized**/
13
val getElements = true
14
15
/**Call sections’ API**/
16
MBurgerTasks.askForSections(this, block_id, arrayOfFilters, getElements)
17
}
18
19
override fun onPause() {
20
super.onPause()
21
MBurgerApiActionInitializer.pauseNookoReceiver(getActivity(), bRec)
22
}
23
24
override fun onApiResult(response: MBAPIResponse ) {
25
if (response.getResult()) {
26
val sections = response.getPayload().get(MBApiPayloadKeys.key_sections) as ArrayList<MBSection>
27
if (sections.size() > 0) {
28
//Your code
29
} else {
30
Log.w(“WARNINGS HOME”, “THE HOME’ S SECTION IS EMPTY”)
31
}
32
} else {
33
Log.e(“ERROR RESPONSE API”, “THERE WAS AN ERROR DURING HOME’ S LOADING”)
34
}
35
}
Copied!
If you specify more filters of the same type inside the array, only the last one of those type will be considered.
Last modified 1yr ago
Copy link