首页排行榜改成可伸缩的模式

This commit is contained in:
zlzw 2022-11-02 16:53:28 +08:00
parent b48ceea571
commit b10d9ada46
6 changed files with 484 additions and 8 deletions

View File

@ -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'
}

View File

@ -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);

View File

@ -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<ListBean> 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<ListBean> list);
}
public interface OnAppbarListener {
void onShow(boolean isShow);
}
class HeadView {
View mItem1;
View mItem2;

View File

@ -53,9 +53,11 @@ public class MainListContributeViewHolder extends AbsMainListChildViewHolder {
@Override
public List<ListBean> 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;
}

View File

@ -50,8 +50,10 @@ public class MainListProfitViewHolder extends AbsMainListChildViewHolder {
@Override
public List<ListBean> 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;
}

View File

@ -0,0 +1,428 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="100dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:toolbarId="@+id/toolbar">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bg_layout"
android:layout_width="match_parent"
android:layout_height="421dp"
android:background="@mipmap/bg_glamour_top"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/item_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="40dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/item_2"
app:layout_constraintEnd_toStartOf="@+id/item_3"
app:layout_constraintStart_toEndOf="@+id/item_2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/avatar_1"
android:layout_width="60dp"
android:layout_height="60dp"
android:scaleType="centerCrop"
app:riv_oval="true" />
</RelativeLayout>
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/svga1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp" />
<RelativeLayout
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp">
<pl.droidsonroids.gif.GifImageView
android:id="@+id/liveing1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="50dp"
android:src="@mipmap/icon_user_home_living" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/name_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:lines="1"
android:maxEms="4"
android:singleLine="true"
android:text="名字"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="@+id/sex_1"
android:layout_width="12dp"
android:layout_height="12dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:src="@mipmap/diamond" />
<TextView
android:id="@+id/votes_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="11111"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</LinearLayout>
<com.yunbao.common.custom.MyRadioButton
android:id="@+id/btn_follow_1"
android:layout_width="70dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="@drawable/background_dbdbdb"
android:button="@null"
android:gravity="center"
android:text="@string/shield_gift_effect"
android:textColor="@color/white"
android:textSize="11sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/item_2"
android:layout_width="0dp"
android:layout_height="152dp"
android:layout_marginStart="25dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="70dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/item_1"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/avatar_2"
android:layout_width="66dp"
android:layout_height="66dp"
android:scaleType="centerCrop"
app:riv_border_color="#B6B6B6"
app:riv_border_width="2dp"
app:riv_oval="true" />
</RelativeLayout>
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/svga2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp" />
<RelativeLayout
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp">
<pl.droidsonroids.gif.GifImageView
android:id="@+id/liveing2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="50dp"
android:src="@mipmap/icon_user_home_living" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/name_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:lines="1"
android:maxEms="4"
android:singleLine="true"
android:text="名字"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="@+id/sex_2"
android:layout_width="12dp"
android:layout_height="12dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:src="@mipmap/diamond" />
<TextView
android:id="@+id/votes_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="11111"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</LinearLayout>
<com.yunbao.common.custom.MyRadioButton
android:id="@+id/btn_follow_2"
android:layout_width="70dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="@drawable/background_dbdbdb"
android:button="@null"
android:gravity="center"
android:text="已关注"
android:textColor="@color/white"
android:textSize="11sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/item_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginBottom="60dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_1">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/avatar_3"
android:layout_width="66dp"
android:layout_height="66dp"
android:scaleType="centerCrop"
app:riv_border_color="#B6B6B6"
app:riv_border_width="2dp"
app:riv_oval="true" />
</RelativeLayout>
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/svga3"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp" />
<RelativeLayout
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp">
<pl.droidsonroids.gif.GifImageView
android:id="@+id/liveing3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="50dp"
android:src="@mipmap/icon_user_home_living" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/name_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:lines="1"
android:maxEms="4"
android:singleLine="true"
android:text="名字"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="@+id/sex_3"
android:layout_width="12dp"
android:layout_height="12dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:src="@mipmap/diamond" />
<TextView
android:id="@+id/votes_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="11111"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</LinearLayout>
<com.yunbao.common.custom.MyRadioButton
android:id="@+id/btn_follow_3"
android:layout_width="70dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="@drawable/background_dbdbdb"
android:button="@null"
android:gravity="center"
android:text="已关注"
android:textColor="@color/white"
android:textSize="11sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<com.yunbao.common.custom.CommonRefreshView
android:id="@+id/refreshView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_white_up"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>