Commit 34c7325f authored by jyx's avatar jyx

代码优化

parent 41edb128
......@@ -10,4 +10,8 @@
app/build
picture_library/build
ucrop/build
videocache/build
\ No newline at end of file
videocache/build
wxpay/build
rxpay/build
alipay/build
\ No newline at end of file
package com.duben.dayplaylet.mvp.model
data class MusicBean(
val completeCount: Int, //完成的次数(这里的次数不包括翻倍)
val nextIsAd: Boolean, //接下来是不是要看广告了
val openCash: Boolean, //还能不能提现,不能提现就不展示提现入口了
val turnNeedCount: Int //提现需要的次数
)
\ No newline at end of file
package com.duben.dayplaylet.mvp.presenters
import com.duben.dayplaylet.manager.AppHttpManager
import com.duben.dayplaylet.mvp.model.BaseResponse
import com.duben.dayplaylet.mvp.model.MusicBean
import com.duben.dayplaylet.mvp.views.MusicView
import com.duben.library.net.neterror.BaseSubscriber
import com.duben.library.net.neterror.Throwable
class MusicPresenter : BasePresenter<MusicView>() {
// 猜歌页信息
fun rdSongMsg() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.rdSongMsg(),
object : BaseSubscriber<BaseResponse<MusicBean>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.showToast(e.message)
}
override fun onNext(baseResponse: BaseResponse<MusicBean>) {
if (isLinkView) return
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> {
view.rdSongMsgSuc(baseResponse.data)
}
else -> {
view.showToast(message)
}
}
}
})
}
}
\ No newline at end of file
package com.duben.dayplaylet.mvp.views
import com.duben.dayplaylet.mvp.model.MusicBean
interface MusicView : BaseView {
fun rdSongMsgSuc(data: MusicBean)
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.duben.dayplaylet.net;
import android.content.Context;
import android.text.TextUtils;
import com.duben.dayplaylet.mvp.model.MusicBean;
import com.google.gson.JsonObject;
import com.duben.dayplaylet.BuildConfig;
import com.duben.dayplaylet.mvp.model.BannerList;
......@@ -225,6 +226,14 @@ public interface LoanService {
@POST("api/reportAddCoinMsg")
Observable<BaseResponse<JsonObject>> reportAddCoinMsg(@Body Map<String, Object> vo);
/**
* 猜歌页信息
*
* @return
*/
@POST("api/reward/rdSongMsg")
Observable<BaseResponse<MusicBean>> rdSongMsg();
/**
* 默认http工厂
*/
......
......@@ -13,22 +13,31 @@ import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.Toast
import androidx.annotation.Nullable
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.bytedance.sdk.dp.*
import com.duben.dayplaylet.R
import com.duben.dayplaylet.common.AppConfig
import com.duben.dayplaylet.common.Constant
import com.duben.dayplaylet.manager.DPHolder
import com.duben.dayplaylet.mvp.model.MusicBean
import com.duben.dayplaylet.mvp.presenters.MusicPresenter
import com.duben.dayplaylet.mvp.views.MusicView
import com.duben.dayplaylet.ui.fragment.base.LazyLoadBaseFragment
import com.duben.dayplaylet.utils.BubbleUtils
import com.duben.dayplaylet.utils.LogUtil
import kotlinx.android.synthetic.main.fragment_music.*
import kotlinx.android.synthetic.main.layout_draw_header.*
class MusicFragment : LazyLoadBaseFragment() {
/**
* 猜歌
*/
class MusicFragment : LazyLoadBaseFragment(), MusicView {
private val TAG = "MusicFragment"
private val musicPresenter by lazy { MusicPresenter() }
private var mIDPWidget: IDPWidget? = null
private var mDrawFragment: Fragment? = null
......@@ -37,6 +46,7 @@ class MusicFragment : LazyLoadBaseFragment() {
override fun getContentViewLayoutID() = R.layout.fragment_music
override fun initViewsAndEvents() {
musicPresenter.attachView(this)
btn1.setOnClickListener {
addAnimation(it, iv_gold)
......@@ -64,8 +74,9 @@ class MusicFragment : LazyLoadBaseFragment() {
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_TWO) {
mIDPWidget?.fragment?.onResume()
mIDPWidget?.fragment?.userVisibleHint = true
musicPresenter.rdSongMsg()
}
}
......@@ -88,307 +99,222 @@ class MusicFragment : LazyLoadBaseFragment() {
private fun initDrawWidget() {
mIDPWidget =
DPHolder.getInstance().buildDrawWidget(DPWidgetDrawParams.obtain().liveAdCodeId(
"947474066"
).liveNativeAdCodeId("947474068")
.adOffset(0) //单位 dp,为 0 时可以不设置
.quizMode(1)
.hideClose(true, null)
.listener(object : IDPDrawListener() {
override fun onDPRefreshFinish() {
LogUtil.d(
TAG,
"onDPRefreshFinish"
)
}
override fun onDPPageChange(position: Int) {
LogUtil.d(
TAG,
"onDPPageChange: $position"
)
}
override fun onDPPageChange(position: Int, map: Map<String, Any>) {
if (map == null) {
return
}
mPos = position
LogUtil.d(
TAG,
"onDPPageChange: $position, map = $map"
)
}
override fun onCreateQuizView(container: ViewGroup): View {
val quizView: View = LayoutInflater.from(container.context)
.inflate(R.layout.media_layout_quiz, container, false)
LogUtil.d(
TAG,
"onCreateQuizView"
)
return quizView
}
override fun onQuizBindData(
view: View,
options: List<String>,
answer: Int,
lastAnswer: Int,
quizHandler: IDPQuizHandler,
feedParamsForCallback: Map<String, Any>
) {
super.onQuizBindData(
view,
options,
answer,
lastAnswer,
quizHandler,
feedParamsForCallback
)
val option0 = view.findViewById<Button>(R.id.quiz_option0)
val option1 = view.findViewById<Button>(R.id.quiz_option1)
val optionsList: MutableList<Button> = ArrayList()
optionsList.add(option0)
optionsList.add(option1)
for (i in optionsList.indices) {
val right = answer == i
val background: Int =
if (right) R.drawable.selector_quzi_button_ok else R.drawable.selector_quzi_button_error
val button = optionsList[i]
button.text = options[i]
button.setBackgroundResource(R.drawable.selector_quzi_button_default)
button.setOnClickListener {
if (right) {
Toast.makeText(view.context, "回答正确", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(view.context, "回答错误", Toast.LENGTH_SHORT).show()
}
for (btn in optionsList) {
btn.setBackgroundResource(R.drawable.selector_quzi_button_default)
DPHolder.getInstance()
.buildDrawWidget(DPWidgetDrawParams.obtain().liveAdCodeId("947474066")
.liveNativeAdCodeId("947474068")
.adOffset(0) //单位 dp,为 0 时可以不设置
.quizMode(1)
.hideClose(true, null)
.listener(object : IDPDrawListener() {
override fun onDPRefreshFinish() {
LogUtil.d(TAG, "onDPRefreshFinish")
}
override fun onDPPageChange(position: Int) {
LogUtil.d(TAG, "onDPPageChange: $position")
}
override fun onDPPageChange(position: Int, map: Map<String, Any>) {
if (map == null) {
return
}
mPos = position
LogUtil.d(TAG, "onDPPageChange: $position, map = $map")
}
override fun onCreateQuizView(container: ViewGroup): View {
val quizView: View = LayoutInflater.from(container.context)
.inflate(R.layout.media_layout_quiz, container, false)
LogUtil.d(TAG, "onCreateQuizView")
return quizView
}
override fun onQuizBindData(
view: View,
options: List<String>,
answer: Int,
lastAnswer: Int,
quizHandler: IDPQuizHandler,
feedParamsForCallback: Map<String, Any>
) {
super.onQuizBindData(
view,
options,
answer,
lastAnswer,
quizHandler,
feedParamsForCallback
)
val option0 = view.findViewById<Button>(R.id.quiz_option0)
val option1 = view.findViewById<Button>(R.id.quiz_option1)
val optionsList: MutableList<Button> = ArrayList()
optionsList.add(option0)
optionsList.add(option1)
for (i in optionsList.indices) {
val right = answer == i
val background: Int =
if (right) R.drawable.selector_quzi_button_ok else R.drawable.selector_quzi_button_error
val button = optionsList[i]
button.text = options[i]
button.setBackgroundResource(R.drawable.selector_quzi_button_default)
button.setOnClickListener {
if (right) {
Toast.makeText(view.context, "回答正确", Toast.LENGTH_SHORT)
.show()
} else {
Toast.makeText(view.context, "回答错误", Toast.LENGTH_SHORT)
.show()
}
for (btn in optionsList) {
btn.setBackgroundResource(R.drawable.selector_quzi_button_default)
}
button.setBackgroundResource(background)
quizHandler.reportResult(i)
if (mIDPWidget != null) {
mIDPWidget!!.setCurrentPage(mPos + 1)
}
}
button.setBackgroundResource(background)
quizHandler.reportResult(i)
if (mIDPWidget != null) {
mIDPWidget!!.setCurrentPage(mPos + 1)
if (lastAnswer == i) {
button.setBackgroundResource(background)
}
}
if (lastAnswer == i) {
button.setBackgroundResource(background)
}
}
}
override fun onDPVideoPlay(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPVideoPlay map = $map"
)
}
override fun onDPVideoOver(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPVideoOver map = $map"
)
}
override fun onDPVideoCompletion(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPVideoCompletion map = $map"
)
}
override fun onDPClose() {
LogUtil.d(
TAG,
"onDPClose"
)
}
override fun onDPReportResult(isSucceed: Boolean) {
LogUtil.d(
TAG,
"onDPReportResult isSucceed = $isSucceed"
)
}
override fun onDPPageStateChanged(pageState: DPPageState) {
LogUtil.d(
TAG,
"onDPPageStateChanged pageState = $pageState"
)
}
override fun onDPReportResult(isSucceed: Boolean, map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPReportResult isSucceed = $isSucceed, map = $map"
)
}
override fun onDPRequestStart(@Nullable map: Map<String, Any>?) {
LogUtil.d(
TAG,
"onDPRequestStart"
)
}
override fun onDPRequestSuccess(list: List<Map<String, Any>>) {
if (list == null) {
return
}
for (i in list.indices) {
override fun onDPVideoPlay(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPVideoPlay map = $map")
}
override fun onDPVideoOver(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPVideoOver map = $map")
}
override fun onDPVideoCompletion(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPVideoCompletion map = $map")
}
override fun onDPClose() {
LogUtil.d(TAG, "onDPClose")
}
override fun onDPReportResult(isSucceed: Boolean) {
LogUtil.d(TAG, "onDPReportResult isSucceed = $isSucceed")
}
override fun onDPPageStateChanged(pageState: DPPageState) {
LogUtil.d(TAG, "onDPPageStateChanged pageState = $pageState")
}
override fun onDPReportResult(
isSucceed: Boolean,
map: Map<String, Any>
) {
LogUtil.d(
TAG,
"onDPRequestSuccess i = " + i + ", map = " + list[i].toString()
"onDPReportResult isSucceed = $isSucceed, map = $map"
)
}
}
override fun onDPRequestFail(
code: Int,
msg: String,
@Nullable map: Map<String, Any>?
) {
if (map == null) {
override fun onDPRequestStart(@Nullable map: Map<String, Any>?) {
LogUtil.d(TAG, "onDPRequestStart")
}
override fun onDPRequestSuccess(list: List<Map<String, Any>>) {
if (list == null) {
return
}
for (i in list.indices) {
LogUtil.d(TAG, "onDPRequestSuccess i=$i,map=${list[i]}")
}
}
override fun onDPRequestFail(
code: Int,
msg: String,
@Nullable map: Map<String, Any>?
) {
if (map == null) {
LogUtil.d(TAG, "onDPRequestFail code = $code, msg = $msg")
return
}
LogUtil.d(
TAG,
"onDPRequestFail code = $code, msg = $msg"
"onDPRequestFail code = $code, msg = $msg, map = $map"
)
return
}
LogUtil.d(
TAG,
"onDPRequestFail code = $code, msg = $msg, map = $map"
)
}
override fun onDPClickAuthorName(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPClickAuthorName map = $map"
)
}
override fun onDPClickAvatar(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPClickAvatar map = $map"
)
}
override fun onDPClickComment(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPClickComment map = $map"
)
}
override fun onDPClickLike(isLike: Boolean, map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPClickLike isLike = $isLike, map = $map"
)
}
override fun onDPVideoPause(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPVideoPause map = $map"
)
}
override fun onDPVideoContinue(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPVideoContinue map = $map"
)
}
override fun onDPClickShare(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPClickShare map = $map"
)
}
}).adListener(object : IDPAdListener() {
override fun onDPAdRequest(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdRequest map = $map"
)
}
override fun onDPAdRequestSuccess(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdRequestSuccess map = $map"
)
}
override fun onDPAdRequestFail(
code: Int,
msg: String,
map: Map<String, Any>
) {
LogUtil.d(
TAG,
"onDPAdRequestFail map = $map"
)
}
override fun onDPAdFillFail(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdFillFail map = $map"
)
}
override fun onDPAdShow(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdShow map = $map"
)
}
override fun onDPAdPlayStart(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdPlayStart map = $map"
)
}
override fun onDPAdPlayPause(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdPlayPause map = $map"
)
}
override fun onDPAdPlayContinue(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdPlayContinue map = $map"
)
}
override fun onDPAdPlayComplete(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdPlayComplete map = $map"
)
}
override fun onDPAdClicked(map: Map<String, Any>) {
LogUtil.d(
TAG,
"onDPAdClicked map = $map"
)
}
})
)
}
override fun onDPClickAuthorName(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPClickAuthorName map = $map")
}
override fun onDPClickAvatar(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPClickAvatar map = $map")
}
override fun onDPClickComment(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPClickComment map = $map")
}
override fun onDPClickLike(isLike: Boolean, map: Map<String, Any>) {
LogUtil.d(TAG, "onDPClickLike isLike = $isLike, map = $map")
}
override fun onDPVideoPause(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPVideoPause map = $map")
}
override fun onDPVideoContinue(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPVideoContinue map = $map")
}
override fun onDPClickShare(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPClickShare map = $map")
}
}).adListener(object : IDPAdListener() {
override fun onDPAdRequest(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdRequest map = $map")
}
override fun onDPAdRequestSuccess(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdRequestSuccess map = $map")
}
override fun onDPAdRequestFail(
code: Int,
msg: String,
map: Map<String, Any>
) {
LogUtil.d(TAG, "onDPAdRequestFail map = $map")
}
override fun onDPAdFillFail(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdFillFail map = $map")
}
override fun onDPAdShow(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdShow map = $map")
}
override fun onDPAdPlayStart(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdPlayStart map = $map")
}
override fun onDPAdPlayPause(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdPlayPause map = $map")
}
override fun onDPAdPlayContinue(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdPlayContinue map = $map")
}
override fun onDPAdPlayComplete(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdPlayComplete map = $map")
}
override fun onDPAdClicked(map: Map<String, Any>) {
LogUtil.d(TAG, "onDPAdClicked map = $map")
}
})
)
}
//计算path路径中点的坐标
......@@ -406,13 +332,8 @@ class MusicFragment : LazyLoadBaseFragment() {
// 一、创造出执行动画的主题---imageview
//代码new一个imageview,图片资源是上面的imageview的图片
// (这个图片就是执行动画的图片,从开始位置出发,经过一个抛物线(贝塞尔曲线),移动到购物车里)
val goods = ImageView(requireContext())
goods.setImageDrawable(
resources.getDrawable(
R.mipmap.ic_launcher_main,
null
)
)
val goods = ImageView(mContext)
goods.setImageDrawable(ContextCompat.getDrawable(mContext, R.mipmap.ic_launcher_main))
val params = RelativeLayout.LayoutParams(BubbleUtils.dp2px(30), BubbleUtils.dp2px(30))
rl.addView(goods, params)
......@@ -491,4 +412,8 @@ class MusicFragment : LazyLoadBaseFragment() {
override fun onAnimationRepeat(animation: Animator) {}
})
}
override fun rdSongMsgSuc(data: MusicBean) {
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment