-
Notifications
You must be signed in to change notification settings - Fork 814
CATROID-1554: Refactor WaitForSoundAction to Kotlin #5193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshsomankar123-tech
wants to merge
4
commits into
Catrobat:develop
Choose a base branch
from
harshsomankar123-tech:refactor/CATROID-1554-kotlin
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−97
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b12b35
CATROID-1554: Refactor WaitForSoundAction to Kotlin
harshsomankar123-tech 3e79a6f
Simplify complex conditions in end() for Detekt
harshsomankar123-tech 31b5db2
Fix detekt complexity and Float type mismatch errors
harshsomankar123-tech 89e0bd3
CATROID-1554: Fix unit conversion and reset soundStopped flag in Wait…
harshsomankar123-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 0 additions & 97 deletions
97
catroid/src/main/java/org/catrobat/catroid/content/actions/WaitForSoundAction.java
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
catroid/src/main/java/org/catrobat/catroid/content/actions/WaitForSoundAction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * Catroid: An on-device visual programming system for Android devices | ||
| * Copyright (C) 2010-2026 The Catrobat Team | ||
| * (<http://developer.catrobat.org/credits>) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * An additional term exception under section 7 of the GNU Affero | ||
| * General Public License, version 3, is available at | ||
| * http://developer.catrobat.org/license_additional_term | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.catrobat.catroid.content.actions | ||
|
|
||
| import androidx.annotation.VisibleForTesting | ||
| import org.catrobat.catroid.content.SoundFilePathWithSprite | ||
| import org.catrobat.catroid.io.SoundManager | ||
| import org.catrobat.catroid.pocketmusic.mididriver.MidiSoundManager | ||
|
|
||
| class WaitForSoundAction : WaitAction() { | ||
|
|
||
| var soundFilePath: String? = null | ||
|
|
||
| @VisibleForTesting | ||
| var soundManager: SoundManager = SoundManager.getInstance() | ||
|
|
||
| @VisibleForTesting | ||
| var midiSoundManager: MidiSoundManager = MidiSoundManager.getInstance() | ||
|
|
||
| private var soundStopped = false | ||
|
|
||
| override fun restart() { | ||
| soundStopped = false | ||
| super.restart() | ||
| } | ||
|
|
||
| override fun update(percent: Float) { | ||
| val path = soundFilePath ?: return | ||
| val sprite = scope.sprite | ||
|
|
||
| val startedPaths = midiSoundManager.startedSoundfilePaths | ||
| if (startedPaths.isNotEmpty()) { | ||
| val spriteSoundFilePath = SoundFilePathWithSprite(path, sprite) | ||
| if (spriteSoundFilePath in startedPaths && | ||
| !midiSoundManager.isSoundInSpritePlaying(sprite, path) | ||
| ) { | ||
| startedPaths.remove(spriteSoundFilePath) | ||
| finish() | ||
| soundStopped = true | ||
| return | ||
| } | ||
| } | ||
|
|
||
| val stoppedPaths = soundManager.recentlyStoppedSoundfilePaths | ||
| if (stoppedPaths.isNotEmpty()) { | ||
| val spriteSoundFilePath = SoundFilePathWithSprite(path, sprite) | ||
| if (spriteSoundFilePath in stoppedPaths) { | ||
| stoppedPaths.remove(spriteSoundFilePath) | ||
| finish() | ||
| soundStopped = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun end() { | ||
| if (soundStopped) return | ||
| val path = soundFilePath ?: return | ||
| val sprite = scope.sprite | ||
|
|
||
| for (mediaPlayer in soundManager.mediaPlayers) { | ||
| if (mediaPlayer.isPlaying && | ||
| mediaPlayer.startedBySprite === sprite && | ||
| mediaPlayer.pathToSoundFile == path | ||
| ) { | ||
| restart() | ||
| setTime(mediaPlayer.currentPosition.toFloat() / MILLISECONDS_IN_SECOND) | ||
| } | ||
|
harshsomankar123-tech marked this conversation as resolved.
|
||
| } | ||
|
|
||
| for (midiPlayer in midiSoundManager.midiPlayers) { | ||
| if (midiPlayer.isPlaying && | ||
| midiPlayer.startedBySprite === sprite && | ||
| midiPlayer.pathToSoundFile == path | ||
| ) { | ||
| restart() | ||
| setTime(midiPlayer.currentPosition.toFloat() / MILLISECONDS_IN_SECOND) | ||
| } | ||
|
harshsomankar123-tech marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| @JvmField | ||
| val TAG: String = WaitForSoundAction::class.java.simpleName | ||
|
|
||
| private const val MILLISECONDS_IN_SECOND = 1000f | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.