This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A [CallAdapter.Factory] which allows [NetworkResponse] objects to be | |
* returned from RxJava streams created by Retrofit. | |
* | |
* Adding this class to [Retrofit] allows you to write service methods like: | |
* | |
* fun getTokens(): Single<NetworkResponse<AccessToken,Error>> | |
*/ | |
class KotlinRxJava2CallAdapterFactory : CallAdapter.Factory() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIComponent(BaseModel, ABC): | |
sdui_component_type: ComponentType | |
def __init__(self, **data) -> None: | |
data['sdui_component_type'] = self.component_type() | |
super().__init__(**data) | |
@classmethod | |
@abstractmethod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataRow(UIComponent): | |
title: str | |
subtitle: str | |
layout: Layout = Layout.HORIZONTAL | |
@classmethod | |
def component_type(cls) -> ComponentType: | |
return ComponentType.DATA_ROW_STACKED | |
class Layout(str, Enum): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIComponent(BaseModel, ABC): | |
# ... | |
def __init__(self, **data) -> None: | |
# SDUIContext is set as a context var when handling any request on the backend | |
current_context = SDUIContext.current() | |
if current_context is not None: | |
# Will raise an error if incompatible | |
current_context.validate_compatibility( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Row(UIComponent): | |
title: str | |
subtitle: Optional[str] = None | |
@classmethod | |
def component_type(cls) -> ComponentType: | |
return ComponentType.BUTTON | |
@classmethod | |
def platform_compatibility(cls) -> Dict[Platform, Version]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum SDUIComponent: Equatable, Codable { | |
case button(SDUIButton) | |
case row(SDUIRow) | |
case text(SDUIText) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed interface SDUIComponent | |
data class SDUIButton: SDUIComponent | |
data class SDUIRow: SDUIComponent | |
data class SDUIText: SDUIComponent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDUIComponent = SDUIButton | SDUIRow | SDUIText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension DataRow: ViewModelConvertible { | |
func viewModel(context: SDUIContext) -> some ViewModel { | |
return DataRowViewModel( | |
title: self.title, | |
titleURL: self.titleHyperlink, | |
subtitle: self.subtitle, | |
layout: self.layout.toNativeLayout(), | |
accessory: accessoryView?.viewModel(context: context) | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SDUIComponent { | |
private var concreteModel: Any { | |
switch self { | |
case .button(let button): | |
return button | |
case .row(let row): | |
return row | |
case .text(let text): | |
return text | |
} |