sync
This commit is contained in:
@@ -67,11 +67,17 @@ editor.setOption("hintOptions", {
|
|||||||
completeSingle: false,
|
completeSingle: false,
|
||||||
globalScope: autoJsGlobalScope()
|
globalScope: autoJsGlobalScope()
|
||||||
});
|
});
|
||||||
|
var id = null;
|
||||||
editor.on("keyup", function(editor, event)
|
editor.on("keyup", function(editor, event)
|
||||||
{
|
{
|
||||||
if (!ExcludedIntelliSenseTriggerKeys[(event.keyCode || event.which).toString()] )
|
if (!ExcludedIntelliSenseTriggerKeys[(event.keyCode || event.which).toString()] )
|
||||||
{
|
{
|
||||||
editor.execCommand("autocomplete");
|
if(id != null){
|
||||||
|
clearTimeout(id);
|
||||||
|
}
|
||||||
|
id = setTimeout(function(){
|
||||||
|
editor.execCommand("autocomplete");
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
editor.setCursor({line: 0, ch: 0});
|
editor.setCursor({line: 0, ch: 0});
|
||||||
|
|||||||
@@ -8,16 +8,15 @@ import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
|||||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
import com.stardust.scriptdroid.network.api.ConfigApi;
|
import com.stardust.scriptdroid.network.api.ConfigApi;
|
||||||
import com.stardust.scriptdroid.network.entity.config.Config;
|
|
||||||
import com.stardust.scriptdroid.network.util.WebkitCookieManagerProxy;
|
import com.stardust.scriptdroid.network.util.WebkitCookieManagerProxy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.Scheduler;
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import retrofit2.Response;
|
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
import retrofit2.converter.gson.GsonConverterFactory;
|
||||||
|
|
||||||
@@ -30,8 +29,7 @@ public class NodeBB {
|
|||||||
public static final String BASE_URL = "http://www.autojs.org/";
|
public static final String BASE_URL = "http://www.autojs.org/";
|
||||||
private static final NodeBB sInstance = new NodeBB();
|
private static final NodeBB sInstance = new NodeBB();
|
||||||
private static final String LOG_TAG = "NodeBB";
|
private static final String LOG_TAG = "NodeBB";
|
||||||
private Config mConfig;
|
private Map<String, String> mXCsrfToken;
|
||||||
|
|
||||||
|
|
||||||
private Retrofit mRetrofit;
|
private Retrofit mRetrofit;
|
||||||
|
|
||||||
@@ -56,18 +54,17 @@ public class NodeBB {
|
|||||||
return mRetrofit;
|
return mRetrofit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<Config> getConfig() {
|
|
||||||
if (mConfig == null) {
|
|
||||||
return mRetrofit.create(ConfigApi.class)
|
|
||||||
.getConfig()
|
|
||||||
.doOnNext(config -> mConfig = config);
|
|
||||||
}
|
|
||||||
return Observable.just(mConfig);
|
|
||||||
|
|
||||||
|
public Observable<Map<String, String>> getXCsrfToken() {
|
||||||
|
if (mXCsrfToken != null)
|
||||||
|
return Observable.just(mXCsrfToken);
|
||||||
|
return mRetrofit.create(ConfigApi.class)
|
||||||
|
.getConfig()
|
||||||
|
.map(config -> mXCsrfToken = Collections.singletonMap("x-csrf-token", config.getCsrfToken()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateConfig() {
|
public void invalidateXCsrfToken() {
|
||||||
mConfig = null;
|
mXCsrfToken = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getErrorMessage(Throwable e, Context context, String defaultMsg) {
|
public static String getErrorMessage(Throwable e, Context context, String defaultMsg) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.disposables.Disposable;
|
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import io.reactivex.subjects.PublishSubject;
|
import io.reactivex.subjects.PublishSubject;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
@@ -37,10 +36,12 @@ public class UserService {
|
|||||||
|
|
||||||
private static final UserService sInstance = new UserService();
|
private static final UserService sInstance = new UserService();
|
||||||
private final Retrofit mRetrofit;
|
private final Retrofit mRetrofit;
|
||||||
|
private UserApi mUserApi;
|
||||||
private volatile User mUser;
|
private volatile User mUser;
|
||||||
|
|
||||||
UserService() {
|
UserService() {
|
||||||
mRetrofit = NodeBB.getInstance().getRetrofit();
|
mRetrofit = NodeBB.getInstance().getRetrofit();
|
||||||
|
mUserApi = mRetrofit.create(UserApi.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserService getInstance() {
|
public static UserService getInstance() {
|
||||||
@@ -49,14 +50,12 @@ public class UserService {
|
|||||||
|
|
||||||
public Observable<ResponseBody> login(String userName, final String password) {
|
public Observable<ResponseBody> login(String userName, final String password) {
|
||||||
return NodeBB.getInstance()
|
return NodeBB.getInstance()
|
||||||
.getConfig()
|
.getXCsrfToken()
|
||||||
.flatMap(config ->
|
.flatMap(token ->
|
||||||
mRetrofit.create(UserApi.class)
|
mUserApi.login(token, userName, password)
|
||||||
.login(Collections.singletonMap("x-csrf-token", config.getCsrfToken()),
|
|
||||||
userName, password)
|
|
||||||
.doOnError(error -> {
|
.doOnError(error -> {
|
||||||
if (error instanceof HttpException && ((HttpException) error).code() == 403) {
|
if (error instanceof HttpException && ((HttpException) error).code() == 403) {
|
||||||
NodeBB.getInstance().invalidateConfig();
|
NodeBB.getInstance().invalidateXCsrfToken();
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.doOnComplete(this::refreshOnlineStatus);
|
.doOnComplete(this::refreshOnlineStatus);
|
||||||
@@ -66,10 +65,8 @@ public class UserService {
|
|||||||
|
|
||||||
public Observable<ResponseBody> register(String email, String userName, String password) {
|
public Observable<ResponseBody> register(String email, String userName, String password) {
|
||||||
return NodeBB.getInstance()
|
return NodeBB.getInstance()
|
||||||
.getConfig()
|
.getXCsrfToken()
|
||||||
.flatMap(config -> mRetrofit.create(UserApi.class)
|
.flatMap(token -> mUserApi.register(token, email, userName, password, password));
|
||||||
.register(Collections.singletonMap("x-csrf-token", config.getCsrfToken()),
|
|
||||||
email, userName, password, password));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnline() {
|
public boolean isOnline() {
|
||||||
@@ -81,7 +78,7 @@ public class UserService {
|
|||||||
mUser = user;
|
mUser = user;
|
||||||
if (!Objects.equals(old, mUser)) {
|
if (!Objects.equals(old, mUser)) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
NodeBB.getInstance().invalidateConfig();
|
NodeBB.getInstance().invalidateXCsrfToken();
|
||||||
}
|
}
|
||||||
EventBus.getDefault().post(new LoginStateChange(user != null));
|
EventBus.getDefault().post(new LoginStateChange(user != null));
|
||||||
}
|
}
|
||||||
@@ -106,11 +103,8 @@ public class UserService {
|
|||||||
|
|
||||||
public Observable<ResponseBody> logout() {
|
public Observable<ResponseBody> logout() {
|
||||||
return NodeBB.getInstance()
|
return NodeBB.getInstance()
|
||||||
.getConfig()
|
.getXCsrfToken()
|
||||||
.flatMap(config ->
|
.flatMap(mUserApi::logout)
|
||||||
mRetrofit.create(UserApi.class)
|
|
||||||
.logout(Collections.singletonMap("x-csrf-token", config.getCsrfToken()))
|
|
||||||
)
|
|
||||||
.doOnError(Throwable::printStackTrace)
|
.doOnError(Throwable::printStackTrace)
|
||||||
.doOnComplete(this::refreshOnlineStatus);
|
.doOnComplete(this::refreshOnlineStatus);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
@Override
|
@Override
|
||||||
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
||||||
InputConnection connection = super.onCreateInputConnection(outAttrs);
|
InputConnection connection = super.onCreateInputConnection(outAttrs);
|
||||||
return connection == null ? null : new MyInputConnection(connection);
|
return connection;// == null ? null : new MyInputConnection(connection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
setupWebSettings();
|
setupWebSettings();
|
||||||
@@ -446,12 +446,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
if (mCallback == null) {
|
if (mCallback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mWebView.post(new Runnable() {
|
mWebView.post(() -> mCallback.onChange());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mCallback.onChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
@@ -459,12 +454,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
if (mCallback == null) {
|
if (mCallback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mWebView.post(new Runnable() {
|
mWebView.post(() -> mCallback.updateCodeCompletion(fromLine, fromCh, toLine, toCh, list, urls));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mCallback.updateCodeCompletion(fromLine, fromCh, toLine, toCh, list, urls);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -500,12 +490,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
private void showRenamePrompt(String name, String defaultValue, final JsPromptResult result) {
|
private void showRenamePrompt(String name, String defaultValue, final JsPromptResult result) {
|
||||||
new ThemeColorMaterialDialogBuilder(getContext())
|
new ThemeColorMaterialDialogBuilder(getContext())
|
||||||
.title(getResources().getString(R.string.text_rename) + name)
|
.title(getResources().getString(R.string.text_rename) + name)
|
||||||
.input("", defaultValue, new MaterialDialog.InputCallback() {
|
.input("", defaultValue, (dialog, input) -> result.confirm(input.toString()))
|
||||||
@Override
|
|
||||||
public void onInput(@android.support.annotation.NonNull MaterialDialog dialog, CharSequence input) {
|
|
||||||
result.confirm(input.toString());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user