123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- package com.ysnows.sultra.activity
- import android.os.Bundle
- import android.view.View
- import com.bytedance.sdk.openadsdk.TTAdConstant
- import com.bytedance.sdk.openadsdk.TTAppDownloadListener
- import com.bytedance.sdk.openadsdk.TTNativeExpressAd
- import com.qmuiteam.qmui.util.QMUIKeyboardHelper
- import com.ysnows.base.base.BRepository
- import com.ysnows.base.utils.MMKVManager
- import com.ysnows.sultra.base.MBActivity
- import com.ysnows.sultra.config.ConfigMMKV
- import com.ysnows.sultra.databinding.ActivitySearchBinding
- import com.ysnows.sultra.repository.SearchRepository
- import com.ysnows.sultra.utils.ad.AdUtils
- import com.ysnows.sultra.utils.fluid.FluidContentResizer
- import com.ysnows.sultra.vmodel.MainVModel
- import io.reactivex.android.schedulers.AndroidSchedulers
- class MainActivity : MBActivity<MainVModel, ActivitySearchBinding>() {
- private lateinit var mTTAd: TTNativeExpressAd
- override val isRxbus: Boolean = true
- override fun title(): String? = null
- override fun initCreate(savedInstanceState: Bundle?) {
- super.initCreate(savedInstanceState)
- if (MMKVManager.instance().decodeBool(ConfigMMKV.FIRST_OPEN, true)) {
- single(SplashActivity::class.java)
- } else {
- }
- }
- //绑定广告行为
- private fun bindAdListener(ad: TTNativeExpressAd) {
- ad.setExpressInteractionListener(object : TTNativeExpressAd.AdInteractionListener {
- override fun onAdDismiss() {
- QMUIKeyboardHelper.showKeyboard(binding.searchBar.binding.edtBar, 100)
- }
- override fun onAdClicked(view: View?, type: Int) {
- }
- override fun onAdShow(view: View?, type: Int) {
- }
- override fun onRenderFail(view: View?, msg: String, code: Int) {
- }
- override fun onRenderSuccess(view: View?, width: Float, height: Float) {
- //返回view的宽高 单位 dp
- //在渲染成功回调时展示广告,提升体验
- mTTAd.showInteractionExpressAd(this@MainActivity)
- // binding.layContainer.addView(mTTAd.expressAdView)
- }
- })
- if (ad.interactionType != TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
- return
- }
- //可选,下载监听设置
- ad.setDownloadListener(object : TTAppDownloadListener {
- override fun onIdle() {
- }
- override fun onDownloadActive(totalBytes: Long, currBytes: Long, fileName: String, appName: String) {
- // if (!mHasShowDownloadActive) {
- // mHasShowDownloadActive = true
- // }
- }
- override fun onDownloadPaused(totalBytes: Long, currBytes: Long, fileName: String, appName: String) {
- }
- override fun onDownloadFailed(totalBytes: Long, currBytes: Long, fileName: String, appName: String) {
- }
- override fun onInstalled(fileName: String, appName: String) {
- }
- override fun onDownloadFinished(totalBytes: Long, fileName: String, appName: String) {
- }
- })
- }
- override fun listeners() {
- super.listeners()
- FluidContentResizer.listen(this)
- }
- override fun binding(): ActivitySearchBinding = ActivitySearchBinding.inflate(layoutInflater)
- override fun transluent(): Boolean = true
- private fun checkAndInit() {
- // Thread {
- // if (SettingsUtil.clipboard_listener()) {
- // if (!CheckUtil.isServiceWorked(context(), "ClipBoardListenService")) {
- // runOnUiThread { ClipBoardListenService.start(context()) }
- // }
- // boolean floatPermission = PermissionUtils.checkFloatPermission(getContext());
- // if (!floatPermission) {
- // runOnUiThread(() -> PermissionUtils.openFloatPermission(MainActivity.this));
- // }
- // }
- // }.start()
- }
- override fun onResume() {
- super.onResume()
- AdUtils.loadInteractionAd("945450432", this)
- ?.observeOn(AndroidSchedulers.mainThread())
- ?.doOnNext() {
- mTTAd = it
- bindAdListener(it)
- }
- ?.subscribe()
- QMUIKeyboardHelper.showKeyboard(binding.searchBar.binding.edtBar, false)
- }
- override fun createRepository(): BRepository {
- return SearchRepository();
- }
- override fun vmClass(): Class<MainVModel> {
- return MainVModel::class.java
- }
- }
|