Project for Continous Integration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
10 KiB

  1. package device.radioPlayer;
  2. import device.Device;
  3. import java.time.LocalDateTime;
  4. import java.util.ArrayList;
  5. public class RadioPlayer implements Device {
  6. private int x;
  7. public RadioPlayer() {
  8. super();
  9. savedPlaylist.add("YouFM");
  10. savedPlaylist.add("Teddy");
  11. savedPlaylist.add("MegaHits");
  12. playedStation = savedPlaylist.get(0);
  13. }
  14. ArrayList<String> savedPlaylist = new ArrayList<String>();
  15. ArrayList<String> regionPlaylist = new ArrayList<String>();
  16. LocalDateTime now = LocalDateTime.now();
  17. int hour = now.getHour();
  18. int Lautstaerke = 0;
  19. int savedVolume;
  20. String playedStation = "";
  21. public String getYouFMInfoByTime(int x) {
  22. if (x >= 5 && x < 10) return YouFMInfo[0];
  23. else if (x >= 10 && x < 14) return YouFMInfo[1];
  24. else if (x >= 14 && x < 18) return YouFMInfo[2];
  25. else if (x >= 18 && x < 20) return YouFMInfo[3];
  26. else if (x >= 20 && x < 22) return YouFMInfo[4];
  27. else if (x >= 22 && x <= 23) return YouFMInfo[5];
  28. else return YouFMInfo[6];
  29. }
  30. String[] YouFMInfo = {"YOUFM Good Morning Show", "YOUFM Worktime", "YOUFM am Nachmittag", "YOUFM am Abend", "YOUFM Wir feiern euch", "YOUFM Deutschrap ideal", "YOUFM Junge Nacht der ARD"};
  31. public String getBR3InfoByTime(int x) {
  32. if (x >= 5 && x < 9) return BR3Info[0];
  33. else if (x >= 9 && x < 12) return BR3Info[1];
  34. else if (x == 12) return BR3Info[2];
  35. else if (x >= 13 && x < 16) return BR3Info[3];
  36. else if (x >= 16 && x < 19) return BR3Info[4];
  37. else if (x >= 19 && x < 21) return BR3Info[5];
  38. else if (x >= 21 && x < 24) return BR3Info[6];
  39. else return BR3Info[7];
  40. }
  41. String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend", "Die Nacht"};
  42. public String getAntenneBYInfoByTime(int x) {
  43. if (x >= 5 && x < 9) return AntenneBYInfo[0];
  44. else if (x >= 9 && x < 12) return AntenneBYInfo[1];
  45. else if (x >= 12 && x < 15) return AntenneBYInfo[2];
  46. else if (x >= 15 && x < 19) return AntenneBYInfo[3];
  47. else return AntenneBYInfo[4];
  48. }
  49. String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"};
  50. public void setLautstaerke(int lautstaerke) {
  51. Lautstaerke = lautstaerke;
  52. }
  53. public void changeRegion(String region) {
  54. switch (region) {
  55. case "BY":
  56. regionPlaylist.clear();
  57. regionPlaylist.add("Antenne Bayern");
  58. regionPlaylist.add("Bayern 1");
  59. regionPlaylist.add("Bayern 3");
  60. regionPlaylist.add("Hit Radio N1");
  61. playedStation = regionPlaylist.get(0);
  62. break;
  63. case "HE":
  64. regionPlaylist.clear();
  65. regionPlaylist.add("Hit Radio FFH");
  66. regionPlaylist.add("HR 1");
  67. regionPlaylist.add("HR 3");
  68. regionPlaylist.add("YouFM");
  69. playedStation = regionPlaylist.get(0);
  70. break;
  71. case "BW":
  72. regionPlaylist.clear();
  73. regionPlaylist.add("DASDING");
  74. regionPlaylist.add("SWR 1");
  75. regionPlaylist.add("SWR 3");
  76. regionPlaylist.add("sunshine live");
  77. playedStation = regionPlaylist.get(0);
  78. break;
  79. }
  80. }
  81. @Override
  82. public void louder() {
  83. if (Lautstaerke < 100) {
  84. Lautstaerke += 1;
  85. } else Lautstaerke = 100;
  86. }
  87. @Override
  88. public void quieter() {
  89. if (Lautstaerke > 0) {
  90. Lautstaerke -= 1;
  91. } else Lautstaerke = 0;
  92. }
  93. @Override
  94. public int getVolume() {
  95. return Lautstaerke;
  96. }
  97. @Override
  98. public void next() {
  99. if (regionPlaylist.contains(playedStation)) {
  100. int currentIndex = regionPlaylist.indexOf(playedStation);
  101. int nextIndex = (currentIndex + 1) % regionPlaylist.size();
  102. playedStation = regionPlaylist.get(nextIndex);
  103. } else {
  104. int currentIndex = savedPlaylist.indexOf(playedStation);
  105. int nextIndex = (currentIndex + 1) % savedPlaylist.size();
  106. playedStation = savedPlaylist.get(nextIndex);
  107. }
  108. }
  109. @Override
  110. public void prev() {
  111. if (regionPlaylist.contains(playedStation)) {
  112. int currentIndex = regionPlaylist.indexOf(playedStation);
  113. int nextIndex = regionPlaylist.size() - 1;
  114. if (currentIndex != 0) {
  115. nextIndex = (currentIndex - 1);
  116. }
  117. playedStation = regionPlaylist.get(nextIndex);
  118. } else {
  119. {
  120. int currentIndex = savedPlaylist.indexOf(playedStation);
  121. int nextIndex = savedPlaylist.size() - 1;
  122. if (currentIndex != 0) {
  123. nextIndex = (currentIndex - 1);
  124. }
  125. playedStation = savedPlaylist.get(nextIndex);
  126. }
  127. }
  128. }
  129. @Override
  130. public String getInfoText() {
  131. return "InfoText";
  132. }
  133. @Override
  134. public String[] getOptions() {
  135. return new String[0];
  136. }
  137. @Override
  138. public String chooseItem(int itemNr) {
  139. if (regionPlaylist.contains(playedStation)) {
  140. if (itemNr > regionPlaylist.size()) {
  141. playedStation = regionPlaylist.get(regionPlaylist.size() - 1);
  142. return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist");
  143. } else if (itemNr < 1) {
  144. playedStation = regionPlaylist.get(0);
  145. return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist");
  146. } else {
  147. playedStation = regionPlaylist.get(itemNr - 1);
  148. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  149. }
  150. } else {
  151. if (itemNr > savedPlaylist.size()) {
  152. playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
  153. return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
  154. } else if (itemNr < 1) {
  155. playedStation = savedPlaylist.get(0);
  156. return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
  157. } else {
  158. playedStation = savedPlaylist.get(itemNr - 1);
  159. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  160. }
  161. }
  162. }
  163. @Override
  164. public String[] getItemList() {
  165. if (regionPlaylist.contains(playedStation))
  166. return regionPlaylist.toArray(new String[0]);
  167. else
  168. return savedPlaylist.toArray(new String[0]);
  169. }
  170. @Override
  171. public String mute() {
  172. savedVolume = getVolume();
  173. setLautstaerke(0);
  174. return "RadioPlayer is muted now";
  175. }
  176. @Override
  177. public String unmute() {
  178. setLautstaerke(savedVolume);
  179. return ("RadioPlayer is unmuted Volume is set to " + getVolume());
  180. }
  181. @Override
  182. public String play() {
  183. if (regionPlaylist.contains(playedStation))
  184. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  185. else
  186. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  187. }
  188. public String showStationInfo() {
  189. switch (playedStation) {
  190. case "Antenne Bayern":
  191. return getAntenneBYInfoByTime(hour);
  192. case "YouFM":
  193. return getYouFMInfoByTime(hour);
  194. case "Bayern 3":
  195. return getBR3InfoByTime(hour);
  196. default:
  197. return "";
  198. }
  199. }
  200. public String saveStation() {
  201. if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
  202. else savedPlaylist.add(playedStation);
  203. regionPlaylist.clear();
  204. return "Station " + playedStation + " is saved in your Station list";
  205. }
  206. public String deleteStation() {
  207. String station = playedStation;
  208. if ((savedPlaylist.size()) > 1) {
  209. savedPlaylist.remove(playedStation);
  210. playedStation = savedPlaylist.get(0);
  211. return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
  212. } else return " Last Station: 01 " + station + " can´t by deleted";
  213. }
  214. public String changeToSavedPlaylist() {
  215. if (regionPlaylist.contains(playedStation)) {
  216. playedStation = savedPlaylist.get(0);
  217. regionPlaylist.clear();
  218. return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
  219. }
  220. return "You are already in saved Playlist!";
  221. }
  222. public String changeOrderInSavedPlaylist(int nr) {
  223. String station = playedStation;
  224. if ((nr - 1) > savedPlaylist.size()) {
  225. savedPlaylist.remove(playedStation);
  226. savedPlaylist.add(savedPlaylist.size(), station);
  227. return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
  228. } else if (nr < 0) {
  229. savedPlaylist.remove(playedStation);
  230. savedPlaylist.add(0, station);
  231. return "Station " + playedStation + " is now on place 01 in saved playlist";
  232. } else {
  233. savedPlaylist.remove(playedStation);
  234. savedPlaylist.add(nr - 1, station);
  235. return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
  236. }
  237. }
  238. }