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

Commit 37386768 authored by Ben Kwa's avatar Ben Kwa Committed by Android (Google) Code Review
Browse files

Merge "Restore more missing DirectoryFragment functionality."

parents d179b862 91caed80
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->

<!-- Variant of progress_indeterminate_horizontal_material in frameworks/base/core/res, which
     draws the whole height of the progress bar instead having blank space above and below the
     bar. -->
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/vector_drawable_progress_indeterminate_horizontal_trimmed" >
    <target
        android:name="rect2_grp"
        android:animation="@*android:anim/progress_indeterminate_horizontal_rect2" />
    <target
        android:name="rect1_grp"
        android:animation="@*android:anim/progress_indeterminate_horizontal_rect1" />
</animated-vector>
+53 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->

<!-- Variant of vector_drawable_progress_indeterminate_horizontal in frameworks/base/core/res, which
     draws the whole height of the progress bar instead having blank space above and below the
     bar. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="10dp"
    android:width="360dp"
    android:viewportHeight="10"
    android:viewportWidth="360" >
    <group
        android:name="progress_group"
        android:translateX="180"
        android:translateY="5" >
        <path
            android:name="background_track"
            android:pathData="M -180.0,-5.0 l 360.0,0 l 0,10.0 l -360.0,0 Z"
            android:fillColor="?android:attr/colorControlActivated"
            android:fillAlpha="?android:attr/disabledAlpha"/>
        <group
            android:name="rect2_grp"
            android:translateX="-197.60001"
            android:scaleX="0.1" >
            <path
                android:name="rect2"
                android:pathData="M -144.0,-5.0 l 288.0,0 l 0,10.0 l -288.0,0 Z"
                android:fillColor="?android:attr/colorControlActivated" />
        </group>
        <group
            android:name="rect1_grp"
            android:translateX="-522.59998"
            android:scaleX="0.1" >
            <path
                android:name="rect1"
                android:pathData="M -144.0,-5.0 l 288.0,0 l 0,10.0 l -288.0,0 Z"
                android:fillColor="?android:attr/colorControlActivated" />
        </group>
    </group>
</vector>
+12 −4
Original line number Diff line number Diff line
@@ -41,6 +41,14 @@
        android:orientation="vertical"
        android:animateLayoutChanges="true">

        <ProgressBar
            android:id="@+id/progressbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:indeterminate="true"
            style="@style/TrimmedHorizontalProgressBar"
            android:visibility="gone"/>

        <FrameLayout
            android:id="@+id/container_message_bar"
            android:layout_width="match_parent"
+8 −2
Original line number Diff line number Diff line
@@ -77,9 +77,9 @@
        <item name="android:colorPrimaryDark">@color/platform_blue_700</item>
        <item name="android:colorPrimary">@color/platform_blue_500</item>
        <item name="android:colorAccent">@color/platform_blue_700</item>
        <item name="colorControlActivated">@color/platform_blue_a100</item>
        <item name="android:actionModeStyle">@style/FilesActionModeStyle</item>
        <item name="colorActionMode">@color/platform_blue_700</item>

        <item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
    </style>

@@ -87,4 +87,10 @@
        <item name="android:background">@color/platform_blue_100</item>
    </style>

    <style name="TrimmedHorizontalProgressBar" parent="android:Widget.Material.ProgressBar.Horizontal">
        <item name="android:indeterminateDrawable">@drawable/progress_indeterminate_horizontal_material_trimmed</item>
        <item name="android:minHeight">3dp</item>
        <item name="android:maxHeight">3dp</item>    
    </style>

