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

Add initial database integration

parent 04ae0817
...@@ -37,6 +37,7 @@ import foundation.e.blisslauncher.BuildConfig; ...@@ -37,6 +37,7 @@ import foundation.e.blisslauncher.BuildConfig;
import foundation.e.blisslauncher.R; import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Utilities; import foundation.e.blisslauncher.core.Utilities;
import foundation.e.blisslauncher.core.customviews.pageindicators.PageIndicatorDots; 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.ApplicationItem;
import foundation.e.blisslauncher.core.database.model.FolderItem; import foundation.e.blisslauncher.core.database.model.FolderItem;
import foundation.e.blisslauncher.core.database.model.LauncherItem; import foundation.e.blisslauncher.core.database.model.LauncherItem;
...@@ -299,8 +300,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -299,8 +300,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
|| launcherItem.screenId > mScreenOrder.size() - 1) { || launcherItem.screenId > mScreenOrder.size() - 1) {
workspaceScreen = insertNewWorkspaceScreen(mScreenOrder.size()); workspaceScreen = insertNewWorkspaceScreen(mScreenOrder.size());
} }
launcherItem.screenId = mScreenOrder.size() - 1;
launcherItem.cell = workspaceScreen.getChildCount();
GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED); GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.Spec colSpec = GridLayout.spec(GridLayout.UNDEFINED); GridLayout.Spec colSpec = GridLayout.spec(GridLayout.UNDEFINED);
GridLayout.LayoutParams iconLayoutParams = GridLayout.LayoutParams iconLayoutParams =
...@@ -310,7 +309,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -310,7 +309,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
iconLayoutParams.setGravity(Gravity.CENTER); iconLayoutParams.setGravity(Gravity.CENTER);
appView.setLayoutParams(iconLayoutParams); appView.setLayoutParams(iconLayoutParams);
appView.setTextVisibility(true); appView.setTextVisibility(true);
//appView.setWithText(true);
workspaceScreen.addView(appView); workspaceScreen.addView(appView);
} else if (launcherItem.container == Constants.CONTAINER_HOTSEAT) { } else if (launcherItem.container == Constants.CONTAINER_HOTSEAT) {
GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED); GridLayout.Spec rowSpec = GridLayout.spec(GridLayout.UNDEFINED);
...@@ -321,7 +319,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -321,7 +319,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
iconLayoutParams.height = mLauncher.getDeviceProfile().getHotseatCellHeightPx(); iconLayoutParams.height = mLauncher.getDeviceProfile().getHotseatCellHeightPx();
iconLayoutParams.width = mLauncher.getDeviceProfile().getCellWidthPx(); iconLayoutParams.width = mLauncher.getDeviceProfile().getCellWidthPx();
appView.setLayoutParams(iconLayoutParams); appView.setLayoutParams(iconLayoutParams);
//appView.setWithText(false);
mLauncher.getHotseat().getLayout().addView(appView); mLauncher.getHotseat().getLayout().addView(appView);
} }
} }
...@@ -1399,6 +1396,9 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -1399,6 +1396,9 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
mTargetCell, resultSpan, CellLayout.MODE_ON_DROP mTargetCell, resultSpan, CellLayout.MODE_ON_DROP
); );
}*/ }*/
Log.i(TAG, "onDrop: Test here");
int[] resultSpan = new int[2]; int[] resultSpan = new int[2];
mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1], 1, 1, spanX, spanY, cell, (int) mDragViewVisualCenter[1], 1, 1, spanX, spanY, cell,
...@@ -1442,7 +1442,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -1442,7 +1442,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
lp.cellVSpan = item.spanY; lp.cellVSpan = item.spanY;
lp.isLockedToGrid = true;*/ lp.isLockedToGrid = true;*/
//TODO: Update the launcher database here. updateDatabase(getWorkspaceAndHotseatCellLayouts());
} else { } else {
onNoCellFound(dropTargetLayout); onNoCellFound(dropTargetLayout);
...@@ -1456,6 +1456,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -1456,6 +1456,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
} }
} }
Log.i(TAG, "onDrop: Test here2");
final CellLayout parent = (CellLayout) cell.getParent(); final CellLayout parent = (CellLayout) cell.getParent();
if (d.dragView.hasDrawn()) { if (d.dragView.hasDrawn()) {
if (droppedOnOriginalCellDuringTransition) { if (droppedOnOriginalCellDuringTransition) {
...@@ -1484,6 +1486,43 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -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( boolean createUserFolderIfNecessary(
View newView, long container, CellLayout target, View newView, long container, CellLayout target,
int[] targetCell, float distance, boolean external, DragView dragView int[] targetCell, float distance, boolean external, DragView dragView
...@@ -1553,7 +1592,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V ...@@ -1553,7 +1592,8 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
invalidate(); invalidate();
post(() -> { post(() -> {
if (fi.cell % 2 == 0) { if (fi.cell % 2 == 0) {
folderView.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble)); folderView
.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble));
} else { } else {
folderView.startAnimation(AnimationUtils folderView.startAnimation(AnimationUtils
.loadAnimation(getContext(), R.anim.wobble_reverse)); .loadAnimation(getContext(), R.anim.wobble_reverse));
......
...@@ -9,6 +9,8 @@ import foundation.e.blisslauncher.core.database.model.LauncherItem; ...@@ -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.database.model.WidgetItem;
import foundation.e.blisslauncher.core.executors.AppExecutors; import foundation.e.blisslauncher.core.executors.AppExecutors;
import foundation.e.blisslauncher.core.utils.Constants; 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 io.reactivex.Single;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -46,7 +48,10 @@ public class DatabaseManager { ...@@ -46,7 +48,10 @@ public class DatabaseManager {
public void saveLayouts(List<GridLayout> pages, GridLayout dock) { public void saveLayouts(List<GridLayout> pages, GridLayout dock) {
List<GridLayout> tempPages = pages; List<GridLayout> tempPages = pages;
GridLayout tempDock = dock; 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) { private void saveLauncherItems(final List<GridLayout> pages, final GridLayout dock) {
......
...@@ -94,8 +94,6 @@ open class CellLayout @JvmOverloads constructor( ...@@ -94,8 +94,6 @@ open class CellLayout @JvmOverloads constructor(
private val mDragOutlinePaint = Paint() private val mDragOutlinePaint = Paint()
private var mEaseOutInterpolator: TimeInterpolator? = null private var mEaseOutInterpolator: TimeInterpolator? = null
open var containerType = Constants.CONTAINER_DESKTOP
private var cellWidth: Int = 0 private var cellWidth: Int = 0
private var cellHeight: Int = 0 private var cellHeight: Int = 0
...@@ -196,6 +194,8 @@ open class CellLayout @JvmOverloads constructor( ...@@ -196,6 +194,8 @@ open class CellLayout @JvmOverloads constructor(
} }
} }
fun getContainerType() = mContainerType
open fun getCellContentHeight(): Int { open fun getCellContentHeight(): Int {
return Math.min( return Math.min(
measuredHeight, measuredHeight,
...@@ -226,7 +226,7 @@ open class CellLayout @JvmOverloads constructor( ...@@ -226,7 +226,7 @@ open class CellLayout @JvmOverloads constructor(
val cHeight: Int = getCellContentHeight() val cHeight: Int = getCellContentHeight()
val cellPaddingY = 0f.coerceAtLeast((lp.height - cHeight) / 2f).toInt() val cellPaddingY = 0f.coerceAtLeast((lp.height - cHeight) / 2f).toInt()
var cellPaddingX: Int var cellPaddingX: Int
if (containerType == Constants.CONTAINER_DESKTOP) { if (mContainerType == WORKSPACE) {
cellPaddingX = dp.workspaceCellPaddingXPx cellPaddingX = dp.workspaceCellPaddingXPx
} else { } else {
cellPaddingX = (dp.edgeMarginPx / 2f).toInt() cellPaddingX = (dp.edgeMarginPx / 2f).toInt()
...@@ -840,6 +840,13 @@ open class CellLayout @JvmOverloads constructor( ...@@ -840,6 +840,13 @@ open class CellLayout @JvmOverloads constructor(
dragView.layoutParams = iconLayoutParams dragView.layoutParams = iconLayoutParams
addView(dragView, index) 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) /*copySolutionToTempState(finalSolution, dragView)
setItemPlacementDirty(true) setItemPlacementDirty(true)
animateItemsToSolution(finalSolution, dragView!!, mode == MODE_ON_DROP) animateItemsToSolution(finalSolution, dragView!!, mode == MODE_ON_DROP)
......
...@@ -1092,7 +1092,7 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -1092,7 +1092,7 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
} }
private fun showApps(launcherItems: List<LauncherItem?>) { private fun showApps(launcherItems: List<LauncherItem?>) {
if (hotseat != null) hotseat.resetLayout(false) hotseat.resetLayout(false)
workspace.bindItems(launcherItems) workspace.bindItems(launcherItems)
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment