Merge "Don't show title in delete confirmation." into nyc-dev
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 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.
|
||||
-->
|
||||
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="30dp"
|
||||
android:gravity="center"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="@*android:color/primary_text_default_material_light">
|
||||
</TextView>
|
||||
@@ -208,11 +208,9 @@
|
||||
<string name="allow">Allow</string>
|
||||
<!-- Text in the button asking user to deny access to a given directory. -->
|
||||
<string name="deny">Deny</string>
|
||||
<!-- Dialog title shown to users when asking if they want to delete files (a confirmation). -->
|
||||
<string name="delete_confirmation_title">Delete files?</string>
|
||||
<!-- Dialog text shown to users when asking if they want to delete files (a confirmation). -->
|
||||
<plurals name="delete_confirmation_message">
|
||||
<item quantity="one">Are you sure you want to delete <xliff:g id="count" example="1">%1$d</xliff:g> file?</item>
|
||||
<item quantity="other">Are you sure you want to delete <xliff:g id="count" example="3">%1$d</xliff:g> files?</item>
|
||||
<item quantity="one">Delete <xliff:g id="count" example="1">%1$d</xliff:g> file?</item>
|
||||
<item quantity="other">Delete <xliff:g id="count" example="3">%1$d</xliff:g> files?</item>
|
||||
</plurals>
|
||||
</resources>
|
||||
|
||||
@@ -168,6 +168,7 @@ public class DirectoryFragment extends Fragment
|
||||
private GridLayoutManager mLayout;
|
||||
private int mColumnCount = 1; // This will get updated when layout changes.
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private MessageBar mMessageBar;
|
||||
private View mProgressBar;
|
||||
|
||||
@@ -182,13 +183,12 @@ public class DirectoryFragment extends Fragment
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mInflater = inflater;
|
||||
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);
|
||||
|
||||
mRecView = (RecyclerView) view.findViewById(R.id.dir_list);
|
||||
mRecView.setRecyclerListener(
|
||||
new RecyclerListener() {
|
||||
@@ -708,13 +708,27 @@ public class DirectoryFragment extends Fragment
|
||||
new GetDocumentsTask() {
|
||||
@Override
|
||||
void onDocumentsReady(final List<DocumentInfo> docs) {
|
||||
|
||||
TextView message =
|
||||
(TextView) mInflater.inflate(R.layout.dialog_delete_confirmation, null);
|
||||
message.setText(
|
||||
Shared.getQuantityString(
|
||||
getActivity(),
|
||||
R.plurals.delete_confirmation_message,
|
||||
docs.size()));
|
||||
|
||||
// This "insta-hides" files that are being deleted, because
|
||||
// the delete operation may be not execute immediately (it
|
||||
// may be queued up on the FileOperationService.)
|
||||
// To hide the files locally, we call the hide method on the adapter
|
||||
// ...which a live object...cannot be parceled.
|
||||
// For that reason, for now, we implement this dialog NOT
|
||||
// as a fragment (which can survive rotation and have its own state),
|
||||
// but as a simple runtime dialog. So rotating a device with an
|
||||
// active delete dialog...results in that dialog disappearing.
|
||||
// We can do better, but don't have cycles for it now.
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.delete_confirmation_title)
|
||||
.setMessage(
|
||||
Shared.getQuantityString(
|
||||
getActivity(),
|
||||
R.plurals.delete_confirmation_message,
|
||||
docs.size()))
|
||||
.setView(message)
|
||||
.setPositiveButton(
|
||||
android.R.string.yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@@ -73,13 +73,6 @@ abstract class DocumentsAdapter
|
||||
*/
|
||||
abstract public SparseArray<String> hide(String... ids);
|
||||
|
||||
/**
|
||||
* Unhides a set of previously hidden items.
|
||||
*
|
||||
* @param ids A sparse array of IDs from a previous call to {@link #hide}.
|
||||
*/
|
||||
abstract void unhide(SparseArray<String> ids);
|
||||
|
||||
/**
|
||||
* Returns a class that yields the span size for a particular element. This is
|
||||
* primarily useful in {@link SectionBreakDocumentsAdapterWrapper} where
|
||||
|
||||
@@ -24,12 +24,12 @@ import static com.android.documentsui.model.DocumentInfo.getCursorString;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.documentsui.State;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -181,29 +181,6 @@ final class ModelBackedDocumentsAdapter extends DocumentsAdapter {
|
||||
return hiddenItems;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@Override
|
||||
public void unhide(SparseArray<String> ids) {
|
||||
if (DEBUG) Log.d(TAG, "Unhiding ids: " + ids);
|
||||
|
||||
// An ArrayList can shrink at runtime...and in fact
|
||||
// it does when we clear it completely.
|
||||
// This means we can't call add(pos, id) without
|
||||
// first checking the list size.
|
||||
List<String> oldIds = mModelIds;
|
||||
mModelIds = new ArrayList<>(oldIds.size() + ids.size());
|
||||
mModelIds.addAll(oldIds);
|
||||
|
||||
// Finally insert the unhidden items.
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
int pos = ids.keyAt(i);
|
||||
String id = ids.get(pos);
|
||||
mHiddenIds.remove(id);
|
||||
mModelIds.add(pos, id);
|
||||
notifyItemInserted(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getModelIds() {
|
||||
return mModelIds;
|
||||
|
||||
@@ -168,13 +168,6 @@ final class SectionBreakDocumentsAdapterWrapper extends DocumentsAdapter {
|
||||
return mDelegate.hide(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
void unhide(SparseArray<String> ids) {
|
||||
// NOTE: We hear about these changes and adjust break position
|
||||
// in our AdapterDataObserver.
|
||||
mDelegate.unhide(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
List<String> getModelIds() {
|
||||
return mDelegate.getModelIds();
|
||||
|
||||
@@ -73,28 +73,6 @@ public class ModelBackedDocumentsAdapterTest extends AndroidTestCase {
|
||||
assertEquals(mModel.getItemCount() - 2, mAdapter.getItemCount());
|
||||
}
|
||||
|
||||
// Tests that the items can be hidden and unhidden.
|
||||
public void testUnhide_ItemCount() {
|
||||
List<String> ids = mModel.getModelIds();
|
||||
SparseArray<String> hidden = mAdapter.hide(ids.toArray(new String[ids.size()]));
|
||||
mAdapter.unhide(hidden);
|
||||
assertEquals(mModel.getItemCount(), mAdapter.getItemCount());
|
||||
}
|
||||
|
||||
// Tests that the items can be hidden and unhidden.
|
||||
public void testUnhide_PreservesOrder() {
|
||||
List<String> ids = mModel.getModelIds();
|
||||
SparseArray<String> hidden = mAdapter.hide(
|
||||
ids.get(0), ids.get(1), ids.get(5), ids.get(9));
|
||||
mAdapter.unhide(hidden);
|
||||
|
||||
// Finally ensure the restored items are in the original order
|
||||
// by checking them against the model.
|
||||
for (int i = 0; i < mAdapter.getItemCount(); i++) {
|
||||
assertEquals(mModel.idForPosition(i), mAdapter.getModelId(i));
|
||||
}
|
||||
}
|
||||
|
||||
private final class TestEnvironment implements DocumentsAdapter.Environment {
|
||||
private final Context testContext;
|
||||
|
||||
|
||||
@@ -60,11 +60,6 @@ public class TestDocumentsAdapter extends DocumentsAdapter {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
void unhide(SparseArray<String> ids) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
Reference in New Issue
Block a user