mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-04-13 18:12:06 +02:00
Convert MainFragment to Kotlin
This commit is contained in:
parent
e00137a635
commit
e8baea6195
@ -30,7 +30,6 @@
|
|||||||
<ID>LongMethod:EditServerFragment.kt$EditServerFragment$override fun onViewCreated(view: View, savedInstanceState: Bundle?)</ID>
|
<ID>LongMethod:EditServerFragment.kt$EditServerFragment$override fun onViewCreated(view: View, savedInstanceState: Bundle?)</ID>
|
||||||
<ID>LongMethod:FilePickerAdapter.kt$FilePickerAdapter$private fun fileLister(currentDirectory: File)</ID>
|
<ID>LongMethod:FilePickerAdapter.kt$FilePickerAdapter$private fun fileLister(currentDirectory: File)</ID>
|
||||||
<ID>LongMethod:LocalMediaPlayer.kt$LocalMediaPlayer$@Synchronized private fun doPlay(downloadFile: DownloadFile, position: Int, start: Boolean)</ID>
|
<ID>LongMethod:LocalMediaPlayer.kt$LocalMediaPlayer$@Synchronized private fun doPlay(downloadFile: DownloadFile, position: Int, start: Boolean)</ID>
|
||||||
<ID>LongMethod:MediaPlayerService.kt$MediaPlayerService$private fun updateMediaSession(currentPlaying: DownloadFile?, playerState: PlayerState)</ID>
|
|
||||||
<ID>LongMethod:NavigationActivity.kt$NavigationActivity$override fun onCreate(savedInstanceState: Bundle?)</ID>
|
<ID>LongMethod:NavigationActivity.kt$NavigationActivity$override fun onCreate(savedInstanceState: Bundle?)</ID>
|
||||||
<ID>LongMethod:ShareHandler.kt$ShareHandler$private fun showDialog( fragment: Fragment, shareDetails: ShareDetails, swipe: SwipeRefreshLayout?, cancellationToken: CancellationToken )</ID>
|
<ID>LongMethod:ShareHandler.kt$ShareHandler$private fun showDialog( fragment: Fragment, shareDetails: ShareDetails, swipe: SwipeRefreshLayout?, cancellationToken: CancellationToken )</ID>
|
||||||
<ID>LongMethod:SongView.kt$SongView$fun setSong(song: MusicDirectory.Entry, checkable: Boolean, draggable: Boolean)</ID>
|
<ID>LongMethod:SongView.kt$SongView$fun setSong(song: MusicDirectory.Entry, checkable: Boolean, draggable: Boolean)</ID>
|
||||||
@ -49,7 +48,6 @@
|
|||||||
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$86400L</ID>
|
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$86400L</ID>
|
||||||
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$8L</ID>
|
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$8L</ID>
|
||||||
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.CheckCompletionTask$5000L</ID>
|
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.CheckCompletionTask$5000L</ID>
|
||||||
<ID>MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$50L</ID>
|
|
||||||
<ID>MagicNumber:MediaPlayerService.kt$MediaPlayerService$256</ID>
|
<ID>MagicNumber:MediaPlayerService.kt$MediaPlayerService$256</ID>
|
||||||
<ID>MagicNumber:MediaPlayerService.kt$MediaPlayerService$3</ID>
|
<ID>MagicNumber:MediaPlayerService.kt$MediaPlayerService$3</ID>
|
||||||
<ID>MagicNumber:MediaPlayerService.kt$MediaPlayerService$4</ID>
|
<ID>MagicNumber:MediaPlayerService.kt$MediaPlayerService$4</ID>
|
||||||
@ -70,11 +68,9 @@
|
|||||||
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$exception: Throwable</ID>
|
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$exception: Throwable</ID>
|
||||||
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$x: Exception</ID>
|
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$x: Exception</ID>
|
||||||
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$e: Exception</ID>
|
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$e: Exception</ID>
|
||||||
<ID>TooGenericExceptionCaught:MediaPlayerService.kt$MediaPlayerService$e: Exception</ID>
|
|
||||||
<ID>TooGenericExceptionCaught:SongView.kt$SongView$e: Exception</ID>
|
<ID>TooGenericExceptionCaught:SongView.kt$SongView$e: Exception</ID>
|
||||||
<ID>TooGenericExceptionCaught:SubsonicUncaughtExceptionHandler.kt$SubsonicUncaughtExceptionHandler$x: Throwable</ID>
|
<ID>TooGenericExceptionCaught:SubsonicUncaughtExceptionHandler.kt$SubsonicUncaughtExceptionHandler$x: Throwable</ID>
|
||||||
<ID>TooGenericExceptionThrown:DownloadFile.kt$DownloadFile.DownloadTask$throw Exception(String.format("Download of '%s' was cancelled", song))</ID>
|
<ID>TooGenericExceptionThrown:DownloadFile.kt$DownloadFile.DownloadTask$throw Exception(String.format("Download of '%s' was cancelled", song))</ID>
|
||||||
<ID>TooManyFunctions:LocalMediaPlayer.kt$LocalMediaPlayer</ID>
|
|
||||||
<ID>TooManyFunctions:MediaPlayerService.kt$MediaPlayerService : Service</ID>
|
<ID>TooManyFunctions:MediaPlayerService.kt$MediaPlayerService : Service</ID>
|
||||||
<ID>TooManyFunctions:RESTMusicService.kt$RESTMusicService : MusicService</ID>
|
<ID>TooManyFunctions:RESTMusicService.kt$RESTMusicService : MusicService</ID>
|
||||||
<ID>TooManyFunctions:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment</ID>
|
<ID>TooManyFunctions:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment</ID>
|
||||||
|
@ -1,272 +1,294 @@
|
|||||||
package org.moire.ultrasonic.fragment;
|
package org.moire.ultrasonic.fragment
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater
|
||||||
import android.view.View;
|
import android.view.View
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup
|
||||||
import android.widget.ListView;
|
import android.widget.AdapterView
|
||||||
import android.widget.TextView;
|
import android.widget.AdapterView.OnItemClickListener
|
||||||
|
import android.widget.ListView
|
||||||
import androidx.annotation.NonNull;
|
import android.widget.TextView
|
||||||
import androidx.annotation.Nullable;
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.navigation.Navigation
|
||||||
import androidx.navigation.Navigation;
|
import java.util.Locale
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
import org.moire.ultrasonic.R;
|
import org.koin.core.component.inject
|
||||||
import org.moire.ultrasonic.data.ActiveServerProvider;
|
import org.moire.ultrasonic.R
|
||||||
import org.moire.ultrasonic.data.ServerSetting;
|
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||||
import org.moire.ultrasonic.util.Constants;
|
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||||
import org.moire.ultrasonic.util.MergeAdapter;
|
import org.moire.ultrasonic.util.Constants
|
||||||
import org.moire.ultrasonic.util.Util;
|
import org.moire.ultrasonic.util.MergeAdapter
|
||||||
|
import org.moire.ultrasonic.util.Util.applyTheme
|
||||||
import java.util.Collections;
|
import org.moire.ultrasonic.util.Util.getMaxAlbums
|
||||||
|
import org.moire.ultrasonic.util.Util.getMaxSongs
|
||||||
import kotlin.Lazy;
|
import org.moire.ultrasonic.util.Util.getShouldUseId3Tags
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
import static org.koin.java.KoinJavaComponent.inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the Main screen of Ultrasonic, where the music library can be browsed
|
* Displays the Main screen of Ultrasonic, where the music library can be browsed
|
||||||
*/
|
*/
|
||||||
public class MainFragment extends Fragment {
|
class MainFragment : Fragment(), KoinComponent {
|
||||||
|
private var list: ListView? = null
|
||||||
|
|
||||||
private static boolean shouldUseId3;
|
private lateinit var serverButton: View
|
||||||
private static String lastActiveServerProperties;
|
private lateinit var serverTextView: TextView
|
||||||
|
private lateinit var musicTitle: View
|
||||||
|
private lateinit var artistsButton: View
|
||||||
|
private lateinit var albumsButton: View
|
||||||
|
private lateinit var genresButton: View
|
||||||
|
private lateinit var videosTitle: View
|
||||||
|
private lateinit var songsTitle: View
|
||||||
|
private lateinit var randomSongsButton: View
|
||||||
|
private lateinit var songsStarredButton: View
|
||||||
|
private lateinit var albumsTitle: View
|
||||||
|
private lateinit var albumsNewestButton: View
|
||||||
|
private lateinit var albumsRandomButton: View
|
||||||
|
private lateinit var albumsHighestButton: View
|
||||||
|
private lateinit var albumsStarredButton: View
|
||||||
|
private lateinit var albumsRecentButton: View
|
||||||
|
private lateinit var albumsFrequentButton: View
|
||||||
|
private lateinit var albumsAlphaByNameButton: View
|
||||||
|
private lateinit var albumsAlphaByArtistButton: View
|
||||||
|
private lateinit var videosButton: View
|
||||||
|
|
||||||
private ListView list;
|
private val activeServerProvider: ActiveServerProvider by inject()
|
||||||
|
|
||||||
private final Lazy<ActiveServerProvider> activeServerProvider = inject(ActiveServerProvider.class);
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
applyTheme(this.context)
|
||||||
@Override
|
super.onCreate(savedInstanceState)
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
Util.applyTheme(this.getContext());
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun onCreateView(
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
inflater: LayoutInflater,
|
||||||
Bundle savedInstanceState) {
|
container: ViewGroup?,
|
||||||
return inflater.inflate(R.layout.main, container, false);
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
return inflater.inflate(R.layout.main, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
list = view.findViewById(R.id.main_list)
|
||||||
|
cachedActiveServerProperties = getActiveServerProperties()
|
||||||
|
|
||||||
list = view.findViewById(R.id.main_list);
|
setupButtons()
|
||||||
setupMenuList(list);
|
|
||||||
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
if (list != null) setupMenuList(list!!)
|
||||||
|
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun onResume() {
|
||||||
public void onResume() {
|
super.onResume()
|
||||||
super.onResume();
|
var shouldRestart = false
|
||||||
boolean shouldRestart = false;
|
val currentId3Setting = getShouldUseId3Tags()
|
||||||
|
val currentActiveServerProperties = getActiveServerProperties()
|
||||||
|
|
||||||
boolean id3 = Util.getShouldUseId3Tags();
|
// If setting has changed...
|
||||||
String currentActiveServerProperties = getActiveServerProperties();
|
if (currentId3Setting != shouldUseId3) {
|
||||||
|
shouldUseId3 = currentId3Setting
|
||||||
if (id3 != shouldUseId3)
|
shouldRestart = true
|
||||||
{
|
|
||||||
shouldUseId3 = id3;
|
|
||||||
shouldRestart = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentActiveServerProperties.equals(lastActiveServerProperties))
|
// or the server has changed...
|
||||||
{
|
if (currentActiveServerProperties != cachedActiveServerProperties) {
|
||||||
lastActiveServerProperties = currentActiveServerProperties;
|
cachedActiveServerProperties = currentActiveServerProperties
|
||||||
shouldRestart = true;
|
shouldRestart = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// then setup the list anew.
|
||||||
if (shouldRestart) {
|
if (shouldRestart) {
|
||||||
setupMenuList(list);
|
if (list != null) setupMenuList(list!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupMenuList(ListView list)
|
private fun setupButtons() {
|
||||||
{
|
val buttons = layoutInflater.inflate(R.layout.main_buttons, list, false)
|
||||||
final View buttons = getLayoutInflater().inflate(R.layout.main_buttons, list, false);
|
serverButton = buttons.findViewById(R.id.main_select_server)
|
||||||
final View serverButton = buttons.findViewById(R.id.main_select_server);
|
serverTextView = serverButton.findViewById(R.id.main_select_server_2)
|
||||||
final TextView serverTextView = serverButton.findViewById(R.id.main_select_server_2);
|
musicTitle = buttons.findViewById(R.id.main_music)
|
||||||
|
artistsButton = buttons.findViewById(R.id.main_artists_button)
|
||||||
lastActiveServerProperties = getActiveServerProperties();
|
albumsButton = buttons.findViewById(R.id.main_albums_button)
|
||||||
String name = activeServerProvider.getValue().getActiveServer().getName();
|
genresButton = buttons.findViewById(R.id.main_genres_button)
|
||||||
|
videosTitle = buttons.findViewById(R.id.main_videos_title)
|
||||||
serverTextView.setText(name);
|
songsTitle = buttons.findViewById(R.id.main_songs)
|
||||||
|
randomSongsButton = buttons.findViewById(R.id.main_songs_button)
|
||||||
final View musicTitle = buttons.findViewById(R.id.main_music);
|
songsStarredButton = buttons.findViewById(R.id.main_songs_starred)
|
||||||
final View artistsButton = buttons.findViewById(R.id.main_artists_button);
|
albumsTitle = buttons.findViewById(R.id.main_albums)
|
||||||
final View albumsButton = buttons.findViewById(R.id.main_albums_button);
|
albumsNewestButton = buttons.findViewById(R.id.main_albums_newest)
|
||||||
final View genresButton = buttons.findViewById(R.id.main_genres_button);
|
albumsRandomButton = buttons.findViewById(R.id.main_albums_random)
|
||||||
final View videosTitle = buttons.findViewById(R.id.main_videos_title);
|
albumsHighestButton = buttons.findViewById(R.id.main_albums_highest)
|
||||||
final View songsTitle = buttons.findViewById(R.id.main_songs);
|
albumsStarredButton = buttons.findViewById(R.id.main_albums_starred)
|
||||||
final View randomSongsButton = buttons.findViewById(R.id.main_songs_button);
|
albumsRecentButton = buttons.findViewById(R.id.main_albums_recent)
|
||||||
final View songsStarredButton = buttons.findViewById(R.id.main_songs_starred);
|
albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent)
|
||||||
final View albumsTitle = buttons.findViewById(R.id.main_albums);
|
albumsAlphaByNameButton = buttons.findViewById(R.id.main_albums_alphaByName)
|
||||||
final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest);
|
albumsAlphaByArtistButton = buttons.findViewById(R.id.main_albums_alphaByArtist)
|
||||||
final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random);
|
videosButton = buttons.findViewById(R.id.main_videos)
|
||||||
final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest);
|
|
||||||
final View albumsStarredButton = buttons.findViewById(R.id.main_albums_starred);
|
|
||||||
final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent);
|
|
||||||
final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent);
|
|
||||||
final View albumsAlphaByNameButton = buttons.findViewById(R.id.main_albums_alphaByName);
|
|
||||||
final View albumsAlphaByArtistButton = buttons.findViewById(R.id.main_albums_alphaByArtist);
|
|
||||||
final View videosButton = buttons.findViewById(R.id.main_videos);
|
|
||||||
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list.setAdapter(adapter);
|
private fun setupMenuList(list: ListView) {
|
||||||
list.setOnItemClickListener((parent, view, position, id) -> {
|
// Set title
|
||||||
if (view == serverButton)
|
val activeServerName = activeServerProvider.getActiveServer().name
|
||||||
{
|
serverTextView.text = activeServerName
|
||||||
showServers();
|
|
||||||
|
// TODO: Should use RecyclerView
|
||||||
|
val adapter = MergeAdapter()
|
||||||
|
|
||||||
|
adapter.addView(serverButton, true)
|
||||||
|
|
||||||
|
shouldUseId3 = getShouldUseId3Tags()
|
||||||
|
|
||||||
|
if (!isOffline()) {
|
||||||
|
adapter.addView(musicTitle, false)
|
||||||
|
adapter.addViews(listOf(artistsButton, albumsButton, genresButton), true)
|
||||||
|
adapter.addView(songsTitle, false)
|
||||||
|
adapter.addViews(listOf(randomSongsButton, songsStarredButton), true)
|
||||||
|
adapter.addView(albumsTitle, false)
|
||||||
|
adapter.addViews(
|
||||||
|
listOf(
|
||||||
|
albumsNewestButton,
|
||||||
|
albumsRecentButton,
|
||||||
|
albumsFrequentButton
|
||||||
|
),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
if (!shouldUseId3) {
|
||||||
|
adapter.addView(albumsHighestButton, true)
|
||||||
}
|
}
|
||||||
else if (view == albumsNewestButton)
|
adapter.addViews(
|
||||||
{
|
listOf(
|
||||||
showAlbumList("newest", R.string.main_albums_newest);
|
albumsRandomButton,
|
||||||
}
|
albumsStarredButton,
|
||||||
else if (view == albumsRandomButton)
|
albumsAlphaByNameButton,
|
||||||
{
|
albumsAlphaByArtistButton
|
||||||
showAlbumList("random", R.string.main_albums_random);
|
),
|
||||||
}
|
true
|
||||||
else if (view == albumsHighestButton)
|
)
|
||||||
{
|
adapter.addView(videosTitle, false)
|
||||||
showAlbumList("highest", R.string.main_albums_highest);
|
adapter.addViews(listOf(videosButton), true)
|
||||||
}
|
} else {
|
||||||
else if (view == albumsRecentButton)
|
// Offline supported calls
|
||||||
{
|
adapter.addView(musicTitle, false)
|
||||||
showAlbumList("recent", R.string.main_albums_recent);
|
adapter.addViews(listOf(artistsButton, genresButton), true)
|
||||||
}
|
adapter.addView(songsTitle, false)
|
||||||
else if (view == albumsFrequentButton)
|
adapter.addView(randomSongsButton, true)
|
||||||
{
|
|
||||||
showAlbumList("frequent", R.string.main_albums_frequent);
|
|
||||||
}
|
|
||||||
else if (view == albumsStarredButton)
|
|
||||||
{
|
|
||||||
showAlbumList(Constants.STARRED, R.string.main_albums_starred);
|
|
||||||
}
|
|
||||||
else if (view == albumsAlphaByNameButton)
|
|
||||||
{
|
|
||||||
showAlbumList(Constants.ALPHABETICAL_BY_NAME, R.string.main_albums_alphaByName);
|
|
||||||
}
|
|
||||||
else if (view == albumsAlphaByArtistButton)
|
|
||||||
{
|
|
||||||
showAlbumList("alphabeticalByArtist", R.string.main_albums_alphaByArtist);
|
|
||||||
}
|
|
||||||
else if (view == songsStarredButton)
|
|
||||||
{
|
|
||||||
showStarredSongs();
|
|
||||||
}
|
|
||||||
else if (view == artistsButton)
|
|
||||||
{
|
|
||||||
showArtists();
|
|
||||||
}
|
|
||||||
else if (view == albumsButton)
|
|
||||||
{
|
|
||||||
showAlbumList(Constants.ALPHABETICAL_BY_NAME, R.string.main_albums_title);
|
|
||||||
}
|
|
||||||
else if (view == randomSongsButton)
|
|
||||||
{
|
|
||||||
showRandomSongs();
|
|
||||||
}
|
|
||||||
else if (view == genresButton)
|
|
||||||
{
|
|
||||||
showGenres();
|
|
||||||
}
|
|
||||||
else if (view == videosButton)
|
|
||||||
{
|
|
||||||
showVideos();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getActiveServerProperties()
|
list.adapter = adapter
|
||||||
{
|
list.onItemClickListener = listListener
|
||||||
ServerSetting currentSetting = activeServerProvider.getValue().getActiveServer();
|
|
||||||
return String.format("%s;%s;%s;%s;%s;%s", currentSetting.getUrl(), currentSetting.getUserName(),
|
|
||||||
currentSetting.getPassword(), currentSetting.getAllowSelfSignedCertificate(),
|
|
||||||
currentSetting.getLdapSupport(), currentSetting.getMinimumApiVersion());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showStarredSongs()
|
private val listListener =
|
||||||
{
|
OnItemClickListener { _: AdapterView<*>?, view: View, _: Int, _: Long ->
|
||||||
Bundle bundle = new Bundle();
|
when {
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_STARRED, 1);
|
view === serverButton -> {
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToTrackCollection, bundle);
|
showServers()
|
||||||
|
}
|
||||||
|
view === albumsNewestButton -> {
|
||||||
|
showAlbumList("newest", R.string.main_albums_newest)
|
||||||
|
}
|
||||||
|
view === albumsRandomButton -> {
|
||||||
|
showAlbumList("random", R.string.main_albums_random)
|
||||||
|
}
|
||||||
|
view === albumsHighestButton -> {
|
||||||
|
showAlbumList("highest", R.string.main_albums_highest)
|
||||||
|
}
|
||||||
|
view === albumsRecentButton -> {
|
||||||
|
showAlbumList("recent", R.string.main_albums_recent)
|
||||||
|
}
|
||||||
|
view === albumsFrequentButton -> {
|
||||||
|
showAlbumList("frequent", R.string.main_albums_frequent)
|
||||||
|
}
|
||||||
|
view === albumsStarredButton -> {
|
||||||
|
showAlbumList(Constants.STARRED, R.string.main_albums_starred)
|
||||||
|
}
|
||||||
|
view === albumsAlphaByNameButton -> {
|
||||||
|
showAlbumList(Constants.ALPHABETICAL_BY_NAME, R.string.main_albums_alphaByName)
|
||||||
|
}
|
||||||
|
view === albumsAlphaByArtistButton -> {
|
||||||
|
showAlbumList("alphabeticalByArtist", R.string.main_albums_alphaByArtist)
|
||||||
|
}
|
||||||
|
view === songsStarredButton -> {
|
||||||
|
showStarredSongs()
|
||||||
|
}
|
||||||
|
view === artistsButton -> {
|
||||||
|
showArtists()
|
||||||
|
}
|
||||||
|
view === albumsButton -> {
|
||||||
|
showAlbumList(Constants.ALPHABETICAL_BY_NAME, R.string.main_albums_title)
|
||||||
|
}
|
||||||
|
view === randomSongsButton -> {
|
||||||
|
showRandomSongs()
|
||||||
|
}
|
||||||
|
view === genresButton -> {
|
||||||
|
showGenres()
|
||||||
|
}
|
||||||
|
view === videosButton -> {
|
||||||
|
showVideos()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showRandomSongs()
|
private fun getActiveServerProperties(): String {
|
||||||
{
|
val server = activeServerProvider.getActiveServer()
|
||||||
Bundle bundle = new Bundle();
|
return String.format(
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_RANDOM, 1);
|
Locale.ROOT,
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxSongs());
|
"%s;%s;%s;%s;%s;%s",
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToTrackCollection, bundle);
|
server.url,
|
||||||
|
server.userName,
|
||||||
|
server.password,
|
||||||
|
server.allowSelfSignedCertificate,
|
||||||
|
server.ldapSupport,
|
||||||
|
server.minimumApiVersion
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showArtists()
|
private fun showStarredSongs() {
|
||||||
{
|
val bundle = Bundle()
|
||||||
Bundle bundle = new Bundle();
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_STARRED, 1)
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, getContext().getResources().getString(R.string.main_artists_title));
|
Navigation.findNavController(requireView()).navigate(R.id.mainToTrackCollection, bundle)
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToArtistList, bundle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAlbumList(final String type, final int titleIndex) {
|
private fun showRandomSongs() {
|
||||||
Bundle bundle = new Bundle();
|
val bundle = Bundle()
|
||||||
String title = getContext().getResources().getString(titleIndex, "");
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_RANDOM, 1)
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, getMaxSongs())
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, title);
|
Navigation.findNavController(requireView()).navigate(R.id.mainToTrackCollection, bundle)
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxAlbums());
|
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
|
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToAlbumList, bundle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showGenres()
|
private fun showArtists() {
|
||||||
{
|
val bundle = Bundle()
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToSelectGenre);
|
bundle.putString(
|
||||||
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE,
|
||||||
|
requireContext().resources.getString(R.string.main_artists_title)
|
||||||
|
)
|
||||||
|
Navigation.findNavController(requireView()).navigate(R.id.mainToArtistList, bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showVideos()
|
private fun showAlbumList(type: String, titleIndex: Int) {
|
||||||
{
|
val bundle = Bundle()
|
||||||
Bundle bundle = new Bundle();
|
val title = requireContext().resources.getString(titleIndex, "")
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_VIDEOS, 1);
|
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type)
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToTrackCollection, bundle);
|
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, title)
|
||||||
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, getMaxAlbums())
|
||||||
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0)
|
||||||
|
Navigation.findNavController(requireView()).navigate(R.id.mainToAlbumList, bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showServers()
|
private fun showGenres() {
|
||||||
{
|
Navigation.findNavController(requireView()).navigate(R.id.mainToSelectGenre)
|
||||||
Navigation.findNavController(getView()).navigate(R.id.mainToServerSelector);
|
}
|
||||||
|
|
||||||
|
private fun showVideos() {
|
||||||
|
val bundle = Bundle()
|
||||||
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_VIDEOS, 1)
|
||||||
|
Navigation.findNavController(requireView()).navigate(R.id.mainToTrackCollection, bundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showServers() {
|
||||||
|
Navigation.findNavController(requireView()).navigate(R.id.mainToServerSelector)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private var shouldUseId3 = false
|
||||||
|
private var cachedActiveServerProperties: String? = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user