From b10d9ada4627d4dcf0f575d01d4763c5e5066c4a Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 2 Nov 2022 16:53:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8E=92=E8=A1=8C=E6=A6=9C?= =?UTF-8?q?=E6=94=B9=E6=88=90=E5=8F=AF=E4=BC=B8=E7=BC=A9=E7=9A=84=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/build.gradle | 1 + .../main/activity/MainListActivity.java | 14 +- .../views/AbsMainListChildViewHolder.java | 35 +- .../views/MainListContributeViewHolder.java | 8 +- .../main/views/MainListProfitViewHolder.java | 6 +- .../main/res/layout/activity_main_list.xml | 428 ++++++++++++++++++ 6 files changed, 484 insertions(+), 8 deletions(-) create mode 100644 main/src/main/res/layout/activity_main_list.xml diff --git a/main/build.gradle b/main/build.gradle index 6aefbe7a8..4905a1d0f 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -84,4 +84,5 @@ dependencies { implementation 'com.google.android.gms:play-services-auth:15.0.0' //引导层 implementation 'com.binioter:guideview:1.0.0' + implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0' } 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 47ebc14a0..768978521 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainListActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainListActivity.java @@ -9,6 +9,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; import androidx.recyclerview.widget.LinearLayoutManager; @@ -87,6 +88,7 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener private RadioButton mDay, mWeek; private int position; private ImageView mBack; + private RadioGroup radioGroup; public static void forward(Context context, int p) { @@ -186,6 +188,7 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener mBack = findViewById(R.id.btn_back); mDay = findViewById(R.id.btn_day); mWeek = findViewById(R.id.btn_week); + radioGroup = findViewById(R.id.radioGroup); mViewPager.setOffscreenPageLimit(PAGE_COUNT - 1); mViewPager.setAdapter(new ViewPagerAdapter(mViewList)); @@ -240,19 +243,28 @@ public class MainListActivity extends AbsActivity implements OnItemClickListener } if (position == 0) { vh = new MainListProfitViewHolder(mContext, parent); + vh.setAppbarColor(Color.parseColor("#FF73C3")); } else if (position == 1) { MainListContributeViewHolder mContributeViewHolder = new MainListContributeViewHolder(mContext, parent); mContributeViewHolder.setHide(outRankHide); vh = mContributeViewHolder; + vh.setAppbarColor(Color.parseColor("#73B2FF")); } if (vh == null) { return; } + vh.setAppbarListener(isShow -> { + if (isShow) { + radioGroup.setVisibility(View.VISIBLE); + } else { + radioGroup.setVisibility(View.INVISIBLE); + } + }); mViewHolders[position] = vh; vh.addToParent(); vh.subscribeActivityLifeCycle(); - } + } if (vh != null) { vh.setType(position, rank); 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 260cae0e7..0a68cdfd9 100644 --- a/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AbsMainListChildViewHolder.java @@ -5,6 +5,7 @@ import android.content.Context; import androidx.recyclerview.widget.LinearLayoutManager; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -12,6 +13,8 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAParser; @@ -57,6 +60,9 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple protected List list; private HeadView hv; private View mBackgroundLayout; + private OnAppbarListener appbarListener; + private AppBarLayout rootView; + private CollapsingToolbarLayout toolbarLayout; public AbsMainListChildViewHolder(Context context, ViewGroup parentView) { super(context, parentView); @@ -65,14 +71,16 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple @Override protected int getLayoutId() { - return R.layout.view_main_list_page; + return R.layout.activity_main_list; } @Override public void init() { mRefreshView = (CommonRefreshView) findViewById(R.id.refreshView); mBackgroundLayout = findViewById(R.id.bg_layout); - hv = new HeadView(findViewById(R.id.rootView)); + rootView = (AppBarLayout) findViewById(R.id.rootView); + toolbarLayout= (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout); + hv = new HeadView(rootView); mRefreshView.setEmptyLayoutId(R.layout.view_no_data_list); mRefreshView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); loadData = list -> { @@ -81,6 +89,21 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple hv.setData(list.get(1), 1); hv.setData(list.get(2), 2); }; + rootView.addOnOffsetChangedListener(new AppBarLayout.BaseOnOffsetChangedListener() { + @Override + public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + if (appbarListener != null) { + if (verticalOffset == 0) { + appbarListener.onShow(true); + } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) { + appbarListener.onShow(false); + } + } + } + }); + } + public void setAppbarColor(int color){ + toolbarLayout.setContentScrimColor(color); } @Override @@ -110,6 +133,10 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple RouteUtil.forwardUserHome(mContext, bean.getUid(), 0); } + public void setAppbarListener(OnAppbarListener appbarListener) { + this.appbarListener = appbarListener; + } + @Override public void onClick(View v) { int i = v.getId(); @@ -146,6 +173,10 @@ public abstract class AbsMainListChildViewHolder extends AbsMainViewHolder imple void onData(List list); } + public interface OnAppbarListener { + void onShow(boolean isShow); + } + class HeadView { View mItem1; View mItem2; 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 3a93d9c03..0f6354734 100644 --- a/main/src/main/java/com/yunbao/main/views/MainListContributeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainListContributeViewHolder.java @@ -53,9 +53,11 @@ public class MainListContributeViewHolder extends AbsMainListChildViewHolder { @Override public List processData(String[] info) { list=JSON.parseArray(Arrays.toString(info), ListBean.class); - if (loadData != null) { - loadData.onData(list); - } + if(mRefreshView.getPageCount()==1){ + if (loadData != null) { + loadData.onData(list); + } + } return list; } 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 bf377b5a0..342c06e12 100644 --- a/main/src/main/java/com/yunbao/main/views/MainListProfitViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainListProfitViewHolder.java @@ -50,8 +50,10 @@ public class MainListProfitViewHolder extends AbsMainListChildViewHolder { @Override public List processData(String[] info) { list = JSON.parseArray(Arrays.toString(info), ListBean.class); - if (loadData != null) { - loadData.onData(list); + if(mRefreshView.getPageCount()==1){ + if (loadData != null) { + loadData.onData(list); + } } return list; } diff --git a/main/src/main/res/layout/activity_main_list.xml b/main/src/main/res/layout/activity_main_list.xml new file mode 100644 index 000000000..fed041be3 --- /dev/null +++ b/main/src/main/res/layout/activity_main_list.xml @@ -0,0 +1,428 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file