Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 1 | package com.android.launcher3 |
| 2 | |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 3 | import android.annotation.TargetApi |
| 4 | import android.os.Build |
| 5 | import android.os.Trace |
| 6 | import android.view.ViewTreeObserver.OnDrawListener |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 7 | import androidx.annotation.UiThread |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 8 | import com.android.launcher3.LauncherConstants.TraceEvents |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 9 | import com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 10 | import com.android.launcher3.allapps.AllAppsStore |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 11 | import com.android.launcher3.config.FeatureFlags |
| 12 | import com.android.launcher3.config.FeatureFlags.shouldShowFirstPageWidget |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 13 | import com.android.launcher3.model.BgDataModel |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 14 | import com.android.launcher3.model.StringCache |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 15 | import com.android.launcher3.model.data.AppInfo |
| 16 | import com.android.launcher3.model.data.ItemInfo |
| 17 | import com.android.launcher3.model.data.LauncherAppWidgetInfo |
| 18 | import com.android.launcher3.model.data.WorkspaceItemInfo |
| 19 | import com.android.launcher3.popup.PopupContainerWithArrow |
| 20 | import com.android.launcher3.util.ComponentKey |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 21 | import com.android.launcher3.util.Executors |
Sebastian Franco | 69fd742 | 2023-10-06 16:48:58 -0700 | [diff] [blame] | 22 | import com.android.launcher3.util.IntArray as LIntArray |
| 23 | import com.android.launcher3.util.IntSet as LIntSet |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 24 | import com.android.launcher3.util.PackageUserKey |
| 25 | import com.android.launcher3.util.Preconditions |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 26 | import com.android.launcher3.util.RunnableList |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 27 | import com.android.launcher3.util.TraceHelper |
| 28 | import com.android.launcher3.util.ViewOnDrawExecutor |
Sebastian Franco | 50b74c3 | 2023-11-16 11:36:49 -0600 | [diff] [blame] | 29 | import com.android.launcher3.widget.PendingAddWidgetInfo |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 30 | import com.android.launcher3.widget.model.WidgetsListBaseEntry |
| 31 | import java.util.function.Predicate |
| 32 | |
| 33 | class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { |
Sebastian Franco | 69fd742 | 2023-10-06 16:48:58 -0700 | [diff] [blame] | 34 | |
| 35 | var synchronouslyBoundPages = LIntSet() |
| 36 | var pagesToBindSynchronously = LIntSet() |
| 37 | |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 38 | private var isFirstPagePinnedItemEnabled = |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 39 | (BuildConfig.QSB_ON_FIRST_SCREEN && !FeatureFlags.ENABLE_SMARTSPACE_REMOVAL.get()) |
| 40 | |
| 41 | var stringCache: StringCache? = null |
| 42 | |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 43 | var pendingExecutor: ViewOnDrawExecutor? = null |
| 44 | |
| 45 | var workspaceLoading = true |
| 46 | |
| 47 | /** |
| 48 | * Refreshes the shortcuts shown on the workspace. |
| 49 | * |
| 50 | * Implementation of the method from LauncherModel.Callbacks. |
| 51 | */ |
| 52 | override fun startBinding() { |
| 53 | TraceHelper.INSTANCE.beginSection("startBinding") |
| 54 | // Floating panels (except the full widget sheet) are associated with individual icons. If |
| 55 | // we are starting a fresh bind, close all such panels as all the icons are about |
| 56 | // to go away. |
| 57 | AbstractFloatingView.closeOpenViews( |
| 58 | launcher, |
| 59 | true, |
| 60 | AbstractFloatingView.TYPE_ALL and AbstractFloatingView.TYPE_REBIND_SAFE.inv() |
| 61 | ) |
| 62 | workspaceLoading = true |
| 63 | |
| 64 | // Clear the workspace because it's going to be rebound |
| 65 | launcher.dragController.cancelDrag() |
| 66 | launcher.workspace.clearDropTargets() |
| 67 | launcher.workspace.removeAllWorkspaceScreens() |
| 68 | launcher.appWidgetHolder.clearViews() |
| 69 | launcher.hotseat?.resetLayout(launcher.deviceProfile.isVerticalBarLayout) |
| 70 | TraceHelper.INSTANCE.endSection() |
| 71 | } |
| 72 | |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 73 | @TargetApi(Build.VERSION_CODES.S) |
| 74 | override fun onInitialBindComplete( |
| 75 | boundPages: LIntSet, |
| 76 | pendingTasks: RunnableList, |
| 77 | workspaceItemCount: Int, |
| 78 | isBindSync: Boolean |
| 79 | ) { |
| 80 | synchronouslyBoundPages = boundPages |
| 81 | pagesToBindSynchronously = LIntSet() |
| 82 | clearPendingBinds() |
| 83 | val executor = ViewOnDrawExecutor(pendingTasks) |
| 84 | pendingExecutor = executor |
| 85 | if (!launcher.isInState(LauncherState.ALL_APPS)) { |
| 86 | launcher.appsView.appsStore.enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW) |
| 87 | pendingTasks.add { |
| 88 | launcher.appsView.appsStore.disableDeferUpdates( |
| 89 | AllAppsStore.DEFER_UPDATES_NEXT_DRAW |
| 90 | ) |
| 91 | } |
| 92 | } |
| 93 | executor.onLoadAnimationCompleted() |
| 94 | executor.attachTo(launcher) |
| 95 | if (Utilities.ATLEAST_S) { |
| 96 | Trace.endAsyncSection( |
| 97 | TraceEvents.DISPLAY_WORKSPACE_TRACE_METHOD_NAME, |
| 98 | TraceEvents.DISPLAY_WORKSPACE_TRACE_COOKIE |
| 99 | ) |
| 100 | } |
| 101 | launcher.bindComplete(workspaceItemCount, isBindSync) |
| 102 | launcher.rootView.viewTreeObserver.addOnDrawListener( |
| 103 | object : OnDrawListener { |
| 104 | override fun onDraw() { |
| 105 | Executors.MAIN_EXECUTOR.handler.postAtFrontOfQueue { |
| 106 | launcher.rootView.getViewTreeObserver().removeOnDrawListener(this) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | ) |
| 111 | } |
| 112 | |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 113 | /** |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 114 | * Callback saying that there aren't any more items to bind. |
| 115 | * |
| 116 | * Implementation of the method from LauncherModel.Callbacks. |
| 117 | */ |
| 118 | override fun finishBindingItems(pagesBoundFirst: LIntSet?) { |
| 119 | TraceHelper.INSTANCE.beginSection("finishBindingItems") |
| 120 | val deviceProfile = launcher.deviceProfile |
| 121 | launcher.workspace.restoreInstanceStateForRemainingPages() |
| 122 | workspaceLoading = false |
| 123 | launcher.processActivityResult() |
| 124 | val currentPage = |
| 125 | if (pagesBoundFirst != null && !pagesBoundFirst.isEmpty) |
| 126 | launcher.workspace.getPageIndexForScreenId(pagesBoundFirst.array[0]) |
| 127 | else PagedView.INVALID_PAGE |
| 128 | // When undoing the removal of the last item on a page, return to that page. |
| 129 | // Since we are just resetting the current page without user interaction, |
| 130 | // override the previous page so we don't log the page switch. |
| 131 | launcher.workspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */) |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 132 | pagesToBindSynchronously = LIntSet() |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 133 | |
| 134 | // Cache one page worth of icons |
| 135 | launcher.viewCache.setCacheSize( |
| 136 | R.layout.folder_application, |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 137 | deviceProfile.numFolderColumns * deviceProfile.numFolderRows |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 138 | ) |
| 139 | launcher.viewCache.setCacheSize(R.layout.folder_page, 2) |
| 140 | TraceHelper.INSTANCE.endSection() |
| 141 | launcher.workspace.removeExtraEmptyScreen(/* stripEmptyScreens= */ true) |
| 142 | launcher.workspace.pageIndicator.setAreScreensBinding(false, deviceProfile.isTwoPanels) |
| 143 | } |
| 144 | |
| 145 | /** |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 146 | * Clear any pending bind callbacks. This is called when is loader is planning to perform a full |
| 147 | * rebind from scratch. |
| 148 | */ |
| 149 | override fun clearPendingBinds() { |
| 150 | pendingExecutor?.cancel() ?: return |
| 151 | pendingExecutor = null |
| 152 | |
| 153 | // We might have set this flag previously and forgot to clear it. |
| 154 | launcher.appsView.appsStore.disableDeferUpdatesSilently( |
| 155 | AllAppsStore.DEFER_UPDATES_NEXT_DRAW |
| 156 | ) |
| 157 | } |
| 158 | |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 159 | override fun preAddApps() { |
| 160 | // If there's an undo snackbar, force it to complete to ensure empty screens are removed |
| 161 | // before trying to add new items. |
| 162 | launcher.modelWriter.commitDelete() |
| 163 | val snackbar = |
| 164 | AbstractFloatingView.getOpenView<AbstractFloatingView>( |
| 165 | launcher, |
| 166 | AbstractFloatingView.TYPE_SNACKBAR |
| 167 | ) |
| 168 | snackbar?.post { snackbar.close(true) } |
| 169 | } |
| 170 | |
| 171 | @UiThread |
| 172 | override fun bindAllApplications( |
| 173 | apps: Array<AppInfo?>?, |
| 174 | flags: Int, |
| 175 | packageUserKeytoUidMap: Map<PackageUserKey?, Int?>? |
| 176 | ) { |
| 177 | Preconditions.assertUIThread() |
| 178 | val hadWorkApps = launcher.appsView.shouldShowTabs() |
| 179 | launcher.appsView.appsStore.setApps(apps, flags, packageUserKeytoUidMap) |
| 180 | PopupContainerWithArrow.dismissInvalidPopup(launcher) |
Alex Chau | 61d1938 | 2024-02-12 17:36:57 +0000 | [diff] [blame] | 181 | if ( |
| 182 | hadWorkApps != launcher.appsView.shouldShowTabs() && |
| 183 | launcher.stateManager.state == LauncherState.ALL_APPS |
| 184 | ) { |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 185 | launcher.stateManager.goToState(LauncherState.NORMAL) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary |
| 191 | * because LauncherModel's map is updated in the background, while Launcher runs on the UI. |
| 192 | */ |
| 193 | override fun bindDeepShortcutMap(deepShortcutMapCopy: HashMap<ComponentKey?, Int?>?) { |
| 194 | launcher.popupDataProvider.setDeepShortcutMap(deepShortcutMapCopy) |
| 195 | } |
| 196 | |
| 197 | override fun bindIncrementalDownloadProgressUpdated(app: AppInfo?) { |
| 198 | launcher.appsView.appsStore.updateProgressBar(app) |
| 199 | } |
| 200 | |
| 201 | override fun bindWidgetsRestored(widgets: ArrayList<LauncherAppWidgetInfo?>?) { |
| 202 | launcher.workspace.widgetsRestored(widgets) |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Some shortcuts were updated in the background. Implementation of the method from |
| 207 | * LauncherModel.Callbacks. |
| 208 | * |
| 209 | * @param updated list of shortcuts which have changed. |
| 210 | */ |
| 211 | override fun bindWorkspaceItemsChanged(updated: List<WorkspaceItemInfo?>) { |
| 212 | if (updated.isNotEmpty()) { |
| 213 | launcher.workspace.updateWorkspaceItems(updated, launcher) |
| 214 | PopupContainerWithArrow.dismissInvalidPopup(launcher) |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Update the state of a package, typically related to install state. Implementation of the |
| 220 | * method from LauncherModel.Callbacks. |
| 221 | */ |
| 222 | override fun bindRestoreItemsChange(updates: HashSet<ItemInfo?>?) { |
| 223 | launcher.workspace.updateRestoreItems(updates, launcher) |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * A package was uninstalled/updated. We take both the super set of packageNames in addition to |
| 228 | * specific applications to remove, the reason being that this can be called when a package is |
| 229 | * updated as well. In that scenario, we only remove specific components from the workspace and |
| 230 | * hotseat, where as package-removal should clear all items by package name. |
| 231 | */ |
| 232 | override fun bindWorkspaceComponentsRemoved(matcher: Predicate<ItemInfo?>?) { |
| 233 | launcher.workspace.removeItemsByMatcher(matcher) |
| 234 | launcher.dragController.onAppsRemoved(matcher) |
| 235 | PopupContainerWithArrow.dismissInvalidPopup(launcher) |
| 236 | } |
| 237 | |
| 238 | override fun bindAllWidgets(allWidgets: List<WidgetsListBaseEntry?>?) { |
| 239 | launcher.popupDataProvider.allWidgets = allWidgets |
| 240 | } |
Sebastian Franco | 69fd742 | 2023-10-06 16:48:58 -0700 | [diff] [blame] | 241 | |
| 242 | /** Returns the ids of the workspaces to bind. */ |
| 243 | override fun getPagesToBindSynchronously(orderedScreenIds: LIntArray): LIntSet { |
| 244 | // If workspace binding is still in progress, getCurrentPageScreenIds won't be |
| 245 | // accurate, and we should use mSynchronouslyBoundPages that's set during initial binding. |
| 246 | val visibleIds = |
| 247 | when { |
| 248 | !pagesToBindSynchronously.isEmpty -> pagesToBindSynchronously |
Sebastian Franco | e496512 | 2023-12-01 13:27:42 -0600 | [diff] [blame] | 249 | !workspaceLoading -> launcher.workspace.currentPageScreenIds |
Sebastian Franco | 69fd742 | 2023-10-06 16:48:58 -0700 | [diff] [blame] | 250 | else -> synchronouslyBoundPages |
| 251 | } |
| 252 | // Launcher IntArray has the same name as Kotlin IntArray |
| 253 | val result = LIntSet() |
| 254 | if (visibleIds.isEmpty) { |
| 255 | return result |
| 256 | } |
| 257 | val actualIds = orderedScreenIds.clone() |
| 258 | val firstId = visibleIds.first() |
| 259 | val pairId = launcher.workspace.getScreenPair(firstId) |
| 260 | // Double check that actual screenIds contains the visibleId, as empty screens are hidden |
| 261 | // in single panel. |
| 262 | if (actualIds.contains(firstId)) { |
| 263 | result.add(firstId) |
| 264 | if (launcher.deviceProfile.isTwoPanels && actualIds.contains(pairId)) { |
| 265 | result.add(pairId) |
| 266 | } |
| 267 | } else if ( |
| 268 | LauncherAppState.getIDP(launcher).supportedProfiles.any(DeviceProfile::isTwoPanels) && |
| 269 | actualIds.contains(pairId) |
| 270 | ) { |
| 271 | // Add the right panel if left panel is hidden when switching display, due to empty |
| 272 | // pages being hidden in single panel. |
| 273 | result.add(pairId) |
| 274 | } |
| 275 | return result |
| 276 | } |
Sebastian Franco | 50b74c3 | 2023-11-16 11:36:49 -0600 | [diff] [blame] | 277 | |
| 278 | override fun bindSmartspaceWidget() { |
| 279 | val cl: CellLayout? = |
| 280 | launcher.workspace.getScreenWithId(WorkspaceLayoutManager.FIRST_SCREEN_ID) |
| 281 | val spanX = InvariantDeviceProfile.INSTANCE.get(launcher).numSearchContainerColumns |
| 282 | |
| 283 | if (cl?.isRegionVacant(0, 0, spanX, 1) != true) { |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | val widgetsListBaseEntry: WidgetsListBaseEntry = |
| 288 | launcher.popupDataProvider.allWidgets.firstOrNull { item: WidgetsListBaseEntry -> |
| 289 | item.mPkgItem.packageName == BuildConfig.APPLICATION_ID |
| 290 | } |
| 291 | ?: return |
| 292 | |
| 293 | val info = |
| 294 | PendingAddWidgetInfo( |
| 295 | widgetsListBaseEntry.mWidgets[0].widgetInfo, |
| 296 | LauncherSettings.Favorites.CONTAINER_DESKTOP |
| 297 | ) |
| 298 | launcher.addPendingItem( |
| 299 | info, |
| 300 | info.container, |
| 301 | WorkspaceLayoutManager.FIRST_SCREEN_ID, |
| 302 | intArrayOf(0, 0), |
| 303 | info.spanX, |
| 304 | info.spanY |
| 305 | ) |
| 306 | } |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 307 | |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 308 | override fun bindScreens(orderedScreenIds: LIntArray) { |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 309 | launcher.workspace.pageIndicator.setAreScreensBinding( |
| 310 | true, |
| 311 | launcher.deviceProfile.isTwoPanels |
| 312 | ) |
| 313 | val firstScreenPosition = 0 |
| 314 | if ( |
| 315 | (FeatureFlags.QSB_ON_FIRST_SCREEN && |
| 316 | isFirstPagePinnedItemEnabled && |
| 317 | !shouldShowFirstPageWidget()) && |
| 318 | orderedScreenIds.indexOf(FIRST_SCREEN_ID) != firstScreenPosition |
| 319 | ) { |
| 320 | orderedScreenIds.removeValue(FIRST_SCREEN_ID) |
| 321 | orderedScreenIds.add(firstScreenPosition, FIRST_SCREEN_ID) |
| 322 | } else if ( |
| 323 | (!FeatureFlags.QSB_ON_FIRST_SCREEN && !isFirstPagePinnedItemEnabled || |
| 324 | shouldShowFirstPageWidget()) && orderedScreenIds.isEmpty |
| 325 | ) { |
| 326 | // If there are no screens, we need to have an empty screen |
| 327 | launcher.workspace.addExtraEmptyScreens() |
| 328 | } |
| 329 | bindAddScreens(orderedScreenIds) |
| 330 | |
| 331 | // After we have added all the screens, if the wallpaper was locked to the default state, |
| 332 | // then notify to indicate that it can be released and a proper wallpaper offset can be |
| 333 | // computed before the next layout |
| 334 | launcher.workspace.unlockWallpaperFromDefaultPageOnNextLayout() |
| 335 | } |
| 336 | |
| 337 | override fun bindAppsAdded( |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 338 | newScreens: LIntArray?, |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 339 | addNotAnimated: java.util.ArrayList<ItemInfo?>?, |
| 340 | addAnimated: java.util.ArrayList<ItemInfo?>? |
| 341 | ) { |
| 342 | // Add the new screens |
| 343 | if (newScreens != null) { |
| 344 | // newScreens can contain an empty right panel that is already bound, but not known |
| 345 | // by BgDataModel. |
| 346 | newScreens.removeAllValues(launcher.workspace.mScreenOrder) |
| 347 | bindAddScreens(newScreens) |
| 348 | } |
| 349 | |
| 350 | // We add the items without animation on non-visible pages, and with |
| 351 | // animations on the new page (which we will try and snap to). |
| 352 | if (!addNotAnimated.isNullOrEmpty()) { |
| 353 | launcher.bindItems(addNotAnimated, false) |
| 354 | } |
| 355 | if (!addAnimated.isNullOrEmpty()) { |
| 356 | launcher.bindItems(addAnimated, true) |
| 357 | } |
| 358 | |
| 359 | // Remove the extra empty screen |
| 360 | launcher.workspace.removeExtraEmptyScreen(false) |
| 361 | } |
| 362 | |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 363 | private fun bindAddScreens(orderedScreenIdsArg: LIntArray) { |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 364 | var orderedScreenIds = orderedScreenIdsArg |
| 365 | if (launcher.deviceProfile.isTwoPanels) { |
| 366 | if (FeatureFlags.FOLDABLE_SINGLE_PAGE.get()) { |
| 367 | orderedScreenIds = filterTwoPanelScreenIds(orderedScreenIds) |
| 368 | } else { |
| 369 | // Some empty pages might have been removed while the phone was in a single panel |
| 370 | // mode, so we want to add those empty pages back. |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 371 | val screenIds = LIntSet.wrap(orderedScreenIds) |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 372 | orderedScreenIds.forEach { screenId: Int -> |
| 373 | screenIds.add(launcher.workspace.getScreenPair(screenId)) |
| 374 | } |
| 375 | orderedScreenIds = screenIds.array |
| 376 | } |
| 377 | } |
| 378 | orderedScreenIds |
| 379 | .filterNot { screenId -> |
| 380 | FeatureFlags.QSB_ON_FIRST_SCREEN && |
| 381 | isFirstPagePinnedItemEnabled && |
| 382 | !FeatureFlags.shouldShowFirstPageWidget() && |
| 383 | screenId == WorkspaceLayoutManager.FIRST_SCREEN_ID |
| 384 | } |
| 385 | .forEach { screenId -> |
| 386 | launcher.workspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId) |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Remove odd number because they are already included when isTwoPanels and add the pair screen |
| 392 | * if not present. |
| 393 | */ |
Sebastian Franco | 6196b90 | 2023-12-06 11:39:52 -0600 | [diff] [blame] | 394 | private fun filterTwoPanelScreenIds(orderedScreenIds: LIntArray): LIntArray { |
Sebastian Franco | 0b461ef | 2023-12-08 12:20:07 -0600 | [diff] [blame] | 395 | val screenIds = LIntSet.wrap(orderedScreenIds) |
Sebastian Franco | 6dda7c7 | 2023-11-17 18:03:00 -0600 | [diff] [blame] | 396 | orderedScreenIds |
| 397 | .filter { screenId -> screenId % 2 == 1 } |
| 398 | .forEach { screenId -> |
| 399 | screenIds.remove(screenId) |
| 400 | // In case the pair is not added, add it |
| 401 | if (!launcher.workspace.containsScreenId(screenId - 1)) { |
| 402 | screenIds.add(screenId - 1) |
| 403 | } |
| 404 | } |
| 405 | return screenIds.array |
| 406 | } |
| 407 | |
| 408 | override fun setIsFirstPagePinnedItemEnabled(isFirstPagePinnedItemEnabled: Boolean) { |
| 409 | this.isFirstPagePinnedItemEnabled = isFirstPagePinnedItemEnabled |
| 410 | launcher.workspace.bindAndInitFirstWorkspaceScreen() |
| 411 | } |
| 412 | |
| 413 | override fun bindStringCache(cache: StringCache) { |
| 414 | stringCache = cache |
| 415 | launcher.appsView.updateWorkUI() |
| 416 | } |
| 417 | |
| 418 | fun getIsFirstPagePinnedItemEnabled(): Boolean = isFirstPagePinnedItemEnabled |
Sebastian Franco | bd7919c | 2023-09-19 10:55:37 -0700 | [diff] [blame] | 419 | } |