Commit b914ae54 authored by mengcuiguang's avatar mengcuiguang

优化代码

parent c810c373
Pipeline #213 canceled with stages
......@@ -109,7 +109,6 @@ public class MintsApplication extends MultiDexApplication {
// preInit预初始化函数耗时极少,不会影响App首次冷启动用户体验
UMConfigure.preInit(this, CommonUtils.getAppMetaData(MintsApplication.getContext(), "UMENG_KEY"), CommonUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME"));
// 初始化toast
initToast();
......@@ -137,7 +136,6 @@ public class MintsApplication extends MultiDexApplication {
// 天卓珊瑚
TzManager.INSTANCE.initTz(this);
// 猎豹游戏初始化
LiebaoManager.getInstance().initCmGameSdk();
......
......@@ -94,30 +94,6 @@ class HomePresenter : BasePresenter<HomeView>() {
})
}
fun getHomeVedioMsg() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.getHomeVedioMsg(),
object : BaseSubscriber<BaseResponse<MainVideoMsgBean>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<MainVideoMsgBean>) {
if (isLinkView) return
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
when (code) {
200 -> view.getHomeVedioMsgSuc(baseResponse.getData())
else -> view.showToast(message)
}
}
})
}
/**
* 游客登录
......
......@@ -6,5 +6,4 @@ import com.mints.goodnews.mvp.model.UserTaskMsgBean
interface HomeView : BaseView {
fun getHallBaseMsgSuc(data: UserTaskMsgBean)
fun getHomeVedioMsgSuc(data: MainVideoMsgBean)
}
......@@ -3,20 +3,27 @@ package com.mints.goodnews.ui.activitys
import android.content.Context
import android.media.AudioManager
import android.os.Bundle
import android.text.TextUtils
import android.view.KeyEvent
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.mints.goodnews.MintsApplication
import com.mints.goodnews.R
import com.mints.goodnews.ad.video.VideoAdingManager
import com.mints.goodnews.common.AppConfig
import com.mints.goodnews.common.Constant
import com.mints.goodnews.ad.express.TTPreLoadCarrierExpressManager
import com.mints.goodnews.manager.ShumeiManager
import com.mints.goodnews.mvp.views.MainView
import com.mints.goodnews.ui.activitys.base.BaseActivity
import com.mints.goodnews.ui.fragment.*
import com.mints.goodnews.ui.widgets.DialogListener
import com.mints.goodnews.ui.widgets.PowerDialog
import com.mints.library.utils.CommonUtils
import kotlinx.android.synthetic.main.activity_main.*
import net.grandcentrix.tray.AppPreferences
/**
* 描述:main
......@@ -28,6 +35,9 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
private val audioManager by lazy { getSystemService(Context.AUDIO_SERVICE) as AudioManager }
private val ps by lazy { AppPreferences(context) }
private var powerDialog: PowerDialog? = null
// 底部标签切换的Fragment
private var moneyFragment: Fragment? = null
private var panFragment: Fragment? = null
......@@ -35,7 +45,6 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
private var friendsFragment: Fragment? = null
private var myFragment: Fragment? = null
private var channelFragment: Fragment? = null
private var kuYinyueFragment: Fragment? = null
private var wzFragment: Fragment? = null
private var currentFragment: Fragment? = null
......@@ -80,6 +89,13 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
tab_rl_two.setOnClickListener(this)
tab_rl_four.setOnClickListener(this)
tab_rl_five.setOnClickListener(this)
if (ps.getBoolean(Constant.LOAN_PERMISSION_FLAG, true)) {
powerDialog()
} else {
// 数美初始化
ShumeiManager.getInstance().initShumei()
}
}
override fun isApplyKitKatTranslucency() = false
......@@ -301,4 +317,55 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
tab_rl_two.visibility = View.GONE
}
}
/**
* 权限弹窗
*/
private fun powerDialog() {
powerDialog = PowerDialog(this, object : DialogListener() {
override fun onClick(v: View) {
when (v.id) {
R.id.tv_dialogper_agreement -> {
val bundle = Bundle()
bundle.putString(WebActivity.WEB_TITLE, getString(R.string.register_name))
bundle.putString(WebActivity.WEB_URL, Constant.REGISTER_URL)
readyGo(WebActivity::class.java, bundle)
}
R.id.tv_dialogper_policy -> {
val bundle = Bundle()
bundle.putString(WebActivity.WEB_TITLE, getString(R.string.privacy_name))
bundle.putString(WebActivity.WEB_URL, Constant.PRIVACY_URL)
readyGo(WebActivity::class.java, bundle)
}
R.id.btn_dialogper_back -> {
if (powerDialog != null && powerDialog!!.isShowing
) {
showToast("请您同意授权,否则将无法使用APP功能")
}
}
R.id.btn_dialogper_next -> {
if (powerDialog != null && powerDialog!!.isShowing
) {
powerDialog!!.dismiss()
ps.put(Constant.LOAN_PERMISSION_FLAG, false)
// 数美初始化
ShumeiManager.getInstance().initShumei()
// 游客首次提示1500新人奖励 且 不是分享包
val channel = CommonUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME")
if (!TextUtils.equals(channel, Constant.CHANNEL_SHARE) && ps.getBoolean(Constant.FIRST_VISITOR_FLAG, true)) {
ps.put(Constant.FIRST_VISITOR_FLAG, false)
val bundle = Bundle()
bundle.putInt(Constant.MAIN_CUR_COIN, 2000)
bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_NEW_VISITOR)
readyGo(AwardActivity::class.java, bundle)
}
}
}
}
}
})
powerDialog!!.show()
}
}
\ No newline at end of file
......@@ -27,11 +27,8 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
private var currentFragment: Fragment? = null
private var mainFragment: Fragment? = null
private var bookStoreFragment: Fragment? = null
// private var newsFragment: Fragment? = null
private var xmlyGameFragment: Fragment? = null
private var liebaoGameFragment: Fragment? = null
// private var kuYinyueFragment: Fragment? = null
private var curPosition = 0//当前标签选中的下标
......@@ -42,87 +39,43 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
}
override fun onHiddenChanged(hidden: Boolean) {
if (AppConfig.showAdFlag) {
// if (curPosition == 0) {
// mainFragment?.onHiddenChanged(hidden)
// } else if (curPosition == 3) {
// liebaoGameFragment?.onHiddenChanged(hidden)
// }
if (curPosition == 0) {
mainFragment?.onHiddenChanged(hidden)
} else if (curPosition == 2) {
liebaoGameFragment?.onHiddenChanged(hidden)
}
} else {
if (curPosition == 1) {
liebaoGameFragment?.onHiddenChanged(hidden)
}
}
// if (curPosition == 0) {
// mainFragment?.onHiddenChanged(hidden)
// } else if (curPosition == 2) {
// liebaoGameFragment?.onHiddenChanged(hidden)
// }
super.onHiddenChanged(hidden)
}
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
if (curPosition == 0) {
mainFragment?.userVisibleHint = isVisibleToUser
}
// if (curPosition == 0) {
// mainFragment?.userVisibleHint = isVisibleToUser
// }
}
private fun initView() {
if (AppConfig.showAdFlag) {
if (mainFragment == null) {
mainFragment = MainFragment()
}
if (!mainFragment!!.isAdded) {
// 提交事务
childFragmentManager.beginTransaction().add(R.id.fragment_container, mainFragment!!).commitAllowingStateLoss()
// 记录当前Fragment
currentFragment = mainFragment
}
xtFragmentMoney.setxTabDisplayNum(3)
val newTab1 = xtFragmentMoney.newTab()
newTab1.text = "视频"
// val newTab2 = xtFragmentMoney.newTab()
// newTab2.text = "书城"
// val newTab3 = xtFragmentMoney.newTab()
// newTab3.text = "新闻"
val newTab4 = xtFragmentMoney.newTab()
newTab4.text = "听书"
val newTab5 = xtFragmentMoney.newTab()
newTab5.text = "游戏"
xtFragmentMoney.addTab(newTab1)
// xtFragmentMoney.addTab(newTab2)
// xtFragmentMoney.addTab(newTab3)
xtFragmentMoney.addTab(newTab4)
xtFragmentMoney.addTab(newTab5)
xtFragmentMoney.addOnTabSelectedListener(this)
} else {
if (xmlyGameFragment == null) {
xmlyGameFragment = XmlyFragment()
}
if (!xmlyGameFragment!!.isAdded) {
// 提交事务
childFragmentManager.beginTransaction().add(R.id.fragment_container, xmlyGameFragment!!).commitAllowingStateLoss()
// 记录当前Fragment
currentFragment = xmlyGameFragment
}
xtFragmentMoney.setxTabDisplayNum(2)
val newTab4 = xtFragmentMoney.newTab()
newTab4.text = "听书"
val newTab5 = xtFragmentMoney.newTab()
newTab5.text = "游戏"
// xtFragmentMoney.addTab(newTab3)
xtFragmentMoney.addTab(newTab4)
xtFragmentMoney.addTab(newTab5)
xtFragmentMoney.addOnTabSelectedListener(this)
if (mainFragment == null) {
mainFragment = MainFragment()
}
if (!mainFragment!!.isAdded) {
// 提交事务
childFragmentManager.beginTransaction().add(R.id.fragment_container, mainFragment!!).commitAllowingStateLoss()
// 记录当前Fragment
currentFragment = mainFragment
}
xtFragmentMoney.setxTabDisplayNum(3)
val newTab1 = xtFragmentMoney.newTab()
newTab1.text = "新闻"
val newTab4 = xtFragmentMoney.newTab()
newTab4.text = "听书"
val newTab5 = xtFragmentMoney.newTab()
newTab5.text = "游戏"
xtFragmentMoney.addTab(newTab1)
xtFragmentMoney.addTab(newTab4)
xtFragmentMoney.addTab(newTab5)
xtFragmentMoney.addOnTabSelectedListener(this)
}
/**
......@@ -181,38 +134,11 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: XTabLayout.Tab) {
when (tab.position) {
0 -> {
if (AppConfig.showAdFlag) {
if (mainFragment == null) {
mainFragment = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment!!, FRAGMENT_TAG_VIDEO)
} else {
if (xmlyGameFragment == null) {
xmlyGameFragment = XmlyFragment()
}
addOrShowFragment(childFragmentManager, xmlyGameFragment!!, FRAGMENT_TAG_XMLY)
if (mainFragment == null) {
mainFragment = MainFragment()
}
addOrShowFragment(childFragmentManager, mainFragment!!, FRAGMENT_TAG_VIDEO)
}
// 1 -> {
// if (AppConfig.showAdFlag) {
// if (bookStoreFragment == null) {
// bookStoreFragment = ZhangyueFragment()
// }
// addOrShowFragment(childFragmentManager, bookStoreFragment!!, FRAGMENT_TAG_BOOKSTORE)
// } else {
// if (liebaoGameFragment == null) {
// liebaoGameFragment = LiebaoGameFragment()
// }
// addOrShowFragment(childFragmentManager, liebaoGameFragment!!, FRAGMENT_TAG_GAME)
// }
// }
// 2 -> {
// if (newsFragment == null) {
// newsFragment = RsNewsFragment()
// }
// addOrShowFragment(childFragmentManager, newsFragment!!, FRAGMENT_TAG_NEWS)
// }
1 -> {
if (xmlyGameFragment == null) {
xmlyGameFragment = XmlyFragment()
......@@ -225,12 +151,6 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
}
addOrShowFragment(childFragmentManager, liebaoGameFragment!!, FRAGMENT_TAG_GAME)
}
// 3 -> {
// if (kuYinyueFragment == null) {
// kuYinyueFragment = KuYinYueFragment()
// }
// addOrShowFragment(childFragmentManager, kuYinyueFragment!!, FRAGMENT_TAG_KYL)
// }
}
curPosition = tab.position
}
......
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