</resources>
+43 −51
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ public class DirectoryFragment extends Fragment {
    private static final String EXTRA_IGNORE_STATE = "ignoreState";

    private Model mModel;
    private Model.UpdateListener mModelUpdateListener = new ModelUpdateListener();

    private final Handler mHandler = new Handler(Looper.getMainLooper());

@@ -160,6 +161,7 @@ public class DirectoryFragment extends Fragment {
    private int mColumnCount = 1;  // This will get updated when layout changes.

    private MessageBar mMessageBar;
    private View mProgressBar;

    public static void showNormal(FragmentManager fm, RootInfo root, DocumentInfo doc, int anim) {
        show(fm, TYPE_NORMAL, root, doc, null, anim);
@@ -223,6 +225,7 @@ public class DirectoryFragment extends Fragment {
        final View view = inflater.inflate(R.layout.fragment_directory, container, false);

        mMessageBar = MessageBar.create(getChildFragmentManager());
        mProgressBar = view.findViewById(R.id.progressbar);

        mEmptyView = view.findViewById(android.R.id.empty);

@@ -311,9 +314,8 @@ public class DirectoryFragment extends Fragment {
                    : MultiSelectManager.MODE_SINGLE);
        selMgr.addCallback(new SelectionModeListener());

        mModel = new Model(context, selMgr);
        mModel.setSelectionManager(selMgr);
        mModel.addUpdateListener(mAdapter);
        mModel = new Model(context, selMgr, mAdapter);
        mModel.addUpdateListener(mModelUpdateListener);

        mType = getArguments().getInt(EXTRA_TYPE);
        mStateKey = buildStateKey(root, doc);
@@ -897,8 +899,7 @@ public class DirectoryFragment extends Fragment {
        }
    }

    private final class DocumentsAdapter extends RecyclerView.Adapter<DocumentHolder>
            implements Model.UpdateListener {
    private final class DocumentsAdapter extends RecyclerView.Adapter<DocumentHolder> {

        private final Context mContext;
        private final LayoutInflater mInflater;
@@ -908,30 +909,6 @@ public class DirectoryFragment extends Fragment {
            mInflater = LayoutInflater.from(context);
        }

        @Override
        public void onModelUpdate(Model model) {
            if (model.info != null || model.error != null) {
                mMessageBar.setInfo(model.info);
                mMessageBar.setError(model.error);
                mMessageBar.show();
            }

            if (model.isEmpty()) {
                mEmptyView.setVisibility(View.VISIBLE);
            } else {
                mEmptyView.setVisibility(View.GONE);
            }

            notifyDataSetChanged();
        }

        @Override
        public void onModelUpdateFailed(Exception e) {
            // TODO: deal with catastrophic update failures
            String error = getString(R.string.query_error);
            notifyDataSetChanged();
        }

        @Override
        public DocumentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            final State state = getDisplayState(DirectoryFragment.this);
@@ -1675,6 +1652,7 @@ public class DirectoryFragment extends Fragment {
    @VisibleForTesting
    public static final class Model implements DocumentContext {
        private MultiSelectManager mSelectionManager;
        private RecyclerView.Adapter<?> mViewAdapter;
        private Context mContext;
        private int mCursorCount;
        private boolean mIsLoading;
@@ -1684,17 +1662,11 @@ public class DirectoryFragment extends Fragment {
        @Nullable private String info;
        @Nullable private String error;

        Model(Context context, MultiSelectManager selectionManager) {
        Model(Context context, MultiSelectManager selectionManager,
                RecyclerView.Adapter<?> viewAdapter) {
            mContext = context;
            mSelectionManager = selectionManager;
        }

        /**
         * Sets the selection manager used by the model.
         * TODO: the model should instantiate the selection manager.  See onActivityCreated.
         */
        void setSelectionManager(MultiSelectManager mgr) {
            mSelectionManager = mgr;
            mViewAdapter = viewAdapter;
        }

        /**
@@ -1859,7 +1831,7 @@ public class DirectoryFragment extends Fragment {
                int position = selected.get(i);
                if (DEBUG) Log.d(TAG, "Marked position " + position + " for deletion");
                mMarkedForDeletion.append(position, true);
                mUpdateListener.notifyItemRemoved(position);
                mViewAdapter.notifyItemRemoved(position);
            }
        }

@@ -1874,7 +1846,7 @@ public class DirectoryFragment extends Fragment {
            for (int i = 0; i < size; ++i) {
                final int position = mMarkedForDeletion.keyAt(i);
                mMarkedForDeletion.put(position, false);
                mUpdateListener.notifyItemInserted(position);
                mViewAdapter.notifyItemInserted(position);
            }

            // Then, clear the deletion list.
@@ -1957,26 +1929,46 @@ public class DirectoryFragment extends Fragment {
            mUpdateListener = listener;
        }

        interface UpdateListener {
        static class UpdateListener {
            /**
             * Called when a successful update has occurred.
             */
            void onModelUpdate(Model model);
            void onModelUpdate(Model model) {}

            /**
             * Called when an update has been attempted but failed.
             */
            void onModelUpdateFailed(Exception e);
            void onModelUpdateFailed(Exception e) {}
        }
    }

            /**
             * Called when an item has been removed from the model.
             */
            void notifyItemRemoved(int position);
    private class ModelUpdateListener extends Model.UpdateListener {
        @Override
        public void onModelUpdate(Model model) {
            if (model.info != null || model.error != null) {
                mMessageBar.setInfo(model.info);
                mMessageBar.setError(model.error);
                mMessageBar.show();
            }

            /**
             * Called when an item has been added to the model.
             */
            void notifyItemInserted(int position);
            mProgressBar.setVisibility(model.isLoading() ? View.VISIBLE : View.GONE);

            if (model.isEmpty()) {
                mEmptyView.setVisibility(View.VISIBLE);
                mRecView.setVisibility(View.GONE);
            } else {
                mEmptyView.setVisibility(View.GONE);
                mRecView.setVisibility(View.VISIBLE);
            }

            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onModelUpdateFailed(Exception e) {
            // TODO: deal with catastrophic update failures
            String error = getString(R.string.query_error);
            mAdapter.notifyDataSetChanged();
        }
    }
}
Loading