Merge remote-tracking branch 'origin/2.3' into 2.3
# Conflicts: # .idea/modules.xml
This commit is contained in:
@ -10,7 +10,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@ -23,18 +22,16 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadService;
|
||||
import com.gh.gamecenter.db.info.FilterInfo;
|
||||
import com.gh.gamecenter.entity.PlatformEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.xiaomi.mipush.sdk.MiPushMessage;
|
||||
import com.xiaomi.mipush.sdk.PushMessageHelper;
|
||||
@ -42,17 +39,10 @@ import com.xiaomi.mipush.sdk.PushMessageHelper;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
@ -60,16 +50,11 @@ import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* 引导页面
|
||||
*
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private String from;
|
||||
|
||||
private long start;
|
||||
|
||||
private boolean isFirst;
|
||||
@ -100,14 +85,12 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
isFirst = true;
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true);
|
||||
|
||||
from = getIntent().getStringExtra("from");
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true);
|
||||
|
||||
if (isNewFirstLaunch || sp.getInt("actionbar_height", 0) != 0) {
|
||||
setTheme(R.style.AppTheme_Guide);
|
||||
setTheme(R.style.AppGuideTheme);
|
||||
} else {
|
||||
setTheme(R.style.AppTheme_Fullscreen);
|
||||
setTheme(R.style.AppFullScreenTheme);
|
||||
// 自定义ActionBar
|
||||
ActionBar mActionBar = getActionBar();
|
||||
if (mActionBar != null) {
|
||||
@ -122,20 +105,14 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
if (isNewFirstLaunch) {
|
||||
setContentView(R.layout.activity_splash_intro);
|
||||
ViewPager splash_viewPager = (ViewPager) findViewById(R.id.splash_viewPager);
|
||||
splash_viewPager.setAdapter(new ViewPagerAdapter());
|
||||
ViewPager guideLayout = (ViewPager) findViewById(R.id.splash_intro_vp_guide);
|
||||
guideLayout.setAdapter(new GuidePagerAdapter());
|
||||
} else {
|
||||
setContentView(R.layout.activity_splash_normal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Utils.log("flags---------------onNewIntent");
|
||||
}
|
||||
|
||||
private class ViewPagerAdapter extends PagerAdapter {
|
||||
private class GuidePagerAdapter extends PagerAdapter {
|
||||
|
||||
private int[] pics = { R.drawable.splash_01 };
|
||||
|
||||
@ -147,23 +124,28 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
if (position == pics.length - 1) {
|
||||
View view = View.inflate(SplashScreenActivity.this, R.layout.splash_viewpage_item, null);
|
||||
TextView textView = (TextView) view.findViewById(R.id.splash_viewPager_item_btn);
|
||||
View view = View.inflate(container.getContext(), R.layout.splash_guide_item, null);
|
||||
|
||||
ImageView ivImage = (ImageView) view.findViewById(R.id.splsh_guide_iv_image);
|
||||
ivImage.setImageResource(pics[position]);
|
||||
|
||||
TextView tvSkip = (TextView) view.findViewById(R.id.splsh_guide_tv_skip);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) textView.getLayoutParams();
|
||||
RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) tvSkip.getLayoutParams();
|
||||
rparams.height = outMetrics.heightPixels / 4;
|
||||
textView.setLayoutParams(rparams);
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
tvSkip.setLayoutParams(rparams);
|
||||
tvSkip.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
launch();
|
||||
}
|
||||
});
|
||||
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else {
|
||||
ImageView imageView = new ImageView(SplashScreenActivity.this);
|
||||
ImageView imageView = new ImageView(container.getContext());
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
imageView.setImageResource(pics[position]);
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
@ -204,38 +186,28 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
isFirst = false;
|
||||
|
||||
// 第一次启动,把package.txt文件内容加载进数据库
|
||||
FilterManager filterManager = null;
|
||||
if (!sp.getBoolean("isLoadFilter", false)) {
|
||||
try {
|
||||
List<FilterInfo> list = new ArrayList<>();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(getAssets().open("package.txt")));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
list.add(new FilterInfo(line));
|
||||
}
|
||||
reader.close();
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
filterManager.addAllFilter(list);
|
||||
sp.edit().putBoolean("isLoadFilter", true).apply();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
filterManager = new FilterManager(getApplicationContext());
|
||||
filterManager.loadFilter();
|
||||
}
|
||||
|
||||
checkGhFile();
|
||||
// 检查是否存在旧版本光环助手包
|
||||
checkOldGhFile();
|
||||
|
||||
/*
|
||||
* 更新过滤表,获取自动刷新的cd,获取版本对应表
|
||||
*/
|
||||
// 更新过滤表,获取自动刷新的cd,获取版本对应表
|
||||
String time = sp.getString("filter_time", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
String today = format.format(new Date());
|
||||
if (!today.equals(time)) {
|
||||
FilterManager manager = new FilterManager(getApplicationContext());
|
||||
manager.getFilterFromServer(today);
|
||||
// 获取过滤包
|
||||
if (filterManager == null) {
|
||||
filterManager = new FilterManager(getApplicationContext());
|
||||
}
|
||||
filterManager.getFilterFromServer(today);
|
||||
|
||||
// 获取版本代码、名称
|
||||
getPlatform();
|
||||
PlatformUtils.getInstance(getApplicationContext()).getPlatform();
|
||||
}
|
||||
|
||||
// 获取下载按钮状态、开启or关闭
|
||||
@ -243,14 +215,13 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
getDownloadStatus();
|
||||
}
|
||||
|
||||
// 获取界面设置
|
||||
getUISetting();
|
||||
|
||||
// 更新本地时间
|
||||
TokenUtils.getTime(this);
|
||||
|
||||
/*
|
||||
* 上传数据
|
||||
*/
|
||||
// 上传数据
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
// 解决助手奔溃后导致的下载状态保留问题
|
||||
@ -283,9 +254,27 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取界面设置
|
||||
*/
|
||||
// 检查下载文件夹下是否有旧版本的光环助手的包,有则删除
|
||||
private void checkOldGhFile() {
|
||||
File folder = new File(FileUtils.getDownloadDir(this) + File.separator);
|
||||
if (folder.isDirectory()) {
|
||||
for (File file : folder.listFiles()) {
|
||||
if (!file.isDirectory() && file.getName().startsWith("光环助手V")) {
|
||||
String name = file.getName();
|
||||
int index = name.indexOf("_");
|
||||
if (index != -1) {
|
||||
float version = Float.valueOf(name.substring(name.indexOf("V") + 1, index));
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersionName(getApplicationContext()));
|
||||
if (version <= currentVersion && file.delete()) {
|
||||
Utils.log(file.getName() + " file delete success.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取界面设置
|
||||
private void getUISetting() {
|
||||
RetrofitManager.getApi().getUISetting()
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -311,13 +300,10 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取下载按钮显示状态
|
||||
*/
|
||||
// 获取下载按钮显示状态
|
||||
private void getDownloadStatus() {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this,
|
||||
getPackageName(), "TD_CHANNEL_ID");
|
||||
RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersion(getApplicationContext()), TD_CHANNEL_ID)
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
|
||||
RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersionName(getApplicationContext()), TD_CHANNEL_ID)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@ -343,103 +329,18 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 检查下载文件夹下是否有旧版本的光环助手的包,有则删除
|
||||
*/
|
||||
private void checkGhFile() {
|
||||
File folder = new File(FileUtils.getDownloadDir(this) + File.separator);
|
||||
if (folder.isDirectory()) {
|
||||
for (File file : folder.listFiles()) {
|
||||
if (!file.isDirectory() && file.getName().startsWith("光环助手V")) {
|
||||
String name = file.getName();
|
||||
int index = name.indexOf("_");
|
||||
if (index != -1) {
|
||||
float version = Float.valueOf(name.substring(
|
||||
name.indexOf("V") + 1, index));
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext()));
|
||||
if (version <= currentVersion) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getPlatform() {
|
||||
RetrofitManager.getApi().getGamePlatform()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<PlatformEntity>>(){
|
||||
@Override
|
||||
public void onResponse(List<PlatformEntity> response) {
|
||||
Set<String> platformSet = new HashSet<>();
|
||||
for (PlatformEntity platformEntity : response) {
|
||||
platformSet.add(platformEntity.toString());
|
||||
}
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("gh_platform", Context.MODE_PRIVATE);
|
||||
sharedPreferences.edit().putStringSet("platform", platformSet).apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 跳转到主界面
|
||||
private void launch() {
|
||||
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if (bundle != null && bundle.getString("to") != null) {
|
||||
intentControl(bundle, intent);
|
||||
} else {
|
||||
intent.putExtra("from", from);
|
||||
if (!TextUtils.isEmpty(from)) {
|
||||
if ("plugin".equals(from)) {
|
||||
intent.putExtra("packageName", getIntent().getStringExtra("packageName"));
|
||||
} else if ("mipush_news".equals(from)) {
|
||||
intent.putExtra("newsId", getIntent().getStringExtra("newsId"));
|
||||
} else if ("mipush_plugin".equals(from)) {
|
||||
intent.putExtra("data", getIntent().getStringExtra("data"));
|
||||
} else if ("plugin_install".equals(from)) {
|
||||
intent.putExtra("path", getIntent().getStringExtra("path"));
|
||||
}
|
||||
}
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (intent.getBundleExtra("data") != null) {
|
||||
bundle = intent.getBundleExtra("data");
|
||||
}
|
||||
intent.putExtra("data", bundle);
|
||||
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void intentControl(Bundle bundle, Intent intent) {
|
||||
String to = bundle.getString("to");
|
||||
if ("NewsActivity".equals(to) || "NewsDetailActivity".equals(to)) {
|
||||
intent.putExtra("newsId", bundle.getString("newsId"));
|
||||
intent.putExtra("entrance", bundle.getString("entrance"));
|
||||
} else if("DownloadManagerActivity".equals(to)) {
|
||||
intent.putExtra("packageName", bundle.getString("packageName"));
|
||||
} else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) {
|
||||
intent.putExtra("gameId", bundle.getString("gameId"));
|
||||
intent.putExtra("entrance", bundle.getString("entrance"));
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
intent.putExtra("id", bundle.getString("id"));
|
||||
intent.putExtra("name", bundle.getString("name"));
|
||||
intent.putExtra("order", bundle.getBoolean("order"));
|
||||
} else if ("ViewImageActivity".equals(to)) {
|
||||
intent.putExtra("urls", bundle.getStringArrayList("urls"));
|
||||
intent.putExtra("current", bundle.getInt("current",0));
|
||||
intent.putExtra("ScaleType", bundle.getString("ScaleType"));
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
intent.putExtra("id", bundle.getString("id"));
|
||||
intent.putExtra("name", bundle.getString("name"));
|
||||
} else if ("SuggestionActivity".equals(to)) {
|
||||
intent.putExtra("content", bundle.getString("content"));
|
||||
}
|
||||
if ("NewsActivity".equals(to)) {
|
||||
intent.putExtra("to", "NewsDetailActivity");
|
||||
} else if ("GameDetailsActivity".equals(to)) {
|
||||
intent.putExtra("to", "GameDetailActivity");
|
||||
} else {
|
||||
intent.putExtra("to", to);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user