lmw
2025-04-24 718f31c92e2029d05260810435a2c70cef6e6ce5
app/src/main/java/com/sinata/xqmuse/ui/BGMSettingActivity.kt
@@ -24,13 +24,14 @@
    private val cardBannerAdapter by lazy { BgmBannerAdapter(list,this) }
    private val fromPrivacy by lazy { intent.getBooleanExtra("fromPrivacy",false) } //从私人定制过来,设置完成需要发送停止引导的事件
    private val player by lazy { AudioUtils() }
    private var isSilent = false //true:bgm静音
    override fun initClick() {
        iv_back.setOnClickListener { finish() }
        iv_silent.setOnClickListener {
            sb_voice.progress = 0
        }
        banner_landscape.setOnBannerListener { data, position ->
        banner_landscape.setOnBannerListener { _, position ->
            cardBannerAdapter.playPosition = position
            cardBannerAdapter.notifyDataSetChanged()
            player.startPlayMusic(this,list[position].audioFile)
@@ -50,16 +51,27 @@
            }
        })
        sb_silent.setOnClickListener {
            isSilent = !isSilent
            sb_silent.setImageResource(if (!isSilent) R.mipmap.sw_on else R.mipmap.sw_off)
        }
        tv_action.setOnClickListener {
            //存音量
            SPUtils.instance().put(Const.User.VOLUME,sb_voice.progress).apply()
            if (list.isNotEmpty()){ //存bgm和bg
                SPUtils.instance().put(Const.User.BG,list[banner_landscape.currentItem].imageUrl)
                    .put(Const.User.BGM,list[banner_landscape.currentItem].audioFile).apply()
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.CHANGE_BGM))
                tv_action.isEnabled = false
                HttpManager.saveUserHomeBackgroundMusic(list[banner_landscape.currentItem].id).request(this,success = {_,_->
                    //存音量
//                    SPUtils.instance().put(Const.User.VOLUME,sb_voice.progress).apply()
                    SPUtils.instance().put(Const.User.VOLUME,if (isSilent) 0 else 50).apply()
                    SPUtils.instance().put(Const.User.BG,list[banner_landscape.currentItem].imageUrl)
                        .put(Const.User.BGM,list[banner_landscape.currentItem].audioFile).apply()
                    EventBus.getDefault().post(EmptyEvent(Const.EventCode.CHANGE_BGM))
                    toast("保存成功")
                    startActivity<MainActivity>()
                }){_,_->
                    tv_action.isEnabled = true
                }
            }
            toast("保存成功")
            startActivity<MainActivity>()
            if (fromPrivacy)
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_GUIDE_AUDIO))
        }
@@ -71,7 +83,9 @@
        banner_landscape.setBannerGalleryEffect(110,12,0.85f)
        player.setOnAudioStatusUpdateListener(this)
        sb_voice.progress = SPUtils.instance().getInt(Const.User.VOLUME,50)
        player.setVolume(sb_voice.progress.toFloat()/100)
        isSilent = SPUtils.instance().getInt(Const.User.VOLUME,50) == 0
        sb_silent.setImageResource(if (!isSilent) R.mipmap.sw_on else R.mipmap.sw_off)
//        player.setVolume(sb_voice.progress.toFloat()/100)
        getData()
    }
@@ -83,6 +97,8 @@
            val indexOf = list.map { it.audioFile }.indexOf(bgm)
            if (indexOf>=0){
                banner_landscape.currentItem = indexOf
            }else if (list.size>2){
                banner_landscape.currentItem = 1
            }
            cardBannerAdapter.notifyDataSetChanged()
        }