Commit e34a7048 authored by jyx's avatar jyx

代码优化

parent cf792285
......@@ -30,23 +30,14 @@ public class FriendHallMsgBean implements Serializable {
private int friendCount;
private int directFriendsCount;
private int indirectFriendsCount;
private String gameRule;
private String rankRule;
private String rules;
public String getGameRule() {
return gameRule;
public String getRules() {
return rules;
}
public void setGameRule(String gameRule) {
this.gameRule = gameRule;
}
public String getRankRule() {
return rankRule;
}
public void setRankRule(String rankRule) {
this.rankRule = rankRule;
public void setRules(String rules) {
this.rules = rules;
}
public int getDirectFriendsCount() {
......@@ -174,8 +165,17 @@ public class FriendHallMsgBean implements Serializable {
private double contribution;
private int status;
private String name;
private String createTime;
private String head = null;
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public int getId() {
return id;
}
......
......@@ -108,7 +108,7 @@ class FriendsPresenter : BasePresenter<FriendsView>() {
}
/**
* 日贡献榜
* 日贡献榜
*/
fun getFriendsGiveTodayList() {
AppHttpManager.getInstance(loanApplication)
......@@ -129,7 +129,7 @@ class FriendsPresenter : BasePresenter<FriendsView>() {
when (baseResponse.status) {
200 -> {
view.getContributionLeadersSuc(baseResponse.data)
view.getFriendsGiveTodayListSuc(baseResponse.data)
}
else -> {
view.showToast(baseResponse.message)
......
......@@ -14,6 +14,8 @@ interface FriendsView : BaseView {
fun getContributionLeadersSuc(data: FriendHallMsgBean)
fun getFriendsGiveTodayListSuc(data: FriendHallMsgBean)
fun getContributionOutToCashSuc()
}
......@@ -10,8 +10,8 @@ import com.mints.goodmoney.mvp.model.FriendHallMsgBean
import com.mints.goodmoney.mvp.presenters.FriendsActivityPresenter
import com.mints.goodmoney.mvp.views.FriendsActivityView
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.adapter.FriendsInvitedAdapter
import com.mints.goodmoney.ui.adapter.FriendsPagerAdapter
import com.mints.goodmoney.ui.adapter.InvitedAdapter
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshListener
import kotlinx.android.synthetic.main.fragment_main_friends.*
......@@ -33,8 +33,8 @@ class FriendsActivity : BaseActivity(), View.OnClickListener, FriendsActivityVie
private var directData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var indirectData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var directAdapter: InvitedAdapter? = null
private var indirectAdapter: InvitedAdapter? = null
private var directAdapter: FriendsInvitedAdapter? = null
private var indirectAdapter: FriendsInvitedAdapter? = null
override fun getContentViewLayoutID() = R.layout.activity_friends
......@@ -47,6 +47,8 @@ class FriendsActivity : BaseActivity(), View.OnClickListener, FriendsActivityVie
initListener()
initRecy()
friendsActivityPresenter.getDirectFriends()
}
private fun initRecy() {
......@@ -55,8 +57,8 @@ class FriendsActivity : BaseActivity(), View.OnClickListener, FriendsActivityVie
recyFriends.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recyWorld.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
directAdapter = InvitedAdapter(mContext, directData)
indirectAdapter = InvitedAdapter(mContext, indirectData)
directAdapter = FriendsInvitedAdapter(mContext, directData)
indirectAdapter = FriendsInvitedAdapter(mContext, indirectData)
recyFriends.adapter = directAdapter
recyWorld.adapter = indirectAdapter
......
package com.mints.goodmoney.ui.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mints.goodmoney.R
import com.mints.goodmoney.mvp.model.FriendHallMsgBean
import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener
import com.mints.library.utils.GlideUtils
class FriendsInvitedAdapter(context: Context, invitedData: MutableList<FriendHallMsgBean.ListBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
companion object {
const val HOLDER_TYPE_EMPTY = 0
const val HOLDER_TYPE_INVITED = 1
}
private var mContext: Context = context
private var invitedData: List<FriendHallMsgBean.ListBean> = invitedData
private var mOnItemClickListener: OnItemClickListener? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if (viewType == HOLDER_TYPE_EMPTY) {
val emptyView = LayoutInflater.from(parent.context).inflate(R.layout.item_empty, parent, false)
return EmptyHolder(emptyView)
}
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_recy_invited, parent, false)
return InvitedHolder(view)
}
override fun getItemCount(): Int {
return if (invitedData.isEmpty()) {
1
} else {
invitedData.size
}
}
override fun getItemViewType(position: Int): Int {
if (invitedData.isEmpty()) {
return HOLDER_TYPE_EMPTY
}
return HOLDER_TYPE_INVITED
}
override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
if (viewHolder is EmptyHolder) {
return
}
val holder = viewHolder as InvitedHolder
when (position) {
0 -> {
holder.tvNum.visibility = View.GONE
holder.ivRanking.visibility = View.VISIBLE
holder.ivRanking.setImageResource(R.mipmap.icon_ranking_first)
}
1 -> {
holder.tvNum.visibility = View.GONE
holder.ivRanking.visibility = View.VISIBLE
holder.ivRanking.setImageResource(R.mipmap.icon_ranking_second)
}
2 -> {
holder.tvNum.visibility = View.GONE
holder.ivRanking.visibility = View.VISIBLE
holder.ivRanking.setImageResource(R.mipmap.icon_ranking_third)
}
else -> {
holder.tvNum.visibility = View.VISIBLE
holder.ivRanking.visibility = View.GONE
holder.tvNum.text = "" + (position + 1)
}
}
val data = invitedData[position]
GlideUtils.loadCircleImageView(mContext, data.head, holder.ivAvatar, R.mipmap.ic_avatar_ph, R.mipmap.ic_avatar_ph)
holder.tvName.text = data.name
holder.tvCoin.text = "" + data.createTime
holder.tvCoin.textSize = 16f
holder.tvCoin.setTextColor(mContext.resources.getColor(R.color.gray))
holder.tvStr.visibility = View.GONE
holder.itemView.setOnClickListener {
mOnItemClickListener?.onItemClick(holder.itemView, position)
}
}
inner class EmptyHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
inner class InvitedHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val tvNum: TextView = itemView.findViewById(R.id.item_invited_tv_num)
val ivAvatar: ImageView = itemView.findViewById(R.id.item_invited_iv_avatar)
val ivRanking: ImageView = itemView.findViewById(R.id.item_invite_iv_ranking)
val tvName: TextView = itemView.findViewById(R.id.item_invited_tv_name)
val tvCoin: TextView = itemView.findViewById(R.id.item_invited_tv_coin)
val tvStr: TextView = itemView.findViewById(R.id.item_invited_tv_str)
}
fun setOnItemClickListener(listener: OnItemClickListener) {
mOnItemClickListener = listener
}
}
\ No newline at end of file
......@@ -41,15 +41,19 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
private var viewPagerAdapter: FriendsPagerAdapter? = null
// 收益总榜数据
private var allData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var friendsData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var worldData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var allAdapter: InvitedAdapter? = null
private val recyList: MutableList<RecyclerView> = mutableListOf()
// 今日贡献榜数据
private var todayData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var todayAdapter: InvitedAdapter? = null
private var allAdapter: InvitedAdapter? = null
private var friendsAdapter: InvitedAdapter? = null
private var worldAdapter: InvitedAdapter? = null
// 昨日收益榜数据
private var yesterdayData: MutableList<FriendHallMsgBean.ListBean> = mutableListOf()
private var yesterdayAdapter: InvitedAdapter? = null
private val recyList: MutableList<RecyclerView> = mutableListOf()
private var mFriendsHallMsgBean: FriendHallMsgBean? = null
......@@ -71,9 +75,8 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
tv_right_subtitle.text = "玩法规则"
tv_right_subtitle.setTextColor(resources.getColor(R.color.main_bg_text))
tv_right_subtitle.setOnClickListener { }
tv_title.text = "分红福利"
tv_title.text = "瓜分百万现金福利"
iv_question.setOnClickListener(this)
btn_get_bonus.setOnClickListener(this)
tv_right_subtitle.setOnClickListener(this)
btn_invite.setOnClickListener(this)
......@@ -84,23 +87,24 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
private fun initRecy() {
val recyAll = View.inflate(mContext, R.layout.item_friends_recy, null) as RecyclerView
val recyFriends = View.inflate(mContext, R.layout.item_friends_recy, null) as RecyclerView
val recyWorld = View.inflate(mContext, R.layout.item_friends_recy, null) as RecyclerView
val recyToday = View.inflate(mContext, R.layout.item_friends_recy, null) as RecyclerView
val recyYesterday = View.inflate(mContext, R.layout.item_friends_recy, null) as RecyclerView
recyAll.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recyFriends.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recyWorld.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recyToday.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recyYesterday.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
allAdapter = InvitedAdapter(mContext, allData)
friendsAdapter = InvitedAdapter(mContext, friendsData)
worldAdapter = InvitedAdapter(mContext, worldData)
yesterdayAdapter = InvitedAdapter(mContext, yesterdayData)
todayAdapter = InvitedAdapter(mContext, todayData)
recyAll.adapter = allAdapter
recyFriends.adapter = friendsAdapter
recyWorld.adapter = worldAdapter
recyToday.adapter = todayAdapter
recyYesterday.adapter = yesterdayAdapter
recyList.add(recyAll)
recyList.add(recyFriends)
recyList.add(recyWorld)
recyList.add(recyToday)
recyList.add(recyYesterday)
val titleList = arrayListOf("总收益榜", "今日贡献榜", "昨日收益榜")
viewPagerAdapter = FriendsPagerAdapter(titleList, recyList)
......@@ -117,12 +121,12 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
}
1 -> {
if (friendsData.size <= 0) {
if (todayData.size <= 0) {
friendsPresenter.getFriendsGiveTodayList()
}
}
2 -> {
if (worldData.size <= 0) {
if (yesterdayData.size <= 0) {
friendsPresenter.getContributionLeaders()
}
}
......@@ -163,6 +167,7 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
2 -> {
friendsPresenter.getContributionLeaders()
}
else -> {
}
......@@ -263,8 +268,8 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
}
private fun ruleDialog(flag: Boolean) {
if (mFriendsHallMsgBean?.gameRule != null && mFriendsHallMsgBean?.rankRule != null) {
private fun ruleDialog() {
if (mFriendsHallMsgBean?.rules != null) {
bonusDialog = BonusDialog(requireActivity(), object : DialogListener() {
override fun onClick(v: View) {
when (v.id) {
......@@ -279,18 +284,10 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
})
bonusDialog?.let {
if (flag) {
it.setTitle("玩法规则")
it.setContent(mFriendsHallMsgBean?.gameRule!!)
it.setBtnStr("知道了")
it.show()
} else {
it.setTitle("收益规则")
it.setContent(mFriendsHallMsgBean?.rankRule!!)
it.setBtnStr("知道了")
it.show()
}
it.setTitle("玩法规则")
it.setContent(mFriendsHallMsgBean?.rules!!)
it.setBtnStr("知道了")
it.show()
}
}
}
......@@ -328,11 +325,7 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
R.id.tv_right_subtitle -> {
// 玩法规则
ruleDialog(true)
}
R.id.iv_question -> {
// 收益规则
ruleDialog(false)
ruleDialog()
}
R.id.btn_get_bonus -> {
// 领取收益
......@@ -349,6 +342,7 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
}
// 总收益榜
override fun getContributionBigLeadersSuc(data: FriendHallMsgBean) {
srl_my.finishRefresh(true)
......@@ -363,12 +357,22 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
generateData(data)
}
// 昨日收益榜
override fun getContributionLeadersSuc(data: FriendHallMsgBean) {
srl_my.finishRefresh(true)
worldData.clear()
worldData.addAll(data.list)
worldAdapter?.notifyDataSetChanged()
yesterdayData.clear()
yesterdayData.addAll(data.list)
yesterdayAdapter?.notifyDataSetChanged()
}
// 今日贡献榜
override fun getFriendsGiveTodayListSuc(data: FriendHallMsgBean) {
srl_my.finishRefresh(true)
todayData.clear()
todayData.addAll(data.list)
todayAdapter?.notifyDataSetChanged()
}
// 提现成功
......
......@@ -38,6 +38,12 @@
app:xTabTextColor="#666666"
app:xTabTextSize="15sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="@color/my_color_gray3" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager_friends"
android:layout_width="match_parent"
......
......@@ -33,6 +33,7 @@
android:layout_height="42dp"
android:layout_marginTop="20dp"
android:background="@drawable/shape_btn_friends"
android:gravity="center"
android:textColor="@color/white"
android:textSize="18sp" />
......
......@@ -103,7 +103,10 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="15dp"
android:background="@drawable/shape_gold_card"
android:elevation="1dp"
android:orientation="vertical"
......@@ -232,7 +235,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="15dp"
android:layout_marginBottom="10dp"
android:background="@drawable/shape_gold_card"
android:elevation="1dp"
android:padding="15dp">
......@@ -404,15 +407,6 @@
app:xTabTextColor="#666666"
app:xTabTextSize="15sp" />
<ImageView
android:id="@+id/iv_question"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_toEndOf="@id/tab_friends"
android:src="@mipmap/ic_question" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
......
......@@ -45,6 +45,7 @@
android:textSize="22sp" />
<TextView
android:id="@+id/item_invited_tv_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
......
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