From 662660de0aedaf89f1929c1e32cc438497512853 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 7 Jan 2017 21:50:16 +0100 Subject: [PATCH] couple tweaks here and there --- .../musicplayer/activities/MainActivity.kt | 30 +++++-------------- .../activities/WidgetConfigureActivity.kt | 12 +++----- .../musicplayer/adapters/SongAdapter.kt | 20 ++++--------- .../musicplayer/helpers/Constants.kt | 2 -- .../musicplayer/helpers/MyWidgetProvider.kt | 2 -- .../musicplayer/models/Song.kt | 4 +-- .../musicplayer/services/MusicService.kt | 7 ++++- 7 files changed, 25 insertions(+), 52 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt index 039dc785..e2a063d4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt @@ -83,29 +83,15 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - R.id.sort -> { - showSortingDialog() - true - } - R.id.toggle_shuffle -> { - toggleShuffle() - true - } - R.id.toggle_song_repetition -> { - toggleSongRepetition() - true - } - R.id.settings -> { - launchSettings() - true - } - R.id.about -> { - launchAbout() - true - } - else -> super.onOptionsItemSelected(item) + when (item.itemId) { + R.id.sort -> showSortingDialog() + R.id.toggle_shuffle -> toggleShuffle() + R.id.toggle_song_repetition -> toggleSongRepetition() + R.id.settings -> launchSettings() + R.id.about -> launchAbout() + else -> return super.onOptionsItemSelected(item) } + return true } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/WidgetConfigureActivity.kt index bf510474..a8f351ab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/WidgetConfigureActivity.kt @@ -91,7 +91,7 @@ class WidgetConfigureActivity : AppCompatActivity() { } fun pickBackgroundColor() { - val dialog = AmbilWarnaDialog(this, mBgColorWithoutTransparency, object : AmbilWarnaDialog.OnAmbilWarnaListener { + AmbilWarnaDialog(this, mBgColorWithoutTransparency, object : AmbilWarnaDialog.OnAmbilWarnaListener { override fun onCancel(dialog: AmbilWarnaDialog) { } @@ -99,13 +99,11 @@ class WidgetConfigureActivity : AppCompatActivity() { mBgColorWithoutTransparency = color updateBackgroundColor() } - }) - - dialog.show() + }).show() } fun pickTextColor() { - val dialog = AmbilWarnaDialog(this, mTextColor, object : AmbilWarnaDialog.OnAmbilWarnaListener { + AmbilWarnaDialog(this, mTextColor, object : AmbilWarnaDialog.OnAmbilWarnaListener { override fun onCancel(dialog: AmbilWarnaDialog) { } @@ -113,9 +111,7 @@ class WidgetConfigureActivity : AppCompatActivity() { mTextColor = color updateTextColor() } - }) - - dialog.show() + }).show() } private fun storeWidgetColors() { diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt index 014ad45f..cf6538de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt @@ -48,21 +48,13 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList, val val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - return when (item.itemId) { - R.id.cab_properties -> { - showProperties() - true - } - R.id.cab_rename -> { - displayEditDialog() - true - } - R.id.cab_delete -> { - askConfirmDelete() - true - } - else -> false + when (item.itemId) { + R.id.cab_properties -> showProperties() + R.id.cab_rename -> displayEditDialog() + R.id.cab_delete -> askConfirmDelete() + else -> return false } + return true } override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean { diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt index 5c53ecab..8e2f9614 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt @@ -22,8 +22,6 @@ val SET_EQUALIZER = PATH + "SET_EQUALIZER" // shared preferences val PREFS_KEY = "Music Player" -val IS_FIRST_RUN = "is_first_run" -val IS_DARK_THEME = "is_dark_theme" val SHUFFLE = "shuffle" val NUMERIC_PROGRESS = "numeric_progress" val SORTING = "track_sorting" diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/MyWidgetProvider.kt index 9c23f7b7..70dcbc65 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/MyWidgetProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/MyWidgetProvider.kt @@ -215,7 +215,6 @@ class MyWidgetProvider : AppWidgetProvider() { mBus!!.register(this) } catch (e: Exception) { } - } private fun unregisterBus() { @@ -223,6 +222,5 @@ class MyWidgetProvider : AppWidgetProvider() { mBus!!.unregister(this) } catch (e: Exception) { } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt index 54e28d92..96b73933 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Song.kt @@ -6,7 +6,7 @@ import com.simplemobiletools.musicplayer.helpers.SORT_BY_TITLE import com.simplemobiletools.musicplayer.helpers.SORT_DESCENDING import java.io.Serializable -class Song(val id: Long, var title: String, var artist: String, var path: String, val duration: Int) : Serializable, Comparable { +data class Song(val id: Long, var title: String, var artist: String, var path: String, val duration: Int) : Serializable, Comparable { companion object { private const val serialVersionUID = 6717978793256842245L var sorting: Int = 0 @@ -35,8 +35,6 @@ class Song(val id: Long, var title: String, var artist: String, var path: String return res } - override fun toString() = "Song {id=$id, title=$title, artist=$artist, path=$path, duration=$duration}" - override fun equals(o: Any?): Boolean { return if (this === o) true diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index 5fc15da7..fb68a637 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -269,7 +269,12 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr val rawArt = mediaMetadataRetriever.embeddedPicture if (rawArt != null) { val options = BitmapFactory.Options() - return BitmapFactory.decodeByteArray(rawArt, 0, rawArt.size, options) + try { + val bitmap = BitmapFactory.decodeByteArray(rawArt, 0, rawArt.size, options) + if (bitmap != null) + return bitmap + } catch (e: Exception) { + } } }