Эх сурвалжийг харах

add shimmer effect to file detail activities

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 4 жил өмнө
parent
commit
5cedaad2ba

+ 26 - 16
src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java

@@ -145,8 +145,16 @@ public class FileDetailActivitiesFragment extends Fragment implements
 
         fetchAndSetData(-1);
 
-        binding.swipeContainingList.setOnRefreshListener(() -> onRefreshListLayout(binding.swipeContainingList));
-        binding.swipeContainingEmpty.setOnRefreshListener(() -> onRefreshListLayout(binding.swipeContainingEmpty));
+        binding.swipeContainingList.setOnRefreshListener(() -> {
+            setLoadingMessage();
+            binding.swipeContainingList.setRefreshing(true);
+            fetchAndSetData(-1);
+        });
+
+        binding.swipeContainingEmpty.setOnRefreshListener(() -> {
+            setLoadingMessageEmpty();
+            fetchAndSetData(-1);
+        });
 
         callback = new VersionListInterface.CommentCallback() {
 
@@ -188,18 +196,15 @@ public class FileDetailActivitiesFragment extends Fragment implements
         }
     }
 
-    private void onRefreshListLayout(SwipeRefreshLayout refreshLayout) {
-        setLoadingMessage();
-        if (refreshLayout != null && refreshLayout.isRefreshing()) {
-            refreshLayout.setRefreshing(false);
-        }
-        fetchAndSetData(-1);
+    private void setLoadingMessage() {
+        binding.swipeContainingEmpty.setVisibility(View.GONE);
     }
 
-    private void setLoadingMessage() {
-        binding.emptyList.emptyListViewHeadline.setText(R.string.file_list_loading);
-        binding.emptyList.emptyListViewText.setText("");
-        binding.emptyList.emptyListIcon.setVisibility(View.GONE);
+    @VisibleForTesting
+    public void setLoadingMessageEmpty() {
+        binding.swipeContainingList.setVisibility(View.GONE);
+        binding.emptyList.emptyListView.setVisibility(View.GONE);
+        binding.loadingContent.setVisibility(View.VISIBLE);
     }
 
     @Override
@@ -266,15 +271,11 @@ public class FileDetailActivitiesFragment extends Fragment implements
             return;
         }
 
-        final SwipeRefreshLayout empty = binding.swipeContainingEmpty;
-        final SwipeRefreshLayout list = binding.swipeContainingList;
         final User user = accountManager.getUser();
 
         if (user.isAnonymous()) {
             activity.runOnUiThread(() -> {
                 setEmptyContent(getString(R.string.common_error), getString(R.string.file_detail_activity_error));
-                list.setVisibility(View.GONE);
-                empty.setVisibility(View.VISIBLE);
             });
             return;
         }
@@ -378,9 +379,11 @@ public class FileDetailActivitiesFragment extends Fragment implements
                            );
             binding.swipeContainingList.setVisibility(View.GONE);
             binding.swipeContainingEmpty.setVisibility(View.VISIBLE);
+            binding.emptyList.emptyListView.setVisibility(View.VISIBLE);
         } else {
             binding.swipeContainingList.setVisibility(View.VISIBLE);
             binding.swipeContainingEmpty.setVisibility(View.GONE);
+            binding.emptyList.emptyListView.setVisibility(View.GONE);
         }
         isLoadingActivities = false;
     }
@@ -394,6 +397,11 @@ public class FileDetailActivitiesFragment extends Fragment implements
 
         binding.emptyList.emptyListViewText.setVisibility(View.VISIBLE);
         binding.emptyList.emptyListIcon.setVisibility(View.VISIBLE);
+
+        binding.swipeContainingList.setVisibility(View.GONE);
+        binding.loadingContent.setVisibility(View.GONE);
+        binding.swipeContainingEmpty.setVisibility(View.VISIBLE);
+        binding.emptyList.emptyListView.setVisibility(View.VISIBLE);
     }
 
     @VisibleForTesting
