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.

281 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. if(showStationInfo().equals("")) return buildInfoText();
  132. return (buildInfoText() + "\n Now playing: " + showStationInfo());
  133. }
  134. private String buildInfoText() {
  135. String infoText = playedStation;
  136. if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText);
  137. else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText);
  138. }
  139. @Override
  140. public String[] getOptions() {
  141. return new String[0];
  142. }
  143. @Override
  144. public String chooseItem(int itemNr) {
  145. if (regionPlaylist.contains(playedStation)) {
  146. if (itemNr > regionPlaylist.size()) {
  147. playedStation = regionPlaylist.get(regionPlaylist.size() - 1);
  148. return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist");
  149. } else if (itemNr < 1) {
  150. playedStation = regionPlaylist.get(0);
  151. return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist");
  152. } else {
  153. playedStation = regionPlaylist.get(itemNr - 1);
  154. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  155. }
  156. } else {
  157. if (itemNr > savedPlaylist.size()) {
  158. playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
  159. return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
  160. } else if (itemNr < 1) {
  161. playedStation = savedPlaylist.get(0);
  162. return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
  163. } else {
  164. playedStation = savedPlaylist.get(itemNr - 1);
  165. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  166. }
  167. }
  168. }
  169. @Override
  170. public String[] getItemList() {
  171. if (regionPlaylist.contains(playedStation))
  172. return regionPlaylist.toArray(new String[0]);
  173. else
  174. return savedPlaylist.toArray(new String[0]);
  175. }
  176. @Override
  177. public String mute() {
  178. savedVolume = getVolume();
  179. setLautstaerke(0);
  180. return "RadioPlayer is muted now";
  181. }
  182. @Override
  183. public String unmute() {
  184. setLautstaerke(savedVolume);
  185. return ("RadioPlayer is unmuted Volume is set to " + getVolume());
  186. }
  187. @Override
  188. public String play() {
  189. if (regionPlaylist.contains(playedStation))
  190. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  191. else
  192. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  193. }
  194. public String showStationInfo() {
  195. switch (playedStation) {
  196. case "Antenne Bayern":
  197. return getAntenneBYInfoByTime(hour);
  198. case "YouFM":
  199. return getYouFMInfoByTime(hour);
  200. case "Bayern 3":
  201. return getBR3InfoByTime(hour);
  202. default:
  203. return "";
  204. }
  205. }
  206. public String saveStation() {
  207. if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
  208. else savedPlaylist.add(playedStation);
  209. regionPlaylist.clear();
  210. return "Station " + playedStation + " is saved in your Station list";
  211. }
  212. public String deleteStation() {
  213. String station = playedStation;
  214. if ((savedPlaylist.size()) > 1) {
  215. savedPlaylist.remove(playedStation);
  216. playedStation = savedPlaylist.get(0);
  217. return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
  218. } else return " Last Station: 01 " + station + " can´t by deleted";
  219. }
  220. public String changeToSavedPlaylist() {
  221. if (regionPlaylist.contains(playedStation)) {
  222. playedStation = savedPlaylist.get(0);
  223. regionPlaylist.clear();
  224. return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
  225. }
  226. return "You are already in saved Playlist!";
  227. }
  228. public String changeOrderInSavedPlaylist(int nr) {
  229. String station = playedStation;
  230. if ((nr - 1) > savedPlaylist.size()) {
  231. savedPlaylist.remove(playedStation);
  232. savedPlaylist.add(savedPlaylist.size(), station);
  233. return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
  234. } else if (nr < 0) {
  235. savedPlaylist.remove(playedStation);
  236. savedPlaylist.add(0, station);
  237. return "Station " + playedStation + " is now on place 01 in saved playlist";
  238. } else {
  239. savedPlaylist.remove(playedStation);
  240. savedPlaylist.add(nr - 1, station);
  241. return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
  242. }
  243. }
  244. }