两个activity hilt 以及 route 配置
This commit is contained in:
parent
ad1735ad4e
commit
13410ad822
|
|
@ -0,0 +1,29 @@
|
|||
package com.gamedog.vididin.di
|
||||
|
||||
import com.gamedog.vididin.features.benefit.BenefitRouter
|
||||
import com.gamedog.vididin.features.benefit.DefaultBenefitRouter
|
||||
import com.gamedog.vididin.features.zero.DefaultZeroBuyRouter
|
||||
import com.gamedog.vididin.features.zero.ZeroBuyRouter
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object BenefitModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRouter(): BenefitRouter = DefaultBenefitRouter()
|
||||
}
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object ZeroBuyModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRouter(): ZeroBuyRouter = DefaultZeroBuyRouter()
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ import com.gamedog.vididin.core.router.interfaces.HomeRouter
|
|||
import com.gamedog.vididin.core.router.interfaces.LoginRouter
|
||||
import com.gamedog.vididin.core.router.interfaces.MineRouter
|
||||
import com.gamedog.vididin.core.router.interfaces.TaskRouter
|
||||
import com.gamedog.vididin.features.benefit.BenefitRouter
|
||||
import com.gamedog.vididin.features.zero.ZeroBuyRouter
|
||||
import dagger.hilt.EntryPoint
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
|
|
@ -16,5 +18,10 @@ interface RouterEntryPoint {
|
|||
fun taskRouter(): TaskRouter
|
||||
fun mineRouter(): MineRouter
|
||||
fun loginRouter(): LoginRouter
|
||||
|
||||
|
||||
fun benefitRouter(): BenefitRouter
|
||||
fun zeroBuyRouter(): ZeroBuyRouter
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package com.gamedog.vididin.features.benefit
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
interface BenefitRouter {
|
||||
fun startActivity(activity: Activity)
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.gamedog.vididin.features.benefit
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
class DefaultBenefitRouter: BenefitRouter {
|
||||
override fun startActivity(activity: Activity) {
|
||||
BenefitActivity.startActivity(activity)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.gamedog.vididin.features.zero
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
class DefaultZeroBuyRouter: ZeroBuyRouter {
|
||||
override fun startActivity(activity: Activity) {
|
||||
ZeroBuyActivity.Companion.startActivity(activity)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.gamedog.vididin.features.zero
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
interface ZeroBuyRouter {
|
||||
fun startActivity(activity: Activity)
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import com.ama.core.architecture.appBase.AppViewsEmptyViewModelFragment
|
|||
import com.ama.core.common.widget.PopMenuIconView
|
||||
import com.gamedog.vididin.R
|
||||
import com.gamedog.vididin.beans.YoutubeVideo
|
||||
import com.gamedog.vididin.router.Router
|
||||
import com.gamedog.vididin.widget.MyPlayerControlView
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer
|
||||
|
|
@ -55,7 +56,7 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
popMenu.setMenuList(
|
||||
mutableListOf(
|
||||
PopMenuIconView.MenuItem(R.mipmap.home_menu_1) {
|
||||
|
||||
Router.Benefit.startActivity(requireActivity())
|
||||
},
|
||||
PopMenuIconView.MenuItem(R.mipmap.home_menu_2) {
|
||||
|
||||
|
|
@ -64,95 +65,11 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
|
||||
},
|
||||
PopMenuIconView.MenuItem(R.mipmap.home_menu_4) {
|
||||
|
||||
Router.Benefit.startActivity(requireActivity())
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
fun initAndStartPlay() {
|
||||
/*
|
||||
val youtubePlayerView: YouTubePlayerView = binding?.youtubePlayerView!!
|
||||
|
||||
val iFramePlayerOptions = IFramePlayerOptions.Builder(requireContext())
|
||||
.rel(1)
|
||||
.ccLoadPolicy(1)
|
||||
.controls(0)
|
||||
.listType("playlist")
|
||||
.list(PLAYLIST_ID)
|
||||
.fullscreen(0)
|
||||
.build()
|
||||
youtubePlayerView.initialize(object : YouTubePlayerListener {
|
||||
override fun onReady(youTubePlayer: YouTubePlayer) {
|
||||
|
||||
}
|
||||
|
||||
override fun onStateChange(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
state: PlayerConstants.PlayerState
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onPlaybackQualityChange(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
playbackQuality: PlayerConstants.PlaybackQuality
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onPlaybackRateChange(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
playbackRate: PlayerConstants.PlaybackRate
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onError(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
error: PlayerConstants.PlayerError
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onCurrentSecond(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
second: Float
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onVideoDuration(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
duration: Float
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onVideoLoadedFraction(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
loadedFraction: Float
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onVideoId(
|
||||
youTubePlayer: YouTubePlayer,
|
||||
videoId: String
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun onApiChange(youTubePlayer: YouTubePlayer) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, iFramePlayerOptions)*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun ViewBinding.initListeners() {
|
||||
ivStar.setOnClickListener {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import com.gamedog.vididin.core.router.interfaces.LoginRouter
|
|||
import com.gamedog.vididin.core.router.interfaces.MineRouter
|
||||
import com.gamedog.vididin.core.router.interfaces.TaskRouter
|
||||
import com.gamedog.vididin.di.RouterEntryPoint
|
||||
import com.gamedog.vididin.features.benefit.BenefitRouter
|
||||
import com.gamedog.vididin.features.zero.ZeroBuyRouter
|
||||
import dagger.hilt.android.EntryPointAccessors
|
||||
import kotlin.getValue
|
||||
import kotlin.jvm.java
|
||||
|
|
@ -23,5 +25,9 @@ object Router : RouterContract {
|
|||
override val Mine: MineRouter by lazy { routerEntryPoint.mineRouter() }
|
||||
override val Login: LoginRouter by lazy { routerEntryPoint.loginRouter() }
|
||||
|
||||
|
||||
|
||||
override val Benefit: BenefitRouter by lazy { routerEntryPoint.benefitRouter() }
|
||||
override val ZeroBuy: ZeroBuyRouter by lazy { routerEntryPoint.zeroBuyRouter() }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.gamedog.vididin.core.router.interfaces.HomeRouter
|
|||
import com.gamedog.vididin.core.router.interfaces.LoginRouter
|
||||
import com.gamedog.vididin.core.router.interfaces.TaskRouter
|
||||
import com.gamedog.vididin.core.router.interfaces.MineRouter
|
||||
import com.gamedog.vididin.features.benefit.BenefitRouter
|
||||
import com.gamedog.vididin.features.zero.ZeroBuyRouter
|
||||
|
||||
|
||||
@Suppress("PropertyName")
|
||||
|
|
@ -12,4 +14,7 @@ interface RouterContract {
|
|||
val Task: TaskRouter
|
||||
val Mine: MineRouter
|
||||
val Login: LoginRouter
|
||||
|
||||
val Benefit: BenefitRouter
|
||||
val ZeroBuy: ZeroBuyRouter
|
||||
}
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
package com.ama.core.architecture.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.setPadding
|
||||
import com.ama.core.architecture.R
|
||||
import com.ama.core.common.util.dp
|
||||
import com.ama.core.common.util.sp
|
||||
|
||||
class CustomTitleBar @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private lateinit var ivLeft: ImageView
|
||||
private lateinit var tvTitle: TextView
|
||||
private lateinit var llRight: LinearLayout
|
||||
|
||||
// 点击回调
|
||||
private var onLeftClick: (() -> Unit)? = null
|
||||
private var onRightButtonClick: ((index: Int) -> Unit)? = null
|
||||
|
||||
// 右侧按钮列表
|
||||
private val rightButtons = mutableListOf<ImageView>()
|
||||
|
||||
init {
|
||||
initView()
|
||||
initAttributes(attrs, defStyleAttr)
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
// 设置水平方向布局
|
||||
orientation = HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
|
||||
// 设置默认内边距
|
||||
setPadding(16.dp)
|
||||
|
||||
// 创建左侧ImageView
|
||||
ivLeft = ImageView(context).apply {
|
||||
layoutParams = LayoutParams(
|
||||
24.dp,
|
||||
24.dp
|
||||
).apply {
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
}
|
||||
scaleType = ImageView.ScaleType.CENTER_INSIDE
|
||||
setOnClickListener { onLeftClick?.invoke() }
|
||||
}
|
||||
|
||||
// 创建中间标题TextView
|
||||
tvTitle = TextView(context).apply {
|
||||
layoutParams = LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT
|
||||
).apply {
|
||||
weight = 1f // 占据剩余空间
|
||||
gravity = Gravity.CENTER
|
||||
}
|
||||
gravity = Gravity.CENTER
|
||||
setTextColor(ContextCompat.getColor(context, android.R.color.white))
|
||||
textSize = 18f
|
||||
}
|
||||
|
||||
// 创建右侧LinearLayout
|
||||
llRight = LinearLayout(context).apply {
|
||||
layoutParams = LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT
|
||||
).apply {
|
||||
gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||
}
|
||||
orientation = HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
}
|
||||
|
||||
// 添加子视图
|
||||
addView(ivLeft)
|
||||
addView(tvTitle)
|
||||
addView(llRight)
|
||||
}
|
||||
|
||||
private fun initAttributes(attrs: AttributeSet?, defStyleAttr: Int) {
|
||||
val typedArray = context.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.CustomTitleBar,
|
||||
defStyleAttr,
|
||||
0
|
||||
)
|
||||
|
||||
try {
|
||||
// 设置标题文本
|
||||
tvTitle.text = typedArray.getString(R.styleable.CustomTitleBar_titleText) ?: ""
|
||||
|
||||
// 设置标题颜色
|
||||
val titleColor = typedArray.getColor(
|
||||
R.styleable.CustomTitleBar_titleTextColor,
|
||||
ContextCompat.getColor(context, android.R.color.white)
|
||||
)
|
||||
tvTitle.setTextColor(titleColor)
|
||||
|
||||
// 设置标题大小
|
||||
val titleSize = typedArray.getDimension(
|
||||
R.styleable.CustomTitleBar_titleTextSize,
|
||||
18f.sp.toFloat()
|
||||
)
|
||||
tvTitle.textSize = titleSize.sp.toFloat()
|
||||
|
||||
// 设置左侧图标
|
||||
val leftIconRes = typedArray.getResourceId(R.styleable.CustomTitleBar_leftIcon, 0)
|
||||
if (leftIconRes != 0) {
|
||||
setLeftIcon(leftIconRes)
|
||||
}
|
||||
|
||||
// 设置左侧图标可见性
|
||||
val leftIconVisible = typedArray.getBoolean(
|
||||
R.styleable.CustomTitleBar_leftIconVisible,
|
||||
true
|
||||
)
|
||||
ivLeft.visibility = if (leftIconVisible) VISIBLE else GONE
|
||||
|
||||
// 设置背景颜色
|
||||
val background = typedArray.getColor(
|
||||
R.styleable.CustomTitleBar_titleBarBackground,
|
||||
ContextCompat.getColor(context, R.color.title_bar_default_bg)
|
||||
)
|
||||
setBackgroundColor(background)
|
||||
|
||||
// 设置右侧按钮间距
|
||||
val buttonSpacing = typedArray.getDimension(
|
||||
R.styleable.CustomTitleBar_rightButtonSpacing,
|
||||
8.dp.toFloat()
|
||||
)
|
||||
llRight.setPadding(0, 0, 0, 0)
|
||||
|
||||
} finally {
|
||||
typedArray.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置左侧图标
|
||||
*/
|
||||
fun setLeftIcon(@DrawableRes resId: Int) {
|
||||
ivLeft.setImageResource(resId)
|
||||
ivLeft.visibility = VISIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置左侧图标可见性
|
||||
*/
|
||||
fun setLeftIconVisible(visible: Boolean) {
|
||||
ivLeft.visibility = if (visible) VISIBLE else GONE
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题文本
|
||||
*/
|
||||
fun setTitle(text: String) {
|
||||
tvTitle.text = text
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题颜色
|
||||
*/
|
||||
fun setTitleColor(color: Int) {
|
||||
tvTitle.setTextColor(color)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题大小
|
||||
*/
|
||||
fun setTitleSize(sp: Float) {
|
||||
tvTitle.textSize = sp
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加右侧按钮
|
||||
*/
|
||||
fun addRightButton(@DrawableRes resId: Int, spacing: Int = 8.dp): Int {
|
||||
val imageView = ImageView(context).apply {
|
||||
layoutParams = LayoutParams(
|
||||
24.dp,
|
||||
24.dp
|
||||
).apply {
|
||||
if (rightButtons.isNotEmpty()) {
|
||||
marginStart = spacing
|
||||
}
|
||||
}
|
||||
setImageResource(resId)
|
||||
scaleType = ImageView.ScaleType.CENTER_INSIDE
|
||||
setOnClickListener {
|
||||
onRightButtonClick?.invoke(rightButtons.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
rightButtons.add(imageView)
|
||||
llRight.addView(imageView)
|
||||
|
||||
return rightButtons.size - 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除右侧按钮
|
||||
*/
|
||||
fun removeRightButton(index: Int) {
|
||||
if (index in 0 until rightButtons.size) {
|
||||
llRight.removeView(rightButtons[index])
|
||||
rightButtons.removeAt(index)
|
||||
// 更新剩余按钮的点击事件索引
|
||||
updateRightButtonsClickListeners()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空右侧按钮
|
||||
*/
|
||||
fun clearRightButtons() {
|
||||
llRight.removeAllViews()
|
||||
rightButtons.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置左侧点击回调
|
||||
*/
|
||||
fun setOnLeftClickListener(listener: () -> Unit) {
|
||||
onLeftClick = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置右侧按钮点击回调
|
||||
*/
|
||||
fun setOnRightButtonClickListener(listener: (index: Int) -> Unit) {
|
||||
onRightButtonClick = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新右侧按钮点击监听器
|
||||
*/
|
||||
private fun updateRightButtonsClickListeners() {
|
||||
rightButtons.forEachIndexed { index, imageView ->
|
||||
imageView.setOnClickListener {
|
||||
onRightButtonClick?.invoke(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue