diff --git a/catroid/config/detekt.yml b/catroid/config/detekt.yml index 93a7b127dfe..5973c3d1047 100644 --- a/catroid/config/detekt.yml +++ b/catroid/config/detekt.yml @@ -70,11 +70,12 @@ complexity: threshold: 80 LongParameterList: active: true - threshold: 6 + functionThreshold: 8 + constructorThreshold: 8 ignoreDefaultParameters: false MethodOverloading: active: true - threshold: 2 + threshold: 6 NestedBlockDepth: active: true threshold: 4 diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickContextMenuTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickContextMenuTest.kt index cd2825550d9..2036a62b2fd 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickContextMenuTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/bricks/BrickContextMenuTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -100,7 +100,7 @@ class BrickContextMenuTest( arrayOf(WhenNfcBrick(), false, false), arrayOf(WhenRaspiPinChangedBrick(), false, false), arrayOf(WhenTouchDownBrick(), false, false) - ) + ) } @Before diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/sprite/DeleteImportedSpriteTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/sprite/DeleteImportedSpriteTest.kt index ee0a83fb005..e28f1ed3571 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/sprite/DeleteImportedSpriteTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/sprite/DeleteImportedSpriteTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -79,14 +79,18 @@ class DeleteImportedSpriteTest { baseActivityTestRule.launchActivity() Intents.init() - expectedIntent = AllOf.allOf(IntentMatchers.hasExtra( - ProjectListActivity.IMPORT_LOCAL_INTENT, - baseActivityTestRule.activity.getString(R.string.import_sprite_from_project_launcher) - )) + expectedIntent = AllOf.allOf( + IntentMatchers.hasExtra( + ProjectListActivity.IMPORT_LOCAL_INTENT, + baseActivityTestRule.activity.getString(R.string.import_sprite_from_project_launcher) + ) + ) val resultData = Intent() - resultData.putExtra(ProjectListActivity.IMPORT_LOCAL_INTENT, - localProject.directory.absoluteFile.absolutePath) + resultData.putExtra( + ProjectListActivity.IMPORT_LOCAL_INTENT, + localProject.directory.absoluteFile.absolutePath + ) val result = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData) Intents.intending(expectedIntent).respondWith(result) diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/stage/ScreenshotSaverTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/test/stage/ScreenshotSaverTest.kt index 2584032886a..8972fc22889 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/stage/ScreenshotSaverTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/stage/ScreenshotSaverTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -52,11 +52,11 @@ class ScreenshotSaverTest(private val name: String, private val fileName: String @JvmStatic @Parameterized.Parameters(name = "{0}") fun data() = listOf( - arrayOf("VALID", "valid.png", true), - arrayOf("NULL", null, false), - arrayOf("WHITESPACES", " ", false), - arrayOf("ILLEGAL_CHARACTERS", "|\\?*<\":>+[]/'", false) - ) + arrayOf("VALID", "valid.png", true), + arrayOf("NULL", null, false), + arrayOf("WHITESPACES", " ", false), + arrayOf("ILLEGAL_CHARACTERS", "|\\?*<\":>+[]/'", false) + ) private const val NUMBER_OF_COLORS = 4 } diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/ui/BrickSearchTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/test/ui/BrickSearchTest.kt index 7c9c7b20f85..9c8b171f6c4 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/ui/BrickSearchTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/ui/BrickSearchTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -103,8 +103,14 @@ class BrickSearchTest { InstrumentationRegistry.getInstrumentation().waitForIdleSync() viewMatcher.perform(pressKey(KeyEvent.KEYCODE_ENTER)) InstrumentationRegistry.getInstrumentation().waitForIdleSync() - Espresso.onData(Matchers.allOf(Matchers.`is`(Matchers.instanceOf - (bricks[index] as Class<*>?)))) + Espresso.onData( + Matchers.allOf( + Matchers.`is`( + Matchers.instanceOf + (bricks[index] as Class<*>?) + ) + ) + ) .inAdapterView(BrickPrototypeListMatchers.isBrickPrototypeView()) .atPosition(0) .check(matches(isDisplayed())) @@ -237,13 +243,13 @@ class BrickSearchTest { ) } - fun ensureKeyboardIsClosed() { + private fun ensureKeyboardIsClosed() { if (isKeyboardVisible()) { hideKeyboard() } } - fun hideKeyboard() { + private fun hideKeyboard() { Espresso.onView(ViewMatchers.isRoot()).perform(ViewActions.closeSoftKeyboard()) } @Test diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/ui/AssertEqualsBrickTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/ui/AssertEqualsBrickTest.kt index de57dfb1b3d..3647dac1747 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/ui/AssertEqualsBrickTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/ui/AssertEqualsBrickTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -115,13 +115,9 @@ class AssertEqualsBrickTest { private fun handleConstraints(action: ViewAction, constraints: Matcher): ViewAction { return object : ViewAction { - override fun getConstraints(): Matcher { - return constraints - } + override fun getConstraints(): Matcher = constraints - override fun getDescription(): String { - return action.description - } + override fun getDescription(): String = action.description override fun perform(uiController: UiController?, view: View?) { action.perform(uiController, view) diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/StartListeningStageTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/StartListeningStageTest.kt index 64ec166d8b8..629a18f5a9d 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/StartListeningStageTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/StartListeningStageTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -67,12 +67,12 @@ class StartListeningStageTest { @Before fun setUp() { createProject(javaClass.simpleName) - textToSpeech = TextToSpeech(ApplicationProvider.getApplicationContext(), TextToSpeech.OnInitListener - { status -> - if (status == TextToSpeech.SUCCESS) { - textToSpeech.language = Locale.US + textToSpeech = + TextToSpeech(ApplicationProvider.getApplicationContext()) { status -> + if (status == TextToSpeech.SUCCESS) { + textToSpeech.language = Locale.US + } } - }) baseActivityTestRule.launchActivity(null) } diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/TextDetectionResourceTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/TextDetectionResourceTest.kt index fc1c7995cd7..a0bc9fce36c 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/TextDetectionResourceTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/stage/TextDetectionResourceTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -111,8 +111,8 @@ class TextDetectionResourceTest { val script = UiTestUtils.createProjectAndGetStartScript("TextDetectionResourceTest") .also { - it.addBrick(SetSizeToBrick(formula)) - } + it.addBrick(SetSizeToBrick(formula)) + } lastBrickInScript = ScriptEvaluationGateBrick.appendToScript(script) } diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/FormulaEditorComputeDialogComputationResultTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/FormulaEditorComputeDialogComputationResultTest.kt index 6e594f6d458..2053242156a 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/FormulaEditorComputeDialogComputationResultTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/FormulaEditorComputeDialogComputationResultTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -126,6 +126,7 @@ import org.junit.runners.Parameterized @Category(AppUi::class, Smoke::class) @RunWith(Parameterized::class) class FormulaEditorComputeDialogComputationResultTest( + @Suppress("unused") private val name: String, private val formula: Formula, private val userVariableLeftValue: Any?, @@ -149,7 +150,7 @@ class FormulaEditorComputeDialogComputationResultTest( @After @Throws(Exception::class) fun tearDown() { - TestUtils.deleteProjects(projectName) + TestUtils.deleteProjects(PROJECT_NAME) } @Test @@ -167,28 +168,28 @@ class FormulaEditorComputeDialogComputationResultTest( } fun createProject() { - val sprite = Sprite(spriteName) - val collisionSprite = Sprite(collisionSpriteName) + val sprite = Sprite(SPRITE_NAME) + val collisionSprite = Sprite(COLLISION_SPRITE_NAME) val script: Script = StartScript() val noteFormula = formula script.addBrick(NoteBrick(noteFormula)) sprite.addScript(script) - project = Project(ApplicationProvider.getApplicationContext(), projectName) + project = Project(ApplicationProvider.getApplicationContext(), PROJECT_NAME) project.defaultScene.addSprite(sprite) project.defaultScene.addSprite(collisionSprite) if (userVariableLeftValue != null) { - project.addUserVariable(UserVariable(userVariableLeftName, userVariableLeftValue)) + project.addUserVariable(UserVariable(USER_VARIABLE_LEFT_NAME, userVariableLeftValue)) } if (userVariableRightValue != null) { - project.addUserVariable(UserVariable(userVariableRightName, userVariableRightValue)) + project.addUserVariable(UserVariable(USER_VARIABLE_RIGHT_NAME, userVariableRightValue)) } if (userListLeftElements != null) { - project.addUserList(UserList(userListLeftName, userListLeftElements)) + project.addUserList(UserList(USER_LIST_LEFT_NAME, userListLeftElements)) } if (userListRightElements != null) { - project.addUserList(UserList(userListRightName, userListRightElements)) + project.addUserList(UserList(USER_LIST_RIGHT_NAME, userListRightElements)) } ProjectManager.getInstance().currentProject = project @@ -197,13 +198,13 @@ class FormulaEditorComputeDialogComputationResultTest( companion object { private lateinit var project: Project - private const val projectName = "formulaEditorComputeDialogBooleanTest" - private const val spriteName = "testSprite" - private const val collisionSpriteName = "testCollisionSprite" - private const val userListLeftName = "userListLeft" - private const val userListRightName = "userListRight" - private const val userVariableLeftName = "userVariableLeft" - private const val userVariableRightName = "userVariableRight" + private const val PROJECT_NAME = "formulaEditorComputeDialogBooleanTest" + private const val SPRITE_NAME = "testSprite" + private const val COLLISION_SPRITE_NAME = "testCollisionSprite" + private const val USER_LIST_LEFT_NAME = "userListLeft" + private const val USER_LIST_RIGHT_NAME = "userListRight" + private const val USER_VARIABLE_LEFT_NAME = "userVariableLeft" + private const val USER_VARIABLE_RIGHT_NAME = "userVariableRight" @JvmStatic @Parameterized.Parameters(name = "{0}") @@ -221,7 +222,7 @@ class FormulaEditorComputeDialogComputationResultTest( ) private val applicationContext: Context = - ApplicationProvider.getApplicationContext() + ApplicationProvider.getApplicationContext() private val trueString = applicationContext.getString(R.string.formula_editor_true) private val falseString = applicationContext.getString(R.string.formula_editor_false) @@ -655,7 +656,7 @@ class FormulaEditorComputeDialogComputationResultTest( "Function LIST_ITEM Strings", getFormula( Pair(FUNCTION, LIST_ITEM.name), Pair(NUMBER, 3), - Pair(USER_LIST, userListLeftName) + Pair(USER_LIST, USER_LIST_LEFT_NAME) ), null, null, listOf("1", "2", "3", "4", "5"), null, "3" @@ -664,7 +665,7 @@ class FormulaEditorComputeDialogComputationResultTest( "Function LIST_ITEM Ints", getFormula( Pair(FUNCTION, LIST_ITEM.name), Pair(NUMBER, 3), - Pair(USER_LIST, userListLeftName) + Pair(USER_LIST, USER_LIST_LEFT_NAME) ), null, null, listOf(1, 2, 3, 4, 5), null, "3" @@ -673,7 +674,7 @@ class FormulaEditorComputeDialogComputationResultTest( "Function NUMBER_OF_ITEMS", getFormula( Pair(FUNCTION, NUMBER_OF_ITEMS.name), - Pair(USER_LIST, userListLeftName) + Pair(USER_LIST, USER_LIST_LEFT_NAME) ), null, null, listOf(1, 2, 3, 4), null, "4" @@ -751,13 +752,13 @@ class FormulaEditorComputeDialogComputationResultTest( ), arrayOf( "Function FLATTEN Strings", - getFormula(Pair(FUNCTION, FLATTEN.name), Pair(USER_LIST, userListLeftName)), + getFormula(Pair(FUNCTION, FLATTEN.name), Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf("1", "2", "3", "4", "5"), null, "12345" ), arrayOf( "Function FLATTEN Ints", - getFormula(Pair(FUNCTION, FLATTEN.name), Pair(USER_LIST, userListLeftName)), + getFormula(Pair(FUNCTION, FLATTEN.name), Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(1, 2, 3, 4, 5), null, "12345" ) @@ -780,7 +781,7 @@ class FormulaEditorComputeDialogComputationResultTest( arrayOf( "Function CONTAINS false", getFormula( - Pair(FUNCTION, CONTAINS.name), Pair(USER_LIST, userListLeftName), + Pair(FUNCTION, CONTAINS.name), Pair(USER_LIST, USER_LIST_LEFT_NAME), Pair(NUMBER, 10) ), null, null, listOf(1, 2, 3, 4, 5), null, @@ -789,7 +790,7 @@ class FormulaEditorComputeDialogComputationResultTest( arrayOf( "Function CONTAINS true", getFormula( - Pair(FUNCTION, CONTAINS.name), Pair(USER_LIST, userListLeftName), + Pair(FUNCTION, CONTAINS.name), Pair(USER_LIST, USER_LIST_LEFT_NAME), Pair(NUMBER, 3) ), null, null, listOf(1, 2, 3, 4, 5), null, @@ -840,79 +841,79 @@ class FormulaEditorComputeDialogComputationResultTest( arrayOf( arrayOf( "UserVariable Int", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), 123, null, null, null, "123" ), arrayOf( "UserVariable Int 1000", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), 1000, null, null, null, "1000" ), arrayOf( "UserVariable Int -1000000", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), -1_000_000, null, null, null, "-1000000" ), arrayOf( "UserVariable Double", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), 123.45, null, null, null, "123.45" ), arrayOf( "UserVariable String", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), "Hello", null, null, null, "Hello" ), arrayOf( "UserVariable Character", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), 'X', null, null, null, "X" ), arrayOf( "UserList Int", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(1, 2, 3), null, "123" ), arrayOf( "UserList Int 2000 3000000", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(1, 2_000, 3_000_000), null, "1 2000 3000000" ), arrayOf( "UserList Int -2000 -3000000", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(-1, -2_000, -3_000_000), null, "-1 -2000 -3000000" ), arrayOf( "UserList Double", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(1.1, 2.2, 3.3), null, "1.1 2.2 3.3" ), arrayOf( "UserList Character", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf('H', 'e', 'l', 'l', 'o'), null, "Hello" ), arrayOf( "UserList String", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf("Hello", "world", "!"), null, "Hello world !" ), arrayOf( "UserList Mixed", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf("Hello", '!', 123, 3.1415, true), null, "Hello ! 123 3.1415 $trueString" ) @@ -922,61 +923,61 @@ class FormulaEditorComputeDialogComputationResultTest( arrayOf( arrayOf( "Function UserVariable false", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), false, null, null, null, falseString ), arrayOf( "Function UserVariable true", - getFormula(Pair(USER_VARIABLE, userVariableLeftName)), + getFormula(Pair(USER_VARIABLE, USER_VARIABLE_LEFT_NAME)), true, null, null, null, trueString ), arrayOf( "UserList false", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(false), null, falseString ), arrayOf( "UserList true", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(true), null, trueString ), arrayOf( "UserList false false", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(false, false), null, "$falseString $falseString" ), arrayOf( "UserList false true", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(false, true), null, "$falseString $trueString" ), arrayOf( "UserList true false", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(true, false), null, "$trueString $falseString" ), arrayOf( "UserList true true", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(true, true), null, "$trueString $trueString" ), arrayOf( "UserList true false false", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(true, false, false), null, "$trueString $falseString $falseString" ), arrayOf( "UserList false true true", - getFormula(Pair(USER_LIST, userListLeftName)), + getFormula(Pair(USER_LIST, USER_LIST_LEFT_NAME)), null, null, listOf(false, true, true), null, "$falseString $trueString $trueString" ) @@ -986,7 +987,7 @@ class FormulaEditorComputeDialogComputationResultTest( arrayOf( arrayOf( "Collision false", - getFormula(Pair(COLLISION_FORMULA, collisionSpriteName)), + getFormula(Pair(COLLISION_FORMULA, COLLISION_SPRITE_NAME)), null, null, null, null, falseString ) diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/MergeLocalSpriteTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/MergeLocalSpriteTest.kt index 81948284516..a7b3902cc54 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/MergeLocalSpriteTest.kt +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/MergeLocalSpriteTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -54,14 +54,14 @@ import org.koin.java.KoinJavaComponent.inject class MergeLocalSpriteTest { lateinit var project: Project - lateinit var sameGlobalsProject: Project - lateinit var conflictProject: Project - var sameGlobalsName = "sameGlobals" - var defaultProjectName = "defaultProject" - var conflictProjectName = "conflictProject" + private lateinit var sameGlobalsProject: Project + private lateinit var conflictProject: Project + private var sameGlobalsName = "sameGlobals" + private var defaultProjectName = "defaultProject" + private var conflictProjectName = "conflictProject" val controller = SpriteController() - lateinit var originalSprite: Sprite - lateinit var originalSpriteCopy: Sprite + private lateinit var originalSprite: Sprite + private lateinit var originalSpriteCopy: Sprite private val projectManager = inject( ProjectManager::class.java ) @@ -209,12 +209,18 @@ class MergeLocalSpriteTest { val mergedSoundList = mergedSprite.soundList val mergedLookList = mergedSprite.lookList - Assert.assertEquals(sprite1.lookList.size + sprite2.lookList.size, - mergedLookList.size) - Assert.assertEquals(sprite1.scriptList.size + sprite2.scriptList.size, - mergedScriptList.size) - Assert.assertEquals(sprite1.soundList.size + sprite2.soundList.size, - mergedSoundList.size) + Assert.assertEquals( + sprite1.lookList.size + sprite2.lookList.size, + mergedLookList.size + ) + Assert.assertEquals( + sprite1.scriptList.size + sprite2.scriptList.size, + mergedScriptList.size + ) + Assert.assertEquals( + sprite1.soundList.size + sprite2.soundList.size, + mergedSoundList.size + ) } private fun assertOriginalIntact(originalSprite: Sprite, currentSprite: Sprite) { diff --git a/catroid/src/main/java/org/catrobat/catroid/TrustedDomainManager.kt b/catroid/src/main/java/org/catrobat/catroid/TrustedDomainManager.kt index 4792d60d528..9ec9ccac299 100644 --- a/catroid/src/main/java/org/catrobat/catroid/TrustedDomainManager.kt +++ b/catroid/src/main/java/org/catrobat/catroid/TrustedDomainManager.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -42,7 +42,7 @@ object TrustedDomainManager { private const val PARSE_ERROR_LOG = "Cannot parse trusted domains" private var trustListPattern: Pattern? = null - var userTrustListPattern: Pattern? = null + private var userTrustListPattern: Pattern? = null @Synchronized fun isURLTrusted(url: String): Boolean { @@ -93,7 +93,9 @@ object TrustedDomainManager { val domains = trustList.getJSONArray(TRUST_LIST_JSON_ARRAY_NAME) cleanUpUserInput(domains.join("\n")) } - } else "" + } else { + "" + } } catch (e: IOException) { Log.e(TAG, READ_ERROR_LOG, e) "" diff --git a/catroid/src/main/java/org/catrobat/catroid/content/EventWrapperListener.kt b/catroid/src/main/java/org/catrobat/catroid/content/EventWrapperListener.kt index ba2fdef2766..3fdedd81d31 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/EventWrapperListener.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/EventWrapperListener.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -34,7 +34,9 @@ class EventWrapperListener internal constructor(private val look: Look) : EventL if (event is EventWrapper) { handleEvent(event) true - } else false + } else { + false + } private fun handleEvent(event: EventWrapper) { with(look) { diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/ParameterizedAssertAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/ParameterizedAssertAction.kt index 14230f47f49..caffceeb07e 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/ParameterizedAssertAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/ParameterizedAssertAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -55,18 +55,21 @@ class ParameterizedAssertAction : AssertAction() { parameterizedData?.let { data -> if (!equalValues(actualValue, expectedValue.toString())) { data.failMessages.append("\n${data.currentParameters}\n").append( - formattedAssertEqualsError(actualValue, expectedValue)) + formattedAssertEqualsError(actualValue, expectedValue) + ) } else { data.successMessages.append("\n${data.currentParameters}\n").append( - formattedSuccessMessage(actualValue, expectedValue)) + formattedSuccessMessage(actualValue, expectedValue) + ) } data.currentPosition++ data.currentParameters = "" if (data.failMessages.isNotEmpty() && - data.currentPosition >= expectedList?.value?.size ?: 0) { - failWith("Failed Tests:\n${data.failMessages}\n\nSucceeded Tests:\n${data.successMessages}") + data.currentPosition >= (expectedList?.value?.size ?: 0) + ) { + failWith("Failed Tests:\n${data.failMessages}\n\nSucceeded Tests:\n${data.successMessages}") } } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/PlaySoundAtAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/PlaySoundAtAction.kt index 6be50b8833d..8ee5f7cbbb9 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/PlaySoundAtAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/PlaySoundAtAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -40,7 +40,7 @@ class PlaySoundAtAction : TemporalAction() { var scope: Scope? = null override fun update(percent: Float) { - var offsetMilliseconds: Int + val offsetMilliseconds: Int try { offsetMilliseconds = (offset.interpretFloat(scope) * SECONDS_TO_MILLISECONDS).toInt() } catch (exception: InterpretationException) { @@ -70,7 +70,7 @@ class PlaySoundAtAction : TemporalAction() { @VisibleForTesting fun runWithMockedSoundManager(manager: SoundManager): Float { - var offsetMilliseconds: Int + val offsetMilliseconds: Int try { offsetMilliseconds = (offset.interpretFloat(scope) * SECONDS_TO_MILLISECONDS).toInt() } catch (exception: InterpretationException) { @@ -81,9 +81,9 @@ class PlaySoundAtAction : TemporalAction() { if (sprite.soundList.contains(sound)) { sound?.let { - manager.playSoundFileWithStartTime( - it.file.absolutePath, sprite, offsetMilliseconds - ) + manager.playSoundFileWithStartTime( + it.file.absolutePath, sprite, offsetMilliseconds + ) } return manager.getDurationOfSoundFile(sound?.file?.absolutePath) - offsetMilliseconds } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/SetLookAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/SetLookAction.kt index a409321d520..34ac4533bba 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/SetLookAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/SetLookAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -35,6 +35,8 @@ open class SetLookAction : MultiSpriteEventAction() { return if (lookData != null && sprite?.lookList?.contains(lookData) == true) { sprite!!.look.lookData = lookData SetLookEventId(sprite, lookData) - } else null + } else { + null + } } } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/SetRelativeLookAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/SetRelativeLookAction.kt index 53e5cf06a22..b50d75b5685 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/SetRelativeLookAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/SetRelativeLookAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -37,7 +37,9 @@ abstract class SetRelativeLookAction : SetLookByIndexAction() { (look.lookListIndexBeforeLookRequest + change + lookList.size) % lookList.size } else if (currentLookData != null && lookList?.contains(currentLookData) == true) { (lookList.indexOf(currentLookData) + change + lookList.size) % lookList.size - } else 0 + } else { + 0 + } formula = Formula(newIndex + 1) look?.lookListIndexBeforeLookRequest = -1 return super.getEventId() diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/WebAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/WebAction.kt index b45b1a4789a..eae83dba826 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/WebAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/WebAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -58,7 +58,9 @@ abstract class WebAction : Action(), WebRequestListener { formula!!.interpretString(scope)!!.let { url = if (it.startsWith("http://") || it.startsWith("https://")) { it - } else "https://$it" + } else { + "https://$it" + } } val newlineIndex = url?.indexOf("\n") if (newlineIndex != -1) { @@ -134,7 +136,9 @@ abstract class WebAction : Action(), WebRequestListener { return if (stageListener.webConnectionHolder.addConnection(webConnection!!)) { webConnection!!.sendWebRequest() true - } else false + } else { + false + } } abstract fun handleResponse() diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteEmbroideryToFileAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteEmbroideryToFileAction.kt index 0aef7e2b57b..d607f41a048 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteEmbroideryToFileAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteEmbroideryToFileAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -100,7 +100,9 @@ class WriteEmbroideryToFileAction : Action(), IntentListener { val file = File(Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY, fileName) return if (file.exists() || file.createNewFile()) { file - } else null + } else { + null + } } @VisibleForTesting diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteVariableToFileAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteVariableToFileAction.kt index 0532b4518ac..5967d5f7444 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteVariableToFileAction.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/WriteVariableToFileAction.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -86,7 +86,9 @@ class WriteVariableToFileAction : Action(), IntentListener { val file = File(Constants.EXTERNAL_STORAGE_ROOT_EXPORT_DIRECTORY, fileName) return if (file.exists() || file.createNewFile()) { file - } else null + } else { + null + } } @VisibleForTesting diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/BackgroundRequestBrick.kt b/catroid/src/main/java/org/catrobat/catroid/content/bricks/BackgroundRequestBrick.kt index 546401f78a8..1df63ed04fb 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/BackgroundRequestBrick.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/BackgroundRequestBrick.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ import org.catrobat.catroid.content.bricks.Brick.BrickField import org.catrobat.catroid.content.bricks.Brick.ResourcesSet import org.catrobat.catroid.formulaeditor.Formula -class BackgroundRequestBrick constructor() : FormulaBrick() { +class BackgroundRequestBrick() : FormulaBrick() { constructor(value: String) : this(Formula(value)) constructor(formula: Formula) : this() { @@ -44,7 +44,8 @@ class BackgroundRequestBrick constructor() : FormulaBrick() { override fun getViewResource(): Int = R.layout.brick_background_request override fun addActionToSequence(sprite: Sprite, sequence: ScriptSequenceAction) { - sequence.addAction(sprite.actionFactory.createLookRequestAction( + sequence.addAction( + sprite.actionFactory.createLookRequestAction( ProjectManager.getInstance().currentlyPlayingScene.backgroundSprite, sequence, getFormulaWithBrickField(BrickField.BACKGROUND_REQUEST) ) diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/LookRequestBrick.kt b/catroid/src/main/java/org/catrobat/catroid/content/bricks/LookRequestBrick.kt index 16adac9d041..e85c5331e54 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/LookRequestBrick.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/LookRequestBrick.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -29,7 +29,7 @@ import org.catrobat.catroid.content.bricks.Brick.BrickField import org.catrobat.catroid.content.bricks.Brick.ResourcesSet import org.catrobat.catroid.formulaeditor.Formula -class LookRequestBrick constructor() : FormulaBrick() { +class LookRequestBrick() : FormulaBrick() { constructor(value: String) : this(Formula(value)) constructor(formula: Formula) : this() { @@ -43,7 +43,8 @@ class LookRequestBrick constructor() : FormulaBrick() { override fun getViewResource(): Int = R.layout.brick_look_request override fun addActionToSequence(sprite: Sprite, sequence: ScriptSequenceAction) { - sequence.addAction(sprite.actionFactory.createLookRequestAction( + sequence.addAction( + sprite.actionFactory.createLookRequestAction( sprite, sequence, getFormulaWithBrickField(BrickField.LOOK_REQUEST) ) diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetCameraFocusPointBrick.kt b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetCameraFocusPointBrick.kt index d43ab1ba839..a67350894ed 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetCameraFocusPointBrick.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetCameraFocusPointBrick.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -36,12 +36,12 @@ class SetCameraFocusPointBrick : FormulaBrick() { init { addAllowedBrickField( - BrickField.HORIZONTAL_FLEXIBILITY, - R.id.brick_set_camera_focus_horizontal_input + BrickField.HORIZONTAL_FLEXIBILITY, + R.id.brick_set_camera_focus_horizontal_input ) addAllowedBrickField( - BrickField.VERTICAL_FLEXIBILITY, - R.id.brick_set_camera_focus_vertical_input + BrickField.VERTICAL_FLEXIBILITY, + R.id.brick_set_camera_focus_vertical_input ) } @@ -51,11 +51,11 @@ class SetCameraFocusPointBrick : FormulaBrick() { override fun addActionToSequence(sprite: Sprite, sequence: ScriptSequenceAction) { sequence.addAction( - sprite.actionFactory.createSetCameraFocusPointAction( - sprite, sequence, - getFormulaWithBrickField(BrickField.HORIZONTAL_FLEXIBILITY), - getFormulaWithBrickField(BrickField.VERTICAL_FLEXIBILITY) - ) + sprite.actionFactory.createSetCameraFocusPointAction( + sprite, sequence, + getFormulaWithBrickField(BrickField.HORIZONTAL_FLEXIBILITY), + getFormulaWithBrickField(BrickField.VERTICAL_FLEXIBILITY) + ) ) } } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/WebRequestBrick.kt b/catroid/src/main/java/org/catrobat/catroid/content/bricks/WebRequestBrick.kt index 691b4146ad5..3f3fc923e93 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/WebRequestBrick.kt +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/WebRequestBrick.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -43,7 +43,8 @@ class WebRequestBrick() : UserVariableBrickWithFormula() { override fun getViewResource(): Int = R.layout.brick_web_request override fun addActionToSequence(sprite: Sprite, sequence: ScriptSequenceAction) { - sequence.addAction(sprite.actionFactory.createWebRequestAction( + sequence.addAction( + sprite.actionFactory.createWebRequestAction( sprite, sequence, getFormulaWithBrickField(BrickField.WEB_REQUEST), userVariable ) diff --git a/catroid/src/main/java/org/catrobat/catroid/merge/ImportProjectHelper.kt b/catroid/src/main/java/org/catrobat/catroid/merge/ImportProjectHelper.kt index 96fb5baf2a4..eac96ee87d2 100644 --- a/catroid/src/main/java/org/catrobat/catroid/merge/ImportProjectHelper.kt +++ b/catroid/src/main/java/org/catrobat/catroid/merge/ImportProjectHelper.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -85,14 +85,16 @@ class ImportProjectHelper( } addGlobalsToProject(newProject!!.userLists, currentScene!!.project.userLists) addGlobalsToProject(newProject!!.userVariables, currentScene!!.project.userVariables) - addGlobalsToProject(newProject!!.broadcastMessageContainer.broadcastMessages, - currentScene!!.project.broadcastMessageContainer.broadcastMessages) + addGlobalsToProject( + newProject!!.broadcastMessageContainer.broadcastMessages, + currentScene!!.project.broadcastMessageContainer.broadcastMessages + ) currentScene?.project?.broadcastMessageContainer?.update() return newSprite } - fun addGlobalsToProject(globalList: List, globalsToAdd: List) { + private fun addGlobalsToProject(globalList: List, globalsToAdd: List) { for (global in globalsToAdd) { if (!globalList.contains(global)) { globalList.plus(global) @@ -141,7 +143,7 @@ class ImportProjectHelper( return true } - fun getProject(resolvedName: String): Project? { + private fun getProject(resolvedName: String): Project? { val projectDir = File(DEFAULT_ROOT_DIRECTORY, resolvedName) return if (projectDir.exists() && projectDir.isDirectory) { XstreamSerializer.getInstance() @@ -151,7 +153,7 @@ class ImportProjectHelper( } } - fun getNewProject(resolvedName: String): Project? { + private fun getNewProject(resolvedName: String): Project? { try { val cachedProjectDir = File(Constants.MEDIA_LIBRARY_CACHE_DIRECTORY, resolvedName) diff --git a/catroid/src/main/java/org/catrobat/catroid/physics/content/ActionPhysicsFactory.kt b/catroid/src/main/java/org/catrobat/catroid/physics/content/ActionPhysicsFactory.kt index adb443780f6..29615586106 100644 --- a/catroid/src/main/java/org/catrobat/catroid/physics/content/ActionPhysicsFactory.kt +++ b/catroid/src/main/java/org/catrobat/catroid/physics/content/ActionPhysicsFactory.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -57,7 +57,13 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createGlideToAction(sprite: Sprite, sequence: SequenceAction, x: Formula?, y: Formula?, duration: Formula?): Action { + override fun createGlideToAction( + sprite: Sprite, + sequence: SequenceAction, + x: Formula?, + y: Formula?, + duration: Formula? + ): Action { val action = Actions.action(GlideToPhysicsAction::class.java) action.setPosition(x, y) action.setDuration(duration) @@ -67,7 +73,11 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createSetBounceFactorAction(sprite: Sprite, sequence: SequenceAction, bounceFactor: Formula?): Action { + override fun createSetBounceFactorAction( + sprite: Sprite, + sequence: SequenceAction, + bounceFactor: Formula? + ): Action { val action = Actions.action(SetBounceFactorAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) @@ -76,7 +86,11 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createSetFrictionAction(sprite: Sprite, sequence: SequenceAction, friction: Formula?): Action { + override fun createSetFrictionAction( + sprite: Sprite, + sequence: SequenceAction, + friction: Formula? + ): Action { val action = Actions.action(SetFrictionAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) @@ -85,7 +99,12 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createSetGravityAction(sprite: Sprite, sequence: SequenceAction, gravityX: Formula?, gravityY: Formula?): Action { + override fun createSetGravityAction( + sprite: Sprite, + sequence: SequenceAction, + gravityX: Formula?, + gravityY: Formula? + ): Action { val action = Actions.action(SetGravityAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) @@ -94,7 +113,11 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createSetMassAction(sprite: Sprite, sequence: SequenceAction, mass: Formula?): Action { + override fun createSetMassAction( + sprite: Sprite, + sequence: SequenceAction, + mass: Formula? + ): Action { val action = Actions.action(SetMassAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) @@ -103,14 +126,22 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createSetPhysicsObjectTypeAction(sprite: Sprite, type: PhysicsObject.Type): Action { + override fun createSetPhysicsObjectTypeAction( + sprite: Sprite, + type: PhysicsObject.Type + ): Action { val action = Actions.action(SetPhysicsObjectTypeAction::class.java) action.setPhysicsObject(getPhysicsObject(sprite)) action.setType(type) return action } - override fun createSetVelocityAction(sprite: Sprite, sequence: SequenceAction, velocityX: Formula?, velocityY: Formula?): Action { + override fun createSetVelocityAction( + sprite: Sprite, + sequence: SequenceAction, + velocityX: Formula?, + velocityY: Formula? + ): Action { val action = Actions.action(SetVelocityAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) @@ -119,7 +150,11 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createTurnLeftSpeedAction(sprite: Sprite, sequence: SequenceAction, speed: Formula?): Action { + override fun createTurnLeftSpeedAction( + sprite: Sprite, + sequence: SequenceAction, + speed: Formula? + ): Action { val action = Actions.action(TurnLeftSpeedAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) @@ -128,7 +163,11 @@ class ActionPhysicsFactory : ActionFactory() { return action } - override fun createTurnRightSpeedAction(sprite: Sprite, sequence: SequenceAction, speed: Formula?): Action { + override fun createTurnRightSpeedAction( + sprite: Sprite, + sequence: SequenceAction, + speed: Formula? + ): Action { val action = Actions.action(TurnRightSpeedAction::class.java) val scope = Scope(ProjectManager.getInstance().currentProject, sprite, sequence) action.setScope(scope) diff --git a/catroid/src/main/java/org/catrobat/catroid/stage/TextToSpeechHolder.kt b/catroid/src/main/java/org/catrobat/catroid/stage/TextToSpeechHolder.kt index cd4b10ef207..929b1fb049d 100644 --- a/catroid/src/main/java/org/catrobat/catroid/stage/TextToSpeechHolder.kt +++ b/catroid/src/main/java/org/catrobat/catroid/stage/TextToSpeechHolder.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -39,38 +39,52 @@ class TextToSpeechHolder private constructor() { fun initTextToSpeech(stageActivity: StageActivity, stageResourceHolder: StageResourceHolder) { textToSpeech = TextToSpeech(stageActivity, OnInitListener { status -> - if (status == TextToSpeech.SUCCESS) { - utteranceProgressListenerContainer = UtteranceProgressListenerContainer() - textToSpeech?.setOnUtteranceProgressListener(utteranceProgressListenerContainer) - stageResourceHolder.resourceInitialized() - } else { - val builder = AlertDialog.Builder(ContextThemeWrapper(stageActivity, R.style.Theme_AppCompat_Dialog)) - builder.setMessage(R.string.prestage_text_to_speech_engine_not_installed) - .setCancelable(false) - .setPositiveButton(R.string.yes) { _, _ -> - val installIntent = Intent() - installIntent.action = TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA - stageActivity.startActivity(installIntent) - stageResourceHolder.resourceFailed(Brick.TEXT_TO_SPEECH) - } - .setNegativeButton(R.string.no) { _, _ -> - stageResourceHolder.resourceFailed(Brick.TEXT_TO_SPEECH) - } - val alert = builder.create() - alert.show() - } - }) + if (status == TextToSpeech.SUCCESS) { + utteranceProgressListenerContainer = UtteranceProgressListenerContainer() + textToSpeech?.setOnUtteranceProgressListener(utteranceProgressListenerContainer) + stageResourceHolder.resourceInitialized() + } else { + val builder = AlertDialog.Builder( + ContextThemeWrapper( + stageActivity, + R.style.Theme_AppCompat_Dialog + ) + ) + builder.setMessage(R.string.prestage_text_to_speech_engine_not_installed) + .setCancelable(false) + .setPositiveButton(R.string.yes) { _, _ -> + val installIntent = Intent() + installIntent.action = TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA + stageActivity.startActivity(installIntent) + stageResourceHolder.resourceFailed(Brick.TEXT_TO_SPEECH) + } + .setNegativeButton(R.string.no) { _, _ -> + stageResourceHolder.resourceFailed(Brick.TEXT_TO_SPEECH) + } + val alert = builder.create() + alert.show() + } + }) } fun shutDownTextToSpeech() { - textToSpeech?.stop() - textToSpeech?.shutdown() + textToSpeech?.stop() + textToSpeech?.shutdown() } - fun textToSpeech(text: String?, speechFile: File, listener: UtteranceProgressListener, speakParameter: HashMap) { - if (utteranceProgressListenerContainer?.addUtteranceProgressListener(speechFile, listener, - speakParameter[TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID]) == true) { - val status = textToSpeech?.synthesizeToFile(text ?: "", speakParameter, speechFile.absolutePath) + fun textToSpeech( + text: String?, + speechFile: File, + listener: UtteranceProgressListener, + speakParameter: HashMap + ) { + if (utteranceProgressListenerContainer?.addUtteranceProgressListener( + speechFile, listener, + speakParameter[TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID] + ) == true + ) { + val status = + textToSpeech?.synthesizeToFile(text ?: "", speakParameter, speechFile.absolutePath) if (status == TextToSpeech.ERROR) { Log.e(TAG, "File synthesizing failed") } @@ -90,6 +104,7 @@ class TextToSpeechHolder private constructor() { private val TAG = TextToSpeechHolder::class.java.simpleName private var textToSpeech: TextToSpeech? = null private var utteranceProgressListenerContainer: UtteranceProgressListenerContainer? = null + @JvmStatic var instance = TextToSpeechHolder() } diff --git a/catroid/src/main/java/org/catrobat/catroid/stage/UtteranceProgressListenerContainer.kt b/catroid/src/main/java/org/catrobat/catroid/stage/UtteranceProgressListenerContainer.kt index 85fb9657890..8c547ca17e5 100644 --- a/catroid/src/main/java/org/catrobat/catroid/stage/UtteranceProgressListenerContainer.kt +++ b/catroid/src/main/java/org/catrobat/catroid/stage/UtteranceProgressListenerContainer.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -31,7 +31,11 @@ class UtteranceProgressListenerContainer : UtteranceProgressListener() { private val listeners: MutableMap?> = HashMap() @Synchronized - fun addUtteranceProgressListener(speechFile: File, utteranceProgressListener: UtteranceProgressListener, utteranceId: String?): Boolean { + fun addUtteranceProgressListener( + speechFile: File, + utteranceProgressListener: UtteranceProgressListener, + utteranceId: String? + ): Boolean { val utteranceIdListeners = listeners[utteranceId] return if (utteranceIdListeners == null) { if (speechFile.exists()) { diff --git a/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectDownloadService.kt b/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectDownloadService.kt index b42f0d3aa77..3568abd35f6 100644 --- a/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectDownloadService.kt +++ b/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectDownloadService.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -80,10 +80,12 @@ class ProjectDownloadService : IntentService("ProjectDownloadService") { ?: return logWarning("Called ProjectDownloadService with null projectName - aborting") val url = downloadIntent.getStringExtra(EXTRA_URL) ?: return logWarning("Called ProjectDownloadService without url - aborting") - val resultReceiver = downloadIntent.getParcelableExtra(EXTRA_RESULT_RECEIVER) + val resultReceiver = + downloadIntent.getParcelableExtra(EXTRA_RESULT_RECEIVER) ?: return logWarning("Called ProjectDownloadService without url - aborting") - val zipFileString = File(File(CACHE_DIRECTORY, TMP_DIRECTORY_NAME), DOWNLOAD_FILE_NAME).absolutePath + val zipFileString = + File(File(CACHE_DIRECTORY, TMP_DIRECTORY_NAME), DOWNLOAD_FILE_NAME).absolutePath val destinationFile = File(zipFileString) if ((destinationFile.parentFile.isDirectory or destinationFile.parentFile.mkdirs()).not()) { @@ -91,7 +93,8 @@ class ProjectDownloadService : IntentService("ProjectDownloadService") { return } - val notificationData = downloadIntent.getSerializableExtra(EXTRA_NOTIFICATION_DATA) as NotificationData + val notificationData = + downloadIntent.getSerializableExtra(EXTRA_NOTIFICATION_DATA) as NotificationData val notification = notificationData.toNotification(this, CHANNEL_ID, null) val id = notificationData.notificationID @@ -113,12 +116,21 @@ class ProjectDownloadService : IntentService("ProjectDownloadService") { }, object : DownloadErrorCallback { override fun onError(code: Int, message: String) { - downloadErrorCallback(this@ProjectDownloadService, resultReceiver, projectName) + downloadErrorCallback( + this@ProjectDownloadService, + resultReceiver, + projectName + ) } }, object : DownloadProgressCallback { override fun onProgress(progress: Long) { - downloadProgressCallback(this@ProjectDownloadService, resultReceiver, notificationData, progress) + downloadProgressCallback( + this@ProjectDownloadService, + resultReceiver, + notificationData, + progress + ) } } ) diff --git a/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUpload.kt b/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUpload.kt index ba60b2d060b..cdcb8346b97 100644 --- a/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUpload.kt +++ b/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUpload.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -41,6 +41,7 @@ import java.util.Locale typealias UploadProjectSuccessCallback = (projectId: String) -> Unit typealias UploadProjectErrorCallback = (errorCode: Int, errorMessage: String) -> Unit +@Suppress("LongParameterList") class ProjectUpload( private val projectDirectory: File, private val projectName: String, diff --git a/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUploadService.kt b/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUploadService.kt index 30896329458..01da5c3cd64 100644 --- a/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUploadService.kt +++ b/catroid/src/main/java/org/catrobat/catroid/transfers/project/ProjectUploadService.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -195,7 +195,6 @@ class ProjectUploadService : IntentService("ProjectUploadService") { ) } - return NotificationCompat.Builder(applicationContext, StatusBarNotificationManager.CHANNEL_ID) .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_stat) diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/ProjectUploadActivity.kt b/catroid/src/main/java/org/catrobat/catroid/ui/ProjectUploadActivity.kt index ceb8f3b2302..d50d0b6943b 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/ProjectUploadActivity.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/ProjectUploadActivity.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -652,7 +652,9 @@ open class ProjectUploadActivity : BaseActivity(), .contains(name) ) { getString(R.string.name_already_exists) - } else null + } else { + null + } } override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/ScriptFinder.kt b/catroid/src/main/java/org/catrobat/catroid/ui/ScriptFinder.kt index db4e506c30f..7af44d55364 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/ScriptFinder.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/ScriptFinder.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -116,7 +116,7 @@ class ScriptFinder(context: Context, attrs: AttributeSet?) : LinearLayout(contex companion object { val TAG = ScriptFinder::class.java.simpleName - @Suppress("ComplexMethod", "TooGenericExceptionCaught") + @Suppress("ComplexMethod", "TooGenericExceptionCaught", "NestedBlockDepth") fun searchBrickViews(v: View?, searchQuery: String): Boolean { try { if (v is Spinner) { diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/AddBrickFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/AddBrickFragment.kt index e942faa929a..28a72d0d8eb 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/AddBrickFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/AddBrickFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -51,13 +51,21 @@ class AddBrickFragment : ListFragment() { private var addBrickListener: OnAddBrickListener? = null private var previousActionBarTitle: CharSequence? = null private var adapter: PrototypeBrickAdapter? = null - private fun onlyBeginnerBricks(): Boolean = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(AccessibilityProfile.BEGINNER_BRICKS, false) + private fun onlyBeginnerBricks(): Boolean = + PreferenceManager.getDefaultSharedPreferences(activity) + .getBoolean(AccessibilityProfile.BEGINNER_BRICKS, false) + private val projectManager: ProjectManager by inject(ProjectManager::class.java) - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { val view = inflater.inflate(R.layout.fragment_brick_add, container, false) previousActionBarTitle = (activity as? AppCompatActivity)?.supportActionBar?.title - (activity as? AppCompatActivity)?.supportActionBar?.title = arguments?.getString(BUNDLE_ARGUMENTS_SELECTED_CATEGORY) + (activity as? AppCompatActivity)?.supportActionBar?.title = + arguments?.getString(BUNDLE_ARGUMENTS_SELECTED_CATEGORY) setupSelectedBrickCategory() return view } @@ -71,11 +79,14 @@ class AddBrickFragment : ListFragment() { onlyBeginnerBricks() -> CategoryBeginnerBricksFactory() else -> CategoryBricksFactory() } - val brickList = selectedCategory?.let { context?.let { it1 -> - categoryBricksFactory.getBricks(it, backgroundSprite == sprite, - it1 - ) - } } + val brickList = selectedCategory?.let { + context?.let { it1 -> + categoryBricksFactory.getBricks( + it, backgroundSprite == sprite, + it1 + ) + } + } adapter = brickList?.let { PrototypeBrickAdapter(it) } listAdapter = adapter } @@ -111,13 +122,18 @@ class AddBrickFragment : ListFragment() { listView.setSelection(listIndexToFocus) listIndexToFocus = -1 } - listView.onItemClickListener = AdapterView.OnItemClickListener { parent: AdapterView<*>?, view: View?, position: Int, id: Long -> adapter?.getItem(position)?.let { addBrickToScript( - it, - activity as SpriteActivity, - addBrickListener, - parentFragmentManager, - ADD_BRICK_FRAGMENT_TAG) } - } + listView.onItemClickListener = + AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, position: Int, _: Long -> + adapter?.getItem(position)?.let { + addBrickToScript( + it, + activity as SpriteActivity, + addBrickListener, + parentFragmentManager, + ADD_BRICK_FRAGMENT_TAG + ) + } + } } interface OnAddBrickListener { @@ -129,8 +145,12 @@ class AddBrickFragment : ListFragment() { val ADD_BRICK_FRAGMENT_TAG = AddBrickFragment::class.java.simpleName private const val BUNDLE_ARGUMENTS_SELECTED_CATEGORY = "selected_category" private var listIndexToFocus = -1 + @JvmStatic - fun newInstance(selectedCategory: String?, addBrickListener: OnAddBrickListener?): AddBrickFragment { + fun newInstance( + selectedCategory: String?, + addBrickListener: OnAddBrickListener? + ): AddBrickFragment { val fragment = AddBrickFragment() val arguments = Bundle() arguments.putString(BUNDLE_ARGUMENTS_SELECTED_CATEGORY, selectedCategory) @@ -142,13 +162,25 @@ class AddBrickFragment : ListFragment() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == R.id.search) { - (addBrickListener as BrickCategoryFragment.OnCategorySelectedListener).onCategorySelected(arguments?.getString(BUNDLE_ARGUMENTS_SELECTED_CATEGORY)) + (addBrickListener as BrickCategoryFragment.OnCategorySelectedListener).onCategorySelected( + arguments?.getString(BUNDLE_ARGUMENTS_SELECTED_CATEGORY) + ) } return super.onOptionsItemSelected(item) } } -fun addBrickToScript(brick: Brick, activity: SpriteActivity, addBrickListener: AddBrickFragment.OnAddBrickListener?, parentFragmentManager: FragmentManager, tag: String) { - if (ProjectManager.getInstance().currentProject.isCastProject && CastManager.unsupportedBricks.contains(brick.javaClass)) { + +fun addBrickToScript( + brick: Brick, + activity: SpriteActivity, + addBrickListener: AddBrickFragment.OnAddBrickListener?, + parentFragmentManager: FragmentManager, + tag: String +) { + if (ProjectManager.getInstance().currentProject.isCastProject && CastManager.unsupportedBricks.contains( + brick.javaClass + ) + ) { ToastUtil.showError(activity, R.string.error_unsupported_bricks_chromecast) return } @@ -157,7 +189,8 @@ fun addBrickToScript(brick: Brick, activity: SpriteActivity, addBrickListener: A addBrickListener?.addBrick(brickToAdd) SnackbarUtil.showHintSnackbar(activity, R.string.hint_scripts) val fragmentTransaction = parentFragmentManager.beginTransaction() - val categoryFragment = parentFragmentManager.findFragmentByTag(BrickCategoryFragment.BRICK_CATEGORY_FRAGMENT_TAG) + val categoryFragment = + parentFragmentManager.findFragmentByTag(BrickCategoryFragment.BRICK_CATEGORY_FRAGMENT_TAG) if (categoryFragment != null) { fragmentTransaction.remove(categoryFragment) parentFragmentManager.popBackStack() diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/BrickSearchFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/BrickSearchFragment.kt index 0f341d4ded6..889ea376d60 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/BrickSearchFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/BrickSearchFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -124,7 +124,7 @@ class BrickSearchFragment : ListFragment() { view: AbsListView, scrollState: Int ) { - searchView.hideKeyboard() + searchView.hideKeyboard() } @SuppressWarnings("EmptyFunctionBlock") @@ -133,45 +133,46 @@ class BrickSearchFragment : ListFragment() { firstVisibleItem: Int, visibleItemCount: Int, totalItemCount: Int - ) {} + ) { + } }) searchView = searchItem if (searchView != null) { - var countDownTimer: CountDownTimer - adapter = PrototypeBrickAdapter(searchResults) - listAdapter = adapter - queryTextListener = object : SearchView.OnQueryTextListener { - override fun onQueryTextChange(query: String): Boolean { - previousQuery = query - recentlyUsedTitle?.setVisibleOrGone(query.isEmpty()) - countDownTimer = object : CountDownTimer( - PROGESSIVE_INPUT_DELAY, - PROGESSIVE_INPUT_COUNTDOWN_INTERVALL - ) { - @SuppressWarnings("EmptyFunctionBlock") - override fun onTick(millisUntilFinished: Long) { - } + var countDownTimer: CountDownTimer + adapter = PrototypeBrickAdapter(searchResults) + listAdapter = adapter + queryTextListener = object : SearchView.OnQueryTextListener { + override fun onQueryTextChange(query: String): Boolean { + previousQuery = query + recentlyUsedTitle?.setVisibleOrGone(query.isEmpty()) + countDownTimer = object : CountDownTimer( + PROGESSIVE_INPUT_DELAY, + PROGESSIVE_INPUT_COUNTDOWN_INTERVALL + ) { + @SuppressWarnings("EmptyFunctionBlock") + override fun onTick(millisUntilFinished: Long) { + } - override fun onFinish() { - when (query) { - previousQuery -> searchAndFillBrickList(query) - } + override fun onFinish() { + when (query) { + previousQuery -> searchAndFillBrickList(query) } } - emptyQuery = query.isEmpty() - if (query.isEmpty()) { - searchResults.clear() - searchResults.addAll(recentlyUsedBricks) - adapter?.replaceList(searchResults) - countDownTimer.cancel() - setShowProgressBar(false) - } else { - countDownTimer.start() - setShowProgressBar(true) - } - return true } + emptyQuery = query.isEmpty() + if (query.isEmpty()) { + searchResults.clear() + searchResults.addAll(recentlyUsedBricks) + adapter?.replaceList(searchResults) + countDownTimer.cancel() + setShowProgressBar(false) + } else { + countDownTimer.start() + setShowProgressBar(true) + } + return true + } override fun onQueryTextSubmit(query: String): Boolean { searchResults.clear() @@ -186,9 +187,7 @@ class BrickSearchFragment : ListFragment() { } } suggestionListener = object : SearchView.OnSuggestionListener { - override fun onSuggestionSelect(position: Int): Boolean { - return false - } + override fun onSuggestionSelect(position: Int): Boolean = false override fun onSuggestionClick(position: Int): Boolean { val cursor: Cursor? = searchView?.suggestionsAdapter?.cursor @@ -206,11 +205,11 @@ class BrickSearchFragment : ListFragment() { } private fun setShowProgressBar(visible: Boolean) { - if (visible) { - view?.findViewById(R.id.progress_bar)?.visibility = View.VISIBLE - } else { - view?.findViewById(R.id.progress_bar)?.visibility = View.INVISIBLE - } + if (visible) { + view?.findViewById(R.id.progress_bar)?.visibility = View.VISIBLE + } else { + view?.findViewById(R.id.progress_bar)?.visibility = View.INVISIBLE + } } override fun onPrepareOptionsMenu(menu: Menu) { @@ -267,11 +266,14 @@ class BrickSearchFragment : ListFragment() { for (i in 0 until view.childCount) { val child = view.getChildAt(i) val stringFoundInBrick = findBrickString(child) - if (stringFoundInBrick.isNotBlank()) wholeStringFoundInBrick = wholeStringFoundInBrick.plus(stringFoundInBrick) + if (stringFoundInBrick.isNotBlank()) { + wholeStringFoundInBrick = + wholeStringFoundInBrick.plus(stringFoundInBrick) + } } } else if (view is TextView) return view.text.toString().toLowerCase(Locale.ROOT) return wholeStringFoundInBrick - } + } fun getRecentlyUsedBricks() { val categoryBricksFactory: CategoryBricksFactory = when { diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.kt b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.kt index 7a2a307e064..10affb9d12c 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/CategoryBricksFactory.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -270,7 +270,7 @@ open class CategoryBricksFactory { } } - fun setupRecentBricksCategoryList(isBackgroundSprite: Boolean): List = RecentBrickListManager.getInstance().getRecentBricks(isBackgroundSprite) + private fun setupRecentBricksCategoryList(isBackgroundSprite: Boolean): List = RecentBrickListManager.getInstance().getRecentBricks(isBackgroundSprite) protected open fun setupEventCategoryList( context: Context, @@ -491,9 +491,11 @@ open class CategoryBricksFactory { ProjectManager.getInstance().currentProject.xmlHeader.islandscapeMode() -> looksBrickList.add(BackgroundRequestBrick(BrickValues.BACKGROUND_REQUEST_LANDSCAPE)) else -> looksBrickList.add(BackgroundRequestBrick(BrickValues.BACKGROUND_REQUEST)) } - if (SettingsFragment.isPhiroSharedPreferenceEnabled(context)) looksBrickList.add( - PhiroRGBLightBrick(PhiroRGBLightBrick.Eye.BOTH, BrickValues.PHIRO_VALUE_RED, BrickValues.PHIRO_VALUE_GREEN, BrickValues.PHIRO_VALUE_BLUE) - ) + if (SettingsFragment.isPhiroSharedPreferenceEnabled(context)) { + looksBrickList.add( + PhiroRGBLightBrick(PhiroRGBLightBrick.Eye.BOTH, BrickValues.PHIRO_VALUE_RED, BrickValues.PHIRO_VALUE_GREEN, BrickValues.PHIRO_VALUE_BLUE) + ) + } looksBrickList.add(PaintNewLookBrick(context.getString(R.string.brick_paint_new_look_name))) looksBrickList.add(EditLookBrick()) looksBrickList.add(CopyLookBrick(context.getString(R.string.brick_copy_look_name))) @@ -728,7 +730,7 @@ open class CategoryBricksFactory { return assertionsBrickList } - fun searchList(searchBrick: Brick, list: List): Boolean = list.any { it == searchBrick.javaClass } + private fun searchList(searchBrick: Brick, list: List): Boolean = list.any { it == searchBrick.javaClass } fun getBrickCategory(brick: Brick, isBackgroundSprite: Boolean, context: Context): String { val res = context.resources diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectDetailsFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectDetailsFragment.kt index 272229dd772..f6d7ddc5210 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectDetailsFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/ProjectDetailsFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -200,7 +200,9 @@ class ProjectDetailsFragment : Fragment() { val userHandle = project.xmlHeader.userHandle return if (userHandle == null || userHandle == "") { getString(R.string.unknown) - } else userHandle + } else { + userHandle + } } private val remixOf: String @@ -208,10 +210,12 @@ class ProjectDetailsFragment : Fragment() { val remixOf = project.xmlHeader.remixParentsUrlString return if (remixOf == null || remixOf == "") { getString(R.string.nxt_no_sensor) - } else remixOf + } else { + remixOf + } } - fun setDescription(description: String?) { + private fun setDescription(description: String?) { project.description = description if (XstreamSerializer.getInstance().saveProject(project)) { binding.descriptionValue.text = description diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/AutoScrollableRecyclerView.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/AutoScrollableRecyclerView.kt index 1c1326ac85b..930c9b282f3 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/AutoScrollableRecyclerView.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/AutoScrollableRecyclerView.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -55,22 +55,20 @@ class AutoScrollableRecyclerView @JvmOverloads constructor( 0 ) .apply { - try { - delayMillis = getInt( - R.styleable.AutoScrollableRecyclerView_delay, - DELAY_BETWEEN_SCROLLS - ) - .toLong() - } finally { - recycle() + try { + delayMillis = getInt( + R.styleable.AutoScrollableRecyclerView_delay, + DELAY_BETWEEN_SCROLLS + ) + .toLong() + } finally { + recycle() + } } - } } private fun createScroller(position: Int) = object : LinearSmoothScroller(context) { - override fun getHorizontalSnapPreference(): Int { - return SNAP_TO_END - } + override fun getHorizontalSnapPreference(): Int = SNAP_TO_END override fun calculateTimeForScrolling(dx: Int) = DURATION_OF_SCROLL }.apply { @@ -112,7 +110,7 @@ class AutoScrollableRecyclerView @JvmOverloads constructor( private class ScrollHandler(autoScrollableRecyclerView: AutoScrollableRecyclerView) : Handler() { private val autoScrollViewPager = - WeakReference(autoScrollableRecyclerView) + WeakReference(autoScrollableRecyclerView) override fun handleMessage(msg: Message) { super.handleMessage(msg) diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/IndicatorDecoration.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/IndicatorDecoration.kt index 37829638273..91ad93dca5d 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/IndicatorDecoration.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/IndicatorDecoration.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -79,50 +79,51 @@ class IndicatorDecoration(context: Context) : RecyclerView.ItemDecoration() { (parent.layoutManager as? LinearLayoutManager) ?.let { layoutManager -> - val firstItemPosition = layoutManager.findFirstVisibleItemPosition() - val actualItemPosition = firstItemPosition % itemCount - - layoutManager.findViewByPosition(firstItemPosition) - ?.let { firstView -> - val totalWidth = margin * (itemCount - 1) - val startX = (parent.width - totalWidth) / 2 - val y = parent.height - margin - - val left = firstView.left - val width = firstView.width - val progress = interpolator.getInterpolation(-1 * left / width.toFloat()) - - for (i in 0 until itemCount) { - var radius = unselectedRadius - - when (i) { - actualItemPosition -> { - radius += diffRadius * (1 - progress) - paint.color = evaluator.evaluate( - 1 - progress, - unselectedColor, - selectedColor - ) as Int + val firstItemPosition = layoutManager.findFirstVisibleItemPosition() + val actualItemPosition = firstItemPosition % itemCount + + layoutManager.findViewByPosition(firstItemPosition) + ?.let { firstView -> + val totalWidth = margin * (itemCount - 1) + val startX = (parent.width - totalWidth) / 2 + val y = parent.height - margin + + val left = firstView.left + val width = firstView.width + val progress = + interpolator.getInterpolation(-1 * left / width.toFloat()) + + for (i in 0 until itemCount) { + var radius = unselectedRadius + + when (i) { + actualItemPosition -> { + radius += diffRadius * (1 - progress) + paint.color = evaluator.evaluate( + 1 - progress, + unselectedColor, + selectedColor + ) as Int + } + + actualItemPosition + 1 -> { + radius += diffRadius * progress + paint.color = + evaluator.evaluate( + progress, + unselectedColor, + selectedColor + ) as Int + } + + else -> + paint.color = unselectedColor + } + + canvas.drawCircle(startX + i * margin, y, radius, paint) } - - actualItemPosition + 1 -> { - radius += diffRadius * progress - paint.color = - evaluator.evaluate( - progress, - unselectedColor, - selectedColor - ) as Int - } - - else -> - paint.color = unselectedColor } - - canvas.drawCircle(startX + i * margin, y, radius, paint) - } } - } } } } diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/SoundAdapter.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/SoundAdapter.kt index be7a6c57e52..077409fb626 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/SoundAdapter.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/SoundAdapter.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -91,7 +91,8 @@ class SoundAdapter(items: List?) : ExtendedRVAdapter(ite val metadataRetriever = MediaMetadataRetriever() metadataRetriever.setDataSource(sound.file?.absolutePath) - var duration = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION) + var duration = + metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION) ?.toLong() ?: 0 duration = diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/controller/ScriptController.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/controller/ScriptController.kt index cbe1d1950c9..43a645c2fa9 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/controller/ScriptController.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/controller/ScriptController.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2023 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -263,7 +263,10 @@ class ScriptController { private fun isUserDataAlreadyInScript(userDataName: String, map: HashMap?, variableType: Int): Boolean = map?.get(userDataName) == variableType - private fun checkIfUserDefinedBrickDefinitionIsInBricksToPack(bricksToPack: List?, userDefinedBrick: UserDefinedBrick): Boolean { + private fun checkIfUserDefinedBrickDefinitionIsInBricksToPack( + bricksToPack: List?, + userDefinedBrick: UserDefinedBrick + ): Boolean { bricksToPack?.forEach { brick -> if (brick is UserDefinedReceiverBrick && brick.userDefinedBrick.userDefinedBrickID == userDefinedBrick.userDefinedBrickID) { return true @@ -352,7 +355,12 @@ class ScriptController { } } - private fun addUserVariableToBrick(sprite: Sprite, name: String, destinationList: MutableList, brick: Brick) { + private fun addUserVariableToBrick( + sprite: Sprite, + name: String, + destinationList: MutableList, + brick: Brick + ) { if (renamedUserVariables.containsKey(name)) { if (brick is UserVariableBrickInterface) { brick.userVariable = destinationList.find { userVariable -> @@ -362,7 +370,8 @@ class ScriptController { updateFormula(brick, name, renamedUserVariables[name], USER_VARIABLE) } else if (!destinationList.any { variable -> variable.name == name }) { - val newNameForVariable = UniqueNameProvider().getUniqueName(name, getAllUserDataNames(sprite)) + val newNameForVariable = + UniqueNameProvider().getUniqueName(name, getAllUserDataNames(sprite)) if (newNameForVariable != name) { renamedUserVariables[name] = newNameForVariable diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/NewSpriteDialogFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/NewSpriteDialogFragment.kt index fc7e7a5bc25..9b5a2831bb2 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/NewSpriteDialogFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/dialog/NewSpriteDialogFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -62,6 +62,7 @@ import org.catrobat.catroid.visualplacement.VisualPlacementActivity import java.io.File import java.io.IOException +@Suppress("LongParameterList") class NewSpriteDialogFragment( private val emptySprite: Boolean, private val lookDataName: String, diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/CatblocksScriptFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/CatblocksScriptFragment.kt index 05184b71d93..b30c9b0f107 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/CatblocksScriptFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/CatblocksScriptFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2023 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -134,22 +134,21 @@ class CatblocksScriptFragment( override fun shouldInterceptRequest( view: WebView, request: WebResourceRequest - ): WebResourceResponse? { - return assetLoader.shouldInterceptRequest(request.url) - } + ): WebResourceResponse? = assetLoader.shouldInterceptRequest(request.url) override fun onPageFinished(view: WebView?, url: String?) { super.onPageFinished(view, url) if (testingMode) { - view?.evaluateJavascript(""" + view?.evaluateJavascript( + """ javascript:(function(){ console.log("Load webViewUtilsFunctions.js"); const scriptElement = document.createElement("script"); scriptElement.src = "https://appassets.androidplatform.net/assets/catblocks/webViewUtilsFunctions.js"; document.head.appendChild(scriptElement); - })() - """.trimIndent(), null) + })()""".trimIndent(), null + ) } view?.evaluateJavascript( @@ -173,15 +172,14 @@ class CatblocksScriptFragment( const object = Android.getSpriteNameToDisplay(); CatBlocks.render(programXML, scene, object); ${ - if (testingMode) { - "if (window.webViewUtils) window.webViewUtils" + - ".onPageLoaded();" - } else { - "" - } + if (testingMode) { + "if (window.webViewUtils) window.webViewUtils" + + ".onPageLoaded();" + } else { + "" } - })() - """.trimMargin(), null + } + })()""".trimMargin(), null ) } } @@ -258,8 +256,9 @@ class CatblocksScriptFragment( return brickAtTopID.toString() } else { if (projectManager.currentSprite?.scriptList != null && - projectManager.currentSprite.scriptList.any()) { - return projectManager.currentSprite.scriptList[0].scriptId.toString() + projectManager.currentSprite.scriptList.any() + ) { + return projectManager.currentSprite.scriptList[0].scriptId.toString() } } return null @@ -422,8 +421,10 @@ class CatblocksScriptFragment( @JavascriptInterface fun addBrickByName(categoryName: String, brickName: String): String { - val bricksOfCategory = CategoryBricksFactory().getBricks(categoryName, projectManager - .currentSprite.isBackgroundSprite, requireContext()) + val bricksOfCategory = CategoryBricksFactory().getBricks( + categoryName, projectManager + .currentSprite.isBackgroundSprite, requireContext() + ) val foundBricks = bricksOfCategory.filter { it.javaClass.simpleName.equals(brickName) } @@ -434,23 +435,36 @@ class CatblocksScriptFragment( if (brick is ScriptBrick) { projectManager.currentSprite.scriptList.add(brick.script) - addedBricks.add(BrickInfoHolder(brick.script.scriptId.toString(), brick - .script.javaClass.simpleName)) + addedBricks.add( + BrickInfoHolder( + brick.script.scriptId.toString(), brick + .script.javaClass.simpleName + ) + ) } else { val emptyBrick = EmptyEventBrick() emptyBrick.script.brickList.add(brick) projectManager.currentSprite.scriptList.add(emptyBrick.script) - addedBricks.add(BrickInfoHolder(emptyBrick.script.scriptId.toString(), - emptyBrick.script.javaClass.simpleName)) - - addedBricks.add(BrickInfoHolder(brick.brickID.toString(), - brick.javaClass.simpleName)) + addedBricks.add( + BrickInfoHolder( + emptyBrick.script.scriptId.toString(), + emptyBrick.script.javaClass.simpleName + ) + ) + + addedBricks.add( + BrickInfoHolder( + brick.brickID.toString(), + brick.javaClass.simpleName + ) + ) } try { if (brick.javaClass != UserDefinedReceiverBrick::class.java && - brick.javaClass != UserDefinedBrick::class.java) { + brick.javaClass != UserDefinedBrick::class.java + ) { RecentBrickListManager.getInstance().addBrick(brick.clone()) } } catch (e: CloneNotSupportedException) { diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/DataListFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/DataListFragment.kt index 826c08a0dbf..74ed01b06e3 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/DataListFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/DataListFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -238,8 +238,10 @@ class DataListFragment : Fragment(), .getBoolean(INDEXING_VARIABLE_PREFERENCE_KEY, false) if (!indexVariable) { - initialIndexing(userDefinedBrickInputs, globalVars, localVars, multiplayerVars, - globalLists, localLists) + initialIndexing( + userDefinedBrickInputs, globalVars, localVars, multiplayerVars, + globalLists, localLists + ) indexVariable = true PreferenceManager.getDefaultSharedPreferences(activity) .edit() @@ -247,8 +249,10 @@ class DataListFragment : Fragment(), .apply() } - sortVariableAndList(userDefinedBrickInputs, globalVars, localVars, multiplayerVars, - globalLists, localLists) + sortVariableAndList( + userDefinedBrickInputs, globalVars, localVars, multiplayerVars, + globalLists, localLists + ) adapter?.notifyDataSetChanged() } @@ -283,7 +287,7 @@ class DataListFragment : Fragment(), sortUserList(localLists, sortData) } - fun sortUserVariable(data: MutableList, sorted: Boolean) { + private fun sortUserVariable(data: MutableList, sorted: Boolean) { if (sorted) { data.sortWith(Comparator { item1: UserVariable, item2: UserVariable -> item1.name.compareTo(item2.name) @@ -295,7 +299,7 @@ class DataListFragment : Fragment(), } } - fun sortUserList(data: MutableList, sorted: Boolean) { + private fun sortUserList(data: MutableList, sorted: Boolean) { if (sorted) { data.sortWith(Comparator { item1: UserList, item2: UserList -> item1.name.compareTo(item2.name) @@ -431,8 +435,12 @@ class DataListFragment : Fragment(), adapter?.remove(item) } ProjectManager.getInstance().currentProject.deselectElements(selectedItems) - ToastUtil.showSuccess(activity, resources.getQuantityString(R.plurals.deleted_Items, - selectedItems.size, selectedItems.size)) + ToastUtil.showSuccess( + activity, resources.getQuantityString( + R.plurals.deleted_Items, + selectedItems.size, selectedItems.size + ) + ) } private fun showRenameDialog(selectedItems: List>) { @@ -533,14 +541,16 @@ class DataListFragment : Fragment(), } val itemList: MutableList> = ArrayList() itemList.add(item) - val hiddenOptionsMenu = mutableListOf( + val hiddenOptionsMenu = mutableListOf( R.id.copy, R.id.show_details, R.id.from_library, R.id.from_local, R.id.new_group, R.id.new_scene, R.id.cast_button, R.id.backpack, R.id.project_options ) if (item is UserVariable) { - val popupMenu = UiUtils.createSettingsPopUpMenu(view, requireContext(), - R.menu.menu_project_activity, - hiddenOptionsMenu.toIntArray()) + val popupMenu = UiUtils.createSettingsPopUpMenu( + view, requireContext(), + R.menu.menu_project_activity, + hiddenOptionsMenu.toIntArray() + ) popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.rename -> showRenameDialog(ArrayList(listOf(item))) @@ -552,9 +562,11 @@ class DataListFragment : Fragment(), popupMenu.show() } else { hiddenOptionsMenu.add(R.id.edit) - val popupMenu = UiUtils.createSettingsPopUpMenu(view, requireContext(), - R.menu.menu_project_activity, - hiddenOptionsMenu.toIntArray()) + val popupMenu = UiUtils.createSettingsPopUpMenu( + view, requireContext(), + R.menu.menu_project_activity, + hiddenOptionsMenu.toIntArray() + ) popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.rename -> showRenameDialog(ArrayList(listOf(item))) diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ListSelectorFragment.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ListSelectorFragment.kt index 8b27608b25a..c03f85d0cbf 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ListSelectorFragment.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/fragment/ListSelectorFragment.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -273,17 +273,19 @@ class ListSelectorFragment : Fragment(), RVAdapter.SelectionListener, val itemList: MutableList> = ArrayList() itemList.add(item) val hiddenOptionMenuIds = intArrayOf( - R.id.backpack, - R.id.copy, - R.id.new_group, - R.id.new_scene, - R.id.show_details, - R.id.project_options, - R.id.from_library, - R.id.from_local + R.id.backpack, + R.id.copy, + R.id.new_group, + R.id.new_scene, + R.id.show_details, + R.id.project_options, + R.id.from_library, + R.id.from_local + ) + val popupMenu = UiUtils.createSettingsPopUpMenu( + view, context, R.menu + .menu_project_activity, hiddenOptionMenuIds ) - val popupMenu = UiUtils.createSettingsPopUpMenu(view, context, R.menu - .menu_project_activity, hiddenOptionMenuIds) popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.rename -> showRenameDialog(listOf(item)) diff --git a/catroid/src/main/java/org/catrobat/catroid/utils/PcmToWavConverter.kt b/catroid/src/main/java/org/catrobat/catroid/utils/PcmToWavConverter.kt index 197b50babf2..77787458917 100644 --- a/catroid/src/main/java/org/catrobat/catroid/utils/PcmToWavConverter.kt +++ b/catroid/src/main/java/org/catrobat/catroid/utils/PcmToWavConverter.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -125,7 +125,7 @@ object PcmToWavConverter { } private fun writeToOutput(output: OutputStream, data: String) { - for (element in data) output.write(element.toInt()) + for (element in data) output.write(element.code) } private fun writeToOutput(output: OutputStream, data: Int) { diff --git a/catroid/src/main/java/org/catrobat/catroid/utils/ProjectDownloadUtil.kt b/catroid/src/main/java/org/catrobat/catroid/utils/ProjectDownloadUtil.kt index cc32a6521de..bdfd8a02d82 100644 --- a/catroid/src/main/java/org/catrobat/catroid/utils/ProjectDownloadUtil.kt +++ b/catroid/src/main/java/org/catrobat/catroid/utils/ProjectDownloadUtil.kt @@ -1,6 +1,6 @@ - /* +/* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify diff --git a/catroid/src/main/java/org/catrobat/catroid/utils/notifications/NotificationData.kt b/catroid/src/main/java/org/catrobat/catroid/utils/notifications/NotificationData.kt index 90070016165..49c7c8961bc 100644 --- a/catroid/src/main/java/org/catrobat/catroid/utils/notifications/NotificationData.kt +++ b/catroid/src/main/java/org/catrobat/catroid/utils/notifications/NotificationData.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -46,18 +46,23 @@ data class NotificationData( private const val serialVersionUID: Long = 42 } - fun toNotification(context: Context, channelId: String, contentIntent: PendingIntent?): Notification { - val title = (if (progressInPercent < maxProgress) titleWorking else titleDone) + " " + programName + fun toNotification( + context: Context, + channelId: String, + contentIntent: PendingIntent? + ): Notification { + val title = + (if (progressInPercent < maxProgress) titleWorking else titleDone) + " " + programName val text = if (progressInPercent < maxProgress) textWorking else textDone return NotificationCompat.Builder(context, channelId) - .setContentTitle(title) - .setContentText(text) - .setSmallIcon(notificationIconResId) - .setProgress(maxProgress, progressInPercent, false) - .setOngoing(ongoing) - .setAutoCancel(autoCancel) - .setContentIntent(contentIntent) - .build() + .setContentTitle(title) + .setContentText(text) + .setSmallIcon(notificationIconResId) + .setProgress(maxProgress, progressInPercent, false) + .setOngoing(ongoing) + .setAutoCancel(autoCancel) + .setContentIntent(contentIntent) + .build() } } diff --git a/catroid/src/main/java/org/catrobat/catroid/web/ProjectDownloader.kt b/catroid/src/main/java/org/catrobat/catroid/web/ProjectDownloader.kt index 2a917d36be9..538afa87bd3 100644 --- a/catroid/src/main/java/org/catrobat/catroid/web/ProjectDownloader.kt +++ b/catroid/src/main/java/org/catrobat/catroid/web/ProjectDownloader.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -129,7 +129,7 @@ class ProjectDownloader( } @SuppressLint("ParcelCreator") - private inner class Receiver internal constructor( + private inner class Receiver( val projectName: String, handler: Handler ) : ResultReceiver(handler) { @@ -138,7 +138,7 @@ class ProjectDownloader( when (resultCode) { UPDATE_PROGRESS_CODE -> { val progress = resultData.getInt(UPDATE_PROGRESS_EXTRA) - callbackWeakReference.get()?.onDownloadProgress(progress.toInt(), url) + callbackWeakReference.get()?.onDownloadProgress(progress, url) } SUCCESS_CODE -> { callbackWeakReference.get()?.onDownloadFinished(projectName, url) @@ -161,7 +161,7 @@ object GlobalProjectDownloadQueue { val queue = ProjectDownloadQueue() class ProjectDownloadQueue : ProjectDownloader.ProjectDownloadQueue { - private var projectNameSet: Set = Collections.synchronizedSet(HashSet()) + private var projectNameSet: Set = Collections.synchronizedSet(HashSet()) @Synchronized override fun alreadyInQueue(projectName: String): Boolean = diff --git a/catroid/src/main/java/org/catrobat/catroid/web/WebConnectionHolder.kt b/catroid/src/main/java/org/catrobat/catroid/web/WebConnectionHolder.kt index f33fd42c0fe..15dd4158fba 100644 --- a/catroid/src/main/java/org/catrobat/catroid/web/WebConnectionHolder.kt +++ b/catroid/src/main/java/org/catrobat/catroid/web/WebConnectionHolder.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -63,7 +63,9 @@ class WebConnectionHolder { if (connections.size < MAX_CONNECTIONS) { connections.add(connection) true - } else false + } else { + false + } @Synchronized fun removeConnection(connection: WebConnection?) { diff --git a/catroid/src/test/java/org/catrobat/catroid/test/content/actions/IfOnEdgeBounceActionTest.kt b/catroid/src/test/java/org/catrobat/catroid/test/content/actions/IfOnEdgeBounceActionTest.kt index aa15a5763f1..42af4cfd866 100644 --- a/catroid/src/test/java/org/catrobat/catroid/test/content/actions/IfOnEdgeBounceActionTest.kt +++ b/catroid/src/test/java/org/catrobat/catroid/test/content/actions/IfOnEdgeBounceActionTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -34,6 +34,7 @@ import org.junit.runners.Parameterized @RunWith(Parameterized::class) class IfOnEdgeBounceActionTest( + @Suppress("unused") private val name: String, private val initialPosX: Float, private val initialPosY: Float, @@ -48,34 +49,82 @@ class IfOnEdgeBounceActionTest( companion object { @JvmStatic @Parameterized.Parameters(name = "{0} {5}") - fun parameters() = (-179..180).flatMap { initialDirection -> listOf( - arrayOf("TOP_BOUNCE", 0f, TOP_BORDER_POSITION, 0f, BOUNCE_TOP_POSITION, initialDirection, - getExpectedDirection(initialDirection, (-90..89).toSet(), 180)), - arrayOf("BOTTOM_BOUNCE", 0f, BOTTOM_BORDER_POSITION, 0f, BOUNCE_BOTTOM_POSITION, initialDirection, - getExpectedDirection(initialDirection, (-179..-91).union(90..180), 180)), - arrayOf("LEFT_BOUNCE", LEFT_BORDER_POSITION, 0f, BOUNCE_LEFT_POSITION, 0f, initialDirection, - getExpectedDirection(initialDirection, (-179..-1).toSet(), 0)), - arrayOf("RIGHT_BOUNCE", RIGHT_BORDER_POSITION, 0f, BOUNCE_RIGHT_POSITION, 0f, initialDirection, - getExpectedDirection(initialDirection, (0..179).toSet(), 0)), - arrayOf("NO_BOUNCE", 0f, 0f, 0f, 0f, initialDirection, initialDirection.toFloat()) - ) }.plus(listOf( - arrayOf("LEFT_TOP_BOUNCE", LEFT_BORDER_POSITION, TOP_BORDER_POSITION, - BOUNCE_LEFT_POSITION, BOUNCE_TOP_POSITION, -45, 135f), - arrayOf("LEFT_TOP_NO_BOUNCE", LEFT_BORDER_POSITION, TOP_BORDER_POSITION, - BOUNCE_LEFT_POSITION, BOUNCE_TOP_POSITION, 135, 135f), - arrayOf("RIGHT_TOP_BOUNCE", RIGHT_BORDER_POSITION, TOP_BORDER_POSITION, - BOUNCE_RIGHT_POSITION, BOUNCE_TOP_POSITION, 45, -135f), - arrayOf("RIGHT_TOP_NO_BOUNCE", RIGHT_BORDER_POSITION, TOP_BORDER_POSITION, - BOUNCE_RIGHT_POSITION, BOUNCE_TOP_POSITION, -135, -135f), - arrayOf("LEFT_BOTTOM_BOUNCE", LEFT_BORDER_POSITION, BOTTOM_BORDER_POSITION, - BOUNCE_LEFT_POSITION, BOUNCE_BOTTOM_POSITION, -135, 45f), - arrayOf("LEFT_BOTTOM_NO_BOUNCE", LEFT_BORDER_POSITION, BOTTOM_BORDER_POSITION, - BOUNCE_LEFT_POSITION, BOUNCE_BOTTOM_POSITION, 45, 45f), - arrayOf("RIGHT_BOTTOM_BOUNCE", RIGHT_BORDER_POSITION, BOTTOM_BORDER_POSITION, - BOUNCE_RIGHT_POSITION, BOUNCE_BOTTOM_POSITION, 135, -45f), - arrayOf("RIGHT_BOTTOM_NO_BOUNCE", RIGHT_BORDER_POSITION, BOTTOM_BORDER_POSITION, - BOUNCE_RIGHT_POSITION, BOUNCE_BOTTOM_POSITION, -45, -45f) - )) + fun parameters() = (-179..180).flatMap { initialDirection -> + listOf( + arrayOf( + "TOP_BOUNCE", + 0f, + TOP_BORDER_POSITION, + 0f, + BOUNCE_TOP_POSITION, + initialDirection, + getExpectedDirection(initialDirection, (-90..89).toSet(), 180) + ), + arrayOf( + "BOTTOM_BOUNCE", + 0f, + BOTTOM_BORDER_POSITION, + 0f, + BOUNCE_BOTTOM_POSITION, + initialDirection, + getExpectedDirection(initialDirection, (-179..-91).union(90..180), 180) + ), + arrayOf( + "LEFT_BOUNCE", + LEFT_BORDER_POSITION, + 0f, + BOUNCE_LEFT_POSITION, + 0f, + initialDirection, + getExpectedDirection(initialDirection, (-179..-1).toSet(), 0) + ), + arrayOf( + "RIGHT_BOUNCE", + RIGHT_BORDER_POSITION, + 0f, + BOUNCE_RIGHT_POSITION, + 0f, + initialDirection, + getExpectedDirection(initialDirection, (0..179).toSet(), 0) + ), + arrayOf("NO_BOUNCE", 0f, 0f, 0f, 0f, initialDirection, initialDirection.toFloat()) + ) + }.plus( + listOf( + arrayOf( + "LEFT_TOP_BOUNCE", LEFT_BORDER_POSITION, TOP_BORDER_POSITION, + BOUNCE_LEFT_POSITION, BOUNCE_TOP_POSITION, -45, 135f + ), + arrayOf( + "LEFT_TOP_NO_BOUNCE", LEFT_BORDER_POSITION, TOP_BORDER_POSITION, + BOUNCE_LEFT_POSITION, BOUNCE_TOP_POSITION, 135, 135f + ), + arrayOf( + "RIGHT_TOP_BOUNCE", RIGHT_BORDER_POSITION, TOP_BORDER_POSITION, + BOUNCE_RIGHT_POSITION, BOUNCE_TOP_POSITION, 45, -135f + ), + arrayOf( + "RIGHT_TOP_NO_BOUNCE", RIGHT_BORDER_POSITION, TOP_BORDER_POSITION, + BOUNCE_RIGHT_POSITION, BOUNCE_TOP_POSITION, -135, -135f + ), + arrayOf( + "LEFT_BOTTOM_BOUNCE", LEFT_BORDER_POSITION, BOTTOM_BORDER_POSITION, + BOUNCE_LEFT_POSITION, BOUNCE_BOTTOM_POSITION, -135, 45f + ), + arrayOf( + "LEFT_BOTTOM_NO_BOUNCE", LEFT_BORDER_POSITION, BOTTOM_BORDER_POSITION, + BOUNCE_LEFT_POSITION, BOUNCE_BOTTOM_POSITION, 45, 45f + ), + arrayOf( + "RIGHT_BOTTOM_BOUNCE", RIGHT_BORDER_POSITION, BOTTOM_BORDER_POSITION, + BOUNCE_RIGHT_POSITION, BOUNCE_BOTTOM_POSITION, 135, -45f + ), + arrayOf( + "RIGHT_BOTTOM_NO_BOUNCE", RIGHT_BORDER_POSITION, BOTTOM_BORDER_POSITION, + BOUNCE_RIGHT_POSITION, BOUNCE_BOTTOM_POSITION, -45, -45f + ) + ) + ) private const val WIDTH = 100f private const val HEIGHT = 100f @@ -90,7 +139,11 @@ class IfOnEdgeBounceActionTest( private const val BOUNCE_RIGHT_POSITION = RIGHT_BORDER_POSITION - WIDTH / 2f private const val BOUNCE_LEFT_POSITION = -BOUNCE_RIGHT_POSITION - private fun getExpectedDirection(initialDirection: Int, bounceRange: Set, axis: Int): Float { + private fun getExpectedDirection( + initialDirection: Int, + bounceRange: Set, + axis: Int + ): Float { return when { initialDirection !in bounceRange -> initialDirection initialDirection >= 0 -> axis - initialDirection diff --git a/catroid/src/test/java/org/catrobat/catroid/test/content/actions/ReadVariableFromFileActionTest.kt b/catroid/src/test/java/org/catrobat/catroid/test/content/actions/ReadVariableFromFileActionTest.kt index de793f3a189..e0c3b53ce4b 100644 --- a/catroid/src/test/java/org/catrobat/catroid/test/content/actions/ReadVariableFromFileActionTest.kt +++ b/catroid/src/test/java/org/catrobat/catroid/test/content/actions/ReadVariableFromFileActionTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -41,7 +41,9 @@ import org.powermock.api.mockito.PowerMockito.spy import java.io.File @RunWith(Parameterized::class) +@Suppress("LongParameterList") class ReadVariableFromFileActionTest( + @Suppress("unused") private val name: String, private val formula: Formula?, private val userVariable: UserVariable?, @@ -58,24 +60,42 @@ class ReadVariableFromFileActionTest( @JvmStatic @Parameterized.Parameters(name = "{0}") fun parameters() = listOf( - arrayOf("USER_VARIABLE_NULL", Formula("file.txt"), null, DEFAULT_FILE_CONTENT, - null, 0, 0, false), - arrayOf("FORMULA_NULL", null, UserVariable(VAR_NAME), DEFAULT_FILE_CONTENT, 0.0, 0, - 0, false), - arrayOf("VALID_FILE_NAME", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), - DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, false), - arrayOf("DELETE_FILE", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), - DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, true), - arrayOf("CANNOT_READ_FILE", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), - DEFAULT_FILE_CONTENT, 0.0, 1, 0, false), - arrayOf("NO_SUFFIX", Formula("file"), UserVariable(VAR_NAME), - DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, false), - arrayOf("INVALID_FILE_NAME", Formula("\"f\\i^^ *\\\"l\\|\"e.t xt\\\""), - UserVariable(VAR_NAME), DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, false), - arrayOf("UNICODE", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), - "🐼~🐵~🐘", "🐼~🐵~🐘", 1, 1, false), - arrayOf("NUMBER", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), - "-3.14", -3.14, 1, 1, false) + arrayOf( + "USER_VARIABLE_NULL", Formula("file.txt"), null, DEFAULT_FILE_CONTENT, + null, 0, 0, false + ), + arrayOf( + "FORMULA_NULL", null, UserVariable(VAR_NAME), DEFAULT_FILE_CONTENT, 0.0, 0, + 0, false + ), + arrayOf( + "VALID_FILE_NAME", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), + DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, false + ), + arrayOf( + "DELETE_FILE", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), + DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, true + ), + arrayOf( + "CANNOT_READ_FILE", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), + DEFAULT_FILE_CONTENT, 0.0, 1, 0, false + ), + arrayOf( + "NO_SUFFIX", Formula("file"), UserVariable(VAR_NAME), + DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, false + ), + arrayOf( + "INVALID_FILE_NAME", Formula("\"f\\i^^ *\\\"l\\|\"e.t xt\\\""), + UserVariable(VAR_NAME), DEFAULT_FILE_CONTENT, DEFAULT_FILE_CONTENT, 1, 1, false + ), + arrayOf( + "UNICODE", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), + "🐼~🐵~🐘", "🐼~🐵~🐘", 1, 1, false + ), + arrayOf( + "NUMBER", Formula(DEFAULT_FILE_NAME), UserVariable(VAR_NAME), + "-3.14", -3.14, 1, 1, false + ) ) private const val DEFAULT_FILE_NAME = "file.txt" diff --git a/catroid/src/test/java/org/catrobat/catroid/test/content/actions/WriteVariableToFileActionTest.kt b/catroid/src/test/java/org/catrobat/catroid/test/content/actions/WriteVariableToFileActionTest.kt index 9adfd81cc27..2b2e7f20e56 100644 --- a/catroid/src/test/java/org/catrobat/catroid/test/content/actions/WriteVariableToFileActionTest.kt +++ b/catroid/src/test/java/org/catrobat/catroid/test/content/actions/WriteVariableToFileActionTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -44,6 +44,7 @@ import java.io.File @RunWith(Parameterized::class) class WriteVariableToFileActionTest( + @Suppress("unused") private val name: String, private val formula: Formula?, private val userVariable: UserVariable?, @@ -61,18 +62,30 @@ class WriteVariableToFileActionTest( fun parameters() = listOf( arrayOf("USER_VARIABLE_NULL", Formula("file.txt"), null, "", 0, 0), arrayOf("FORMULA_NULL", null, UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), "", 0, 0), - arrayOf("VALID_FILE_NAME", Formula(DEFAULT_FILE_NAME), - UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 1), - arrayOf("CANNOT_CREATE_FILE", Formula(DEFAULT_FILE_NAME), - UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 0), - arrayOf("NO_SUFFIX", Formula("file"), - UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 1), - arrayOf("INVALID_FILE_NAME", Formula("\"f\\i^^ *\\\"l\\|\"e.t xt\\\""), - UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 1), - arrayOf("UNICODE", Formula(DEFAULT_FILE_NAME), - UserVariable(VAR_NAME, "🐼~🐵~🐘"), "🐼~🐵~🐘", 1, 1), - arrayOf("NUMBER", Formula(DEFAULT_FILE_NAME), - UserVariable(VAR_NAME, -3.14), "-3.14", 1, 1) + arrayOf( + "VALID_FILE_NAME", Formula(DEFAULT_FILE_NAME), + UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 1 + ), + arrayOf( + "CANNOT_CREATE_FILE", Formula(DEFAULT_FILE_NAME), + UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 0 + ), + arrayOf( + "NO_SUFFIX", Formula("file"), + UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 1 + ), + arrayOf( + "INVALID_FILE_NAME", Formula("\"f\\i^^ *\\\"l\\|\"e.t xt\\\""), + UserVariable(VAR_NAME, DEFAULT_VAR_VALUE), DEFAULT_VAR_VALUE, 1, 1 + ), + arrayOf( + "UNICODE", Formula(DEFAULT_FILE_NAME), + UserVariable(VAR_NAME, "🐼~🐵~🐘"), "🐼~🐵~🐘", 1, 1 + ), + arrayOf( + "NUMBER", Formula(DEFAULT_FILE_NAME), + UserVariable(VAR_NAME, -3.14), "-3.14", 1, 1 + ) ) private const val DEFAULT_FILE_NAME = "file.txt" diff --git a/catroid/src/test/java/org/catrobat/catroid/test/formulaeditor/parser/SingleParameterFunctionParserTest.kt b/catroid/src/test/java/org/catrobat/catroid/test/formulaeditor/parser/SingleParameterFunctionParserTest.kt index 7433e9844c0..478eedf565e 100644 --- a/catroid/src/test/java/org/catrobat/catroid/test/formulaeditor/parser/SingleParameterFunctionParserTest.kt +++ b/catroid/src/test/java/org/catrobat/catroid/test/formulaeditor/parser/SingleParameterFunctionParserTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -98,9 +98,14 @@ class SingleParameterFunctionParserTest( arrayOf("ABS", ABS, AssociatedFunction { par -> abs(par) }, -4.0), arrayOf("ARCSIN", ARCSIN, AssociatedFunction { par -> toDegrees(asin(par)) }, 0.66), arrayOf("ARCCOS", ARCCOS, AssociatedFunction { par -> toDegrees(acos(par)) }, 0.66), - arrayOf("ARCTAN", ARCTAN, AssociatedFunction { par -> toDegrees(atan(par)) }, 45.66), + arrayOf( + "ARCTAN", + ARCTAN, + AssociatedFunction { par -> toDegrees(atan(par)) }, + 45.66 + ), arrayOf("EXP", EXP, AssociatedFunction { par -> exp(par) }, 45.66) - ) + ) } } diff --git a/catroid/src/test/java/org/catrobat/catroid/test/web/EmbeddedSurveyTest.kt b/catroid/src/test/java/org/catrobat/catroid/test/web/EmbeddedSurveyTest.kt index 858a0a7215b..70fc475e5b6 100644 --- a/catroid/src/test/java/org/catrobat/catroid/test/web/EmbeddedSurveyTest.kt +++ b/catroid/src/test/java/org/catrobat/catroid/test/web/EmbeddedSurveyTest.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -48,15 +48,15 @@ import java.util.Date class EmbeddedSurveyTest { private var currentTimeInMilliseconds: Long = 0 private var surveySpy: Survey? = null - private val URL1: String = "https://url1.at/" - private val URL2: String = "https://url2.at/" + private val url1: String = "https://url1.at/" + private val url2: String = "https://url2.at/" @Mock var sharedPreferencesMock: SharedPreferences? = null - var sharedPreferenceEditorMock: SharedPreferences.Editor? = null - var contextMock: Context? = null - var surveyMock: Survey? = null - var getSurveyTaskMock: GetSurveyTask? = null + private var sharedPreferenceEditorMock: SharedPreferences.Editor? = null + private var contextMock: Context? = null + private var surveyMock: Survey? = null + private var getSurveyTaskMock: GetSurveyTask? = null @Before @Throws(Exception::class) @@ -76,7 +76,7 @@ class EmbeddedSurveyTest { @Test fun doNotShowSurveyUnderMinimumTime() { - val dateYesterday = Date(currentTimeInMilliseconds - dayInMilliseconds) + val dateYesterday = Date(currentTimeInMilliseconds - DAY_IN_MILLISECONDS) val timeSpentInApp = (Survey.MINIMUM_TIME_SPENT_IN_APP_IN_SECONDS - 1).toLong() initMocks( dateYesterday, timeSpentInApp, showSurveyKey = false, networkConnected = true, @@ -102,7 +102,7 @@ class EmbeddedSurveyTest { @Test fun doNotShowSurveyWhenNoInternetConnection() { - val dateYesterday = Date(currentTimeInMilliseconds - dayInMilliseconds) + val dateYesterday = Date(currentTimeInMilliseconds - DAY_IN_MILLISECONDS) val timeSpentInApp = (Survey.MINIMUM_TIME_SPENT_IN_APP_IN_SECONDS + 1).toLong() initMocks( dateYesterday, timeSpentInApp, showSurveyKey = false, networkConnected = false, @@ -115,7 +115,7 @@ class EmbeddedSurveyTest { @Test fun doNotShowSurveyTwice() { - val dateYesterday = Date(currentTimeInMilliseconds - dayInMilliseconds) + val dateYesterday = Date(currentTimeInMilliseconds - DAY_IN_MILLISECONDS) val timeSpentInApp = (Survey.MINIMUM_TIME_SPENT_IN_APP_IN_SECONDS + 1).toLong() initMocks( dateYesterday, timeSpentInApp, showSurveyKey = false, networkConnected = true, @@ -126,7 +126,7 @@ class EmbeddedSurveyTest { ArgumentMatchers.eq(SharedPreferenceKeys.SURVEY_URL1_HASH_KEY), ArgumentMatchers.anyLong() ) - ).thenReturn(URL1.hashCode().toLong()) + ).thenReturn(url1.hashCode().toLong()) Mockito.`when`( sharedPreferencesMock!!.getLong( ArgumentMatchers.eq(SharedPreferenceKeys.SURVEY_URL2_HASH_KEY), @@ -134,16 +134,16 @@ class EmbeddedSurveyTest { ) ).thenReturn(0) - surveySpy?.onSurveyReceived(contextMock, URL1) + surveySpy?.onSurveyReceived(contextMock, url1) Mockito.verify(surveySpy, Mockito.times(1))!! - .isUrlNew(contextMock, URL1) + .isUrlNew(contextMock, url1) Mockito.verify(surveySpy, Mockito.times(0))!! - .saveUrlHash(contextMock, URL1) + .saveUrlHash(contextMock, url1) } @Test fun doNotShowSameSurveyAfterShowingAnotherSurvey() { - val dateYesterday = Date(currentTimeInMilliseconds - dayInMilliseconds) + val dateYesterday = Date(currentTimeInMilliseconds - DAY_IN_MILLISECONDS) val timeSpentInApp = (Survey.MINIMUM_TIME_SPENT_IN_APP_IN_SECONDS + 1).toLong() initMocks( dateYesterday, timeSpentInApp, showSurveyKey = false, networkConnected = true, @@ -154,24 +154,24 @@ class EmbeddedSurveyTest { ArgumentMatchers.eq(SharedPreferenceKeys.SURVEY_URL1_HASH_KEY), ArgumentMatchers.anyLong() ) - ).thenReturn(URL2.hashCode().toLong()) + ).thenReturn(url2.hashCode().toLong()) Mockito.`when`( sharedPreferencesMock!!.getLong( ArgumentMatchers.eq(SharedPreferenceKeys.SURVEY_URL2_HASH_KEY), ArgumentMatchers.anyLong() ) - ).thenReturn(URL1.hashCode().toLong()) + ).thenReturn(url1.hashCode().toLong()) - surveySpy?.onSurveyReceived(contextMock, URL1) + surveySpy?.onSurveyReceived(contextMock, url1) Mockito.verify(surveySpy, Mockito.times(1))!! - .isUrlNew(contextMock, URL1) + .isUrlNew(contextMock, url1) Mockito.verify(surveySpy, Mockito.times(0))!! - .saveUrlHash(contextMock, URL1) + .saveUrlHash(contextMock, url1) } @Test fun doNotShowSurveyForLanguageNotDeposited() { - val dateYesterday = Date(currentTimeInMilliseconds - dayInMilliseconds) + val dateYesterday = Date(currentTimeInMilliseconds - DAY_IN_MILLISECONDS) val timeSpentInApp = (Survey.MINIMUM_TIME_SPENT_IN_APP_IN_SECONDS + 1).toLong() initMocks( dateYesterday, timeSpentInApp, showSurveyKey = false, networkConnected = true, @@ -201,7 +201,7 @@ class EmbeddedSurveyTest { @Test fun showSurveyFulfilledRequirements() { - val dateYesterday = Date(currentTimeInMilliseconds - dayInMilliseconds) + val dateYesterday = Date(currentTimeInMilliseconds - DAY_IN_MILLISECONDS) val timeSpentInApp = (Survey.MINIMUM_TIME_SPENT_IN_APP_IN_SECONDS + 1).toLong() initMocks( dateYesterday, timeSpentInApp, showSurveyKey = false, networkConnected = true, @@ -212,10 +212,16 @@ class EmbeddedSurveyTest { .getSurvey(contextMock) } - private fun initMocks(date: Date, timeSpentInApp: Long, showSurveyKey: Boolean, networkConnected: Boolean, uploadFlag: Boolean) { + private fun initMocks( + date: Date, + timeSpentInApp: Long, + showSurveyKey: Boolean, + networkConnected: Boolean, + uploadFlag: Boolean + ) { PowerMockito.`when`(Utils.isNetworkAvailable(contextMock)).thenReturn(networkConnected) PowerMockito.`when`(DateUtils.isToday(ArgumentMatchers.anyLong())).thenReturn( - currentTimeInMilliseconds - date.time < dayInMilliseconds + currentTimeInMilliseconds - date.time < DAY_IN_MILLISECONDS ) PowerMockito.`when`(PreferenceManager.getDefaultSharedPreferences(contextMock)) .thenReturn(sharedPreferencesMock) @@ -253,6 +259,6 @@ class EmbeddedSurveyTest { } companion object { - private const val dayInMilliseconds = (24 * 60 * 60 * 1000).toLong() + private const val DAY_IN_MILLISECONDS = (24 * 60 * 60 * 1000).toLong() } }