OSDN Git Service

feat: added Twitter Integration
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Thu, 5 Aug 2021 08:52:43 +0000 (17:52 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Thu, 5 Aug 2021 08:52:43 +0000 (17:52 +0900)
BREAKING CHANGE: Releasing major release!

README.md
src/com/ranfa/main/DelesteRandomSelector.java

index b56fc89..c78c257 100644 (file)
--- a/README.md
+++ b/README.md
@@ -23,10 +23,10 @@ THIS SOFTWARE DEPENDS ON APACHE LICENSE 2.0 BECAUSE THIS USED SOME LIBRARIES WHI
 
 |設定項目|値|デフォルト|説明|
 |:--:|:--:|:--:|:--:|
-|`checkVersion`|`true`/`false`|`true`|アプリケーションのバージョンをチェックします|
+|`checkVersion`|`true`/`false`|`true`|アプリケーションのバージョンをチェックします(機能作成中のためこの値は使用していません)|
 |`checkLibaryUpdates`|`true`/`false`|`true`|楽曲ライブラリの更新を毎回チェックします|
-|`windowWidth`|1以上の整数値|`640`|ウィンドウの横長さを指定します|
-|`windowHeight`|1以上の整数値|`360`|ウィンドウの縦長さを指定します|
+|`windowWidth`|1以上の整数値|`640`|ウィンドウの横長さを指定します(機能作成中のためこの値は使用していません)|
+|`windowHeight`|1以上の整数値|`360`|ウィンドウの縦長さを指定します(機能作成中のためこの値は使用していません)|
 |`songLimit`|1以上の整数値|`3`|ランダム選曲する最大曲数を指定します|
-|`saveScoreLog`|`true`/`false`|`false`|スコアデータを保存するかどうか指定します|
+|`saveScoreLog`|`true`/`false`|`false`|スコアデータを保存するかどうか指定します(機能作成中のためこの値は使用していません)|
 |`outputDebugSentences`|`true`/`false`|`false`|標準出力へログを流すかどうか指定します
\ No newline at end of file
index 5ebaac0..de533ae 100644 (file)
@@ -36,9 +36,10 @@ import com.ranfa.lib.Scraping;
 import com.ranfa.lib.SettingJSONProperty;
 import com.ranfa.lib.Settings;
 import com.ranfa.lib.Song;
+import com.ranfa.lib.TwitterIntegration;
 import com.ranfa.lib.Version;
 
-@Version(major = 0, minor = 2, patch = 1)
+@Version(major = 1, minor = 0, patch = 0)
 public class DelesteRandomSelector extends JFrame {
 
        private static ArrayList<Song> selectedSongsList = new ArrayList<Song>();
@@ -62,8 +63,10 @@ public class DelesteRandomSelector extends JFrame {
        private JComboBox comboDifficultySelect;
        private JLabel labelLvCaution;
        private JComboBox comboAttribute;
-
        private SettingJSONProperty property = new SettingJSONProperty();
+       private JButton btnTwitterIntegration;
+       private String[] integratorArray;
+       private boolean integratorBool = false;
 
        /**
         * Launch the application.
@@ -221,15 +224,21 @@ public class DelesteRandomSelector extends JFrame {
                        new RowSpec[] {
                                RowSpec.decode("26px"),
                                FormSpecs.RELATED_GAP_ROWSPEC,
-                               RowSpec.decode("max(50dlu;default)"),
+                               RowSpec.decode("max(36dlu;default)"),
                                FormSpecs.RELATED_GAP_ROWSPEC,
                                FormSpecs.DEFAULT_ROWSPEC,
                                FormSpecs.RELATED_GAP_ROWSPEC,
-                               RowSpec.decode("max(50dlu;default)"),
+                               RowSpec.decode("max(30dlu;default)"),
                                FormSpecs.RELATED_GAP_ROWSPEC,
                                RowSpec.decode("max(15dlu;default)"),
                                FormSpecs.RELATED_GAP_ROWSPEC,
-                               RowSpec.decode("max(11dlu;default)"),}));
+                               RowSpec.decode("max(11dlu;default)"),
+                               FormSpecs.RELATED_GAP_ROWSPEC,
+                               FormSpecs.DEFAULT_ROWSPEC,
+                               FormSpecs.RELATED_GAP_ROWSPEC,
+                               FormSpecs.DEFAULT_ROWSPEC,
+                               FormSpecs.RELATED_GAP_ROWSPEC,
+                               FormSpecs.DEFAULT_ROWSPEC,}));
 
                btnImport = new JButton("<html><body>楽曲<br>絞り込み</body></html>");
                btnImport.addActionListener(new ActionListener() {
@@ -253,9 +262,11 @@ public class DelesteRandomSelector extends JFrame {
                        public void actionPerformed(ActionEvent e) {
                                Random random = new Random(System.currentTimeMillis());
                                String[] tmp = new String[property.getSongLimit()];
+                               integratorArray = new String[property.getSongLimit()];
                                for(int i = 0; i < property.getSongLimit(); i++) {
                                        int randomInt = random.nextInt(selectedSongsList.size());
                                        tmp[i] = (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + ")\n\n";
+                                       integratorArray[i] = selectedSongsList.get(randomInt).getName() + "\n";
                                }
                                String paneString = "";
                                for (int i = 0; i < tmp.length; i++) {
@@ -263,25 +274,81 @@ public class DelesteRandomSelector extends JFrame {
                                }
                                paneString = paneString + "この" + tmp.length + "曲をプレイしましょう!!!";
                                textPane.setText(paneString);
+                               integratorBool = true;
                                LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "show up completed.");
                        }
                });
                btnStart.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 13));
                panelEast.add(btnStart, "1, 7, fill, fill");
 
-               btnExit = new JButton("終了");
-               btnExit.addActionListener(new ActionListener() {
-                       public void actionPerformed(ActionEvent e) {
-                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " +"Requested Exit by Button");
-                               if(getWholeDataFuture.isDone()) {
-                                       System.exit(0);
-                               } else {
-                                       JOptionPane.showMessageDialog(null, "非同期処理が完了していません。少し時間が経ってからやり直してください。");
-                               }
-                       }
-               });
-               btnExit.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 13));
-               panelEast.add(btnExit, "1, 11");
+                               btnTwitterIntegration = new JButton("Twitter連携");
+                               btnTwitterIntegration.addActionListener(new ActionListener() {
+                                       public void actionPerformed(ActionEvent e) {
+                                               System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Twitter Integration requested.Verify permission status.");
+                                               boolean authorizationStatus = TwitterIntegration.authorization();
+                                               System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Permission Verifying completed.\nStatus: " + authorizationStatus);
+                                               System.out.print("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Construction status message...");
+                                               String updatedStatus = "【TEST】デレステ課題曲セレクターで\n";
+                                               int lengthLimit = updatedStatus.length();
+                                               boolean isBroken = false;
+                                               if(!integratorBool) {
+                                                       JOptionPane.showMessageDialog(null, "ちひろ「まだプレイを始めていないみたいですね」");
+                                                       System.out.println();
+                                                       return;
+                                               }
+                                               for(int i = 0; i < integratorArray.length; i++) {
+                                                       updatedStatus = updatedStatus + integratorArray[i];
+                                                       lengthLimit += integratorArray[i].length();
+                                                       if(lengthLimit > 69) {
+                                                               isBroken = true;
+                                                               break;
+                                                       }
+                                               }
+                                               if(isBroken) {
+                                                       updatedStatus = updatedStatus + "…その他数曲\nをプレイしました!\n#DelesteRandomSelector #デレステ ";
+                                               } else {
+                                                       updatedStatus = updatedStatus + "\nをプレイしました!\n#DelesteRandomSelector #デレステ ";
+                                               }
+                                               System.out.println("completed.\n" + updatedStatus);
+                                               lengthLimit = updatedStatus.length();
+                                               if(authorizationStatus) {
+                                                       int option = JOptionPane.showConfirmDialog(null, "Twitterへ以下の内容を投稿します。よろしいですか?\n\n" + updatedStatus + "\n\n文字数:" + lengthLimit);
+                                                       System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "User selected " + option);
+                                                       switch(option) {
+                                                               case JOptionPane.OK_OPTION:
+                                                                       TwitterIntegration.PostTwitter(updatedStatus);
+                                                                       System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "Success to update the status.");
+                                                                       JOptionPane.showMessageDialog(null, "投稿が完了しました。");
+                                                                       break;
+                                                               case JOptionPane.NO_OPTION:
+                                                                       System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "There is no will to post.");
+                                                                       break;
+                                                               case JOptionPane.CANCEL_OPTION:
+                                                                       System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " + "The Operation was canceled by user.");
+                                                                       break;
+                                                               default:
+                                                                       break;
+                                                       }
+                                               } else {
+                                                       System.out.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[WARN]: " + "seems to reject the permission.it should need try again.");
+                                               }
+                                       }
+                               });
+                               panelEast.add(btnTwitterIntegration, "1, 11");
+
+                                                               btnExit = new JButton("終了");
+                                                               btnExit.addActionListener(new ActionListener() {
+                                                                       public void actionPerformed(ActionEvent e) {
+                                                                               LimitedLog.println("[" + Thread.currentThread().toString() + "]:" + this.getClass() + ":[INFO]: " +"Requested Exit by Button");
+                                                                               if(getWholeDataFuture.isDone()) {
+                                                                                       System.exit(0);
+                                                                               } else {
+                                                                                       JOptionPane.showMessageDialog(null, "非同期処理が完了していません。少し時間が経ってからやり直してください。");
+                                                                               }
+                                                                       }
+                                                               });
+                                                               btnExit.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 13));
+                                                               panelEast.add(btnExit, "1, 13");
 
                panelCentre = new JPanel();
                contentPane.add(panelCentre, BorderLayout.CENTER);