implement editing songs + cleanup
This commit is contained in:
parent
3e163932dd
commit
8068f66306
8 changed files with 31 additions and 71 deletions
|
@ -5,8 +5,6 @@ import android.content.Intent
|
|||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaScannerConnection
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
|
@ -30,7 +28,7 @@ import com.squareup.otto.Subscribe
|
|||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), MediaScannerConnection.OnScanCompletedListener, SeekBar.OnSeekBarChangeListener {
|
||||
class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
||||
companion object {
|
||||
private val STORAGE_PERMISSION = 1
|
||||
|
||||
|
@ -181,37 +179,6 @@ class MainActivity : SimpleActivity(), MediaScannerConnection.OnScanCompletedLis
|
|||
fillSongsListView(event.songs)
|
||||
}
|
||||
|
||||
/*
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.cab_edit -> {
|
||||
displayEditDialog()
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
R.id.cab_delete -> {
|
||||
prepareForDeleting()
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayEditDialog() {
|
||||
val songIndex = selectedSongIndex
|
||||
if (songIndex == -1)
|
||||
return
|
||||
|
||||
val selectedSong = mSongs[songIndex]
|
||||
|
||||
EditDialog(this, selectedSong)
|
||||
}*/
|
||||
|
||||
override fun onScanCompleted(path: String, uri: Uri) {
|
||||
sendIntent(REFRESH_LIST)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun songChangedEvent(event: Events.ProgressUpdated) {
|
||||
progressbar.progress = event.progress
|
||||
|
@ -228,7 +195,6 @@ class MainActivity : SimpleActivity(), MediaScannerConnection.OnScanCompletedLis
|
|||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||
|
|
|
@ -7,10 +7,10 @@ import android.view.View
|
|||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.extensions.sendIntent
|
||||
import com.simplemobiletools.musicplayer.helpers.EQUALIZER
|
||||
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
|
||||
import com.simplemobiletools.musicplayer.helpers.SET_EQUALIZER
|
||||
import com.simplemobiletools.musicplayer.helpers.UPDATE_ACTIVITY
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
|
@ -56,7 +56,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
settings_sorting.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
mConfig.sorting = settings_sorting.selectedItemPosition
|
||||
updatePlaylist()
|
||||
sendIntent(REFRESH_LIST)
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
|
@ -97,12 +97,4 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun restartActivity() {
|
||||
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
||||
}
|
||||
|
||||
private fun updatePlaylist() {
|
||||
Intent(this, MusicService::class.java).apply {
|
||||
putExtra(UPDATE_ACTIVITY, true)
|
||||
action = REFRESH_LIST
|
||||
startService(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import android.widget.RemoteViews
|
|||
import android.widget.SeekBar
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.helpers.MyWidgetProvider
|
||||
import com.simplemobiletools.musicplayer.helpers.PREFS
|
||||
import com.simplemobiletools.musicplayer.helpers.PREFS_KEY
|
||||
import com.simplemobiletools.musicplayer.helpers.WIDGET_BG_COLOR
|
||||
import com.simplemobiletools.musicplayer.helpers.WIDGET_TEXT_COLOR
|
||||
import kotlinx.android.synthetic.main.widget.*
|
||||
|
@ -49,7 +49,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun initVariables() {
|
||||
val prefs = getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
val prefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
mBgColor = prefs.getInt(WIDGET_BG_COLOR, 1)
|
||||
if (mBgColor == 1) {
|
||||
mBgColor = Color.BLACK
|
||||
|
@ -112,7 +112,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun storeWidgetColors() {
|
||||
getSharedPreferences(PREFS, Context.MODE_PRIVATE).apply {
|
||||
getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE).apply {
|
||||
edit().putInt(WIDGET_BG_COLOR, mBgColor).putInt(WIDGET_TEXT_COLOR, mTextColor).apply()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simplemobiletools.musicplayer.adapters
|
||||
|
||||
import android.content.Intent
|
||||
import android.support.v7.view.ActionMode
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.*
|
||||
|
@ -12,10 +11,10 @@ import com.simplemobiletools.filepicker.extensions.scanPaths
|
|||
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||
import com.simplemobiletools.musicplayer.dialogs.EditDialog
|
||||
import com.simplemobiletools.musicplayer.extensions.sendIntent
|
||||
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
|
||||
import com.simplemobiletools.musicplayer.helpers.UPDATE_ACTIVITY
|
||||
import com.simplemobiletools.musicplayer.models.Song
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import kotlinx.android.synthetic.main.song.view.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
@ -47,6 +46,10 @@ class SongAdapter(val activity: SimpleActivity, val songs: ArrayList<Song>, val
|
|||
showProperties()
|
||||
true
|
||||
}
|
||||
R.id.cab_edit -> {
|
||||
displayEditDialog()
|
||||
true
|
||||
}
|
||||
R.id.cab_delete -> {
|
||||
askConfirmDelete()
|
||||
true
|
||||
|
@ -86,6 +89,16 @@ class SongAdapter(val activity: SimpleActivity, val songs: ArrayList<Song>, val
|
|||
}
|
||||
}
|
||||
|
||||
private fun displayEditDialog() {
|
||||
val selections = multiSelector.selectedPositions
|
||||
if (selections.size == 1) {
|
||||
EditDialog(activity, songs[selections[0]]) {
|
||||
activity.sendIntent(REFRESH_LIST)
|
||||
activity.runOnUiThread { actMode?.finish() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(activity) {
|
||||
actMode?.finish()
|
||||
|
@ -102,11 +115,7 @@ class SongAdapter(val activity: SimpleActivity, val songs: ArrayList<Song>, val
|
|||
}
|
||||
|
||||
activity.scanPaths(paths) {
|
||||
Intent(activity, MusicService::class.java).apply {
|
||||
putExtra(UPDATE_ACTIVITY, true)
|
||||
action = REFRESH_LIST
|
||||
activity.startService(this)
|
||||
}
|
||||
activity.sendIntent(REFRESH_LIST)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,13 +10,11 @@ import android.view.WindowManager
|
|||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||
import com.simplemobiletools.musicplayer.extensions.sendIntent
|
||||
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
|
||||
import com.simplemobiletools.musicplayer.models.Song
|
||||
import kotlinx.android.synthetic.main.rename_song.view.*
|
||||
import java.io.File
|
||||
|
||||
class EditDialog(val activity: SimpleActivity, val song: Song) {
|
||||
class EditDialog(val activity: SimpleActivity, val song: Song, val callback: () -> Unit) {
|
||||
init {
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.rename_song, null)
|
||||
view.title.setText(song.title)
|
||||
|
@ -52,15 +50,15 @@ class EditDialog(val activity: SimpleActivity, val song: Song) {
|
|||
val file = File(song.path)
|
||||
val newFile = File(file.parent, "$newFilename.$newFileExtension")
|
||||
if (file == newFile) {
|
||||
callback.invoke()
|
||||
dismiss()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (file.renameTo(newFile)) {
|
||||
context.scanFiles(arrayListOf(file, newFile)) {
|
||||
context.sendIntent(REFRESH_LIST)
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
dismiss()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simplemobiletools.musicplayer.extensions
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.musicplayer.helpers.PREFS
|
||||
import com.simplemobiletools.musicplayer.helpers.PREFS_KEY
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
|
||||
fun Context.sendIntent(action: String) {
|
||||
|
@ -12,4 +12,4 @@ fun Context.sendIntent(action: String) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.getSharedPrefs() = getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package com.simplemobiletools.musicplayer.helpers
|
||||
|
||||
val PREFS = "prefs"
|
||||
val WIDGET_BG_COLOR = "widget_bg_color"
|
||||
val WIDGET_TEXT_COLOR = "widget_text_color"
|
||||
val SONG_POS = "song_position"
|
||||
val PROGRESS = "progress"
|
||||
val EDITED_SONG = "edited_song"
|
||||
val UPDATE_ACTIVITY = "update_activity"
|
||||
|
||||
private val PATH = "com.simplemobiletools.musicplayer.action."
|
||||
|
||||
|
@ -33,3 +29,5 @@ val NUMERIC_PROGRESS = "numeric_progress"
|
|||
val SORTING = "sorting"
|
||||
val EQUALIZER = "equalizer"
|
||||
val REPEAT_SONG = "repeat_song"
|
||||
val WIDGET_BG_COLOR = "widget_bg_color"
|
||||
val WIDGET_TEXT_COLOR = "widget_text_color"
|
||||
|
|
|
@ -137,10 +137,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
REFRESH_LIST -> {
|
||||
getSortedSongs()
|
||||
|
||||
if (intent.extras?.containsKey(UPDATE_ACTIVITY) == true) {
|
||||
mBus!!.post(Events.PlaylistUpdated(mSongs!!))
|
||||
}
|
||||
mBus!!.post(Events.PlaylistUpdated(mSongs!!))
|
||||
}
|
||||
SET_PROGRESS -> {
|
||||
if (mPlayer != null) {
|
||||
|
|
Loading…
Reference in a new issue