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.

249 lines
9.1 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. String playedStation = "";
  20. public String getYouFMInfoByTime(int x) {
  21. if (x >= 5 && x < 10) return YouFMInfo[0];
  22. else if (x >= 10 && x < 14) return YouFMInfo[1];
  23. else if (x >= 14 && x < 18) return YouFMInfo[2];
  24. else if (x >= 18 && x < 20) return YouFMInfo[3];
  25. else if (x >= 20 && x < 22) return YouFMInfo[4];
  26. else if (x >= 22 && x <= 23) return YouFMInfo[5];
  27. else return YouFMInfo[6];
  28. }
  29. 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"};
  30. public String getBR3InfoByTime(int x) {
  31. if (x >= 5 && x < 9) return BR3Info[0];
  32. else if (x >= 9 && x < 12) return BR3Info[1];
  33. else if (x == 12) return BR3Info[2];
  34. else if (x >= 13 && x < 16) return BR3Info[3];
  35. else if (x >= 16 && x < 19) return BR3Info[4];
  36. else if (x >= 19 && x < 21) return BR3Info[5];
  37. else if (x >= 21 && x < 24) return BR3Info[6];
  38. else return BR3Info[7];
  39. }
  40. 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"};
  41. public String getAntenneBYInfoByTime(int x) {
  42. if (x >= 5 && x < 9) return AntenneBYInfo[0];
  43. else if (x >= 9 && x < 12) return AntenneBYInfo[1];
  44. else if (x >= 12 && x < 15) return AntenneBYInfo[2];
  45. else if (x >= 15 && x < 19) return AntenneBYInfo[3];
  46. else return AntenneBYInfo[4];
  47. }
  48. String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"};
  49. public void setLautstaerke(int lautstaerke) {
  50. Lautstaerke = lautstaerke;
  51. }
  52. public void changeRegion(String region) {
  53. switch (region) {
  54. case "BY":
  55. regionPlaylist.clear();
  56. regionPlaylist.add("Antenne Bayern");
  57. regionPlaylist.add("Bayern 1");
  58. regionPlaylist.add("Bayern 3");
  59. regionPlaylist.add("Hit Radio N1");
  60. playedStation = regionPlaylist.get(0);
  61. break;
  62. case "HE":
  63. regionPlaylist.clear();
  64. regionPlaylist.add("Hit Radio FFH");
  65. regionPlaylist.add("HR 1");
  66. regionPlaylist.add("HR 3");
  67. regionPlaylist.add("YouFM");
  68. playedStation = regionPlaylist.get(0);
  69. break;
  70. case "BW":
  71. regionPlaylist.clear();
  72. regionPlaylist.add("DASDING");
  73. regionPlaylist.add("SWR 1");
  74. regionPlaylist.add("SWR 3");
  75. regionPlaylist.add("sunshine live");
  76. playedStation = regionPlaylist.get(0);
  77. break;
  78. }
  79. }
  80. @Override
  81. public void louder() {
  82. if (Lautstaerke < 100) {
  83. Lautstaerke += 1;
  84. } else Lautstaerke = 100;
  85. }
  86. @Override
  87. public void quieter() {
  88. if (Lautstaerke > 0) {
  89. Lautstaerke -= 1;
  90. } else Lautstaerke = 0;
  91. }
  92. @Override
  93. public int getVolume() {
  94. return Lautstaerke;
  95. }
  96. @Override
  97. public void next() {
  98. if (regionPlaylist.contains(playedStation)) {
  99. int currentIndex = regionPlaylist.indexOf(playedStation);
  100. int nextIndex = (currentIndex + 1) % regionPlaylist.size();
  101. playedStation = regionPlaylist.get(nextIndex);
  102. } else {
  103. int currentIndex = savedPlaylist.indexOf(playedStation);
  104. int nextIndex = (currentIndex + 1) % savedPlaylist.size();
  105. playedStation = savedPlaylist.get(nextIndex);
  106. }
  107. }
  108. @Override
  109. public void prev() {
  110. if (regionPlaylist.contains(playedStation)) {
  111. int currentIndex = regionPlaylist.indexOf(playedStation);
  112. int nextIndex = regionPlaylist.size() - 1;
  113. if (currentIndex != 0) {
  114. nextIndex = (currentIndex - 1);
  115. }
  116. playedStation = regionPlaylist.get(nextIndex);
  117. } else {
  118. {
  119. int currentIndex = savedPlaylist.indexOf(playedStation);
  120. int nextIndex = savedPlaylist.size() - 1;
  121. if (currentIndex != 0) {
  122. nextIndex = (currentIndex - 1);
  123. }
  124. playedStation = savedPlaylist.get(nextIndex);
  125. }
  126. }
  127. }
  128. @Override
  129. public String getInfoText() {
  130. return null;
  131. }
  132. @Override
  133. public String[] getOptions() {
  134. return new String[0];
  135. }
  136. @Override
  137. public String chooseItem(int itemNr) {
  138. if (regionPlaylist.contains(playedStation)) {
  139. playedStation = regionPlaylist.get(itemNr - 1);
  140. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  141. } else {
  142. if (itemNr > savedPlaylist.size()) {
  143. playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
  144. return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
  145. } else if (itemNr < 1) {
  146. playedStation = savedPlaylist.get(0);
  147. return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
  148. } else {
  149. playedStation = savedPlaylist.get(itemNr - 1);
  150. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  151. }
  152. }
  153. }
  154. @Override
  155. public String[] getItemList() {
  156. return null;
  157. }
  158. @Override
  159. public String play() {
  160. if (regionPlaylist.contains(playedStation))
  161. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  162. else
  163. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  164. }
  165. public String showStationInfo() {
  166. switch (playedStation) {
  167. case "Antenne Bayern":
  168. return getAntenneBYInfoByTime(hour);
  169. case "YouFM":
  170. return getYouFMInfoByTime(hour);
  171. case "Bayern 3":
  172. return getBR3InfoByTime(hour);
  173. default:
  174. return "";
  175. }
  176. }
  177. public String saveStation() {
  178. if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
  179. else savedPlaylist.add(playedStation);
  180. regionPlaylist.clear();
  181. return "Station " + playedStation + " is saved in your Station list";
  182. }
  183. public String deleteStation() {
  184. String station = playedStation;
  185. if ((savedPlaylist.size()) > 1) {
  186. savedPlaylist.remove(playedStation);
  187. playedStation = savedPlaylist.get(0);
  188. return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
  189. } else return " Last Station: 01 " + station + " can´t by deleted";
  190. }
  191. public String changeToSavedPlaylist() {
  192. if (regionPlaylist.contains(playedStation)) {
  193. playedStation = savedPlaylist.get(0);
  194. regionPlaylist.clear();
  195. return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
  196. }
  197. return "You are already in saved Playlist!";
  198. }
  199. public String changeOrderInSavedPlaylist(int nr) {
  200. String station = playedStation;
  201. if ((nr - 1) > savedPlaylist.size()) {
  202. savedPlaylist.remove(playedStation);
  203. savedPlaylist.add(savedPlaylist.size(), station);
  204. return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
  205. } else if (nr < 0) {
  206. savedPlaylist.remove(playedStation);
  207. savedPlaylist.add(0, station);
  208. return "Station " + playedStation + " is now on place 01 in saved playlist";
  209. } else {
  210. savedPlaylist.remove(playedStation);
  211. savedPlaylist.add(nr - 1, station);
  212. return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
  213. }
  214. }
  215. }