2177 lines
61 KiB
C#
2177 lines
61 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Crosstales.Radio.Model;
|
|
using Crosstales.Radio.Model.Enum;
|
|
using Crosstales.Radio.Provider;
|
|
using Crosstales.Radio.Util;
|
|
using UnityEngine;
|
|
|
|
namespace Crosstales.Radio
|
|
{
|
|
[ExecuteInEditMode]
|
|
[HelpURLAttribute("https://www.crosstales.com/media/data/assets/radio/api/class_crosstales_1_1_radio_1_1_radio_manager.html")]
|
|
public class RadioManager : MonoBehaviour
|
|
{
|
|
[Header("General Settings")]
|
|
[Tooltip("Radio station providers for this manager.")]
|
|
public BaseRadioProvider[] Providers;
|
|
|
|
[Tooltip("Global RadioFilter (active if no explicit filter is given).")]
|
|
public RadioFilter Filter;
|
|
|
|
[Header("Behaviour Settings")]
|
|
[Tooltip("Calls 'Load' on Start (default: true).")]
|
|
public bool LoadOnStart = true;
|
|
|
|
[Tooltip("Calls 'Load' on Start in Editor (default: true).")]
|
|
public bool LoadOnStartInEditor = true;
|
|
|
|
[Header("Player Settings")]
|
|
[Tooltip("Instantiate RadioPlayers (default: false).")]
|
|
public bool InstantiateRadioPlayers;
|
|
|
|
[Tooltip("Prefab of the RadioPlayer.")]
|
|
public GameObject RadioPrefab;
|
|
|
|
private int stationIndex = -1;
|
|
|
|
private List<RadioStation> randomStations = new List<RadioStation>(Constants.INITIAL_LIST_SIZE);
|
|
|
|
private int randomStationIndex = -1;
|
|
|
|
private int playerIndex = -1;
|
|
|
|
private List<RadioPlayer> randomPlayers = new List<RadioPlayer>(Constants.INITIAL_LIST_SIZE);
|
|
|
|
private int randomPlayerIndex = -1;
|
|
|
|
private RadioPlayer currentRadioPlayer;
|
|
|
|
private List<RadioStation> stations = new List<RadioStation>(Constants.INITIAL_LIST_SIZE);
|
|
|
|
private List<RadioPlayer> players = new List<RadioPlayer>(Constants.INITIAL_LIST_SIZE);
|
|
|
|
private bool clearedStation = true;
|
|
|
|
private bool clearedStationRandom = true;
|
|
|
|
private RadioFilter lastStationFilter;
|
|
|
|
private RadioFilter lastRandomStationFilter;
|
|
|
|
private List<RadioStation> lastFilteredStations;
|
|
|
|
private List<RadioStation> lastFilteredRandomStations;
|
|
|
|
private RadioFilter lastPlayerFilter;
|
|
|
|
private RadioFilter lastRandomPlayerFilter;
|
|
|
|
private List<RadioPlayer> lastFilteredPlayers;
|
|
|
|
private List<RadioPlayer> lastFilteredRandomPlayers;
|
|
|
|
private RadioFilter playersByNameFilterDesc;
|
|
|
|
private RadioFilter playersByNameFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByNameDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByNameAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter playersByURLFilterDesc;
|
|
|
|
private RadioFilter playersByURLFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByURLDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByURLAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter playersByFormatFilterDesc;
|
|
|
|
private RadioFilter playersByFormatFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByFormatDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByFormatAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter playersByStationFilterDesc;
|
|
|
|
private RadioFilter playersByStationFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByStationDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByStationAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter playersByBitrateFilterDesc;
|
|
|
|
private RadioFilter playersByBitrateFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByBitrateDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByBitrateAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter playersByGenresFilterDesc;
|
|
|
|
private RadioFilter playersByGenresFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByGenresDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByGenresAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter playersByRatingFilterDesc;
|
|
|
|
private RadioFilter playersByRatingFilterAsc;
|
|
|
|
private List<RadioPlayer> playersByRatingDesc = new List<RadioPlayer>();
|
|
|
|
private List<RadioPlayer> playersByRatingAsc = new List<RadioPlayer>();
|
|
|
|
private RadioFilter stationsByNameFilterDesc;
|
|
|
|
private RadioFilter stationsByNameFilterAsc;
|
|
|
|
private List<RadioStation> stationsByNameDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByNameAsc = new List<RadioStation>();
|
|
|
|
private RadioFilter stationsByURLFilterDesc;
|
|
|
|
private RadioFilter stationsByURLFilterAsc;
|
|
|
|
private List<RadioStation> stationsByURLDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByURLAsc = new List<RadioStation>();
|
|
|
|
private RadioFilter stationsByFormatFilterDesc;
|
|
|
|
private RadioFilter stationsByFormatFilterAsc;
|
|
|
|
private List<RadioStation> stationsByFormatDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByFormatAsc = new List<RadioStation>();
|
|
|
|
private RadioFilter stationsByStationFilterDesc;
|
|
|
|
private RadioFilter stationsByStationFilterAsc;
|
|
|
|
private List<RadioStation> stationsByStationDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByStationAsc = new List<RadioStation>();
|
|
|
|
private RadioFilter stationsByBitrateFilterDesc;
|
|
|
|
private RadioFilter stationsByBitrateFilterAsc;
|
|
|
|
private List<RadioStation> stationsByBitrateDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByBitrateAsc = new List<RadioStation>();
|
|
|
|
private RadioFilter stationsByGenresFilterDesc;
|
|
|
|
private RadioFilter stationsByGenresFilterAsc;
|
|
|
|
private List<RadioStation> stationsByGenresDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByGenresAsc = new List<RadioStation>();
|
|
|
|
private RadioFilter stationsByRatingFilterDesc;
|
|
|
|
private RadioFilter stationsByRatingFilterAsc;
|
|
|
|
private List<RadioStation> stationsByRatingDesc = new List<RadioStation>();
|
|
|
|
private List<RadioStation> stationsByRatingAsc = new List<RadioStation>();
|
|
|
|
private FilterChange _filterChange;
|
|
|
|
private ProviderReady _providerReady;
|
|
|
|
public List<RadioStation> Stations
|
|
{
|
|
get
|
|
{
|
|
return stations;
|
|
}
|
|
}
|
|
|
|
public List<RadioPlayer> Players
|
|
{
|
|
get
|
|
{
|
|
return players;
|
|
}
|
|
}
|
|
|
|
public bool isReady
|
|
{
|
|
get
|
|
{
|
|
if (Providers != null)
|
|
{
|
|
BaseRadioProvider[] providers = Providers;
|
|
foreach (BaseRadioProvider baseRadioProvider in providers)
|
|
{
|
|
if (baseRadioProvider != null && !baseRadioProvider.isReady)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public bool isPlayback
|
|
{
|
|
get
|
|
{
|
|
foreach (RadioPlayer player in Players)
|
|
{
|
|
if (player != null && player.isPlayback)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool isAudioPlaying
|
|
{
|
|
get
|
|
{
|
|
foreach (RadioPlayer player in Players)
|
|
{
|
|
if (player != null && player.isAudioPlaying)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool isBuffering
|
|
{
|
|
get
|
|
{
|
|
foreach (RadioPlayer player in Players)
|
|
{
|
|
if (player != null && player.isBuffering)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public event FilterChange OnFilterChange
|
|
{
|
|
add
|
|
{
|
|
_filterChange = (FilterChange)Delegate.Combine(_filterChange, value);
|
|
}
|
|
remove
|
|
{
|
|
_filterChange = (FilterChange)Delegate.Remove(_filterChange, value);
|
|
}
|
|
}
|
|
|
|
public event ProviderReady OnProviderReady
|
|
{
|
|
add
|
|
{
|
|
_providerReady = (ProviderReady)Delegate.Combine(_providerReady, value);
|
|
}
|
|
remove
|
|
{
|
|
_providerReady = (ProviderReady)Delegate.Remove(_providerReady, value);
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
if (LoadOnStart && !Helper.isEditorMode)
|
|
{
|
|
Invoke("Load", 0.1f);
|
|
}
|
|
if (LoadOnStartInEditor && Helper.isEditorMode)
|
|
{
|
|
Load();
|
|
}
|
|
}
|
|
|
|
public void Load()
|
|
{
|
|
if (!Helper.isEditorMode)
|
|
{
|
|
StartCoroutine(init());
|
|
}
|
|
}
|
|
|
|
public void Save(string path, RadioFilter filter = null)
|
|
{
|
|
if (!string.IsNullOrEmpty(path))
|
|
{
|
|
try
|
|
{
|
|
path = path.Replace(Constants.PREFIX_FILE, string.Empty);
|
|
using (StreamWriter streamWriter = new StreamWriter(path))
|
|
{
|
|
streamWriter.WriteLine("# Radio PRO 2.9.2");
|
|
streamWriter.WriteLine("# © 2015-2017 by crosstales LLC (https://www.crosstales.com)");
|
|
streamWriter.WriteLine("#");
|
|
streamWriter.WriteLine("# List of all radio stations from '" + GetType().Name + "'");
|
|
streamWriter.WriteLine("# Created: " + DateTime.Now.ToString("dd.MM.yyyy"));
|
|
streamWriter.WriteLine("# Name;Url;DataFormat;AudioFormat;Station (optional);Genres (optional);Bitrate (in kbit/s, optional);Rating (0-5, optional);Description (optional);ExcludeCodec (optional);ChunkSize (in KB, optional);BufferSize (in KB, optional)");
|
|
foreach (RadioStation item in StationsByStation(false, getFilter(filter)))
|
|
{
|
|
streamWriter.WriteLine(item.ToTextLine());
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogError("Could not save file: " + path + Environment.NewLine + ex);
|
|
return;
|
|
}
|
|
}
|
|
Debug.LogWarning("'path' was null or empty! Could not save the data!");
|
|
}
|
|
|
|
public List<RadioStation> GetStations(bool random = false, RadioFilter filter = null)
|
|
{
|
|
return filterStations(random, getFilter(filter)).ToList();
|
|
}
|
|
|
|
public List<RadioPlayer> GetPlayers(bool random = false, RadioFilter filter = null)
|
|
{
|
|
return filterPlayers(random, getFilter(filter)).ToList();
|
|
}
|
|
|
|
public int CountStations(RadioFilter filter = null)
|
|
{
|
|
if (getFilter(filter) == null)
|
|
{
|
|
return Stations.Count();
|
|
}
|
|
return filterStations(false, getFilter(filter)).ToList().Count();
|
|
}
|
|
|
|
public int CountPlayers(RadioFilter filter = null)
|
|
{
|
|
if (getFilter(filter) == null)
|
|
{
|
|
return Players.Count();
|
|
}
|
|
return filterPlayers(false, getFilter(filter)).ToList().Count();
|
|
}
|
|
|
|
public void PlayAll()
|
|
{
|
|
StopAll();
|
|
foreach (RadioPlayer player in Players)
|
|
{
|
|
if (player != null)
|
|
{
|
|
player.Play();
|
|
}
|
|
}
|
|
}
|
|
|
|
public RadioPlayer PlayerByIndex(bool random = false, int index = 0, RadioFilter filter = null)
|
|
{
|
|
return playerByIndex(random, index, filter);
|
|
}
|
|
|
|
public RadioPlayer Next(bool random = false, RadioFilter filter = null, bool stopAll = true, bool playImmediately = true)
|
|
{
|
|
if (Players != null && Players.Count > 0)
|
|
{
|
|
if (stopAll)
|
|
{
|
|
StopAll();
|
|
}
|
|
currentRadioPlayer = nextPlayer(random, getFilter(filter));
|
|
if (stopAll && playImmediately)
|
|
{
|
|
Invoke("play", 0.4f);
|
|
}
|
|
else
|
|
{
|
|
play();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("No 'Players' found. Can't play next radio station and returning null.");
|
|
}
|
|
return currentRadioPlayer;
|
|
}
|
|
|
|
public RadioPlayer Previous(bool random = false, RadioFilter filter = null, bool stopAll = true, bool playImmediately = true)
|
|
{
|
|
if (Players != null && Players.Count > 0)
|
|
{
|
|
if (stopAll)
|
|
{
|
|
StopAll();
|
|
}
|
|
currentRadioPlayer = previousPlayer(random, getFilter(filter));
|
|
if (stopAll && playImmediately)
|
|
{
|
|
Invoke("play", 0.4f);
|
|
}
|
|
else
|
|
{
|
|
play();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("No 'Players' found. Can't play previous radio station and returning null.");
|
|
}
|
|
return currentRadioPlayer;
|
|
}
|
|
|
|
public RadioStation StationByIndex(bool random = false, int index = 0, RadioFilter filter = null)
|
|
{
|
|
return stationByIndex(random, index, filter);
|
|
}
|
|
|
|
public RadioStation NextStation(bool random = false, RadioFilter filter = null)
|
|
{
|
|
if (Stations != null && Stations.Count > 0)
|
|
{
|
|
return nextStation(random, getFilter(filter));
|
|
}
|
|
Debug.LogWarning("No 'Stations' found: returning null.");
|
|
return null;
|
|
}
|
|
|
|
public RadioStation PreviousStation(bool random = false, RadioFilter filter = null)
|
|
{
|
|
if (Stations != null && Stations.Count > 0)
|
|
{
|
|
return previousStation(random, getFilter(filter));
|
|
}
|
|
Debug.LogWarning("No 'Stations' found: returning null.");
|
|
return null;
|
|
}
|
|
|
|
public void StopAll(bool resetIndex = false)
|
|
{
|
|
foreach (RadioPlayer player in Players)
|
|
{
|
|
if (player != null)
|
|
{
|
|
player.Stop();
|
|
}
|
|
}
|
|
if (resetIndex)
|
|
{
|
|
playerIndex = (randomPlayerIndex = 0);
|
|
}
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByName(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByNameFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName with filter DESC: CACHED!");
|
|
}
|
|
return playersByNameDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName with filter DESC: NOT cached!");
|
|
}
|
|
playersByNameDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Name descending
|
|
select entry);
|
|
playersByNameFilterDesc = new RadioFilter(filter2);
|
|
return playersByNameDesc;
|
|
}
|
|
if (playersByNameDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName without filter DESC: CACHED!");
|
|
}
|
|
return playersByNameDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName without filter DESC: NOT cached!");
|
|
}
|
|
playersByNameDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Name descending
|
|
select entry);
|
|
playersByNameFilterDesc = null;
|
|
return playersByNameDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByNameFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName with filter ASC: CACHED!");
|
|
}
|
|
return playersByNameAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName with filter ASC: NOT cached!");
|
|
}
|
|
playersByNameAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Name
|
|
select entry);
|
|
playersByNameFilterAsc = new RadioFilter(filter2);
|
|
return playersByNameAsc;
|
|
}
|
|
if (playersByNameAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName without filter ASC: CACHED!");
|
|
}
|
|
return playersByNameAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByName without filter ASC: NOT cached!");
|
|
}
|
|
playersByNameAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Name
|
|
select entry);
|
|
playersByNameFilterAsc = null;
|
|
return playersByNameAsc;
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByURL(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByURLFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL with filter DESC: CACHED!");
|
|
}
|
|
return playersByURLDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL with filter DESC: NOT cached!");
|
|
}
|
|
playersByURLDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Url descending, entry.Station.Name
|
|
select entry);
|
|
playersByURLFilterDesc = new RadioFilter(filter2);
|
|
return playersByURLDesc;
|
|
}
|
|
if (playersByURLDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL without filter DESC: CACHED!");
|
|
}
|
|
return playersByURLDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL without filter DESC: NOT cached!");
|
|
}
|
|
playersByURLDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Url descending, entry.Station.Name
|
|
select entry);
|
|
playersByURLFilterDesc = null;
|
|
return playersByURLDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByURLFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL with filter ASC: CACHED!");
|
|
}
|
|
return playersByURLAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL with filter ASC: NOT cached!");
|
|
}
|
|
playersByURLAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Url, entry.Station.Name
|
|
select entry);
|
|
playersByURLFilterAsc = new RadioFilter(filter2);
|
|
return playersByURLAsc;
|
|
}
|
|
if (playersByURLAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL without filter ASC: CACHED!");
|
|
}
|
|
return playersByURLAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByURL without filter ASC: NOT cached!");
|
|
}
|
|
playersByURLAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Url, entry.Station.Name
|
|
select entry);
|
|
playersByURLFilterAsc = null;
|
|
return playersByURLAsc;
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByFormat(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByFormatFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat with filter DESC: CACHED!");
|
|
}
|
|
return playersByFormatDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat with filter DESC: NOT cached!");
|
|
}
|
|
playersByFormatDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Format descending, entry.Station.Name
|
|
select entry);
|
|
playersByFormatFilterDesc = new RadioFilter(filter2);
|
|
return playersByFormatDesc;
|
|
}
|
|
if (playersByFormatDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat without filter DESC: CACHED!");
|
|
}
|
|
return playersByFormatDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat without filter DESC: NOT cached!");
|
|
}
|
|
playersByFormatDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Format descending, entry.Station.Name
|
|
select entry);
|
|
playersByFormatFilterDesc = null;
|
|
return playersByFormatDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByFormatFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat with filter ASC: CACHED!");
|
|
}
|
|
return playersByFormatAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat with filter ASC: NOT cached!");
|
|
}
|
|
playersByFormatAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Format, entry.Station.Name
|
|
select entry);
|
|
playersByFormatFilterAsc = new RadioFilter(filter2);
|
|
return playersByFormatAsc;
|
|
}
|
|
if (playersByFormatAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat without filter ASC: CACHED!");
|
|
}
|
|
return playersByFormatAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByFormat without filter ASC: NOT cached!");
|
|
}
|
|
playersByFormatAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Format, entry.Station.Name
|
|
select entry);
|
|
playersByFormatFilterAsc = null;
|
|
return playersByFormatAsc;
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByStation(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByStationFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation with filter DESC: CACHED!");
|
|
}
|
|
return playersByStationDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation with filter DESC: NOT cached!");
|
|
}
|
|
playersByStationDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Station descending, entry.Station.Name
|
|
select entry);
|
|
playersByStationFilterDesc = new RadioFilter(filter2);
|
|
return playersByStationDesc;
|
|
}
|
|
if (playersByStationDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation without filter DESC: CACHED!");
|
|
}
|
|
return playersByStationDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation without filter DESC: NOT cached!");
|
|
}
|
|
playersByStationDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Station descending, entry.Station.Name
|
|
select entry);
|
|
playersByStationFilterDesc = null;
|
|
return playersByStationDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByStationFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation with filter ASC: CACHED!");
|
|
}
|
|
return playersByStationAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation with filter ASC: NOT cached!");
|
|
}
|
|
playersByStationAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Station, entry.Station.Name
|
|
select entry);
|
|
playersByStationFilterAsc = new RadioFilter(filter2);
|
|
return playersByStationAsc;
|
|
}
|
|
if (playersByStationAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation without filter ASC: CACHED!");
|
|
}
|
|
return playersByStationAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByStation without filter ASC: NOT cached!");
|
|
}
|
|
playersByStationAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Station, entry.Station.Name
|
|
select entry);
|
|
playersByStationFilterAsc = null;
|
|
return playersByStationAsc;
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByBitrate(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByBitrateFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate with filter DESC: CACHED!");
|
|
}
|
|
return playersByBitrateDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate with filter DESC: NOT cached!");
|
|
}
|
|
playersByBitrateDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Bitrate descending, entry.Station.Name
|
|
select entry);
|
|
playersByBitrateFilterDesc = new RadioFilter(filter2);
|
|
return playersByBitrateDesc;
|
|
}
|
|
if (playersByBitrateDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate without filter DESC: CACHED!");
|
|
}
|
|
return playersByBitrateDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate without filter DESC: NOT cached!");
|
|
}
|
|
playersByBitrateDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Bitrate descending, entry.Station.Name
|
|
select entry);
|
|
return playersByBitrateDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByBitrateFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate with filter ASC: CACHED!");
|
|
}
|
|
return playersByBitrateAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate with filter ASC: NOT cached!");
|
|
}
|
|
playersByBitrateAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Bitrate, entry.Station.Name
|
|
select entry);
|
|
playersByBitrateFilterAsc = new RadioFilter(filter2);
|
|
return playersByBitrateAsc;
|
|
}
|
|
if (playersByBitrateAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate without filter ASC: CACHED!");
|
|
}
|
|
return playersByBitrateAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByBitrate without filter ASC: NOT cached!");
|
|
}
|
|
playersByBitrateAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Bitrate, entry.Station.Name
|
|
select entry);
|
|
playersByBitrateFilterAsc = null;
|
|
return playersByBitrateAsc;
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByGenres(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByGenresFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres with filter DESC: CACHED!");
|
|
}
|
|
return playersByGenresDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres with filter DESC: NOT cached!");
|
|
}
|
|
playersByGenresDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Genres descending, entry.Station.Name
|
|
select entry);
|
|
playersByGenresFilterDesc = new RadioFilter(filter2);
|
|
return playersByGenresDesc;
|
|
}
|
|
if (playersByGenresDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres without filter DESC: CACHED!");
|
|
}
|
|
return playersByGenresDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres without filter DESC: NOT cached!");
|
|
}
|
|
playersByGenresDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Genres descending, entry.Station.Name
|
|
select entry);
|
|
playersByGenresFilterDesc = null;
|
|
return playersByGenresDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByGenresFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres with filter ASC: CACHED!");
|
|
}
|
|
return playersByGenresAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres with filter ASC: NOT cached!");
|
|
}
|
|
playersByGenresAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Genres, entry.Station.Name
|
|
select entry);
|
|
playersByGenresFilterAsc = new RadioFilter(filter2);
|
|
return playersByGenresAsc;
|
|
}
|
|
if (playersByGenresAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres without filter ASC: CACHED!");
|
|
}
|
|
return playersByGenresAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByGenres without filter ASC: NOT cached!");
|
|
}
|
|
playersByGenresAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Genres, entry.Station.Name
|
|
select entry);
|
|
playersByGenresFilterAsc = null;
|
|
return playersByGenresAsc;
|
|
}
|
|
|
|
public List<RadioPlayer> PlayersByRating(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByRatingFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating with filter DESC: CACHED!");
|
|
}
|
|
return playersByRatingDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating with filter DESC: NOT cached!");
|
|
}
|
|
playersByRatingDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Rating descending, entry.Station.Name
|
|
select entry);
|
|
playersByRatingFilterDesc = new RadioFilter(filter2);
|
|
return playersByRatingDesc;
|
|
}
|
|
if (playersByRatingDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating without filter DESC: CACHED!");
|
|
}
|
|
return playersByRatingDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating without filter DESC: NOT cached!");
|
|
}
|
|
playersByRatingDesc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Rating descending, entry.Station.Name
|
|
select entry);
|
|
playersByRatingFilterDesc = null;
|
|
return playersByRatingDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(playersByRatingFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating with filter ASC: CACHED!");
|
|
}
|
|
return playersByRatingAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating with filter ASC: NOT cached!");
|
|
}
|
|
playersByRatingAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Rating, entry.Station.Name
|
|
select entry);
|
|
playersByRatingFilterAsc = new RadioFilter(filter2);
|
|
return playersByRatingAsc;
|
|
}
|
|
if (playersByRatingAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating without filter ASC: CACHED!");
|
|
}
|
|
return playersByRatingAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("PlayersByRating without filter ASC: NOT cached!");
|
|
}
|
|
playersByRatingAsc = new List<RadioPlayer>(from entry in filterPlayers(false, getFilter(filter2))
|
|
orderby entry.Station.Rating, entry.Station.Name
|
|
select entry);
|
|
playersByRatingFilterAsc = null;
|
|
return playersByRatingAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByName(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByNameFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName with filter DESC: CACHED!");
|
|
}
|
|
return stationsByNameDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName with filter DESC: NOT cached!");
|
|
}
|
|
stationsByNameDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Name descending
|
|
select entry);
|
|
stationsByNameFilterDesc = new RadioFilter(filter2);
|
|
return stationsByNameDesc;
|
|
}
|
|
if (stationsByNameDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName without filter DESC: CACHED!");
|
|
}
|
|
return stationsByNameDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName without filter DESC: NOT cached!");
|
|
}
|
|
stationsByNameDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Name descending
|
|
select entry);
|
|
stationsByNameFilterDesc = null;
|
|
return stationsByNameDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByNameFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName with filter ASC: CACHED!");
|
|
}
|
|
return stationsByNameAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName with filter ASC: NOT cached!");
|
|
}
|
|
stationsByNameAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Name
|
|
select entry);
|
|
stationsByNameFilterAsc = new RadioFilter(filter2);
|
|
return stationsByNameAsc;
|
|
}
|
|
if (stationsByNameAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName without filter ASC: CACHED!");
|
|
}
|
|
return stationsByNameAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByName without filter ASC: NOT cached!");
|
|
}
|
|
stationsByNameAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Name
|
|
select entry);
|
|
stationsByNameFilterAsc = null;
|
|
return stationsByNameAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByURL(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByURLFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL with filter DESC: CACHED!");
|
|
}
|
|
return stationsByURLDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL with filter DESC: NOT cached!");
|
|
}
|
|
stationsByURLDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Url descending, entry.Name
|
|
select entry);
|
|
stationsByURLFilterDesc = new RadioFilter(filter2);
|
|
return stationsByURLDesc;
|
|
}
|
|
if (stationsByURLDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL without filter DESC: CACHED!");
|
|
}
|
|
return stationsByURLDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL without filter DESC: NOT cached!");
|
|
}
|
|
stationsByURLDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Url descending, entry.Name
|
|
select entry);
|
|
stationsByURLFilterDesc = null;
|
|
return stationsByURLDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByURLFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL with filter ASC: CACHED!");
|
|
}
|
|
return stationsByURLAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL with filter ASC: NOT cached!");
|
|
}
|
|
stationsByURLAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Url, entry.Name
|
|
select entry);
|
|
stationsByURLFilterAsc = new RadioFilter(filter2);
|
|
return stationsByURLAsc;
|
|
}
|
|
if (stationsByURLAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL without filter ASC: CACHED!");
|
|
}
|
|
return stationsByURLAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByURL without filter ASC: NOT cached!");
|
|
}
|
|
stationsByURLAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Url, entry.Name
|
|
select entry);
|
|
stationsByURLFilterAsc = null;
|
|
return stationsByURLAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByFormat(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByFormatFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat with filter DESC: CACHED!");
|
|
}
|
|
return stationsByFormatDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat with filter DESC: NOT cached!");
|
|
}
|
|
stationsByFormatDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Format descending, entry.Name
|
|
select entry);
|
|
stationsByFormatFilterDesc = new RadioFilter(filter2);
|
|
return stationsByFormatDesc;
|
|
}
|
|
if (stationsByFormatDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat without filter DESC: CACHED!");
|
|
}
|
|
return stationsByFormatDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat without filter DESC: NOT cached!");
|
|
}
|
|
stationsByFormatDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Format descending, entry.Name
|
|
select entry);
|
|
stationsByFormatFilterDesc = null;
|
|
return stationsByFormatDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByFormatFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat with filter ASC: CACHED!");
|
|
}
|
|
return stationsByFormatAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat with filter ASC: NOT cached!");
|
|
}
|
|
stationsByFormatAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Format, entry.Name
|
|
select entry);
|
|
stationsByFormatFilterAsc = new RadioFilter(filter2);
|
|
return stationsByFormatAsc;
|
|
}
|
|
if (stationsByFormatAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat without filter ASC: CACHED!");
|
|
}
|
|
return stationsByFormatAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByFormat without filter ASC: NOT cached!");
|
|
}
|
|
stationsByFormatAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Format, entry.Name
|
|
select entry);
|
|
stationsByFormatFilterAsc = null;
|
|
return stationsByFormatAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByStation(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByStationFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation with filter DESC: CACHED!");
|
|
}
|
|
return stationsByStationDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation with filter DESC: NOT cached!");
|
|
}
|
|
stationsByStationDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Station descending, entry.Name
|
|
select entry);
|
|
stationsByStationFilterDesc = new RadioFilter(filter2);
|
|
return stationsByStationDesc;
|
|
}
|
|
if (stationsByStationDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation without filter DESC: CACHED!");
|
|
}
|
|
return stationsByStationDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation without filter DESC: NOT cached!");
|
|
}
|
|
stationsByStationDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Station descending, entry.Name
|
|
select entry);
|
|
stationsByStationFilterDesc = null;
|
|
return stationsByStationDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByStationFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation with filter ASC: CACHED!");
|
|
}
|
|
return stationsByStationAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation with filter ASC: NOT cached!");
|
|
}
|
|
stationsByStationAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Station, entry.Name
|
|
select entry);
|
|
stationsByStationFilterAsc = new RadioFilter(filter2);
|
|
return stationsByStationAsc;
|
|
}
|
|
if (stationsByStationAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation without filter ASC: CACHED!");
|
|
}
|
|
return stationsByStationAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByStation without filter ASC: NOT cached!");
|
|
}
|
|
stationsByStationAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Station, entry.Name
|
|
select entry);
|
|
stationsByStationFilterAsc = null;
|
|
return stationsByStationAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByBitrate(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByBitrateFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate with filter DESC: CACHED!");
|
|
}
|
|
return stationsByBitrateDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate with filter DESC: NOT cached!");
|
|
}
|
|
stationsByBitrateDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Bitrate descending, entry.Name
|
|
select entry);
|
|
stationsByBitrateFilterDesc = new RadioFilter(filter2);
|
|
return stationsByBitrateDesc;
|
|
}
|
|
if (stationsByBitrateDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate without filter DESC: CACHED!");
|
|
}
|
|
return stationsByBitrateDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate without filter DESC: NOT cached!");
|
|
}
|
|
stationsByBitrateDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Bitrate descending, entry.Name
|
|
select entry);
|
|
stationsByBitrateFilterDesc = null;
|
|
return stationsByBitrateDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByBitrateFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate with filter ASC: CACHED!");
|
|
}
|
|
return stationsByBitrateAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate with filter ASC: NOT cached!");
|
|
}
|
|
stationsByBitrateAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Bitrate, entry.Name
|
|
select entry);
|
|
stationsByBitrateFilterAsc = new RadioFilter(filter2);
|
|
return stationsByBitrateAsc;
|
|
}
|
|
if (stationsByBitrateAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate without filter ASC: CACHED!");
|
|
}
|
|
return stationsByBitrateAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByBitrate without filter ASC: NOT cached!");
|
|
}
|
|
stationsByBitrateAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Bitrate, entry.Name
|
|
select entry);
|
|
stationsByBitrateFilterAsc = null;
|
|
return stationsByBitrateAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByGenres(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByGenresFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres with filter DESC: CACHED!");
|
|
}
|
|
return stationsByGenresDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres with filter DESC: NOT cached!");
|
|
}
|
|
stationsByGenresDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Genres descending, entry.Name
|
|
select entry);
|
|
stationsByGenresFilterDesc = new RadioFilter(filter2);
|
|
return stationsByGenresDesc;
|
|
}
|
|
if (stationsByGenresDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres without filter DESC: CACHED!");
|
|
}
|
|
return stationsByGenresDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres without filter DESC: NOT cached!");
|
|
}
|
|
stationsByGenresDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Genres descending, entry.Name
|
|
select entry);
|
|
stationsByGenresFilterDesc = null;
|
|
return stationsByGenresDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByGenresFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres with filter ASC: CACHED!");
|
|
}
|
|
return stationsByGenresAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres with filter ASC: NOT cached!");
|
|
}
|
|
stationsByGenresAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Genres, entry.Name
|
|
select entry);
|
|
stationsByGenresFilterAsc = new RadioFilter(filter2);
|
|
return stationsByGenresAsc;
|
|
}
|
|
if (stationsByGenresAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres without filter ASC: CACHED!");
|
|
}
|
|
return stationsByGenresAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByGenres without filter ASC: NOT cached!");
|
|
}
|
|
stationsByGenresAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Genres, entry.Name
|
|
select entry);
|
|
stationsByGenresFilterAsc = null;
|
|
return stationsByGenresAsc;
|
|
}
|
|
|
|
public List<RadioStation> StationsByRating(bool desc = false, RadioFilter filter = null)
|
|
{
|
|
RadioFilter filter2 = getFilter(filter);
|
|
if (desc)
|
|
{
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByRatingFilterDesc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating with filter DESC: CACHED!");
|
|
}
|
|
return stationsByRatingDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating with filter DESC: NOT cached!");
|
|
}
|
|
stationsByRatingDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Rating descending, entry.Name
|
|
select entry);
|
|
stationsByRatingFilterDesc = new RadioFilter(filter2);
|
|
return stationsByRatingDesc;
|
|
}
|
|
if (stationsByRatingDesc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating without filter DESC: CACHED!");
|
|
}
|
|
return stationsByRatingDesc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating without filter DESC: NOT cached!");
|
|
}
|
|
stationsByRatingDesc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Rating descending, entry.Name
|
|
select entry);
|
|
return stationsByRatingDesc;
|
|
}
|
|
if (filter2 != null)
|
|
{
|
|
if (filter2.Equals(stationsByRatingFilterAsc))
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating with filter ASC: CACHED!");
|
|
}
|
|
return stationsByRatingAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating with filter ASC: NOT cached!");
|
|
}
|
|
stationsByRatingAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Rating, entry.Name
|
|
select entry);
|
|
stationsByRatingFilterAsc = new RadioFilter(filter2);
|
|
return stationsByRatingAsc;
|
|
}
|
|
if (stationsByRatingAsc.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating without filter ASC: CACHED!");
|
|
}
|
|
return stationsByRatingAsc;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("StationsByRating without filter ASC: NOT cached!");
|
|
}
|
|
stationsByRatingAsc = new List<RadioStation>(from entry in filterStations(false, getFilter(filter2))
|
|
orderby entry.Rating, entry.Name
|
|
select entry);
|
|
stationsByRatingFilterAsc = null;
|
|
return stationsByRatingAsc;
|
|
}
|
|
|
|
public void RandomizePlayers(bool resetIndex = true)
|
|
{
|
|
randomPlayers.CTShuffle();
|
|
if (resetIndex)
|
|
{
|
|
randomPlayerIndex = 0;
|
|
}
|
|
}
|
|
|
|
public void RandomizeStations(bool resetIndex = true)
|
|
{
|
|
randomStations.CTShuffle();
|
|
if (resetIndex)
|
|
{
|
|
randomStationIndex = 0;
|
|
}
|
|
}
|
|
|
|
private IEnumerator init()
|
|
{
|
|
Stations.Clear();
|
|
randomStations.Clear();
|
|
Players.Clear();
|
|
randomPlayers.Clear();
|
|
if (Providers != null)
|
|
{
|
|
while (!isReady)
|
|
{
|
|
yield return null;
|
|
}
|
|
BaseRadioProvider[] providers = Providers;
|
|
foreach (BaseRadioProvider provider in providers)
|
|
{
|
|
if (provider != null)
|
|
{
|
|
foreach (RadioStation station in provider.Stations)
|
|
{
|
|
if (!Stations.Contains(station))
|
|
{
|
|
Stations.Add(station);
|
|
randomStations.Add(station);
|
|
if (InstantiateRadioPlayers && RadioPrefab != null)
|
|
{
|
|
GameObject gameObject = UnityEngine.Object.Instantiate(RadioPrefab);
|
|
gameObject.transform.parent = base.transform;
|
|
RadioPlayer component = gameObject.GetComponent<RadioPlayer>();
|
|
component.Station = station;
|
|
Players.Add(component);
|
|
randomPlayers.Add(component);
|
|
if (Config.DEBUG)
|
|
{
|
|
Debug.Log("Radio station found: " + component);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning(string.Concat("Station already added: '", station, "'"));
|
|
}
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
RandomizePlayers();
|
|
RandomizeStations();
|
|
}
|
|
onProviderReady();
|
|
}
|
|
|
|
private IEnumerable<RadioPlayer> filterPlayers(bool random = false, RadioFilter filter = null)
|
|
{
|
|
if (random)
|
|
{
|
|
if (filter != null && filter.isFiltering)
|
|
{
|
|
clearedStationRandom = false;
|
|
if (filter.Equals(lastRandomPlayerFilter) && lastFilteredRandomPlayers.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterPlayers RND: CACHED!");
|
|
}
|
|
return lastFilteredRandomPlayers;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterPlayers RND: NOT Cached!");
|
|
}
|
|
IEnumerable<RadioPlayer> enumerable = randomPlayers.Where((RadioPlayer entry) => filter == null || ((string.IsNullOrEmpty(entry.Station.Name) || entry.Station.Name.CTContainsAny(filter.Name)) && (string.IsNullOrEmpty(entry.Station.Station) || entry.Station.Station.CTContainsAny(filter.Station)) && (string.IsNullOrEmpty(entry.Station.Url) || entry.Station.Url.CTContainsAll(filter.Url)) && (string.IsNullOrEmpty(entry.Station.Genres) || entry.Station.Genres.CTContainsAny(filter.Genres)) && entry.Station.Format.ToString().CTContainsAny(filter.Format) && entry.Station.Bitrate >= filter.BitrateMin && entry.Station.Bitrate <= filter.BitrateMax && entry.Station.Rating >= filter.RatingMin && entry.Station.Rating <= filter.RatingMax && (!filter.ExcludeUnsupportedCodecs || entry.Station.ExcludedCodec == AudioCodec.None || entry.Station.ExcludedCodec != Helper.AudioCodecForAudioFormat(entry.Station.Format))));
|
|
lastFilteredRandomPlayers = enumerable.ToList();
|
|
lastRandomPlayerFilter = new RadioFilter(filter);
|
|
clearFilters(false, false);
|
|
onFilterChange();
|
|
return enumerable;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterPlayers RND: No filtering!");
|
|
}
|
|
if (!clearedStationRandom)
|
|
{
|
|
clearFilters();
|
|
clearedStationRandom = true;
|
|
onFilterChange();
|
|
}
|
|
return randomPlayers;
|
|
}
|
|
if (filter != null && filter.isFiltering)
|
|
{
|
|
clearedStation = false;
|
|
if (filter.Equals(lastPlayerFilter) && lastFilteredPlayers.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterPlayers: CACHED!");
|
|
}
|
|
return lastFilteredPlayers;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterPlayers: NOT Cached!");
|
|
}
|
|
IEnumerable<RadioPlayer> enumerable2 = Players.Where((RadioPlayer entry) => filter == null || ((string.IsNullOrEmpty(entry.Station.Name) || entry.Station.Name.CTContainsAny(filter.Name)) && (string.IsNullOrEmpty(entry.Station.Station) || entry.Station.Station.CTContainsAny(filter.Station)) && (string.IsNullOrEmpty(entry.Station.Url) || entry.Station.Url.CTContainsAll(filter.Url)) && (string.IsNullOrEmpty(entry.Station.Genres) || entry.Station.Genres.CTContainsAny(filter.Genres)) && entry.Station.Format.ToString().CTContainsAny(filter.Format) && entry.Station.Bitrate >= filter.BitrateMin && entry.Station.Bitrate <= filter.BitrateMax && entry.Station.Rating >= filter.RatingMin && entry.Station.Rating <= filter.RatingMax && (!filter.ExcludeUnsupportedCodecs || entry.Station.ExcludedCodec == AudioCodec.None || entry.Station.ExcludedCodec != Helper.AudioCodecForAudioFormat(entry.Station.Format))));
|
|
lastFilteredPlayers = enumerable2.ToList();
|
|
lastPlayerFilter = new RadioFilter(filter);
|
|
clearFilters(false, false);
|
|
onFilterChange();
|
|
return enumerable2;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterPlayers: No filtering!");
|
|
}
|
|
if (!clearedStation)
|
|
{
|
|
clearFilters();
|
|
clearedStation = true;
|
|
onFilterChange();
|
|
}
|
|
return Players;
|
|
}
|
|
|
|
private IEnumerable<RadioStation> filterStations(bool random = false, RadioFilter filter = null)
|
|
{
|
|
if (random)
|
|
{
|
|
if (filter != null && filter.isFiltering)
|
|
{
|
|
clearedStationRandom = false;
|
|
if (filter.Equals(lastRandomStationFilter) && lastFilteredRandomStations.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterStations RND: CACHED!");
|
|
}
|
|
return lastFilteredRandomStations;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterStations RND: NOT Cached!");
|
|
}
|
|
IEnumerable<RadioStation> enumerable = randomStations.Where((RadioStation entry) => filter == null || ((entry.Name == null || entry.Name.CTContainsAny(filter.Name)) && (entry.Station == null || entry.Station.CTContainsAny(filter.Station)) && (entry.Url == null || entry.Url.CTContainsAll(filter.Url)) && (entry.Genres == null || entry.Genres.CTContainsAny(filter.Genres)) && entry.Format.ToString().CTContainsAny(filter.Format) && entry.Bitrate >= filter.BitrateMin && entry.Bitrate <= filter.BitrateMax && entry.Rating >= filter.RatingMin && entry.Rating <= filter.RatingMax && (!filter.ExcludeUnsupportedCodecs || entry.ExcludedCodec == AudioCodec.None || entry.ExcludedCodec != Helper.AudioCodecForAudioFormat(entry.Format))));
|
|
lastFilteredRandomStations = enumerable.ToList();
|
|
lastRandomStationFilter = new RadioFilter(filter);
|
|
clearFilters(false, false);
|
|
onFilterChange();
|
|
return enumerable;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterStations RND: No filtering!");
|
|
}
|
|
if (!clearedStationRandom)
|
|
{
|
|
clearFilters();
|
|
clearedStationRandom = true;
|
|
onFilterChange();
|
|
}
|
|
return randomStations;
|
|
}
|
|
if (filter != null && filter.isFiltering)
|
|
{
|
|
clearedStation = false;
|
|
if (filter.Equals(lastStationFilter) && lastFilteredStations.Count > 0)
|
|
{
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterStations: CACHED!");
|
|
}
|
|
return lastFilteredStations;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterStations: NOT Cached!");
|
|
}
|
|
IEnumerable<RadioStation> enumerable2 = Stations.Where((RadioStation entry) => filter == null || ((entry.Name == null || entry.Name.CTContainsAny(filter.Name)) && (entry.Station == null || entry.Station.CTContainsAny(filter.Station)) && (entry.Url == null || entry.Url.CTContainsAll(filter.Url)) && (entry.Genres == null || entry.Genres.CTContainsAny(filter.Genres)) && entry.Format.ToString().CTContainsAny(filter.Format) && entry.Bitrate >= filter.BitrateMin && entry.Bitrate <= filter.BitrateMax && entry.Rating >= filter.RatingMin && entry.Rating <= filter.RatingMax && (!filter.ExcludeUnsupportedCodecs || entry.ExcludedCodec == AudioCodec.None || entry.ExcludedCodec != Helper.AudioCodecForAudioFormat(entry.Format))));
|
|
lastFilteredStations = enumerable2.ToList();
|
|
lastStationFilter = new RadioFilter(filter);
|
|
clearFilters(false, false);
|
|
onFilterChange();
|
|
return enumerable2;
|
|
}
|
|
if (Constants.DEV_DEBUG)
|
|
{
|
|
Debug.Log("filterStations: No filtering!");
|
|
}
|
|
if (!clearedStation)
|
|
{
|
|
clearFilters();
|
|
clearedStation = true;
|
|
onFilterChange();
|
|
}
|
|
return Stations;
|
|
}
|
|
|
|
private void clearFilters(bool clearLastFilter = true, bool clearLastRandomFilter = true)
|
|
{
|
|
if (clearLastFilter)
|
|
{
|
|
lastFilteredStations = null;
|
|
lastStationFilter = null;
|
|
lastFilteredPlayers = null;
|
|
lastPlayerFilter = null;
|
|
}
|
|
if (clearLastRandomFilter)
|
|
{
|
|
lastFilteredRandomStations = null;
|
|
lastRandomStationFilter = null;
|
|
lastFilteredRandomPlayers = null;
|
|
lastRandomPlayerFilter = null;
|
|
}
|
|
playersByNameFilterDesc = null;
|
|
playersByNameFilterAsc = null;
|
|
playersByURLFilterDesc = null;
|
|
playersByURLFilterAsc = null;
|
|
playersByFormatFilterDesc = null;
|
|
playersByFormatFilterAsc = null;
|
|
playersByStationFilterDesc = null;
|
|
playersByStationFilterAsc = null;
|
|
playersByBitrateFilterDesc = null;
|
|
playersByBitrateFilterAsc = null;
|
|
playersByGenresFilterDesc = null;
|
|
playersByGenresFilterAsc = null;
|
|
playersByRatingFilterDesc = null;
|
|
playersByRatingFilterAsc = null;
|
|
stationsByNameFilterDesc = null;
|
|
stationsByNameFilterAsc = null;
|
|
stationsByURLFilterDesc = null;
|
|
stationsByURLFilterAsc = null;
|
|
stationsByFormatFilterDesc = null;
|
|
stationsByFormatFilterAsc = null;
|
|
stationsByStationFilterDesc = null;
|
|
stationsByStationFilterAsc = null;
|
|
stationsByBitrateFilterDesc = null;
|
|
stationsByBitrateFilterAsc = null;
|
|
stationsByGenresFilterDesc = null;
|
|
stationsByGenresFilterAsc = null;
|
|
stationsByRatingFilterDesc = null;
|
|
stationsByRatingFilterAsc = null;
|
|
resetFilterLists();
|
|
}
|
|
|
|
private void resetFilterLists()
|
|
{
|
|
playersByNameDesc.Clear();
|
|
playersByNameAsc.Clear();
|
|
stationsByNameDesc.Clear();
|
|
stationsByNameAsc.Clear();
|
|
playersByURLDesc.Clear();
|
|
playersByURLAsc.Clear();
|
|
stationsByURLDesc.Clear();
|
|
stationsByURLAsc.Clear();
|
|
playersByFormatDesc.Clear();
|
|
playersByFormatAsc.Clear();
|
|
stationsByFormatDesc.Clear();
|
|
stationsByFormatAsc.Clear();
|
|
playersByStationDesc.Clear();
|
|
playersByStationAsc.Clear();
|
|
stationsByStationDesc.Clear();
|
|
stationsByStationAsc.Clear();
|
|
playersByBitrateDesc.Clear();
|
|
playersByBitrateAsc.Clear();
|
|
stationsByBitrateDesc.Clear();
|
|
stationsByBitrateAsc.Clear();
|
|
playersByGenresDesc.Clear();
|
|
playersByGenresAsc.Clear();
|
|
stationsByGenresDesc.Clear();
|
|
stationsByGenresAsc.Clear();
|
|
playersByRatingDesc.Clear();
|
|
playersByRatingAsc.Clear();
|
|
stationsByRatingDesc.Clear();
|
|
stationsByRatingAsc.Clear();
|
|
}
|
|
|
|
private void play()
|
|
{
|
|
currentRadioPlayer.Play();
|
|
}
|
|
|
|
private RadioPlayer playerByIndex(bool random = false, int index = 0, RadioFilter filter = null)
|
|
{
|
|
List<RadioPlayer> list = new List<RadioPlayer>(filterPlayers(random, filter));
|
|
if (random)
|
|
{
|
|
if (index > -1 && index < list.Count)
|
|
{
|
|
randomPlayerIndex = index;
|
|
return list[index];
|
|
}
|
|
}
|
|
else if (index > -1 && index < list.Count)
|
|
{
|
|
playerIndex = index;
|
|
return list[index];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private RadioPlayer nextPlayer(bool random = false, RadioFilter filter = null)
|
|
{
|
|
List<RadioPlayer> list = new List<RadioPlayer>(filterPlayers(random, filter));
|
|
if (random)
|
|
{
|
|
if (randomPlayerIndex > -1 && randomPlayerIndex + 1 < list.Count)
|
|
{
|
|
randomPlayerIndex++;
|
|
}
|
|
else
|
|
{
|
|
randomPlayerIndex = 0;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[randomPlayerIndex];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (playerIndex > -1 && playerIndex + 1 < list.Count)
|
|
{
|
|
playerIndex++;
|
|
}
|
|
else
|
|
{
|
|
playerIndex = 0;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[playerIndex];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private RadioPlayer previousPlayer(bool random = false, RadioFilter filter = null)
|
|
{
|
|
List<RadioPlayer> list = new List<RadioPlayer>(filterPlayers(random, filter));
|
|
if (random)
|
|
{
|
|
if (randomPlayerIndex > 0 && randomPlayerIndex < list.Count)
|
|
{
|
|
randomPlayerIndex--;
|
|
}
|
|
else
|
|
{
|
|
randomPlayerIndex = list.Count - 1;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[randomPlayerIndex];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (playerIndex > 0 && playerIndex < list.Count)
|
|
{
|
|
playerIndex--;
|
|
}
|
|
else
|
|
{
|
|
playerIndex = list.Count - 1;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[playerIndex];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private RadioStation stationByIndex(bool random = false, int index = 0, RadioFilter filter = null)
|
|
{
|
|
List<RadioStation> list = new List<RadioStation>(filterStations(random, filter));
|
|
if (random)
|
|
{
|
|
if (index > -1 && index < list.Count)
|
|
{
|
|
randomStationIndex = index;
|
|
return list[index];
|
|
}
|
|
}
|
|
else if (index > -1 && index < list.Count)
|
|
{
|
|
stationIndex = index;
|
|
return list[index];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private RadioStation nextStation(bool random = false, RadioFilter filter = null)
|
|
{
|
|
List<RadioStation> list = new List<RadioStation>(filterStations(random, filter));
|
|
if (random)
|
|
{
|
|
if (randomStationIndex > -1 && randomStationIndex + 1 < list.Count)
|
|
{
|
|
randomStationIndex++;
|
|
}
|
|
else
|
|
{
|
|
randomStationIndex = 0;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[randomStationIndex];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (stationIndex > -1 && stationIndex + 1 < list.Count)
|
|
{
|
|
stationIndex++;
|
|
}
|
|
else
|
|
{
|
|
stationIndex = 0;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[stationIndex];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private RadioStation previousStation(bool random = false, RadioFilter filter = null)
|
|
{
|
|
List<RadioStation> list = new List<RadioStation>(filterStations(random, filter));
|
|
if (random)
|
|
{
|
|
if (randomStationIndex > 0 && randomStationIndex < list.Count)
|
|
{
|
|
randomStationIndex--;
|
|
}
|
|
else
|
|
{
|
|
randomStationIndex = list.Count - 1;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[randomStationIndex];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (stationIndex > 0 && stationIndex < list.Count)
|
|
{
|
|
stationIndex--;
|
|
}
|
|
else
|
|
{
|
|
stationIndex = list.Count - 1;
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
return list[stationIndex];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private RadioFilter getFilter(RadioFilter filter)
|
|
{
|
|
if (filter != null && filter.isFiltering)
|
|
{
|
|
return filter;
|
|
}
|
|
if (Filter.isFiltering)
|
|
{
|
|
return Filter;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void onProviderReady()
|
|
{
|
|
if (Config.DEBUG)
|
|
{
|
|
Debug.Log("onProviderReady");
|
|
}
|
|
if (_providerReady != null)
|
|
{
|
|
_providerReady();
|
|
}
|
|
}
|
|
|
|
private void onFilterChange()
|
|
{
|
|
if (Config.DEBUG)
|
|
{
|
|
Debug.Log("onFilterChange");
|
|
}
|
|
if (_filterChange != null)
|
|
{
|
|
_filterChange();
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.Append(GetType().Name);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_START);
|
|
stringBuilder.Append("Providers='");
|
|
stringBuilder.Append(Providers);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
|
|
stringBuilder.Append("LoadOnStart='");
|
|
stringBuilder.Append(LoadOnStart);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
|
|
stringBuilder.Append("LoadOnStartInEditor='");
|
|
stringBuilder.Append(LoadOnStartInEditor);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
|
|
stringBuilder.Append("InstantiateRadioPlayers='");
|
|
stringBuilder.Append(InstantiateRadioPlayers);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
|
|
stringBuilder.Append("RadioPrefab='");
|
|
stringBuilder.Append(RadioPrefab);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER_END);
|
|
stringBuilder.Append(Constants.TEXT_TOSTRING_END);
|
|
return stringBuilder.ToString();
|
|
}
|
|
}
|
|
}
|