differentiate between icon and widget grid items
This commit is contained in:
parent
7f777cf557
commit
f93272aa97
|
@ -25,6 +25,8 @@ import com.simplemobiletools.launcher.extensions.*
|
|||
import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
||||
import com.simplemobiletools.launcher.fragments.MyFragment
|
||||
import com.simplemobiletools.launcher.fragments.WidgetsFragment
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_WIDGET
|
||||
import com.simplemobiletools.launcher.helpers.ROW_COUNT
|
||||
import com.simplemobiletools.launcher.helpers.UNINSTALL_APP_REQUEST_CODE
|
||||
import com.simplemobiletools.launcher.interfaces.FlingListener
|
||||
|
@ -276,9 +278,14 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
}
|
||||
|
||||
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
|
||||
if (gridItem.type == ITEM_TYPE_WIDGET) {
|
||||
anchorView.y += resources.getDimension(R.dimen.home_long_press_anchor_offset_y)
|
||||
}
|
||||
|
||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
||||
inflate(R.menu.menu_app_icon)
|
||||
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
|
||||
setOnMenuItemClickListener { item ->
|
||||
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||
|
@ -387,7 +394,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
try {
|
||||
val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage
|
||||
appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply {
|
||||
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, defaultDialerPackage, title, null)
|
||||
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, 1, 1, defaultDialerPackage, title, ITEM_TYPE_ICON, null)
|
||||
homeScreenGridItems.add(dialerIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -397,7 +404,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this)
|
||||
appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply {
|
||||
val SMSMessengerIcon =
|
||||
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, defaultSMSMessengerPackage, title, null)
|
||||
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, 1, 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, null)
|
||||
homeScreenGridItems.add(SMSMessengerIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -408,7 +415,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
|
||||
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
|
||||
val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, defaultBrowserPackage, title, null)
|
||||
val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, 1, 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, null)
|
||||
homeScreenGridItems.add(browserIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -419,7 +426,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) }
|
||||
if (storePackage != null) {
|
||||
appLaunchers.firstOrNull { it.packageName == storePackage }?.apply {
|
||||
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, storePackage, title, null)
|
||||
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, 1, 1, storePackage, title, ITEM_TYPE_ICON, null)
|
||||
homeScreenGridItems.add(storeIcon)
|
||||
}
|
||||
}
|
||||
|
@ -431,7 +438,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val resolveInfo = packageManager.resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
val defaultCameraPackage = resolveInfo!!.activityInfo.packageName
|
||||
appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply {
|
||||
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, defaultCameraPackage, title, null)
|
||||
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, 1, 1, defaultCameraPackage, title, ITEM_TYPE_ICON, null)
|
||||
homeScreenGridItems.add(cameraIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -87,7 +87,7 @@ class WidgetsAdapter(
|
|||
text = if (widget.isShortcut) {
|
||||
activity.getString(R.string.shortcut)
|
||||
} else {
|
||||
"${widget.widthTiles} x ${widget.heightTiles}"
|
||||
"${widget.widthCells} x ${widget.heightCells}"
|
||||
}
|
||||
setTextColor(textColor)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.simplemobiletools.launcher.activities.MainActivity
|
|||
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
||||
import com.simplemobiletools.launcher.extensions.launchApp
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
|
||||
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
||||
import com.simplemobiletools.launcher.models.AppLauncher
|
||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||
|
@ -135,7 +136,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
}
|
||||
|
||||
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, 1, appLauncher.packageName, appLauncher.title, appLauncher.drawable)
|
||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, -1, 1, 1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, appLauncher.drawable)
|
||||
activity?.showHomeIconMenu(x, y, gridItem, true)
|
||||
ignoreTouches = true
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|||
import com.simplemobiletools.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.launcher.activities.MainActivity
|
||||
import com.simplemobiletools.launcher.adapters.WidgetsAdapter
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_WIDGET
|
||||
import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
|
||||
import com.simplemobiletools.launcher.models.*
|
||||
import kotlinx.android.synthetic.main.widgets_fragment.view.*
|
||||
|
@ -204,7 +205,20 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
}
|
||||
|
||||
override fun onWidgetLongPressed(appWidget: AppWidget) {
|
||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, 1, appWidget.appPackageName, "", appWidget.widgetPreviewImage)
|
||||
val gridItem =
|
||||
HomeScreenGridItem(
|
||||
null,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
appWidget.widthCells,
|
||||
appWidget.heightCells,
|
||||
appWidget.appPackageName,
|
||||
"",
|
||||
ITEM_TYPE_WIDGET,
|
||||
appWidget.widgetPreviewImage
|
||||
)
|
||||
activity?.widgetLongPressedOnList(gridItem)
|
||||
ignoreTouches = true
|
||||
}
|
||||
|
|
|
@ -11,3 +11,6 @@ const val ROW_COUNT = 6
|
|||
const val COLUMN_COUNT = 5
|
||||
|
||||
const val UNINSTALL_APP_REQUEST_CODE = 50
|
||||
|
||||
const val ITEM_TYPE_ICON = 0
|
||||
const val ITEM_TYPE_WIDGET = 1
|
||||
|
|
|
@ -8,7 +8,7 @@ data class AppWidget(
|
|||
val appIcon: Drawable,
|
||||
val widgetTitle: String,
|
||||
val widgetPreviewImage: Drawable?,
|
||||
var widthTiles: Int,
|
||||
val heightTiles: Int,
|
||||
var widthCells: Int,
|
||||
val heightCells: Int,
|
||||
val isShortcut: Boolean
|
||||
) : WidgetsListItem()
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.launcher.models
|
|||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.room.*
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
|
||||
|
||||
// grid coords are from 0-5 by default. Icons occupy 1 slot only, widgets can be bigger
|
||||
@Entity(tableName = "home_screen_grid_items", indices = [(Index(value = ["id"], unique = true))])
|
||||
|
@ -11,10 +12,13 @@ data class HomeScreenGridItem(
|
|||
@ColumnInfo(name = "top") var top: Int,
|
||||
@ColumnInfo(name = "right") var right: Int,
|
||||
@ColumnInfo(name = "bottom") var bottom: Int,
|
||||
@ColumnInfo(name = "width_cells") var widthCells: Int,
|
||||
@ColumnInfo(name = "height_cells") var heightCells: Int,
|
||||
@ColumnInfo(name = "package_name") var packageName: String,
|
||||
@ColumnInfo(name = "title") var title: String,
|
||||
@ColumnInfo(name = "type") var type: Int,
|
||||
|
||||
@Ignore var drawable: Drawable?
|
||||
) {
|
||||
constructor() : this(null, -1, -1, -1, -1, "", "", null)
|
||||
constructor() : this(null, -1, -1, -1, -1, 1, 1, "", "", ITEM_TYPE_ICON, null)
|
||||
}
|
||||
|
|
|
@ -139,7 +139,19 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
} else if (draggedItem != null) {
|
||||
// we are dragging a new item at the home screen from the All Apps fragment
|
||||
val newHomeScreenGridItem =
|
||||
HomeScreenGridItem(null, xIndex, yIndex, xIndex + 1, yIndex + 1, draggedItem!!.packageName, draggedItem!!.title, draggedItem!!.drawable)
|
||||
HomeScreenGridItem(
|
||||
null,
|
||||
xIndex,
|
||||
yIndex,
|
||||
xIndex + 1,
|
||||
yIndex + 1,
|
||||
1,
|
||||
1,
|
||||
draggedItem!!.packageName,
|
||||
draggedItem!!.title,
|
||||
draggedItem!!.type,
|
||||
draggedItem!!.drawable
|
||||
)
|
||||
ensureBackgroundThread {
|
||||
val newId = context.homeScreenGridItemsDB.insert(newHomeScreenGridItem)
|
||||
newHomeScreenGridItem.id = newId
|
||||
|
|
Loading…
Reference in New Issue