diff --git a/JSON/json-20141113.jar b/JSON/json-20141113.jar new file mode 100644 index 0000000..015c308 Binary files /dev/null and b/JSON/json-20141113.jar differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4dd6a56 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.ixab.Main + diff --git a/src/com/ixab/GUI/StreamChooserMenu.form b/src/com/ixab/GUI/StreamChooserMenu.form index e60901a..a8e106c 100644 --- a/src/com/ixab/GUI/StreamChooserMenu.form +++ b/src/com/ixab/GUI/StreamChooserMenu.form @@ -38,7 +38,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -144,12 +144,20 @@ - + + + + + + + + + diff --git a/src/com/ixab/GUI/StreamChooserMenu.java b/src/com/ixab/GUI/StreamChooserMenu.java index 9bf8bb7..ef8b13d 100644 --- a/src/com/ixab/GUI/StreamChooserMenu.java +++ b/src/com/ixab/GUI/StreamChooserMenu.java @@ -6,15 +6,12 @@ import com.ixab.StreamHandling.StreamInfo; import com.ixab.StreamHandling.StreamOpener; import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; +import java.awt.event.*; public class StreamChooserMenu { private JPanel panel; private JComboBox comboBoxStreams; - private JComboBox comboBox2; + private JComboBox comboBoxQuality; private JTextField textField1; private JButton hinzufügenButton; private JButton streamAbspielenButton; @@ -23,13 +20,15 @@ public class StreamChooserMenu { private JLabel labelStreamViewers; private JLabel labelStreamTitle; private JLabel labelStreamGame; + private JButton neuLadenButton; + private boolean lockStreamInfoGetter = false; public StreamChooserMenu() { this.initComboBoxes(); streamAbspielenButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - StreamOpener so = new StreamOpener(ConfigFileInstanceHandler.getConfig(), ConfigFileInstanceHandler.getConfig().getStreams().indexOf(comboBoxStreams.getSelectedItem()), comboBox2.getSelectedItem().toString()); + StreamOpener so = new StreamOpener(ConfigFileInstanceHandler.getConfig(), ConfigFileInstanceHandler.getConfig().getStreams().indexOf(comboBoxStreams.getSelectedItem()), comboBoxQuality.getSelectedItem().toString()); so.start(); } }); @@ -44,18 +43,17 @@ public class StreamChooserMenu { public void actionPerformed(ActionEvent e) { ConfigFileInstanceHandler.getConfig().removeStream(comboBoxStreams.getSelectedItem()); ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig()); + lockStreamInfoGetter = true; initStreamsComboBox(); + lockStreamInfoGetter = false; } }); comboBoxStreams.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - // TODO: implement twitch api and update stream info - StreamInfo.getStreamInfo(comboBoxStreams.getSelectedItem().toString()); - labelStreamStatus.setText(StreamInfo.getStatus()); - labelStreamGame.setText(StreamInfo.getGame()); - labelStreamViewers.setText(StreamInfo.getViewers()); - labelStreamTitle.setText(StreamInfo.getTitle()); + if (!lockStreamInfoGetter) { + updateStreamDetails(); + } } }); textField1.addKeyListener(new KeyAdapter() { @@ -67,11 +65,26 @@ public class StreamChooserMenu { } } }); + neuLadenButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + updateStreamDetails(); + } + }); + } + private void updateStreamDetails() { + StreamInfo.getStreamInfo(comboBoxStreams.getSelectedItem().toString()); + labelStreamStatus.setText(StreamInfo.getStatus()); + labelStreamGame.setText(StreamInfo.getGame()); + labelStreamViewers.setText(StreamInfo.getViewers()); + labelStreamTitle.setText(StreamInfo.getTitle()); } private void addNewStream() { ConfigFileInstanceHandler.getConfig().addStream(textField1.getText()); ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig()); + lockStreamInfoGetter = true; initStreamsComboBox(); + lockStreamInfoGetter = false; textField1.setText(""); } private void initComboBoxes() { @@ -86,8 +99,8 @@ public class StreamChooserMenu { } } private void initQualityComboBox() { - comboBox2.removeAllItems(); - comboBox2.addItem("best"); comboBox2.addItem("high"); comboBox2.addItem("medium"); comboBox2.addItem("low"); comboBox2.addItem("mobile"); + comboBoxQuality.removeAllItems(); + comboBoxQuality.addItem("best"); comboBoxQuality.addItem("high"); comboBoxQuality.addItem("medium"); comboBoxQuality.addItem("low"); comboBoxQuality.addItem("mobile"); } public static void main(String[] args) { JFrame frame = new JFrame("jLSLauncher v"+ com.ixab.Main.getVersion()); diff --git a/src/com/ixab/StreamHandling/StreamInfo.java b/src/com/ixab/StreamHandling/StreamInfo.java index 5892f7a..156295a 100644 --- a/src/com/ixab/StreamHandling/StreamInfo.java +++ b/src/com/ixab/StreamHandling/StreamInfo.java @@ -43,51 +43,51 @@ public class StreamInfo { } } public static void getStreamInfo(String streamName) { - InputStream is = null; - URL url = null; - JSONObject object = null; - StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append("https://api.twitch.tv/kraken/streams/"); + if (streamName != null) { + InputStream is = null; + URL url = null; + JSONObject object = null; + StringBuilder urlBuilder = new StringBuilder(); + urlBuilder.append("https://api.twitch.tv/kraken/streams/"); - urlBuilder.append(streamName); + urlBuilder.append(streamName); - String URLString = urlBuilder.toString(); + String URLString = urlBuilder.toString(); - try { - url = new URL(URLString); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - try { - is = url.openStream(); - } catch (IOException e) { - e.printStackTrace(); - } - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - - try { - String line; - StringBuilder sb = new StringBuilder(); - while ((line = br.readLine()) != null) - { - sb.append(line); + try { + url = new URL(URLString); + } catch (MalformedURLException e) { + e.printStackTrace(); } - object = new JSONObject(sb.toString()); + try { + is = url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + } + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); - } catch (IOException e) { - e.printStackTrace(); + try { + String line; + StringBuilder sb = new StringBuilder(); + while ((line = br.readLine()) != null) { + sb.append(line); + } + object = new JSONObject(sb.toString()); + + } catch (IOException e) { + e.printStackTrace(); + } + + String result = object.get("stream").toString(); + + if (result == "null") { + streamData = null; + streamPreviewData = null; + } else { + streamData = new JSONObject(result); + streamPreviewData = new JSONObject(streamData.get("preview").toString()); + } } - - String result = object.get("stream").toString(); - - if (result == "null") { - streamData = null; - streamPreviewData = null; - } else { - streamData = new JSONObject(result); - streamPreviewData = new JSONObject(streamData.get("preview").toString()); - } - } }