Add ktlint

This commit is contained in:
Nathan Adams 2024-03-16 23:55:01 +01:00 committed by TÖRÖK Attila
parent e395c087b4
commit bf88d5c8e6
15 changed files with 352 additions and 345 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
root = true
[*.{kt,kts}]
ktlint_code_style = android_studio
ij_kotlin_name_count_to_use_star_import = 9999
ij_kotlin_name_count_to_use_star_import_for_members = 9999
ktlint_function_naming_ignore_when_annotated_with=Composable

View File

@ -69,7 +69,6 @@ android {
} }
} }
splits { splits {
// Configures multiple APKs based on ABI. // Configures multiple APKs based on ABI.
abi { abi {

View File

@ -1,13 +1,11 @@
package rs.ruffle package rs.ruffle
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.junit.Assert.*
/** /**
* Instrumented test, which will execute on an Android device. * Instrumented test, which will execute on an Android device.
* *

View File

@ -6,8 +6,8 @@ import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import rs.ruffle.ui.theme.RuffleTheme
import java.io.IOException import java.io.IOException
import rs.ruffle.ui.theme.RuffleTheme
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -18,7 +18,7 @@ fun RuffleNavHost(
) { ) {
NavHost( NavHost(
navController = navController, navController = navController,
startDestination = Destinations.SELECT_SWF_ROUTE, startDestination = Destinations.SELECT_SWF_ROUTE
) { ) {
composable(Destinations.SELECT_SWF_ROUTE) { composable(Destinations.SELECT_SWF_ROUTE) {
SelectSwfRoute( SelectSwfRoute(

View File

@ -36,7 +36,7 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import rs.ruffle.ui.theme.RuffleTheme import rs.ruffle.ui.theme.RuffleTheme
import rs.ruffle.ui.theme.slightlyDeemphasizedAlpha import rs.ruffle.ui.theme.SLIGHTLY_DEEMPHASIZED_ALPHA
@Composable @Composable
fun BrandBar() { fun BrandBar() {
@ -49,9 +49,7 @@ fun BrandBar() {
} }
@Composable @Composable
fun SelectSwfRoute( fun SelectSwfRoute(openSwf: (uri: Uri) -> Unit) {
openSwf: (uri: Uri) -> Unit
) {
SelectSwfScreen( SelectSwfScreen(
openSwf = openSwf openSwf = openSwf
) )
@ -78,9 +76,7 @@ fun SelectSwfScreen(openSwf: (uri: Uri) -> Unit) {
} }
@Composable @Composable
private fun SelectSwfUrlOrFile( private fun SelectSwfUrlOrFile(openSwf: (uri: Uri) -> Unit) {
openSwf: (uri: Uri) -> Unit
) {
val urlState by rememberSaveable(stateSaver = UrlStateSaver) { val urlState by rememberSaveable(stateSaver = UrlStateSaver) {
mutableStateOf(UrlState()) mutableStateOf(UrlState())
} }
@ -109,7 +105,7 @@ private fun SelectSwfUrlOrFile(
label = { label = {
Text( Text(
text = stringResource(id = R.string.url), text = stringResource(id = R.string.url),
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium
) )
}, },
textStyle = MaterialTheme.typography.bodyMedium, textStyle = MaterialTheme.typography.bodyMedium,
@ -143,7 +139,9 @@ private fun SelectSwfUrlOrFile(
Text( Text(
text = stringResource(id = R.string.or), text = stringResource(id = R.string.or),
style = MaterialTheme.typography.titleSmall, style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = slightlyDeemphasizedAlpha), color = MaterialTheme.colorScheme.onSurface.copy(
alpha = SLIGHTLY_DEEMPHASIZED_ALPHA
),
modifier = Modifier.paddingFromBaseline(top = 25.dp) modifier = Modifier.paddingFromBaseline(top = 25.dp)
) )
PickSwfButton(openSwf) PickSwfButton(openSwf)
@ -167,9 +165,9 @@ fun PickSwfButton(onSelect: (uri: Uri) -> Unit) {
}, },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 20.dp, bottom = 24.dp), .padding(top = 20.dp, bottom = 24.dp)
) { ) {
Text(text = stringResource(id = R.string.select_a_swf)) Text(text = stringResource(id = R.string.select_a_swf))
} }
} }

View File

@ -219,10 +219,3 @@ val surfaceContainerLowDarkHighContrast = Color(0xFF211A12)
val surfaceContainerDarkHighContrast = Color(0xFF261E16) val surfaceContainerDarkHighContrast = Color(0xFF261E16)
val surfaceContainerHighDarkHighContrast = Color(0xFF302920) val surfaceContainerHighDarkHighContrast = Color(0xFF302920)
val surfaceContainerHighestDarkHighContrast = Color(0xFF3C332A) val surfaceContainerHighestDarkHighContrast = Color(0xFF3C332A)

View File

@ -12,8 +12,8 @@ import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
const val stronglyDeemphasizedAlpha = 0.6f const val STRONGLY_DEEMPHASIZED_ALPHA = 0.6f
const val slightlyDeemphasizedAlpha = 0.87f const val SLIGHTLY_DEEMPHASIZED_ALPHA = 0.87f
private val lightScheme = lightColorScheme( private val lightScheme = lightColorScheme(
primary = primaryLight, primary = primaryLight,
@ -50,7 +50,7 @@ private val lightScheme = lightColorScheme(
surfaceContainerLow = surfaceContainerLowLight, surfaceContainerLow = surfaceContainerLowLight,
surfaceContainer = surfaceContainerLight, surfaceContainer = surfaceContainerLight,
surfaceContainerHigh = surfaceContainerHighLight, surfaceContainerHigh = surfaceContainerHighLight,
surfaceContainerHighest = surfaceContainerHighestLight, surfaceContainerHighest = surfaceContainerHighestLight
) )
private val darkScheme = darkColorScheme( private val darkScheme = darkColorScheme(
@ -88,7 +88,7 @@ private val darkScheme = darkColorScheme(
surfaceContainerLow = surfaceContainerLowDark, surfaceContainerLow = surfaceContainerLowDark,
surfaceContainer = surfaceContainerDark, surfaceContainer = surfaceContainerDark,
surfaceContainerHigh = surfaceContainerHighDark, surfaceContainerHigh = surfaceContainerHighDark,
surfaceContainerHighest = surfaceContainerHighestDark, surfaceContainerHighest = surfaceContainerHighestDark
) )
private val mediumContrastLightColorScheme = lightColorScheme( private val mediumContrastLightColorScheme = lightColorScheme(
@ -126,7 +126,7 @@ private val mediumContrastLightColorScheme = lightColorScheme(
surfaceContainerLow = surfaceContainerLowLightMediumContrast, surfaceContainerLow = surfaceContainerLowLightMediumContrast,
surfaceContainer = surfaceContainerLightMediumContrast, surfaceContainer = surfaceContainerLightMediumContrast,
surfaceContainerHigh = surfaceContainerHighLightMediumContrast, surfaceContainerHigh = surfaceContainerHighLightMediumContrast,
surfaceContainerHighest = surfaceContainerHighestLightMediumContrast, surfaceContainerHighest = surfaceContainerHighestLightMediumContrast
) )
private val highContrastLightColorScheme = lightColorScheme( private val highContrastLightColorScheme = lightColorScheme(
@ -164,7 +164,7 @@ private val highContrastLightColorScheme = lightColorScheme(
surfaceContainerLow = surfaceContainerLowLightHighContrast, surfaceContainerLow = surfaceContainerLowLightHighContrast,
surfaceContainer = surfaceContainerLightHighContrast, surfaceContainer = surfaceContainerLightHighContrast,
surfaceContainerHigh = surfaceContainerHighLightHighContrast, surfaceContainerHigh = surfaceContainerHighLightHighContrast,
surfaceContainerHighest = surfaceContainerHighestLightHighContrast, surfaceContainerHighest = surfaceContainerHighestLightHighContrast
) )
private val mediumContrastDarkColorScheme = darkColorScheme( private val mediumContrastDarkColorScheme = darkColorScheme(
@ -202,7 +202,7 @@ private val mediumContrastDarkColorScheme = darkColorScheme(
surfaceContainerLow = surfaceContainerLowDarkMediumContrast, surfaceContainerLow = surfaceContainerLowDarkMediumContrast,
surfaceContainer = surfaceContainerDarkMediumContrast, surfaceContainer = surfaceContainerDarkMediumContrast,
surfaceContainerHigh = surfaceContainerHighDarkMediumContrast, surfaceContainerHigh = surfaceContainerHighDarkMediumContrast,
surfaceContainerHighest = surfaceContainerHighestDarkMediumContrast, surfaceContainerHighest = surfaceContainerHighestDarkMediumContrast
) )
private val highContrastDarkColorScheme = darkColorScheme( private val highContrastDarkColorScheme = darkColorScheme(
@ -240,7 +240,7 @@ private val highContrastDarkColorScheme = darkColorScheme(
surfaceContainerLow = surfaceContainerLowDarkHighContrast, surfaceContainerLow = surfaceContainerLowDarkHighContrast,
surfaceContainer = surfaceContainerDarkHighContrast, surfaceContainer = surfaceContainerDarkHighContrast,
surfaceContainerHigh = surfaceContainerHighDarkHighContrast, surfaceContainerHigh = surfaceContainerHighDarkHighContrast,
surfaceContainerHighest = surfaceContainerHighestDarkHighContrast, surfaceContainerHighest = surfaceContainerHighestDarkHighContrast
) )
@Immutable @Immutable
@ -252,7 +252,10 @@ data class ColorFamily(
) )
val unspecified_scheme = ColorFamily( val unspecified_scheme = ColorFamily(
Color.Unspecified, Color.Unspecified, Color.Unspecified, Color.Unspecified Color.Unspecified,
Color.Unspecified,
Color.Unspecified,
Color.Unspecified
) )
@Composable @Composable
@ -260,7 +263,9 @@ fun RuffleTheme(
darkTheme: Boolean = isSystemInDarkTheme(), darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+ // Dynamic color is available on Android 12+
dynamicColor: Boolean = false, dynamicColor: Boolean = false,
content: @Composable() () -> Unit content:
@Composable()
() -> Unit
) { ) {
val colorScheme = when { val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
@ -278,4 +283,3 @@ fun RuffleTheme(
content = content content = content
) )
} }

View File

@ -8,13 +8,13 @@ import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with // Set of Material typography styles to start with
val Typography = Typography( val Typography = Typography(
bodyLarge = TextStyle( bodyLarge = TextStyle(
fontFamily = FontFamily.Default, fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
fontSize = 16.sp, fontSize = 16.sp,
lineHeight = 24.sp, lineHeight = 24.sp,
letterSpacing = 0.5.sp letterSpacing = 0.5.sp
) )
/* Other default text styles to override /* Other default text styles to override
titleLarge = TextStyle( titleLarge = TextStyle(
fontFamily = FontFamily.Default, fontFamily = FontFamily.Default,
@ -30,5 +30,5 @@ val Typography = Typography(
lineHeight = 16.sp, lineHeight = 16.sp,
letterSpacing = 0.5.sp letterSpacing = 0.5.sp
) )
*/ */
) )

View File

@ -1,9 +1,8 @@
package rs.ruffle package rs.ruffle
import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.Assert.*
/** /**
* Example local unit test, which will execute on the development machine (host). * Example local unit test, which will execute on the development machine (host).
* *

View File

@ -1,6 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
alias(libs.plugins.ktlint)
alias(libs.plugins.androidApplication) apply false alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.cargoNdkAndroid) apply false alias(libs.plugins.cargoNdkAndroid) apply false
} }
allprojects {
apply(plugin = rootProject.libs.plugins.ktlint.get().pluginId)
}
ktlint {
android.set(true)
}

View File

@ -14,6 +14,7 @@ navigationCompose = "2.7.7"
gamesActivity = "2.0.2" # Needs to be in sync with android-activity crate gamesActivity = "2.0.2" # Needs to be in sync with android-activity crate
constraintlayout = "2.1.4" constraintlayout = "2.1.4"
appcompat = "1.6.1" appcompat = "1.6.1"
ktlint = "12.1.0"
[libraries] [libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@ -40,6 +41,6 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
[plugins] [plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" } androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
cargoNdkAndroid = { id = "com.github.willir.rust.cargo-ndk-android", version = "0.3.4" } cargoNdkAndroid = { id = "com.github.willir.rust.cargo-ndk-android", version = "0.3.4" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }

View File

@ -21,4 +21,3 @@ dependencyResolutionManagement {
rootProject.name = "Ruffle" rootProject.name = "Ruffle"
include(":app") include(":app")