看广告act+1
This commit is contained in:
parent
a8ab37a17b
commit
cfe4acbb78
|
|
@ -35,6 +35,7 @@
|
||||||
<activity android:name=".features.feedback.FeedbackActivity" android:exported="false" />
|
<activity android:name=".features.feedback.FeedbackActivity" android:exported="false" />
|
||||||
<activity android:name=".features.withdrawrecord.WithdrawRecordActivity" android:exported="false" />
|
<activity android:name=".features.withdrawrecord.WithdrawRecordActivity" android:exported="false" />
|
||||||
<activity android:name=".features.privacy.PrivacyActivity" android:exported="false" />
|
<activity android:name=".features.privacy.PrivacyActivity" android:exported="false" />
|
||||||
|
<activity android:name=".features.watchad.WatchAdActivity" android:exported="false" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,20 @@ package com.gamedog.vididin.features.watchad
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.CountDownTimer
|
||||||
|
import android.os.PersistableBundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import com.ama.core.architecture.appBase.AppViewsActivity
|
import com.ama.core.architecture.appBase.AppViewsActivity
|
||||||
|
import com.ama.core.architecture.ext.toast
|
||||||
|
import com.ama.core.architecture.util.AndroidUtil
|
||||||
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||||
|
import com.gamedog.vididin.R
|
||||||
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
|
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlin.getValue
|
import kotlin.getValue
|
||||||
|
|
@ -22,6 +30,10 @@ class WatchAdActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnT
|
||||||
override val mViewModel: ViewModel by viewModels()
|
override val mViewModel: ViewModel by viewModels()
|
||||||
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
||||||
|
|
||||||
|
|
||||||
|
private lateinit var mCountDownTimer: CountDownTimer
|
||||||
|
private var mTaskUUID: Int = 0
|
||||||
|
|
||||||
override fun ViewBinding.initViews() {
|
override fun ViewBinding.initViews() {
|
||||||
with(binding) {
|
with(binding) {
|
||||||
|
|
||||||
|
|
@ -31,15 +43,49 @@ class WatchAdActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnT
|
||||||
|
|
||||||
override fun ViewBinding.initWindowInsets() {
|
override fun ViewBinding.initWindowInsets() {
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(contentRoot) { v, insets ->
|
ViewCompat.setOnApplyWindowInsetsListener(contentRoot) { v, insets ->
|
||||||
val systemBars =
|
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
||||||
insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
|
||||||
v.updatePadding(top = systemBars.top)
|
v.updatePadding(top = systemBars.top)
|
||||||
insets
|
insets
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ViewBinding.initListeners() {
|
override fun ViewBinding.initListeners() {
|
||||||
//TODO("Not yet implemented")
|
onBackPressedDispatcher.addCallback(this@WatchAdActivity) {
|
||||||
|
AndroidUtil.showToast("Can't exit while watching video")
|
||||||
|
}
|
||||||
|
|
||||||
|
stateCounter()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun notifyAdWatchFinish() {
|
||||||
|
NotifyMan.instance().sendEvent(mTaskUUID, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stateCounter() {
|
||||||
|
mCountDownTimer = object : CountDownTimer(5000, 1000) {
|
||||||
|
override fun onTick(millisUntilFinished: Long) {
|
||||||
|
val secondsRemaining = millisUntilFinished / 1000
|
||||||
|
binding.tvAdCounter.text = "${secondsRemaining}"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFinish() {
|
||||||
|
notifyAdWatchFinish()
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mCountDownTimer.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun readIntent(intent: Intent) {
|
||||||
|
super.readIntent(intent)
|
||||||
|
mTaskUUID = intent.getIntExtra(KEY_TASKID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
mCountDownTimer.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ViewBinding.initObservers() {
|
override fun ViewBinding.initObservers() {
|
||||||
|
|
@ -56,8 +102,12 @@ class WatchAdActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnT
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal fun startActivity(activity: Activity) {
|
private val KEY_TASKID = "KEY_TASKID"
|
||||||
activity.startActivity(Intent(activity.applicationContext, WatchAdActivity::class.java))
|
|
||||||
|
internal fun startActivity(activity: Activity, taskUUID: Int) {
|
||||||
|
val intent = Intent(activity.applicationContext, WatchAdActivity::class.java)
|
||||||
|
intent.putExtra(KEY_TASKID, taskUUID)
|
||||||
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
package com.gamedog.vididin.main
|
package com.gamedog.vididin.main
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import com.ama.core.architecture.util.AndroidUtil
|
||||||
import com.ama.core.architecture.util.setOnClickBatch
|
import com.ama.core.architecture.util.setOnClickBatch
|
||||||
import com.ama.core.architecture.widget.BindingDialog
|
import com.ama.core.architecture.widget.BindingDialog
|
||||||
import com.gamedog.vididin.databinding.DialogWatchVideoBinding
|
import com.gamedog.vididin.databinding.DialogWatchVideoBinding
|
||||||
import com.gamedog.vididin.main.fragments.task.RewardDetail
|
import com.gamedog.vididin.router.Router
|
||||||
|
|
||||||
|
|
||||||
class WatchVideoDialog(context: Activity) : BindingDialog<DialogWatchVideoBinding>(context, DialogWatchVideoBinding::inflate) {
|
class WatchVideoDialog(context: Activity) : BindingDialog<DialogWatchVideoBinding>(context, DialogWatchVideoBinding::inflate) {
|
||||||
private lateinit var mDataList: List<RewardDetail>
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
build()
|
build()
|
||||||
|
|
@ -30,7 +29,6 @@ class WatchVideoDialog(context: Activity) : BindingDialog<DialogWatchVideoBindin
|
||||||
}
|
}
|
||||||
flAction -> {
|
flAction -> {
|
||||||
gotoWatchVideo()
|
gotoWatchVideo()
|
||||||
dismiss()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +36,13 @@ class WatchVideoDialog(context: Activity) : BindingDialog<DialogWatchVideoBindin
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotoWatchVideo() {
|
private fun gotoWatchVideo() {
|
||||||
|
val taskUUID = AndroidUtil.genRandomInt(500000, Int.MAX_VALUE)
|
||||||
|
registerEvents({
|
||||||
|
AndroidUtil.showToast("广告任务完成")
|
||||||
|
dismiss()
|
||||||
|
}, taskUUID)
|
||||||
|
|
||||||
|
Router.WatchAd.startActivity(mActivity, taskUUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class DefaultVersionRouter: IRouterVersion {
|
||||||
|
|
||||||
|
|
||||||
class DefaultWatchAdRouter: IRouterWatchAd {
|
class DefaultWatchAdRouter: IRouterWatchAd {
|
||||||
override fun startActivity(activity: Activity) {
|
override fun startActivity(activity: Activity, taskUUID: Int) {
|
||||||
WatchAdActivity.Companion.startActivity(activity)
|
WatchAdActivity.Companion.startActivity(activity, taskUUID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ interface IRouterSplash {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IRouterWatchAd {
|
interface IRouterWatchAd {
|
||||||
fun startActivity(activity: Activity)
|
fun startActivity(activity: Activity, taskUUID: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:orientation="vertical"
|
|
||||||
android:id="@+id/content_root" >
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
|
@ -14,6 +12,22 @@
|
||||||
android:src="@mipmap/bg_record_win_rgiht"
|
android:src="@mipmap/bg_record_win_rgiht"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
<FrameLayout
|
||||||
|
android:id="@+id/content_root"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/tv_ad_counter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:text="ad showing"
|
||||||
|
/>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ama.core.architecture.base.views
|
package com.ama.core.architecture.base.views
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
|
@ -55,6 +56,7 @@ abstract class BaseViewsActivity<Binding : ViewBinding, UiState : Any,
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
initEdgeToEdge()
|
initEdgeToEdge()
|
||||||
|
readIntent(intent)
|
||||||
// 内容
|
// 内容
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
// 初始化
|
// 初始化
|
||||||
|
|
@ -65,6 +67,15 @@ abstract class BaseViewsActivity<Binding : ViewBinding, UiState : Any,
|
||||||
binding.initObservers()
|
binding.initObservers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun readIntent(intent: Intent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
readIntent(intent)
|
||||||
|
}
|
||||||
|
|
||||||
open fun initEdgeToEdge() {
|
open fun initEdgeToEdge() {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ama.core.architecture.interfaces
|
package com.ama.core.architecture.interfaces
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
|
|
@ -17,6 +18,8 @@ interface ViewBindingActivity<Binding : ViewBinding, UiState> {
|
||||||
fun Binding.initObservers()
|
fun Binding.initObservers()
|
||||||
|
|
||||||
fun Binding.onUiStateCollect(uiState: UiState)
|
fun Binding.onUiStateCollect(uiState: UiState)
|
||||||
|
|
||||||
|
fun readIntent(intent: Intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ViewBindingFragment<Binding : ViewBinding, UiState> {
|
interface ViewBindingFragment<Binding : ViewBinding, UiState> {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,26 @@
|
||||||
package com.ama.core.architecture.util
|
package com.ama.core.architecture.util
|
||||||
|
|
||||||
import android.app.Activity
|
import android.widget.Toast
|
||||||
import android.content.Intent
|
|
||||||
import com.ama.core.architecture.BaseApp
|
import com.ama.core.architecture.BaseApp
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class AndroidUtil private constructor() {
|
class AndroidUtil private constructor() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|
||||||
|
fun genRandomInt(rangeBegin: Int, rangeEnd: Int): Int {
|
||||||
|
return Random.nextInt(rangeBegin, rangeEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun showToast(strRes: Int) {
|
||||||
|
Toast.makeText(BaseApp.appContext(), strRes, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showToast(str: String) {
|
||||||
|
Toast.makeText(BaseApp.appContext(), str, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.ama.core.architecture.R
|
import com.ama.core.architecture.R
|
||||||
import com.ama.core.architecture.util.ScreenUtils
|
import com.ama.core.architecture.util.ScreenUtils
|
||||||
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||||
import com.ama.core.common.util.dp
|
import com.ama.core.common.util.dp
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,6 +49,20 @@ open class BindingDialog<VB : ViewBinding>(protected val mActivity: Activity,
|
||||||
lateinit var mBinding: VB
|
lateinit var mBinding: VB
|
||||||
var currEvent: Lifecycle.Event? = null
|
var currEvent: Lifecycle.Event? = null
|
||||||
|
|
||||||
|
private var mEventCallback: NotifyMan.ICallback? = null
|
||||||
|
|
||||||
|
protected fun registerEvents(onEvents: ((NotifyMan.NotifyData<*>?)->Unit), vararg eventTypes: Int) {
|
||||||
|
if (mEventCallback == null) {
|
||||||
|
mEventCallback = object : NotifyMan.ICallback(true) {
|
||||||
|
override fun onEvent(data: NotifyMan.NotifyData<*>?) {
|
||||||
|
onEvents.invoke(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyMan.instance().register(mEventCallback, *eventTypes)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun getRoundRectDrawable(radius: Int, color: Int): ShapeDrawable {
|
fun getRoundRectDrawable(radius: Int, color: Int): ShapeDrawable {
|
||||||
|
|
@ -78,6 +93,9 @@ open class BindingDialog<VB : ViewBinding>(protected val mActivity: Activity,
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
mBinding = inflate(layoutInflater)
|
mBinding = inflate(layoutInflater)
|
||||||
setContentView(mBinding.root)
|
setContentView(mBinding.root)
|
||||||
|
setOnDismissListener {
|
||||||
|
NotifyMan.instance().unregister(mEventCallback)
|
||||||
|
}
|
||||||
init()
|
init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,6 +106,7 @@ open class BindingDialog<VB : ViewBinding>(protected val mActivity: Activity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
if (mActivity is ComponentActivity) {
|
if (mActivity is ComponentActivity) {
|
||||||
mActivity.lifecycle.addObserver(this)
|
mActivity.lifecycle.addObserver(this)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue