Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 613c4237 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Add initial database integration

parent 04ae0817
Loading
Loading
Loading
Loading
+46 −6
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import foundation.e.blisslauncher.BuildConfig;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Utilities;
import foundation.e.blisslauncher.core.customviews.pageindicators.PageIndicatorDots;
import foundation.e.blisslauncher.core.database.DatabaseManager;
import foundation.e.blisslauncher.core.database.model.ApplicationItem;
import foundation.e.blisslauncher.core.database.model.FolderItem;
import foundation.e.blisslauncher.core.database.model.LauncherItem;
@@ -299,8 +300,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
                    || launcherItem.screenId > mScreenOrder.size() - 1) {
                    workspaceScreen = insertNewWorkspaceScreen(mScreenOrder.size());
                }
                launcherItem.screenId = mScreenOrder.size() - 1;
                launcherItem.cell = workspaceScreen.getChildCount();
                GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
                GridLayout.Spec colSpec = GridLayout.spec(GridLayout.UNDEFINED);
                GridLayout.LayoutParams iconLayoutParams =
@@ -310,7 +309,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
                iconLayoutParams.setGravity(Gravity.CENTER);
                appView.setLayoutParams(iconLayoutParams);
                appView.setTextVisibility(true);
                //appView.setWithText(true);
                workspaceScreen.addView(appView);
            } else if (launcherItem.container == Constants.CONTAINER_HOTSEAT) {
                GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
@@ -321,7 +319,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
                iconLayoutParams.height = mLauncher.getDeviceProfile().getHotseatCellHeightPx();
                iconLayoutParams.width = mLauncher.getDeviceProfile().getCellWidthPx();
                appView.setLayoutParams(iconLayoutParams);
                //appView.setWithText(false);
                mLauncher.getHotseat().getLayout().addView(appView);
            }
        }
@@ -1399,6 +1396,9 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
                        mTargetCell, resultSpan, CellLayout.MODE_ON_DROP
                    );
                }*/

                Log.i(TAG, "onDrop: Test here");

                int[] resultSpan = new int[2];
                mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0],
                    (int) mDragViewVisualCenter[1], 1, 1, spanX, spanY, cell,
