properly show empty playlist placeholder whenever appropriate
This commit is contained in:
parent
0c04d32b4d
commit
858ea8f3bd
4 changed files with 47 additions and 22 deletions
|
@ -3,6 +3,7 @@ package com.simplemobiletools.musicplayer.activities
|
|||
import android.app.SearchManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Paint
|
||||
import android.media.AudioManager
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
|
@ -16,6 +17,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
|||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
import com.simplemobiletools.musicplayer.BuildConfig
|
||||
|
@ -40,7 +42,7 @@ import kotlinx.android.synthetic.main.activity_main.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
||||
class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener, RefreshRecyclerViewListener {
|
||||
private var isThirdPartyIntent = false
|
||||
private var songs = ArrayList<Song>()
|
||||
private var searchMenuItem: MenuItem? = null
|
||||
|
@ -87,7 +89,8 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
setupIconColors()
|
||||
markCurrentSong()
|
||||
updateTextColors(main_holder)
|
||||
songs_playlist_empty_add_folder.background.applyColorFilter(config.textColor)
|
||||
songs_playlist_empty_add_folder.setTextColor(getAdjustedPrimaryColor())
|
||||
songs_playlist_empty_add_folder.paintFlags = songs_playlist_empty_add_folder.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
|
||||
songs_fastscroller.allowBubbleDisplay = config.showInfoBubble
|
||||
songs_fastscroller.updateBubbleColors()
|
||||
|
@ -105,6 +108,15 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bus.unregister(this)
|
||||
|
||||
if (isThirdPartyIntent) {
|
||||
sendIntent(FINISH)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
setupSearch(menu)
|
||||
|
@ -179,13 +191,20 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
|
||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||
songs_playlist_empty.text = getString(R.string.no_items_found)
|
||||
songs_playlist_empty_add_folder.beGone()
|
||||
main_header_holder.beGone()
|
||||
isSearchOpen = true
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||
songs_playlist_empty.text = getString(R.string.playlist_empty)
|
||||
songs_playlist_empty_add_folder.beVisibleIf(songs.isEmpty())
|
||||
main_header_holder.beVisible()
|
||||
if (isSearchOpen) {
|
||||
searchQueryChanged("")
|
||||
}
|
||||
isSearchOpen = false
|
||||
return true
|
||||
}
|
||||
|
@ -383,7 +402,7 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
}
|
||||
|
||||
if (currAdapter == null) {
|
||||
SongAdapter(this@MainActivity, songs, songs_list, songs_fastscroller) {
|
||||
SongAdapter(this@MainActivity, songs, this, songs_list, songs_fastscroller) {
|
||||
songPicked(getSongIndex(it as Song))
|
||||
}.apply {
|
||||
setupDragListener(true)
|
||||
|
@ -406,15 +425,6 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
|
||||
private fun getSongIndex(song: Song): Int = songs.indexOfFirstOrNull { it == song } ?: 0
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bus.unregister(this)
|
||||
|
||||
if (isThirdPartyIntent) {
|
||||
sendIntent(FINISH)
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun songChangedEvent(event: Events.SongChanged) {
|
||||
updateSongInfo(event.song)
|
||||
|
@ -452,6 +462,7 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
private fun searchQueryChanged(text: String) {
|
||||
val filtered = songs.filter { it.artist.contains(text, true) || it.title.contains(text, true) } as ArrayList
|
||||
filtered.sortBy { !(it.artist.startsWith(text, true) || it.title.startsWith(text, true)) }
|
||||
songs_playlist_empty.beVisibleIf(filtered.isEmpty())
|
||||
(songs_list.adapter as? SongAdapter)?.updateSongs(filtered)
|
||||
}
|
||||
|
||||
|
@ -472,6 +483,10 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
sendIntent(REFRESH_LIST)
|
||||
}
|
||||
|
||||
private fun checkWhatsNewDialog() {
|
||||
arrayListOf<Release>().apply {
|
||||
add(Release(25, R.string.release_25))
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.simplemobiletools.commons.extensions.applyColorFilter
|
|||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import com.simplemobiletools.commons.extensions.deleteFiles
|
||||
import com.simplemobiletools.commons.extensions.shareUris
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.musicplayer.BuildConfig
|
||||
|
@ -31,8 +32,8 @@ import kotlinx.android.synthetic.main.item_song.view.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit)
|
||||
: MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, val listener: RefreshRecyclerViewListener, recyclerView: MyRecyclerView,
|
||||
fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private var currentSongIndex = 0
|
||||
private var songsHashCode = songs.hashCode()
|
||||
|
@ -145,6 +146,10 @@ class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, recycler
|
|||
activity.dbHelper.removeSongsFromPlaylist(paths, -1)
|
||||
activity.deleteFiles(files) { }
|
||||
removeSelectedItems()
|
||||
|
||||
if (songs.isEmpty()) {
|
||||
listener.refreshItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +174,10 @@ class SongAdapter(activity: SimpleActivity, var songs: ArrayList<Song>, recycler
|
|||
songs.removeAll(removeSongs)
|
||||
activity.dbHelper.removeSongsFromPlaylist(paths)
|
||||
removeSelectedItems()
|
||||
|
||||
if (songs.isEmpty()) {
|
||||
listener.refreshItems()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSongs(newSongs: ArrayList<Song>) {
|
||||
|
|
|
@ -150,8 +150,9 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||
val rows = getCellsForSize(minHeight)
|
||||
|
||||
var layoutId = R.layout.widget
|
||||
if (rows == 1)
|
||||
if (rows == 1) {
|
||||
layoutId = R.layout.small_widget
|
||||
}
|
||||
|
||||
return RemoteViews(context.packageName, layoutId)
|
||||
}
|
||||
|
|
|
@ -131,8 +131,11 @@
|
|||
android:id="@+id/songs_playlist_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha="0.7"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="@dimen/big_margin"
|
||||
android:paddingRight="@dimen/big_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:text="@string/playlist_empty"
|
||||
android:textSize="@dimen/bigger_text_size"/>
|
||||
|
||||
|
@ -142,14 +145,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/songs_playlist_empty"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:alpha="0.7"
|
||||
android:background="@drawable/button_background"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:padding="@dimen/normal_margin"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/add_folder_to_playlist"
|
||||
android:textAllCaps="true"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/bigger_text_size"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue