update commons to 3.0.21

This commit is contained in:
tibbi 2017-12-01 19:36:22 +01:00
parent 61c627a2e3
commit f01973f1ad
7 changed files with 77 additions and 76 deletions

View file

@ -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'

View file

@ -40,8 +40,8 @@ import java.util.*
class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
private var isThirdPartyIntent = false
private var storedUseEnglish = false
private var songs = ArrayList<Song>()
lateinit var bus: Bus
private var songs: ArrayList<Song> = 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()
}
}

View file

@ -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)

View file

@ -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)
}
}
})
}
}
}

View file

@ -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)
}
})
}
}
}
}

View file

@ -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"/>
<com.simplemobiletools.commons.views.FastScroller

View file

@ -1,20 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/song_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector">
android:foreground="@drawable/selector"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin">
<RelativeLayout
android:id="@+id/song_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:paddingTop="@dimen/medium_margin">
<com.simplemobiletools.commons.views.MyTextView
@ -24,8 +26,8 @@
android:layout_toLeftOf="@+id/song_note_image"
android:ellipsize="end"
android:maxLines="3"
android:text="Song Title"
android:textSize="@dimen/bigger_text_size"/>
android:textSize="@dimen/bigger_text_size"
tools:text="Song Title"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/song_artist"
@ -35,8 +37,8 @@
android:layout_toLeftOf="@+id/song_note_image"
android:ellipsize="end"
android:maxLines="3"
android:text="Song Artist"
android:textSize="@dimen/normal_text_size"/>
android:textSize="@dimen/normal_text_size"
tools:text="Song Artist"/>
<ImageView
android:id="@+id/song_note_image"