Commit 9db567c7 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 2c8070d1
......@@ -97,10 +97,10 @@ class TaskCpdFragment : BaseFragment(), TaskView,
}
private fun initView() {
val gridLayoutManager = GridLayoutManager(mContext, 3)
val gridLayoutManager = GridLayoutManager(activity, 3)
recy_task.layoutManager = gridLayoutManager
recy_task.addItemDecoration(SpacesItemDecoration(3, SpacesItemDecoration.px2dp(10f)))
mTaskAdapter = TaskAdapter(mFakeTaskList, mContext)
mTaskAdapter = TaskAdapter(mFakeTaskList, activity!!)
recy_task.adapter = mTaskAdapter
recy_task.setItemViewCacheSize(20)
mTaskAdapter?.setOnItemChildClickListener(this)
......@@ -365,8 +365,8 @@ class TaskCpdFragment : BaseFragment(), TaskView,
DownloadApkManager.destroy()
if (mReceiverBroadcastReceiver != null) {
mContext.stopService(Intent(context, AppInstallService::class.java))
mContext.unregisterReceiver(mReceiverBroadcastReceiver)
activity?.stopService(Intent(activity, AppInstallService::class.java))
activity?.unregisterReceiver(mReceiverBroadcastReceiver)
mReceiverBroadcastReceiver = null
}
......@@ -393,7 +393,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
mFakeTaskList[it.getPosition()].state = 0
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
if (AppUtil.checkPackInfo(activity!!, currentPkgName)) {
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
......@@ -431,7 +431,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
mFakeTaskList[it.getPosition()].state = 0
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
if (AppUtil.checkPackInfo(activity!!, currentPkgName)) {
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
showToast("未找到当前APP、可能被卸载,请重试~")
......@@ -480,7 +480,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
private fun registerBroad() {
if (mReceiverBroadcastReceiver != null) return
mContext.startService(Intent(context, AppInstallService::class.java))
activity?.startService(Intent(activity, AppInstallService::class.java))
mReceiverBroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
......@@ -526,7 +526,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
val intentFilter = IntentFilter()
intentFilter.addAction(AppInstallService.APP_INSTALL_ACTION)
mContext.registerReceiver(this.mReceiverBroadcastReceiver, intentFilter)
activity?.registerReceiver(this.mReceiverBroadcastReceiver, intentFilter)
}
......
......@@ -39,9 +39,9 @@ class TaskCpdHistoryFragment : LazyLoadBaseFragment(), TaskCpdHistoryView,
override fun initViewsAndEvents() {}
private fun initView() {
val linearLayoutManager = LinearLayoutManager(mContext)
val linearLayoutManager = LinearLayoutManager(activity)
recy_task.layoutManager = linearLayoutManager
mTaskAdapter = TaskCpdHistoryAdapter(mFakeTaskList, mContext)
mTaskAdapter = TaskCpdHistoryAdapter(mFakeTaskList, activity!!)
recy_task.adapter = mTaskAdapter
mTaskAdapter?.setOnItemChildClickListener(this)
}
......@@ -104,7 +104,7 @@ class TaskCpdHistoryFragment : LazyLoadBaseFragment(), TaskCpdHistoryView,
mFakeTaskList[it.getPosition()].state = 3
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
if (AppUtil.checkPackInfo(activity!!, currentPkgName)) {
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
......@@ -139,7 +139,7 @@ class TaskCpdHistoryFragment : LazyLoadBaseFragment(), TaskCpdHistoryView,
mFakeTaskList[it.getPosition()].state = 3
it.notifyItemChanged(it.getPosition())
} else {
if (AppUtil.checkPackInfo(mContext, currentPkgName)) {
if (AppUtil.checkPackInfo(activity!!, currentPkgName)) {
AppTryPlayManager.toTryPlay(currentPkgName)
} else {
showToast("未找到当前APP、可能被卸载,请重试~")
......
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