Merge "Provide siblings in a sorted orders in DocumentsUI." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7d37da7086
@@ -50,6 +50,7 @@ import android.widget.Spinner;
|
||||
import com.android.documentsui.SearchManager.SearchManagerListener;
|
||||
import com.android.documentsui.State.ViewMode;
|
||||
import com.android.documentsui.dirlist.DirectoryFragment;
|
||||
import com.android.documentsui.dirlist.Model;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.documentsui.model.DocumentStack;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
@@ -86,7 +87,7 @@ public abstract class BaseActivity extends Activity
|
||||
|
||||
private boolean mNavDrawerHasFocus;
|
||||
|
||||
public abstract void onDocumentPicked(DocumentInfo doc, @Nullable SiblingProvider siblings);
|
||||
public abstract void onDocumentPicked(DocumentInfo doc, Model model);
|
||||
public abstract void onDocumentsPicked(List<DocumentInfo> docs);
|
||||
|
||||
abstract void onTaskFinished(Uri... uris);
|
||||
@@ -701,17 +702,4 @@ public abstract class BaseActivity extends Activity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface providing access to current view of documents
|
||||
* even when all documents are not homed to the same parent.
|
||||
*/
|
||||
public interface SiblingProvider {
|
||||
/**
|
||||
* Returns the cursor for the selected document. The cursor can be used to retrieve
|
||||
* details about a document and its siblings.
|
||||
* @return
|
||||
*/
|
||||
Cursor getCursor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import android.view.MenuItem;
|
||||
import com.android.documentsui.RecentsProvider.RecentColumns;
|
||||
import com.android.documentsui.RecentsProvider.ResumeColumns;
|
||||
import com.android.documentsui.dirlist.DirectoryFragment;
|
||||
import com.android.documentsui.dirlist.Model;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.documentsui.model.DurableUtils;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
@@ -328,7 +329,7 @@ public class DocumentsActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDocumentPicked(DocumentInfo doc, SiblingProvider siblings) {
|
||||
public void onDocumentPicked(DocumentInfo doc, Model model) {
|
||||
final FragmentManager fm = getFragmentManager();
|
||||
if (doc.isContainer()) {
|
||||
openContainerDocument(doc);
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.view.MenuItem;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.android.documentsui.dirlist.DirectoryFragment;
|
||||
import com.android.documentsui.dirlist.Model;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.documentsui.model.RootInfo;
|
||||
import com.android.internal.util.Preconditions;
|
||||
@@ -132,7 +133,7 @@ public class DownloadsActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDocumentPicked(DocumentInfo doc, SiblingProvider siblings) {
|
||||
public void onDocumentPicked(DocumentInfo doc, Model model) {
|
||||
Preconditions.checkArgument(!doc.isDirectory());
|
||||
// First try managing the document; we expect manager to filter
|
||||
// based on authority, so we don't grant.
|
||||
|
||||
@@ -43,6 +43,7 @@ import android.view.MenuItem;
|
||||
import com.android.documentsui.OperationDialogFragment.DialogType;
|
||||
import com.android.documentsui.RecentsProvider.ResumeColumns;
|
||||
import com.android.documentsui.dirlist.DirectoryFragment;
|
||||
import com.android.documentsui.dirlist.Model;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
import com.android.documentsui.model.DocumentStack;
|
||||
import com.android.documentsui.model.DurableUtils;
|
||||
@@ -272,24 +273,20 @@ public class FilesActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDocumentPicked(DocumentInfo doc, @Nullable SiblingProvider siblings) {
|
||||
public void onDocumentPicked(DocumentInfo doc, Model model) {
|
||||
if (doc.isContainer()) {
|
||||
openContainerDocument(doc);
|
||||
} else {
|
||||
openDocument(doc, siblings);
|
||||
openDocument(doc, model);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches an intent to view the specified document.
|
||||
*/
|
||||
private void openDocument(DocumentInfo doc, @Nullable SiblingProvider siblings) {
|
||||
Intent intent = null;
|
||||
if (siblings != null) {
|
||||
QuickViewIntentBuilder builder = new QuickViewIntentBuilder(
|
||||
getPackageManager(), getResources(), doc, siblings);
|
||||
intent = builder.build();
|
||||
}
|
||||
private void openDocument(DocumentInfo doc, Model model) {
|
||||
Intent intent = new QuickViewIntentBuilder(
|
||||
getPackageManager(), getResources(), doc, model).build();
|
||||
|
||||
if (intent != null) {
|
||||
// TODO: un-work around issue b/24963914. Should be fixed soon.
|
||||
|
||||
@@ -34,16 +34,18 @@ import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.documentsui.BaseActivity.SiblingProvider;
|
||||
import com.android.documentsui.dirlist.Model;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides support for gather a list of quick-viewable files into a quick view intent.
|
||||
*/
|
||||
final class QuickViewIntentBuilder {
|
||||
|
||||
private final DocumentInfo mDocument;
|
||||
private final SiblingProvider mSiblings;
|
||||
private final Model mModel;
|
||||
|
||||
private final PackageManager mPkgManager;
|
||||
private final Resources mResources;
|
||||
@@ -55,12 +57,12 @@ final class QuickViewIntentBuilder {
|
||||
PackageManager pkgManager,
|
||||
Resources resources,
|
||||
DocumentInfo doc,
|
||||
SiblingProvider siblings) {
|
||||
Model model) {
|
||||
|
||||
mPkgManager = pkgManager;
|
||||
mResources = resources;
|
||||
mDocument = doc;
|
||||
mSiblings = siblings;
|
||||
mModel = model;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,9 +80,9 @@ final class QuickViewIntentBuilder {
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
intent.setPackage(trustedPkg);
|
||||
if (hasRegisteredHandler(intent)) {
|
||||
Cursor cursor = mSiblings.getCursor();
|
||||
for (int i = 0; i < cursor.getCount(); i++) {
|
||||
onNextItem(i, cursor);
|
||||
List<String> siblingIds = mModel.getModelIds();
|
||||
for (int i = 0; i < siblingIds.size(); i++) {
|
||||
onNextItem(i, siblingIds);
|
||||
}
|
||||
intent.putExtra(Intent.EXTRA_INDEX, mDocumentLocation);
|
||||
intent.setClipData(mClipData);
|
||||
@@ -99,8 +101,12 @@ final class QuickViewIntentBuilder {
|
||||
return intent.resolveActivity(mPkgManager) != null;
|
||||
}
|
||||
|
||||
private void onNextItem(int index, Cursor cursor) {
|
||||
cursor.moveToPosition(index);
|
||||
private void onNextItem(int index, List<String> siblingIds) {
|
||||
final Cursor cursor = mModel.getItem(siblingIds.get(index));
|
||||
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
|
||||
if (Document.MIME_TYPE_DIR.equals(mimeType)) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.documentsui.BaseActivity.SiblingProvider;
|
||||
import com.android.documentsui.DirectoryResult;
|
||||
import com.android.documentsui.RootCursorWrapper;
|
||||
import com.android.documentsui.dirlist.MultiSelectManager.Selection;
|
||||
@@ -48,7 +47,7 @@ import java.util.Map;
|
||||
* The data model for the current loaded directory.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public class Model implements SiblingProvider {
|
||||
public class Model {
|
||||
private static final String TAG = "Model";
|
||||
|
||||
private boolean mIsLoading;
|
||||
@@ -358,7 +357,7 @@ public class Model implements SiblingProvider {
|
||||
return (l == -1) ? Long.MAX_VALUE : l;
|
||||
}
|
||||
|
||||
@Nullable Cursor getItem(String modelId) {
|
||||
public @Nullable Cursor getItem(String modelId) {
|
||||
Integer pos = mPositions.get(modelId);
|
||||
if (pos != null) {
|
||||
mCursor.moveToPosition(pos);
|
||||
@@ -388,14 +387,6 @@ public class Model implements SiblingProvider {
|
||||
return docs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getCursor() {
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
throw new IllegalStateException("Can't call getCursor from non-main thread.");
|
||||
}
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
void addUpdateListener(UpdateListener listener) {
|
||||
mUpdateListeners.add(listener);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user