Commit bca1dd75 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent b914ae54
Pipeline #216 canceled with stages
......@@ -32,6 +32,7 @@ import com.mints.goodnews.mvp.views.HomeView
import com.mints.goodnews.ui.activitys.AwardActivity
import com.mints.goodnews.ui.activitys.WebActivity
import com.mints.goodnews.ui.fragment.base.BaseFragment
import com.mints.goodnews.ui.fragment.base.LazyLoadBaseFragment
import com.mints.goodnews.ui.widgets.BindWxDialog
import com.mints.goodnews.ui.widgets.DialogListener
import com.mints.goodnews.ui.widgets.PowerDialog
......@@ -40,7 +41,9 @@ import com.mints.goodnews.ui.widgets.countdowntimer.OnCountDownTimerListener
import com.mints.goodnews.ui.widgets.seekbar.BubbleUtils
import com.mints.goodnews.utils.LogUtil
import com.mints.goodnews.utils.TimeRender
import com.mints.library.base.BaseLazyFragment
import com.mints.library.utils.CommonUtils
import kotlinx.android.synthetic.main.fragment_liebao_game.*
import kotlinx.android.synthetic.main.layout_red_bag.*
import kotlinx.android.synthetic.main.layout_red_box.*
import net.grandcentrix.tray.AppPreferences
......@@ -52,7 +55,7 @@ private val TAG = MainFragment::class.java.simpleName
* 作者:孟崔广
* 时间:2020/10/10 17:30
*/
class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener {
private val ps by lazy { AppPreferences(context) }
private val homePresenter by lazy { HomePresenter() }
......@@ -64,6 +67,10 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
override fun getContentViewLayoutID() = R.layout.fragment_main_first
override fun initViewsAndEvents() {
}
override fun onFragmentFirstVisible() {
homePresenter.attachView(this)
videoAdingManager = VideoAdingManager.getInstance(activity)
......@@ -80,32 +87,21 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
innerApp()
}
private fun innerApp() {
if (userManager.userIsLogin()) {
homePresenter.getNetWorkIp()
TrackManager.getInstance().innerApp()
}
}
override fun onHiddenChanged(hidden: Boolean) {
if (hidden) {
onPause()
} else {
onResume()
}
super.onHiddenChanged(hidden)
}
override fun onResume() {
super.onResume()
override fun onFragmentResume() {
super.onFragmentResume()
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_ONE) {
if (!TextUtils.isEmpty(userManager?.userID)) {
homePresenter.getHallBaseMsg()
} else {
homePresenter.userLogin()
}
}
}
private fun innerApp() {
if (userManager.userIsLogin()) {
homePresenter.getNetWorkIp()
TrackManager.getInstance().innerApp()
}
}
......
......@@ -17,16 +17,21 @@ import kotlinx.android.synthetic.main.fragment_main_money.*
class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
companion object {
const val FRAGMENT_TAG_VIDEO = "FRAGMENT_TAG_VIDEO"
const val FRAGMENT_TAG_BOOKSTORE = "FRAGMENT_TAG_BOOKSTORE"
const val FRAGMENT_TAG_NEWS = "FRAGMENT_TAG_NEWS"
const val FRAGMENT_TAG_GAME = "FRAGMENT_TAG_GAME"
const val FRAGMENT_TAG_KYL = "FRAGMENT_TAG_KYL"
const val FRAGMENT_TAG_MAIN1 = "FRAGMENT_TAG_MAIN1"
const val FRAGMENT_TAG_MAIN2 = "FRAGMENT_TAG_MAIN2"
const val FRAGMENT_TAG_MAIN3 = "FRAGMENT_TAG_MAIN3"
const val FRAGMENT_TAG_MAIN4 = "FRAGMENT_TAG_MAIN4"
const val FRAGMENT_TAG_MAIN5 = "FRAGMENT_TAG_MAIN5"
const val FRAGMENT_TAG_XMLY = "FRAGMENT_TAG_XMLY"
const val FRAGMENT_TAG_GAME = "FRAGMENT_TAG_GAME"
}
private var currentFragment: Fragment? = null
private var mainFragment: Fragment? = null
private var mainFragment1: Fragment? = null
private var mainFragment2: Fragment? = null
private var mainFragment3: Fragment? = null
private var mainFragment4: Fragment? = null
private var mainFragment5: Fragment? = null
private var xmlyGameFragment: Fragment? = null
private var liebaoGameFragment: Fragment? = null
......@@ -55,26 +60,39 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
}
private fun initView() {
if (mainFragment == null) {
mainFragment = MainFragment()
if (mainFragment1 == null) {
mainFragment1 = MainFragment()
}
if (!mainFragment!!.isAdded) {
if (!mainFragment1!!.isAdded) {
// 提交事务
childFragmentManager.beginTransaction().add(R.id.fragment_container, mainFragment!!).commitAllowingStateLoss()
childFragmentManager.beginTransaction().add(R.id.fragment_container, mainFragment1!!).commitAllowingStateLoss()
// 记录当前Fragment
currentFragment = mainFragment
currentFragment = mainFragment1
}
xtFragmentMoney.setxTabDisplayNum(3)
xtFragmentMoney.setxTabDisplayNum(7)
val newTab1 = xtFragmentMoney.newTab()
newTab1.text = "新闻"
val newTab2 = xtFragmentMoney.newTab()
val newTab3 = xtFragmentMoney.newTab()
val newTab4 = xtFragmentMoney.newTab()
newTab4.text = "听书"
val newTab5 = xtFragmentMoney.newTab()
newTab5.text = "游戏"
val newTab6 = xtFragmentMoney.newTab()
val newTab7 = xtFragmentMoney.newTab()
newTab1.text = "热点"
newTab2.text = "娱乐"
newTab3.text = "体育"
newTab4.text = "军事"
newTab5.text = "小说"
newTab6.text = "听书"
newTab7.text = "游戏"
xtFragmentMoney.addTab(newTab1)
xtFragmentMoney.addTab(newTab2)
xtFragmentMoney.addTab(newTab3)
xtFragmentMoney.addTab(newTab4)
xtFragmentMoney.addTab(newTab5)
xtFragmentMoney.addTab(newTab6)
xtFragmentMoney.addTab(newTab7)
xtFragmentMoney.addOnTabSelectedListener(this)
}
......@@ -96,28 +114,9 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
currentFragment = fragment
}
fun selectVedio() {
// vpFragmentMoney.currentItem = 0
xtFragmentMoney.getTabAt(0)?.select()
if (mainFragment == null) {
mainFragment = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment!!, FRAGMENT_TAG_VIDEO)
}
fun selectBook() {
// vpFragmentMoney.currentItem = 1
// xtFragmentMoney.getTabAt(1)?.select()
// if (bookStoreFragment == null) {
// bookStoreFragment = ZhangyueFragment()
// }
//
// addOrShowFragment(childFragmentManager, bookStoreFragment!!, FRAGMENT_TAG_BOOKSTORE)
}
fun selectXmly() {
xtFragmentMoney.getTabAt(1)?.select()
xtFragmentMoney.getTabAt(5)?.select()
// xtFragmentMoney.getTabAt(2)?.select()
if (xmlyGameFragment == null) {
xmlyGameFragment = XmlyFragment()
......@@ -134,18 +133,42 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: XTabLayout.Tab) {
when (tab.position) {
0 -> {
if (mainFragment == null) {
mainFragment = MainFragment()
if (mainFragment1 == null) {
mainFragment1 = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment!!, FRAGMENT_TAG_VIDEO)
addOrShowFragment(childFragmentManager, mainFragment1!!, FRAGMENT_TAG_MAIN1)
}
1 -> {
if (mainFragment2 == null) {
mainFragment2 = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment2!!, FRAGMENT_TAG_MAIN2)
}
2 -> {
if (mainFragment3 == null) {
mainFragment3 = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment3!!, FRAGMENT_TAG_MAIN3)
}
3 -> {
if (mainFragment4 == null) {
mainFragment4 = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment4!!, FRAGMENT_TAG_MAIN4)
}
4 -> {
if (mainFragment5 == null) {
mainFragment4 = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment5!!, FRAGMENT_TAG_MAIN5)
}
5 -> {
if (xmlyGameFragment == null) {
xmlyGameFragment = XmlyFragment()
}
addOrShowFragment(childFragmentManager, xmlyGameFragment!!, FRAGMENT_TAG_XMLY)
}
2 -> {
6 -> {
if (liebaoGameFragment == null) {
liebaoGameFragment = LiebaoGameFragment()
}
......
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