NimarkoGram Docs
RU
Docs/Confirmation dialogs

Confirmation dialogs

Ask for confirmation before resetting a saved preference.

On this pageOffer a choiceBuild the dialogRefresh the settings screen

Offer a choice

Download reset-en.plugin and install it in the GitHub edition. The plugin settings contain a signature field and a separate reset action. Change the field to “For the project”, save it and tap Reset signature. The dialog displays the proposed replacement. Tap Cancel and reopen the field. It should still contain “For the project”.

Build the dialog

A Text row passes its Android view to the tap handler. Read the screen context from that view when the user taps the row. Supply it to AlertDialogBuilder, configure the buttons and call show(). A cancel button only needs a label. For the confirmation button, pass a method accepting the dialog builder and the button code after self.

Python
__id__ = "sdk_reset"
__name__ = "Signature"
__author__ = "NimarkoGram"
__version__ = "1.0"
__host__ = "NimarkoGram"
__sdk_version__ = ">=1.0"

from base_plugin import BasePlugin
from ui.alert import AlertDialogBuilder
from ui.settings import Input, Text

DEFAULT = "From my phone"


class SignaturePlugin(BasePlugin):
    def create_settings(self):
        return [
            Input(key="signature", text=__name__, default=DEFAULT),
            Text(text="Reset signature", on_click=self.confirm_reset),
        ]

    def confirm_reset(self, view):
        dialog = AlertDialogBuilder(view.getContext())
        dialog.set_title("Reset the signature?")
        dialog.set_message(DEFAULT)
        dialog.set_negative_button("Cancel")
        dialog.set_positive_button("Reset", self.reset)
        dialog.show()

    def reset(self, dialog, which):
        self.set_setting("signature", DEFAULT, reload_settings=True)

Refresh the settings screen

The write happens inside reset. Passing reload_settings=True asks the client to rebuild the settings after writing. Open the dialog a second time and confirm. The field should now show “From my phone”. If cancelling also changes the signature, inspect the location of set_setting and check for parentheses where you pass self.reset.

For feedback that requires no decision, see the one-tap bulletin example.