From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Date: Thu, 16 Dec 2021 09:14:59 +0000 (+0900)
Subject: feat: add manualUpdate feature.
X-Git-Tag: v3.0.0^2~4
X-Git-Url: http://git.osdn.net/view?p=delesterandomselector%2FDelesteRandomSelector.git;a=commitdiff_plain;h=16c1739bd46f8f721cfc0c7bdd5aa21813d531e4
feat: add manualUpdate feature.
BREAKING CHANGE: GUI Structure has been changed partly because of this.
---
diff --git a/src/com/ranfa/languages/List_en_US.properties b/src/com/ranfa/languages/List_en_US.properties
index c0ec3f6..2733d5b 100644
--- a/src/com/ranfa/languages/List_en_US.properties
+++ b/src/com/ranfa/languages/List_en_US.properties
@@ -25,4 +25,6 @@ MSGCompletePost:Complete to post.
MSGTerminate:End
MSGInternalYpdateNotDoneYet:Internal update in progress. Please wait a moment.
MSGNarrowDownProcedure:How to select songs\r\n1.Select difficulty, attribute, and level.\r\n2.Click [Narrow down songs] button.\r\n3.Click [start!] button.\r\n4.Selected songs will be shown here!\r\nThe maximum number of selected songs:
-MSGCurrentAlbumType:\nCurrent MASTER+ ALBUM type(based on simulation):
\ No newline at end of file
+MSGCurrentAlbumType:\nCurrent MASTER+ ALBUM type(based on simulation):
+MSGManualUpdate:
Manual
Update
+MSGManualUpdateNotCompleteYet:Manual Update has not been finished yet. Please wait a moment.
\ No newline at end of file
diff --git a/src/com/ranfa/languages/List_ja_JP.properties b/src/com/ranfa/languages/List_ja_JP.properties
index 009177a..f0ecea4 100644
--- a/src/com/ranfa/languages/List_ja_JP.properties
+++ b/src/com/ranfa/languages/List_ja_JP.properties
@@ -25,4 +25,6 @@ MSGCompletePost:\u6295\u7a3f\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002
MSGTerminate:\u7d42\u4e86
MSGInternalYpdateNotDoneYet:\u5185\u90e8\u66f4\u65b0\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u5c11\u3057\u5f85\u3063\u3066\u304b\u3089\u3084\u308a\u76f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002
MSGNarrowDownProcedure:\u697d\u66f2\u9078\u629e\u306e\u624b\u9806\r\n\uff11\uff0e\u96e3\u6613\u5ea6\u3001\u5c5e\u6027\u3001\u30ec\u30d9\u30eb\u3092\u9078\u629e\u3059\u308b\r\n\uff12\uff0e\u300c\u697d\u66f2\u53d6\u308a\u8fbc\u307f\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3059\uff01\r\n\uff13\uff0e\u300c\u958b\u59cb\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3059\uff01\r\n\uff14\uff0e\u9078\u629e\u3055\u308c\u305f\u697d\u66f2\u304c\u3053\u3053\u306b\u8868\u793a\u3055\u308c\u307e\u3059\uff01\r\n\u73fe\u5728\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u697d\u66f2\u9078\u629e\u306e\u6700\u5927\u6570\uff1a
-MSGCurrentAlbumType:\n\u73fe\u5728\u306eMASTER+\u30a2\u30eb\u30d0\u30e0\u5468\u671f\uff08\u63a8\u5b9a\uff09\uff1a
\ No newline at end of file
+MSGCurrentAlbumType:\n\u73fe\u5728\u306eMASTER+\u30a2\u30eb\u30d0\u30e0\u5468\u671f\uff08\u63a8\u5b9a\uff09\uff1a
+MSGManualUpdate:\u624b\u52d5\u66f4\u65b0
+MSGManualUpdateNotCompleteYet:\u624b\u52d5\u66f4\u65b0\u304c\u5b8c\u4e86\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u3082\u3046\u3057\u3070\u3089\u304f\u304a\u5f85\u3061\u304f\u3060\u3055\u3044\u3002
\ No newline at end of file
diff --git a/src/com/ranfa/lib/ManualUpdateThreadImpl.java b/src/com/ranfa/lib/ManualUpdateThreadImpl.java
new file mode 100644
index 0000000..8ff7efd
--- /dev/null
+++ b/src/com/ranfa/lib/ManualUpdateThreadImpl.java
@@ -0,0 +1,59 @@
+package com.ranfa.lib;
+
+import java.util.ArrayList;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.function.BiConsumer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManualUpdateThreadImpl implements Runnable {
+
+ //Declare flag
+ private static boolean flag = true;
+
+ //Declare Executor service
+ private Executor executor = Executors.newWorkStealingPool();
+ private BiConsumer, ArrayList> updateConsumer = (list1, list2) -> {
+ this.logger.info("Checking database updates...");
+ if(list1.size() > list2.size()) {
+ long time = System.currentTimeMillis();
+ this.logger.info("{} Update detected.", (list1.size() - list2.size()));
+ Scraping.writeToJson(list1);
+ this.logger.info("Update completed in {} ms", (System.currentTimeMillis() - time));
+ this.logger.info("Updated database size: {}", list1.size());
+ } else {
+ this.logger.info("database is up-to-date.");
+ }
+ };
+
+ //Declare logger
+ private Logger logger = LoggerFactory.getLogger(ManualUpdateThreadImpl.class);
+
+ public ManualUpdateThreadImpl() {
+ this.logger.info("ManualUpdateThread is now available.");
+ }
+
+ @Override
+ public void run() {
+ if (flag) {
+ flag = false;
+ }
+ this.logger.info("Checking database updates...");
+ CompletableFuture> webData = CompletableFuture.supplyAsync(Scraping::getWholeData, this.executor);
+ CompletableFuture> localData = CompletableFuture.supplyAsync(Scraping::getFromJson, this.executor);
+ try {
+ this.updateConsumer.accept(webData.get(), localData.get());
+ } catch (InterruptedException | ExecutionException e) {
+ this.logger.warn("Update failed.", e);
+ }
+ flag = true;
+ }
+
+ public boolean getFlag() {
+ return flag;
+ }
+}
diff --git a/src/com/ranfa/main/DelesteRandomSelector.java b/src/com/ranfa/main/DelesteRandomSelector.java
index 935842b..0feeb6d 100644
--- a/src/com/ranfa/main/DelesteRandomSelector.java
+++ b/src/com/ranfa/main/DelesteRandomSelector.java
@@ -34,6 +34,7 @@ import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec;
import com.ranfa.lib.CheckVersion;
import com.ranfa.lib.EstimateAlbumTypeCycle;
+import com.ranfa.lib.ManualUpdateThreadImpl;
import com.ranfa.lib.Scraping;
import com.ranfa.lib.SettingJSONProperty;
import com.ranfa.lib.Settings;
@@ -74,6 +75,9 @@ public class DelesteRandomSelector extends JFrame {
private CompletableFuture albumTypeEstimateFuture = null;
private String albumType = Messages.MSGAlbumTypeBeingCalculated.toString();
private Logger logger = LoggerFactory.getLogger(DelesteRandomSelector.class);
+ private ManualUpdateThreadImpl impl;
+ private Thread manualUpdateThread;
+ private JButton btnNewButton;
/**
* Launch the application.
@@ -163,8 +167,8 @@ public class DelesteRandomSelector extends JFrame {
}
this.logger.debug("Version: {}", CheckVersion.getVersion());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setBounds(100, 100, this.property.getWindowWidth(), this.property.getWindowHeight());
- // this.setBounds(100, 100, 640, 360);
+ // this.setBounds(100, 100, this.property.getWindowWidth(), this.property.getWindowHeight());
+ this.setBounds(100, 100, 640, 360);
this.contentPane = new JPanel();
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
this.setContentPane(this.contentPane);
@@ -269,6 +273,11 @@ public class DelesteRandomSelector extends JFrame {
this.btnImport = new JButton(Messages.MSGUpdatingDatabase.toString());
this.btnImport.setEnabled(false);
this.btnImport.addActionListener(e -> {
+ if(this.impl != null) {
+ if(!this.impl.getFlag()) {
+ JOptionPane.showMessageDialog(null, Messages.MSGManualUpdateNotCompleteYet.toString());
+ }
+ }
ArrayList fromJson = Scraping.getFromJson();
ArrayList specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)DelesteRandomSelector.this.spinnerLevel.getValue(), DelesteRandomSelector.this.checkLessLv.isSelected(), DelesteRandomSelector.this.checkMoreLv.isSelected());
ArrayList specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, DelesteRandomSelector.this.comboDifficultySelect.getSelectedItem().toString());
@@ -351,11 +360,21 @@ public class DelesteRandomSelector extends JFrame {
DelesteRandomSelector.this.logger.info("seems to reject the permission.it should need try again.");
}
});
+
+ this.btnNewButton = new JButton(Messages.MSGManualUpdate.toString());
+ this.btnNewButton.addActionListener(e -> {
+ this.impl = new ManualUpdateThreadImpl();
+ this.manualUpdateThread = new Thread(this.impl);
+ this.manualUpdateThread.setName("ManualUpdate-thread");
+ this.manualUpdateThread.setDaemon(false);
+ this.manualUpdateThread.start();
+ });
+ this.panelEast.add(this.btnNewButton, "1, 9");
this.panelEast.add(this.btnTwitterIntegration, "1, 11");
this.btnExit = new JButton(Messages.MSGTerminate.toString());
this.btnExit.addActionListener(e -> {
- if(DelesteRandomSelector.this.softwareUpdateFuture.isDone() || DelesteRandomSelector.this.albumTypeEstimateFuture.isDone()) {
+ if(DelesteRandomSelector.this.softwareUpdateFuture.isDone() || DelesteRandomSelector.this.albumTypeEstimateFuture.isDone() || !this.impl.getFlag()) {
DelesteRandomSelector.this.logger.info("Requested Exit by Button");
System.exit(0);
} else {
diff --git a/src/com/ranfa/main/Messages.java b/src/com/ranfa/main/Messages.java
index bd34357..78cfedc 100644
--- a/src/com/ranfa/main/Messages.java
+++ b/src/com/ranfa/main/Messages.java
@@ -37,7 +37,9 @@ public enum Messages {
MSGTerminate,
MSGInternalYpdateNotDoneYet,
MSGNarrowDownProcedure,
- MSGCurrentAlbumType;
+ MSGCurrentAlbumType,
+ MSGManualUpdate,
+ MSGManualUpdateNotCompleteYet;
@Override
diff --git a/src/test/LanguageTest.java b/src/test/LanguageTest.java
index 985fa7e..bbdcc87 100644
--- a/src/test/LanguageTest.java
+++ b/src/test/LanguageTest.java
@@ -50,6 +50,8 @@ public class LanguageTest {
assertTrue(Messages.MSGInternalYpdateNotDoneYet.toString().equals("å
é¨æ´æ°å¦çãå®äºãã¦ãã¾ãããå°ãå¾
ã£ã¦ããããç´ãã¦ãã ããã"));
assertTrue(Messages.MSGNarrowDownProcedure.toString().equals("楽æ²é¸æã®æé \r\nï¼ï¼é£æ度ãå±æ§ãã¬ãã«ãé¸æãã\r\nï¼ï¼ã楽æ²åãè¾¼ã¿ããã¿ã³ãæ¼ãï¼\r\nï¼ï¼ãéå§ããã¿ã³ãæ¼ãï¼\r\nï¼ï¼é¸æããã楽æ²ãããã«è¡¨ç¤ºããã¾ãï¼\r\nç¾å¨è¨å®ããã¦ãã楽æ²é¸æã®æ大æ°ï¼"));
assertTrue(Messages.MSGCurrentAlbumType.toString().equals("\nç¾å¨ã®MASTER+ã¢ã«ãã å¨æï¼æ¨å®ï¼ï¼"));
+ assertTrue(Messages.MSGManualUpdate.toString().equals("æåæ´æ°"));
+ assertTrue(Messages.MSGManualUpdateNotCompleteYet.toString().equals("æåæ´æ°ãå®äºãã¦ãã¾ããããããã°ãããå¾
ã¡ãã ããã"));
}
@Test
@@ -86,6 +88,8 @@ public class LanguageTest {
assertTrue(Messages.MSGInternalYpdateNotDoneYet.toString().equals("Internal update in progress. Please wait a moment."));
assertTrue(Messages.MSGNarrowDownProcedure.toString().equals("How to select songs\r\n1.Select difficulty, attribute, and level.\r\n2.Click [Narrow down songs] button.\r\n3.Click [start!] button.\r\n4.Selected songs will be shown here!\r\nThe maximum number of selected songs:"));
assertTrue(Messages.MSGCurrentAlbumType.toString().equals("\nCurrent MASTER+ ALBUM type(based on simulation):"));
+ assertTrue(Messages.MSGManualUpdate.toString().equals("Manual
Update"));
+ assertTrue(Messages.MSGManualUpdateNotCompleteYet.toString().equals("Manual Update has not been finished yet. Please wait a moment."));
}
@After