diff --git a/app/src/main/java/com/astarivi/kaizoyu/gui/more/settings/SettingsActivity.java b/app/src/main/java/com/astarivi/kaizoyu/gui/more/settings/SettingsActivity.java index fcd9bf9..f1c21b4 100644 --- a/app/src/main/java/com/astarivi/kaizoyu/gui/more/settings/SettingsActivity.java +++ b/app/src/main/java/com/astarivi/kaizoyu/gui/more/settings/SettingsActivity.java @@ -101,6 +101,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { binding.advancedSearch.setOnCheckedChangeListener(this::triggerSave); binding.strictModeValue.setOnCheckedChangeListener(this::triggerSave); binding.autoMoveValue.setOnCheckedChangeListener(this::triggerSave); + binding.xdccValue.setOnCheckedChangeListener(this::triggerSave); binding.clearCacheTrigger.setOnClickListener(view -> { Utils.clearCache(); @@ -196,6 +197,11 @@ private void saveSettings(){ binding.analyticsValue.isChecked() ); + config.setBooleanProperty( + "use_xdcc", + binding.xdccValue.isChecked() + ); + config.setBooleanProperty( "show_ipv6", binding.ipv6SorcesValue.isChecked() @@ -251,6 +257,10 @@ private void loadSettings() { ); // Switches + binding.xdccValue.setChecked( + config.getBooleanProperty("use_xdcc", false) + ); + binding.analyticsValue.setChecked( config.getBooleanProperty("analytics", true) ); diff --git a/app/src/main/java/com/astarivi/kaizoyu/video/VideoPlayerViewModel.java b/app/src/main/java/com/astarivi/kaizoyu/video/VideoPlayerViewModel.java index a3443b2..9e8891a 100644 --- a/app/src/main/java/com/astarivi/kaizoyu/video/VideoPlayerViewModel.java +++ b/app/src/main/java/com/astarivi/kaizoyu/video/VideoPlayerViewModel.java @@ -107,6 +107,14 @@ public void startDownload(Context context, Result result) { 10 ); + boolean useXdcc = appProperties.getBooleanProperty("use_xdcc", false); + + Logger.info("User has set 'use XDCC' to {}", useXdcc); + + xdccDownloader.setXDCC( + useXdcc + ); + xdccDownloader.setXDCCDownloadListener(new XDCCDownloadListener() { @Override public void onDownloadReadyToPlay(int i, File file) { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index bc8130e..522dd0c 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -348,7 +348,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" - > + > + + + + + + + diff --git a/app/src/main/res/layout/fragment_home_item.xml b/app/src/main/res/layout/fragment_home_item.xml index 98910fd..29b2c81 100644 --- a/app/src/main/res/layout/fragment_home_item.xml +++ b/app/src/main/res/layout/fragment_home_item.xml @@ -5,7 +5,7 @@ android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginBottom="24dp" - > +> diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index fcf60b5..5721088 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -53,4 +53,6 @@ Hide Developer Menu Hides the developer section again Welcome to developer mode, fellow weeb + Use XDCC + When enabled, XDCC will be used instead of DCC; this may result in faster downloads. May cause complete download failure \ No newline at end of file diff --git a/service/src/main/java/com/astarivi/kaizolib/xdcc/XDCCDownloader.java b/service/src/main/java/com/astarivi/kaizolib/xdcc/XDCCDownloader.java index c0543f4..d94ada8 100644 --- a/service/src/main/java/com/astarivi/kaizolib/xdcc/XDCCDownloader.java +++ b/service/src/main/java/com/astarivi/kaizolib/xdcc/XDCCDownloader.java @@ -4,6 +4,7 @@ import com.astarivi.kaizolib.xdcc.base.XDCCDownloadListener; import com.astarivi.kaizolib.xdcc.base.XDCCFailure; import com.astarivi.kaizolib.xdcc.model.DCC; + import org.tinylog.Logger; import java.io.*; @@ -21,6 +22,7 @@ public class XDCCDownloader { private int speedKBps = 0; private long lastTimeReminderRan = 0; private XDCCDownloadListener downloadEventListener; + private boolean isXDCC = false; // Uses default timeout of 20 seconds public XDCCDownloader(DCC dcc, File downloadFile) { @@ -41,6 +43,10 @@ public void setXDCCDownloadListener(XDCCDownloadListener listener){ downloadEventListener = listener; } + public void setXDCC(boolean value) { + isXDCC = value; + } + @SuppressWarnings("unused") public void stop() { this.stop = true; @@ -102,7 +108,7 @@ public void start() { Logger.debug("About to start download loop. Downloading from: " + dcc.getIp()); // Signal start - output.write(0); + write(output, 0); while (downloadedLength < fileLength && !stop) { // Has the download not even started? @@ -135,7 +141,7 @@ public void start() { fileOutput.write(buffer, 0, read); // For old DCC compatibility - output.write((int) downloadedLength); + write(output, (int) downloadedLength); //Update progress every 400 repetitions to avoid calculating the progress so often. if (repetitions >= 400) { @@ -210,7 +216,7 @@ private void contactServer(OutputStream output) throws IOException { // First time we run if (lastTimeReminderRan == 0) { lastTimeReminderRan = timeNow; - output.write(0); + write(output, 0); Logger.debug("Telling server that we're waiting."); return; } @@ -220,7 +226,13 @@ private void contactServer(OutputStream output) throws IOException { } lastTimeReminderRan = timeNow; - output.write(0); + write(output, 0); Logger.debug("Telling server that we're waiting."); } + + private void write(OutputStream stream, int value) throws IOException { + if (isXDCC) return; + + stream.write(value); + } }