Introducing CellPosMapper which allows mapping between UI position

and model position

Test: atest CellPosMapperTest
Bug: 188081026
Change-Id: If5c6b3df5ad240317bb535c675f6ead94084238e
This commit is contained in:
Sunny Goyal
2023-01-27 14:37:07 -08:00
parent 150b7b0497
commit 669b71f5b3
17 changed files with 385 additions and 88 deletions

View File

@@ -20,6 +20,8 @@ import android.view.View;
import android.view.ViewGroup;
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
import com.android.launcher3.celllayout.CellPosMapper;
import com.android.launcher3.celllayout.CellPosMapper.CellPos;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.model.data.ItemInfo;
@@ -48,15 +50,16 @@ public interface WorkspaceLayoutManager {
* See {@link #addInScreen}.
*/
default void addInScreenFromBind(View child, ItemInfo info) {
int x = info.cellX;
int y = info.cellY;
CellPos presenterPos = getCellPosMapper().mapModelToPresenter(info);
int x = presenterPos.cellX;
int y = presenterPos.cellY;
if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT
|| info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
int screenId = info.screenId;
int screenId = presenterPos.screenId;
x = getHotseat().getCellXFromOrder(screenId);
y = getHotseat().getCellYFromOrder(screenId);
}
addInScreen(child, info.container, info.screenId, x, y, info.spanX, info.spanY);
addInScreen(child, info.container, presenterPos.screenId, x, y, info.spanX, info.spanY);
}
/**
@@ -64,7 +67,9 @@ public interface WorkspaceLayoutManager {
* See {@link #addInScreen(View, int, int, int, int, int, int)}.
*/
default void addInScreen(View child, ItemInfo info) {
addInScreen(child, info.container, info.screenId, info.cellX, info.cellY,
CellPos presenterPos = getCellPosMapper().mapModelToPresenter(info);
addInScreen(child, info.container,
presenterPos.screenId, presenterPos.cellX, presenterPos.cellY,
info.spanX, info.spanY);
}
@@ -114,7 +119,7 @@ public interface WorkspaceLayoutManager {
ViewGroup.LayoutParams genericLp = child.getLayoutParams();
CellLayoutLayoutParams lp;
if (genericLp == null || !(genericLp instanceof CellLayoutLayoutParams)) {
lp = new CellLayoutLayoutParams(x, y, spanX, spanY, screenId);
lp = new CellLayoutLayoutParams(x, y, spanX, spanY);
} else {
lp = (CellLayoutLayoutParams) genericLp;
lp.setCellX(x);
@@ -151,6 +156,11 @@ public interface WorkspaceLayoutManager {
return ItemLongClickListener.INSTANCE_WORKSPACE;
}
/**
* Returns the mapper for converting between model and presenter
*/
CellPosMapper getCellPosMapper();
Hotseat getHotseat();
CellLayout getScreenWithId(int screenId);