All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.freeletics.mad.whetstone.Data.kt Maven / Gradle / Ivy

There is a newer version: 0.14.1
Show newest version
package com.freeletics.mad.whetstone

import com.freeletics.mad.whetstone.codegen.util.composeBottomSheetDestination
import com.freeletics.mad.whetstone.codegen.util.composeDestination
import com.freeletics.mad.whetstone.codegen.util.composeDialogDestination
import com.freeletics.mad.whetstone.codegen.util.composeScreenDestination
import com.freeletics.mad.whetstone.codegen.util.fragmentDestination
import com.freeletics.mad.whetstone.codegen.util.fragmentDialogDestination
import com.freeletics.mad.whetstone.codegen.util.fragmentScreenDestination
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.MemberName

internal sealed interface BaseData {
    val baseName: String
    val packageName: String
}

internal sealed interface CommonData : BaseData {
    val scope: ClassName

    val parentScope: ClassName
    val dependencies: ClassName

    val stateMachine: ClassName

    val navigation: Navigation?

    val coroutinesEnabled: Boolean
    val rxJavaEnabled: Boolean
}

internal sealed interface Navigation {
    val route: ClassName
    val destinationClass: ClassName
    val destinationScope: ClassName
    val destinationMethod: MemberName?

    data class Compose(
        override val route: ClassName,
        private val destinationType: String,
        override val destinationScope: ClassName,
    ) : Navigation {
        override val destinationClass: ClassName = composeDestination

        override val destinationMethod = when(destinationType) {
            "NONE" -> null
            "SCREEN" -> composeScreenDestination
            "DIALOG" -> composeDialogDestination
            "BOTTOM_SHEET" -> composeBottomSheetDestination
            else -> throw IllegalArgumentException("Unknown destinationType $destinationType")
        }
    }

    data class Fragment(
        override val route: ClassName,
        private val destinationType: String,
        override val destinationScope: ClassName,
    ) : Navigation {
        override val destinationClass: ClassName = fragmentDestination

        override val destinationMethod = when(destinationType) {
            "NONE" -> null
            "SCREEN" -> fragmentScreenDestination
            "DIALOG" -> fragmentDialogDestination
            else -> throw IllegalArgumentException("Unknown destinationType $destinationType")
        }
    }
}

internal data class ComposeScreenData(
    override val baseName: String,
    override val packageName: String,

    override val scope: ClassName,

    override val parentScope: ClassName,
    override val dependencies: ClassName,

    override val stateMachine: ClassName,

    override val navigation: Navigation.Compose?,

    override val coroutinesEnabled: Boolean,
    override val rxJavaEnabled: Boolean,
) :  CommonData

internal data class ComposeFragmentData(
    override val baseName: String,
    override val packageName: String,

    override val scope: ClassName,

    override val parentScope: ClassName,
    override val dependencies: ClassName,

    override val stateMachine: ClassName,
    val fragmentBaseClass: ClassName,

    override val navigation: Navigation.Fragment?,

    val enableInsetHandling: Boolean,
    override val coroutinesEnabled: Boolean,
    override val rxJavaEnabled: Boolean,
) : CommonData

internal data class RendererFragmentData(
    override val baseName: String,
    override val packageName: String,

    override val scope: ClassName,

    override val parentScope: ClassName,
    override val dependencies: ClassName,

    override val stateMachine: ClassName,
    val factory: ClassName,
    val fragmentBaseClass: ClassName,

    override val navigation: Navigation.Fragment?,

    override val coroutinesEnabled: Boolean,
    override val rxJavaEnabled: Boolean,
) : CommonData

internal data class NavEntryData(
    override val baseName: String,
    override val packageName: String,

    val scope: ClassName,

    val parentScope: ClassName,

    val coroutinesEnabled: Boolean,
    val rxJavaEnabled: Boolean,
): BaseData




© 2015 - 2025 Weber Informatics LLC | Privacy Policy