couple code style changes
This commit is contained in:
parent
ebd28f7446
commit
ce5812d9f0
11 changed files with 46 additions and 54 deletions
|
@ -40,7 +40,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun setupEqualizer() {
|
||||
val equalizer = MusicService.mEqualizer ?: return
|
||||
val items = arrayListOf<RadioItem>()
|
||||
(0..equalizer.numberOfPresets - 1).mapTo(items) { RadioItem(it, equalizer.getPresetName(it.toShort())) }
|
||||
(0 until equalizer.numberOfPresets).mapTo(items) { RadioItem(it, equalizer.getPresetName(it.toShort())) }
|
||||
|
||||
settings_equalizer.text = items[config.equalizer].title
|
||||
settings_equalizer_holder.setOnClickListener {
|
||||
|
|
|
@ -86,14 +86,14 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||
finish()
|
||||
}
|
||||
|
||||
fun pickBackgroundColor() {
|
||||
private fun pickBackgroundColor() {
|
||||
ColorPickerDialog(this, mBgColorWithoutTransparency) {
|
||||
mBgColorWithoutTransparency = it
|
||||
updateBackgroundColor()
|
||||
}
|
||||
}
|
||||
|
||||
fun pickTextColor() {
|
||||
private fun pickTextColor() {
|
||||
ColorPickerDialog(this, mTextColor) {
|
||||
mTextColor = it
|
||||
updateTextColor()
|
||||
|
|
|
@ -56,7 +56,7 @@ class PlaylistsAdapter(val activity: SimpleActivity, val mItems: List<Playlist>,
|
|||
itemCnt = mItems.size
|
||||
}
|
||||
|
||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||
private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
|
@ -158,7 +158,7 @@ class PlaylistsAdapter(val activity: SimpleActivity, val mItems: List<Playlist>,
|
|||
return itemView
|
||||
}
|
||||
|
||||
fun viewClicked(playlist: Playlist) {
|
||||
private fun viewClicked(playlist: Playlist) {
|
||||
if (multiSelector.isSelectable) {
|
||||
val isSelected = multiSelector.selectedPositions.contains(layoutPosition)
|
||||
multiSelector.setSelected(this, !isSelected)
|
||||
|
|
|
@ -55,12 +55,12 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
updateTitle(selectedPositions.size)
|
||||
}
|
||||
|
||||
fun updateTitle(cnt: Int) {
|
||||
private fun updateTitle(cnt: Int) {
|
||||
actMode?.title = "$cnt / ${songs.size}"
|
||||
actMode?.invalidate()
|
||||
}
|
||||
|
||||
val adapterListener = object : MyAdapterListener {
|
||||
private val adapterListener = object : MyAdapterListener {
|
||||
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
|
||||
toggleItemSelection(select, position)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
override fun getSelectedPositions(): HashSet<Int> = selectedPositions
|
||||
}
|
||||
|
||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||
private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.cab_properties -> showProperties()
|
||||
|
@ -133,7 +133,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
|
||||
private fun selectAll() {
|
||||
val cnt = songs.size
|
||||
for (i in 0..cnt - 1) {
|
||||
for (i in 0 until cnt) {
|
||||
selectedPositions.add(i)
|
||||
notifyItemChanged(i)
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
toggleItemSelection(true, i)
|
||||
|
||||
if (min > -1 && min < to) {
|
||||
(min..to - 1).filter { it != from }
|
||||
(min until to).filter { it != from }
|
||||
.forEach { toggleItemSelection(false, it) }
|
||||
}
|
||||
if (max > -1) {
|
||||
|
@ -257,7 +257,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
}
|
||||
|
||||
if (min > -1) {
|
||||
for (i in min..from - 1)
|
||||
for (i in min until from)
|
||||
toggleItemSelection(false, i)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simplemobiletools.musicplayer.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -15,14 +14,14 @@ import com.simplemobiletools.musicplayer.helpers.SORT_BY_FILE_NAME
|
|||
import com.simplemobiletools.musicplayer.helpers.SORT_BY_TITLE
|
||||
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||
|
||||
class ChangeSortingDialog(val activity: Activity, val callback: () -> Unit) : DialogInterface.OnClickListener {
|
||||
class ChangeSortingDialog(val activity: Activity, val callback: () -> Unit) {
|
||||
private var currSorting = 0
|
||||
var config = activity.config
|
||||
var view: View = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null)
|
||||
|
||||
init {
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, this)
|
||||
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||
|
@ -57,7 +56,7 @@ class ChangeSortingDialog(val activity: Activity, val callback: () -> Unit) : Di
|
|||
orderBtn.isChecked = true
|
||||
}
|
||||
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
private fun dialogConfirmed() {
|
||||
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||
var sorting = when (sortingRadio.checkedRadioButtonId) {
|
||||
R.id.sorting_dialog_radio_title -> SORT_BY_TITLE
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.simplemobiletools.musicplayer.extensions.dbHelper
|
|||
import com.simplemobiletools.musicplayer.models.Playlist
|
||||
import kotlinx.android.synthetic.main.dialog_new_playlist.view.*
|
||||
|
||||
class NewPlaylistDialog(val activity: Activity, var playlist: Playlist? = null, val callback: (playlistId: Int) -> Unit) : AlertDialog.Builder(activity) {
|
||||
class NewPlaylistDialog(val activity: Activity, var playlist: Playlist? = null, val callback: (playlistId: Int) -> Unit) {
|
||||
var isNewPlaylist = playlist == null
|
||||
|
||||
init {
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.simplemobiletools.musicplayer.R
|
|||
import com.simplemobiletools.musicplayer.models.Playlist
|
||||
import kotlinx.android.synthetic.main.dialog_remove_playlist.view.*
|
||||
|
||||
class RemovePlaylistDialog(val activity: Activity, val playlist: Playlist? = null, val callback: (deleteFiles: Boolean) -> Unit) : AlertDialog.Builder(activity) {
|
||||
class RemovePlaylistDialog(val activity: Activity, val playlist: Playlist? = null, val callback: (deleteFiles: Boolean) -> Unit) {
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_remove_playlist, null).apply {
|
||||
remove_playlist_description.text = getDescriptionText()
|
||||
|
|
|
@ -33,9 +33,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val DB_NAME = "playlists.db"
|
||||
val INITIAL_PLAYLIST_ID = 1
|
||||
|
||||
fun newInstance(context: Context): DBHelper {
|
||||
return DBHelper(context)
|
||||
}
|
||||
fun newInstance(context: Context) = DBHelper(context)
|
||||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
|
@ -160,13 +158,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return null
|
||||
}
|
||||
|
||||
fun removeSongFromPlaylist(path: String, playlistId: Int) {
|
||||
private fun removeSongFromPlaylist(path: String, playlistId: Int) {
|
||||
removeSongsFromPlaylist(ArrayList<String>().apply { add(path) }, playlistId)
|
||||
}
|
||||
|
||||
fun removeSongsFromPlaylist(paths: ArrayList<String>, playlistId: Int = context.config.currentPlaylist) {
|
||||
val SPLICE_SIZE = 200
|
||||
for (i in 0..paths.size - 1 step SPLICE_SIZE) {
|
||||
for (i in 0 until paths.size step SPLICE_SIZE) {
|
||||
val curPaths = paths.subList(i, Math.min(i + SPLICE_SIZE, paths.size))
|
||||
val questionMarks = getQuestionMarks(curPaths.size)
|
||||
var selection = "$COL_PATH IN ($questionMarks)"
|
||||
|
@ -210,10 +208,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
if (paths.isEmpty())
|
||||
return songs
|
||||
|
||||
for (i in 0..paths.size - 1 step SPLICE_SIZE) {
|
||||
for (i in 0 until paths.size step SPLICE_SIZE) {
|
||||
val curPaths = paths.subList(i, Math.min(i + SPLICE_SIZE, paths.size))
|
||||
val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
|
||||
val columns = arrayOf(MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.DATA)
|
||||
val columns = arrayOf(MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DURATION)
|
||||
val questionMarks = getQuestionMarks(curPaths.size)
|
||||
val selection = "${MediaStore.Audio.Media.DATA} IN ($questionMarks)"
|
||||
val selectionArgs = curPaths.toTypedArray()
|
||||
|
|
|
@ -35,12 +35,9 @@ data class Song(val id: Long, var title: String, var artist: String, var path: S
|
|||
return res
|
||||
}
|
||||
|
||||
override fun equals(o: Any?): Boolean {
|
||||
return if (this === o)
|
||||
true
|
||||
else if (o == null)
|
||||
false
|
||||
else
|
||||
id == (o as Song).id
|
||||
override fun equals(other: Any?): Boolean = when {
|
||||
this === other -> true
|
||||
other == null -> false
|
||||
else -> id == (other as Song).id
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,8 +84,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
|
||||
private fun initService() {
|
||||
mConfig = applicationContext.config
|
||||
mSongs = ArrayList<Song>()
|
||||
mPlayedSongIndexes = ArrayList<Int>()
|
||||
mSongs = ArrayList()
|
||||
mPlayedSongIndexes = ArrayList()
|
||||
mCurrSong = null
|
||||
setupIntents()
|
||||
getSortedSongs()
|
||||
|
@ -163,7 +163,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
fun initMediaPlayerIfNeeded() {
|
||||
private fun initMediaPlayerIfNeeded() {
|
||||
if (mPlayer != null)
|
||||
return
|
||||
|
||||
|
@ -248,7 +248,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
|
||||
val notification = NotificationCompat.Builder(this)
|
||||
.setStyle(NotificationCompat.MediaStyle().setShowActionsInCompactView(*intArrayOf(playPauseButtonPosition, nextButtonPosition)))
|
||||
.setStyle(NotificationCompat.MediaStyle().setShowActionsInCompactView(playPauseButtonPosition, nextButtonPosition))
|
||||
.setContentTitle(title)
|
||||
.setContentText(artist)
|
||||
.setSmallIcon(R.drawable.ic_headset_small)
|
||||
|
@ -303,11 +303,10 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
private fun getNewSongId(): Int {
|
||||
return if (mConfig!!.isShuffleEnabled) {
|
||||
val cnt = mSongs!!.size
|
||||
if (cnt == 0) {
|
||||
-1
|
||||
} else if (cnt == 1) {
|
||||
0
|
||||
} else {
|
||||
when (cnt) {
|
||||
0 -> -1
|
||||
1 -> 0
|
||||
else -> {
|
||||
val random = Random()
|
||||
var newSongIndex = random.nextInt(cnt)
|
||||
while (mPlayedSongIndexes!!.contains(newSongIndex)) {
|
||||
|
@ -315,6 +314,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
newSongIndex
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mPlayedSongIndexes!!.isEmpty()) {
|
||||
return 0
|
||||
|
@ -325,7 +325,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
}
|
||||
|
||||
fun playPreviousSong() {
|
||||
private fun playPreviousSong() {
|
||||
if (mSongs!!.isEmpty()) {
|
||||
handleEmptyPlaylist()
|
||||
return
|
||||
|
@ -343,7 +343,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
}
|
||||
|
||||
fun pauseSong() {
|
||||
private fun pauseSong() {
|
||||
if (mSongs!!.isEmpty())
|
||||
return
|
||||
|
||||
|
@ -353,7 +353,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
songStateChanged(false)
|
||||
}
|
||||
|
||||
fun resumeSong() {
|
||||
private fun resumeSong() {
|
||||
if (mSongs!!.isEmpty()) {
|
||||
handleEmptyPlaylist()
|
||||
return
|
||||
|
@ -370,7 +370,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
songStateChanged(true)
|
||||
}
|
||||
|
||||
fun playNextSong() {
|
||||
private fun playNextSong() {
|
||||
setSong(getNewSongId(), true)
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
setSong(pos, true)
|
||||
}
|
||||
|
||||
fun setSong(songIndex: Int, addNewSong: Boolean) {
|
||||
private fun setSong(songIndex: Int, addNewSong: Boolean) {
|
||||
if (mSongs!!.isEmpty()) {
|
||||
handleEmptyPlaylist()
|
||||
return
|
||||
|
@ -471,7 +471,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
stopSelf()
|
||||
}
|
||||
|
||||
fun incomingCallStart() {
|
||||
private fun incomingCallStart() {
|
||||
if (getIsPlaying()) {
|
||||
mWasPlayingAtCall = true
|
||||
pauseSong()
|
||||
|
@ -480,7 +480,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
}
|
||||
|
||||
fun incomingCallStop() {
|
||||
private fun incomingCallStop() {
|
||||
if (mWasPlayingAtCall)
|
||||
resumeSong()
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:layout_marginLeft="@dimen/small_margin"
|
||||
android:layout_marginStart="@dimen/small_margin"
|
||||
android:inputType="textCapSentences"
|
||||
android:maxLength="50"
|
||||
android:singleLine="true"
|
||||
|
|
Loading…
Reference in a new issue