优化代码
This commit is contained in:
@@ -31,55 +31,4 @@ public class FcmCheckUtil {
|
|||||||
&& googleApi.getApkVersion(context) >= MIN_GOOGLE_PLAY_SERVICES_VERSION;
|
&& googleApi.getApkVersion(context) >= MIN_GOOGLE_PLAY_SERVICES_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取详细的FCM支持状态(用于调试/用户提示)
|
|
||||||
* @param context 上下文
|
|
||||||
* @return 状态描述
|
|
||||||
*/
|
|
||||||
public static String getFcmSupportStatus(Context context) {
|
|
||||||
GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance();
|
|
||||||
int resultCode = googleApi.isGooglePlayServicesAvailable(context);
|
|
||||||
|
|
||||||
switch (resultCode) {
|
|
||||||
case ConnectionResult.SUCCESS:
|
|
||||||
if (googleApi.getApkVersion(context) >= MIN_GOOGLE_PLAY_SERVICES_VERSION) {
|
|
||||||
return "设备支持FCM(Google Play服务可用且版本达标)";
|
|
||||||
} else {
|
|
||||||
return "Google Play服务版本过低,不支持FCM(需更新)";
|
|
||||||
}
|
|
||||||
case ConnectionResult.SERVICE_MISSING:
|
|
||||||
return "未安装Google Play服务,不支持FCM";
|
|
||||||
case ConnectionResult.SERVICE_DISABLED:
|
|
||||||
return "Google Play服务已禁用,不支持FCM";
|
|
||||||
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
|
|
||||||
return "Google Play服务需要更新,暂不支持FCM";
|
|
||||||
default:
|
|
||||||
return "设备不支持FCM(错误码:" + resultCode + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取详细的FCM支持状态(用于调试/用户提示)
|
|
||||||
* @param context 上下文
|
|
||||||
* @return 状态描述
|
|
||||||
*/
|
|
||||||
public static boolean getFcmSupport(Context context) {
|
|
||||||
LogUtils.i("支持FCM:"+getFcmSupportStatus(context));
|
|
||||||
GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance();
|
|
||||||
int resultCode = googleApi.isGooglePlayServicesAvailable(context);
|
|
||||||
|
|
||||||
switch (resultCode) {
|
|
||||||
case ConnectionResult.SUCCESS:
|
|
||||||
return true;
|
|
||||||
case ConnectionResult.SERVICE_MISSING:
|
|
||||||
return false;
|
|
||||||
case ConnectionResult.SERVICE_DISABLED:
|
|
||||||
return false;
|
|
||||||
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
|
|
||||||
setTotalTongJi(); //每日活跃统计
|
setTotalTongJi(); //每日活跃统计
|
||||||
LogUtils.i("版本号1:"+getVersion());
|
// LogUtils.i("版本号1:"+getVersion());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,6 +401,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
ActionConfirmDialog actionDialog;
|
ActionConfirmDialog actionDialog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查请求通知权限
|
||||||
|
*/
|
||||||
public void checkNotify() {
|
public void checkNotify() {
|
||||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
@@ -419,6 +422,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toCancel() {
|
public void toCancel() {
|
||||||
|
//通知请求为强制要求时候 拒绝直接app 不让用
|
||||||
if (notifyApply == 1) {
|
if (notifyApply == 1) {
|
||||||
MainActivity.this.finish();
|
MainActivity.this.finish();
|
||||||
}
|
}
|
||||||
@@ -598,91 +602,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
DataInfo dataInfo = o.data;
|
DataInfo dataInfo = o.data;
|
||||||
if (dataInfo != null) {
|
if (dataInfo != null) {
|
||||||
if (dataInfo.getIsUse() == 0) {
|
toConfigSet(dataInfo);
|
||||||
MainActivity.this.finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(dataInfo.getUrl())) {
|
|
||||||
saveString(MainActivity.this, "base_url", dataInfo.getUrl());
|
|
||||||
toLoadWebUrl(dataInfo);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
String link = dataInfo.getLinkConfig();
|
|
||||||
if (!TextUtils.isEmpty(link)) {
|
|
||||||
try {
|
|
||||||
linkconfiglist = GsonUtils.getListFromJSON(link, LinkConfigInfo.class);
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(dataInfo.getVersionCode())) {
|
|
||||||
|
|
||||||
if (Integer.parseInt(dataInfo.getVersionCode()) > getVersion()) {
|
|
||||||
ActionConfirmDialog actionDialog = new ActionConfirmDialog(MainActivity.this,
|
|
||||||
getString(R.string.banbengengxin_txt), getString(R.string.xiacigengxin_txt),
|
|
||||||
getString(R.string.lijigengxin_txt));
|
|
||||||
actionDialog.setOnToActionListener(new ActionConfirmDialog.OnToActionListener() {
|
|
||||||
@Override
|
|
||||||
public void toSumbit() {
|
|
||||||
checkUpdate(dataInfo.getApkUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toCancel() {
|
|
||||||
if (dataInfo.getForceUpdate() == 1) {
|
|
||||||
MainActivity.this.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
actionDialog.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contactApply = dataInfo.getContactApplyMode();
|
|
||||||
notifyApply = dataInfo.getNoticeApplyMode();
|
|
||||||
|
|
||||||
if (notifyApply == 0 || notifyApply == 1) {
|
|
||||||
if (FcmCheckUtil.isFcmSupported(MainActivity.this) && FcmCheckUtil.getFcmSupport(MainActivity.this)) {
|
|
||||||
regFcm();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
facebookUrl = dataInfo.getFbUrl().trim();
|
|
||||||
telegramUrl = dataInfo.getTgUrl().trim();
|
|
||||||
whatsappUrl = dataInfo.getWsUrl().trim();
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(facebookUrl)) {
|
|
||||||
if (userId == 217 || userId == 211) {
|
|
||||||
activityMain2Binding.btOtherapp.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
activityMain2Binding.btOtherapp.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
activityMain2Binding.ivFacebook.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(telegramUrl)) {
|
|
||||||
if (userId == 217 || userId == 211) {
|
|
||||||
activityMain2Binding.ivFacebook.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
activityMain2Binding.ivFacebook.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
activityMain2Binding.ivTel.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(whatsappUrl)) {
|
|
||||||
if (userId == 217 || userId == 211) {
|
|
||||||
activityMain2Binding.btOtherapp.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
activityMain2Binding.btOtherapp.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
activityMain2Binding.ivWhatsapp.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
if (userId == 143 || userId == 149) {
|
|
||||||
activityMain2Binding.btOtherapp.setVisibility(View.INVISIBLE);
|
|
||||||
activityMain2Binding.ivFacebook.setVisibility(View.GONE);
|
|
||||||
activityMain2Binding.ivTel.setVisibility(View.GONE);
|
|
||||||
activityMain2Binding.ivWhatsapp.setVisibility(View.GONE);
|
|
||||||
activityMain2Binding.layoutOtherapp.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
url = getString(MainActivity.this, "base_url", url);
|
url = getString(MainActivity.this, "base_url", url);
|
||||||
activityMain2Binding.webview.loadUrl(url);
|
activityMain2Binding.webview.loadUrl(url);
|
||||||
@@ -706,7 +626,111 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toConfigSet(DataInfo dataInfo) {
|
||||||
|
//后台禁用了 直接退出
|
||||||
|
if (dataInfo.getIsUse() == 0) {
|
||||||
|
MainActivity.this.finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//后台配置url不为空 去加载
|
||||||
|
if (!TextUtils.isEmpty(dataInfo.getUrl())) {
|
||||||
|
saveString(MainActivity.this, "base_url", dataInfo.getUrl());
|
||||||
|
toLoadWebUrl(dataInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
//通用外链配置
|
||||||
|
String link = dataInfo.getLinkConfig();
|
||||||
|
if (!TextUtils.isEmpty(link)) {
|
||||||
|
try {
|
||||||
|
linkconfiglist = GsonUtils.getListFromJSON(link, LinkConfigInfo.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showUpApp(dataInfo);
|
||||||
|
|
||||||
|
contactApply = dataInfo.getContactApplyMode();
|
||||||
|
notifyApply = dataInfo.getNoticeApplyMode();
|
||||||
|
|
||||||
|
//通知权限
|
||||||
|
if (notifyApply == 0 || notifyApply == 1) {
|
||||||
|
//检测手机是否支持fcm推送
|
||||||
|
if (FcmCheckUtil.isFcmSupported(MainActivity.this)) {
|
||||||
|
regFcm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
facebookUrl = dataInfo.getFbUrl().trim();
|
||||||
|
telegramUrl = dataInfo.getTgUrl().trim();
|
||||||
|
whatsappUrl = dataInfo.getWsUrl().trim();
|
||||||
|
|
||||||
|
//外链逻辑修改
|
||||||
|
if (!TextUtils.isEmpty(facebookUrl)) {
|
||||||
|
if (userId == 217 || userId == 211) {
|
||||||
|
activityMain2Binding.btOtherapp.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
activityMain2Binding.btOtherapp.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
activityMain2Binding.ivFacebook.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(telegramUrl)) {
|
||||||
|
if (userId == 217 || userId == 211) {
|
||||||
|
activityMain2Binding.ivFacebook.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
activityMain2Binding.ivFacebook.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
activityMain2Binding.ivTel.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(whatsappUrl)) {
|
||||||
|
if (userId == 217 || userId == 211) {
|
||||||
|
activityMain2Binding.btOtherapp.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
activityMain2Binding.btOtherapp.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
activityMain2Binding.ivWhatsapp.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (userId == 143 || userId == 149) {
|
||||||
|
activityMain2Binding.btOtherapp.setVisibility(View.INVISIBLE);
|
||||||
|
activityMain2Binding.ivFacebook.setVisibility(View.GONE);
|
||||||
|
activityMain2Binding.ivTel.setVisibility(View.GONE);
|
||||||
|
activityMain2Binding.ivWhatsapp.setVisibility(View.GONE);
|
||||||
|
activityMain2Binding.layoutOtherapp.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void showUpApp(DataInfo dataInfo) {
|
||||||
|
//判定版本更新
|
||||||
|
if (!TextUtils.isEmpty(dataInfo.getVersionCode())) {
|
||||||
|
|
||||||
|
if (Integer.parseInt(dataInfo.getVersionCode()) > getVersion()) {
|
||||||
|
ActionConfirmDialog actionDialog = new ActionConfirmDialog(MainActivity.this,
|
||||||
|
getString(R.string.banbengengxin_txt), getString(R.string.xiacigengxin_txt),
|
||||||
|
getString(R.string.lijigengxin_txt));
|
||||||
|
actionDialog.setOnToActionListener(new ActionConfirmDialog.OnToActionListener() {
|
||||||
|
@Override
|
||||||
|
public void toSumbit() {
|
||||||
|
checkUpdate(dataInfo.getApkUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toCancel() {
|
||||||
|
if (dataInfo.getForceUpdate() == 1) {
|
||||||
|
MainActivity.this.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
actionDialog.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主链接和备用链接 ping 选择最优线路
|
||||||
|
* @param dataInfo
|
||||||
|
*/
|
||||||
private void toLoadWebUrl(DataInfo dataInfo) {
|
private void toLoadWebUrl(DataInfo dataInfo) {
|
||||||
|
//没有备用域名 直接加载主域名
|
||||||
if (TextUtils.isEmpty(dataInfo.getBackupDomains())) {
|
if (TextUtils.isEmpty(dataInfo.getBackupDomains())) {
|
||||||
activityMain2Binding.webview.loadUrl(dataInfo.getUrl());
|
activityMain2Binding.webview.loadUrl(dataInfo.getUrl());
|
||||||
} else {
|
} else {
|
||||||
@@ -728,6 +752,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
int lastCheckIndex = 0;
|
int lastCheckIndex = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ping 最佳线路 加载
|
||||||
|
* @param index
|
||||||
|
*/
|
||||||
private void checkUrl(int index) {
|
private void checkUrl(int index) {
|
||||||
lastCheckIndex = index;
|
lastCheckIndex = index;
|
||||||
Uri uri = Uri.parse(urlList.get(lastCheckIndex));
|
Uri uri = Uri.parse(urlList.get(lastCheckIndex));
|
||||||
@@ -845,7 +873,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView webView, String s) {
|
public void onPageFinished(WebView webView, String s) {
|
||||||
super.onPageFinished(webView, s);
|
super.onPageFinished(webView, s);
|
||||||
LogUtils.i("URL是啥加载完成:" + webView.getUrl());
|
// LogUtils.i("URL是啥加载完成:" + webView.getUrl());
|
||||||
if (webView.getUrl().contains("hasSignIn")) {
|
if (webView.getUrl().contains("hasSignIn")) {
|
||||||
hasSignIn = true;
|
hasSignIn = true;
|
||||||
}
|
}
|
||||||
@@ -923,8 +951,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView webView, String url1) {
|
public boolean shouldOverrideUrlLoading(WebView webView, String url1) {
|
||||||
|
|
||||||
LogUtils.i("URL是啥:" + url1);
|
|
||||||
|
|
||||||
if (url1.equals(url + "index") || url1.equals(url + "/index")) {
|
if (url1.equals(url + "index") || url1.equals(url + "/index")) {
|
||||||
isAtGame = false;
|
isAtGame = false;
|
||||||
activityMain2Binding.topVvvv.setVisibility(View.GONE);
|
activityMain2Binding.topVvvv.setVisibility(View.GONE);
|
||||||
@@ -977,7 +1003,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
uri = Uri.parse(request.toString());
|
uri = Uri.parse(request.toString());
|
||||||
}
|
}
|
||||||
String url1 = uri.toString();
|
String url1 = uri.toString();
|
||||||
LogUtils.i("URL是啥1:" + url1);
|
|
||||||
|
|
||||||
if (isToOutSideUrl(url1)) {
|
if (isToOutSideUrl(url1)) {
|
||||||
try {
|
try {
|
||||||
@@ -1121,7 +1146,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
|
||||||
LogUtils.i("数据接口:onShowFileChooser");
|
|
||||||
mUploadCallbackForHighApi = filePathCallback;
|
mUploadCallbackForHighApi = filePathCallback;
|
||||||
Intent intent = fileChooserParams.createIntent();
|
Intent intent = fileChooserParams.createIntent();
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ public class IndexActivity extends MainActivity {
|
|||||||
initConfig();
|
initConfig();
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
initWinwdowLogoConfig();
|
initWinwdowLogoConfig();
|
||||||
// registerFCM();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,6 +32,7 @@ public class IndexActivity extends MainActivity {
|
|||||||
if (!task.isSuccessful()) {
|
if (!task.isSuccessful()) {
|
||||||
msg = "Subscribe failed";
|
msg = "Subscribe failed";
|
||||||
}else{
|
}else{
|
||||||
|
//fcm能注册成功 再去请求通知权限
|
||||||
checkNotify();
|
checkNotify();
|
||||||
}
|
}
|
||||||
LogUtils.i("支持FCM 结果:"+msg);
|
LogUtils.i("支持FCM 结果:"+msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user