From 584c41cc1ae2add4d03975f7ac191c30818083ad Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 18 Nov 2017 23:29:16 -0800 Subject: [PATCH] Resource and prefs cleanups. --- .../remote/service/system/SystemService.kt | 8 +----- .../ui/albums/adapter/AlbumBrowseAdapter.kt | 15 +++++++++- .../remote/ui/home/view/MainMetadataView.kt | 19 ++++++------- .../ui/settings/activity/SettingsActivity.kt | 4 +-- .../remote/ui/settings/constants/Prefs.kt | 6 ++-- .../ui/shared/mixin/ItemContextMenuMixin.kt | 3 +- .../remote/ui/shared/util/AlbumArtLookup.kt | 12 +++++--- .../res/drawable-v21/ic_art_placeholder.xml | 4 +++ .../{drawable => drawable-v21}/ic_fab_add.xml | 0 .../src/main/res/drawable-v21/ic_overflow.xml | 28 +++++-------------- .../src/main/res/layout/simple_list_item.xml | 5 +++- .../app/src/main/res/values/strings.xml | 2 +- 12 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 src/musikdroid/app/src/main/res/drawable-v21/ic_art_placeholder.xml rename src/musikdroid/app/src/main/res/{drawable => drawable-v21}/ic_fab_add.xml (100%) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt index df2ce7fa3..c3ec761f7 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/system/SystemService.kt @@ -239,16 +239,10 @@ class SystemService : Service() { } } - private val albumArtEnabled: Boolean - get() { - return this.prefs.getBoolean( - Prefs.Key.ALBUM_ART_ENABLED, Prefs.Default.ALBUM_ART_ENABLED) - } - private fun updateMediaSession(track: ITrack?, duration: Int) { var currentImage: Bitmap? = null - if (albumArtEnabled && track != null) { + if (track != null) { downloadAlbumArtIfNecessary(track, duration) currentImage = albumArt.bitmap } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/adapter/AlbumBrowseAdapter.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/adapter/AlbumBrowseAdapter.kt index 18493ba13..b03174386 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/adapter/AlbumBrowseAdapter.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/adapter/AlbumBrowseAdapter.kt @@ -6,6 +6,8 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.request.RequestOptions import io.casey.musikcube.remote.R import io.casey.musikcube.remote.injection.GlideApp import io.casey.musikcube.remote.service.websocket.model.IAlbum @@ -67,7 +69,11 @@ class AlbumBrowseAdapter(private val listener: EventListener, artwork.visibility = View.VISIBLE - GlideApp.with(itemView.context).load(getUrl(album, Size.Large)).into(artwork) + GlideApp + .with(itemView.context) + .load(getUrl(album, Size.Large)) + .apply(OPTIONS) + .into(artwork) title.text = fallback(album.value, "-") title.setTextColor(getColorCompat(titleColor)) @@ -77,5 +83,12 @@ class AlbumBrowseAdapter(private val listener: EventListener, itemView.tag = album action.tag = album } + + companion object { + val OPTIONS = RequestOptions() + .placeholder(R.drawable.ic_art_placeholder) + .error(R.drawable.ic_art_placeholder) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + } } } \ No newline at end of file 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 4b7d4331c..00d0eb42d 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 @@ -28,19 +28,21 @@ import io.casey.musikcube.remote.R import io.casey.musikcube.remote.injection.DaggerViewComponent import io.casey.musikcube.remote.injection.DataModule import io.casey.musikcube.remote.injection.GlideApp -import io.casey.musikcube.remote.service.playback.* +import io.casey.musikcube.remote.service.playback.IPlaybackService +import io.casey.musikcube.remote.service.playback.PlaybackServiceFactory +import io.casey.musikcube.remote.service.playback.PlaybackState import io.casey.musikcube.remote.service.playback.impl.remote.Metadata import io.casey.musikcube.remote.service.playback.impl.streaming.StreamingPlaybackService +import io.casey.musikcube.remote.service.websocket.Messages +import io.casey.musikcube.remote.service.websocket.SocketMessage +import io.casey.musikcube.remote.service.websocket.WebSocketService import io.casey.musikcube.remote.ui.albums.activity.AlbumBrowseActivity -import io.casey.musikcube.remote.ui.tracks.activity.TrackListActivity +import io.casey.musikcube.remote.ui.settings.constants.Prefs import io.casey.musikcube.remote.ui.shared.extension.fallback import io.casey.musikcube.remote.ui.shared.extension.getColorCompat import io.casey.musikcube.remote.ui.shared.model.albumart.Size +import io.casey.musikcube.remote.ui.tracks.activity.TrackListActivity import io.casey.musikcube.remote.util.Strings -import io.casey.musikcube.remote.service.websocket.Messages -import io.casey.musikcube.remote.ui.settings.constants.Prefs -import io.casey.musikcube.remote.service.websocket.SocketMessage -import io.casey.musikcube.remote.service.websocket.WebSocketService import org.json.JSONArray import javax.inject.Inject import io.casey.musikcube.remote.ui.shared.model.albumart.getUrl as getAlbumArtUrl @@ -138,10 +140,7 @@ class MainMetadataView : FrameLayout { this.titleWithArt.text = if (Strings.empty(title)) getString(if (buffering) R.string.buffering else R.string.unknown_title) else title this.buffering.visibility = if (buffering) View.VISIBLE else View.GONE - val albumArtEnabledInSettings = this.prefs.getBoolean( - Prefs.Key.ALBUM_ART_ENABLED, Prefs.Default.ALBUM_ART_ENABLED) - - if (!albumArtEnabledInSettings || Strings.empty(artist) || Strings.empty(album)) { + if (Strings.empty(artist) || Strings.empty(album)) { setMetadataDisplayMode(DisplayMode.NoArtwork) } else { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/activity/SettingsActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/activity/SettingsActivity.kt index 5e6cd4ce5..fe4604c0d 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/activity/SettingsActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/activity/SettingsActivity.kt @@ -128,7 +128,7 @@ class SettingsActivity : BaseActivity() { /* advanced */ albumArtCheckbox.isChecked = prefs.getBoolean( - Keys.ALBUM_ART_ENABLED, Defaults.ALBUM_ART_ENABLED) + Keys.LASTFM_ENABLED, Defaults.LASTFM_ENABLED) messageCompressionCheckbox.isChecked = prefs.getBoolean( Keys.MESSAGE_COMPRESSION_ENABLED, Defaults.MESSAGE_COMPRESSION_ENABLED) @@ -244,7 +244,7 @@ class SettingsActivity : BaseActivity() { .putInt(Keys.MAIN_PORT, if (port.isNotEmpty()) port.toInt() else 0) .putInt(Keys.AUDIO_PORT, if (httpPort.isNotEmpty()) httpPort.toInt() else 0) .putString(Keys.PASSWORD, password) - .putBoolean(Keys.ALBUM_ART_ENABLED, albumArtCheckbox.isChecked) + .putBoolean(Keys.LASTFM_ENABLED, albumArtCheckbox.isChecked) .putBoolean(Keys.MESSAGE_COMPRESSION_ENABLED, messageCompressionCheckbox.isChecked) .putBoolean(Keys.SOFTWARE_VOLUME, softwareVolume.isChecked) .putBoolean(Keys.SSL_ENABLED, sslCheckbox.isChecked) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/constants/Prefs.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/constants/Prefs.kt index 07db23332..61554cd1c 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/constants/Prefs.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/settings/constants/Prefs.kt @@ -7,7 +7,7 @@ class Prefs { val MAIN_PORT = "port" val AUDIO_PORT = "http_port" val PASSWORD = "password" - val ALBUM_ART_ENABLED = "album_art_enabled" + val LASTFM_ENABLED = "lastfm_enabled" val MESSAGE_COMPRESSION_ENABLED = "message_compression_enabled" val STREAMING_PLAYBACK = "streaming_playback" val SOFTWARE_VOLUME = "software_volume" @@ -15,7 +15,6 @@ class Prefs { val CERT_VALIDATION_DISABLED = "cert_validation_disabled" val TRANSCODER_BITRATE_INDEX = "transcoder_bitrate_index" val DISK_CACHE_SIZE_INDEX = "disk_cache_size_index" - val SYSTEM_SERVICE_FOR_REMOTE = "system_service_for_remote" val UPDATE_DIALOG_SUPPRESSED_VERSION = "update_dialog_suppressed_version" } } @@ -26,7 +25,7 @@ class Prefs { val MAIN_PORT = 7905 val AUDIO_PORT = 7906 val PASSWORD = "" - val ALBUM_ART_ENABLED = true + val LASTFM_ENABLED = true val MESSAGE_COMPRESSION_ENABLED = true val STREAMING_PLAYBACK = false val SOFTWARE_VOLUME = false @@ -34,7 +33,6 @@ class Prefs { val CERT_VALIDATION_DISABLED = false val TRANSCODER_BITRATE_INDEX = 0 val DISK_CACHE_SIZE_INDEX = 2 - val SYSTEM_SERVICE_FOR_REMOTE = false } } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt index 7d5d171ae..3ad04a94d 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt @@ -346,7 +346,8 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, val dlg = AlertDialog.Builder(activity) .setTitle(R.string.playlist_name_title) - .setPositiveButton(R.string.button_create, { _: DialogInterface, _: Int -> + .setNegativeButton(R.string.button_cancel, null) + .setPositiveButton(R.string.button_create, { _: DialogInterface, _: Int -> val playlistName = editText.text.toString() if (playlistName.isNotBlank()) { mixin.createPlaylist(playlistName) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/util/AlbumArtLookup.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/util/AlbumArtLookup.kt index e070171fd..6d2ef10af 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/util/AlbumArtLookup.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/util/AlbumArtLookup.kt @@ -50,6 +50,10 @@ private val urlCache = LruCache(500) private val badUrlCache = LruCache(100) private val inFlight = mutableMapOf() +private val prefs by lazy { + Application.instance!!.getSharedPreferences(Prefs.NAME, Context.MODE_PRIVATE) +} + fun getUrl(album: IAlbum, size: Size = Size.Small): String? { return getThumbnailUrl(album.thumbnailId) ?: getUrl(album.albumArtist, album.name, size) @@ -61,6 +65,10 @@ fun getUrl(track: ITrack, size: Size = Size.Small): String? { } fun getUrl(artist: String = "", album: String = "", size: Size = Size.Small): String? { + if (!prefs.getBoolean(Prefs.Key.LASTFM_ENABLED, Prefs.Default.LASTFM_ENABLED)) { + return null + } + if (artist.isBlank() || album.isBlank()) { return null } @@ -197,10 +205,6 @@ fun intercept(req: Request): Request? { return result } -private val prefs by lazy { - Application.instance!!.getSharedPreferences(Prefs.NAME, Context.MODE_PRIVATE) -} - private fun getThumbnailUrl(id: Long): String? { if (id > 0) { val host = prefs.getString(Prefs.Key.ADDRESS, Prefs.Default.ADDRESS) diff --git a/src/musikdroid/app/src/main/res/drawable-v21/ic_art_placeholder.xml b/src/musikdroid/app/src/main/res/drawable-v21/ic_art_placeholder.xml new file mode 100644 index 000000000..5b72941a5 --- /dev/null +++ b/src/musikdroid/app/src/main/res/drawable-v21/ic_art_placeholder.xml @@ -0,0 +1,4 @@ + + + diff --git a/src/musikdroid/app/src/main/res/drawable/ic_fab_add.xml b/src/musikdroid/app/src/main/res/drawable-v21/ic_fab_add.xml similarity index 100% rename from src/musikdroid/app/src/main/res/drawable/ic_fab_add.xml rename to src/musikdroid/app/src/main/res/drawable-v21/ic_fab_add.xml diff --git a/src/musikdroid/app/src/main/res/drawable-v21/ic_overflow.xml b/src/musikdroid/app/src/main/res/drawable-v21/ic_overflow.xml index 7f194817a..8ad62859b 100644 --- a/src/musikdroid/app/src/main/res/drawable-v21/ic_overflow.xml +++ b/src/musikdroid/app/src/main/res/drawable-v21/ic_overflow.xml @@ -1,23 +1,9 @@ - - + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> - \ No newline at end of file + android:fillColor="?attr/colorControlNormal" + android:pathData="M7,10l5,5 5,-5z"/> + diff --git a/src/musikdroid/app/src/main/res/layout/simple_list_item.xml b/src/musikdroid/app/src/main/res/layout/simple_list_item.xml index 2d53c2970..90789b918 100644 --- a/src/musikdroid/app/src/main/res/layout/simple_list_item.xml +++ b/src/musikdroid/app/src/main/res/layout/simple_list_item.xml @@ -11,6 +11,8 @@ android:id="@+id/artwork" android:layout_width="52dp" android:layout_height="52dp" + android:src="@drawable/ic_art_placeholder" + android:scaleType="centerInside" android:visibility="gone" /> streaming disk cache size: advanced: use ssl for server connections - enable album art (uses last.fm) + uses last.fm for missing album art enable message compression enable streaming playback use software volume while streaming