Skip to content

Unit Mode List Item Widget

Cristina Suciu edited this page Dec 23, 2020 · 1 revision

Unit Mode List Item Widget is a DUXBetaListItemRadioButtonWidget type of widget which displays the Unit System used. The currently enabled unit type will be highlighted. The widget provides functionality to change the unit type by tapping on any option. Changing the unit type will change the unit system used in all the widgets. For example, Max Altitude List Item Widget, Max Flight Distance List Item Widget, and telemetry widgets.

Following are examples of the widget states:

Disconnected

Imperial

Metric

Dynamic Widget States

As you can see below, both hints and edit values update dynnamically

Imperial

Metric

When switching to imperial units, a warning dialog is shown explaining that imperial units are approximations of the metric values used by the aircraft.

Usage

To add the unit mode list item widget to your DUXBetaSmartListModel class, override buildModelLists and include DUXBetaUnitModeListItemWidget.duxbeta_className() or [DUXBetaUnitModeListItemWidget duxbeta_className] in your modelClassnameList:

Swift Example

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

ObjC Example

@interface DUXBetaTestSmartListModel : DUXBetaSmartListModel
@end

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

Customizations

The following customizations are available on the Unit Mode List Item Widget:

  • imperialModeOnAlertAppearance - An instance of DUXBetaAlertView.systemAlertAppearance to customize all the standard aspects of the imperial approximations dialog
  • imperialModeExampleTextFont - Optional custom font to use for the example text in the imperial dialog
  • imperialModeOnExampleTextColor - Optional custom color to use for the example text in the imperial dialog
  • imperialModeOnCheckboxTextFont - Optional custom font to use for the "Don't Show Again" checkbox text in the imperial dialog
  • imperialModeOnCheckboxTextColor - Optional custom color to use for the "Don't Show Again" checkbox text in the imperial dialog
  • imperialModeOnCheckboxTintColor - Optional tint color to apply to the checkbox icon in the imperial dialog
  • imperialModeCheckboxOnImage - Optional checkbox "on" image to use for the "Don't Show Again" checkbox. It should be white for tint application
  • imperialModeCheckboxOffImage - Optional checkbox "off" image to use for the "Don't Show Again" checkbox. It should be white for tint application
  • neverShowAgainCheckboxTitle - Customizable string for the checkbox to prevent the imperial change dialog from being shown again

The dialog shown when switching to imperial mode can be customized in multiple ways. To achieve this customized dialog, use the following code:

Swift

unitWiget.imperialModeOnAlertAppearance.backgroundColor =  .duxbeta_gray()
unitWiget.imperialModeExampleTextFont = UIFont(name: "Copperplate-Bold", size: 24.0)
unitWiget.imperialModeOnExampleTextColor = UIColor.blue
unitWiget.imperialModeOnCheckboxTextFont = UIFont(name: "Optima-ExtraBlack", size: 24.0)
unitWiget.imperialModeOnCheckboxTextColor = UIColor.yellow
unitWiget.imperialModeOnCheckboxTintColor = UIColor.blue

Obj-C

unitWiget.imperialModeOnAlertAppearance.backgroundColor =  UIColor.duxbeta_gray();
unitWiget.imperialModeExampleTextFont = [UIFont fontWithName:@"Copperplate-Bold" size:24.0];
unitWiget.imperialModeOnExampleTextColor = [UIColor blueColor];
unitWiget.imperialModeOnCheckboxTextFont = [UIFont fontWithName:@"Optima-ExtraBlack"  size: 24.0];
unitWiget.imperialModeOnCheckboxTextColor = [UIColor yellowColor];
unitWiget.imperialModeOnCheckboxTintColor = [UIColor blueColor];

Hooks

The widget provides hooks for the users to add functionality based on the state changes in the widget. The unit mode list item widget provides the following hooks:

  1. UnitModeItemModelState - Provides hooks for events received by the widget from the widget model. It inherits from ListItemTitleModelState and adds the following hooks:
  • + (instancetype)setUnitTypeSucceeded; - Event with TRUE value when the unit mode has been successfully updated.
  • + (instancetype)setUnitTypeFailed; - Event when setting the unit mode fails.
  • + (instancetype)unitTypeUpdated:(MeasureUnitType)newUnitsMode; - Event when the units mode has changed, passing 1 for metric, 2 for imperial, 3 for unknown
  1. UnitModeItemUIState - Provides hooks for events received by the widget from user interactions. It inherits from ListItemTitleUIState and adds the following hooks:
  • + (instancetype)neverShowAgainCheckChanged:(Bool)newCheckboxSetting; - Event when the user toggles the "Don't Show Again" checkbox.
Clone this wiki locally