diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Artist.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Artist.kt index 1c8e6440..3da622c6 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Artist.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Artist.kt @@ -11,21 +11,4 @@ data class Artist( override var coverArt: String? = null, override var albumCount: Long? = null, override var closeness: Int = 0 -) : ArtistOrIndex(id) { - - fun compareTo(other: Artist): Int { - when { - this.closeness == other.closeness -> { - return 0 - } - this.closeness > other.closeness -> { - return -1 - } - else -> { - return 1 - } - } - } - - override fun compareTo(other: Identifiable) = compareTo(other as Artist) -} +) : ArtistOrIndex(id) diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/ArtistOrIndex.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/ArtistOrIndex.kt index 586f1dae..602cae66 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/ArtistOrIndex.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/ArtistOrIndex.kt @@ -15,4 +15,21 @@ abstract class ArtistOrIndex( open var albumCount: Long? = null, @Ignore open var closeness: Int = 0 -) : GenericEntry() +) : GenericEntry() { + + fun compareTo(other: ArtistOrIndex): Int { + when { + this.closeness == other.closeness -> { + return 0 + } + this.closeness > other.closeness -> { + return -1 + } + else -> { + return 1 + } + } + } + + override fun compareTo(other: Identifiable) = compareTo(other as ArtistOrIndex) +} diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Identifiable.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Identifiable.kt index b316ce8e..71a57502 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Identifiable.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Identifiable.kt @@ -3,19 +3,17 @@ package org.moire.ultrasonic.domain import androidx.room.Ignore abstract class GenericEntry : Identifiable { - abstract override val id: String @Ignore open val name: String? = null - override fun compareTo(other: Identifiable): Int { - return this.id.toInt().compareTo(other.id.toInt()) - } - @delegate:Ignore - override val longId: Long by lazy { - id.hashCode().toLong() - } } interface Identifiable : Comparable { val id: String + val longId: Long + get() = id.hashCode().toLong() + + override fun compareTo(other: Identifiable): Int { + return longId.compareTo(other.longId) + } } diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt index b409acab..e316dc42 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt @@ -32,7 +32,7 @@ class MusicDirectory : ArrayList() { } } - abstract class Child : Identifiable, GenericEntry() { + abstract class Child : GenericEntry() { abstract override var id: String abstract var parent: String? abstract var isDirectory: Boolean diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/SearchResult.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/SearchResult.kt index 7c8ee9bd..ec576d8f 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/SearchResult.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/SearchResult.kt @@ -7,7 +7,7 @@ import org.moire.ultrasonic.domain.MusicDirectory.Entry * The result of a search. Contains matching artists, albums and songs. */ data class SearchResult( - val artists: List = listOf(), + val artists: List = listOf(), val albums: List = listOf(), val songs: List = listOf() ) diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Album.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Album.kt index 801634c3..47ad7cd8 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Album.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Album.kt @@ -7,8 +7,8 @@ data class Album( val id: String = "", val parent: String = "", val album: String = "", - val title: String = "", - val name: String = "", + val title: String? = null, + val name: String? = null, val discNumber: Int = 0, val coverArt: String = "", val songCount: Int = 0, diff --git a/gradle.properties b/gradle.properties index 19077ae1..2635181c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,8 @@ org.gradle.parallel=true org.gradle.daemon=true org.gradle.configureondemand=true org.gradle.caching=true -org.gradle.jvmargs=-Xmx2g +org.gradle.jvmargs=-Xmx2g -XX:+UseParallelGC + kotlin.incremental=true kotlin.caching.enabled=true diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/view/ArtistAdapter.java b/ultrasonic/src/main/java/org/moire/ultrasonic/view/ArtistAdapter.java deleted file mode 100644 index b29de4e6..00000000 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/view/ArtistAdapter.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2010 (C) Sindre Mehus - */ -package org.moire.ultrasonic.view; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.SectionIndexer; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.moire.ultrasonic.R; -import org.moire.ultrasonic.domain.Artist; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; - -/** - * @author Sindre Mehus - */ -public class ArtistAdapter extends ArrayAdapter implements SectionIndexer -{ - private final LayoutInflater layoutInflater; - - // Both arrays are indexed by section ID. - private final Object[] sections; - private final Integer[] positions; - - public ArtistAdapter(Context context, List artists) - { - super(context, R.layout.list_item_generic, artists); - - layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - Collection sectionSet = new LinkedHashSet(30); - List positionList = new ArrayList(30); - - for (int i = 0; i < artists.size(); i++) - { - Artist artist = artists.get(i); - String index = artist.getIndex(); - - if (!sectionSet.contains(index)) - { - sectionSet.add(index); - positionList.add(i); - } - } - - sections = sectionSet.toArray(new Object[0]); - positions = positionList.toArray(new Integer[0]); - } - - @NonNull - @Override - public View getView( - int position, - @Nullable View convertView, - @NonNull ViewGroup parent - ) { - View rowView = convertView; - if (rowView == null) { - rowView = layoutInflater.inflate(R.layout.list_item_generic, parent, false); - } - ((TextView) rowView).setText(getItem(position).getName()); - - return rowView; - } - - @Override - public Object[] getSections() - { - return sections; - } - - @Override - public int getPositionForSection(int section) - { - return positions.length > section ? positions[section] : 0; - } - - @Override - public int getSectionForPosition(int pos) - { - for (int i = 0; i < sections.length - 1; i++) - { - if (pos < positions[i + 1]) - { - return i; - } - } - - return sections.length - 1; - } -} diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumHeader.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumHeader.kt index 978ead6f..da300de0 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumHeader.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumHeader.kt @@ -88,8 +88,4 @@ class AlbumHeader( override val longId: Long get() = -1L - - override fun compareTo(other: Identifiable): Int { - return this.longId.compareTo(other.longId) - } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/BaseAdapter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/BaseAdapter.kt index d17f25e2..2deaf433 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/BaseAdapter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/BaseAdapter.kt @@ -52,8 +52,6 @@ class BaseAdapter : MultiTypeAdapter() { return mDiffer.currentList[position] } - // override getIt - override var items: List get() = getCurrentList() set(value) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt index b4f4627c..6e862163 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt @@ -41,9 +41,5 @@ class DividerBinder : ItemViewBinder Unit) - ): Identifiable { + ) : Identifiable { override val id: String get() = stringId.toString() - override val longId: Long - get() = stringId.toLong() - - override fun compareTo(other: Identifiable): Int = longId.compareTo(other.longId) } - } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt index acccda31..eb42d409 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt @@ -7,7 +7,7 @@ import org.moire.ultrasonic.api.subsonic.models.Album fun Album.toDomainEntity(): MusicDirectory.Album = MusicDirectory.Album( id = this@toDomainEntity.id, - title = this@toDomainEntity.title, + title = this@toDomainEntity.name ?: this@toDomainEntity.title, album = this@toDomainEntity.album, coverArt = this@toDomainEntity.coverArt, artist = this@toDomainEntity.artist, diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt index e719e8f8..92e4ed2e 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt @@ -9,15 +9,12 @@ package org.moire.ultrasonic.fragment import android.os.Bundle import android.view.View -import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.lifecycle.LiveData import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.RecyclerView import org.moire.ultrasonic.R import org.moire.ultrasonic.adapters.AlbumRowBinder -import org.moire.ultrasonic.adapters.FolderSelectorBinder -import org.moire.ultrasonic.domain.Identifiable import org.moire.ultrasonic.domain.MusicDirectory import org.moire.ultrasonic.model.AlbumListModel import org.moire.ultrasonic.util.Constants @@ -40,7 +37,10 @@ class AlbumListFragment : EntryListFragment() { /** * The central function to pass a query to the model and return a LiveData object */ - override fun getLiveData(args: Bundle?, refresh: Boolean): LiveData> { + override fun getLiveData( + args: Bundle?, + refresh: Boolean + ): LiveData> { if (args == null) throw IllegalArgumentException("Required arguments are missing") val refresh = args.getBoolean(Constants.INTENT_EXTRA_NAME_REFRESH) || refresh diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListFragment.kt index 73346de6..36490411 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListFragment.kt @@ -2,25 +2,20 @@ package org.moire.ultrasonic.fragment import android.os.Bundle import android.view.View -import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.lifecycle.LiveData +import androidx.navigation.NavController import androidx.navigation.fragment.findNavController import org.moire.ultrasonic.R import org.moire.ultrasonic.adapters.ArtistRowBinder -import org.moire.ultrasonic.adapters.FolderSelectorBinder import org.moire.ultrasonic.domain.Artist import org.moire.ultrasonic.domain.ArtistOrIndex -import org.moire.ultrasonic.domain.Identifiable import org.moire.ultrasonic.domain.Index -import org.moire.ultrasonic.domain.MusicDirectory import org.moire.ultrasonic.model.ArtistListModel import org.moire.ultrasonic.util.Constants /** - * Displays the list of Artists from the media library - * - * FIXME: FOLDER HEADER NOT POPULATED ON FIST LOAD + * Displays the list of Artists or Indexes (folders) from the media library */ class ArtistListFragment : EntryListFragment() { @@ -60,23 +55,32 @@ class ArtistListFragment : EntryListFragment() { * If we are showing artists, we need to go to AlbumList */ override fun onItemClick(item: ArtistOrIndex) { - val bundle = Bundle() + Companion.onItemClick(item, findNavController()) + } - // Common arguments - bundle.putString(Constants.INTENT_EXTRA_NAME_ID, item.id) - bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, item.name) - bundle.putString(Constants.INTENT_EXTRA_NAME_PARENT_ID, item.id) - bundle.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, (item is Artist)) + companion object { + fun onItemClick(item: ArtistOrIndex, navController: NavController) { + val bundle = Bundle() - // Check type - if (item is Index) { - findNavController().navigate(R.id.artistsListToTrackCollection, bundle) - } else { - bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, Constants.ALBUMS_OF_ARTIST) - bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, item.name) - bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 1000) - bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) - findNavController().navigate(R.id.artistsListToAlbumsList, bundle) + // Common arguments + bundle.putString(Constants.INTENT_EXTRA_NAME_ID, item.id) + bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, item.name) + bundle.putString(Constants.INTENT_EXTRA_NAME_PARENT_ID, item.id) + bundle.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, (item is Artist)) + + // Check type + if (item is Index) { + navController.navigate(R.id.artistsListToTrackCollection, bundle) + } else { + bundle.putString( + Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, + Constants.ALBUMS_OF_ARTIST + ) + bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, item.name) + bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 1000) + bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + navController.navigate(R.id.artistsListToAlbumsList, bundle) + } } } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt index 00726af2..ffb127f0 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt @@ -9,7 +9,6 @@ import androidx.navigation.fragment.findNavController import org.moire.ultrasonic.R import org.moire.ultrasonic.adapters.FolderSelectorBinder import org.moire.ultrasonic.domain.Artist -import org.moire.ultrasonic.domain.ArtistOrIndex import org.moire.ultrasonic.domain.GenericEntry import org.moire.ultrasonic.domain.Identifiable import org.moire.ultrasonic.service.RxBus @@ -50,6 +49,10 @@ abstract class EntryListFragment : MultiListFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + // Call a cheap function on ServerSettingsModel to make sure it is initialized by Koin, + // because it can't be initialized from inside the callback + serverSettingsModel.toString() + RxBus.musicFolderChangedEventObservable.subscribe { if (!listModel.isOffline()) { val currentSetting = listModel.activeServer diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt index ded120e4..eeddb97b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt @@ -3,17 +3,16 @@ package org.moire.ultrasonic.fragment import android.app.SearchManager import android.content.Context import android.os.Bundle -import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.widget.ListAdapter import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.lifecycle.viewModelScope import androidx.navigation.Navigation +import androidx.navigation.fragment.findNavController import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import kotlinx.coroutines.launch import org.koin.core.component.KoinComponent @@ -26,7 +25,9 @@ import org.moire.ultrasonic.adapters.MoreButtonBinder import org.moire.ultrasonic.adapters.MoreButtonBinder.MoreButton import org.moire.ultrasonic.adapters.TrackViewBinder import org.moire.ultrasonic.domain.Artist +import org.moire.ultrasonic.domain.ArtistOrIndex import org.moire.ultrasonic.domain.Identifiable +import org.moire.ultrasonic.domain.Index import org.moire.ultrasonic.domain.MusicDirectory import org.moire.ultrasonic.domain.SearchResult import org.moire.ultrasonic.fragment.FragmentTitle.Companion.setTitle @@ -41,12 +42,10 @@ import org.moire.ultrasonic.util.CommunicationError import org.moire.ultrasonic.util.Constants import org.moire.ultrasonic.util.Settings import org.moire.ultrasonic.util.Util.toast -import org.moire.ultrasonic.view.ArtistAdapter import timber.log.Timber /** * Initiates a search on the media library and displays the results - * FIXME: Artist click, display */ class SearchFragment : MultiListFragment(), KoinComponent { private var searchResult: SearchResult? = null @@ -265,11 +264,28 @@ class SearchFragment : MultiListFragment(), KoinComponent { populateList(listModel.trimResultLength(searchResult!!, maxSongs = Int.MAX_VALUE)) } - private fun onArtistSelected(artist: Artist) { + private fun onArtistSelected(item: ArtistOrIndex) { val bundle = Bundle() - bundle.putString(Constants.INTENT_EXTRA_NAME_ID, artist.id) - bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.id) - Navigation.findNavController(requireView()).navigate(R.id.searchToSelectAlbum, bundle) + + // Common arguments + bundle.putString(Constants.INTENT_EXTRA_NAME_ID, item.id) + bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, item.name) + bundle.putString(Constants.INTENT_EXTRA_NAME_PARENT_ID, item.id) + bundle.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, (item is Artist)) + + // Check type + if (item is Index) { + findNavController().navigate(R.id.searchToTrackCollection, bundle) + } else { + bundle.putString( + Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, + Constants.ALBUMS_OF_ARTIST + ) + bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, item.name) + bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 1000) + bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + findNavController().navigate(R.id.searchToAlbumsList, bundle) + } } private fun onAlbumSelected(album: MusicDirectory.Album, autoplay: Boolean) { @@ -278,14 +294,21 @@ class SearchFragment : MultiListFragment(), KoinComponent { bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, album.title) bundle.putBoolean(Constants.INTENT_EXTRA_NAME_IS_ALBUM, album.isDirectory) bundle.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay) - Navigation.findNavController(requireView()).navigate(R.id.searchToSelectAlbum, bundle) + Navigation.findNavController(requireView()).navigate(R.id.searchToTrackCollection, bundle) } private fun onSongSelected(song: MusicDirectory.Entry, append: Boolean) { if (!append) { mediaPlayerController.clear() } - mediaPlayerController.addToPlaylist(listOf(song), false, false, false, false, false) + mediaPlayerController.addToPlaylist( + listOf(song), + save = false, + autoPlay = false, + playNext = false, + shuffle = false, + newPlaylist = false + ) mediaPlayerController.play(mediaPlayerController.playlistSize - 1) toast(context, resources.getQuantityString(R.plurals.select_album_n_songs_added, 1, 1)) } @@ -304,7 +327,7 @@ class SearchFragment : MultiListFragment(), KoinComponent { override fun onItemClick(item: Identifiable) { when (item) { - is Artist -> { + is ArtistOrIndex -> { onArtistSelected(item) } is MusicDirectory.Entry -> { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt index 5cd254a5..ecd62571 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt @@ -49,13 +49,11 @@ import org.moire.ultrasonic.util.Settings import org.moire.ultrasonic.util.Util /** - * * Displays a group of tracks, eg. the songs of an album, of a playlist etc. * * In most cases the data should be just a list of Entries, but there are some cases * where the list can contain Albums as well. This happens especially when having ID3 tags disabled, * or using Offline mode, both in which Indexes instead of Artists are being used. - * */ @Suppress("TooManyFunctions") open class TrackCollectionFragment : MultiListFragment() { @@ -96,7 +94,7 @@ open class TrackCollectionFragment : MultiListFragment() { // Setup refresh handler refreshListView = view.findViewById(refreshListId) refreshListView?.setOnRefreshListener { - refreshData(true) + getLiveData(arguments, true) } // TODO: remove special casing for songsForGenre @@ -209,12 +207,6 @@ open class TrackCollectionFragment : MultiListFragment() { refreshListView?.isRefreshing = false } - private fun refreshData(refresh: Boolean = false) { - val args = getArgumentsClone() - args.putBoolean(Constants.INTENT_EXTRA_NAME_REFRESH, refresh) - getLiveData(args) - } - override fun onPrepareOptionsMenu(menu: Menu) { super.onPrepareOptionsMenu(menu) playAllButton = menu.findItem(R.id.select_album_play_all) @@ -293,8 +285,6 @@ open class TrackCollectionFragment : MultiListFragment() { } val isArtist = arguments?.getBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, false) ?: false - - // FIXME WHICH id if no arguments? val id = arguments?.getString(Constants.INTENT_EXTRA_NAME_ID) if (hasSubFolders && id != null) { @@ -565,7 +555,10 @@ open class TrackCollectionFragment : MultiListFragment() { } @Suppress("LongMethod") - override fun getLiveData(args: Bundle?, refresh: Boolean): LiveData> { + override fun getLiveData( + args: Bundle?, + refresh: Boolean + ): LiveData> { if (args == null) return listModel.currentList val id = args.getString(Constants.INTENT_EXTRA_NAME_ID) val isAlbum = args.getBoolean(Constants.INTENT_EXTRA_NAME_IS_ALBUM, false) @@ -588,7 +581,7 @@ open class TrackCollectionFragment : MultiListFragment() { val albumListOffset = args.getInt( Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0 ) - val refresh = args.getBoolean(Constants.INTENT_EXTRA_NAME_REFRESH, true) || refresh + val refresh2 = args.getBoolean(Constants.INTENT_EXTRA_NAME_REFRESH, true) || refresh listModel.viewModelScope.launch(handler) { refreshListView?.isRefreshing = true @@ -610,7 +603,7 @@ open class TrackCollectionFragment : MultiListFragment() { listModel.getStarred() } else if (getVideos != 0) { setTitle(R.string.main_videos) - listModel.getVideos(refresh) + listModel.getVideos(refresh2) } else if (getRandomTracks != 0) { setTitle(R.string.main_songs_random) listModel.getRandom(albumListSize) @@ -618,12 +611,12 @@ open class TrackCollectionFragment : MultiListFragment() { setTitle(name) if (!isOffline() && Settings.shouldUseId3Tags) { if (isAlbum) { - listModel.getAlbum(refresh, id!!, name) + listModel.getAlbum(refresh2, id!!, name) } else { throw IllegalAccessException("Use AlbumFragment instead!") } } else { - listModel.getMusicDirectory(refresh, id!!, name) + listModel.getMusicDirectory(refresh2, id!!, name) } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt index 90c8bf45..74244c78 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt @@ -436,10 +436,6 @@ class DownloadFile( override val id: String get() = song.id - override val longId: Long by lazy { - id.hashCode().toLong() - } - companion object { const val MAX_RETRIES = 5 } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt index fad431f7..a7549a47 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt @@ -24,6 +24,7 @@ import org.koin.core.component.KoinComponent import org.koin.core.component.inject import org.moire.ultrasonic.data.ActiveServerProvider import org.moire.ultrasonic.domain.Artist +import org.moire.ultrasonic.domain.ArtistOrIndex import org.moire.ultrasonic.domain.Bookmark import org.moire.ultrasonic.domain.ChatMessage import org.moire.ultrasonic.domain.Genre @@ -122,7 +123,7 @@ class OfflineMusicService : MusicService, KoinComponent { } override fun search(criteria: SearchCriteria): SearchResult { - val artists: MutableList = ArrayList() + val artists: MutableList = ArrayList() val albums: MutableList = ArrayList() val songs: MutableList = ArrayList() val root = FileUtil.musicDirectory @@ -131,7 +132,7 @@ class OfflineMusicService : MusicService, KoinComponent { val artistName = artistFile.name if (artistFile.isDirectory) { if (matchCriteria(criteria, artistName).also { closeness = it } > 0) { - val artist = Artist(artistFile.path) + val artist = Index(artistFile.path) artist.index = artistFile.name.substring(0, 1) artist.name = artistName artist.closeness = closeness diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt index 545fab3d..74c7c3ea 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt @@ -361,7 +361,6 @@ open class RESTMusicService( musicFolderId ).execute().throwOnFailure() - return response.body()!!.albumList.toDomainEntityList() } diff --git a/ultrasonic/src/main/res/navigation/navigation_graph.xml b/ultrasonic/src/main/res/navigation/navigation_graph.xml index 0ab8f38c..90f978a6 100644 --- a/ultrasonic/src/main/res/navigation/navigation_graph.xml +++ b/ultrasonic/src/main/res/navigation/navigation_graph.xml @@ -60,8 +60,11 @@ android:id="@+id/searchFragment" android:name="org.moire.ultrasonic.fragment.SearchFragment" > +