Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into common-t…
Browse files Browse the repository at this point in the history
…o-jvm
  • Loading branch information
brahmkshatriya committed Aug 15, 2024
2 parents 64843c6 + 3da2547 commit 90f5fec
Show file tree
Hide file tree
Showing 16 changed files with 1,919 additions and 94 deletions.
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
# Echo : Music Player
# Echo: Music Player
An Extension based Music Player for Android, with a clean and simple UI.

> This is a work in progress, and is not yet ready for use.
> This is a work in progress and is not yet ready for use.
## DISCLAIMER

- The developer is not responsible for any misuse of this app, and is not responsible for any damages or legal implications caused by the use of this app.
- This app does not provide any download or streaming service from any online source.
- The developer is not responsible for any misuse of this app and is not responsible for any damages or legal implications caused by the use of this app.
- Echo only has offline source by default; external sources are managed by users. Echo does not endorse piracy.
- It was solely created for educational purposes.

## Official Discord Server

<a href="https://discord.gg/J3WvbBUU8Z"><img src="https://invidget.switchblade.xyz/J3WvbBUU8Z"></a>

## Wanna Donate?

<a href='https://ko-fi.com/I2I5C3UUV' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

## Official Communities

<p align="left" style="display: flex; align-items: center;">
<a href="https://discord.gg/J3WvbBUU8Z" style="margin-right: 10px; display: inline-block;"><img src="https://uxwing.com/wp-content/themes/uxwing/download/brands-and-social-media/discord-round-color-icon.png" alt="Discord" height="40" style="vertical-align: middle;"></a>
<a href="https://t.me/echo_extension" style="display: inline-block;"><img src="https://upload.wikimedia.org/wikipedia/commons/8/82/Telegram_logo.svg" alt="Telegram" height="40" style="vertical-align: middle;"></a>
</p>

## CONTRIBUTION
We would be very grateful if you could contribute to the development of this application. Everything from simple string translation to the implementation of new features is accepted. If you have any questions, please visit our <a href="https://discord.gg/J3WvbBUU8Z">Discord</a> server or <a href="https://t.me/echo_extension">Telegram</a> group.

<a href="https://hosted.weblate.org/engage/echo/"><img src="https://hosted.weblate.org/widget/echo/app/multi-auto.svg" alt="Translation status" /></a>

## Credits
A big thank you to everyone who has contributed to the development of Echo! Your efforts in improving the app are greatly appreciated.
<a href="https://github.com/brahmkshatriya/echo/graphs/contributors">
<img src="https://contrib.rocks/image?repo=brahmkshatriya/echo" />
</a>

## License

Echo is licensed under the [GNU General Public License v3.0](LICENSE.md)
Echo is licensed under the [GNU General Public License v3.0](LICENSE.md)
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ class PlayerSessionCallback(
val error = SessionResult(SessionResult.RESULT_ERROR_UNKNOWN)
val clientId = args.getString("clientId") ?: return@future error
val item = args.getParcel<EchoMediaItem>("item") ?: return@future error
radioFlow.value = Radio.State.Loading
val loaded = Radio.start(
context, messageFlow, throwableFlow, radioFlow, extensionList, clientId, item, 0
) ?: return@future error
context, messageFlow, throwableFlow, extensionList, clientId, item, 0
)
radioFlow.value = loaded ?: Radio.State.Empty
if (loaded == null) return@future error
val mediaItem = MediaItemUtils.build(
settings, loaded.tracks[0], loaded.clientId, loaded.playlist.toMediaItem()
)
Expand Down
16 changes: 6 additions & 10 deletions app/src/main/java/dev/brahmkshatriya/echo/playback/Radio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Radio(
context: Context,
messageFlow: MutableSharedFlow<SnackBar.Message>,
throwableFlow: MutableSharedFlow<Throwable>,
stateFlow: MutableStateFlow<State>,
extensionListFlow: StateFlow<List<MusicExtension>?>,
clientId: String,
item: EchoMediaItem,
Expand All @@ -74,8 +73,6 @@ class Radio(
}

else -> {
stateFlow.value = State.Loading

suspend fun <T> tryIO(block: suspend () -> T): T? =
withContext(Dispatchers.IO) {
tryWith(throwableFlow, extension.info) { block() }
Expand Down Expand Up @@ -107,10 +104,7 @@ class Radio(
)
null
}
stateFlow.value = state ?: State.Empty
return state
} else {
stateFlow.value = State.Empty
}
}
}
Expand All @@ -133,21 +127,23 @@ class Radio(
val mediaItem = player.currentMediaItem ?: return
val client = mediaItem.clientId
val item = mediaItem.context ?: mediaItem.track.toMediaItem()
stateFlow.value = State.Loading
scope.launch {
val loaded = start(
context, messageFlow, throwFlow, stateFlow, extensionList, client, item, 0
) ?: return@launch
play(loaded, 0)
val loaded = start(context, messageFlow, throwFlow, extensionList, client, item, 0)
stateFlow.value = loaded ?: State.Empty
if (loaded != null) play(loaded, 0)
}
}

private var autoStartRadio = true

init {
settings.registerOnSharedPreferenceChangeListener { pref, key ->
if (key == AUTO_START_RADIO)
autoStartRadio = pref.getBoolean(AUTO_START_RADIO, true)
}
}

private fun startRadio() {
if (!autoStartRadio) return
if (player.hasNextMediaItem() || player.currentMediaItem == null) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import com.google.android.material.checkbox.MaterialCheckBox
class CheckBoxListener(private val block: (Boolean) -> Unit) :
MaterialCheckBox.OnCheckedStateChangedListener {
var enabled = true
var checked = false
private var checked = false
private fun check(isChecked: Boolean) {
if(checked == isChecked) return
checked = isChecked
if (checked == isChecked) return
block(isChecked)
}

override fun onCheckedStateChangedListener(checkBox: MaterialCheckBox, state: Int) {
if (enabled) when (state) {
MaterialCheckBox.STATE_CHECKED -> check(true)
else -> check(false)
}
val isChecked = checkBox.isChecked
if (enabled) check(isChecked)
checked = isChecked
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class PlayerTrackAdapter(
binding.playerControls.trackHeart.run {
viewModel.isLiked.value = item.isLiked
isChecked = item.isLiked
viewModel.likeListener.checked = item.isLiked
val client = viewModel.extensionListFlow.getExtension(clientId)?.client
val isLibrary = client is LibraryClient
isVisible = isLibrary
Expand Down
Loading

0 comments on commit 90f5fec

Please sign in to comment.