| | |
| | | package com.sinata.xqmuse.ui |
| | | |
| | | class BGMSettingActivity :TransparentStatusBarActivity(){ |
| | | override fun setContentView(): Int { |
| | | TODO("Not yet implemented") |
| | | } |
| | | import android.widget.SeekBar |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import com.sinata.xqmuse.MainActivity |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.network.HttpManager |
| | | import com.sinata.xqmuse.network.entity.BGMBean |
| | | import com.sinata.xqmuse.network.request |
| | | import com.sinata.xqmuse.ui.home.adapter.BgmBannerAdapter |
| | | import com.sinata.xqmuse.utils.AudioUtils |
| | | import com.sinata.xqmuse.utils.Const |
| | | import com.sinata.xqmuse.utils.event.EmptyEvent |
| | | import kotlinx.android.synthetic.main.activity_bgm.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.jetbrains.anko.startActivity |
| | | import org.jetbrains.anko.toast |
| | | |
| | | class BGMSettingActivity :TransparentStatusBarActivity(), AudioUtils.OnAudioStatusUpdateListener { |
| | | override fun setContentView() = R.layout.activity_bgm |
| | | |
| | | private val list = arrayListOf<BGMBean>() |
| | | 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() { |
| | | TODO("Not yet implemented") |
| | | iv_back.setOnClickListener { finish() } |
| | | iv_silent.setOnClickListener { |
| | | sb_voice.progress = 0 |
| | | } |
| | | banner_landscape.setOnBannerListener { _, position -> |
| | | cardBannerAdapter.playPosition = position |
| | | cardBannerAdapter.notifyDataSetChanged() |
| | | player.startPlayMusic(this,list[position].audioFile) |
| | | if (banner_landscape.currentItem != position){ |
| | | banner_landscape.setCurrentItem(position,true) |
| | | } |
| | | } |
| | | sb_voice.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{ |
| | | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { |
| | | player.setVolume(progress.toFloat()/100) |
| | | } |
| | | |
| | | override fun onStartTrackingTouch(seekBar: SeekBar?) { |
| | | } |
| | | |
| | | override fun onStopTrackingTouch(seekBar: SeekBar?) { |
| | | } |
| | | }) |
| | | |
| | | sb_silent.setOnClickListener { |
| | | isSilent = !isSilent |
| | | sb_silent.setImageResource(if (!isSilent) R.mipmap.sw_on else R.mipmap.sw_off) |
| | | } |
| | | |
| | | tv_action.setOnClickListener { |
| | | if (list.isNotEmpty()){ //存bgm和bg |
| | | 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 |
| | | } |
| | | } |
| | | if (fromPrivacy) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_GUIDE_AUDIO)) |
| | | } |
| | | } |
| | | |
| | | override fun initView() { |
| | | TODO("Not yet implemented") |
| | | titleBar.gone() |
| | | banner_landscape.adapter = cardBannerAdapter |
| | | banner_landscape.setBannerGalleryEffect(110,12,0.85f) |
| | | player.setOnAudioStatusUpdateListener(this) |
| | | sb_voice.progress = SPUtils.instance().getInt(Const.User.VOLUME,50) |
| | | 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() |
| | | } |
| | | |
| | | private fun getData(){ |
| | | HttpManager.getHomeBackgroun().request(this){_,data-> |
| | | list.clear() |
| | | list.addAll(data?: arrayListOf()) |
| | | val bgm = SPUtils.instance().getString(Const.User.BGM) |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | override fun onUpdate(db: Double, time: Long) { |
| | | |
| | | } |
| | | |
| | | override fun onStop(filePath: String?) { |
| | | } |
| | | |
| | | override fun onStartPlay() { |
| | | } |
| | | |
| | | override fun onFinishPlay() { |
| | | val p = cardBannerAdapter.playPosition |
| | | cardBannerAdapter.playPosition = -1 |
| | | cardBannerAdapter.notifyItemChanged(p) |
| | | } |
| | | |
| | | override fun onGetDuration(duration: Int) { |
| | | } |
| | | |
| | | override fun onPause() { |
| | | super.onPause() |
| | | player.stopPlayMusic(true) |
| | | } |
| | | } |