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
This commit is contained in:
@@ -17,61 +17,70 @@
|
||||
<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">
|
||||
android:background="@color/material_grey_50"
|
||||
android:orientation="vertical"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/empty"
|
||||
<ProgressBar
|
||||
android:id="@+id/progressbar"
|
||||
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" />
|
||||
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"
|
||||
android:layout_height="wrap_content"
|
||||
android:elevation="8dp"
|
||||
android:background="@color/material_grey_50"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!-- The empty directory view -->
|
||||
<LinearLayout
|
||||
android:id="@+id/content"
|
||||
android:id="@android:id/empty"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressbar"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
style="@style/TrimmedHorizontalProgressBar"
|
||||
android:visibility="gone"/>
|
||||
android:text="@string/empty"
|
||||
style="@android:style/TextAppearance.Material.Subhead" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container_message_bar"
|
||||
android:layout_width="match_parent"
|
||||
<Button
|
||||
android:id="@+id/button_retry"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:elevation="8dp"
|
||||
android:background="@color/material_grey_50"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!-- This FrameLayout works around b/24189541 -->
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="@dimen/grid_padding_horiz"
|
||||
android:paddingEnd="@dimen/grid_padding_horiz"
|
||||
android:paddingTop="@dimen/grid_padding_vert"
|
||||
android:paddingBottom="@dimen/grid_padding_vert"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:drawSelectorOnTop="true"
|
||||
android:background="@color/directory_background" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
android:text="@string/button_retry"
|
||||
style="?android:attr/buttonBarPositiveButtonStyle" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- This FrameLayout works around b/24189541 -->
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="@dimen/grid_padding_horiz"
|
||||
android:paddingEnd="@dimen/grid_padding_horiz"
|
||||
android:paddingTop="@dimen/grid_padding_vert"
|
||||
android:paddingBottom="@dimen/grid_padding_vert"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:drawSelectorOnTop="true"
|
||||
android:background="@color/directory_background" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</com.android.documentsui.DirectoryView>
|
||||
|
||||
@@ -81,7 +81,8 @@
|
||||
<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>
|
||||
<!-- Mode that sorts documents by their last modified time in descending order; most recent first [CHAR LIMIT=24] -->
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModelUpdateFailed(Exception e) {
|
||||
// TODO: deal with catastrophic update failures
|
||||
String error = getString(R.string.query_error);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
showErrorView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user