Skip to content

SD Card Remaining Capacity List Item Widget

Shane Looker edited this page May 15, 2020 · 1 revision

SD Card Status List Item Widget is a DUXListItemLabelAndButton 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

/Images/SDCardStatusListItemWidget/SDCardFormatAreUSure.png

Format error dialog

Usage

To add the SD card remaining capacity list item widget to your DUXSmartListModel class, override buildModelLists and include DUXSDCardRemainingCapacityListItemWidget.dux_className() or [DUXSDCardRemainingCapacityListItemWidget dux_className] in your modelClassnameList:

Swift Example

@objc open class MySmartListModel : DUXSmartListModel {
    @objc open override func buildModelLists() {
        super.buildModelLists()
        self.modelClassnameList.append(DUXSDCardRemainingCapacityListItemWidget.dux_className())
    }
}

ObjC Example

@interface DUXTestSmartListModel : DUXSmartListModel
@end

@implementation DUXTestSmartListModel
- (void)buildModelLists {
    [super buildModelLists];
    [self.modelClassnameList append:[DUXSDCardRemainingCapacityListItemWidget dux_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, DUXListItemLabelAndButton supports. An example of a customized SD card remaining capacity 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;

Hooks

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

The SD Card Remaining Capacity List Item widget provides the following hooks:

  1. SDCardRemainingCapacityListWidgetModelState - Provides hooks in events received by the widget from the widget model. It inherits from ListItemLabelButtonModelState and it adds the following hooks:
  • + (instancetype)sdCardRemainingCapacityChanged:(NSInteger)freeStorageChanged; - Event when the SD card's remaining capacity changes.
  • + (instancetype)sdCardRemainingCapacityCardInserted:(BOOL)cardInserted; - Sends a boolean value as an NSInteger when an SD card is inserted or removed. YES indicates insertion, NO indicates removal.
  • + (instancetype)sdCardRemainingCapacityOperatingStatusChanged:(NSNumber *)operationState; - Event when the SDCardOperationState is updated.
  1. SDCardRemainingCapacityListWidgetUIState - Provides hooks in events related to user interaction with the widget. It inherits from ListItemLabelButtonUIState and adds no other hooks.
Clone this wiki locally