Two panel home empty page removing logic change

- Don't remove a single page if it's empty, only if both pages are empty.
- Add back empty pages after they were removed while the phone
  was on single panel home.
- On two panel home don't add new workspace items onto the second screen

Test: manual
Bug: 196376162
Change-Id: I4c54ffa3b359a236deb3ab67adb54111e77ec896
This commit is contained in:
Andras Kloczl
2021-08-17 23:12:17 +02:00
parent 12bfd96432
commit 8c574de97f
7 changed files with 62 additions and 7 deletions

View File

@@ -123,6 +123,7 @@ import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverla
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -797,6 +798,21 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return mScreenOrder;
}
/**
* Returns the page that is shown together with the given page when two panel is enabled.
* @throws IllegalStateException if called while two panel home isn't enabled.
*/
public int getPagePair(int page) {
if (!isTwoPanelEnabled()) {
throw new IllegalStateException("Two panel home isn't enabled.");
}
if (page % 2 == 0) {
return page + 1;
} else {
return page - 1;
}
}
public void stripEmptyScreens() {
if (mLauncher.isWorkspaceLoading()) {
// Don't strip empty screens if the workspace is still loading.
@@ -822,6 +838,22 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
}
// When two panel home is enabled we only remove an empty page if both visible pages are
// empty.
if (isTwoPanelEnabled()) {
// We go through all the pages that were marked as removable and check their page pair
Iterator<Integer> removeScreensIterator = removeScreens.iterator();
while (removeScreensIterator.hasNext()) {
int pageToRemove = removeScreensIterator.next();
int pagePair = getPagePair(pageToRemove);
if (!removeScreens.contains(pagePair)) {
// The page pair isn't empty so we want to remove the current page from the
// removable pages' collection
removeScreensIterator.remove();
}
}
}
// We enforce at least one page to add new items to. In the case that we remove the last
// such screen, we convert the last screen to the empty screen
int minScreens = 1;