MainActivity.kt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.ysnows.sultra.activity
  2. import android.os.Bundle
  3. import android.view.View
  4. import com.bytedance.sdk.openadsdk.TTAdConstant
  5. import com.bytedance.sdk.openadsdk.TTAppDownloadListener
  6. import com.bytedance.sdk.openadsdk.TTNativeExpressAd
  7. import com.qmuiteam.qmui.util.QMUIKeyboardHelper
  8. import com.ysnows.base.base.BRepository
  9. import com.ysnows.base.utils.MMKVManager
  10. import com.ysnows.sultra.base.MBActivity
  11. import com.ysnows.sultra.config.ConfigMMKV
  12. import com.ysnows.sultra.databinding.ActivitySearchBinding
  13. import com.ysnows.sultra.repository.SearchRepository
  14. import com.ysnows.sultra.utils.ad.AdUtils
  15. import com.ysnows.sultra.utils.fluid.FluidContentResizer
  16. import com.ysnows.sultra.vmodel.MainVModel
  17. import io.reactivex.android.schedulers.AndroidSchedulers
  18. class MainActivity : MBActivity<MainVModel, ActivitySearchBinding>() {
  19. private lateinit var mTTAd: TTNativeExpressAd
  20. override val isRxbus: Boolean = true
  21. override fun title(): String? = null
  22. override fun initCreate(savedInstanceState: Bundle?) {
  23. super.initCreate(savedInstanceState)
  24. if (MMKVManager.instance().decodeBool(ConfigMMKV.FIRST_OPEN, true)) {
  25. single(SplashActivity::class.java)
  26. } else {
  27. }
  28. }
  29. //绑定广告行为
  30. private fun bindAdListener(ad: TTNativeExpressAd) {
  31. ad.setExpressInteractionListener(object : TTNativeExpressAd.AdInteractionListener {
  32. override fun onAdDismiss() {
  33. QMUIKeyboardHelper.showKeyboard(binding.searchBar.binding.edtBar, 100)
  34. }
  35. override fun onAdClicked(view: View?, type: Int) {
  36. }
  37. override fun onAdShow(view: View?, type: Int) {
  38. }
  39. override fun onRenderFail(view: View?, msg: String, code: Int) {
  40. }
  41. override fun onRenderSuccess(view: View?, width: Float, height: Float) {
  42. //返回view的宽高 单位 dp
  43. //在渲染成功回调时展示广告,提升体验
  44. mTTAd.showInteractionExpressAd(this@MainActivity)
  45. // binding.layContainer.addView(mTTAd.expressAdView)
  46. }
  47. })
  48. if (ad.interactionType != TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
  49. return
  50. }
  51. //可选,下载监听设置
  52. ad.setDownloadListener(object : TTAppDownloadListener {
  53. override fun onIdle() {
  54. }
  55. override fun onDownloadActive(totalBytes: Long, currBytes: Long, fileName: String, appName: String) {
  56. // if (!mHasShowDownloadActive) {
  57. // mHasShowDownloadActive = true
  58. // }
  59. }
  60. override fun onDownloadPaused(totalBytes: Long, currBytes: Long, fileName: String, appName: String) {
  61. }
  62. override fun onDownloadFailed(totalBytes: Long, currBytes: Long, fileName: String, appName: String) {
  63. }
  64. override fun onInstalled(fileName: String, appName: String) {
  65. }
  66. override fun onDownloadFinished(totalBytes: Long, fileName: String, appName: String) {
  67. }
  68. })
  69. }
  70. override fun listeners() {
  71. super.listeners()
  72. FluidContentResizer.listen(this)
  73. }
  74. override fun binding(): ActivitySearchBinding = ActivitySearchBinding.inflate(layoutInflater)
  75. override fun transluent(): Boolean = true
  76. private fun checkAndInit() {
  77. // Thread {
  78. // if (SettingsUtil.clipboard_listener()) {
  79. // if (!CheckUtil.isServiceWorked(context(), "ClipBoardListenService")) {
  80. // runOnUiThread { ClipBoardListenService.start(context()) }
  81. // }
  82. // boolean floatPermission = PermissionUtils.checkFloatPermission(getContext());
  83. // if (!floatPermission) {
  84. // runOnUiThread(() -> PermissionUtils.openFloatPermission(MainActivity.this));
  85. // }
  86. // }
  87. // }.start()
  88. }
  89. override fun onResume() {
  90. super.onResume()
  91. AdUtils.loadInteractionAd("945450432", this)
  92. ?.observeOn(AndroidSchedulers.mainThread())
  93. ?.doOnNext() {
  94. mTTAd = it
  95. bindAdListener(it)
  96. }
  97. ?.subscribe()
  98. QMUIKeyboardHelper.showKeyboard(binding.searchBar.binding.edtBar, false)
  99. }
  100. override fun createRepository(): BRepository {
  101. return SearchRepository();
  102. }
  103. override fun vmClass(): Class<MainVModel> {
  104. return MainVModel::class.java
  105. }
  106. }