소스 검색

滑动布局修改

liujiangyao 7 년 전
부모
커밋
d8891522ba

+ 26 - 0
app/src/main/java/com/sheep/gamegroup/util/RefreshUtil.java

@@ -0,0 +1,26 @@
+package com.sheep.gamegroup.util;
+
+import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
+
+/**
+ * SmartRefreshLayout
+ * Created by ljy on 2018/9/18.
+ */
+
+public class RefreshUtil {
+
+    private static RefreshUtil refreshUtil;
+
+    public static RefreshUtil newInstance(){
+        if(refreshUtil == null)
+            refreshUtil = new RefreshUtil();
+        return refreshUtil;
+    }
+
+    /**
+     * SmartRefreshLayout初始化一些参数和信息
+     */
+    public void initRefresh(){
+        ClassicsFooter.REFRESH_FOOTER_LOADING = "羊羊努力加载中...";//"正在加载...";
+    }
+}

+ 10 - 55
app/src/main/java/com/sheep/gamegroup/view/fragment/BaseListFragment2.java

@@ -1,24 +1,17 @@
 package com.sheep.gamegroup.view.fragment;
 
 import android.app.Activity;
-import android.os.Build;
 import android.os.Bundle;
-import android.os.Handler;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.TextView;
 
-import com.jcodecraeer.xrecyclerview.XRecyclerView;
 import com.scwang.smartrefresh.layout.SmartRefreshLayout;
 import com.scwang.smartrefresh.layout.api.RefreshLayout;
-import com.scwang.smartrefresh.layout.api.ScrollBoundaryDecider;
 import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
-import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
 import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
-import com.scwang.smartrefresh.layout.header.BezierRadarHeader;
 import com.scwang.smartrefresh.layout.header.ClassicsHeader;
 import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
 import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
@@ -29,7 +22,6 @@ import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.SysAppUtil;
-import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
@@ -83,8 +75,6 @@ public abstract class BaseListFragment2<T> extends BaseFragment {
     protected SmartRefreshLayout refreshLayout;
     @BindView(R.id.view_list)
     protected RecyclerView view_list;
-    @BindView(R.id.click_tv)
-    protected TextView click_tv;
 
     protected BaseMessage lastMessage;//最后一个网络获取的结果
     protected int page = 1;//页数
@@ -116,32 +106,21 @@ public abstract class BaseListFragment2<T> extends BaseFragment {
         refreshLayout.setOnRefreshListener(new OnRefreshListener() {
             @Override
             public void onRefresh(RefreshLayout refreshlayout) {
-                refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
+                refreshlayout.finishRefresh(1000/*,false*/);//传入false表示刷新失败
                 refreshData();
             }
         });
         refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
             @Override
             public void onLoadMore(final RefreshLayout refreshlayout) {
-//                refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
-                new Handler().postDelayed(new Runnable() {
-                    @Override
-                    public void run() {
-                        if(per_page != 100){
-                            if(!loadMore){
-                                loadMore = true;
-                                if(ListUtil.size(list) >= per_page*page){
-                                    page += 1;
-                                    initData();
-                                }else {
-                                    refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
-                                    setNoMore(true);
-                                }
-                            }
-                        }
+                if(ListUtil.size(list) >= per_page*page){
+                    page += 1;
+                    initData();
+                }else {
+                    refreshlayout.finishLoadMore(1000/*,false*/);//传入false表示加载失败
+                    setNoMore(true);
+                }
 
-                    }
-                },1000);
             }
         });
         view_list.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -158,25 +137,6 @@ public abstract class BaseListFragment2<T> extends BaseFragment {
                 }
             }
         });
-        click_tv.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-
-                refreshLayout.autoLoadMore();
-            }
-        });
-//        refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
-//            @Override
-//            public boolean canRefresh(View view) {
-//                return false;
-//            }
-//
-//            @Override
-//            public boolean canLoadMore(View view) {
-//                refreshLayout.autoLoadMore();
-//                return true;
-//            }
-//        });
 
 //        bottomLine = ViewUtil.setBottomLine(refreshLayout, getNoMoreCallBack());
         view_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
