Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac155ab6 authored by Steve McKay's avatar Steve McKay
Browse files

Grid view padding + explicit background.

Also move section break holder into the wrapper class.

Change-Id: I949e81af180f11514aff558615cfeda44cb96a3c
parent 32e05a45
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:background="@color/window_background"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
-->

<resources>
    <dimen name="grid_container_padding">10dp</dimen>
    <dimen name="list_container_padding">0dp</dimen>

    <dimen name="icon_size">40dp</dimen>
    <dimen name="root_icon_size">24dp</dimen>
    <dimen name="root_icon_margin">0dp</dimen>
+18 −4
Original line number Diff line number Diff line
@@ -601,11 +601,11 @@ public class DirectoryFragment extends Fragment implements DocumentsAdapter.Envi
                throw new IllegalArgumentException("Unsupported layout mode: " + mode);
        }

        mRecView.setLayoutManager(layout);
        // TODO: Once b/23691541 is resolved, use a listener within MultiSelectManager instead of
        // imperatively calling this function.
        mSelectionManager.handleLayoutChanged();
        int pad = getDirectoryPadding(mode);
        mRecView.setPadding(pad, pad, pad, pad);
        // setting layout manager automatically invalidates existing ViewHolders.
        mRecView.setLayoutManager(layout);
        mSelectionManager.handleLayoutChanged();  // RecyclerView doesn't do this for us
        mIconHelper.setMode(mode);
    }

@@ -621,6 +621,20 @@ public class DirectoryFragment extends Fragment implements DocumentsAdapter.Envi
        return columnCount;
    }

    private int getDirectoryPadding(int mode) {
        switch (mode) {
            case MODE_GRID:
                return getResources().getDimensionPixelSize(
                        R.dimen.grid_container_padding);
            case MODE_LIST:
                return getResources().getDimensionPixelSize(
                        R.dimen.list_container_padding);
            case MODE_UNKNOWN:
            default:
                throw new IllegalArgumentException("Unsupported layout mode: " + mode);
        }
    }

    @Override
    public int getColumnCount() {
        return mColumnCount;
+0 −50
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.dirlist;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.widget.Space;

import com.android.documentsui.R;
import com.android.documentsui.State;

final class EmptyDocumentHolder extends DocumentHolder {
    final int mVisibleHeight;

    public EmptyDocumentHolder(Context context) {
        super(context, new Space(context));

        // Per UX spec, this puts a bigger gap between the folders and documents in the grid.
        mVisibleHeight = context.getResources().getDimensionPixelSize(R.dimen.grid_item_margin) * 2;
    }

    public void bind(State state) {
        bind(null, null, state);
    }

    @Override
    public void bind(Cursor cursor, String modelId, State state) {
        if (state.derivedMode == State.MODE_GRID) {
            itemView.setMinimumHeight(mVisibleHeight);
        } else {
            itemView.setMinimumHeight(0);
        }
        return;
    }
}
+35 −0
Original line number Diff line number Diff line
@@ -18,10 +18,16 @@ package com.android.documentsui.dirlist;

import static com.android.internal.util.Preconditions.checkArgument;

import android.content.Context;
import android.database.Cursor;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView.AdapterDataObserver;
import android.util.SparseArray;
import android.view.ViewGroup;
import android.widget.Space;

import com.android.documentsui.R;
import com.android.documentsui.State;

import java.util.List;

@@ -222,4 +228,33 @@ final class SectionBreakDocumentsAdapterWrapper extends DocumentsAdapter {
            throw new UnsupportedOperationException();
        }
    }

    /**
     * The most elegant transparent blank box that spans N rows ever conceived.
     */
    private static final class EmptyDocumentHolder extends DocumentHolder {
        final int mVisibleHeight;

        public EmptyDocumentHolder(Context context) {
            super(context, new Space(context));

            // Per UX spec, this puts a bigger gap between the folders and documents in the grid.
            mVisibleHeight = context.getResources().getDimensionPixelSize(
                    R.dimen.grid_item_margin);
        }

        public void bind(State state) {
            bind(null, null, state);
        }

        @Override
        public void bind(Cursor cursor, String modelId, State state) {
            if (state.derivedMode == State.MODE_GRID) {
                itemView.setMinimumHeight(mVisibleHeight);
            } else {
                itemView.setMinimumHeight(0);
            }
            return;
        }
    }
}