Merge "Update RecentsCreateView to use RecyclerView."
This commit is contained in:
@@ -28,12 +28,6 @@
|
||||
android:visibility="gone"
|
||||
style="@android:style/TextAppearance.Material.Subhead" />
|
||||
|
||||
<!-- The 'list' view is still used for RecentsCreateFragment -->
|
||||
<ListView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -90,6 +90,7 @@ abstract class BaseActivity extends Activity {
|
||||
@LayoutRes
|
||||
private int mLayoutId;
|
||||
private final String mTag;
|
||||
private DirectoryContainerView mDirectoryContainer;
|
||||
|
||||
public abstract void onDocumentPicked(DocumentInfo doc, @Nullable DocumentContext siblings);
|
||||
public abstract void onDocumentsPicked(List<DocumentInfo> docs);
|
||||
@@ -116,6 +117,7 @@ abstract class BaseActivity extends Activity {
|
||||
setContentView(mLayoutId);
|
||||
|
||||
mRoots = DocumentsApplication.getRootsCache(this);
|
||||
mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
|
||||
mSearchManager = new SearchManager();
|
||||
|
||||
// Base classes must update result in their onCreate.
|
||||
@@ -316,6 +318,7 @@ abstract class BaseActivity extends Activity {
|
||||
* @param anim
|
||||
*/
|
||||
final void onCurrentDirectoryChanged(int anim) {
|
||||
mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
|
||||
onDirectoryChanged(anim);
|
||||
|
||||
final RootsFragment roots = RootsFragment.get(getFragmentManager());
|
||||
|
||||
@@ -102,6 +102,7 @@ import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.documentsui.model.DocumentStack;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -75,8 +75,6 @@ public class DocumentsActivity extends BaseActivity {
|
||||
|
||||
private Toolbar mRootsToolbar;
|
||||
|
||||
private DirectoryContainerView mDirectoryContainer;
|
||||
|
||||
private ItemSelectedListener mStackListener;
|
||||
private BaseAdapter mStackAdapter;
|
||||
|
||||
@@ -114,8 +112,6 @@ public class DocumentsActivity extends BaseActivity {
|
||||
mDrawer = DrawerController.create(this);
|
||||
}
|
||||
|
||||
mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
|
||||
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
|
||||
mStackAdapter = new StackAdapter();
|
||||
@@ -407,8 +403,6 @@ public class DocumentsActivity extends BaseActivity {
|
||||
final RootInfo root = getCurrentRoot();
|
||||
final DocumentInfo cwd = getCurrentDirectory();
|
||||
|
||||
mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
|
||||
|
||||
if (cwd == null) {
|
||||
// No directory means recents
|
||||
if (mState.action == ACTION_CREATE ||
|
||||
|
||||
@@ -62,7 +62,6 @@ public class FilesActivity extends BaseActivity {
|
||||
|
||||
private Toolbar mToolbar;
|
||||
private Spinner mToolbarStack;
|
||||
private DirectoryContainerView mDirectoryContainer;
|
||||
private ItemSelectedListener mStackListener;
|
||||
private BaseAdapter mStackAdapter;
|
||||
private DocumentClipper mClipper;
|
||||
@@ -77,8 +76,6 @@ public class FilesActivity extends BaseActivity {
|
||||
|
||||
final Context context = this;
|
||||
|
||||
mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
|
||||
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
|
||||
mStackAdapter = new StackAdapter();
|
||||
@@ -235,8 +232,6 @@ public class FilesActivity extends BaseActivity {
|
||||
final RootInfo root = getCurrentRoot();
|
||||
final DocumentInfo cwd = getCurrentDirectory();
|
||||
|
||||
mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
|
||||
|
||||
if (cwd == null) {
|
||||
DirectoryFragment.showRecentsOpen(fm, anim);
|
||||
|
||||
|
||||
@@ -56,8 +56,6 @@ public class ManageRootActivity extends BaseActivity {
|
||||
private Toolbar mToolbar;
|
||||
private Spinner mToolbarStack;
|
||||
|
||||
private DirectoryContainerView mDirectoryContainer;
|
||||
|
||||
private ItemSelectedListener mStackListener;
|
||||
private BaseAdapter mStackAdapter;
|
||||
|
||||
@@ -73,8 +71,6 @@ public class ManageRootActivity extends BaseActivity {
|
||||
|
||||
mDrawer = DrawerController.createDummy();
|
||||
|
||||
mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
|
||||
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
mToolbar.setTitleTextAppearance(context,
|
||||
android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title);
|
||||
@@ -157,7 +153,6 @@ public class ManageRootActivity extends BaseActivity {
|
||||
// If started in manage roots mode, there has to be a cwd (i.e. the root dir of the managed
|
||||
// root).
|
||||
Preconditions.checkNotNull(cwd);
|
||||
mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
|
||||
|
||||
if (mState.currentSearch != null) {
|
||||
// Ongoing search
|
||||
|
||||
@@ -30,19 +30,19 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils.TruncateAt;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.documentsui.BaseActivity.State;
|
||||
@@ -64,8 +64,7 @@ import java.util.List;
|
||||
public class RecentsCreateFragment extends Fragment {
|
||||
|
||||
private View mEmptyView;
|
||||
private ListView mListView;
|
||||
|
||||
private RecyclerView mRecView;
|
||||
private DocumentStackAdapter mAdapter;
|
||||
private LoaderCallbacks<List<DocumentStack>> mCallbacks;
|
||||
|
||||
@@ -85,13 +84,14 @@ public class RecentsCreateFragment extends Fragment {
|
||||
|
||||
final View view = inflater.inflate(R.layout.fragment_directory, container, false);
|
||||
|
||||
mRecView = (RecyclerView) view.findViewById(R.id.recyclerView);
|
||||
mRecView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecView.addOnItemTouchListener(mItemListener);
|
||||
|
||||
mEmptyView = view.findViewById(android.R.id.empty);
|
||||
|
||||
mListView = (ListView) view.findViewById(R.id.list);
|
||||
mListView.setOnItemClickListener(mItemListener);
|
||||
|
||||
mAdapter = new DocumentStackAdapter();
|
||||
mListView.setAdapter(mAdapter);
|
||||
mRecView.setAdapter(mAdapter);
|
||||
|
||||
final RootsCache roots = DocumentsApplication.getRootsCache(context);
|
||||
final State state = ((BaseActivity) getActivity()).getDisplayState();
|
||||
@@ -105,7 +105,7 @@ public class RecentsCreateFragment extends Fragment {
|
||||
@Override
|
||||
public void onLoadFinished(
|
||||
Loader<List<DocumentStack>> loader, List<DocumentStack> data) {
|
||||
mAdapter.swapStacks(data);
|
||||
mAdapter.update(data);
|
||||
|
||||
// When launched into empty recents, show drawer
|
||||
if (mAdapter.isEmpty() && !state.stackTouched &&
|
||||
@@ -116,7 +116,7 @@ public class RecentsCreateFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<List<DocumentStack>> loader) {
|
||||
mAdapter.swapStacks(null);
|
||||
mAdapter.update(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -135,13 +135,24 @@ public class RecentsCreateFragment extends Fragment {
|
||||
getLoaderManager().destroyLoader(LOADER_RECENTS);
|
||||
}
|
||||
|
||||
private OnItemClickListener mItemListener = new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final DocumentStack stack = mAdapter.getItem(position);
|
||||
((BaseActivity) getActivity()).onStackPicked(stack);
|
||||
}
|
||||
};
|
||||
private RecyclerView.OnItemTouchListener mItemListener =
|
||||
new RecyclerView.OnItemTouchListener() {
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
||||
Events.MotionInputEvent event = new Events.MotionInputEvent(e, mRecView);
|
||||
if (event.isOverItem() && event.isActionUp()) {
|
||||
final DocumentStack stack = mAdapter.getItem(event.getItemPosition());
|
||||
((BaseActivity) getActivity()).onStackPicked(stack);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchEvent(RecyclerView rv, MotionEvent e) {}
|
||||
@Override
|
||||
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {}
|
||||
};
|
||||
|
||||
public static class RecentsCreateLoader extends UriDerivativeLoader<Uri, List<DocumentStack>> {
|
||||
private final RootsCache mRoots;
|
||||
@@ -187,14 +198,32 @@ public class RecentsCreateFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private class DocumentStackAdapter extends BaseAdapter {
|
||||
private List<DocumentStack> mStacks;
|
||||
private static final class StackHolder extends RecyclerView.ViewHolder {
|
||||
public View view;
|
||||
public StackHolder(View view) {
|
||||
super(view);
|
||||
this.view = view;
|
||||
}
|
||||
}
|
||||
|
||||
public DocumentStackAdapter() {
|
||||
private class DocumentStackAdapter extends RecyclerView.Adapter<StackHolder> {
|
||||
@Nullable private List<DocumentStack> mItems;
|
||||
|
||||
DocumentStack getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
public void swapStacks(List<DocumentStack> stacks) {
|
||||
mStacks = stacks;
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mItems == null ? 0 : mItems.size();
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return mItems == null ? true : mItems.isEmpty();
|
||||
}
|
||||
|
||||
void update(@Nullable List<DocumentStack> items) {
|
||||
mItems = items;
|
||||
|
||||
if (isEmpty()) {
|
||||
mEmptyView.setVisibility(View.VISIBLE);
|
||||
@@ -206,17 +235,22 @@ public class RecentsCreateFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final Context context = parent.getContext();
|
||||
public StackHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
final Context context = parent.getContext();
|
||||
|
||||
if (convertView == null) {
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
|
||||
}
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
return new StackHolder(
|
||||
(View) inflater.inflate(R.layout.item_doc_list, parent, false));
|
||||
}
|
||||
|
||||
final ImageView iconMime = (ImageView) convertView.findViewById(R.id.icon_mime);
|
||||
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
|
||||
final View line2 = convertView.findViewById(R.id.line2);
|
||||
@Override
|
||||
public void onBindViewHolder(StackHolder holder, int position) {
|
||||
Context context = getContext();
|
||||
View view = holder.view;
|
||||
|
||||
final ImageView iconMime = (ImageView) view.findViewById(R.id.icon_mime);
|
||||
final TextView title = (TextView) view.findViewById(android.R.id.title);
|
||||
final View line2 = view.findViewById(R.id.line2);
|
||||
|
||||
final DocumentStack stack = getItem(position);
|
||||
iconMime.setImageDrawable(stack.root.loadIcon(context));
|
||||
@@ -234,23 +268,6 @@ public class RecentsCreateFragment extends Fragment {
|
||||
title.setEllipsize(TruncateAt.MIDDLE);
|
||||
|
||||
if (line2 != null) line2.setVisibility(View.GONE);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mStacks != null ? mStacks.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentStack getItem(int position) {
|
||||
return mStacks.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return getItem(position).hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user