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

Commit 91bec536 authored by Ben Kwa's avatar Ben Kwa
Browse files

DocumentsUI: Add an error screen to DirectoryFragment.

- Reorganize the directory fragment.
- Repurpose the "empty" view to hold a message and a button.
- Message is set to the "No items" message if a directory is empty.
- Message is set to the error message if a query error occurs.
- Don't close DocumentsUI when a query error occurs.

Change-Id: I4e1e96f23040606b410ac746252dcb0ab9286f04
parent 7d92c474
Loading
Loading
Loading
Loading
+52 −43
Original line number Diff line number Diff line
@@ -17,21 +17,7 @@
<com.android.documentsui.DirectoryView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/material_grey_50">

    <TextView
        android:id="@android:id/empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/empty"
        android:visibility="gone"
        style="@android:style/TextAppearance.Material.Subhead" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    android:background="@color/material_grey_50"
    android:orientation="vertical"
    android:animateLayoutChanges="true">

@@ -51,6 +37,31 @@
        android:background="@color/material_grey_50"
        android:visibility="gone"/>

    <!-- The empty directory view -->
    <LinearLayout
        android:id="@android:id/empty"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="gone">
        
        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/empty"
            style="@android:style/TextAppearance.Material.Subhead" />

         <Button
            android:id="@+id/button_retry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_retry"
            style="?android:attr/buttonBarPositiveButtonStyle" />
        
    </LinearLayout>
    
    <!-- This FrameLayout works around b/24189541 -->
    <FrameLayout
        android:layout_width="match_parent"
@@ -72,6 +83,4 @@

    </FrameLayout>

    </LinearLayout>

</com.android.documentsui.DirectoryView>
+2 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@
    <string name="button_move">Move</string>
    <!-- Button label that hides the error bar [CHAR LIMIT=24] -->
    <string name="button_dismiss">Dismiss</string>
    <string name="button_retry">Try Again</string>
    
    <!-- Mode that sorts documents by their display name alphabetically [CHAR LIMIT=24] -->
    <string name="sort_name">By name</string>
+27 −24
Original line number Diff line number Diff line
@@ -369,21 +369,6 @@ public class DirectoryFragment extends Fragment {

            @Override
            public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
                if (result == null || result.exception != null) {
                    // onBackPressed does a fragment transaction, which can't be done inside
                    // onLoadFinished
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            final Activity activity = getActivity();
                            if (activity != null) {
                                activity.onBackPressed();
                            }
                        }
                    });
                    return;
                }

                if (!isAdded()) return;

                mModel.update(result);
@@ -900,6 +885,29 @@ public class DirectoryFragment extends Fragment {
        }
    }

    void showEmptyView() {
        mEmptyView.setVisibility(View.VISIBLE);
        mRecView.setVisibility(View.GONE);
        TextView msg = (TextView) mEmptyView.findViewById(R.id.message);
        msg.setText(R.string.empty);
        // No retry button for the empty view.
        mEmptyView.findViewById(R.id.button_retry).setVisibility(View.GONE);
    }

    void showErrorView() {
        mEmptyView.setVisibility(View.VISIBLE);
        mRecView.setVisibility(View.GONE);
        TextView msg = (TextView) mEmptyView.findViewById(R.id.message);
        msg.setText(R.string.query_error);
        // TODO: Enable this once the retry button does something.
        mEmptyView.findViewById(R.id.button_retry).setVisibility(View.GONE);
    }

    void showRecyclerView() {
        mEmptyView.setVisibility(View.GONE);
        mRecView.setVisibility(View.VISIBLE);
    }

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

        private final Context mContext;
@@ -1955,21 +1963,16 @@ public class DirectoryFragment extends Fragment {
            mProgressBar.setVisibility(model.isLoading() ? View.VISIBLE : View.GONE);

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

                showRecyclerView();
                mAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onModelUpdateFailed(Exception e) {
            // TODO: deal with catastrophic update failures
            String error = getString(R.string.query_error);
            mAdapter.notifyDataSetChanged();
            showErrorView();
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -18,9 +18,9 @@ package com.android.documentsui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class DirectoryView extends FrameLayout {
public class DirectoryView extends LinearLayout {
    private float mPosition = 0f;

    private int mWidth;