Add title to the wallpapers list

For improved reachability of the items

Co-authored-by: Asher Simonds <dayanhammer@gmail.com>
Signed-off-by: Joey <joey@lineageos.org>
Change-Id: I25c3b7eba6cc6739b80ea349e85da8f42fb0a8de
diff --git a/app/src/main/java/org/lineageos/backgrounds/adapters/WallsAdapter.java b/app/src/main/java/org/lineageos/backgrounds/adapters/WallsAdapter.java
index 95669d2..a4d0b6d 100644
--- a/app/src/main/java/org/lineageos/backgrounds/adapters/WallsAdapter.java
+++ b/app/src/main/java/org/lineageos/backgrounds/adapters/WallsAdapter.java
@@ -60,14 +60,8 @@
 
     @Override
     public void onBindViewHolder(final @NonNull WallpaperHolder holder, final int position) {
-        /*
-         * + 2 is for the last 2 items of the list as the one
-         * before the last might happen to end "below" the real
-         * last one
-         */
-        final boolean isLast = position + 2 == mData.size();
         final WallpaperBundle bundle = mData.get(position);
-        holder.bind(bundle, isLast);
+        holder.bind(bundle);
     }
 
     @Override
diff --git a/app/src/main/java/org/lineageos/backgrounds/holders/UserHolder.java b/app/src/main/java/org/lineageos/backgrounds/holders/UserHolder.java
index e5e8fb3..86d906e 100644
--- a/app/src/main/java/org/lineageos/backgrounds/holders/UserHolder.java
+++ b/app/src/main/java/org/lineageos/backgrounds/holders/UserHolder.java
@@ -30,9 +30,8 @@
     }
 
     @Override
-    public void bind(@NonNull final WallpaperBundle bundle,
-                     final boolean isLast) {
-        super.bind(bundle, isLast);
+    public void bind(@NonNull final WallpaperBundle bundle) {
+        super.bind(bundle);
 
         itemView.setOnClickListener(v -> callback.onWallpaperSelected(previewView, null));
     }
diff --git a/app/src/main/java/org/lineageos/backgrounds/holders/WallpaperHolder.java b/app/src/main/java/org/lineageos/backgrounds/holders/WallpaperHolder.java
index 8666c0d..ed4742d 100644
--- a/app/src/main/java/org/lineageos/backgrounds/holders/WallpaperHolder.java
+++ b/app/src/main/java/org/lineageos/backgrounds/holders/WallpaperHolder.java
@@ -26,7 +26,6 @@
 import org.lineageos.backgrounds.R;
 import org.lineageos.backgrounds.bundle.WallpaperBundle;
 import org.lineageos.backgrounds.ui.SelectionInterface;
-import org.lineageos.backgrounds.util.UiUtils;
 
 public class WallpaperHolder extends RecyclerView.ViewHolder {
     @NonNull
@@ -40,8 +39,7 @@
         this.callback = callback;
     }
 
-    public void bind(@NonNull final WallpaperBundle bundle,
-                     final boolean isLast) {
+    public void bind(@NonNull final WallpaperBundle bundle) {
         previewView = itemView.findViewById(R.id.item_wallpaper_preview);
         TextView nameView = itemView.findViewById(R.id.item_wallpaper_name);
 
@@ -57,9 +55,5 @@
         nameView.setText(name);
 
         itemView.setOnClickListener((v) -> callback.onWallpaperSelected(previewView, bundle));
-
-        // Update margins
-        UiUtils.setMarginForListItem(itemView.getResources(), itemView,
-                R.dimen.item_margin_vertical, isLast);
     }
 }
diff --git a/app/src/main/java/org/lineageos/backgrounds/ui/MainActivity.java b/app/src/main/java/org/lineageos/backgrounds/ui/MainActivity.java
index fd0217c..5056b82 100644
--- a/app/src/main/java/org/lineageos/backgrounds/ui/MainActivity.java
+++ b/app/src/main/java/org/lineageos/backgrounds/ui/MainActivity.java
@@ -28,6 +28,7 @@
 import androidx.annotation.Nullable;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.core.app.ActivityOptionsCompat;
+import androidx.core.widget.NestedScrollView;
 import androidx.recyclerview.widget.DefaultItemAnimator;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.recyclerview.widget.StaggeredGridLayoutManager;
@@ -48,6 +49,8 @@
 
     private ProgressBar mLoadingProgressBar;
     private TextView mLoadingTextView;
+    private NestedScrollView mContentLayout;
+    private TextView mTitleView;
     private RecyclerView mContentRecyclerView;
 
     private WallsAdapter mAdapter;
@@ -63,10 +66,13 @@
 
         mLoadingProgressBar = findViewById(R.id.main_loading_bar);
         mLoadingTextView = findViewById(R.id.main_loading_text);
+        mContentLayout = findViewById(R.id.main_contents);
+        mTitleView = findViewById(R.id.main_title);
         mContentRecyclerView = findViewById(R.id.main_recyclerview);
 
         setupRecyclerView();
         loadContent();
+        setupTitle();
     }
 
     @Override
