Skip to content

SD Card Status List Item Widget

Cristina Suciu edited this page Dec 23, 2020 · 2 revisions

SD Card Status List Item Widget is a DUXBetaListItemLabelAndButton type of widget which will display the remaining capacity of the SD card and SDCardOperationState.

Following are examples of the widget states:

Disconnected

CurrentSDCardState: Normal

CurrentSDCardState: Full

CurrentSDCardState: Not Inserted

It also provides an option to format the SD card. Tapping on the format button will show the format confirmation dialogs.

Format confirmation dialog

Format success dialog

Format error dialog

Usage

To add the SD card status list item widget to your DUXBetaSmartListModel class, override buildModelLists and include DUXBetaSDCardStatusListItemWidget.duxbeta_className() or [DUXBetaSDCardStatusListItemWidget duxbeta_className] in your modelClassnameList:

Swift Example

@objc open class MySmartListModel : DUXBetaSmartListModel {
    @objc open override func buildModelLists() {
        super.buildModelLists()
        self.modelClassnameList.append(DUXBetaSDCardStatusListItemWidget.duxbeta_className())
    }
}

ObjC Example

@interface DUXBetaTestSmartListModel : DUXBetaSmartListModel
@end

@implementation DUXBetaTestSmartListModel
- (void)buildModelLists {
    [super buildModelLists];
    [self.modelClassnameList append:[DUXBetaSDCardStatusListItemWidget duxbeta_className]];
}
@end

Customizations

The UI elements can be customized to match the style of the user's application. The widget supports all the customizations that its parent, DUXBetaListItemLabelAndButton supports. An example of a customized SD card status list item widget in various states could look something like this:

To get this effect we would use the following code:

Swift Example

sdCardWidget.setButtonColor(.red, for: .normal)
sdCardWidget.backgroundColor = .darkGray
sdCardWidget.titleColor = .black

ObjC Example

[sdCardWidget setButtonColor:UIColor.redColor forUIControlState:UIControlStateNormal];
sdCardWidget.backgroundColor = UIColor.darkGrayColor;
sdCardWidget.titleColor = UIColor.blackColor;

To customize the appearance of the dialogs presented when formatting SD cards, there are 3 different appearances of type DUXBetaAlertViewAppearance, one per dialog which can be customized.

Dialog Customization Properties

List of the dialog properties for customization
  • sdCardConfirmFormatAlertAppearance - The customization object for the format confirmation dialog.
  • sdCardFormattingSuccessAlertAppearance - The customization object for succsessful formatting completion dialog.
  • sdCardFormattingErrorAlertAppearance - The customization object for the dialog shown when an error happens during formatting.

See Alerts Customization Overview for all the customizable properties.

To get this effect we would use the following code:

Swift Example

    sdCardWidget.sdCardConfirmFormatAlertAppearance.backgroundColor = .duxbeta_grayColor

ObjC Example

    sdCardWidget.sdCardConfirmFormatAlertAppearance.backgroundColor = [UIColor duxbeta_grayColor];

Hooks

The widget provides hooks for the users to add functionality based on the state changes in the widget.

The SD Card Status List Item widget provides the following hooks:

  1. SDCardStatusListWidgetModelState - Provides hooks in events received by the widget from the widget model. It inherits from ListItemLabelButtonModelState and it adds the following hooks:
  • + (instancetype)sdCardStatusCapacityChanged:(NSInteger)freeStorageChanged; - Event when the SD card's remaining capacity changes.
  • + (instancetype)sdCardStateUpdated:(NSNumber *)operationState; - Event when the SDCardOperationState is updated.
  1. SDCardStatusListWidgetUIState - Provides hooks in events related to user interaction with the widget. It inherits from ListItemLabelButtonUIState and adds no other hooks.
Clone this wiki locally