do some preparation for Albums viewpager item + some renaming
This commit is contained in:
parent
aa8c36510d
commit
d7610813fb
13 changed files with 78 additions and 19 deletions
|
@ -7,7 +7,7 @@ import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.extensions.getFormattedDuration
|
import com.simplemobiletools.commons.extensions.getFormattedDuration
|
||||||
import com.simplemobiletools.musicplayer.R
|
import com.simplemobiletools.musicplayer.R
|
||||||
import com.simplemobiletools.musicplayer.adapters.AlbumsAdapter
|
import com.simplemobiletools.musicplayer.adapters.AlbumsTracksAdapter
|
||||||
import com.simplemobiletools.musicplayer.extensions.getAlbumTracksSync
|
import com.simplemobiletools.musicplayer.extensions.getAlbumTracksSync
|
||||||
import com.simplemobiletools.musicplayer.extensions.getAlbums
|
import com.simplemobiletools.musicplayer.extensions.getAlbums
|
||||||
import com.simplemobiletools.musicplayer.extensions.resetQueueItems
|
import com.simplemobiletools.musicplayer.extensions.resetQueueItems
|
||||||
|
@ -40,7 +40,7 @@ class AlbumsActivity : SimpleActivity() {
|
||||||
|
|
||||||
getAlbums(artist) { albums ->
|
getAlbums(artist) { albums ->
|
||||||
val listItems = ArrayList<ListItem>()
|
val listItems = ArrayList<ListItem>()
|
||||||
val albumsSectionLabel = resources.getQuantityString(R.plurals.albums, albums.size, albums.size)
|
val albumsSectionLabel = resources.getQuantityString(R.plurals.albums_plural, albums.size, albums.size)
|
||||||
listItems.add(AlbumSection(albumsSectionLabel))
|
listItems.add(AlbumSection(albumsSectionLabel))
|
||||||
listItems.addAll(albums)
|
listItems.addAll(albums)
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ class AlbumsActivity : SimpleActivity() {
|
||||||
tracksToAdd.addAll(tracks)
|
tracksToAdd.addAll(tracks)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tracksSectionLabel = resources.getQuantityString(R.plurals.tracks, tracksToAdd.size, tracksToAdd.size)
|
var tracksSectionLabel = resources.getQuantityString(R.plurals.tracks_plural, tracksToAdd.size, tracksToAdd.size)
|
||||||
tracksSectionLabel += " • ${trackFullDuration.getFormattedDuration(true)}"
|
tracksSectionLabel += " • ${trackFullDuration.getFormattedDuration(true)}"
|
||||||
listItems.add(AlbumSection(tracksSectionLabel))
|
listItems.add(AlbumSection(tracksSectionLabel))
|
||||||
listItems.addAll(tracksToAdd)
|
listItems.addAll(tracksToAdd)
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val adapter = AlbumsAdapter(this, listItems, albums_list, albums_fastscroller) {
|
val adapter = AlbumsTracksAdapter(this, listItems, albums_list, albums_fastscroller) {
|
||||||
if (it is Album) {
|
if (it is Album) {
|
||||||
Intent(this, TracksActivity::class.java).apply {
|
Intent(this, TracksActivity::class.java).apply {
|
||||||
putExtra(ALBUM, Gson().toJson(it))
|
putExtra(ALBUM, Gson().toJson(it))
|
||||||
|
|
|
@ -34,7 +34,7 @@ import com.simplemobiletools.musicplayer.services.MusicService
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.android.synthetic.main.fragment_artists.*
|
import kotlinx.android.synthetic.main.fragment_artists.*
|
||||||
import kotlinx.android.synthetic.main.fragment_playlists.*
|
import kotlinx.android.synthetic.main.fragment_playlists.*
|
||||||
import kotlinx.android.synthetic.main.fragment_songs.*
|
import kotlinx.android.synthetic.main.fragment_old_songs.*
|
||||||
import kotlinx.android.synthetic.main.view_current_track_bar.*
|
import kotlinx.android.synthetic.main.view_current_track_bar.*
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
|
@ -179,6 +179,7 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
viewpager.adapter = ViewPagerAdapter(this)
|
viewpager.adapter = ViewPagerAdapter(this)
|
||||||
|
viewpager.offscreenPageLimit = 3
|
||||||
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {}
|
override fun onPageScrollStateChanged(state: Int) {}
|
||||||
|
|
||||||
|
@ -199,7 +200,7 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val tabLabels = arrayOf(getString(R.string.artists), getString(R.string.playlists))
|
val tabLabels = arrayOf(getString(R.string.artists), getString(R.string.albums), getString(R.string.playlists))
|
||||||
main_tabs_holder.apply {
|
main_tabs_holder.apply {
|
||||||
setTabTextColors(config.textColor, getAdjustedPrimaryColor())
|
setTabTextColors(config.textColor, getAdjustedPrimaryColor())
|
||||||
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||||
|
|
|
@ -30,8 +30,8 @@ import kotlinx.android.synthetic.main.item_song.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
// we show both albums and individual tracks here
|
// we show both albums and individual tracks here
|
||||||
class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
|
class AlbumsTracksAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
|
||||||
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||||
|
|
||||||
private val ITEM_SECTION = 0
|
private val ITEM_SECTION = 0
|
||||||
private val ITEM_ALBUM = 1
|
private val ITEM_ALBUM = 1
|
||||||
|
@ -44,7 +44,7 @@ class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, re
|
||||||
setupDragListener(true)
|
setupDragListener(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getActionMenuId() = R.menu.cab_albums
|
override fun getActionMenuId() = R.menu.cab_albums_tracks
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val layout = when (viewType) {
|
val layout = when (viewType) {
|
|
@ -112,8 +112,8 @@ class ArtistsAdapter(activity: SimpleActivity, val artists: ArrayList<Artist>, r
|
||||||
artist_title.text = artist.title
|
artist_title.text = artist.title
|
||||||
artist_title.setTextColor(textColor)
|
artist_title.setTextColor(textColor)
|
||||||
|
|
||||||
val albums = resources.getQuantityString(R.plurals.albums, artist.albumCnt, artist.albumCnt)
|
val albums = resources.getQuantityString(R.plurals.albums_plural, artist.albumCnt, artist.albumCnt)
|
||||||
val tracks = resources.getQuantityString(R.plurals.tracks, artist.trackCnt, artist.trackCnt)
|
val tracks = resources.getQuantityString(R.plurals.tracks_plural, artist.trackCnt, artist.trackCnt)
|
||||||
artist_albums_tracks.text = "$albums, $tracks"
|
artist_albums_tracks.text = "$albums, $tracks"
|
||||||
artist_albums_tracks.setTextColor(textColor)
|
artist_albums_tracks.setTextColor(textColor)
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ class PlaylistsAdapter(activity: SimpleActivity, val playlists: ArrayList<Playli
|
||||||
playlist_title.text = playlist.title
|
playlist_title.text = playlist.title
|
||||||
playlist_title.setTextColor(textColor)
|
playlist_title.setTextColor(textColor)
|
||||||
|
|
||||||
val tracks = resources.getQuantityString(R.plurals.tracks, playlist.trackCnt, playlist.trackCnt)
|
val tracks = resources.getQuantityString(R.plurals.tracks_plural, playlist.trackCnt, playlist.trackCnt)
|
||||||
playlist_tracks.text = tracks
|
playlist_tracks.text = tracks
|
||||||
playlist_tracks.setTextColor(textColor)
|
playlist_tracks.setTextColor(textColor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,11 @@ import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.musicplayer.R
|
import com.simplemobiletools.musicplayer.R
|
||||||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||||
import com.simplemobiletools.musicplayer.extensions.addQueueItems
|
|
||||||
import com.simplemobiletools.musicplayer.extensions.addTracksToPlaylist
|
import com.simplemobiletools.musicplayer.extensions.addTracksToPlaylist
|
||||||
import com.simplemobiletools.musicplayer.extensions.addTracksToQueue
|
import com.simplemobiletools.musicplayer.extensions.addTracksToQueue
|
||||||
import com.simplemobiletools.musicplayer.models.AlbumHeader
|
import com.simplemobiletools.musicplayer.models.AlbumHeader
|
||||||
import com.simplemobiletools.musicplayer.models.ListItem
|
import com.simplemobiletools.musicplayer.models.ListItem
|
||||||
import com.simplemobiletools.musicplayer.models.Track
|
import com.simplemobiletools.musicplayer.models.Track
|
||||||
import com.simplemobiletools.musicplayer.services.MusicService
|
|
||||||
import kotlinx.android.synthetic.main.item_album_header.view.*
|
import kotlinx.android.synthetic.main.item_album_header.view.*
|
||||||
import kotlinx.android.synthetic.main.item_song.view.*
|
import kotlinx.android.synthetic.main.item_song.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -146,7 +144,7 @@ class SongsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, rec
|
||||||
album_title.text = header.title
|
album_title.text = header.title
|
||||||
album_artist.text = header.artist
|
album_artist.text = header.artist
|
||||||
|
|
||||||
val tracks = resources.getQuantityString(R.plurals.tracks, header.songCnt, header.songCnt)
|
val tracks = resources.getQuantityString(R.plurals.tracks_plural, header.songCnt, header.songCnt)
|
||||||
var year = ""
|
var year = ""
|
||||||
if (header.year != 0) {
|
if (header.year != 0) {
|
||||||
year = "${header.year} • "
|
year = "${header.year} • "
|
||||||
|
|
|
@ -24,12 +24,13 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||||
container.removeView(item as View)
|
container.removeView(item as View)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCount() = 2
|
override fun getCount() = 3
|
||||||
|
|
||||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||||
|
|
||||||
private fun getFragment(position: Int) = when (position) {
|
private fun getFragment(position: Int) = when (position) {
|
||||||
0 -> R.layout.fragment_artists
|
0 -> R.layout.fragment_artists
|
||||||
|
1 -> R.layout.fragment_albums
|
||||||
else -> R.layout.fragment_playlists
|
else -> R.layout.fragment_playlists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.simplemobiletools.musicplayer.fragments
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
|
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.musicplayer.extensions.getAlbumsSync
|
||||||
|
import com.simplemobiletools.musicplayer.extensions.getArtistsSync
|
||||||
|
import com.simplemobiletools.musicplayer.models.Album
|
||||||
|
import kotlinx.android.synthetic.main.fragment_albums.view.*
|
||||||
|
|
||||||
|
// Artists -> Albums -> Tracks
|
||||||
|
class AlbumsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||||
|
override fun setupFragment(activity: SimpleActivity) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
val albums = ArrayList<Album>()
|
||||||
|
|
||||||
|
val artists = activity.getArtistsSync()
|
||||||
|
artists.forEach { artist ->
|
||||||
|
albums.addAll(activity.getAlbumsSync(artist))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
albums_fastscroller.updatePrimaryColor()
|
||||||
|
albums_fastscroller.updateBubbleColors()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun finishActMode() {
|
||||||
|
(albums_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ import com.simplemobiletools.musicplayer.helpers.PROGRESS
|
||||||
import com.simplemobiletools.musicplayer.helpers.SET_PROGRESS
|
import com.simplemobiletools.musicplayer.helpers.SET_PROGRESS
|
||||||
import com.simplemobiletools.musicplayer.models.Track
|
import com.simplemobiletools.musicplayer.models.Track
|
||||||
import com.simplemobiletools.musicplayer.services.MusicService
|
import com.simplemobiletools.musicplayer.services.MusicService
|
||||||
import kotlinx.android.synthetic.main.fragment_songs.view.*
|
import kotlinx.android.synthetic.main.fragment_old_songs.view.*
|
||||||
import kotlinx.android.synthetic.main.item_navigation.view.*
|
import kotlinx.android.synthetic.main.item_navigation.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
26
app/src/main/res/layout/fragment_albums.xml
Normal file
26
app/src/main/res/layout/fragment_albums.xml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.simplemobiletools.musicplayer.fragments.AlbumsFragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/albums_fragment_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/albums_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.FastScroller
|
||||||
|
android:id="@+id/albums_fastscroller"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:paddingStart="@dimen/normal_margin">
|
||||||
|
|
||||||
|
<include layout="@layout/fastscroller_handle_vertical" />
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.FastScroller>
|
||||||
|
|
||||||
|
</com.simplemobiletools.musicplayer.fragments.AlbumsFragment>
|
|
@ -50,12 +50,13 @@
|
||||||
|
|
||||||
<!-- Artists -->
|
<!-- Artists -->
|
||||||
<string name="artists">Artists</string>
|
<string name="artists">Artists</string>
|
||||||
<plurals name="albums">
|
<string name="albums">Albums</string>
|
||||||
|
<plurals name="albums_plural">
|
||||||
<item quantity="one">%d Album</item>
|
<item quantity="one">%d Album</item>
|
||||||
<item quantity="other">%d Albums</item>
|
<item quantity="other">%d Albums</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
<plurals name="tracks">
|
<plurals name="tracks_plural">
|
||||||
<item quantity="one">%d Track</item>
|
<item quantity="one">%d Track</item>
|
||||||
<item quantity="other">%d Tracks</item>
|
<item quantity="other">%d Tracks</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
Loading…
Reference in a new issue