To make death I removed RxJava

This commit is contained in:
huangyuhui
2016-01-26 19:50:26 +08:00
parent 54e14a25da
commit 409fc83819
109 changed files with 197 additions and 10696 deletions

View File

@@ -21,7 +21,6 @@ import org.jackhuang.hellominecraft.utils.functions.Predicate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import rx.Observable;
/**
*
@@ -31,7 +30,9 @@ public final class CollectionUtils {
public static <T> ArrayList<T> map(Collection<T> coll, Predicate<T> p) {
ArrayList<T> newColl = new ArrayList<>();
Observable.from(coll).filter(t -> p.apply(t)).subscribe(t -> newColl.add(t));
for (T t : coll)
if (p.apply(t))
newColl.add(t);
return newColl;
}

View File

@@ -18,7 +18,6 @@
package org.jackhuang.hellominecraft.utils;
import java.util.Map;
import rx.Observable;
/**
*
@@ -50,13 +49,13 @@ public interface IUpdateChecker {
*
* @return the process observable.
*/
Observable process(boolean showMessage);
OverridableSwingWorker<VersionNumber> process(boolean showMessage);
/**
* Get the download links.
*
* @return a JSON, which contains the server response.
*/
Observable<Map<String, String>> requestDownloadLink();
OverridableSwingWorker<Map<String, String>> requestDownloadLink();
}

View File

@@ -29,7 +29,6 @@ import java.net.Proxy;
import java.net.URL;
import java.util.Map;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import rx.Observable;
/**
*
@@ -158,14 +157,4 @@ public final class NetUtils {
throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
}
}
public static Observable<String> getRx(String url) {
return Observable.createWithEmptySubscription(t1 -> {
try {
t1.onNext(get(url));
} catch (Exception e) {
t1.onError(e);
}
});
}
}

View File

@@ -0,0 +1,65 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.utils;
import java.util.ArrayList;
import java.util.List;
import javax.swing.SwingWorker;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/**
*
* @author huangyuhui
*/
public abstract class OverridableSwingWorker<T> extends SwingWorker<Void, T> {
List<Consumer<T>> processListeners = new ArrayList<>();
List<Runnable> doneListeners = new ArrayList<>();
protected abstract void work() throws Exception;
@Override
protected void done() {
for (Runnable c : doneListeners)
c.run();
}
@Override
protected Void doInBackground() throws Exception {
work();
return null;
}
public OverridableSwingWorker reg(Consumer<T> c) {
processListeners.add(c);
return this;
}
public OverridableSwingWorker regDone(Runnable c) {
doneListeners.add(c);
return this;
}
@Override
protected void process(List<T> chunks) {
for (T t : chunks)
for (Consumer<T> c : processListeners)
c.accept(t);
}
}

View File

@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.utils;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import java.util.Map;
import rx.Observable;
/**
*
@@ -41,27 +40,26 @@ public final class UpdateChecker implements IUpdateChecker {
VersionNumber value;
@Override
public Observable<VersionNumber> process(boolean showMessage) {
return Observable.createWithEmptySubscription(t -> {
if (value == null) {
try {
versionString = NetUtils.get("http://huangyuhui.duapp.com/info.php?type=" + type);
} catch (Exception e) {
HMCLog.warn("Failed to get update url.", e);
return;
}
value = VersionNumber.check(versionString);
}
public OverridableSwingWorker<VersionNumber> process(boolean showMessage) {
return new OverridableSwingWorker() {
@Override
protected void work() throws Exception {
if (value == null) {
HMCLog.warn("Failed to check update...");
if (showMessage)
MessageBox.Show(C.i18n("update.failed"));
} else if (VersionNumber.isOlder(base, value))
OUT_DATED = true;
if (OUT_DATED)
t.onNext(value);
});
if (value == null) {
versionString = NetUtils.get("http://huangyuhui.duapp.com/info.php?type=" + type);
value = VersionNumber.check(versionString);
}
if (value == null) {
HMCLog.warn("Failed to check update...");
if (showMessage)
MessageBox.Show(C.i18n("update.failed"));
} else if (VersionNumber.isOlder(base, value))
OUT_DATED = true;
if (OUT_DATED)
publish(value);
}
};
}
@Override
@@ -70,16 +68,19 @@ public final class UpdateChecker implements IUpdateChecker {
}
@Override
public synchronized Observable<Map<String, String>> requestDownloadLink() {
return Observable.createWithEmptySubscription(t -> {
if (download_link == null)
try {
download_link = C.gson.fromJson(NetUtils.get("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class);
} catch (Exception e) {
HMCLog.warn("Failed to get update link.", e);
}
t.onNext(download_link);
});
public synchronized OverridableSwingWorker<Map<String, String>> requestDownloadLink() {
return new OverridableSwingWorker() {
@Override
protected void work() throws Exception {
if (download_link == null)
try {
download_link = C.gson.fromJson(NetUtils.get("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class);
} catch (Exception e) {
HMCLog.warn("Failed to get update link.", e);
}
publish(download_link);
}
};
}
public final EventHandler<VersionNumber> outdated = new EventHandler<>(this);

View File

@@ -1,45 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.utils.tasks;
import rx.Observable;
/**
*
* @author huangyuhui
*/
public class TaskObservable<T> extends TaskInfo {
private final Observable<T> r;
public TaskObservable(String info, Observable<T> r) {
super(info);
this.r = r;
}
public TaskObservable(Observable<T> r) {
this("TaskObservable", r);
}
@Override
public void executeTask() {
r.subscribe(t -> {
});
}
}