Home | History | Annotate | Download | only in model
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.launcher3.model;
     17 
     18 import android.os.UserHandle;
     19 
     20 import com.android.launcher3.LauncherModel.BaseModelUpdateTask;
     21 import com.android.launcher3.LauncherModel.CallbackTask;
     22 import com.android.launcher3.LauncherModel.Callbacks;
     23 import com.android.launcher3.ShortcutInfo;
     24 import com.android.launcher3.util.ComponentKey;
     25 import com.android.launcher3.util.MultiHashMap;
     26 
     27 import java.util.ArrayList;
     28 
     29 /**
     30  * Extension of {@link BaseModelUpdateTask} with some utility methods
     31  */
     32 public abstract class ExtendedModelTask extends BaseModelUpdateTask {
     33 
     34     public void bindUpdatedShortcuts(
     35             ArrayList<ShortcutInfo> updatedShortcuts, UserHandle user) {
     36         bindUpdatedShortcuts(updatedShortcuts, new ArrayList<ShortcutInfo>(), user);
     37     }
     38 
     39     public void bindUpdatedShortcuts(
     40             final ArrayList<ShortcutInfo> updatedShortcuts,
     41             final ArrayList<ShortcutInfo> removedShortcuts,
     42             final UserHandle user) {
     43         if (!updatedShortcuts.isEmpty() || !removedShortcuts.isEmpty()) {
     44             scheduleCallbackTask(new CallbackTask() {
     45                 @Override
     46                 public void execute(Callbacks callbacks) {
     47                     callbacks.bindShortcutsChanged(updatedShortcuts, removedShortcuts, user);
     48                 }
     49             });
     50         }
     51     }
     52 
     53     public void bindDeepShortcuts(BgDataModel dataModel) {
     54         final MultiHashMap<ComponentKey, String> shortcutMapCopy = dataModel.deepShortcutMap.clone();
     55         scheduleCallbackTask(new CallbackTask() {
     56             @Override
     57             public void execute(Callbacks callbacks) {
     58                 callbacks.bindDeepShortcutMap(shortcutMapCopy);
     59             }
     60         });
     61     }
     62 }
     63