Merge "Save and restore PickFragment's internal state." into nyc-andromeda-dev
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java
index d9d6cf4..c9050e7 100644
--- a/src/com/android/documentsui/BaseActivity.java
+++ b/src/com/android/documentsui/BaseActivity.java
@@ -209,7 +209,6 @@
@Override
public void onSearchViewChanged(boolean opened) {
- mState.sortModel.setSortEnabled(!opened);
mNavigator.update();
}
};
diff --git a/src/com/android/documentsui/sorting/DropdownSortWidgetController.java b/src/com/android/documentsui/sorting/DropdownSortWidgetController.java
index 7977591..21c182c 100644
--- a/src/com/android/documentsui/sorting/DropdownSortWidgetController.java
+++ b/src/com/android/documentsui/sorting/DropdownSortWidgetController.java
@@ -21,18 +21,14 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import com.android.documentsui.R;
import com.android.documentsui.sorting.SortController.WidgetController;
-import com.android.documentsui.sorting.SortDimension;
import com.android.documentsui.sorting.SortDimension.SortDirection;
-import com.android.documentsui.sorting.SortModel;
import com.android.documentsui.sorting.SortModel.SortDimensionId;
-import com.android.documentsui.sorting.SortModel.UpdateListener;
import com.android.documentsui.sorting.SortModel.UpdateType;
/**
@@ -49,24 +45,23 @@
private final PopupMenu mMenu;
private final ImageView mArrow;
- private final OnClickListener mDimensionButtonClickListener = this::showMenu;
- private final OnClickListener mArrowClickListener = this::onChangeDirection;
- private final UpdateListener mUpdateListener = this::onModelUpdate;
-
public DropdownSortWidgetController(SortModel model, View widget) {
mModel = model;
mWidget = widget;
mDimensionButton = (TextView) mWidget.findViewById(R.id.sort_dimen_dropdown);
+ mDimensionButton.setOnClickListener(this::showMenu);
+
mMenu = new PopupMenu(widget.getContext(), mDimensionButton, Gravity.END | Gravity.TOP);
mMenu.setOnMenuItemClickListener(this::onSelectDimension);
mArrow = (ImageView) mWidget.findViewById(R.id.sort_arrow);
+ mArrow.setOnClickListener(this::onChangeDirection);
populateMenuItems();
onModelUpdate(mModel, SortModel.UPDATE_TYPE_UNSPECIFIED);
- mModel.addListener(mUpdateListener);
+ mModel.addListener(this::onModelUpdate);
}
@Override
@@ -92,10 +87,6 @@
private void onModelUpdate(SortModel model, @UpdateType int updateType) {
final @SortDimensionId int sortedId = model.getSortedDimensionId();
- if ((updateType & SortModel.UPDATE_TYPE_STATUS) != 0) {
- setEnabled(mModel.isSortEnabled());
- }
-
if ((updateType & SortModel.UPDATE_TYPE_VISIBILITY) != 0) {
updateVisibility();
}
@@ -106,17 +97,6 @@
}
}
- private void setEnabled(boolean enabled) {
- if (enabled) {
- mDimensionButton.setOnClickListener(mDimensionButtonClickListener);
- mArrow.setOnClickListener(mArrowClickListener);
- } else {
- mMenu.dismiss();
- mDimensionButton.setOnClickListener(null);
- mArrow.setOnClickListener(null);
- }
- }
-
private void updateVisibility() {
Menu menu = mMenu.getMenu();
diff --git a/src/com/android/documentsui/sorting/SortModel.java b/src/com/android/documentsui/sorting/SortModel.java
index f64bc28..a5c8459 100644
--- a/src/com/android/documentsui/sorting/SortModel.java
+++ b/src/com/android/documentsui/sorting/SortModel.java
@@ -60,7 +60,6 @@
@IntDef(flag = true, value = {
UPDATE_TYPE_NONE,
UPDATE_TYPE_UNSPECIFIED,
- UPDATE_TYPE_STATUS,
UPDATE_TYPE_VISIBILITY,
UPDATE_TYPE_SORTING
})
@@ -71,18 +70,14 @@
*/
public static final int UPDATE_TYPE_NONE = 0;
/**
- * Indicates the status of sorting has changed, i.e. whether soring is enabled.
- */
- public static final int UPDATE_TYPE_STATUS = 1;
- /**
* Indicates the visibility of at least one dimension has changed.
*/
- public static final int UPDATE_TYPE_VISIBILITY = 1 << 1;
+ public static final int UPDATE_TYPE_VISIBILITY = 1;
/**
* Indicates the sorting order has changed, either because the sorted dimension has changed or
* the sort direction has changed.
*/
- public static final int UPDATE_TYPE_SORTING = 1 << 2;
+ public static final int UPDATE_TYPE_SORTING = 1 << 1;
/**
* Anything can be changed if the type is unspecified.
*/
@@ -99,8 +94,6 @@
private boolean mIsUserSpecified = false;
private @Nullable SortDimension mSortedDimension;
- private boolean mIsSortEnabled = true;
-
public SortModel(Collection<SortDimension> columns) {
mDimensions = new SparseArray<>(columns.size());
@@ -146,16 +139,6 @@
: SortDimension.SORT_DIRECTION_NONE;
}
- public void setSortEnabled(boolean enabled) {
- mIsSortEnabled = enabled;
-
- notifyListeners(UPDATE_TYPE_STATUS);
- }
-
- public boolean isSortEnabled() {
- return mIsSortEnabled;
- }
-
/**
* Sort by the default direction of the given dimension if user has never specified any sort
* direction before.
@@ -182,10 +165,6 @@
* @param direction the direction to sort docs in
*/
public void sortByUser(int dimensionId, @SortDirection int direction) {
- if (!mIsSortEnabled) {
- throw new IllegalStateException("Sort is not enabled.");
- }
-
SortDimension dimension = mDimensions.get(dimensionId);
if (dimension == null) {
throw new IllegalArgumentException("Unknown column id: " + dimensionId);
@@ -299,17 +278,6 @@
mListeners.remove(listener);
}
- public void clearSortDirection() {
- if (mSortedDimension != null) {
- mSortedDimension.mSortDirection = SortDimension.SORT_DIRECTION_NONE;
- mSortedDimension = null;
- }
-
- mIsUserSpecified = false;
-
- sortOnDefault();
- }
-
/**
* Sort by default dimension and direction if there is no history of user specifying a sort
* order.
@@ -349,7 +317,6 @@
}
return mDefaultDimensionId == other.mDefaultDimensionId
- && mIsSortEnabled == other.mIsSortEnabled
&& (mSortedDimension == other.mSortedDimension
|| mSortedDimension.equals(other.mSortedDimension));
}
@@ -358,8 +325,7 @@
public String toString() {
return new StringBuilder()
.append("SortModel{")
- .append("enabled=").append(mIsSortEnabled)
- .append(", dimensions=").append(mDimensions)
+ .append("dimensions=").append(mDimensions)
.append(", defaultDimensionId=").append(mDefaultDimensionId)
.append(", sortedDimension=").append(mSortedDimension)
.append("}")
@@ -379,7 +345,6 @@
}
out.writeInt(mDefaultDimensionId);
- out.writeInt(mIsSortEnabled ? 1 : 0);
out.writeInt(getSortedDimensionId());
}
@@ -395,7 +360,6 @@
SortModel model = new SortModel(columns);
model.mDefaultDimensionId = in.readInt();
- model.mIsSortEnabled = (in.readInt() == 1);
model.mSortedDimension = model.getDimensionById(in.readInt());
return model;
diff --git a/src/com/android/documentsui/sorting/TableHeaderController.java b/src/com/android/documentsui/sorting/TableHeaderController.java
index c5957ce..da82a6e 100644
--- a/src/com/android/documentsui/sorting/TableHeaderController.java
+++ b/src/com/android/documentsui/sorting/TableHeaderController.java
@@ -76,8 +76,7 @@
cell.setTag(dimension);
cell.onBind(dimension);
- if (mModel.isSortEnabled()
- && dimension.getVisibility() == View.VISIBLE
+ if (dimension.getVisibility() == View.VISIBLE
&& dimension.getSortCapability() != SortDimension.SORT_CAPABILITY_NONE) {
cell.setOnClickListener(mOnCellClickListener);
} else {
diff --git a/tests/unit/com/android/documentsui/sorting/SortModelTest.java b/tests/unit/com/android/documentsui/sorting/SortModelTest.java
index e418848..aa50fb0 100644
--- a/tests/unit/com/android/documentsui/sorting/SortModelTest.java
+++ b/tests/unit/com/android/documentsui/sorting/SortModelTest.java
@@ -17,9 +17,7 @@
package com.android.documentsui.sorting;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.support.annotation.Nullable;
@@ -82,11 +80,6 @@
}
@Test
- public void testEnabledByDefault() {
- assertTrue(mModel.isSortEnabled());
- }
-
- @Test
public void testSizeEquals() {
assertEquals(DIMENSIONS.length, mModel.getSize());
}
@@ -193,36 +186,6 @@
}
@Test
- public void testSetSortEnabled() {
- mModel.setSortEnabled(false);
-
- assertFalse(mModel.isSortEnabled());
- }
-
- @Test
- public void testSetDefaultDimension_sortDisabled() {
- mModel.setSortEnabled(false);
-
- mModel.setDefaultDimension(DIMENSION_1.getId());
-
- SortDimension sortedDimension = getSortedDimension();
- assertSame(DIMENSION_1, sortedDimension);
- assertEquals(DIMENSION_1.getDefaultSortDirection(), sortedDimension.getSortDirection());
- }
-
- @Test
- public void testSortByUser_sortDisabled() {
- mModel.setSortEnabled(false);
-
- try {
- mModel.sortByUser(DIMENSION_1.getId(), SortDimension.SORT_DIRECTION_ASCENDING);
- fail("Expect exception but not raised.");
- } catch(IllegalStateException expected) {
- // Expected
- }
- }
-
- @Test
public void testSetDefaultDimension_noSortingCapability() {
try {
mModel.setDefaultDimension(DIMENSION_3.getId());