feat:补充启动时更新ticket逻辑
This commit is contained in:
@@ -484,7 +484,6 @@ public class App extends BaseApp {
|
||||
ChannelModel.get();
|
||||
MarketVerifyModel.get();
|
||||
GiftModel.get();
|
||||
GiftModel.get().tryLoadGiftList();
|
||||
// 模厅
|
||||
HallDataManager.get().application();
|
||||
//全局处理
|
||||
|
@@ -15,7 +15,12 @@ import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.chwl.app.ui.login.LoginPasswordActivity;
|
||||
import com.chwl.core.auth.AuthModel;
|
||||
import com.chwl.core.bean.response.result.TicketResult;
|
||||
import com.chwl.core.gift.GiftModel;
|
||||
import com.chwl.library.language.LanguageHelper;
|
||||
import com.chwl.library.utils.SingleToastUtil;
|
||||
import com.example.lib_utils.log.LogUtil;
|
||||
import com.netease.nim.uikit.StatusBarUtil;
|
||||
import com.netease.nim.uikit.support.glide.GlideApp;
|
||||
import com.chwl.app.MainActivity;
|
||||
@@ -32,6 +37,10 @@ import com.chwl.core.utils.OaidUtil;
|
||||
import com.chwl.core.utils.SharedPreferenceUtils;
|
||||
import com.chwl.library.common.util.DeviceUtil;
|
||||
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* @author xiaoyu
|
||||
* @date 2017/12/30
|
||||
@@ -43,8 +52,15 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis
|
||||
private ActivitySplashBinding mBinding;
|
||||
private SplashComponent mLocalSplashVo;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
// ticket状态 -1:加载失败、0:加载中、1:加载成功
|
||||
private int ticketState = 0;
|
||||
|
||||
private volatile boolean needJump = false;
|
||||
|
||||
private Runnable jumpRunnable;
|
||||
|
||||
public static void start(Context context) {
|
||||
Intent starter = new Intent(context, SplashActivity.class);
|
||||
context.startActivity(starter);
|
||||
@@ -72,9 +88,10 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis
|
||||
// 从堆栈恢复,不再重复解析之前的intent
|
||||
setIntent(new Intent());
|
||||
}
|
||||
initiate();
|
||||
StatusBarUtil.transparencyBar(this);
|
||||
StatusBarUtil.StatusBarLightMode(this);
|
||||
initTicket();
|
||||
initiate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,8 +162,12 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis
|
||||
}
|
||||
|
||||
public void jumpActivity(Intent intent) {
|
||||
AccountInfo currentAccountInfo = DemoCache.readCurrentAccountInfo();
|
||||
if (currentAccountInfo == null || TextUtils.isEmpty(currentAccountInfo.getAccess_token())) {
|
||||
jumpRunnable = () -> jumpActivityImpl(intent);
|
||||
next();
|
||||
}
|
||||
|
||||
public void jumpActivityImpl(Intent intent) {
|
||||
if (!AuthModel.get().isLogin()) {
|
||||
NimMiddleActivity.openCommunity = false;
|
||||
LoginPasswordActivity.start(this);
|
||||
finish();
|
||||
@@ -190,4 +211,53 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis
|
||||
|
||||
}
|
||||
|
||||
private void initTicket() {
|
||||
ticketState = 0;
|
||||
if (!AuthModel.get().isLogin()) {
|
||||
ticketState = -1;
|
||||
next();
|
||||
return;
|
||||
}
|
||||
AuthModel.get().refreshTicket().subscribe(new SingleObserver<TicketResult>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
disposable.add(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(TicketResult ticketResult) {
|
||||
LogUtil.d("SplashActivity", "initTicket onSuccess", false);
|
||||
onTicketSuccess();
|
||||
ticketState = 1;
|
||||
next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
LogUtil.d("SplashActivity", "initTicket throwable:" + throwable.getMessage(), false);
|
||||
SingleToastUtil.showToast(throwable.getMessage());
|
||||
AuthModel.get().reset();
|
||||
ticketState = -1;
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onTicketSuccess() {
|
||||
GiftModel.get().tryLoadGiftList();
|
||||
}
|
||||
|
||||
private void next() {
|
||||
if (ticketState != 0 && jumpRunnable != null) {
|
||||
jumpRunnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (disposable != null && !disposable.isDisposed()) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -442,6 +442,19 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
|
||||
}
|
||||
|
||||
public Single<TicketResult> refreshTicket() {
|
||||
return requestTicket()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(ticketResult -> {
|
||||
if (ticketResult.isSuccess()) {
|
||||
ticketInfo = ticketResult.getData();
|
||||
DemoCache.saveTicketInfo(ticketInfo);
|
||||
}
|
||||
return ticketResult;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取tick
|
||||
*
|
||||
|
Reference in New Issue
Block a user