@@ -116,6 +122,14 @@
         mContentRecyclerView.setAdapter(mAdapter);
     }
 
+    private void setupTitle() {
+        mContentLayout.setOnScrollChangeListener((View.OnScrollChangeListener)
+                (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
+                    final int base = v.getHeight() / 8;
+                    mTitleView.setAlpha((float) (base - scrollY) / base);
+                });
+    }
+
     private void loadContent() {
         new FetchDataTask(new FetchDataTask.Callback() {
             @Override
@@ -146,7 +160,7 @@
     private void postContentLoaded() {
         mLoadingTextView.setVisibility(View.GONE);
         mLoadingProgressBar.setVisibility(View.GONE);
-        mContentRecyclerView.setVisibility(View.VISIBLE);
+        mContentLayout.setVisibility(View.VISIBLE);
     }
 
     private void pickWallpaperFromExternalStorage() {
diff --git a/app/src/main/java/org/lineageos/backgrounds/util/UiUtils.java b/app/src/main/java/org/lineageos/backgrounds/util/UiUtils.java
index d7dee59..2d5b798 100644
--- a/app/src/main/java/org/lineageos/backgrounds/util/UiUtils.java
+++ b/app/src/main/java/org/lineageos/backgrounds/util/UiUtils.java
@@ -15,13 +15,10 @@
  */
 package org.lineageos.backgrounds.util;
 
-import android.content.res.Resources;
 import android.view.View;
-import android.view.ViewGroup;
 import android.view.Window;
 
 import androidx.annotation.ColorInt;
-import androidx.annotation.DimenRes;
 import androidx.annotation.NonNull;
 
 public final class UiUtils {
@@ -41,26 +38,4 @@
 
         window.getDecorView().setSystemUiVisibility(flags);
     }
-
-    public static void setMarginForListItem(@NonNull final Resources resources,
-                                            @NonNull final View view,
-                                            @DimenRes final int baseRes,
-                                            final boolean addNavBarMargin) {
-        final ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)
-                view.getLayoutParams();
-
-        params.bottomMargin = resources.getDimensionPixelSize(baseRes);
-
-        // Increase for eventual navBar
-        if (addNavBarMargin) {
-            final int navBarSizeId = resources.getIdentifier("navigation_bar_height",
-                    "dimen", "android");
-            if (navBarSizeId > 0) {
-                final int navBarSize = resources.getDimensionPixelSize(navBarSizeId);
-                params.bottomMargin += navBarSize;
-            }
-        }
-
-        view.setLayoutParams(params);
-    }
 }
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index f42bc8a..2db88c3 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -13,7 +13,8 @@
   See the License for the specific language governing permissions and
   limitations under the License.
   -->
-<merge xmlns:android="http://schemas.android.com/apk/res/android"
+<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">
@@ -36,13 +37,42 @@
         android:textColor="?android:attr/textColorPrimary"
         android:textSize="24sp" />
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/main_recyclerview"
+    <androidx.core.widget.NestedScrollView
+        android:id="@+id/main_contents"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_marginLeft="@dimen/main_list_margin_left"
-        android:layout_marginTop="24dp"
-        android:paddingHorizontal="4dp"
         android:visibility="gone"
-        tools:ignore="RtlHardcoded" />
-</merge>
+        app:layout_behavior="@string/appbar_scrolling_view_behavior">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/main_title"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:paddingHorizontal="16dp"
+                android:paddingTop="72dp"
+                android:paddingBottom="36dp"
+                android:text="@string/app_name"
+                android:textAppearance="@style/AppTheme.AppTitle"
+                android:textColor="?android:attr/textColorPrimary" />
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/main_recyclerview"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginHorizontal="@dimen/main_list_margin_left"
+                android:layout_marginTop="24dp"
+                android:paddingHorizontal="4dp"
+                tools:ignore="RtlHardcoded" />
+
+            <!-- Bottom margin -->
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="72dp" />
+        </LinearLayout>
+    </androidx.core.widget.NestedScrollView>
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index c23da30..ca8875d 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -47,4 +47,8 @@
         <item name="android:textAlignment">center</item>
         <item name="android:textSize">16sp</item>
     </style>
+
+    <style name="AppTheme.AppTitle" parent="AppTheme.ToolbarTitle">
+        <item name="android:textSize">48sp</item>
+    </style>
 </resources>