From ca8e9357245a0e3c09b11cba18c23f19f8cb124c Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 23 Jul 2022 14:17:57 -0700 Subject: [PATCH] Modernized some calls and coding style. --- .../model/impl/remote/RemoteMetadataProxy.kt | 6 ++--- .../remote/ui/home/view/MainMetadataView.kt | 8 +++---- .../viewmodel/RemoteSettingsViewModel.kt | 24 +++++++++---------- .../remote/ui/shared/activity/BaseActivity.kt | 5 ++-- .../remote/ui/shared/extension/Extensions.kt | 6 ++--- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/websocket/model/impl/remote/RemoteMetadataProxy.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/websocket/model/impl/remote/RemoteMetadataProxy.kt index 069b718d2..18eb5b31f 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/websocket/model/impl/remote/RemoteMetadataProxy.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/websocket/model/impl/remote/RemoteMetadataProxy.kt @@ -395,7 +395,7 @@ class RemoteMetadataProxy(private val service: WebSocketService) : IMetadataProx .build() return service.observe(message, client) - .map { socketMessage -> isSuccessful(socketMessage) } + .map { socketMessage -> isSuccessful(socketMessage) } .observeOn(AndroidSchedulers.mainThread()) } @@ -414,7 +414,7 @@ class RemoteMetadataProxy(private val service: WebSocketService) : IMetadataProx .build() return service.observe(message, client) - .map { socketMessage -> toCount(socketMessage) } + .map { socketMessage -> toCount(socketMessage) } .observeOn(AndroidSchedulers.mainThread()) } @@ -430,7 +430,7 @@ class RemoteMetadataProxy(private val service: WebSocketService) : IMetadataProx .build() return service.observe(message, client) - .map { socketMessage -> isSuccessful(socketMessage) } + .map { socketMessage -> isSuccessful(socketMessage) } .observeOn(AndroidSchedulers.mainThread()) } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/view/MainMetadataView.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/view/MainMetadataView.kt index afe870a00..00275ce3e 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/view/MainMetadataView.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/view/MainMetadataView.kt @@ -131,12 +131,12 @@ class MainMetadataView : FrameLayout { this.volumeWithArt.text = volume } - this.title.text = if (title.isEmpty()) getString(if (buffering) R.string.buffering else R.string.unknown_title) else title - this.artist.text = if (artist.isEmpty()) getString(if (buffering) R.string.buffering else R.string.unknown_artist) else artist - this.album.text = if (album.isEmpty()) getString(if (buffering) R.string.buffering else R.string.unknown_album) else album + this.title.text = title.ifEmpty { getString(if (buffering) R.string.buffering else R.string.unknown_title) } + this.artist.text = artist.ifEmpty { getString(if (buffering) R.string.buffering else R.string.unknown_artist) } + this.album.text = album.ifEmpty { getString(if (buffering) R.string.buffering else R.string.unknown_album) } this.rebindAlbumArtistWithArtTextView(playback) - this.titleWithArt.text = if (title.isEmpty()) getString(if (buffering) R.string.buffering else R.string.unknown_title) else title + this.titleWithArt.text = title.ifEmpty { getString(if (buffering) R.string.buffering else R.string.unknown_title) } this.buffering.visibility = if (buffering) View.VISIBLE else View.GONE if (artist.isEmpty() || album.isEmpty()) { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/viewmodel/RemoteSettingsViewModel.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/viewmodel/RemoteSettingsViewModel.kt index c5027d799..61ce08ce2 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/viewmodel/RemoteSettingsViewModel.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/viewmodel/RemoteSettingsViewModel.kt @@ -95,8 +95,8 @@ class RemoteSettingsViewModel(private val environment: IEnvironment): BaseRemote val transportQuery = proxy.setTransportType(transport) Observable.zip( gainQuery, - transportQuery, - { b1, b2 -> b1 && b2 }) + transportQuery + ) { b1, b2 -> b1 && b2 } .observeOn(AndroidSchedulers.mainThread()) .subscribeBy( onNext = { success -> @@ -126,9 +126,9 @@ class RemoteSettingsViewModel(private val environment: IEnvironment): BaseRemote Observable.zip( gainQuery, outputQuery, - transportQuery, - { b1, b2, b3 -> b1 && b2 && b3 }) - .observeOn(AndroidSchedulers.mainThread()) + transportQuery + ) { b1, b2, b3 -> b1 && b2 && b3 } + .observeOn(AndroidSchedulers.mainThread()) .subscribeBy( onNext = { success -> if (success) { state = State.Saved } @@ -153,13 +153,13 @@ class RemoteSettingsViewModel(private val environment: IEnvironment): BaseRemote Observable.zip( gainQuery, outputsQuery, - transportQuery, - { gainSettings, outputs, transportType -> - this.gain = gainSettings - this.outputs = outputs - this.transportType = transportType - true - }) + transportQuery + ) { gainSettings, outputs, transportType -> + this.gain = gainSettings + this.outputs = outputs + this.transportType = transportType + true + } .observeOn(AndroidSchedulers.mainThread()) .subscribeBy( onNext = { state = State.Ready }, diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt index cc6776243..29de98ca4 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt @@ -163,12 +163,11 @@ abstract class BaseActivity : AppCompatActivity(), ViewModel.Provider, Runner.Ta private val top: Fragment? get() { - return when { - fm.backStackEntryCount == 0 -> + return when (fm.backStackEntryCount) { + 0 -> fm.findFragmentByTag(BrowseFragment.TAG) else -> fm.findFragmentByTag( fm.getBackStackEntryAt(fm.backStackEntryCount - 1).name) - } } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt index c96a3c3db..8f5cdf239 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt @@ -62,7 +62,7 @@ fun SharedPreferences.getString(key: String): String? = fun Toolbar.setTitleFromIntent(defaultTitle: String) { val extras = (context as? AppCompatActivity)?.intent?.extras ?: Bundle() val title = extras.getString(Shared.Extra.TITLE_OVERRIDE) ?: "" - this.title = if (title.isNotEmpty()) title else defaultTitle + this.title = title.ifEmpty { defaultTitle } } fun Toolbar.collapseActionViewIfExpanded(): Boolean { @@ -106,7 +106,7 @@ fun AppCompatActivity.enableUpNavigation() { fun AppCompatActivity.setTitleFromIntent(defaultTitle: String) { val title = this.intent.getStringExtra(Shared.Extra.TITLE_OVERRIDE) ?: "" - this.title = if (title.isNotEmpty()) title else defaultTitle + this.title = title.ifEmpty { defaultTitle } } fun BaseFragment.addFilterAction(menu: Menu, filterable: IFilterable?): Boolean { @@ -311,7 +311,7 @@ fun BaseFragment.setupDefaultRecyclerView( fun BaseFragment.getTitleOverride(defaultTitle: String): String { val title = this.extras.getString(Shared.Extra.TITLE_OVERRIDE) ?: "" - return if (title.isNotEmpty()) title else defaultTitle + return title.ifEmpty { defaultTitle } } /*