@@ -408,6 +416,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
         binding.emptyList.emptyListIcon.setVisibility(View.VISIBLE);
         binding.swipeContainingList.setVisibility(View.GONE);
         binding.swipeContainingEmpty.setVisibility(View.VISIBLE);
+        binding.emptyList.emptyListView.setVisibility(View.VISIBLE);
     }
 
     private void hideRefreshLayoutLoader(FragmentActivity activity) {
@@ -415,6 +424,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
             if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
                 binding.swipeContainingList.setRefreshing(false);
                 binding.swipeContainingEmpty.setRefreshing(false);
+                binding.emptyList.emptyListView.setVisibility(View.GONE);
                 isLoadingActivities = false;
             }
         });

+ 26 - 0
src/main/res/layout/activity_list_item_header_shimmer.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Nextcloud Android client application
+
+  Copyright (C) 2020 Andy Scherzinger
+
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+  License as published by the Free Software Foundation; either
+  version 3 of the License, or any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+  You should have received a copy of the GNU Affero General Public
+  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<com.elyeproj.loaderviewlibrary.LoaderTextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/shimmer_header"
+    android:layout_width="140dp"
+    android:layout_height="wrap_content"
+    android:layout_marginStart="@dimen/standard_list_item_size"
+    android:layout_marginTop="@dimen/standard_margin"
+    android:layout_marginBottom="40dp" />

+ 51 - 24
src/main/res/layout/file_details_activities_fragment.xml

@@ -20,6 +20,7 @@
 
 <LinearLayout 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"
     android:orientation="vertical">
@@ -27,8 +28,8 @@
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginEnd="@dimen/zero"
         android:layout_marginStart="@dimen/standard_padding"
+        android:layout_marginEnd="@dimen/zero"
         android:orientation="horizontal">
 
         <com.google.android.material.textfield.TextInputEditText
@@ -52,34 +53,60 @@
 
     </LinearLayout>
 
-    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
-        android:id="@+id/swipe_containing_list"
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:footerDividersEnabled="false"
-        android:visibility="visible">
+        android:layout_height="match_parent">
 
-        <androidx.recyclerview.widget.RecyclerView
-            android:id="@android:id/list"
+        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+            android:id="@+id/swipe_containing_list"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:clipToPadding="false"
-            android:scrollbarStyle="outsideOverlay"
-            android:scrollbars="vertical"
-            android:visibility="visible"/>
+            android:footerDividersEnabled="false"
+            android:visibility="visible">
 
-    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@android:id/list"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_marginLeft="-3dp"
+                android:layout_marginRight="-3dp"
+                android:layout_marginBottom="-3dp"
+                android:background="@color/bg_default"
+                android:clipToPadding="false"
+                android:scrollbarStyle="outsideOverlay"
+                android:scrollbars="vertical"
+                android:visibility="visible"
+                tools:listitem="@layout/activity_list_item" />
 
-    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
-        android:id="@+id/swipe_containing_empty"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:footerDividersEnabled="false"
-        android:visibility="visible">
-
-        <include
-            android:id="@+id/empty_list"
-            layout="@layout/empty_list" />
-    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
+        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
+
+        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+            android:id="@+id/swipe_containing_empty"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:footerDividersEnabled="false"
+            android:visibility="visible">
+
+            <LinearLayout
+                android:id="@+id/loading_content"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical"
+                android:visibility="visible">
+
+                <include layout="@layout/activity_list_item_header_shimmer" />
+                <include layout="@layout/activity_list_item_shimmer" />
+                <include layout="@layout/activity_list_item_header_shimmer" />
+                <include layout="@layout/activity_list_item_shimmer" />
+                <include layout="@layout/activity_list_item_shimmer" />
+
+            </LinearLayout>
+
+            <include
+                android:id="@+id/empty_list"
+                layout="@layout/empty_list" />
+        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
+
+    </FrameLayout>
 
 </LinearLayout>