diff --git a/app/build.gradle b/app/build.gradle index 0c430dda..1e62af9f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.0.12' + implementation 'com.simplemobiletools:commons:3.0.21' implementation 'com.squareup:otto:1.3.8' implementation 'com.facebook.stetho:stetho:1.5.0' 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 126e287b..ca48233e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt @@ -40,8 +40,8 @@ import java.util.* class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener { private var isThirdPartyIntent = false private var storedUseEnglish = false + private var songs = ArrayList() lateinit var bus: Bus - private var songs: ArrayList = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -211,11 +211,11 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener { val initialPath = if (songs.isEmpty()) Environment.getExternalStorageDirectory().toString() else songs[0].path FilePickerDialog(this, initialPath, pickFile = false) { toast(R.string.fetching_songs) - Thread({ + Thread { val songs = getFolderSongs(File(it)) dbHelper.addSongsToPlaylist(songs) sendIntent(REFRESH_LIST) - }).start() + }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/ChangeSortingDialog.kt index c38024a4..ebf888d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/ChangeSortingDialog.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.musicplayer.dialogs import android.app.Activity import android.support.v7.app.AlertDialog -import android.view.LayoutInflater import android.view.View import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.SORT_DESCENDING @@ -17,7 +16,7 @@ import kotlinx.android.synthetic.main.dialog_change_sorting.view.* 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) + var view: View = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null) init { AlertDialog.Builder(activity) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/EditDialog.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/EditDialog.kt index b3405229..d4054779 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/EditDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/EditDialog.kt @@ -5,7 +5,6 @@ import android.content.Context import android.net.Uri import android.provider.MediaStore import android.support.v7.app.AlertDialog -import android.view.LayoutInflater import android.view.WindowManager import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* @@ -16,7 +15,7 @@ import java.io.File class EditDialog(val activity: BaseSimpleActivity, val song: Song, val callback: (Song) -> Unit) { init { - val view = LayoutInflater.from(activity).inflate(R.layout.dialog_rename_song, null).apply { + val view = activity.layoutInflater.inflate(R.layout.dialog_rename_song, null).apply { title.setText(song.title) artist.setText(song.artist) @@ -30,45 +29,46 @@ class EditDialog(val activity: BaseSimpleActivity, val song: Song, val callback: .setNegativeButton(R.string.cancel, null) .create().apply { window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this, R.string.rename_song) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - val newTitle = view.title.value - val newArtist = view.artist.value - val newFilename = view.file_name.value - val newFileExtension = view.extension.value + activity.setupDialogStuff(view, this, R.string.rename_song) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val newTitle = view.title.value + val newArtist = view.artist.value + val newFilename = view.file_name.value + val newFileExtension = view.extension.value - if (newTitle.isEmpty() || newArtist.isEmpty() || newFilename.isEmpty() || newFileExtension.isEmpty()) { - activity.toast(R.string.rename_song_empty) - return@setOnClickListener - } - - val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI - song.artist = newArtist - song.title = newTitle - - if (updateContentResolver(context, uri, song.id, newTitle, newArtist)) { - context.contentResolver.notifyChange(uri, null) - - val file = File(song.path) - val newFile = File(file.parent, "$newFilename.$newFileExtension") - if (file == newFile) { - callback(song) - dismiss() + if (newTitle.isEmpty() || newArtist.isEmpty() || newFilename.isEmpty() || newFileExtension.isEmpty()) { + activity.toast(R.string.rename_song_empty) return@setOnClickListener } - if (file.renameTo(newFile)) { - context.scanFiles(arrayListOf(file, newFile)) { - song.path = newFile.absolutePath + val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + song.artist = newArtist + song.title = newTitle + + if (updateContentResolver(context, uri, song.id, newTitle, newArtist)) { + context.contentResolver.notifyChange(uri, null) + + val file = File(song.path) + val newFile = File(file.parent, "$newFilename.$newFileExtension") + if (file == newFile) { callback(song) + dismiss() + return@setOnClickListener } - dismiss() - return@setOnClickListener - } - activity.toast(R.string.rename_song_error) + if (file.renameTo(newFile)) { + context.scanFiles(arrayListOf(file, newFile)) { + song.path = newFile.absolutePath + callback(song) + } + dismiss() + return@setOnClickListener + } + + activity.toast(R.string.rename_song_error) + } } - }) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/NewPlaylistDialog.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/NewPlaylistDialog.kt index cb21960c..8cf93f99 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/NewPlaylistDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/dialogs/NewPlaylistDialog.kt @@ -27,37 +27,39 @@ class NewPlaylistDialog(val activity: Activity, var playlist: Playlist? = null, .setNegativeButton(R.string.cancel, null) .create().apply { window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this, if (isNewPlaylist) R.string.create_playlist else R.string.rename_playlist) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - val title = view.new_playlist_title.value - val playlistIdWithTitle = activity.dbHelper.getPlaylistIdWithTitle(title) - var isPlaylistTitleTaken = isNewPlaylist && playlistIdWithTitle != -1 - if (!isPlaylistTitleTaken) - isPlaylistTitleTaken = !isNewPlaylist && playlist!!.id != playlistIdWithTitle && playlistIdWithTitle != -1 + val dialogTitle = if (isNewPlaylist) R.string.create_playlist else R.string.rename_playlist + activity.setupDialogStuff(view, this, dialogTitle) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val title = view.new_playlist_title.value + val playlistIdWithTitle = activity.dbHelper.getPlaylistIdWithTitle(title) + var isPlaylistTitleTaken = isNewPlaylist && playlistIdWithTitle != -1 + if (!isPlaylistTitleTaken) + isPlaylistTitleTaken = !isNewPlaylist && playlist!!.id != playlistIdWithTitle && playlistIdWithTitle != -1 - if (title.isEmpty()) { - activity.toast(R.string.empty_name) - return@setOnClickListener - } else if (isPlaylistTitleTaken) { - activity.toast(R.string.playlist_name_exists) - return@setOnClickListener + if (title.isEmpty()) { + activity.toast(R.string.empty_name) + return@setOnClickListener + } else if (isPlaylistTitleTaken) { + activity.toast(R.string.playlist_name_exists) + return@setOnClickListener + } + + playlist!!.title = title + + val eventTypeId = if (isNewPlaylist) { + activity.dbHelper.insertPlaylist(playlist!!) + } else { + activity.dbHelper.updatePlaylist(playlist!!) + } + + if (eventTypeId != -1) { + dismiss() + callback(eventTypeId) + } else { + activity.toast(R.string.unknown_error_occurred) + } } - - playlist!!.title = title - - val eventTypeId = if (isNewPlaylist) { - activity.dbHelper.insertPlaylist(playlist!!) - } else { - activity.dbHelper.updatePlaylist(playlist!!) - } - - if (eventTypeId != -1) { - dismiss() - callback(eventTypeId) - } else { - activity.toast(R.string.unknown_error_occurred) - } - }) + } } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bfc694e6..5fcd3cab 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -105,8 +105,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" - android:paddingLeft="@dimen/activity_margin" - android:paddingRight="@dimen/activity_margin" app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> + android:foreground="@drawable/selector" + android:paddingLeft="@dimen/activity_margin" + android:paddingRight="@dimen/activity_margin"> + android:textSize="@dimen/bigger_text_size" + tools:text="Song Title"/> + android:textSize="@dimen/normal_text_size" + tools:text="Song Artist"/>