Merge "Use the number of shown hotseat icons instead of database items to store into the DB" into main

This commit is contained in:
Sebastián Franco
2023-11-16 15:33:51 +00:00
committed by Android (Google) Code Review
8 changed files with 83 additions and 51 deletions
+3 -3
View File
@@ -780,10 +780,10 @@ public class Launcher extends StatefulActivity<LauncherState>
if (FOLDABLE_SINGLE_PAGE.get() && mDeviceProfile.isTwoPanels) {
mCellPosMapper = new TwoPanelCellPosMapper(mDeviceProfile.inv.numColumns);
} else {
mCellPosMapper = CellPosMapper.DEFAULT;
mCellPosMapper = new CellPosMapper(mDeviceProfile.isVerticalBarLayout(),
mDeviceProfile.numShownHotseatIcons);
}
mModelWriter = mModel.getWriter(getDeviceProfile().isVerticalBarLayout(), true,
mCellPosMapper, this);
mModelWriter = mModel.getWriter(true, mCellPosMapper, this);
return true;
}
+4 -4
View File
@@ -180,10 +180,10 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
}
@NonNull
public ModelWriter getWriter(final boolean hasVerticalHotseat, final boolean verifyChanges,
CellPosMapper cellPosMapper, @Nullable final Callbacks owner) {
return new ModelWriter(mApp.getContext(), this, mBgDataModel,
hasVerticalHotseat, verifyChanges, cellPosMapper, owner);
public ModelWriter getWriter(final boolean verifyChanges, CellPosMapper cellPosMapper,
@Nullable final Callbacks owner) {
return new ModelWriter(mApp.getContext(), this, mBgDataModel, verifyChanges, cellPosMapper,
owner);
}
@Override
@@ -17,6 +17,7 @@ package com.android.launcher3.celllayout;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.data.ItemInfo;
import java.util.Objects;
@@ -26,9 +27,14 @@ import java.util.Objects;
*/
public class CellPosMapper {
public static final CellPosMapper DEFAULT = new CellPosMapper();
public static final CellPosMapper DEFAULT = new CellPosMapper(false, -1);
private final boolean mHasVerticalHotseat;
private final int mNumOfHotseat;
private CellPosMapper() { }
public CellPosMapper(boolean hasVerticalHotseat, int numOfHotseat) {
mHasVerticalHotseat = hasVerticalHotseat;
mNumOfHotseat = numOfHotseat;
}
/**
* Maps the position in model to the position in view
@@ -42,17 +48,22 @@ public class CellPosMapper {
*/
public CellPos mapPresenterToModel(int presenterX, int presenterY, int presenterScreen,
int container) {
if (container == Favorites.CONTAINER_HOTSEAT) {
presenterScreen = mHasVerticalHotseat
? mNumOfHotseat - presenterY - 1 : presenterX;
}
return new CellPos(presenterX, presenterY, presenterScreen);
}
/**
* Cell mapper which maps two panels into a single layout
*/
public static class TwoPanelCellPosMapper extends CellPosMapper {
public static class TwoPanelCellPosMapper extends CellPosMapper {
private final int mColumnCount;
public TwoPanelCellPosMapper(int columnCount) {
super(false, -1);
mColumnCount = columnCount;
}
@@ -103,5 +114,13 @@ public class CellPosMapper {
public int hashCode() {
return Objects.hash(cellX, cellY, screenId);
}
@Override
public String toString() {
return "CellPos{"
+ "cellX=" + cellX
+ ", cellY=" + cellY
+ ", screenId=" + screenId + '}';
}
}
}
@@ -28,7 +28,6 @@ import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.celllayout.CellPosMapper;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.StatsLogManager.StatsLogger;
@@ -177,8 +176,8 @@ public class LauncherDelegate {
@Override
ModelWriter getModelWriter() {
if (mWriter == null) {
mWriter = LauncherAppState.getInstance((Context) mContext).getModel()
.getWriter(false, false, CellPosMapper.DEFAULT, null);
mWriter = LauncherAppState.getInstance((Context) mContext).getModel().getWriter(
false, mContext.getCellPosMapper(), null);
}
return mWriter;
}
@@ -101,8 +101,7 @@ public abstract class BaseModelUpdateTask implements ModelUpdateTask {
public ModelWriter getModelWriter() {
// Updates from model task, do not deal with icon position in hotseat. Also no need to
// verify changes as the ModelTasks always push the changes to callbacks
return mModel.getWriter(false /* hasVerticalHotseat */, false /* verifyChanges */,
CellPosMapper.DEFAULT, null);
return mModel.getWriter(false /* verifyChanges */, CellPosMapper.DEFAULT, null);
}
public void bindUpdatedWorkspaceItems(@NonNull final List<WorkspaceItemInfo> allUpdates) {
@@ -28,7 +28,6 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.LauncherSettings.Favorites;
@@ -74,7 +73,6 @@ public class ModelWriter {
@Nullable
private final Callbacks mOwner;
private final boolean mHasVerticalHotseat;
private final boolean mVerifyChanges;
// Keep track of delete operations that occur when an Undo option is present; we may not commit.
@@ -83,12 +81,10 @@ public class ModelWriter {
private final CellPosMapper mCellPosMapper;
public ModelWriter(Context context, LauncherModel model, BgDataModel dataModel,
boolean hasVerticalHotseat, boolean verifyChanges, CellPosMapper cellPosMapper,
@Nullable Callbacks owner) {
boolean verifyChanges, CellPosMapper cellPosMapper, @Nullable Callbacks owner) {
mContext = context;
mModel = model;
mBgDataModel = dataModel;
mHasVerticalHotseat = hasVerticalHotseat;
mVerifyChanges = verifyChanges;
mOwner = owner;
mCellPosMapper = cellPosMapper;
@@ -102,14 +98,8 @@ public class ModelWriter {
item.container = container;
item.cellX = modelPos.cellX;
item.cellY = modelPos.cellY;
// We store hotseat items in canonical form which is this orientation invariant position
// in the hotseat
if (container == Favorites.CONTAINER_HOTSEAT) {
item.screenId = mHasVerticalHotseat
? LauncherAppState.getIDP(mContext).numDatabaseHotseatIcons - cellY - 1 : cellX;
} else {
item.screenId = modelPos.screenId;
}
item.screenId = modelPos.screenId;
}
/**
@@ -447,7 +447,8 @@ public interface ActivityContext {
}
default CellPosMapper getCellPosMapper() {
return CellPosMapper.DEFAULT;
DeviceProfile dp = getDeviceProfile();
return new CellPosMapper(dp.isVerticalBarLayout(), dp.numShownHotseatIcons);
}
/** Whether bubbles are enabled. */
@@ -39,44 +39,46 @@ public class CellPosMapperTest {
@Test
public void testMapModelToPresenter_default() {
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
CellPosMapper mapper = CellPosMapper.DEFAULT;
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 0, CONTAINER_DESKTOP))).isEqualTo(new CellPos(0, 0, 0));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 1, CONTAINER_DESKTOP))).isEqualTo(new CellPos(0, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 1, CONTAINER_DESKTOP))).isEqualTo(new CellPos(5, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 0, CONTAINER_DESKTOP))).isEqualTo(new CellPos(5, 0, 0));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 0, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(0, 0, 0));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 1, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(0, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 1, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(5, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapModelToPresenter(
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 0, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(5, 0, 0));
}
@Test
public void testMapPresenterToModel_default() {
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
CellPosMapper mapper = CellPosMapper.DEFAULT;
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 0));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 0));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
5, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 1));
assertThat(CellPosMapper.DEFAULT.mapPresenterToModel(
5, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
}
@Test
@@ -116,11 +118,33 @@ public class CellPosMapperTest {
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 1));
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 1));
5, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 0));
5, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
}
@Test
public void testMapPresenterToModel_VerticalHotseat() {
CellPosMapper mapper = new CellPosMapper(true, 6);
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 5));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 5));
assertThat(mapper.mapPresenterToModel(
0, 5, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 5, 0));
assertThat(mapper.mapPresenterToModel(
0, 5, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 5, 0));
}
private ItemInfo createInfo(int cellX, int cellY, int screen, int container) {