create a new type for shortcuts

This commit is contained in:
tibbi 2022-09-26 23:49:15 +02:00
parent e76b2dcc51
commit 55f243c401
3 changed files with 18 additions and 7 deletions

View File

@ -17,6 +17,7 @@ import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.launcher.activities.MainActivity import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.adapters.WidgetsAdapter import com.simplemobiletools.launcher.adapters.WidgetsAdapter
import com.simplemobiletools.launcher.helpers.COLUMN_COUNT import com.simplemobiletools.launcher.helpers.COLUMN_COUNT
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_SHORTCUT
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_WIDGET import com.simplemobiletools.launcher.helpers.ITEM_TYPE_WIDGET
import com.simplemobiletools.launcher.helpers.ROW_COUNT import com.simplemobiletools.launcher.helpers.ROW_COUNT
import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
@ -221,6 +222,12 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
} }
override fun onWidgetLongPressed(appWidget: AppWidget) { override fun onWidgetLongPressed(appWidget: AppWidget) {
val type = if (appWidget.isShortcut) {
ITEM_TYPE_SHORTCUT
} else {
ITEM_TYPE_WIDGET
}
val gridItem = HomeScreenGridItem( val gridItem = HomeScreenGridItem(
null, null,
-1, -1,
@ -231,7 +238,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
appWidget.heightCells, appWidget.heightCells,
appWidget.appPackageName, appWidget.appPackageName,
"", "",
ITEM_TYPE_WIDGET, type,
appWidget.shortClassName, appWidget.shortClassName,
appWidget.widgetPreviewImage appWidget.widgetPreviewImage
) )

View File

@ -15,4 +15,4 @@ const val REQUEST_CONFIGURE_WIDGET = 51
const val ITEM_TYPE_ICON = 0 const val ITEM_TYPE_ICON = 0
const val ITEM_TYPE_WIDGET = 1 const val ITEM_TYPE_WIDGET = 1
const val ITEM_TYPE_SHORTCUT = 2

View File

@ -114,10 +114,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
return return
} }
if (draggedItem!!.type == ITEM_TYPE_ICON) { when (draggedItem!!.type) {
addAppIcon() ITEM_TYPE_ICON -> addAppIcon()
} else if (draggedItem!!.type == ITEM_TYPE_WIDGET) { ITEM_TYPE_WIDGET -> addWidget()
addWidget() ITEM_TYPE_SHORTCUT -> {
// replace this with real shortcut handling
draggedItem = null
invalidate()
}
} }
} }
@ -327,7 +331,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
} }
if (draggedItem != null && draggedItemCurrentCoords.first != -1 && draggedItemCurrentCoords.second != -1) { if (draggedItem != null && draggedItemCurrentCoords.first != -1 && draggedItemCurrentCoords.second != -1) {
if (draggedItem!!.type == ITEM_TYPE_ICON) { if (draggedItem!!.type == ITEM_TYPE_ICON || draggedItem!!.type == ITEM_TYPE_SHORTCUT) {
// draw a circle under the current cell // draw a circle under the current cell
val center = gridCenters.minBy { val center = gridCenters.minBy {
Math.abs(it.first - draggedItemCurrentCoords.first + sideMargins.left) + Math.abs(it.second - draggedItemCurrentCoords.second + sideMargins.top) Math.abs(it.first - draggedItemCurrentCoords.first + sideMargins.left) + Math.abs(it.second - draggedItemCurrentCoords.second + sideMargins.top)