Update an existing Section

Updating a section is a process very similar to creating a new one, but you will need the id of the section you wish to update--the block_id is not necessary.

You should only pay attention in that you must provide a valid locale and only the section with the given locale will be updated; other locale variants will remain untouched.

Also, all media you will send through the API will be appended to the pre-existent array of media.

If you wish to replace and image or a media you will need to call the MBurgerAdminTasks.deleteMedia(this, media_id) method before calling the update.

If you wish to update a section, the method is similar to creating one:

//EditTexts for inserting content
val edt_title: EditText
val edt_content: EditText
val edt_link: EditText

var listener: MBAdminApiUpdateSectionListener

val section_id = //ID of the section you wish to update

//URI of the image, taken from camera or gallery
var img_uri: Uri

//Set if you want this section to be hidden when requesting for block sections, or not
val show_in_app = true;

fun updateSection() {
    val params = ArrayList<MBAdminParameter>()
    params.add(MBAdminParameter(“title”, edt_title.getText().toString()))
    params.add(MBAdminParameter(“content”, edt_content.getText().toString()))
    params.add(MBAdminParameter(“link”, edt_link.getText().toString()))

    val params_file = ArrayList<MBAdminParameterFile>()
    val files = ArrayList<MBAdminSingleFile>()
    
    files.add(MBAdminSingleFile(getFileName(), 
                                getMimeType(), 
                                getUriRealPath(application, img_uri)))
                                
    params_file.add(MBAdminParameterFile(“image”, files))

    MBurgerAdminTasks.updateSection(applicationContext, 
                            section_id, 
                            listener, 
                            params, 
                            params_file, 
                            Locale.getDefault().getLanguage(), show_in_app);
}

Last updated