mirror of
https://github.com/kalarina-bit/Matewave.git
synced 2026-11-22 08:06:09 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6be0cac7a | ||
|
|
e4a6e05cf3 | ||
|
|
a3ec1501e4 | ||
|
|
071430865f | ||
|
|
849e735ed0 | ||
|
|
ae1344d2ec | ||
|
|
c08272fb4a | ||
|
|
5c0f80247f |
@@ -1,23 +1,34 @@
|
||||
<p align="center">
|
||||
<img src="assets/icon-rounded.png" width="128" alt="Matewave icon">
|
||||
<img src="assets/icon-rounded.png" width="112" alt="Matewave icon">
|
||||
</p>
|
||||
|
||||
<h1 align="center">Matewave</h1>
|
||||
|
||||
<p align="center"><b>A beautiful, open-source chess app for Android.</b></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://git.skysparkle.cc/kalarina/Matewave/releases"><img src="assets/get-it-on-gitea.png" height="60" alt="Get it on Gitea"></a>
|
||||
<b>A beautiful, open-source chess app for Android.</b><br>
|
||||
Play against the AI, solve puzzles, learn openings, or play friends nearby over Bluetooth and Wi-Fi/LAN.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/Android-8.0%2B-2e7d32?logo=android&logoColor=white&labelColor=1b1b1b" alt="Android 8.0+">
|
||||
<img src="https://img.shields.io/badge/License-GPL--3.0--or--later-2e7d32?labelColor=1b1b1b" alt="GPL-3.0-or-later">
|
||||
<a href="https://github.com/kalarina-bit/Matewave/releases/latest"><img src="https://img.shields.io/github/v/release/kalarina-bit/Matewave?style=for-the-badge&label=release&labelColor=1b1b1b&color=2e7d32" alt="Latest release"></a>
|
||||
</p>
|
||||
|
||||
Play against the AI, solve puzzles, learn openings, or play friends nearby over Bluetooth and Wi-Fi/LAN.
|
||||
<p align="center">
|
||||
<a href="https://f-droid.org/packages/cc.skysparkle.matewave/"><img src="assets/get-it-on%20(1).png" height="56" alt="Get it on F-Droid"></a>
|
||||
<a href="https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://git.skysparkle.cc/kalarina/Matewave"><img src="assets/badge_obtainium.png" height="56" alt="Get it on Obtainium"></a>
|
||||
<a href="https://github.com/kalarina-bit/Matewave/releases/latest"><img src="assets/get-it-on-github.png" height="56" alt="Get it on GitHub"></a>
|
||||
<a href="https://git.skysparkle.cc/kalarina/Matewave/releases"><img src="assets/get-it-on-gitea.png" height="56" alt="Get it on Gitea"></a>
|
||||
</p>
|
||||
|
||||
## Features
|
||||
<p align="center">
|
||||
<img src="assets/screenshots/5-move-count.png" width="160" alt="Make your next move count">
|
||||
<img src="assets/screenshots/4-home.png" width="160" alt="Home screen">
|
||||
<img src="assets/screenshots/1-friendly-matches.png" width="160" alt="From solo games to friendly matches">
|
||||
<img src="assets/screenshots/3-play-together.png" width="160" alt="Play together">
|
||||
<img src="assets/screenshots/2-keep-growing.png" width="160" alt="Keep growing">
|
||||
</p>
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- 🤖 **AI opponent** with adjustable difficulty
|
||||
- 🧩 **Puzzles** and tactical training
|
||||
@@ -28,27 +39,13 @@ Play against the AI, solve puzzles, learn openings, or play friends nearby over
|
||||
- 🌙 **Dark theme**
|
||||
- 🌍 **Six languages** — English, Russian, German, Japanese, Lithuanian and Chinese
|
||||
|
||||
## Screenshots
|
||||
## <img src="assets/icon-install.png" width="32" alt=""> Installation
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/screenshots/5-move-count.png" width="200" alt="Make your next move count">
|
||||
<img src="assets/screenshots/4-home.png" width="200" alt="Home screen">
|
||||
<img src="assets/screenshots/1-friendly-matches.png" width="200" alt="From solo games to friendly matches">
|
||||
<img src="assets/screenshots/3-play-together.png" width="200" alt="Play together">
|
||||
<img src="assets/screenshots/2-keep-growing.png" width="200" alt="Keep growing">
|
||||
</p>
|
||||
- **[F-Droid](https://f-droid.org/packages/cc.skysparkle.matewave/)** — install and update through the F-Droid client.
|
||||
- **[Obtainium](https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://git.skysparkle.cc/kalarina/Matewave)** — installs the APK straight from Gitea releases and keeps it up to date.
|
||||
- **Manually** — download the latest APK from [GitHub](https://github.com/kalarina-bit/Matewave/releases/latest) or [Gitea](https://git.skysparkle.cc/kalarina/Matewave/releases), allow installs from unknown sources for the app you open it with (Settings → Apps → Special access → Install unknown apps), then open the `.apk` and confirm.
|
||||
|
||||
## Installation
|
||||
|
||||
<img src="assets/icon-install.png" width="36" align="left">
|
||||
|
||||
1. Download the latest APK from the [Releases page](https://git.skysparkle.cc/kalarina/Matewave/releases).
|
||||
2. Allow installs from unknown sources for the app you open it with (Settings → Apps → Special access → Install unknown apps).
|
||||
3. Open the `.apk` file and confirm the install.
|
||||
|
||||
## Verifying a download
|
||||
|
||||
<img src="assets/icon-verify.png" width="36" align="left">
|
||||
## <img src="assets/icon-verify.png" width="32" alt=""> Verifying a download
|
||||
|
||||
Every official APK is signed with the same key. Check it before installing:
|
||||
|
||||
@@ -64,7 +61,7 @@ The SHA-256 fingerprint of the signing certificate must be:
|
||||
|
||||
`apksigner` prints the same value in lowercase without colons. On Android you can check it with [AppVerifier](https://github.com/soupslurpr/AppVerifier) (app ID `cc.skysparkle.matewave`).
|
||||
|
||||
## Building from source
|
||||
## <img src="assets/icon-structure.png" width="32" alt=""> Building from source
|
||||
|
||||
Requires JDK 17+ and Android Studio with AGP 9.2 support.
|
||||
|
||||
@@ -75,10 +72,10 @@ Requires JDK 17+ and Android Studio with AGP 9.2 support.
|
||||
|
||||
Nearby multiplayer needs two physical devices — the emulator has no real Bluetooth, and mDNS discovery is often blocked on emulator networks.
|
||||
|
||||
## Contributing
|
||||
## 🤝 Contributing
|
||||
|
||||
Bug reports, puzzle and opening fixes, translation fixes and pull requests are welcome in the [issue tracker](https://git.skysparkle.cc/kalarina/Matewave/issues). Please read [CONTRIBUTING.md](CONTRIBUTING.md) first — it explains what fits the project and how to send changes. To open an issue or a pull request, [create an account](https://git.skysparkle.cc/user/sign_up) on this Gitea.
|
||||
|
||||
## License
|
||||
## 📄 License
|
||||
|
||||
[GNU General Public License v3.0 or later](LICENSE).
|
||||
|
||||
@@ -13,8 +13,8 @@ android {
|
||||
applicationId = "cc.skysparkle.matewave"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 2
|
||||
versionName = "1.0.44"
|
||||
versionCode = 3
|
||||
versionName = "1.0.45"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
@@ -260,6 +260,7 @@ private fun AppNavHost() {
|
||||
}
|
||||
|
||||
composable("game") {
|
||||
PlayScreenMusic()
|
||||
GameScreen(
|
||||
viewModel = viewModel,
|
||||
onExit = { navController.popBackStack("menu", inclusive = false) }
|
||||
@@ -267,6 +268,7 @@ private fun AppNavHost() {
|
||||
}
|
||||
|
||||
composable("openingStudy") {
|
||||
PlayScreenMusic()
|
||||
cc.skysparkle.matewave.ui.screens.OpeningStudyScreen(
|
||||
viewModel = studyViewModel,
|
||||
onBack = { navController.popBackStack() },
|
||||
@@ -275,6 +277,7 @@ private fun AppNavHost() {
|
||||
}
|
||||
|
||||
composable("openingTrainer") {
|
||||
PlayScreenMusic()
|
||||
cc.skysparkle.matewave.ui.screens.OpeningTrainerScreen(
|
||||
viewModel = studyViewModel,
|
||||
onBack = { navController.popBackStack() }
|
||||
@@ -282,6 +285,7 @@ private fun AppNavHost() {
|
||||
}
|
||||
|
||||
composable("puzzleSolve") {
|
||||
PlayScreenMusic()
|
||||
PuzzleSolveScreen(
|
||||
viewModel = viewModel,
|
||||
onBack = { navController.popBackStack("menu", inclusive = false) },
|
||||
@@ -355,3 +359,12 @@ private fun sharedAxisOut(forward: Boolean): androidx.compose.animation.ExitTran
|
||||
androidx.compose.animation.fadeOut(
|
||||
androidx.compose.animation.core.tween(durationMillis = 120, easing = androidx.compose.animation.core.LinearEasing)
|
||||
)
|
||||
|
||||
// Offline music switches to the game track while a game, puzzle or opening study is open
|
||||
@Composable
|
||||
private fun PlayScreenMusic() {
|
||||
androidx.compose.runtime.DisposableEffect(Unit) {
|
||||
SoundManager.enterPlayScreen()
|
||||
onDispose { SoundManager.leavePlayScreen() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import android.media.AudioFocusRequest
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaPlayer
|
||||
import android.media.SoundPool
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
@@ -25,11 +28,13 @@ object SoundManager {
|
||||
"https://stream.srg-ssr.ch/srgssr/rsj/aac/96"
|
||||
)
|
||||
|
||||
// Played instead of the radio when it can't be reached
|
||||
private const val MENU_TRACK = "music/midnight_grove_conversations.ogg"
|
||||
private const val PLAY_TRACK = "music/raindrops_and_pawns.ogg"
|
||||
|
||||
private const val PREFS = "chess_sound_prefs"
|
||||
private const val KEY_MUSIC = "music_enabled"
|
||||
private const val KEY_SFX = "sfx_enabled"
|
||||
private const val KEY_MENU_MUSIC = "menu_music_enabled"
|
||||
private const val MENU_MUSIC_DIR = "music"
|
||||
private const val TAG = "SoundManager"
|
||||
|
||||
private const val RADIO_START_DELAY_MS = 1_500L
|
||||
@@ -47,45 +52,46 @@ object SoundManager {
|
||||
private var sourceIndex = 0
|
||||
private var connectTimeoutRunnable: Runnable? = null
|
||||
private var audioManager: AudioManager? = null
|
||||
private var connectivity: ConnectivityManager? = null
|
||||
private var networkCallbackRegistered = false
|
||||
private var focusRequest: AudioFocusRequest? = null
|
||||
private var focusGranted = false
|
||||
private var noisyReceiverRegistered = false
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
private var offlinePlayer: MediaPlayer? = null
|
||||
private var offlinePrepared = false
|
||||
private var offlineTrack: String? = null
|
||||
private var playScreens = 0
|
||||
private var appInForeground = false
|
||||
|
||||
/** Jazz radio. Off until the user turns it on, so nothing connects on start. */
|
||||
var musicEnabled: Boolean = false
|
||||
private set
|
||||
/** Bundled tracks on the main screen, used while the radio is off. */
|
||||
var menuMusicEnabled: Boolean = true
|
||||
private set
|
||||
var sfxEnabled: Boolean = true
|
||||
private set
|
||||
|
||||
private val _radioState = MutableStateFlow(RadioState.IDLE)
|
||||
val radioState: StateFlow<RadioState> = _radioState
|
||||
|
||||
private var menuPlayer: MediaPlayer? = null
|
||||
private var menuPrepared = false
|
||||
private var menuTracks: List<String> = emptyList()
|
||||
private var menuTrackIndex = 0
|
||||
private var menuVisible = false
|
||||
private var appInForeground = false
|
||||
|
||||
private fun pauseRadio() {
|
||||
val player = musicPlayer ?: return
|
||||
if (playerPrepared) runCatching { if (player.isPlaying) player.pause() }
|
||||
private fun setRadioState(state: RadioState) {
|
||||
_radioState.value = state
|
||||
updateOfflineMusic()
|
||||
}
|
||||
|
||||
private fun pauseMenuMusic() {
|
||||
val player = menuPlayer ?: return
|
||||
if (menuPrepared) runCatching { if (player.isPlaying) player.pause() }
|
||||
private fun pauseAll() {
|
||||
musicPlayer?.let { player -> if (playerPrepared) runCatching { if (player.isPlaying) player.pause() } }
|
||||
offlinePlayer?.let { player -> if (offlinePrepared) runCatching { if (player.isPlaying) player.pause() } }
|
||||
}
|
||||
|
||||
private fun setVolumeAll(volume: Float) {
|
||||
runCatching { musicPlayer?.setVolume(volume, volume) }
|
||||
runCatching { offlinePlayer?.setVolume(volume, volume) }
|
||||
}
|
||||
|
||||
private val noisyReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) {
|
||||
pauseRadio()
|
||||
pauseMenuMusic()
|
||||
}
|
||||
if (intent.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) pauseAll()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,27 +99,33 @@ object SoundManager {
|
||||
when (change) {
|
||||
AudioManager.AUDIOFOCUS_LOSS -> {
|
||||
stopRadioInternal()
|
||||
releaseMenuPlayer()
|
||||
releaseOfflinePlayer()
|
||||
abandonAudioFocus()
|
||||
}
|
||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
|
||||
pauseRadio()
|
||||
pauseMenuMusic()
|
||||
}
|
||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
|
||||
runCatching { musicPlayer?.setVolume(BASE_VOLUME * 0.3f, BASE_VOLUME * 0.3f) }
|
||||
runCatching { menuPlayer?.setVolume(BASE_VOLUME * 0.3f, BASE_VOLUME * 0.3f) }
|
||||
focusGranted = false
|
||||
pauseAll()
|
||||
}
|
||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> setVolumeAll(BASE_VOLUME * 0.3f)
|
||||
AudioManager.AUDIOFOCUS_GAIN -> {
|
||||
focusGranted = true
|
||||
setVolumeAll(BASE_VOLUME)
|
||||
val player = musicPlayer
|
||||
if (player != null && playerPrepared) runCatching {
|
||||
player.setVolume(BASE_VOLUME, BASE_VOLUME)
|
||||
if (!player.isPlaying) player.start()
|
||||
if (player != null && playerPrepared) runCatching { if (!player.isPlaying) player.start() }
|
||||
val offline = offlinePlayer
|
||||
if (offline != null && offlinePrepared && shouldPlayOffline()) {
|
||||
runCatching { if (!offline.isPlaying) offline.start() }
|
||||
}
|
||||
val menu = menuPlayer
|
||||
if (menu != null && menuPrepared && menuVisible) runCatching {
|
||||
menu.setVolume(BASE_VOLUME, BASE_VOLUME)
|
||||
if (!menu.isPlaying) menu.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Brings the radio back once the device is online again
|
||||
private val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
mainHandler.post {
|
||||
if (musicEnabled && appInForeground && musicPlayer == null && _radioState.value == RadioState.ERROR) {
|
||||
startRadio()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,14 +137,11 @@ object SoundManager {
|
||||
val ctx = context.applicationContext
|
||||
appContext = ctx
|
||||
audioManager = ctx.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
|
||||
connectivity = ctx.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
|
||||
|
||||
val prefs = ctx.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
musicEnabled = prefs.getBoolean(KEY_MUSIC, false)
|
||||
sfxEnabled = prefs.getBoolean(KEY_SFX, true)
|
||||
menuMusicEnabled = prefs.getBoolean(KEY_MENU_MUSIC, true)
|
||||
menuTracks = runCatching {
|
||||
ctx.assets.list(MENU_MUSIC_DIR)?.filter { it.endsWith(".ogg") || it.endsWith(".mp3") }?.sorted()
|
||||
}.getOrNull().orEmpty()
|
||||
|
||||
ensureSoundPool(ctx)
|
||||
|
||||
@@ -143,23 +152,27 @@ object SoundManager {
|
||||
|
||||
private fun requestAudioFocus(): Boolean {
|
||||
val am = audioManager ?: return false
|
||||
if (focusRequest != null) return true
|
||||
val attrs = AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
val request = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
|
||||
.setAudioAttributes(attrs)
|
||||
if (focusGranted) return true
|
||||
// Asked again after a denial or a transient loss, e.g. during a phone call
|
||||
val request = focusRequest ?: AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
|
||||
.setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
)
|
||||
.setOnAudioFocusChangeListener(focusChangeListener, mainHandler)
|
||||
.build()
|
||||
focusRequest = request
|
||||
return am.requestAudioFocus(request) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
|
||||
.also { focusRequest = it }
|
||||
focusGranted = am.requestAudioFocus(request) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
|
||||
return focusGranted
|
||||
}
|
||||
|
||||
private fun abandonAudioFocus() {
|
||||
val am = audioManager ?: return
|
||||
focusRequest?.let { am.abandonAudioFocusRequest(it) }
|
||||
focusRequest = null
|
||||
focusGranted = false
|
||||
}
|
||||
|
||||
private fun registerNoisyReceiver() {
|
||||
@@ -182,22 +195,47 @@ object SoundManager {
|
||||
noisyReceiverRegistered = false
|
||||
}
|
||||
|
||||
private fun registerNetworkCallback() {
|
||||
val cm = connectivity ?: return
|
||||
if (networkCallbackRegistered) return
|
||||
runCatching { cm.registerDefaultNetworkCallback(networkCallback) }
|
||||
.onSuccess { networkCallbackRegistered = true }
|
||||
}
|
||||
|
||||
private fun unregisterNetworkCallback() {
|
||||
val cm = connectivity ?: return
|
||||
if (!networkCallbackRegistered) return
|
||||
runCatching { cm.unregisterNetworkCallback(networkCallback) }
|
||||
networkCallbackRegistered = false
|
||||
}
|
||||
|
||||
private fun isOnline(): Boolean {
|
||||
val cm = connectivity ?: return true
|
||||
val caps = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false
|
||||
return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
}
|
||||
|
||||
private fun startRadio() {
|
||||
val ctx = appContext ?: return
|
||||
if (musicPlayer != null) return
|
||||
releaseMenuPlayer()
|
||||
if (!requestAudioFocus()) {
|
||||
Log.w(TAG, "Audio focus denied, radio not started")
|
||||
_radioState.value = RadioState.ERROR
|
||||
setRadioState(RadioState.ERROR)
|
||||
return
|
||||
}
|
||||
registerNoisyReceiver()
|
||||
registerNetworkCallback()
|
||||
retryCount = 0
|
||||
if (!isOnline()) {
|
||||
// No point waiting for timeouts: play offline music until the network is back
|
||||
setRadioState(RadioState.ERROR)
|
||||
return
|
||||
}
|
||||
connect(ctx)
|
||||
}
|
||||
|
||||
private fun connect(ctx: Context) {
|
||||
_radioState.value = RadioState.CONNECTING
|
||||
setRadioState(RadioState.CONNECTING)
|
||||
val url = RADIO_SOURCES[sourceIndex % RADIO_SOURCES.size]
|
||||
try {
|
||||
val player = MediaPlayer()
|
||||
@@ -214,9 +252,9 @@ object SoundManager {
|
||||
player.setOnPreparedListener {
|
||||
cancelConnectTimeout()
|
||||
playerPrepared = true
|
||||
it.start()
|
||||
retryCount = 0
|
||||
_radioState.value = RadioState.PLAYING
|
||||
if (appInForeground) it.start()
|
||||
setRadioState(RadioState.PLAYING)
|
||||
}
|
||||
player.setOnErrorListener { mp, _, _ ->
|
||||
cancelConnectTimeout()
|
||||
@@ -272,18 +310,18 @@ object SoundManager {
|
||||
private fun scheduleRetry(ctx: Context) {
|
||||
cancelConnectTimeout()
|
||||
if (!musicEnabled) {
|
||||
_radioState.value = RadioState.IDLE
|
||||
setRadioState(RadioState.IDLE)
|
||||
return
|
||||
}
|
||||
if (retryCount >= MAX_RETRIES) {
|
||||
_radioState.value = RadioState.ERROR
|
||||
Log.w(TAG, "Could not connect to the radio after $MAX_RETRIES attempts")
|
||||
if (retryCount >= MAX_RETRIES || !isOnline()) {
|
||||
if (retryCount >= MAX_RETRIES) Log.w(TAG, "Could not connect to the radio after $MAX_RETRIES attempts")
|
||||
setRadioState(RadioState.ERROR)
|
||||
return
|
||||
}
|
||||
sourceIndex++
|
||||
val delay = RETRY_DELAYS_MS.getOrElse(retryCount) { RETRY_DELAYS_MS.last() }
|
||||
retryCount++
|
||||
_radioState.value = RadioState.CONNECTING
|
||||
setRadioState(RadioState.CONNECTING)
|
||||
mainHandler.postDelayed({
|
||||
if (musicEnabled && musicPlayer == null) connect(ctx)
|
||||
}, delay)
|
||||
@@ -295,22 +333,22 @@ object SoundManager {
|
||||
musicPlayer = null
|
||||
playerPrepared = false
|
||||
unregisterNoisyReceiver()
|
||||
unregisterNetworkCallback()
|
||||
abandonAudioFocus()
|
||||
mainHandler.removeCallbacksAndMessages(null)
|
||||
_radioState.value = RadioState.IDLE
|
||||
setRadioState(RadioState.IDLE)
|
||||
}
|
||||
|
||||
fun onAppResumed() {
|
||||
appInForeground = true
|
||||
if (musicEnabled && musicPlayer == null) startRadio()
|
||||
updateMenuMusic()
|
||||
updateOfflineMusic()
|
||||
}
|
||||
|
||||
fun onAppPaused() {
|
||||
appInForeground = false
|
||||
releaseOfflinePlayer()
|
||||
stopRadioInternal()
|
||||
releaseMenuPlayer()
|
||||
abandonAudioFocus()
|
||||
}
|
||||
|
||||
fun setMusicEnabled(enabled: Boolean) {
|
||||
@@ -320,97 +358,86 @@ object SoundManager {
|
||||
if (enabled) {
|
||||
startRadio()
|
||||
} else {
|
||||
releaseOfflinePlayer()
|
||||
stopRadioInternal()
|
||||
updateMenuMusic()
|
||||
}
|
||||
}
|
||||
|
||||
fun setMenuMusicEnabled(enabled: Boolean) {
|
||||
menuMusicEnabled = enabled
|
||||
appContext?.getSharedPreferences(PREFS, Context.MODE_PRIVATE)?.edit()
|
||||
?.putBoolean(KEY_MENU_MUSIC, enabled)?.apply()
|
||||
updateMenuMusic()
|
||||
/** Games, puzzles and opening study call this while they are on screen. */
|
||||
fun enterPlayScreen() {
|
||||
playScreens++
|
||||
updateOfflineMusic()
|
||||
}
|
||||
|
||||
/** Called by the main screen when it appears and disappears. */
|
||||
fun setMenuVisible(visible: Boolean) {
|
||||
menuVisible = visible
|
||||
updateMenuMusic()
|
||||
fun leavePlayScreen() {
|
||||
playScreens = maxOf(0, playScreens - 1)
|
||||
updateOfflineMusic()
|
||||
}
|
||||
|
||||
private fun updateMenuMusic() {
|
||||
val shouldPlay = menuMusicEnabled && !musicEnabled && menuVisible && appInForeground
|
||||
if (shouldPlay) startMenuMusic() else pauseMenuMusicAndFocus()
|
||||
// The radio is on but can't be reached: no network, or the first attempt already failed
|
||||
private fun radioUnavailable(): Boolean = when (_radioState.value) {
|
||||
RadioState.ERROR -> true
|
||||
RadioState.CONNECTING -> retryCount > 0
|
||||
else -> false
|
||||
}
|
||||
|
||||
private fun pauseMenuMusicAndFocus() {
|
||||
pauseMenuMusic()
|
||||
if (!musicEnabled) abandonAudioFocus()
|
||||
}
|
||||
private fun shouldPlayOffline() = musicEnabled && appInForeground && radioUnavailable()
|
||||
|
||||
private fun startMenuMusic() {
|
||||
if (menuTracks.isEmpty()) return
|
||||
val player = menuPlayer
|
||||
if (player != null) {
|
||||
if (menuPrepared && !player.isPlaying && requestAudioFocus()) {
|
||||
registerNoisyReceiver()
|
||||
runCatching { player.setVolume(BASE_VOLUME, BASE_VOLUME); player.start() }
|
||||
}
|
||||
private fun updateOfflineMusic() {
|
||||
if (!shouldPlayOffline()) {
|
||||
releaseOfflinePlayer()
|
||||
return
|
||||
}
|
||||
// Never cut off music another app is already playing.
|
||||
if (audioManager?.isMusicActive == true) return
|
||||
val track = if (playScreens > 0) PLAY_TRACK else MENU_TRACK
|
||||
val player = offlinePlayer
|
||||
if (player != null && offlineTrack == track) {
|
||||
if (offlinePrepared && !player.isPlaying && requestAudioFocus()) runCatching { player.start() }
|
||||
return
|
||||
}
|
||||
releaseOfflinePlayer()
|
||||
if (!requestAudioFocus()) return
|
||||
registerNoisyReceiver()
|
||||
playMenuTrack(menuTrackIndex)
|
||||
playOfflineTrack(track)
|
||||
}
|
||||
|
||||
private fun playMenuTrack(index: Int) {
|
||||
private fun playOfflineTrack(track: String) {
|
||||
val ctx = appContext ?: return
|
||||
if (menuTracks.isEmpty()) return
|
||||
val name = menuTracks[index % menuTracks.size]
|
||||
try {
|
||||
val player = MediaPlayer()
|
||||
menuPlayer = player
|
||||
menuPrepared = false
|
||||
offlinePlayer = player
|
||||
offlineTrack = track
|
||||
offlinePrepared = false
|
||||
player.setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
)
|
||||
ctx.assets.openFd("$MENU_MUSIC_DIR/$name").use { fd ->
|
||||
ctx.assets.openFd(track).use { fd ->
|
||||
player.setDataSource(fd.fileDescriptor, fd.startOffset, fd.length)
|
||||
}
|
||||
player.isLooping = true
|
||||
player.setVolume(BASE_VOLUME, BASE_VOLUME)
|
||||
player.setOnPreparedListener {
|
||||
menuPrepared = true
|
||||
if (menuVisible && appInForeground && menuMusicEnabled && !musicEnabled) it.start()
|
||||
}
|
||||
player.setOnCompletionListener { mp ->
|
||||
if (menuPlayer === mp) {
|
||||
releaseMenuPlayer()
|
||||
menuTrackIndex = (menuTrackIndex + 1) % menuTracks.size
|
||||
if (menuVisible && appInForeground && menuMusicEnabled && !musicEnabled) {
|
||||
playMenuTrack(menuTrackIndex)
|
||||
}
|
||||
}
|
||||
offlinePrepared = true
|
||||
if (shouldPlayOffline() && focusGranted) it.start()
|
||||
}
|
||||
player.setOnErrorListener { mp, _, _ ->
|
||||
if (menuPlayer === mp) releaseMenuPlayer()
|
||||
if (offlinePlayer === mp) releaseOfflinePlayer()
|
||||
true
|
||||
}
|
||||
player.prepareAsync()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Menu music error ($name): ${e.message}")
|
||||
releaseMenuPlayer()
|
||||
Log.w(TAG, "Offline music error ($track): ${e.message}")
|
||||
releaseOfflinePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
private fun releaseMenuPlayer() {
|
||||
try { menuPlayer?.release() } catch (_: Exception) {}
|
||||
menuPlayer = null
|
||||
menuPrepared = false
|
||||
private fun releaseOfflinePlayer() {
|
||||
try { offlinePlayer?.release() } catch (_: Exception) {}
|
||||
offlinePlayer = null
|
||||
offlineTrack = null
|
||||
offlinePrepared = false
|
||||
}
|
||||
|
||||
fun setSfxEnabled(enabled: Boolean) {
|
||||
|
||||
@@ -84,10 +84,6 @@ fun MainMenuScreen(
|
||||
onFriendsClick: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
androidx.compose.runtime.DisposableEffect(Unit) {
|
||||
cc.skysparkle.matewave.audio.SoundManager.setMenuVisible(true)
|
||||
onDispose { cc.skysparkle.matewave.audio.SoundManager.setMenuVisible(false) }
|
||||
}
|
||||
val resumable by viewModel.resumable.collectAsState()
|
||||
val ongoing = resumable
|
||||
val hasOngoingGame = ongoing != null
|
||||
|
||||
@@ -60,7 +60,6 @@ fun SettingsScreen(
|
||||
onOpenShare: () -> Unit
|
||||
) {
|
||||
var musicOn by remember { mutableStateOf(SoundManager.musicEnabled) }
|
||||
var menuMusicOn by remember { mutableStateOf(SoundManager.menuMusicEnabled) }
|
||||
var sfxOn by remember { mutableStateOf(SoundManager.sfxEnabled) }
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -83,6 +82,11 @@ fun SettingsScreen(
|
||||
val status = remember(statusTick) {
|
||||
cc.skysparkle.matewave.network.NetworkRequirements.check(context)
|
||||
}
|
||||
// Wi-Fi alone used to count as "All set" even with the nearby permission denied
|
||||
val permissionsMissing = remember(statusTick) {
|
||||
!status.permissionsGranted ||
|
||||
(cc.skysparkle.matewave.presence.PresenceSettings(context).backgroundEnabled && !status.notificationsGranted)
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) { kotlinx.coroutines.delay(3_000); statusTick++ }
|
||||
}
|
||||
@@ -107,13 +111,6 @@ fun SettingsScreen(
|
||||
) {
|
||||
SectionCaption(stringResource(R.string.settings_section_sound))
|
||||
ListGroup {
|
||||
ListRow(
|
||||
title = stringResource(R.string.settings_menu_music),
|
||||
subtitle = stringResource(R.string.settings_menu_music_subtitle),
|
||||
icon = R.drawable.ic_music,
|
||||
trailing = { SettingSwitch(menuMusicOn) { menuMusicOn = it; SoundManager.setMenuMusicEnabled(it) } }
|
||||
)
|
||||
ListDivider()
|
||||
ListRow(
|
||||
title = stringResource(R.string.settings_radio),
|
||||
subtitle = stringResource(R.string.settings_radio_subtitle),
|
||||
@@ -157,10 +154,10 @@ fun SettingsScreen(
|
||||
ListGroup {
|
||||
ListRow(
|
||||
title = stringResource(R.string.permissions_card_title),
|
||||
icon = if (status.onlineBlocked) R.drawable.ic_permissions else R.drawable.ic_check_permission,
|
||||
iconTint = if (status.onlineBlocked) Color(0xFFFF6B6B) else ChessGreen,
|
||||
value = stringResource(if (status.onlineBlocked) R.string.permissions_card_blocked_short else R.string.permissions_card_ok_short),
|
||||
valueColor = if (status.onlineBlocked) Color(0xFFFF6B6B) else ink.copy(alpha = 0.55f),
|
||||
icon = if (permissionsMissing) R.drawable.ic_permissions else R.drawable.ic_check_permission,
|
||||
iconTint = if (permissionsMissing) Color(0xFFFF6B6B) else ChessGreen,
|
||||
value = stringResource(if (permissionsMissing) R.string.permissions_card_blocked_short else R.string.permissions_card_ok_short),
|
||||
valueColor = if (permissionsMissing) Color(0xFFFF6B6B) else ink.copy(alpha = 0.55f),
|
||||
chevron = true,
|
||||
onClick = onOpenPermissions
|
||||
)
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
<string name="settings_version">Version %1$s</string>
|
||||
<string name="settings_repo_title">Quellcode</string>
|
||||
<string name="settings_radio">Jazzradio</string>
|
||||
<string name="settings_radio_subtitle">Internetradio im Hintergrund statt Stille</string>
|
||||
<string name="settings_radio_subtitle">Radio Swiss Jazz. Ohne Verbindung läuft eingebaute Musik</string>
|
||||
<string name="settings_radio_connecting">Verbinde...</string>
|
||||
<string name="settings_radio_error">Verbindung fehlgeschlagen</string>
|
||||
<string name="settings_radio_error">Keine Verbindung, eingebaute Musik</string>
|
||||
<string name="settings_sfx">Soundeffekte</string>
|
||||
<string name="settings_sfx_subtitle">Figur wählen, ziehen, schlagen</string>
|
||||
<string name="back">Zurück</string>
|
||||
@@ -354,8 +354,6 @@
|
||||
<string name="nearby_bt_off_hint">Schalte es ein, um Spieler per Bluetooth zu finden</string>
|
||||
<string name="nearby_wifi_hint">Spieler im selben WLAN werden erst gefunden, wenn du verbunden bist</string>
|
||||
<string name="permission_open_settings">Einstellungen öffnen</string>
|
||||
<string name="settings_menu_music">Menümusik</string>
|
||||
<string name="settings_menu_music_subtitle">Ruhige Musik auf dem Startbildschirm, solange das Radio aus ist</string>
|
||||
<string name="piece_queen">Dame</string>
|
||||
<string name="piece_rook">Turm</string>
|
||||
<string name="piece_bishop">Läufer</string>
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
<string name="settings_version">バージョン %1$s</string>
|
||||
<string name="settings_repo_title">ソースコード</string>
|
||||
<string name="settings_radio">ジャズラジオ</string>
|
||||
<string name="settings_radio_subtitle">無音のかわりにインターネットラジオをバックグラウンドで再生</string>
|
||||
<string name="settings_radio_subtitle">Radio Swiss Jazz。接続がないときは内蔵の音楽を再生</string>
|
||||
<string name="settings_radio_connecting">接続中...</string>
|
||||
<string name="settings_radio_error">接続できませんでした</string>
|
||||
<string name="settings_radio_error">接続なし・内蔵の音楽</string>
|
||||
<string name="settings_sfx">効果音</string>
|
||||
<string name="settings_sfx_subtitle">駒の選択、移動、取る音</string>
|
||||
<string name="back">戻る</string>
|
||||
@@ -353,8 +353,6 @@
|
||||
<string name="nearby_bt_off_hint">オンにすると、Bluetoothでプレイヤーを探せます</string>
|
||||
<string name="nearby_wifi_hint">接続するまで、同じWi-Fiのプレイヤーは見つかりません</string>
|
||||
<string name="permission_open_settings">設定を開く</string>
|
||||
<string name="settings_menu_music">メニューの音楽</string>
|
||||
<string name="settings_menu_music_subtitle">ラジオがオフのとき、ホーム画面で穏やかな音楽を流します</string>
|
||||
<string name="piece_queen">クイーン</string>
|
||||
<string name="piece_rook">ルーク</string>
|
||||
<string name="piece_bishop">ビショップ</string>
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
<string name="settings_version">Versija %1$s</string>
|
||||
<string name="settings_repo_title">Šaltinio kodas</string>
|
||||
<string name="settings_radio">Džiazo radijas</string>
|
||||
<string name="settings_radio_subtitle">Interneto radijas fone vietoj tylos</string>
|
||||
<string name="settings_radio_subtitle">Radio Swiss Jazz. Be ryšio groja įdiegta muzika</string>
|
||||
<string name="settings_radio_connecting">Jungiamasi...</string>
|
||||
<string name="settings_radio_error">Nepavyko prisijungti</string>
|
||||
<string name="settings_radio_error">Nėra ryšio, įdiegta muzika</string>
|
||||
<string name="settings_sfx">Garso efektai</string>
|
||||
<string name="settings_sfx_subtitle">Figūros pasirinkimas, ėjimas, paėmimas</string>
|
||||
<string name="back">Atgal</string>
|
||||
@@ -356,8 +356,6 @@
|
||||
<string name="nearby_bt_off_hint">Įjunkite, kad rastumėte žaidėjus per „Bluetooth“</string>
|
||||
<string name="nearby_wifi_hint">Žaidėjų tame pačiame „Wi-Fi“ tinkle nerasite, kol neprisijungsite</string>
|
||||
<string name="permission_open_settings">Atidaryti nustatymus</string>
|
||||
<string name="settings_menu_music">Meniu muzika</string>
|
||||
<string name="settings_menu_music_subtitle">Rami muzika pagrindiniame ekrane, kol radijas išjungtas</string>
|
||||
<string name="piece_queen">Valdovė</string>
|
||||
<string name="piece_rook">Bokštas</string>
|
||||
<string name="piece_bishop">Rikis</string>
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
<string name="settings_version">Версия %1$s</string>
|
||||
<string name="settings_repo_title">Исходный код</string>
|
||||
<string name="settings_radio">Джаз-радио</string>
|
||||
<string name="settings_radio_subtitle">Фоновый интернет-эфир вместо тишины</string>
|
||||
<string name="settings_radio_subtitle">Radio Swiss Jazz. Без связи играет встроенная музыка</string>
|
||||
<string name="settings_radio_connecting">Подключение...</string>
|
||||
<string name="settings_radio_error">Не удалось подключиться</string>
|
||||
<string name="settings_radio_error">Нет связи, встроенная музыка</string>
|
||||
<string name="settings_sfx">Звуковые эффекты</string>
|
||||
<string name="settings_sfx_subtitle">Выбор фигуры, ход, взятие</string>
|
||||
<string name="back">Назад</string>
|
||||
@@ -362,8 +362,6 @@
|
||||
<string name="nearby_bt_off_hint">Включите, чтобы находить игроков по Bluetooth</string>
|
||||
<string name="nearby_wifi_hint">Игроков в той же сети Wi-Fi не найти, пока вы не подключитесь</string>
|
||||
<string name="permission_open_settings">Открыть настройки</string>
|
||||
<string name="settings_menu_music">Музыка в меню</string>
|
||||
<string name="settings_menu_music_subtitle">Спокойная музыка на главном экране, пока радио выключено</string>
|
||||
<string name="piece_queen">Ферзь</string>
|
||||
<string name="piece_rook">Ладья</string>
|
||||
<string name="piece_bishop">Слон</string>
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
<string name="settings_version">版本 %1$s</string>
|
||||
<string name="settings_repo_title">源代码</string>
|
||||
<string name="settings_radio">爵士电台</string>
|
||||
<string name="settings_radio_subtitle">在后台播放网络电台,告别寂静</string>
|
||||
<string name="settings_radio_subtitle">Radio Swiss Jazz。无网络时播放内置音乐</string>
|
||||
<string name="settings_radio_connecting">正在连接...</string>
|
||||
<string name="settings_radio_error">无法连接</string>
|
||||
<string name="settings_radio_error">无连接,播放内置音乐</string>
|
||||
<string name="settings_sfx">音效</string>
|
||||
<string name="settings_sfx_subtitle">选子、走子、吃子</string>
|
||||
<string name="back">返回</string>
|
||||
@@ -353,8 +353,6 @@
|
||||
<string name="nearby_bt_off_hint">开启后即可通过蓝牙查找玩家</string>
|
||||
<string name="nearby_wifi_hint">连接 Wi-Fi 后才能找到同一网络中的玩家</string>
|
||||
<string name="permission_open_settings">打开设置</string>
|
||||
<string name="settings_menu_music">菜单音乐</string>
|
||||
<string name="settings_menu_music_subtitle">电台关闭时,在主屏幕播放舒缓的音乐</string>
|
||||
<string name="piece_queen">后</string>
|
||||
<string name="piece_rook">车</string>
|
||||
<string name="piece_bishop">象</string>
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
<string name="settings_version">Version %1$s</string>
|
||||
<string name="settings_repo_title">Source code</string>
|
||||
<string name="settings_radio">Jazz radio</string>
|
||||
<string name="settings_radio_subtitle">Background internet radio instead of silence</string>
|
||||
<string name="settings_radio_subtitle">Radio Swiss Jazz. Without a connection, built-in music plays</string>
|
||||
<string name="settings_radio_connecting">Connecting...</string>
|
||||
<string name="settings_radio_error">Couldn\'t connect</string>
|
||||
<string name="settings_radio_error">No connection, built-in music</string>
|
||||
<string name="settings_sfx">Sound effects</string>
|
||||
<string name="settings_sfx_subtitle">Selecting a piece, moving, capturing</string>
|
||||
<string name="back">Back</string>
|
||||
@@ -354,8 +354,6 @@
|
||||
<string name="nearby_bt_off_hint">Turn it on to find players over Bluetooth</string>
|
||||
<string name="nearby_wifi_hint">Players on the same Wi-Fi network can\'t be found until you connect</string>
|
||||
<string name="permission_open_settings">Open settings</string>
|
||||
<string name="settings_menu_music">Menu music</string>
|
||||
<string name="settings_menu_music_subtitle">Calm music on the main screen while the radio is off</string>
|
||||
<string name="piece_queen">Queen</string>
|
||||
<string name="piece_rook">Rook</string>
|
||||
<string name="piece_bishop">Bishop</string>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
@@ -0,0 +1,3 @@
|
||||
• Eingebaute Musik, wenn das Jazzradio keine Verbindung hat, mit eigenem Stück für Partien und Aufgaben. Sie ersetzt die bisherige Menümusik
|
||||
• Musik spielt nicht mehr, während ein Anruf oder eine andere App den Ton nutzt
|
||||
• Die Einstellungen zeigen „Aktion nötig“, solange Berechtigungen fehlen
|
||||
@@ -0,0 +1,3 @@
|
||||
• Built-in music when the jazz radio has no connection, with its own track for games and puzzles. It replaces the separate menu music
|
||||
• Music no longer plays while a call or another app is using the sound
|
||||
• Settings show "Action needed" while permissions are missing
|
||||
@@ -0,0 +1,3 @@
|
||||
• ジャズラジオに接続できないときは内蔵の音楽を再生。対局とパズルには専用の曲。メニュー音楽はこれに置き換わりました
|
||||
• 通話や他のアプリが音声を使っている間は音楽を再生しません
|
||||
• 権限が足りない間、設定に「要対応」と表示されます
|
||||
@@ -0,0 +1,3 @@
|
||||
• Įdiegta muzika, kai džiazo radijas neturi ryšio, su atskiru kūriniu partijoms ir uždaviniams. Ji pakeitė atskirą meniu muziką
|
||||
• Muzika nebegroja, kol garsą naudoja skambutis ar kita programėlė
|
||||
• Nustatymuose rodoma „Reikia veiksmo“, kol trūksta leidimų
|
||||
@@ -0,0 +1,3 @@
|
||||
• Встроенная музыка, когда у джаз-радио нет связи, со своим треком для партий и задач. Она заменила отдельную музыку в меню
|
||||
• Музыка больше не играет, пока звук занят звонком или другим приложением
|
||||
• В настройках показывается «Нужно действие», пока не хватает разрешений
|
||||
@@ -0,0 +1,3 @@
|
||||
• 爵士电台无法连接时播放内置音乐,对局和谜题有专属曲目,取代了原来的菜单音乐
|
||||
• 通话或其他应用占用声音时不再播放音乐
|
||||
• 缺少权限时,设置中会显示“需要处理”
|
||||
Reference in New Issue
Block a user