|
@@ -13,6 +13,7 @@ import android.support.annotation.Nullable;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.ContextCompat;
|
|
import android.support.v4.content.ContextCompat;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
@@ -22,8 +23,6 @@ import com.bumptech.glide.Glide;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
import com.sheep.gamegroup.greendao.DDProviderHelper;
|
|
import com.sheep.gamegroup.greendao.DDProviderHelper;
|
|
|
import com.sheep.gamegroup.greendao.download.SheepAd;
|
|
import com.sheep.gamegroup.greendao.download.SheepAd;
|
|
|
-import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
-import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
|
|
import com.sheep.gamegroup.module.skin.util.SkinUtil;
|
|
import com.sheep.gamegroup.module.skin.util.SkinUtil;
|
|
|
import com.sheep.gamegroup.util.ApiJSONUtil;
|
|
import com.sheep.gamegroup.util.ApiJSONUtil;
|
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
@@ -32,16 +31,15 @@ import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.RxjavaCountDownTimer;
|
|
import com.sheep.gamegroup.util.RxjavaCountDownTimer;
|
|
|
import com.sheep.gamegroup.util.SysAppUtil;
|
|
import com.sheep.gamegroup.util.SysAppUtil;
|
|
|
-import com.sheep.gamegroup.util.TestUtil;
|
|
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.view.activity.helper.AdHelper;
|
|
import com.sheep.gamegroup.view.activity.helper.AdHelper;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
|
|
+import com.tencent.klevin.KleinManager;
|
|
|
|
|
+import com.tencent.klevin.base.callback.KleinResponseCallback;
|
|
|
|
|
|
|
|
-import java.io.InputStream;
|
|
|
|
|
-import java.net.URL;
|
|
|
|
|
-import java.net.URLConnection;
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -50,6 +48,10 @@ import butterknife.OnClick;
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
|
|
|
|
|
+import static com.tencent.klevin.base.okhttp.ErrorCode.KLSplashAdEvent_AdPlayCompletion;
|
|
|
|
|
+import static com.tencent.klevin.base.okhttp.ErrorCode.KLSplashAdEvent_AdShowFinish;
|
|
|
|
|
+import static com.tencent.klevin.base.okhttp.ErrorCode.KLSplashAdEvent_AdSkip;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Created by ljy on 2018/3/9.
|
|
* Created by ljy on 2018/3/9.
|
|
|
*/
|
|
*/
|
|
@@ -106,43 +108,92 @@ public class SplashAct extends BaseActivity {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void handleResult(boolean isNewSmallSheep) {
|
|
|
|
|
+ DataUtil.getInstance().setIsNewSmallSheep(isNewSmallSheep);
|
|
|
|
|
+ if (SysAppUtil.isNewSmallSheep()) {//新版本只显示引导页面,不展示弹窗和开屏广告
|
|
|
|
|
+ initSelfAdvertisement(false);//只更新,不加载,下次加载上次的数据
|
|
|
|
|
+ sendHandlerMessages(2000);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ad = DDProviderHelper.getInstance().getSheepAd(SheepAd.FORM_SPASH);
|
|
|
|
|
+ if (ad != null) {
|
|
|
|
|
+ //有自己的广告,先加载自己的广告,再拉取一次广告并保存
|
|
|
|
|
+ loadAdvertising();
|
|
|
|
|
+ initSelfAdvertisement(false);//只更新,不加载,下次加载上次的数据
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //没有自己的广告,展示SDK的广告,并拉取一次广告并保存
|
|
|
|
|
+ initSdkAdvertising();
|
|
|
|
|
+ initSelfAdvertisement(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void init() {
|
|
private void init() {
|
|
|
if (SysAppUtil.isNotSupport(this)) return;
|
|
if (SysAppUtil.isNotSupport(this)) return;
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().checkUserFirst()
|
|
SheepApp.getInstance().getNetComponent().getApiService().checkUserFirst()
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
|
|
+ .doOnNext(baseMessage -> {
|
|
|
|
|
+ boolean isNewSmallSheep = baseMessage.getData(Boolean.class);
|
|
|
|
|
+ handleResult(isNewSmallSheep);
|
|
|
|
|
+ })
|
|
|
|
|
+ .doOnError(throwable -> {
|
|
|
|
|
+ //访问出错时,认为不是新设备
|
|
|
|
|
+ handleResult(false);
|
|
|
|
|
+ }).subscribe();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 加载SDK的广告
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initSdkAdvertising() {
|
|
|
|
|
+ //游可盈
|
|
|
|
|
+ int posId; //开屏广告ID
|
|
|
|
|
+ if (BuildConfig.FLAVOR.equals("sheep")) {
|
|
|
|
|
+ posId = 30112;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //posId = 30029;
|
|
|
|
|
+ posId = 30112;
|
|
|
|
|
+ }
|
|
|
|
|
+ String data = "{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":1}]}";
|
|
|
|
|
+ //"{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":1}]}";
|
|
|
|
|
+ KleinManager.getInstance().prepareAD(
|
|
|
|
|
+ getApplicationContext(),
|
|
|
|
|
+ data,
|
|
|
|
|
+ 5000,
|
|
|
|
|
+ true,
|
|
|
|
|
+ new KleinResponseCallback() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
- boolean isNewSmallSheep = baseMessage.getData(Boolean.class);
|
|
|
|
|
- handleResult(isNewSmallSheep);
|
|
|
|
|
|
|
+ public void onSuccess(int i) {
|
|
|
|
|
+ if (BuildConfig.DEBUG)
|
|
|
|
|
+ Log.d("!!!!!Success", String.valueOf(i));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
|
|
- //访问出错时,认为不是新设备
|
|
|
|
|
- handleResult(false);
|
|
|
|
|
|
|
+ public void onFail(int i) {
|
|
|
|
|
+ if (BuildConfig.DEBUG)
|
|
|
|
|
+ Log.d("!!!!!Fail", String.valueOf(i));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void handleResult(boolean isNewSmallSheep) {
|
|
|
|
|
- DataUtil.getInstance().setIsNewSmallSheep(isNewSmallSheep);
|
|
|
|
|
- if (SysAppUtil.isNewSmallSheep()) {//新版本只显示引导页面,不展示弹窗和开屏广告
|
|
|
|
|
- initAdvertisement(false);//只更新,不加载,下次加载上次的数据
|
|
|
|
|
- sendHandlerMessages(2000);
|
|
|
|
|
- } else {
|
|
|
|
|
- ad = DDProviderHelper.getInstance().getSheepAd(SheepAd.FORM_SPASH);
|
|
|
|
|
- if (ad != null) {
|
|
|
|
|
- loadAdvertising();
|
|
|
|
|
- initAdvertisement(false);//只更新,不加载,下次加载上次的数据
|
|
|
|
|
- } else {
|
|
|
|
|
- initAdvertisement(true);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onEvent(int i) {
|
|
|
|
|
+ if (BuildConfig.DEBUG)
|
|
|
|
|
+ Log.d("!!!!!Event", String.valueOf(i));
|
|
|
|
|
+ switch (i) {
|
|
|
|
|
+ case KLSplashAdEvent_AdPlayCompletion:
|
|
|
|
|
+ case KLSplashAdEvent_AdShowFinish:
|
|
|
|
|
+ case KLSplashAdEvent_AdSkip:
|
|
|
|
|
+ sendHandlerMessages(0);
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void initAdvertisement(boolean isLoad) {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 加载自己的广告
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initSelfAdvertisement(boolean isLoad) {
|
|
|
CommonUtil.getInstance().refreshAds((ret, list) -> {
|
|
CommonUtil.getInstance().refreshAds((ret, list) -> {
|
|
|
if (ret) {
|
|
if (ret) {
|
|
|
if (isLoad) {
|
|
if (isLoad) {
|
|
@@ -330,6 +381,7 @@ public class SplashAct extends BaseActivity {
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
|
|
|| ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|| ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
|
|
+ permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
|
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
|
|
result = false;
|
|
result = false;
|
|
|
}
|
|
}
|