diff --git a/main/src/main/java/com/yunbao/main/activity/MainListActivity.java b/main/src/main/java/com/yunbao/main/activity/MainListActivity.java index 14e68b967..0a3a1d0ce 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainListActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainListActivity.java @@ -8,6 +8,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.RadioButton; import android.widget.TextView; import androidx.recyclerview.widget.LinearLayoutManager; @@ -26,17 +27,24 @@ import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.custom.MyRadioButton; import com.yunbao.common.event.FollowEvent; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.CommonIconUtil; +import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.SVGAViewUtils; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.main.R; import com.yunbao.main.adapter.MainListAdapter; import com.yunbao.main.bean.ListBean; import com.yunbao.main.http.MainHttpUtil; import com.yunbao.main.views.AbsMainListChildViewHolder; +import com.yunbao.main.views.MainListContributeViewHolder; +import com.yunbao.main.views.MainListProfitViewHolder; import net.lucode.hackware.magicindicator.MagicIndicator; import net.lucode.hackware.magicindicator.ViewPagerHelper; @@ -73,8 +81,10 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener private MagicIndicator mIndicator; private ViewPager mViewPager; private List outRankHide = new ArrayList<>(); - protected CommonRefreshView mRefreshView; public MainListAdapter mAdapter; + private View mBackgroundLayout; + private RadioButton mDay, mWeek; + private int position; private HeadView hv; @@ -96,7 +106,7 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener @Override protected void main() { - initView(); + mViewList = new ArrayList<>(); for (int i = 0; i < PAGE_COUNT; i++) { FrameLayout frameLayout = new FrameLayout(mContext); @@ -169,15 +179,16 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener Log.e("MainListActivity", error); } }); + initView(); } private void initView() { mType = DAY; - mRefreshView = (CommonRefreshView) findViewById(R.id.refreshView); - mRefreshView.setEmptyLayoutId(R.layout.view_no_data_list); - mRefreshView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); - hv = new HeadView(findViewById(R.id.rootView)); mViewPager = (ViewPager) findViewById(R.id.viewPager); + mBackgroundLayout = findViewById(R.id.bg_layout); + mDay = findViewById(R.id.btn_day); + mWeek = findViewById(R.id.btn_week); + hv = new HeadView(findViewById(R.id.rootView)); mViewPager.setOffscreenPageLimit(PAGE_COUNT - 1); mViewPager.setAdapter(new ViewPagerAdapter(mViewList)); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @@ -188,7 +199,16 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener @Override public void onPageSelected(int position) { - loadPageData(position); + MainListActivity.this.position = position; + mDay.setChecked(true); + mDay.setTextColor(Color.parseColor("#FF82C1")); + mWeek.setTextColor(Color.parseColor("#FFFFFF")); + loadPageData(position, DAY); + if (position == 0) { + mBackgroundLayout.setBackgroundResource(R.mipmap.bg_glamour_top); + } else { + mBackgroundLayout.setBackgroundResource(R.mipmap.bg_glamour2_top); + } } @Override @@ -196,65 +216,63 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener } }); + mDay.setOnClickListener(v -> { + loadPageData(position, DAY); + mDay.setTextColor(Color.parseColor("#FF82C1")); + mWeek.setTextColor(Color.parseColor("#FFFFFF")); + }); + mWeek.setOnClickListener(v -> { + loadPageData(position, WEEK); + mWeek.setTextColor(Color.parseColor("#FF82C1")); + mDay.setTextColor(Color.parseColor("#FFFFFF")); + }); ViewPagerHelper.bind(mIndicator, mViewPager); mViewPager.setCurrentItem(getIntent().getIntExtra("p", 0)); - initData(); + loadPageData(0, DAY); } - private void loadPageData(int position) { - - } - - private void initData() { - mRefreshView.setDataHelper(new CommonRefreshView.DataHelper() { - @Override - public RefreshAdapter getAdapter() { - if (mAdapter == null) { - mAdapter = new MainListAdapter(mContext, MainListAdapter.TYPE_PROFIT); - mAdapter.setOnItemClickListener(MainListActivity.this); + private void loadPageData(int position, String rank) { + if (mViewHolders == null) { + return; + } + AbsMainListChildViewHolder vh = mViewHolders[position]; + if (vh == null) { + if (mViewList != null && position < mViewList.size()) { + FrameLayout parent = mViewList.get(position); + if (parent == null) { + return; } - return mAdapter; - } - - @Override - public void loadData(int p, com.yunbao.common.http.HttpCallback callback) { - if (mType != null && !mType.isEmpty()) { - MainHttpUtil.profitList(mType, p, callback); + if (position == 0) { + MainListProfitViewHolder mProfitViewHolder = new MainListProfitViewHolder(mContext, parent); + vh = mProfitViewHolder; + } else if (position == 1) { + MainListContributeViewHolder mContributeViewHolder = new MainListContributeViewHolder(mContext, parent); + mContributeViewHolder.setHide(outRankHide); + vh = mContributeViewHolder; } - } - - @Override - public List processData(String[] info) { - List list = JSON.parseArray(Arrays.toString(info), ListBean.class); - hv.setData(list.get(0), 0); - hv.setData(list.get(1), 1); - hv.setData(list.get(2), 2); - return list; - } - - @Override - public void onRefreshSuccess(List list, int listCount) { + if (vh == null) { + return; + } + mViewHolders[position] = vh; + vh.addToParent(); + vh.subscribeActivityLifeCycle(); } - - @Override - public void onRefreshFailure() { - - } - - @Override - public void onLoadMoreSuccess(List loadItemList, int loadItemCount) { - - } - - @Override - public void onLoadMoreFailure() { - - } - }); - mRefreshView.initData(); + } + if (vh != null) { + vh.setType(rank); + vh.setOnLoadDataListener(new AbsMainListChildViewHolder.OnLoadData() { + @Override + public void onData(List list) { + hv.setData(list.get(0), 0); + hv.setData(list.get(1), 1); + hv.setData(list.get(2), 2); + } + }); + } } + public void loadData() { } @@ -333,6 +351,8 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener svga1 = (SVGAImageView) itemView.findViewById(R.id.svga1); svga2 = (SVGAImageView) itemView.findViewById(R.id.svga2); svga3 = (SVGAImageView) itemView.findViewById(R.id.svga3); + + } public void setData(ListBean bean, int position) { @@ -393,6 +413,32 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener getItem(position, svga1, svga2, svga3).setVisibility(View.VISIBLE); } getItem(position, mSex1, mSex2, mSex3).setImageResource(CommonIconUtil.getSexIcon(bean.getSex())); + + getItem(position, mBtnFollow1, mBtnFollow2, mBtnFollow3).setOnClickListener(v -> { + ViewClicksAntiShake.clicksAntiShake(v, () -> { + if (!canClick()) { + return; + } + CommonHttpUtil.setAttention(bean.getUid(), new CommonCallback() { + @Override + public void callback(Integer bean) { + if(bean!=null&&bean==1){ + getItem(position,mBtnFollow1,mBtnFollow2,mBtnFollow3).setVisibility(View.INVISIBLE); + } + Log.i("测试", "callback: "+bean); + } + }); + }); + }); + getItem(position, mItem1, mItem2, mItem3).setOnClickListener(v -> { + ViewClicksAntiShake.clicksAntiShake(v, () -> { + if (bean.isHide()) { + ToastUtil.show(R.string.can_not_go); + } else { + RouteUtil.forwardUserHome(mContext, bean.getUid(), 0); + } + }); + }); } private T getItem(int position, T... views) { diff --git a/main/src/main/java/com/yunbao/main/adapter/MainListAdapter.java b/main/src/main/java/com/yunbao/main/adapter/MainListAdapter.java index 6bb44ba45..c31e87380 100644 --- a/main/src/main/java/com/yunbao/main/adapter/MainListAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/MainListAdapter.java @@ -22,6 +22,7 @@ import com.yunbao.common.bean.LevelBean; import com.yunbao.common.custom.MyRadioButton; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.CommonHttpUtil; +import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.utils.CommonIconUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.SVGAViewUtils; @@ -53,7 +54,6 @@ public class MainListAdapter extends RefreshAdapter { private View.OnClickListener mFollowClickListener2; private View.OnClickListener mItemClickListener; private List mTopList; - private HeadVh mHeadVh; private int mType; private List outRankHide = new ArrayList<>(); @@ -64,7 +64,7 @@ public class MainListAdapter extends RefreshAdapter { CommonAppConfig appConfig = CommonAppConfig.getInstance(); mCoinName = type == TYPE_PROFIT ? appConfig.getVotesName() : appConfig.getCoinName(); mTopList = new ArrayList<>(); - mFollow = ("+" + WordUtil.getString(R.string.follow)); + mFollow = (WordUtil.getString(R.string.follow)); mFollowing = WordUtil.getString(R.string.following); mItemClickListener = new View.OnClickListener() { @Override @@ -111,7 +111,14 @@ public class MainListAdapter extends RefreshAdapter { if (tag != null) { final int position = (int) tag; final ListBean bean = mList.get(position); - CommonHttpUtil.setAttention(bean.getUid(), null); + CommonHttpUtil.setAttention(bean.getUid(), new CommonCallback() { + @Override + public void callback(Integer bean) { + if (bean != null && bean == 1) { + v.setVisibility(View.INVISIBLE); + } + } + }); } }); @@ -123,7 +130,7 @@ public class MainListAdapter extends RefreshAdapter { @Override public int getItemCount() { if (mList != null && mTopList.size() > 0) { - return mList.size() ; + return mList.size(); } return 0; } @@ -191,7 +198,7 @@ public class MainListAdapter extends RefreshAdapter { @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder vh, int position, @NonNull List payloads) { Object payload = payloads.size() > 0 ? payloads.get(0) : null; - ((Vh) vh).setData(mList.get(position), position , payload); + ((Vh) vh).setData(mList.get(position), position, payload); } class HeadVh extends RecyclerView.ViewHolder { @@ -277,7 +284,7 @@ public class MainListAdapter extends RefreshAdapter { public void onComplete(SVGAVideoEntity videoItem) { SVGADrawable drawable = new SVGADrawable(videoItem); svga1.setImageDrawable(drawable); - SVGAViewUtils.playEndClear(svga1,false); + SVGAViewUtils.playEndClear(svga1, false); } @Override @@ -354,7 +361,7 @@ public class MainListAdapter extends RefreshAdapter { public void onComplete(SVGAVideoEntity videoItem) { SVGADrawable drawable = new SVGADrawable(videoItem); svga2.setImageDrawable(drawable); - SVGAViewUtils.playEndClear(svga2,false); + SVGAViewUtils.playEndClear(svga2, false); } @Override @@ -430,7 +437,7 @@ public class MainListAdapter extends RefreshAdapter { public void onComplete(SVGAVideoEntity videoItem) { SVGADrawable drawable = new SVGADrawable(videoItem); svga3.setImageDrawable(drawable); - SVGAViewUtils.playEndClear(svga3,false); + SVGAViewUtils.playEndClear(svga3, false); } @Override @@ -533,7 +540,7 @@ public class MainListAdapter extends RefreshAdapter { public void onComplete(SVGAVideoEntity videoItem) { SVGADrawable drawable = new SVGADrawable(videoItem); svga.setImageDrawable(drawable); - SVGAViewUtils.playEndClear(svga,false); + SVGAViewUtils.playEndClear(svga, false); } @Override @@ -587,11 +594,12 @@ public class MainListAdapter extends RefreshAdapter { mBtnFollow.setText(mFollowing); mBtnFollow.setBackgroundResource(R.drawable.background_dbdbdb); mBtnFollow.setTextColor(Color.parseColor("#FFFFFF")); + mBtnFollow.setVisibility(View.INVISIBLE); } else { mBtnFollow.doChecked(false); mBtnFollow.setText(mFollow); - mBtnFollow.setBackgroundResource(R.drawable.background_yellow); - mBtnFollow.setTextColor(Color.parseColor("#FFFFFF")); + mBtnFollow.setBackgroundResource(R.drawable.background_ff7bbaff); + mBtnFollow.setTextColor(Color.parseColor("#7BBAFF")); } } } diff --git a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java index f567b6b9f..f65a6d10f 100644 --- a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java @@ -1,7 +1,9 @@ package com.yunbao.main.views; import android.content.Context; + import androidx.recyclerview.widget.LinearLayoutManager; + import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; @@ -16,6 +18,8 @@ import com.yunbao.main.R; import com.yunbao.main.adapter.MainListAdapter; import com.yunbao.main.bean.ListBean; +import java.util.List; + /** * Created by cxf on 2019/2/23. */ @@ -29,6 +33,8 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple protected String mType; protected CommonRefreshView mRefreshView; public MainListAdapter mAdapter; + protected OnLoadData loadData; + protected List list; public AbsMainListChildViewHolder(Context context, ViewGroup parentView) { super(context, parentView); @@ -45,10 +51,6 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple mRefreshView = (CommonRefreshView) findViewById(R.id.refreshView); mRefreshView.setEmptyLayoutId(R.layout.view_no_data_list); mRefreshView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); - findViewById(R.id.btn_day).setOnClickListener(this); - findViewById(R.id.btn_week).setOnClickListener(this); - findViewById(R.id.btn_month).setOnClickListener(this); - findViewById(R.id.btn_total).setOnClickListener(this); } @Override @@ -75,7 +77,7 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple @Override public void onItemClick(ListBean bean, int position) { - RouteUtil.forwardUserHome(mContext, bean.getUid(),0); + RouteUtil.forwardUserHome(mContext, bean.getUid(), 0); } @Override @@ -86,10 +88,6 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple type = DAY; } else if (i == R.id.btn_week) { type = WEEK; - } else if (i == R.id.btn_month) { - type = MONTH; - } else if (i == R.id.btn_total) { - type = TOTAL; } if (!TextUtils.isEmpty(type) && !type.equals(mType)) { mType = type; @@ -99,4 +97,23 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple } } + public void setOnLoadDataListener(OnLoadData loadData) { + this.loadData = loadData; + if (list != null && !list.isEmpty()) { + loadData.onData(list); + } + } + + public void setType(String type) { + if (type != null) { + this.mType = type; + } + if (mRefreshView != null) { + mRefreshView.initData(); + } + } + + public interface OnLoadData { + void onData(List list); + } } diff --git a/main/src/main/java/com/yunbao/main/views/MainListContributeViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainListContributeViewHolder.java index 9d163a9ac..3a93d9c03 100644 --- a/main/src/main/java/com/yunbao/main/views/MainListContributeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainListContributeViewHolder.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.main.adapter.MainListAdapter; import com.yunbao.main.bean.ListBean; import com.yunbao.main.http.MainHttpConsts; @@ -51,7 +52,11 @@ public class MainListContributeViewHolder extends AbsMainListChildViewHolder { @Override public List processData(String[] info) { - return JSON.parseArray(Arrays.toString(info), ListBean.class); + list=JSON.parseArray(Arrays.toString(info), ListBean.class); + if (loadData != null) { + loadData.onData(list); + } + return list; } @Override diff --git a/main/src/main/java/com/yunbao/main/views/MainListProfitViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainListProfitViewHolder.java index 67cf3b5c3..bf377b5a0 100644 --- a/main/src/main/java/com/yunbao/main/views/MainListProfitViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainListProfitViewHolder.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; import com.yunbao.common.adapter.RefreshAdapter; import com.yunbao.common.custom.CommonRefreshView; import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.main.adapter.MainListAdapter; import com.yunbao.main.bean.ListBean; import com.yunbao.main.http.MainHttpConsts; @@ -41,14 +42,18 @@ public class MainListProfitViewHolder extends AbsMainListChildViewHolder { @Override public void loadData(int p, HttpCallback callback) { - if(!mType.isEmpty()){ + if (!mType.isEmpty()) { MainHttpUtil.profitList(mType, p, callback); } } @Override public List processData(String[] info) { - return JSON.parseArray(Arrays.toString(info), ListBean.class); + list = JSON.parseArray(Arrays.toString(info), ListBean.class); + if (loadData != null) { + loadData.onData(list); + } + return list; } @Override diff --git a/main/src/main/res/drawable/background_ff7bbaff.xml b/main/src/main/res/drawable/background_ff7bbaff.xml new file mode 100644 index 000000000..4867b5728 --- /dev/null +++ b/main/src/main/res/drawable/background_ff7bbaff.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/view_main_list.xml b/main/src/main/res/layout/view_main_list.xml index 7ab8f5508..6e97619d8 100644 --- a/main/src/main/res/layout/view_main_list.xml +++ b/main/src/main/res/layout/view_main_list.xml @@ -1,5 +1,5 @@ - + android:background="@mipmap/bg_glamour_top" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + android:layout_height="0dp" + android:layout_marginTop="-15dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/bg_layout"> - - \ No newline at end of file + \ No newline at end of file diff --git a/main/src/main/res/layout/view_main_list_page.xml b/main/src/main/res/layout/view_main_list_page.xml index 497a0c524..b856bca95 100644 --- a/main/src/main/res/layout/view_main_list_page.xml +++ b/main/src/main/res/layout/view_main_list_page.xml @@ -3,85 +3,13 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="#00FFFFFF" android:orientation="vertical" > - - - - - - - - - - - - - - - - diff --git a/main/src/main/res/mipmap-xxhdpi/bg_glamour2_top.png b/main/src/main/res/mipmap-xxhdpi/bg_glamour2_top.png new file mode 100644 index 000000000..798242589 Binary files /dev/null and b/main/src/main/res/mipmap-xxhdpi/bg_glamour2_top.png differ