Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.yan-code:CoderHelper:1.2.3'
}
在Aplication页面添加初始化代码
/**
* 将第一次启动的api切换为之前设置的环境变量,若之前没设置则按当前的环境运行
*/
HttpConstant.val = CoderHelper.Companion.get().getMCurrentApi() == -1? HttpConstant.val : CoderHelper.Companion.get().getMCurrentApi();
CoderHelper.Companion.get().setMCurrentApi(HttpConstant.val);
CoderHelper.Companion.get().setMApiCallBack(new ApiSwitchCallBack() {
@Override
public void ApiSwitchListener(int position, @NotNull AppApiSaveCallBack appApiSaveCallBack) {
//环境切换逻辑
switch (position){
case 0:
// dev
HttpConstant.val=HttpConstant.Envir.dev;
break;
case 1:
// test
HttpConstant.val=HttpConstant.Envir.test;
break;
case 2:
// test2
HttpConstant.val=HttpConstant.Envir.test_2;
break;
case 3:
// test3
HttpConstant.val = HttpConstant.Envir.test_3;
break;
case 4:
// pre
HttpConstant.val=HttpConstant.Envir.pre;
break;
case 5:
// online
HttpConstant.val=HttpConstant.Envir.online;
break;
}
//保存切换的环境变量
appApiSaveCallBack.AppApiSaveListener(HttpConstant.val);
}
});
CoderHelper.Companion.get().setMTokenCallBack(new TokenSaveCallBack() {
@Override
public void SaveToken(@NotNull String token, @NotNull AppApiSaveCallBack appApiSaveCallBack) {
UserUtil.instance().setWxToken(token);
HttpConstant.val = HttpConstant.Envir.online;
appApiSaveCallBack.AppApiSaveListener(HttpConstant.val);
}
});
if (HttpConstant.val == HttpConstant.Envir.online) {
return;
}
FloatingView.get().add();
FloatingView.get().listener(new MagnetViewListener() {
@Override
public void onRemove(FloatingMagnetView magnetView) {
}
@Override
public void onClick(FloatingMagnetView magnetView) {
FunctionActivity.Companion.startActivity(ChangTouApplication.this);
}
});
在BaseActivity添加
@Override
protected void onResume() {
super.onResume();
FloatingView.get().attach(this);
}
@Override
protected void onPause() {
super.onPause();
FloatingView.get().detach(this);
}
需在root project下的build.gradle中支持kotlin
buildscript {
ext.kotlin_version = '1.3.50'
...
dependencies{
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}