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.

267 lines
9.8 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. if (itemNr > regionPlaylist.size()) {
  140. playedStation = regionPlaylist.get(regionPlaylist.size() - 1);
  141. return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist");
  142. } else if (itemNr < 1) {
  143. playedStation = regionPlaylist.get(0);
  144. return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist");
  145. } else {
  146. playedStation = regionPlaylist.get(itemNr - 1);
  147. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  148. }
  149. } else {
  150. if (itemNr > savedPlaylist.size()) {
  151. playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
  152. return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
  153. } else if (itemNr < 1) {
  154. playedStation = savedPlaylist.get(0);
  155. return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
  156. } else {
  157. playedStation = savedPlaylist.get(itemNr - 1);
  158. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  159. }
  160. }
  161. }
  162. @Override
  163. public String[] getItemList() {
  164. return null;
  165. }
  166. @Override
  167. public String mute() {
  168. return null;
  169. }
  170. @Override
  171. public String unmute() {
  172. return null;
  173. }
  174. @Override
  175. public String play() {
  176. if (regionPlaylist.contains(playedStation))
  177. return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
  178. else
  179. return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
  180. }
  181. public String showStationInfo() {
  182. switch (playedStation) {
  183. case "Antenne Bayern":
  184. return getAntenneBYInfoByTime(hour);
  185. case "YouFM":
  186. return getYouFMInfoByTime(hour);
  187. case "Bayern 3":
  188. return getBR3InfoByTime(hour);
  189. default:
  190. return "";
  191. }
  192. }
  193. public String saveStation() {
  194. if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
  195. else savedPlaylist.add(playedStation);
  196. regionPlaylist.clear();
  197. return "Station " + playedStation + " is saved in your Station list";
  198. }
  199. public String deleteStation() {
  200. String station = playedStation;
  201. if ((savedPlaylist.size()) > 1) {
  202. savedPlaylist.remove(playedStation);
  203. playedStation = savedPlaylist.get(0);
  204. return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
  205. } else return " Last Station: 01 " + station + " can´t by deleted";
  206. }
  207. public String changeToSavedPlaylist() {
  208. if (regionPlaylist.contains(playedStation)) {
  209. playedStation = savedPlaylist.get(0);
  210. regionPlaylist.clear();
  211. return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
  212. }
  213. return "You are already in saved Playlist!";
  214. }
  215. public String changeOrderInSavedPlaylist(int nr) {
  216. String station = playedStation;
  217. if ((nr - 1) > savedPlaylist.size()) {
  218. savedPlaylist.remove(playedStation);
  219. savedPlaylist.add(savedPlaylist.size(), station);
  220. return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
  221. } else if (nr < 0) {
  222. savedPlaylist.remove(playedStation);
  223. savedPlaylist.add(0, station);
  224. return "Station " + playedStation + " is now on place 01 in saved playlist";
  225. } else {
  226. savedPlaylist.remove(playedStation);
  227. savedPlaylist.add(nr - 1, station);
  228. return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
  229. }
  230. }
  231. }