Commit 6d02663d authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 3ce1c8d9
......@@ -181,7 +181,7 @@ dependencies {
// 三方接入
// leakcanary
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
// 极光推送
implementation 'cn.jiguang.sdk:jpush:3.6.6'
implementation 'cn.jiguang.sdk:jcore:2.3.8'
......
......@@ -190,6 +190,9 @@
<activity
android:name=".ui.activitys.WrapperActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.DhGameActivity"
android:screenOrientation="portrait" />
<service
android:name=".service.UpdateService"
......
......@@ -128,7 +128,7 @@ public class MintsApplication extends MultiDexApplication {
LiebaoManager.getInstance().initCmGameSdk();
// 瑞狮新闻
RsNewsManager.INSTANCE.init(this);
RsNewsManager.INSTANCE.initX5Environment(this);
}
private MiitHelper.AppIdsUpdater appIdsUpdater = ids -> OAID = ids;
......
......@@ -14,9 +14,14 @@ public class AppConfig {
public static boolean app_updateing = false;
/**
* 黑名单
* 黑名单 名称
*/
public static String app_black = "";
public static String app_black_name = "";
/**
* 黑名单 包名
*/
public static String app_black_pkg = "";
/**
* 黑名单校验
......
......@@ -551,7 +551,7 @@ class DeviceInfo private constructor() {
/**
* 获取APP列表信息
*/
fun getAppInfoList(): MutableList<String>? {
fun getAppNameInfoList(): MutableList<String>? {
try {
val appList: MutableList<String> = ArrayList()
val mainintent = Intent(Intent.ACTION_MAIN, null)
......@@ -568,6 +568,35 @@ class DeviceInfo private constructor() {
} else {
//非系统程序
appList.add(appInfo.loadLabel(mContext!!.packageManager) as String)
}
}
return appList
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
/**
* 获取APP列表信息
*/
fun getAppPkgInfoList(): MutableList<String>? {
try {
val appList: MutableList<String> = ArrayList()
val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo =
mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null
val count = packageinfo.size
for (i in 0 until count) {
pinfo = packageinfo[i]
val appInfo = pinfo.applicationInfo
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM > 0) {
//系统程序 忽略
} else {
//非系统程序
appList.add(pinfo.packageName)
}
}
......
......@@ -16,7 +16,11 @@ object RsNewsManager {
* 初始化
*/
fun init(application: Application) {
XRNewsManager.getInstance().init(application, APP_ID, UserManager.getInstance().userID)
}
fun initX5Environment(application: Application){
QbSdk.initX5Environment(application, null)
XRNewsManager.getInstance().init(application, APP_ID, UserManager.getInstance().userID)
}
}
\ No newline at end of file
}
......@@ -75,17 +75,42 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
RxjavaUtil.executeRxTask<String>(object : CommonRxTask<String?>("") {
override fun doInIOThread() {
var result = "false"
val appBlack = AppConfig.app_black
if (!TextUtils.isEmpty(appBlack)) {
val appInfoList = deviceInfo.getAppInfoList()
if (appInfoList != null && appInfoList!!.size > 0) {
val appBlackList = appBlack.split(",")
for (appBlackName in appBlackList) {
val serverBlackName = AppConfig.app_black_name
val serverBlackPkg = AppConfig.app_black_pkg
// 校验应用名称
if (!TextUtils.isEmpty(serverBlackName)) {
val sysNameList = deviceInfo.getAppNameInfoList()
if (sysNameList != null && sysNameList.size > 0) {
val serverBlackNameList = serverBlackName.split(",")
for (serverBlackName in serverBlackNameList) {
if (TextUtils.equals(result, "true")) {
break
}
for (sysName in sysNameList) {
// 系统名称 包含 服务名称
if (sysName.contains(serverBlackName)) {
result = "true"
break
}
}
}
}
}
// 校验应用包名
if (TextUtils.equals(result, "false") && !TextUtils.isEmpty(serverBlackPkg)) {
val sysPkgList = deviceInfo.getAppPkgInfoList()
if (sysPkgList != null && sysPkgList.size > 0) {
val serverBlackPkgList = serverBlackPkg.split(",")
for (serverBlackPkg in serverBlackPkgList) {
if (TextUtils.equals(result, "true")) {
break
}
for (appName in appInfoList) {
if (appName.contains(appBlackName)) {
for (sysPkgName in sysPkgList) {
// 系统名称 包含 服务名称
if (sysPkgName.contains(serverBlackPkg)) {
result = "true"
break
}
......@@ -93,6 +118,7 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
}
}
}
t = result
}
......
package com.mints.goodmoney.ui.activitys
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.net.Uri
import android.os.Build
import android.view.View
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebViewClient
import com.mints.goodmoney.R
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.utils.MD5
import com.mints.goodmoney.utils.URIEncoder
import kotlinx.android.synthetic.main.fragment_main_dh.*
import kotlinx.android.synthetic.main.header_layout.*
class DhGameActivity : BaseActivity(), View.OnClickListener {
companion object {
const val CHANNEL = "14533"
const val KEY = "4932d9037fd94f6ba24fa09605203cd6"
const val AUTH_URL = "http://www.shandw.com/auth/"
}
override fun getContentViewLayoutID() = R.layout.fragment_main_dh
override fun isApplyKitKatTranslucency() = false
override fun initViewsAndEvents() {
tv_title.text = "游戏大厅"
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
loadH5Game()
initListener()
}
override fun onDestroy() {
super.onDestroy()
dh_webview?.let {
it.destroyDrawingCache()
val parent = it.getParent() as ViewGroup
parent.removeView(it)
it.removeAllViews()
it.destroy()
}
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.iv_left_icon -> finish()
}
}
private fun initListener() {
iv_left_icon.setOnClickListener(this)
}
/**
* 加载H5Game
*/
@SuppressLint("SetJavaScriptEnabled")
private fun loadH5Game() {
dh_webview?.let {
val loadUrl = getLoadUrl()
val settings = it.settings
// 本地 DOM 存储(解决加载某些网页出现白板现象)
settings.domStorageEnabled = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// 解决 Android 5.0 上 WebView 默认不允许加载 Http 与 Https 混合内容
settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}
settings.javaScriptEnabled = true
settings.javaScriptCanOpenWindowsAutomatically = true
it.setWebViewClient(object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: android.webkit.WebView,
url: String
): Boolean {
if (url.startsWith("weixin://wap/pay?") || url.startsWith("alipay")) {
val hasApp: Boolean
hasApp = if (url.startsWith("weixin://wap/pay?")) {
isAppExist("com.tencent.mm")
} else {
(isAppExist("com.eg.android.AlipayGphone") || isAppExist("com.alipay.android.app"))
}
if (hasApp) {
val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.data = Uri.parse(url)
startActivity(intent)
} else {
showToast("客官,请先安装支付App哦~")
}
return true
}
if (url.startsWith("https")) {
val map = HashMap<String, String>()
map["Referer"] = "http://www.shandw.com"
it.loadUrl(url, map)
}
return super.shouldOverrideUrlLoading(view, url)
}
})
it.loadUrl(loadUrl)
}
}
/**
* 获取拼接url
*/
fun getLoadUrl(): String {
val currentTimeMillis = System.currentTimeMillis() / 1000
val loadUrl = "${AUTH_URL}?" +
"channel=${CHANNEL}&" +
"openid=${URIEncoder.encodeURIComponent(UserManager.getInstance().userID)}&" +
"time=${currentTimeMillis}&" +
"nick=${URIEncoder.encodeURIComponent(UserManager.getInstance().userID)}&" +
"avatar=${URIEncoder.encodeURIComponent("https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg_goodmoney/img/ic_my.png")}&" +
"sex=${0}&" +
"phone=${UserManager.getInstance().mobile}&" +
"sdw_simple=${2}&" +
"sign=${getSignStr(currentTimeMillis)}"
return loadUrl
}
/**
* 获取签名
*/
fun getSignStr(currentTimeMillis: Long): String {
val signStr = "channel=${CHANNEL}&" +
"openid=${URIEncoder.encodeURIComponent(UserManager.getInstance().userID)}&" +
"time=${currentTimeMillis}&" +
"nick=${UserManager.getInstance().userID}&" +
"avatar=https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg_goodmoney/img/ic_my.png&" +
"sex=${0}&" +
"phone=${UserManager.getInstance().mobile}${KEY}"
return MD5.GetMD5Code(signStr).toLowerCase()
}
fun isAppExist(pkgName: String): Boolean {
var info: ApplicationInfo? = null
try {
info = context?.getPackageManager()!!.getApplicationInfo(pkgName, 0)
context!!.startActivity(context!!.packageManager.getLaunchIntentForPackage(pkgName))
} catch (e: Exception) {
}
return if (info != null) true else false
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.fragment
import android.os.Bundle
import android.view.View
import com.cmcm.cmgame.CmGameSdk
import com.cmcm.cmgame.IAppCallback
import com.cmcm.cmgame.IGameAdCallback
import com.cmcm.cmgame.IGamePlayTimeCallback
import com.google.gson.JsonParser
import com.mints.goodmoney.R
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.presenters.GamePresenter
import com.mints.goodmoney.mvp.views.GameView
import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.ui.fragment.base.LazyLoadBaseFragment
import com.mints.goodmoney.utils.SpanUtils
import com.mints.library.utils.json.JsonUtil
import kotlinx.android.synthetic.main.activity_liebao_game.*
import java.util.*
/**
* 描述:邀请好友
* 作者:孟崔广
* 时间:2020/11/25 17:30
*/
class LiebaoGameFragment : LazyLoadBaseFragment(), GameView,
IAppCallback,
IGamePlayTimeCallback,
IGameAdCallback{
val AIP_GAME_URL = "api/gametime/add" //退出游戏
val STASTICIS_GAME_URL = "stasticis/game/add" //点击游戏
private val gamePresenter by lazy { GamePresenter() }
private var gameName = ""
private var gameID = ""
override fun getContentViewLayoutID() = R.layout.fragment_liebao_game
override fun initViewsAndEvents() {
}
override fun onFragmentFirstVisible() {
gamePresenter.attachView(this)
initListener()
}
override fun onFragmentResume() {
super.onFragmentResume()
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_MAIN) {
gamePresenter.getGameInfo()
}
}
override fun onDestroy() {
super.onDestroy()
CmGameSdk.removeGameClickCallback()
CmGameSdk.setMoveView(null)
CmGameSdk.removeGamePlayTimeCallback()
CmGameSdk.removeGameAdCallback()
gamePresenter.detachView()
}
private fun initListener() {
gvGameLiebao.inflate(activity)
// 默认游戏中心页面,点击游戏试,触发回调
CmGameSdk.setGameClickCallback(this)
// 点击游戏右上角或物理返回键,退出游戏时触发回调,并返回游戏时长
CmGameSdk.setGamePlayTimeCallback(this)
// 所有广告类型的展示和点击事件回调,仅供参考,数据以广告后台为准
CmGameSdk.setGameAdCallback(this)
}
override fun gameInfo(sumTime: Int, sumCoin: Int, gameTime: Int) {
tvGameHint.visibility = View.VISIBLE
if (gameTime >= sumTime) {
tvGameHint.setText("今日游戏任务已完成")
} else {
tvGameHint.setText(
SpanUtils()
.append("畅玩").append("${sumTime / 60}").setForegroundColor(mContext.resources.getColor(R.color.color_FF9837)).append("分钟, ")
.append("奖励").append("${sumCoin}").setForegroundColor(mContext.resources.getColor(R.color.red)).append("金币, ")
.append("已玩").append("${gameTime / 60}").setForegroundColor(mContext.resources.getColor(R.color.color_FF9837)).append("分钟")
.create())
}
}
override fun gameAddSuc(eventType: String?, data: Any?) {
when (eventType) {
Constant.EVENT_TYPE_TIME -> if (data != null) {
val json = JsonUtil.toJson(data)
val jsonObject = JsonParser().parse(json).asJsonObject
val gameCoin = jsonObject["gameCoin"].asInt
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, gameCoin)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_GAME)
readyGo(AwardActivity::class.java, bundle)
}
Constant.EVENT_TYPE_GAMEINFO -> {
}
Constant.EVENT_TYPE_CLICK -> {
}
}
}
/**
* 默认游戏中心页面,点击游戏试,触发回调 finish
*
* @param gameName
* @param gameID
*/
override fun gameClickCallback(gameName: String, gameID: String) {
this.gameName = gameName
this.gameID = gameID
val eventTypeClick: String = Constant.EVENT_TYPE_CLICK
val vo = HashMap<String, Any>()
vo["gameName"] = gameID
vo["gameId"] = gameID
vo["gameSource"] = "liebao"
vo["carrierType"] = Constant.CARRIER_GAME
vo["eventType"] = eventTypeClick
vo["num"] = 1
vo["pkg"] = Constant.MINTS_PKG_NAME
gamePresenter.gameAdd(STASTICIS_GAME_URL, eventTypeClick, vo)
}
/**
* @param playTimeInSeconds 玩游戏时长,单位为秒 finish
*
*
* 点击游戏右上角或物理返回键,退出游戏时触发回调,并返回游戏时长
*/
override fun gamePlayTimeCallback(gameId: String?, playTimeInSeconds: Int) {
val eventTypeTime: String = Constant.EVENT_TYPE_TIME
if (playTimeInSeconds < 3) {
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, 0)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_GAME)
readyGo(AwardActivity::class.java, bundle)
} else {
val vo = HashMap<String, Any>()
vo["gameName"] = gameID
vo["gameId"] = gameID
vo["gameSource"] = "liebao"
vo["carrierType"] = Constant.CARRIER_GAME
vo["eventType"] = eventTypeTime
vo["playtimeinseconds"] = playTimeInSeconds
vo["pkg"] = Constant.MINTS_PKG_NAME
gamePresenter.gameAdd(AIP_GAME_URL, eventTypeTime, vo)
}
}
/**
* 广告曝光/点击回调 finish
*
* @param gameId 游戏Id
* @param adType 广告类型:1:激励视频广告;2:Banner广告;3:原生Banner广告;4:全屏视频广告;
* 5:原生插屏广告;6:开屏大卡广告;7:模板Banner广告;8:模板插屏广告;9:游戏列表信息流广告
* 10:游戏列表模板插屏广告;11:游戏加载模板插屏广告;12:游戏列表信息流模板渲染广告;
* 13:游戏退出推荐弹框信息流自渲染广告;14:游戏退出推荐弹框信息流模板渲染广告
* @param adAction 广告操作:1:曝光;2:点击;3:关闭;4:跳过
* @param adChannel 广告源:穿山甲,优量汇
*/
override fun onGameAdAction(gameId: String?, adType: Int, adAction: Int, adChannel: String) {
if (adAction != 1) {
val vo = HashMap<String, Any>()
vo["gameName"] = gameName
vo["gameId"] = gameID
vo["gameSource"] = "liebao"
vo["carrierType"] = Constant.CARRIER_GAME
var eventTypeView = "VIEW"
when (adAction) {
1 -> eventTypeView = "VIEW"
2 -> eventTypeView = "CLICK"
3 -> eventTypeView = "CLOSE"
4 -> eventTypeView = "JUMP"
}
vo["adType"] = adType
vo["adsource"] = adChannel
vo["eventType"] = eventTypeView
vo["pkg"] = Constant.MINTS_PKG_NAME
gamePresenter.gameAdd(STASTICIS_GAME_URL, Constant.EVENT_TYPE_ADCLICK, vo)
}
}
}
\ No newline at end of file
......@@ -177,7 +177,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
// 保存Ip,用于穿山甲回调校验
ps.put(Constant.CSJ_VEDIO_APPIP, data.ip)
AppConfig.app_black = data.userRiskApp
// AppConfig.app_black = data.userRiskApp
AppConfig.flVideoFlag = data.vedioRules.isFlVideoFlag
// 新人福利 放到个人中心展示 防止首页红包转动异常
......
......@@ -19,7 +19,7 @@ import java.util.*
class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
private var mainFragment: MainFragment? = null
private var dhGameFragment: DhGameFragment? = null
private var liebaoGameFragment: LiebaoGameFragment? = null
private var curPosition = 0//当前标签选中的下标
......@@ -33,7 +33,7 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
if (curPosition == 0) {
mainFragment?.onHiddenChanged(hidden)
} else if (curPosition == 3) {
dhGameFragment?.onHiddenChanged(hidden)
liebaoGameFragment?.onHiddenChanged(hidden)
}
super.onHiddenChanged(hidden)
}
......@@ -54,11 +54,11 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
val fragments: MutableList<Fragment> = ArrayList()
mainFragment = MainFragment()
dhGameFragment = DhGameFragment()
liebaoGameFragment = LiebaoGameFragment()
fragments.add(mainFragment!!)
fragments.add(ZhangyueFragment())
fragments.add(RsNewsFragment())
fragments.add(dhGameFragment!!)
fragments.add(liebaoGameFragment!!)
//去除两侧应阴影
vpFragmentMoney.overScrollMode = ViewPager.OVER_SCROLL_NEVER
......@@ -85,13 +85,13 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
}
override fun onTabSelected(tab: XTabLayout.Tab) {
if (tab.position == 3) {
if (!UserManager.getInstance().userIsLogin()) {
readyGo(WxLoginActivity::class.java)
vpFragmentMoney.currentItem = if (curPosition == 3) 0 else curPosition
return
}
}
// if (tab.position == 3) {
// if (!UserManager.getInstance().userIsLogin()) {
// readyGo(WxLoginActivity::class.java)
// vpFragmentMoney.currentItem = if (curPosition == 3) 0 else curPosition
// return
// }
// }
curPosition = tab.position
}
......
......@@ -213,7 +213,7 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
// 更新权重
initAdWeight(data)
AppConfig.app_black = data.userRiskApp
// AppConfig.app_black = data.userRiskApp
AppConfig.flVideoFlag = data.vedioRules.isFlVideoFlag
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:id="@+id/tvGameHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_E6E6E6"
android:drawableLeft="@mipmap/ic_voice"
android:drawablePadding="10pt"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="5dp"
android:paddingBottom="10dp"
android:textSize="14sp"
android:visibility="gone" />
<com.mints.goodmoney.ui.widgets.ElasticScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fadingEdge="none"
android:orientation="vertical"
android:overScrollMode="never">
<!--接入时需要拷贝如下的布局,包括GameView外层的LinearLayout-start -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.cmcm.cmgame.GameView
android:id="@+id/gvGameLiebao"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
app:cmgame_category_title_text_color="#FF222222"
app:cmgame_category_title_text_size="15sp" />
</RelativeLayout>
</LinearLayout>
</com.mints.goodmoney.ui.widgets.ElasticScrollView>
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment