adding a placeholder to empty playlists

This commit is contained in:
tibbi 2020-10-25 10:33:08 +01:00
parent ec4fc67173
commit c4604e244d
2 changed files with 45 additions and 0 deletions

View file

@ -8,6 +8,9 @@ import android.view.MenuItem
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.underlineText
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.musicplayer.R
import com.simplemobiletools.musicplayer.adapters.TracksAdapter
@ -48,11 +51,21 @@ class TracksActivity : SimpleActivity() {
title = playlist?.title ?: album.title
tracks_placeholder_2.setTextColor(getAdjustedPrimaryColor())
tracks_placeholder_2.underlineText()
tracks_placeholder_2.setOnClickListener {
addFolderToPlaylist()
}
ensureBackgroundThread {
val tracks = ArrayList<Track>()
val listItems = ArrayList<ListItem>()
if (playlist != null) {
val playlistTracks = tracksDAO.getTracksFromPlaylist(playlist!!.id)
tracks_placeholder.beVisibleIf(playlistTracks.isEmpty())
tracks_placeholder_2.beVisibleIf(playlistTracks.isEmpty())
tracks_list.beVisibleIf(playlistTracks.isNotEmpty())
tracks.addAll(playlistTracks)
listItems.addAll(tracks)
} else {
@ -145,6 +158,10 @@ class TracksActivity : SimpleActivity() {
val newTracks = tracksDAO.getTracksFromPlaylist(playlist!!.id).toMutableList() as ArrayList<Track>
runOnUiThread {
(tracks_list.adapter as? TracksAdapter)?.updateItems(newTracks)
tracks_placeholder.beVisibleIf(newTracks.isEmpty())
tracks_placeholder_2.beVisibleIf(newTracks.isEmpty())
tracks_list.beVisibleIf(newTracks.isNotEmpty())
}
}
}

View file

@ -5,6 +5,34 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/tracks_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:alpha="0.8"
android:gravity="center"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/no_items_found"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/tracks_placeholder_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tracks_placeholder"
android:layout_centerHorizontal="true"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:padding="@dimen/activity_margin"
android:text="@string/add_folder_to_playlist"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/tracks_list"
android:layout_width="match_parent"