@@ -1442,7 +1442,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
                    lp.cellVSpan = item.spanY;
                    lp.isLockedToGrid = true;*/

                    //TODO: Update the launcher database here.
                    updateDatabase(getWorkspaceAndHotseatCellLayouts());
                } else {
                    onNoCellFound(dropTargetLayout);

@@ -1456,6 +1456,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
                }
            }

            Log.i(TAG, "onDrop: Test here2");

            final CellLayout parent = (CellLayout) cell.getParent();
            if (d.dragView.hasDrawn()) {
                if (droppedOnOriginalCellDuringTransition) {
@@ -1484,6 +1486,43 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
        }
    }

    private void updateDatabase(ArrayList<CellLayout> layouts) {
        List<LauncherItem> items = new ArrayList<>();
        for (int i = 0; i < layouts.size(); i++) {
            CellLayout cellLayout = layouts.get(i);
            long screenId = getIdForScreen(cellLayout);
            long container;
            if (cellLayout.getContainerType() == CellLayout.WORKSPACE) {
                container = Constants.CONTAINER_DESKTOP;
            } else if (cellLayout.getContainerType() == CellLayout.HOTSEAT) {
                container = Constants.CONTAINER_HOTSEAT;
            } else {
                throw new IllegalArgumentException(
                    "Container type can only be CellLayout.WORKSPACE or CellLayout.HOTSEAT");
            }
            for (int j = 0; j < cellLayout.getChildCount(); j++) {
                LauncherItem launcherItem = (LauncherItem) cellLayout.getChildAt(
                    j).getTag();
                launcherItem.cell = j;
                launcherItem.screenId = screenId;
                launcherItem.container = container;
                if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) {
                    FolderItem folderItem = (FolderItem) launcherItem;
                    items.add(folderItem);
                    for (int k = 0; k < folderItem.items.size(); k++) {
                        LauncherItem item = folderItem.items.get(k);
                        item.container = Long.parseLong(folderItem.id);
                        item.cell = k;
                        items.add(item);
                    }
                } else {
                    items.add(launcherItem);
                }
            }
        }
        DatabaseManager.getManager(getContext()).saveItems(items);
    }

    boolean createUserFolderIfNecessary(
        View newView, long container, CellLayout target,
        int[] targetCell, float distance, boolean external, DragView dragView
@@ -1553,7 +1592,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
            invalidate();
            post(() -> {
                if (fi.cell % 2 == 0) {
                    folderView.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble));
                    folderView
                        .startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble));
                } else {
                    folderView.startAnimation(AnimationUtils
                        .loadAnimation(getContext(), R.anim.wobble_reverse));
+6 −1
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@ import foundation.e.blisslauncher.core.database.model.LauncherItem;
import foundation.e.blisslauncher.core.database.model.WidgetItem;
import foundation.e.blisslauncher.core.executors.AppExecutors;
import foundation.e.blisslauncher.core.utils.Constants;
import foundation.e.blisslauncher.features.test.CellLayout;
import foundation.e.blisslauncher.features.test.IconTextView;
import io.reactivex.Single;
import java.util.ArrayList;
import java.util.List;
@@ -46,7 +48,10 @@ public class DatabaseManager {
    public void saveLayouts(List<GridLayout> pages, GridLayout dock) {
        List<GridLayout> tempPages = pages;
        GridLayout tempDock = dock;
        mAppExecutors.diskIO().execute(() -> saveLauncherItems(tempPages, tempDock));
    }

    public void saveItems(final List<LauncherItem> items) {
        mAppExecutors.diskIO().execute(() -> LauncherDB.getDatabase(mContext).launcherDao().insertAll(items));
    }

    private void saveLauncherItems(final List<GridLayout> pages, final GridLayout dock) {
+10 −3
Original line number Diff line number Diff line
@@ -94,8 +94,6 @@ open class CellLayout @JvmOverloads constructor(
    private val mDragOutlinePaint = Paint()
    private var mEaseOutInterpolator: TimeInterpolator? = null

    open var containerType = Constants.CONTAINER_DESKTOP

    private var cellWidth: Int = 0
    private var cellHeight: Int = 0

@@ -196,6 +194,8 @@ open class CellLayout @JvmOverloads constructor(
        }
    }

    fun getContainerType() = mContainerType

    open fun getCellContentHeight(): Int {
        return Math.min(
            measuredHeight,
@@ -226,7 +226,7 @@ open class CellLayout @JvmOverloads constructor(
        val cHeight: Int = getCellContentHeight()
        val cellPaddingY = 0f.coerceAtLeast((lp.height - cHeight) / 2f).toInt()
        var cellPaddingX: Int
        if (containerType == Constants.CONTAINER_DESKTOP) {
        if (mContainerType == WORKSPACE) {
            cellPaddingX = dp.workspaceCellPaddingXPx
        } else {
            cellPaddingX = (dp.edgeMarginPx / 2f).toInt()
@@ -840,6 +840,13 @@ open class CellLayout @JvmOverloads constructor(
            dragView.layoutParams = iconLayoutParams
            addView(dragView, index)

            // Update item info after reordering so that we always save correct state in database.
            // TODO: May optimize this
            val item: LauncherItem = dragView.tag as LauncherItem
            item.container = if (mContainerType == HOTSEAT) Constants.CONTAINER_HOTSEAT else Constants.CONTAINER_DESKTOP
            item.cell = index
            (dragView as IconTextView).applyFromShortcutItem(item)

            /*copySolutionToTempState(finalSolution, dragView)
            setItemPlacementDirty(true)
            animateItemsToSolution(finalSolution, dragView!!, mode == MODE_ON_DROP)
+1 −1
Original line number Diff line number Diff line
@@ -1092,7 +1092,7 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
    }

    private fun showApps(launcherItems: List<LauncherItem?>) {
        if (hotseat != null) hotseat.resetLayout(false)
        hotseat.resetLayout(false)
        workspace.bindItems(launcherItems)
    }