Add better offline Support

This commit is contained in:
Maxence G (Hello-Fluffy) 2021-08-20 18:54:34 +02:00 committed by tzugen
parent 6aa3124ee9
commit a23e5ff794
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 22 additions and 16 deletions

View File

@ -117,24 +117,32 @@ public class MainFragment extends Fragment {
final MergeAdapter adapter = new MergeAdapter();
adapter.addViews(Collections.singletonList(serverButton), true);
shouldUseId3 = Util.getShouldUseId3Tags();
if (!ActiveServerProvider.Companion.isOffline())
{
adapter.addView(musicTitle, false);
adapter.addViews(asList(artistsButton, albumsButton, genresButton), true);
adapter.addView(songsTitle, false);
adapter.addViews(asList(randomSongsButton, songsStarredButton), true);
adapter.addView(albumsTitle, false);
if (Util.getShouldUseId3Tags())
{
shouldUseId3 = true;
adapter.addViews(asList(albumsNewestButton, albumsRecentButton, albumsFrequentButton, albumsRandomButton, albumsStarredButton, albumsAlphaByNameButton, albumsAlphaByArtistButton), true);
}
else
{
shouldUseId3 = false;
adapter.addViews(asList(albumsNewestButton, albumsRecentButton, albumsFrequentButton, albumsHighestButton, albumsRandomButton, albumsStarredButton, albumsAlphaByNameButton, albumsAlphaByArtistButton), true);
}
adapter.addView(albumsTitle, false);
adapter.addViews(asList(albumsNewestButton, albumsRecentButton, albumsFrequentButton), true);
if (!shouldUseId3)
adapter.addView(albumsHighestButton, true);
adapter.addViews(asList(albumsRandomButton, albumsStarredButton, albumsAlphaByNameButton, albumsAlphaByArtistButton), true);
adapter.addView(videosTitle, false);
adapter.addViews(Collections.singletonList(videosButton), true);
}
else // Offline supported calls
{
adapter.addView(musicTitle, false);
adapter.addViews(asList(artistsButton, genresButton), true);
adapter.addView(songsTitle, false);
adapter.addView(randomSongsButton, true);
adapter.addView(videosTitle, false);
adapter.addViews(Collections.singletonList(videosButton), true);
@ -261,5 +269,4 @@ public class MainFragment extends Fragment {
{
Navigation.findNavController(getView()).navigate(R.id.mainToServerSelector);
}
}
}

View File

@ -18,7 +18,6 @@ import java.util.ArrayList
import java.util.HashSet
import java.util.LinkedList
import java.util.Locale
import java.util.Random
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import org.koin.core.component.KoinComponent
@ -257,9 +256,9 @@ class OfflineMusicService : MusicService, KoinComponent {
if (children.isEmpty()) {
return result
}
val random = Random()
children.shuffle()
for (i in 0 until size) {
val file = children[random.nextInt(children.size)]
val file = children[i % children.size]
result.addChild(createEntry(file, getName(file)))
}
return result