Commit 34c7325f authored by jyx's avatar jyx

代码优化

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