mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-02 11:58:27 +00:00
Resource and prefs cleanups.
This commit is contained in:
parent
b6fd556fcf
commit
584c41cc1a
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -50,6 +50,10 @@ private val urlCache = LruCache<String, String>(500)
|
||||
private val badUrlCache = LruCache<String, Boolean>(100)
|
||||
private val inFlight = mutableMapOf<String, CountDownLatch>()
|
||||
|
||||
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)
|
||||
|
@ -0,0 +1,4 @@
|
||||
<vector android:height="24dp" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#88FFFFFF" android:pathData="M12,3v10.55c-0.59,-0.34 -1.27,-0.55 -2,-0.55 -2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4V7h4V3h-6z"/>
|
||||
</vector>
|
@ -1,23 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2014 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2c-1.1,0 -2,0.9 -2,2S10.9,8 12,8zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2c1.1,0 2,-0.9 2,-2S13.1,10 12,10zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2c1.1,0 2,-0.9 2,-2S13.1,16 12,16z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
||||
android:fillColor="?attr/colorControlNormal"
|
||||
android:pathData="M7,10l5,5 5,-5z"/>
|
||||
</vector>
|
||||
|
@ -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" />
|
||||
|
||||
<LinearLayout
|
||||
@ -50,7 +52,8 @@
|
||||
android:id="@+id/action"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:src="@drawable/ic_overflow"
|
||||
android:padding="8dp"
|
||||
android:scaleType="center"
|
||||
android:padding="4dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
|
@ -82,7 +82,7 @@
|
||||
<string name="settings_cache_size">streaming disk cache size:</string>
|
||||
<string name="settings_advanced">advanced:</string>
|
||||
<string name="settings_use_ssl">use ssl for server connections</string>
|
||||
<string name="settings_enable_album_art">enable album art (uses last.fm)</string>
|
||||
<string name="settings_enable_album_art">uses last.fm for missing album art</string>
|
||||
<string name="settings_enable_message_compression">enable message compression</string>
|
||||
<string name="settings_enable_streaming_playback">enable streaming playback</string>
|
||||
<string name="settings_enable_software_volume">use software volume while streaming</string>
|
||||
|
Loading…
Reference in New Issue
Block a user