Skip to content

Commit

Permalink
Merge pull request #796 from splendo/feature/2.0.20-lint
Browse files Browse the repository at this point in the history
Run lint
  • Loading branch information
Daeda88 authored Aug 28, 2024
2 parents d7c510f + acff982 commit 9a2ec9e
Show file tree
Hide file tree
Showing 335 changed files with 2,351 additions and 2,931 deletions.
15 changes: 6 additions & 9 deletions alerts/src/androidMain/kotlin/AlertPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ actual class AlertPresenter(
private val lifecycleManagerObserver: LifecycleManagerObserver = LifecycleManagerObserver(),
coroutineScope: CoroutineScope,
logger: Logger,
) : BaseAlertPresenter(alert, logger), CoroutineScope by coroutineScope {
) : BaseAlertPresenter(alert, logger),
CoroutineScope by coroutineScope {

/**
* A [BaseAlertPresenter.Builder] for creating an [AlertPresenter]
* @param lifecycleManagerObserver The [LifecycleManagerObserver] to observe lifecycle changes
*/
actual class Builder(
private val lifecycleManagerObserver: LifecycleManagerObserver = LifecycleManagerObserver(),
) : BaseAlertPresenter.Builder(), ActivityLifecycleSubscribable by lifecycleManagerObserver {
actual class Builder(private val lifecycleManagerObserver: LifecycleManagerObserver = LifecycleManagerObserver()) :
BaseAlertPresenter.Builder(),
ActivityLifecycleSubscribable by lifecycleManagerObserver {

/**
* Creates an [AlertPresenter]
Expand All @@ -76,11 +77,7 @@ actual class AlertPresenter(
}

private sealed class DialogPresentation {
data class Showing(
val animated: Boolean,
val afterHandler: (Alert.Action?) -> Unit,
val completion: () -> Unit,
) : DialogPresentation()
data class Showing(val animated: Boolean, val afterHandler: (Alert.Action?) -> Unit, val completion: () -> Unit) : DialogPresentation()

data object Hidden : DialogPresentation()
}
Expand Down
20 changes: 3 additions & 17 deletions alerts/src/commonMain/kotlin/Alerts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ typealias AlertTextObserver = (String) -> Unit
* @property actions The list of action objects that the user can take in response to the alert
* @property textInputAction The optional action object that sets the alert's input options and text change callback
*/
data class Alert(
val title: String?,
val message: String?,
val actions: List<Action>,
val textInputAction: TextInputAction? = null,
val style: Style = Style.ALERT,
) {
data class Alert(val title: String?, val message: String?, val actions: List<Action>, val textInputAction: TextInputAction? = null, val style: Style = Style.ALERT) {

/**
* Alert style
Expand Down Expand Up @@ -203,11 +197,7 @@ data class Alert(
* @property style The [Style] that is applied to the action's button
* @property handler The block to execute when the user taps a button
*/
data class Action(
val title: String,
val style: Style = Style.DEFAULT,
val handler: AlertActionHandler = {},
) {
data class Action(val title: String, val style: Style = Style.DEFAULT, val handler: AlertActionHandler = {}) {
/**
* The style of an action. This determines the look of the button when displayed in the alert.
*/
Expand Down Expand Up @@ -251,11 +241,7 @@ data class Alert(
* @param placeholder The hint of the input field
* @param textObserver The block to execute when the user edits the text in the input field
*/
data class TextInputAction(
val text: String?,
val placeholder: String?,
val textObserver: AlertTextObserver,
)
data class TextInputAction(val text: String?, val placeholder: String?, val textObserver: AlertTextObserver)
}

/**
Expand Down
10 changes: 5 additions & 5 deletions alerts/src/iosMain/kotlin/AlertPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ actual class AlertPresenter(
* @param delegateBuilder Method that creates a [UIPopoverPresentationControllerDelegateProtocol] for an [Alert].
* This allows for presentation of [Alert.Style.ACTION_LIST] on iPad.
*/
actual class Builder(
private val viewController: UIViewController,
private val delegateBuilder: (Alert) -> UIPopoverPresentationControllerDelegateProtocol,
) : BaseAlertPresenter.Builder() {
actual class Builder(private val viewController: UIViewController, private val delegateBuilder: (Alert) -> UIPopoverPresentationControllerDelegateProtocol) :
BaseAlertPresenter.Builder() {

/**
* Constructor that returns a [DefaultUIPopoverPresentationControllerDelegateProtocol] when a presented [AlertPresenter] requires a [UIPopoverPresentationControllerDelegateProtocol].
Expand All @@ -125,7 +123,9 @@ actual class AlertPresenter(
actual override fun create(alert: Alert, logger: Logger, coroutineScope: CoroutineScope) = AlertPresenter(alert, viewController, logger, delegateBuilder)
}

class DefaultUIPopoverPresentationControllerDelegateProtocol(private val sourceView: UIView) : NSObject(), UIPopoverPresentationControllerDelegateProtocol {
class DefaultUIPopoverPresentationControllerDelegateProtocol(private val sourceView: UIView) :
NSObject(),
UIPopoverPresentationControllerDelegateProtocol {
override fun prepareForPopoverPresentation(popoverPresentationController: UIPopoverPresentationController) {
popoverPresentationController.sourceView = sourceView
popoverPresentationController.sourceRect = sourceView.bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import kotlinx.coroutines.flow.StateFlow
* @param Action the type of [NavigationAction] this navigator should respond to.
* @param navigationMapper A mapper that converts an [Action] handled by this navigator into a [BottomSheetComposableNavSpec]
*/
sealed class BottomSheetNavigator<Action : NavigationAction<*>>(
private val navigationMapper: @Composable (Action) -> BottomSheetComposableNavSpec,
) : Navigator<Action>, ComposableLifecycleSubscribable {
sealed class BottomSheetNavigator<Action : NavigationAction<*>>(private val navigationMapper: @Composable (Action) -> BottomSheetComposableNavSpec) :
Navigator<Action>,
ComposableLifecycleSubscribable {

protected abstract val routeController: BottomSheetRouteController

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import androidx.compose.material3.BottomSheetScaffold
* @param contentRouteController The [RouteController] managing the content.
* @param sheetContentRouteController The [RouteController] managing the sheet content.
*/
class BottomSheetRouteController(
internal val contentRouteController: RouteController,
internal val sheetContentRouteController: BottomSheetSheetContentRouteController,
) {
class BottomSheetRouteController(internal val contentRouteController: RouteController, internal val sheetContentRouteController: BottomSheetSheetContentRouteController) {

/**
* Navigates using a given [BottomSheetRoute]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ sealed class ComposableNavSpec {
* @property tag Optional tag to add to the Dialog
* @property createDialog Function to create the [DialogFragment] to display
*/
data class Dialog(
val tag: String? = null,
val createDialog: () -> DialogFragment,
) : LaunchedNavigation() {
data class Dialog(val tag: String? = null, val createDialog: () -> DialogFragment) : LaunchedNavigation() {

@Composable
override fun createLauncher(viewModel: BaseLifecycleViewModel, onDispose: () -> Unit): () -> Unit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ typealias RouteContentBuilder = NavGraphBuilder.(StateFlow<NavHostController?>)
* @param Action the type of [NavigationAction] this navigator should respond to.
* @param navigationMapper A mapper that converts an [Action] handled by this navigator into a [ComposableNavSpec]
*/
sealed class ComposableNavigator<Action : NavigationAction<*>>(
private val navigationMapper: @Composable (Action) -> ComposableNavSpec,
) : Navigator<Action>, ComposableLifecycleSubscribable {
sealed class ComposableNavigator<Action : NavigationAction<*>>(private val navigationMapper: @Composable (Action) -> ComposableNavSpec) :
Navigator<Action>,
ComposableLifecycleSubscribable {

protected abstract val routeController: RouteController?

Expand Down Expand Up @@ -197,9 +197,8 @@ class BottomSheetSheetContentNavHostComposableNavigator<Action : NavigationActio
* @param Action the type of [NavigationAction] this navigator should respond to.
* @param navigationMapper Maps [Action] to a [ComposableNavSpec.LaunchedNavigation] to be navigated to.
*/
class LaunchedComposableNavigator<Action : NavigationAction<*>>(
navigationMapper: @Composable (Action) -> ComposableNavSpec.LaunchedNavigation,
) : ComposableNavigator<Action>(navigationMapper) {
class LaunchedComposableNavigator<Action : NavigationAction<*>>(navigationMapper: @Composable (Action) -> ComposableNavSpec.LaunchedNavigation) :
ComposableNavigator<Action>(navigationMapper) {
override val routeController: RouteController? = null
override val contentModifier: @Composable BaseLifecycleViewModel.(@Composable BaseLifecycleViewModel.() -> Unit) -> Unit = @Composable { content -> content() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,12 @@ fun <Value, Action : SingleValueNavigationAction<Value>> NavGraphBuilder.composa
content(bundle.get(type))
}

private fun <SpecType : NavigationBundleSpecRow<*>> Bundle.composable(spec: NavigationBundleSpec<SpecType>): NavigationBundle<SpecType>? {
return try {
spec.toBundle { type ->
composableValue(getString(type.argumentKey), type.associatedType)
}
} catch (e: BundleConversionError) {
null
private fun <SpecType : NavigationBundleSpecRow<*>> Bundle.composable(spec: NavigationBundleSpec<SpecType>): NavigationBundle<SpecType>? = try {
spec.toBundle { type ->
composableValue(getString(type.argumentKey), type.associatedType)
}
} catch (e: BundleConversionError) {
null
}

private fun Bundle.composableValue(value: String?, specType: NavigationBundleSpecType<*>): NavigationBundleValue<*> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ fun HardwareBackButtonNavigation(onBackButtonClickHandler: suspend () -> Unit) {
}
}

private class ComposeOnBackPressedCallback(
private val coroutineScope: CoroutineScope,
private val onBackButtonClickHandler: suspend () -> Unit,
) : OnBackPressedCallback(true) {
private class ComposeOnBackPressedCallback(private val coroutineScope: CoroutineScope, private val onBackButtonClickHandler: suspend () -> Unit) : OnBackPressedCallback(true) {

override fun handleOnBackPressed() {
coroutineScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ sealed class Route : ComposableNavSpec() {
* @param SpecRow the type of [NavigationBundleSpecRow] associated with the action.
* @param Action the type [NavigationAction] to navigate for.
*/
sealed class Navigate<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>> :
Route() {
sealed class Navigate<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>> : Route() {
protected abstract val routeAction: Action

/**
Expand All @@ -220,9 +219,7 @@ sealed class Route : ComposableNavSpec() {
* @param Action the type [NavigationAction] to navigate for.
* @property routeAction The [Action] associated with the screen to navigate to
*/
data class NextRoute<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(
override val routeAction: Action,
) : Navigate<SpecRow, Action>()
data class NextRoute<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(override val routeAction: Action) : Navigate<SpecRow, Action>()

/**
* [Navigate] that navigates from a given route to the screen associated with a [NavigationAction]
Expand All @@ -231,10 +228,8 @@ sealed class Route : ComposableNavSpec() {
* @property routeAction The [Action] associated with the screen to navigate to
* @property from The route string to navigate from
*/
data class FromRoute<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(
override val routeAction: Action,
val from: String,
) : Navigate<SpecRow, Action>()
data class FromRoute<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(override val routeAction: Action, val from: String) :
Navigate<SpecRow, Action>()

/**
* [Navigate] that navigates back to the screen associated with a [NavigationAction]
Expand All @@ -257,19 +252,15 @@ sealed class Route : ComposableNavSpec() {
* @param Action the type [NavigationAction] to navigate for.
* @property routeAction The [Action] associated with the screen to navigate back from
*/
data class PopToIncluding<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(
override val routeAction: Action,
) : Navigate<SpecRow, Action>()
data class PopToIncluding<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(override val routeAction: Action) : Navigate<SpecRow, Action>()

/**
* [Navigate] that replaces the current screen to the screen associated with a [NavigationAction]
* @param SpecRow the type of [NavigationBundleSpecRow] associated with the action.
* @param Action the type [NavigationAction] to navigate for.
* @property routeAction The [Action] associated with the screen to replace the current screen with
*/
data class Replace<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(
override val routeAction: Action,
) : Navigate<SpecRow, Action>()
data class Replace<SpecRow : NavigationBundleSpecRow<*>, Action : NavigationAction<SpecRow>>(override val routeAction: Action) : Navigate<SpecRow, Action>()

/**
* [Route] that navigates back one step in the hierarchy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ sealed interface RouteController {
* @param provider A [StateFlow] of [Provider].
* @param parentRouteController An optional parent [RouteController] managing this controller.
*/
sealed class ProvidingNavHostRouteController<Provider>(
private val provider: StateFlow<Provider?>,
private val parentRouteController: RouteController? = null,
) : RouteController {
sealed class ProvidingNavHostRouteController<Provider>(private val provider: StateFlow<Provider?>, private val parentRouteController: RouteController? = null) : RouteController {

/**
* Converts [Provider] into a [NavHostController]
Expand Down Expand Up @@ -136,10 +133,8 @@ sealed class ProvidingNavHostRouteController<Provider>(
* @param provider The flow of [NavHostController] to be managed by this Route Controller
* @param parentRouteController An optional parent [RouteController] managing this controller.
*/
class NavHostRouteController(
provider: StateFlow<NavHostController?>,
parentRouteController: RouteController? = null,
) : ProvidingNavHostRouteController<NavHostController>(provider, parentRouteController) {
class NavHostRouteController(provider: StateFlow<NavHostController?>, parentRouteController: RouteController? = null) :
ProvidingNavHostRouteController<NavHostController>(provider, parentRouteController) {
override fun NavHostController.provide(): NavHostController = this
}

Expand All @@ -148,10 +143,8 @@ class NavHostRouteController(
* @param provider The flow of [BottomSheetNavigatorState] where the [BottomSheetNavigatorState.contentNavHostController] is to be managed by this Route Controller
* @param parentRouteController An optional parent [RouteController] managing this controller.
*/
class BottomSheetContentRouteController(
provider: StateFlow<BottomSheetNavigatorState?>,
parentRouteController: RouteController? = null,
) : ProvidingNavHostRouteController<BottomSheetNavigatorState>(provider, parentRouteController) {
class BottomSheetContentRouteController(provider: StateFlow<BottomSheetNavigatorState?>, parentRouteController: RouteController? = null) :
ProvidingNavHostRouteController<BottomSheetNavigatorState>(provider, parentRouteController) {
override fun BottomSheetNavigatorState.provide(): NavHostController = contentNavHostController
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ private fun <ViewModel : BaseLifecycleViewModel> ViewModel.linkLifecycle(activit
return this
}

private class VmObserver<ViewModel : BaseLifecycleViewModel>(
private val viewModel: ViewModel,
activity: AppCompatActivity?,
fragmentManager: FragmentManager,
) : DefaultLifecycleObserver {
private class VmObserver<ViewModel : BaseLifecycleViewModel>(private val viewModel: ViewModel, activity: AppCompatActivity?, fragmentManager: FragmentManager) :
DefaultLifecycleObserver {

private val manager = LifecycleSubscribableManager(viewModel, activity, fragmentManager)
private var resumed = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ object MockSpec : NavigationBundleSpec<MockSpecRow<*>>(
),
)

sealed class MockSpecRow<V>(associatedType: NavigationBundleSpecType<V>) :
NavigationBundleSpecRow<V>(associatedType) {
sealed class MockSpecRow<V>(associatedType: NavigationBundleSpecType<V>) : NavigationBundleSpecRow<V>(associatedType) {
data object StringSpecRow : MockSpecRow<String>(NavigationBundleSpecType.StringType)
data object BooleanSpecRow : MockSpecRow<Boolean>(NavigationBundleSpecType.BooleanType)
data object FloatSpecRow : MockSpecRow<Float>(NavigationBundleSpecType.FloatType)
Expand All @@ -73,14 +72,12 @@ sealed class MockSpecRow<V>(associatedType: NavigationBundleSpecType<V>) :

class NestedSpec : NavigationBundleSpec<NestedSpecRow<*>>(setOf(NestedSpecRow.StringSpecRow))

sealed class NestedSpecRow<V>(associatedType: NavigationBundleSpecType<V>) :
NavigationBundleSpecRow<V>(associatedType) {
sealed class NestedSpecRow<V>(associatedType: NavigationBundleSpecType<V>) : NavigationBundleSpecRow<V>(associatedType) {

data object StringSpecRow : NestedSpecRow<String>(NavigationBundleSpecType.StringType)
}

class TestNavigationAction(bundle: NavigationBundle<MockSpecRow<*>>) :
NavigationAction<MockSpecRow<*>>(bundle)
class TestNavigationAction(bundle: NavigationBundle<MockSpecRow<*>>) : NavigationAction<MockSpecRow<*>>(bundle)

class RouteTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import kotlinx.serialization.KSerializer
* @return The [R] value stored in the bundle
* @throws [BundleConversionError] if the [Bundle] is not associated with a [SingleValueNavigationSpec]
*/
fun <R> Bundle.toTypedProperty(type: NavigationBundleSpecType<R>): R {
return toNavigationBundle(SingleValueNavigationSpec(type)).get(type)
}
fun <R> Bundle.toTypedProperty(type: NavigationBundleSpecType<R>): R = toNavigationBundle(SingleValueNavigationSpec(type)).get(type)

/**
* Converts a [Bundle] to a [R] property associated with a [NavigationBundleSpecType]
Expand Down
Loading

0 comments on commit 9a2ec9e

Please sign in to comment.