Search in sources :

Example 1 with ModelWriter

use of com.android.launcher3.model.ModelWriter in project android_packages_apps_Launcher3 by AOSPA.

the class DeleteDropTarget method completeDrop.

@Override
public void completeDrop(DragObject d) {
    ItemInfo item = d.dragInfo;
    if (canRemove(item)) {
        ItemInfo pageItem = item;
        if (item.container <= 0) {
            View v = mLauncher.getWorkspace().getHomescreenIconByItemId(item.container);
            if (v != null) {
                pageItem = (ItemInfo) v.getTag();
            }
        }
        IntSet pageIds = pageItem.container == Favorites.CONTAINER_DESKTOP ? IntSet.wrap(pageItem.screenId) : mLauncher.getWorkspace().getCurrentPageScreenIds();
        onAccessibilityDrop(null, item);
        ModelWriter modelWriter = mLauncher.getModelWriter();
        Runnable onUndoClicked = () -> {
            mLauncher.setPagesToBindSynchronously(pageIds);
            modelWriter.abortDelete();
            mLauncher.getStatsLogManager().logger().log(LAUNCHER_UNDO);
        };
        Snackbar.show(mLauncher, R.string.item_removed, R.string.undo, modelWriter::commitDelete, onUndoClicked);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) IntSet(com.android.launcher3.util.IntSet) View(android.view.View) ModelWriter(com.android.launcher3.model.ModelWriter)

Example 2 with ModelWriter

use of com.android.launcher3.model.ModelWriter in project android_packages_apps_Trebuchet by LineageOS.

the class DeleteDropTarget method completeDrop.

@Override
public void completeDrop(DragObject d) {
    ItemInfo item = d.dragInfo;
    if (canRemove(item)) {
        int itemPage = mLauncher.getWorkspace().getCurrentPage();
        onAccessibilityDrop(null, item);
        ModelWriter modelWriter = mLauncher.getModelWriter();
        Runnable onUndoClicked = () -> {
            mLauncher.setPageToBindSynchronously(itemPage);
            modelWriter.abortDelete();
            mLauncher.getUserEventDispatcher().logActionOnControl(TAP, UNDO);
        };
        Snackbar.show(mLauncher, R.string.item_removed, R.string.undo, modelWriter::commitDelete, onUndoClicked);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ModelWriter(com.android.launcher3.model.ModelWriter)

Example 3 with ModelWriter

use of com.android.launcher3.model.ModelWriter in project android_packages_apps_Trebuchet by LineageOS.

the class FolderInfo method setTitle.

@Override
public void setTitle(@Nullable CharSequence title, ModelWriter modelWriter) {
    // Retaining null title(ie., UNLABELED state) allows auto-labeling when new items added.
    if (isEmpty(title) && this.title == null) {
        return;
    }
    // Updating title to same value does not change any states.
    if (title != null && title.equals(this.title)) {
        return;
    }
    this.title = title;
    LabelState newLabelState = title == null ? LabelState.UNLABELED : title.length() == 0 ? LabelState.EMPTY : getAcceptedSuggestionIndex().isPresent() ? LabelState.SUGGESTED : LabelState.MANUAL;
    if (newLabelState.equals(LabelState.MANUAL)) {
        options |= FLAG_MANUAL_FOLDER_NAME;
    } else {
        options &= ~FLAG_MANUAL_FOLDER_NAME;
    }
    if (modelWriter != null) {
        modelWriter.updateItemInDatabase(this);
    }
}
Also used : FromFolderLabelState(com.android.launcher3.userevent.LauncherLogProto.Target.FromFolderLabelState) ToFolderLabelState(com.android.launcher3.userevent.LauncherLogProto.Target.ToFolderLabelState)

Example 4 with ModelWriter

use of com.android.launcher3.model.ModelWriter in project android_packages_apps_Launcher3 by ProtonAOSP.

the class DeleteDropTarget method completeDrop.

@Override
public void completeDrop(DragObject d) {
    ItemInfo item = d.dragInfo;
    if (canRemove(item)) {
        ItemInfo pageItem = item;
        if (item.container <= 0) {
            View v = mLauncher.getWorkspace().getHomescreenIconByItemId(item.container);
            if (v != null) {
                pageItem = (ItemInfo) v.getTag();
            }
        }
        IntSet pageIds = pageItem.container == Favorites.CONTAINER_DESKTOP ? IntSet.wrap(pageItem.screenId) : mLauncher.getWorkspace().getCurrentPageScreenIds();
        onAccessibilityDrop(null, item);
        ModelWriter modelWriter = mLauncher.getModelWriter();
        Runnable onUndoClicked = () -> {
            mLauncher.setPagesToBindSynchronously(pageIds);
            modelWriter.abortDelete();
            mLauncher.getStatsLogManager().logger().log(LAUNCHER_UNDO);
        };
        Snackbar.show(mLauncher, R.string.item_removed, R.string.undo, modelWriter::commitDelete, onUndoClicked);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) IntSet(com.android.launcher3.util.IntSet) View(android.view.View) ModelWriter(com.android.launcher3.model.ModelWriter)

Example 5 with ModelWriter

use of com.android.launcher3.model.ModelWriter in project android_packages_apps_404Launcher by P-404.

the class DeleteDropTarget method completeDrop.

@Override
public void completeDrop(DragObject d) {
    ItemInfo item = d.dragInfo;
    if (canRemove(item)) {
        ItemInfo pageItem = item;
        if (item.container <= 0) {
            View v = mLauncher.getWorkspace().getHomescreenIconByItemId(item.container);
            if (v != null) {
                pageItem = (ItemInfo) v.getTag();
            }
        }
        IntSet pageIds = pageItem.container == Favorites.CONTAINER_DESKTOP ? IntSet.wrap(pageItem.screenId) : mLauncher.getWorkspace().getCurrentPageScreenIds();
        onAccessibilityDrop(null, item);
        ModelWriter modelWriter = mLauncher.getModelWriter();
        Runnable onUndoClicked = () -> {
            mLauncher.setPagesToBindSynchronously(pageIds);
            modelWriter.abortDelete();
            mLauncher.getStatsLogManager().logger().log(LAUNCHER_UNDO);
        };
        Snackbar.show(mLauncher, R.string.item_removed, R.string.undo, modelWriter::commitDelete, onUndoClicked);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) IntSet(com.android.launcher3.util.IntSet) View(android.view.View) ModelWriter(com.android.launcher3.model.ModelWriter)

Aggregations

ModelWriter (com.android.launcher3.model.ModelWriter)7 ItemInfo (com.android.launcher3.model.data.ItemInfo)6 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)6 View (android.view.View)4 IntSet (com.android.launcher3.util.IntSet)4 AppFilter (com.android.launcher3.AppFilter)1 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)1 LauncherAppState (com.android.launcher3.LauncherAppState)1 LauncherModel (com.android.launcher3.LauncherModel)1 Callbacks (com.android.launcher3.model.BgDataModel.Callbacks)1 FromFolderLabelState (com.android.launcher3.userevent.LauncherLogProto.Target.FromFolderLabelState)1 ToFolderLabelState (com.android.launcher3.userevent.LauncherLogProto.Target.ToFolderLabelState)1 TestLauncherProvider (com.android.launcher3.util.TestLauncherProvider)1 Before (org.junit.Before)1