@@ -278,8 +238,6 @@ public abstract class BaseListFragment2<T> extends BaseFragment {
     public void notifyDataSetChanged(){
         if(refreshLayout == null)
             refreshLayout = findViewById(R.id.refreshLayout);
-        if(click_tv == null)
-            click_tv = findViewById(R.id.click_tv);
         if(empty_view == null)
             empty_view = findViewById(R.id.empty_view);
         if(view_list == null)
@@ -287,21 +245,18 @@ public abstract class BaseListFragment2<T> extends BaseFragment {
         loadMore = false;
         if(list.isEmpty()){
             refreshLayout.setVisibility(View.GONE);
-            click_tv.setVisibility(View.GONE);
         }else {
 
             refreshLayout.setVisibility(View.VISIBLE);
-            click_tv.setVisibility(View.VISIBLE);
         }
         CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
         if(page == 1){
-            refreshLayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
+            refreshLayout.finishRefresh(1000/*,false*/);//传入false表示加载失败
         } else {
-            refreshLayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
+            refreshLayout.finishLoadMore(1000/*,false*/);//传入false表示加载失败
         }
         view_list.getAdapter().notifyDataSetChanged();
         notifyData();
-//        view_list.getFootView().setVisibility(view_list.getAdapter().getItemCount() == 0?View.GONE : View.VISIBLE);
     }
     Unbinder unbinder;
     @Override

+ 6 - 3
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtAskGetMoneyRank.java

@@ -74,7 +74,6 @@ public class FgtAskGetMoneyRank extends BaseFragment {
 
     private void initView() {
         initAskTop5View();
-        askTop5NotYou.setVisibility(View.INVISIBLE);
         this_last_tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
         this_last_tv.getPaint().setAntiAlias(true);//抗锯齿
         initData();
@@ -163,19 +162,23 @@ public class FgtAskGetMoneyRank extends BaseFragment {
                         list.clear();
                         list.add(null);
                         boolean hasMe = false;
+                        int i = 0;
                         if (!ListUtil.isEmpty(newList)) {
 
                             list.addAll(newList);
                             String userId = DataUtil.getInstance().getUserId();
                             for (AskTop item : newList) {
+                                i++;
                                 if (TextUtils.equals(userId, item.getUser_id())) {
                                     hasMe = true;
                                     break;
                                 }
                             }
                         }
-                        if(this_last_tv.getText().equals(activity.getResources().getString(R.string.last_this_month_rank))){
-                            askTop5NotYou.setVisibility(hasMe ? View.INVISIBLE : View.VISIBLE);
+                        if(hasMe){
+                            askTop5NotYou.setText(String.format(Locale.CHINA ,activity.getString(R.string.congratulation_you_in_rank_top), i+""));
+                        }else {
+                            askTop5NotYou.setText(getString(R.string.you_not_rank_in_top5));
                         }
                         notifyDataSetChanged();
                     }

+ 2 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -28,6 +28,7 @@ import com.sheep.gamegroup.util.ConnectAddress;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.ScreenShotListenManager;
 import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
@@ -165,6 +166,7 @@ public class SheepApp extends MultiDexApplication {
     }
 
     private void initUtils() {
+        RefreshUtil.newInstance().initRefresh();
         DisplayMetrics metric = getResources().getDisplayMetrics();
         G.DENSITY = metric.density;
         G.DENSITY_DPI = metric.densityDpi;

+ 11 - 27
app/src/main/res/layout/fgt_playgame_son_refresh_layout.xml

@@ -22,35 +22,19 @@
         android:layout_height="match_parent"
         android:layout_below="@+id/check_net_ll" />
 
-    <LinearLayout
+
+    <com.scwang.smartrefresh.layout.SmartRefreshLayout
+        android:id="@+id/refreshLayout"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:orientation="vertical">
+        android:layout_height="wrap_content">
 
-        <com.scwang.smartrefresh.layout.SmartRefreshLayout
-            android:id="@+id/refreshLayout"
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/view_list"
             android:layout_width="match_parent"
-            android:layout_height="0dp"
-            android:layout_weight="1">
-            <android.support.v7.widget.RecyclerView
-                android:id="@+id/view_list"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:background="#fff"
-                android:overScrollMode="never" />
-
-        </com.scwang.smartrefresh.layout.SmartRefreshLayout>
-
-        <TextView
-            android:id="@+id/click_tv"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="点击加载更多"
-            android:gravity="center_horizontal"
-            android:layout_centerHorizontal="true"
-            android:layout_marginBottom="@dimen/content_padding_15"
-            android:layout_marginTop="@dimen/content_padding_15"
-            android:layout_gravity="center_horizontal"/>
-    </LinearLayout>
+            android:layout_height="match_parent"
+            android:background="#fff"
+            android:overScrollMode="never" />
+
+    </com.scwang.smartrefresh.layout.SmartRefreshLayout>
 
 </RelativeLayout>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -85,4 +85,6 @@
     <string name="last_this_month_rank_top5">上月排行榜top5</string>
     <string name="this_month_rank">查看这月排行</string>
     <string name="this_month_rank_top5">本月排行榜top5</string>
+    <string name="you_not_rank_in_top5">你还未上榜,再接再厉</string>
+    <string name="congratulation_you_in_rank_top">恭喜你,获得排行榜第%s名</string>
 </resources>