BREAKING CHANGE: GUI Structure has been changed partly because of this.
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:<html><body>Manual<br>Update</body></html>
+MSGManualUpdateNotCompleteYet:Manual Update has not been finished yet. Please wait a moment.
\ No newline at end of file
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:<html><body>\u624b\u52d5\u66f4\u65b0</body></html>
+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
--- /dev/null
+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<Song>, ArrayList<Song>> 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<ArrayList<Song>> webData = CompletableFuture.supplyAsync(Scraping::getWholeData, this.executor);
+ CompletableFuture<ArrayList<Song>> 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;
+ }
+}
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;
private CompletableFuture<Void> 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.
}
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);
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<Song> fromJson = Scraping.getFromJson();
ArrayList<Song> specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)DelesteRandomSelector.this.spinnerLevel.getValue(), DelesteRandomSelector.this.checkLessLv.isSelected(), DelesteRandomSelector.this.checkMoreLv.isSelected());
ArrayList<Song> specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, DelesteRandomSelector.this.comboDifficultySelect.getSelectedItem().toString());
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 {
MSGTerminate,
MSGInternalYpdateNotDoneYet,
MSGNarrowDownProcedure,
- MSGCurrentAlbumType;
+ MSGCurrentAlbumType,
+ MSGManualUpdate,
+ MSGManualUpdateNotCompleteYet;
@Override
assertTrue(Messages.MSGInternalYpdateNotDoneYet.toString().equals("内部更新処理が完了していません。少し待ってからやり直してください。"));
assertTrue(Messages.MSGNarrowDownProcedure.toString().equals("楽曲選択の手順\r\n1.難易度、属性、レベルを選択する\r\n2.「楽曲取り込み」ボタンを押す!\r\n3.「開始」ボタンを押す!\r\n4.選択された楽曲がここに表示されます!\r\n現在設定されている楽曲選択の最大数:"));
assertTrue(Messages.MSGCurrentAlbumType.toString().equals("\n現在のMASTER+アルバム周期(推定):"));
+ assertTrue(Messages.MSGManualUpdate.toString().equals("<html><body>手動更新</body></html>"));
+ assertTrue(Messages.MSGManualUpdateNotCompleteYet.toString().equals("手動更新が完了していません。もうしばらくお待ちください。"));
}
@Test
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("<html><body>Manual<br>Update</body></html>"));
+ assertTrue(Messages.MSGManualUpdateNotCompleteYet.toString().equals("Manual Update has not been finished yet. Please wait a moment."));
}
@After