Migrate to viewbinding and kotlin gradle scripts

This commit is contained in:
Ensar Sarajčić 2023-08-03 13:23:31 +02:00
parent b2a2ee653c
commit c15b3e4c6f
21 changed files with 475 additions and 398 deletions

View File

@ -1,71 +0,0 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 34
defaultConfig {
applicationId "com.simplemobiletools.launcher"
minSdkVersion 26
targetSdkVersion 34
versionCode 8
versionName "5.0.6"
setProperty("archivesBaseName", "launcher")
}
signingConfigs {
if (keystorePropertiesFile.exists()) {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (keystorePropertiesFile.exists()) {
signingConfig signingConfigs.release
}
}
}
flavorDimensions "variants"
productFlavors {
core {}
fdroid {}
prepaid {}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:fad9b2cdb0'
kapt "androidx.room:room-compiler:2.5.2"
implementation "androidx.room:room-runtime:2.5.2"
annotationProcessor "androidx.room:room-compiler:2.5.2"
}

96
app/build.gradle.kts Normal file
View File

@ -0,0 +1,96 @@
import java.io.FileInputStream
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.konan.properties.Properties
plugins {
alias(libs.plugins.android)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.ksp)
}
val keystorePropertiesFile: File = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android {
compileSdk = project.libs.versions.app.build.compileSDKVersion.get().toInt()
defaultConfig {
applicationId = libs.versions.app.version.appId.get()
minSdk = project.libs.versions.app.build.minimumSDK.get().toInt()
targetSdk = project.libs.versions.app.build.targetSDK.get().toInt()
versionName = project.libs.versions.app.version.versionName.get()
versionCode = project.libs.versions.app.version.versionCode.get().toInt()
setProperty("archivesBaseName", "launcher")
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
if (keystorePropertiesFile.exists()) {
register("release") {
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
storeFile = file(keystoreProperties.getProperty("storeFile"))
storePassword = keystoreProperties.getProperty("storePassword")
}
}
}
buildFeatures {
viewBinding = true
buildConfig = true
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
}
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
if (keystorePropertiesFile.exists()) {
signingConfig = signingConfigs.getByName("release")
}
}
}
flavorDimensions.add("variants")
productFlavors {
register("core")
register("fdroid")
register("prepaid")
}
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
}
compileOptions {
val currentJavaVersionFromLibs = JavaVersion.valueOf(libs.versions.app.build.javaVersion.get().toString())
sourceCompatibility = currentJavaVersionFromLibs
targetCompatibility = currentJavaVersionFromLibs
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get()
}
namespace = libs.versions.app.version.appId.get()
lint {
checkReleaseBuilds = false
abortOnError = false
}
}
dependencies {
implementation(libs.simple.tools.commons)
implementation(libs.bundles.room)
ksp(libs.androidx.room.compiler)
}

View File

@ -9,31 +9,33 @@ import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.adapters.HiddenIconsAdapter
import com.simplemobiletools.launcher.databinding.ActivityHiddenIconsBinding
import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
import com.simplemobiletools.launcher.extensions.hiddenIconsDB
import com.simplemobiletools.launcher.models.HiddenIcon
import kotlinx.android.synthetic.main.activity_hidden_icons.*
class HiddenIconsActivity : SimpleActivity(), RefreshRecyclerViewListener {
private lateinit var binding: ActivityHiddenIconsBinding
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_hidden_icons)
binding = ActivityHiddenIconsBinding.inflate(layoutInflater)
setContentView(binding.root)
updateIcons()
updateMaterialActivityViews(manage_hidden_icons_coordinator, manage_hidden_icons_list, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(manage_hidden_icons_list, manage_hidden_icons_toolbar)
updateMaterialActivityViews(binding.manageHiddenIconsCoordinator, binding.manageHiddenIconsList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.manageHiddenIconsList, binding.manageHiddenIconsToolbar)
val layoutManager = manage_hidden_icons_list.layoutManager as MyGridLayoutManager
val layoutManager = binding.manageHiddenIconsList.layoutManager as MyGridLayoutManager
layoutManager.spanCount = config.drawerColumnCount
}
override fun onResume() {
super.onResume()
setupToolbar(manage_hidden_icons_toolbar, NavigationIcon.Arrow)
setupToolbar(binding.manageHiddenIconsToolbar, NavigationIcon.Arrow)
}
private fun updateIcons() {
@ -48,7 +50,7 @@ class HiddenIconsActivity : SimpleActivity(), RefreshRecyclerViewListener {
val hiddenIconsEmpty = hiddenIcons.isEmpty()
runOnUiThread {
manage_hidden_icons_placeholder.beVisibleIf(hiddenIconsEmpty)
binding.manageHiddenIconsPlaceholder.beVisibleIf(hiddenIconsEmpty)
}
if (hiddenIcons.isNotEmpty()) {
@ -77,9 +79,9 @@ class HiddenIconsActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
runOnUiThread {
HiddenIconsAdapter(this, hiddenIcons, this, manage_hidden_icons_list) {
HiddenIconsAdapter(this, hiddenIcons, this, binding.manageHiddenIconsList) {
}.apply {
manage_hidden_icons_list.adapter = this
binding.manageHiddenIconsList.adapter = this
}
}
}

View File

@ -33,25 +33,24 @@ import androidx.core.view.GestureDetectorCompat
import androidx.core.view.WindowCompat
import androidx.core.view.isVisible
import androidx.core.view.iterator
import androidx.viewbinding.ViewBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.launcher.BuildConfig
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.databinding.ActivityMainBinding
import com.simplemobiletools.launcher.databinding.AllAppsFragmentBinding
import com.simplemobiletools.launcher.databinding.WidgetsFragmentBinding
import com.simplemobiletools.launcher.dialogs.RenameItemDialog
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.*
import com.simplemobiletools.launcher.interfaces.FlingListener
import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HiddenIcon
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main.view.*
import kotlinx.android.synthetic.main.all_apps_fragment.view.*
import kotlinx.android.synthetic.main.widgets_fragment.view.*
import kotlin.math.abs
import com.simplemobiletools.commons.R as CommonsR
class MainActivity : SimpleActivity(), FlingListener {
private var mTouchDownX = -1
@ -72,6 +71,7 @@ class MainActivity : SimpleActivity(), FlingListener {
private var wasJustPaused: Boolean = false
private lateinit var mDetector: GestureDetectorCompat
private lateinit var binding: ActivityMainBinding
companion object {
private var mLastUpEvent = 0L
@ -83,7 +83,8 @@ class MainActivity : SimpleActivity(), FlingListener {
useDynamicTheme = false
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID)
mDetector = GestureDetectorCompat(this, MyGestureListener(this))
@ -95,7 +96,7 @@ class MainActivity : SimpleActivity(), FlingListener {
mWidgetsFragmentY = mScreenHeight
mMoveGestureThreshold = resources.getDimensionPixelSize(R.dimen.move_gesture_threshold)
arrayOf(all_apps_fragment as MyFragment, widgets_fragment as MyFragment).forEach { fragment ->
arrayOf(binding.allAppsFragment.root as MyFragment<*>, binding.widgetsFragment.root as MyFragment<*>).forEach { fragment ->
fragment.setupFragment(this)
fragment.y = mScreenHeight.toFloat()
fragment.beVisible()
@ -103,12 +104,12 @@ class MainActivity : SimpleActivity(), FlingListener {
handleIntentAction(intent)
home_screen_grid.itemClickListener = {
binding.homeScreenGrid.root.itemClickListener = {
performItemClick(it)
}
home_screen_grid.itemLongClickListener = {
performItemLongClick(home_screen_grid.getClickableRect(it).left.toFloat(), it)
binding.homeScreenGrid.root.itemLongClickListener = {
performItemLongClick(binding.homeScreenGrid.root.getClickableRect(it).left.toFloat(), it)
}
}
@ -116,10 +117,10 @@ class MainActivity : SimpleActivity(), FlingListener {
super.onNewIntent(intent)
if (wasJustPaused) {
if (isAllAppsFragmentExpanded()) {
hideFragment(all_apps_fragment)
hideFragment(binding.allAppsFragment)
}
if (isWidgetsFragmentExpanded()) {
hideFragment(widgets_fragment)
hideFragment(binding.widgetsFragment)
}
} else {
closeAppDrawer()
@ -163,14 +164,14 @@ class MainActivity : SimpleActivity(), FlingListener {
)
runOnUiThread {
home_screen_grid.skipToPage(page)
binding.homeScreenGrid.root.skipToPage(page)
}
// delay showing the shortcut both to let the user see adding it in realtime and hackily avoid concurrent modification exception at HomeScreenGrid
Thread.sleep(2000)
try {
item.accept()
home_screen_grid.storeAndShowGridItem(gridItem)
binding.homeScreenGrid.root.storeAndShowGridItem(gridItem)
} catch (ignored: IllegalStateException) {
}
}
@ -205,7 +206,7 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onStart() {
super.onStart()
home_screen_grid.appWidgetHost.startListening()
binding.homeScreenGrid.root.appWidgetHost.startListening()
}
override fun onResume() {
@ -213,11 +214,11 @@ class MainActivity : SimpleActivity(), FlingListener {
wasJustPaused = false
updateStatusbarColor(Color.TRANSPARENT)
main_holder.onGlobalLayout {
binding.mainHolder.onGlobalLayout {
if (isPiePlus()) {
val addTopPadding = main_holder.rootWindowInsets?.displayCutout != null
(all_apps_fragment as AllAppsFragment).setupViews(addTopPadding)
(widgets_fragment as WidgetsFragment).setupViews(addTopPadding)
val addTopPadding = binding.mainHolder.rootWindowInsets?.displayCutout != null
binding.allAppsFragment.root.setupViews(addTopPadding)
binding.widgetsFragment.root.setupViews(addTopPadding)
updateStatusbarColor(Color.TRANSPARENT)
}
}
@ -239,7 +240,7 @@ class MainActivity : SimpleActivity(), FlingListener {
showIcon
}.toMutableList() as ArrayList<AppLauncher>
(all_apps_fragment as AllAppsFragment).gotLaunchers(mCachedLaunchers)
binding.allAppsFragment.root.gotLaunchers(mCachedLaunchers)
}
refetchLaunchers()
@ -250,16 +251,16 @@ class MainActivity : SimpleActivity(), FlingListener {
window.navigationBarColor = Color.TRANSPARENT
}
home_screen_grid?.resizeGrid(
binding.homeScreenGrid.root.resizeGrid(
newRowCount = config.homeRowCount,
newColumnCount = config.homeColumnCount
)
(all_apps_fragment as? AllAppsFragment)?.onResume()
binding.allAppsFragment.root.onResume()
}
override fun onStop() {
super.onStop()
home_screen_grid?.appWidgetHost?.stopListening()
binding.homeScreenGrid.root.appWidgetHost?.stopListening()
wasJustPaused = false
}
@ -268,15 +269,16 @@ class MainActivity : SimpleActivity(), FlingListener {
wasJustPaused = true
}
@SuppressLint("MissingSuperCall")
override fun onBackPressed() {
if (isAllAppsFragmentExpanded()) {
if ((all_apps_fragment as? AllAppsFragment)?.onBackPressed() == false) {
hideFragment(all_apps_fragment)
if (!binding.allAppsFragment.root.onBackPressed()) {
hideFragment(binding.allAppsFragment)
}
} else if (isWidgetsFragmentExpanded()) {
hideFragment(widgets_fragment)
} else if (home_screen_grid.resize_frame.isVisible) {
home_screen_grid.hideResizeLines()
hideFragment(binding.widgetsFragment)
} else if (binding.homeScreenGrid.resizeFrame.isVisible) {
binding.homeScreenGrid.root.hideResizeLines()
} else {
// this is a home launcher app, avoid glitching by pressing Back
//super.onBackPressed()
@ -311,8 +313,8 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
(all_apps_fragment as? AllAppsFragment)?.onConfigurationChanged()
(widgets_fragment as? WidgetsFragment)?.onConfigurationChanged()
binding.allAppsFragment.root.onConfigurationChanged()
binding.widgetsFragment.root.onConfigurationChanged()
}
override fun onTouchEvent(event: MotionEvent?): Boolean {
@ -333,8 +335,8 @@ class MainActivity : SimpleActivity(), FlingListener {
MotionEvent.ACTION_DOWN -> {
mTouchDownX = event.x.toInt()
mTouchDownY = event.y.toInt()
mAllAppsFragmentY = all_apps_fragment.y.toInt()
mWidgetsFragmentY = widgets_fragment.y.toInt()
mAllAppsFragmentY = binding.allAppsFragment.root.y.toInt()
mWidgetsFragmentY = binding.widgetsFragment.root.y.toInt()
mIgnoreUpEvent = false
}
@ -351,12 +353,12 @@ class MainActivity : SimpleActivity(), FlingListener {
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved) {
mOpenPopupMenu?.dismiss()
mOpenPopupMenu = null
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
hideFragment(all_apps_fragment)
binding.homeScreenGrid.root.itemDraggingStarted(mLongPressedIcon!!)
hideFragment(binding.allAppsFragment)
}
if (mLongPressedIcon != null && hasFingerMoved) {
home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt())
binding.homeScreenGrid.root.draggedItemMoved(event.x.toInt(), event.y.toInt())
}
if (hasFingerMoved && !mIgnoreMoveEvents) {
@ -364,10 +366,10 @@ class MainActivity : SimpleActivity(), FlingListener {
if (isWidgetsFragmentExpanded()) {
val newY = mWidgetsFragmentY - diffY
widgets_fragment.y = Math.min(Math.max(0f, newY), mScreenHeight.toFloat())
binding.widgetsFragment.root.y = Math.min(Math.max(0f, newY), mScreenHeight.toFloat())
} else if (mLongPressedIcon == null) {
val newY = mAllAppsFragmentY - diffY
all_apps_fragment.y = Math.min(Math.max(0f, newY), mScreenHeight.toFloat())
binding.allAppsFragment.root.y = Math.min(Math.max(0f, newY), mScreenHeight.toFloat())
}
}
@ -382,19 +384,19 @@ class MainActivity : SimpleActivity(), FlingListener {
mLongPressedIcon = null
mLastTouchCoords = Pair(-1f, -1f)
resetFragmentTouches()
home_screen_grid.itemDraggingStopped()
binding.homeScreenGrid.root.itemDraggingStopped()
if (!mIgnoreUpEvent) {
if (all_apps_fragment.y < mScreenHeight * 0.5) {
showFragment(all_apps_fragment)
if (binding.allAppsFragment.root.y < mScreenHeight * 0.5) {
showFragment(binding.allAppsFragment)
} else if (isAllAppsFragmentExpanded()) {
hideFragment(all_apps_fragment)
hideFragment(binding.allAppsFragment)
}
if (widgets_fragment.y < mScreenHeight * 0.5) {
showFragment(widgets_fragment)
if (binding.widgetsFragment.root.y < mScreenHeight * 0.5) {
showFragment(binding.widgetsFragment)
} else if (isWidgetsFragmentExpanded()) {
hideFragment(widgets_fragment)
hideFragment(binding.widgetsFragment)
}
}
}
@ -409,8 +411,8 @@ class MainActivity : SimpleActivity(), FlingListener {
private fun refetchLaunchers() {
val launchers = getAllAppLaunchers()
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)
(widgets_fragment as WidgetsFragment).getAppWidgets()
binding.allAppsFragment.root.gotLaunchers(launchers)
binding.widgetsFragment.root.getAppWidgets()
var hasDeletedAnything = false
mCachedLaunchers.map { it.packageName }.forEach { packageName ->
@ -422,7 +424,7 @@ class MainActivity : SimpleActivity(), FlingListener {
}
if (hasDeletedAnything) {
home_screen_grid.fetchGridItems()
binding.homeScreenGrid.root.fetchGridItems()
}
mCachedLaunchers = launchers
@ -431,52 +433,52 @@ class MainActivity : SimpleActivity(), FlingListener {
ensureBackgroundThread {
getDefaultAppPackages(launchers)
config.wasHomeScreenInit = true
home_screen_grid.fetchGridItems()
binding.homeScreenGrid.root.fetchGridItems()
}
}
}
fun isAllAppsFragmentExpanded() = all_apps_fragment.y != mScreenHeight.toFloat()
fun isAllAppsFragmentExpanded() = binding.allAppsFragment.root.y != mScreenHeight.toFloat()
private fun isWidgetsFragmentExpanded() = widgets_fragment.y != mScreenHeight.toFloat()
private fun isWidgetsFragmentExpanded() = binding.widgetsFragment.root.y != mScreenHeight.toFloat()
fun startHandlingTouches(touchDownY: Int) {
mLongPressedIcon = null
mTouchDownY = touchDownY
mAllAppsFragmentY = all_apps_fragment.y.toInt()
mWidgetsFragmentY = widgets_fragment.y.toInt()
mAllAppsFragmentY = binding.allAppsFragment.root.y.toInt()
mWidgetsFragmentY = binding.widgetsFragment.root.y.toInt()
mIgnoreUpEvent = false
}
private fun showFragment(fragment: View) {
ObjectAnimator.ofFloat(fragment, "y", 0f).apply {
private fun showFragment(fragment: ViewBinding) {
ObjectAnimator.ofFloat(fragment.root, "y", 0f).apply {
duration = ANIMATION_DURATION
interpolator = DecelerateInterpolator()
start()
}
window.navigationBarColor = resources.getColor(R.color.semitransparent_navigation)
home_screen_grid.fragmentExpanded()
home_screen_grid.hideResizeLines()
fragment.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null)
binding.homeScreenGrid.root.fragmentExpanded()
binding.homeScreenGrid.root.hideResizeLines()
fragment.root.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null)
}
private fun hideFragment(fragment: View) {
ObjectAnimator.ofFloat(fragment, "y", mScreenHeight.toFloat()).apply {
private fun hideFragment(fragment: ViewBinding) {
ObjectAnimator.ofFloat(fragment.root, "y", mScreenHeight.toFloat()).apply {
duration = ANIMATION_DURATION
interpolator = DecelerateInterpolator()
start()
}
window.navigationBarColor = Color.TRANSPARENT
home_screen_grid.fragmentCollapsed()
Handler().postDelayed({
if (fragment is AllAppsFragment) {
fragment.all_apps_grid.scrollToPosition(0)
fragment.touchDownY = -1
} else if (fragment is WidgetsFragment) {
fragment.widgets_list.scrollToPosition(0)
fragment.touchDownY = -1
binding.homeScreenGrid.root.fragmentCollapsed()
Handler(Looper.getMainLooper()).postDelayed({
if (fragment is AllAppsFragmentBinding) {
fragment.allAppsGrid.scrollToPosition(0)
fragment.root.touchDownY = -1
} else if (fragment is WidgetsFragmentBinding) {
fragment.widgetsList.scrollToPosition(0)
fragment.root.touchDownY = -1
}
}, ANIMATION_DURATION)
}
@ -486,22 +488,22 @@ class MainActivity : SimpleActivity(), FlingListener {
return
}
val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY)
val (x, y) = binding.homeScreenGrid.root.intoViewSpaceCoords(eventX, eventY)
mIgnoreMoveEvents = true
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
val clickedGridItem = binding.homeScreenGrid.root.isClickingGridItem(x.toInt(), y.toInt())
if (clickedGridItem != null) {
performItemLongClick(x, clickedGridItem)
return
}
main_holder.performHapticFeedback()
binding.mainHolder.performHapticFeedback()
showMainLongPressMenu(x, y)
}
fun homeScreenClicked(eventX: Float, eventY: Float) {
home_screen_grid.hideResizeLines()
val (x, y) = home_screen_grid.intoViewSpaceCoords(eventX, eventY)
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
binding.homeScreenGrid.root.hideResizeLines()
val (x, y) = binding.homeScreenGrid.root.intoViewSpaceCoords(eventX, eventY)
val clickedGridItem = binding.homeScreenGrid.root.isClickingGridItem(x.toInt(), y.toInt())
if (clickedGridItem != null) {
performItemClick(clickedGridItem)
}
@ -510,10 +512,10 @@ class MainActivity : SimpleActivity(), FlingListener {
fun closeAppDrawer(delayed: Boolean = false) {
if (isAllAppsFragmentExpanded()) {
val close = {
all_apps_fragment.y = mScreenHeight.toFloat()
all_apps_fragment.all_apps_grid.scrollToPosition(0)
(all_apps_fragment as AllAppsFragment).touchDownY = -1
home_screen_grid.fragmentCollapsed()
binding.allAppsFragment.root.y = mScreenHeight.toFloat()
binding.allAppsFragment.allAppsGrid.scrollToPosition(0)
binding.allAppsFragment.root.touchDownY = -1
binding.homeScreenGrid.root.fragmentCollapsed()
}
if (delayed) {
Handler(Looper.getMainLooper()).postDelayed(close, APP_DRAWER_CLOSE_DELAY)
@ -526,10 +528,10 @@ class MainActivity : SimpleActivity(), FlingListener {
fun closeWidgetsFragment(delayed: Boolean = false) {
if (isWidgetsFragmentExpanded()) {
val close = {
widgets_fragment.y = mScreenHeight.toFloat()
widgets_fragment.widgets_list.scrollToPosition(0)
(widgets_fragment as WidgetsFragment).touchDownY = -1
home_screen_grid.fragmentCollapsed()
binding.widgetsFragment.root.y = mScreenHeight.toFloat()
binding.widgetsFragment.widgetsList.scrollToPosition(0)
binding.widgetsFragment.root.touchDownY = -1
binding.homeScreenGrid.root.fragmentCollapsed()
}
if (delayed) {
Handler(Looper.getMainLooper()).postDelayed(close, APP_DRAWER_CLOSE_DELAY)
@ -546,7 +548,7 @@ class MainActivity : SimpleActivity(), FlingListener {
val id = clickedGridItem.shortcutId
val packageName = clickedGridItem.packageName
val userHandle = android.os.Process.myUserHandle()
val shortcutBounds = home_screen_grid.getClickableRect(clickedGridItem)
val shortcutBounds = binding.homeScreenGrid.root.getClickableRect(clickedGridItem)
val launcherApps = applicationContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
launcherApps.startShortcut(packageName, id, shortcutBounds, null, userHandle)
}
@ -554,44 +556,44 @@ class MainActivity : SimpleActivity(), FlingListener {
private fun performItemLongClick(x: Float, clickedGridItem: HomeScreenGridItem) {
if (clickedGridItem.type == ITEM_TYPE_ICON || clickedGridItem.type == ITEM_TYPE_SHORTCUT) {
main_holder.performHapticFeedback()
binding.mainHolder.performHapticFeedback()
}
val anchorY = home_screen_grid.sideMargins.top + (clickedGridItem.top * home_screen_grid.cellHeight.toFloat())
val anchorY = binding.homeScreenGrid.root.sideMargins.top + (clickedGridItem.top * binding.homeScreenGrid.root.cellHeight.toFloat())
showHomeIconMenu(x, anchorY, clickedGridItem, false)
}
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean) {
home_screen_grid.hideResizeLines()
binding.homeScreenGrid.root.hideResizeLines()
mLongPressedIcon = gridItem
val anchorY = if (isOnAllAppsFragment || gridItem.type == ITEM_TYPE_WIDGET) {
val iconSize = realScreenSize.x / config.drawerColumnCount
y - iconSize / 2f
} else {
val clickableRect = home_screen_grid.getClickableRect(gridItem)
clickableRect.top.toFloat() - home_screen_grid.getCurrentIconSize() / 2f
val clickableRect = binding.homeScreenGrid.root.getClickableRect(gridItem)
clickableRect.top.toFloat() - binding.homeScreenGrid.root.getCurrentIconSize() / 2f
}
home_screen_popup_menu_anchor.x = x
home_screen_popup_menu_anchor.y = anchorY
binding.homeScreenPopupMenuAnchor.x = x
binding.homeScreenPopupMenuAnchor.y = anchorY
if (mOpenPopupMenu == null) {
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, gridItem, isOnAllAppsFragment)
mOpenPopupMenu = handleGridItemPopupMenu(binding.homeScreenPopupMenuAnchor, gridItem, isOnAllAppsFragment)
}
}
fun widgetLongPressedOnList(gridItem: HomeScreenGridItem) {
mLongPressedIcon = gridItem
hideFragment(widgets_fragment)
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
hideFragment(binding.widgetsFragment)
binding.homeScreenGrid.root.itemDraggingStarted(mLongPressedIcon!!)
}
private fun showMainLongPressMenu(x: Float, y: Float) {
home_screen_grid.hideResizeLines()
home_screen_popup_menu_anchor.x = x
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * 2
binding.homeScreenGrid.root.hideResizeLines()
binding.homeScreenPopupMenuAnchor.x = x
binding.homeScreenPopupMenuAnchor.y = y - resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * 2
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
PopupMenu(contextTheme, home_screen_popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
PopupMenu(contextTheme, binding.homeScreenPopupMenuAnchor, Gravity.TOP or Gravity.END).apply {
inflate(R.menu.menu_home_screen)
setOnMenuItemClickListener { item ->
when (item.itemId) {
@ -624,9 +626,9 @@ class MainActivity : SimpleActivity(), FlingListener {
when (item.itemId) {
R.id.hide_icon -> hideIcon(gridItem)
R.id.rename -> renameItem(gridItem)
R.id.resize -> home_screen_grid.widgetLongPressed(gridItem)
R.id.resize -> binding.homeScreenGrid.root.widgetLongPressed(gridItem)
R.id.app_info -> launchAppInfo(gridItem.packageName)
R.id.remove -> home_screen_grid.removeAppIcon(gridItem)
R.id.remove -> binding.homeScreenGrid.root.removeAppIcon(gridItem)
R.id.uninstall -> uninstallApp(gridItem.packageName)
}
true
@ -651,19 +653,19 @@ class MainActivity : SimpleActivity(), FlingListener {
}
private fun resetFragmentTouches() {
(widgets_fragment as WidgetsFragment).apply {
binding.widgetsFragment.root.apply {
touchDownY = -1
ignoreTouches = false
}
(all_apps_fragment as AllAppsFragment).apply {
binding.allAppsFragment.root.apply {
touchDownY = -1
ignoreTouches = false
}
}
private fun showWidgetsFragment() {
showFragment(widgets_fragment)
showFragment(binding.widgetsFragment)
}
private fun hideIcon(item: HomeScreenGridItem) {
@ -672,14 +674,14 @@ class MainActivity : SimpleActivity(), FlingListener {
hiddenIconsDB.insert(hiddenIcon)
runOnUiThread {
(all_apps_fragment as AllAppsFragment).hideIcon(item)
binding.allAppsFragment.root.hideIcon(item)
}
}
}
private fun renameItem(homeScreenGridItem: HomeScreenGridItem) {
RenameItemDialog(this, homeScreenGridItem) {
home_screen_grid.fetchGridItems()
binding.homeScreenGrid.root.fetchGridItems()
}
}
@ -689,7 +691,7 @@ class MainActivity : SimpleActivity(), FlingListener {
startActivity(this)
}
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
toast(CommonsR.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
@ -732,7 +734,7 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onFlingUp() {
if (!isWidgetsFragmentExpanded()) {
mIgnoreUpEvent = true
showFragment(all_apps_fragment)
showFragment(binding.allAppsFragment)
}
}
@ -740,9 +742,9 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onFlingDown() {
mIgnoreUpEvent = true
if (isAllAppsFragmentExpanded()) {
hideFragment(all_apps_fragment)
hideFragment(binding.allAppsFragment)
} else if (isWidgetsFragmentExpanded()) {
hideFragment(widgets_fragment)
hideFragment(binding.widgetsFragment)
} else {
try {
Class.forName("android.app.StatusBarManager").getMethod("expandNotificationsPanel").invoke(getSystemService("statusbar"))
@ -753,12 +755,12 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onFlingRight() {
mIgnoreUpEvent = true
home_screen_grid.prevPage(redraw = true)
binding.homeScreenGrid.root.prevPage(redraw = true)
}
override fun onFlingLeft() {
mIgnoreUpEvent = true
home_screen_grid.nextPage(redraw = true)
binding.homeScreenGrid.root.nextPage(redraw = true)
}
@SuppressLint("WrongConstant")

View File

@ -10,29 +10,33 @@ import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.launcher.BuildConfig
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.databinding.ActivitySettingsBinding
import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.helpers.MAX_COLUMN_COUNT
import com.simplemobiletools.launcher.helpers.MAX_ROW_COUNT
import com.simplemobiletools.launcher.helpers.MIN_COLUMN_COUNT
import com.simplemobiletools.launcher.helpers.MIN_ROW_COUNT
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.Locale
import kotlin.system.exitProcess
import com.simplemobiletools.commons.R as CommonsR
class SettingsActivity : SimpleActivity() {
private lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
updateMaterialActivityViews(settings_coordinator, settings_holder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(settings_nested_scrollview, settings_toolbar)
updateMaterialActivityViews(binding.settingsCoordinator, binding.settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.settingsNestedScrollview, binding.settingsToolbar)
setupOptionsMenu()
}
override fun onResume() {
super.onResume()
setupToolbar(settings_toolbar, NavigationIcon.Arrow)
setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow)
refreshMenuItems()
setupPurchaseThankYou()
@ -45,20 +49,20 @@ class SettingsActivity : SimpleActivity() {
setupHomeColumnCount()
setupLanguage()
setupManageHiddenIcons()
updateTextColors(settings_holder)
updateTextColors(binding.settingsHolder)
arrayOf(
settings_color_customization_section_label,
settings_general_settings_label,
settings_drawer_settings_label,
settings_home_screen_label
binding.settingsColorCustomizationLabel,
binding.settingsGeneralSettingsLabel,
binding.settingsDrawerSettingsLabel,
binding.settingsHomeScreenLabel
).forEach {
it.setTextColor(getProperPrimaryColor())
}
}
private fun setupOptionsMenu() {
settings_toolbar.setOnMenuItemClickListener { menuItem ->
binding.settingsToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.about -> launchAbout()
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
@ -69,50 +73,50 @@ class SettingsActivity : SimpleActivity() {
}
private fun refreshMenuItems() {
settings_toolbar.menu.apply {
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
binding.settingsToolbar.menu.apply {
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(CommonsR.bool.hide_google_relations)
}
}
private fun setupPurchaseThankYou() {
settings_purchase_thank_you_holder.beGoneIf(isOrWasThankYouInstalled())
settings_purchase_thank_you_holder.setOnClickListener {
binding.settingsPurchaseThankYouHolder.beGoneIf(isOrWasThankYouInstalled())
binding.settingsPurchaseThankYouHolder.setOnClickListener {
launchPurchaseThankYouIntent()
}
}
private fun setupCustomizeColors() {
settings_color_customization_label.text = getCustomizeColorsString()
settings_color_customization_holder.setOnClickListener {
binding.settingsColorCustomizationLabel.text = getCustomizeColorsString()
binding.settingsColorCustomizationHolder.setOnClickListener {
startCustomizationActivity()
}
}
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
settings_use_english.isChecked = config.useEnglish
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
binding.settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
binding.settingsUseEnglish.isChecked = config.useEnglish
binding.settingsUseEnglishHolder.setOnClickListener {
binding.settingsUseEnglish.toggle()
config.useEnglish = binding.settingsUseEnglish.isChecked
exitProcess(0)
}
}
private fun setupCloseAppDrawerOnOtherAppOpen() {
settings_close_app_drawer_on_other_app.isChecked = config.closeAppDrawer
settings_close_app_drawer_on_other_app_holder.setOnClickListener {
settings_close_app_drawer_on_other_app.toggle()
config.closeAppDrawer = settings_close_app_drawer_on_other_app.isChecked
binding.settingsCloseAppDrawerOnOtherApp.isChecked = config.closeAppDrawer
binding.settingsCloseAppDrawerOnOtherAppHolder.setOnClickListener {
binding.settingsCloseAppDrawerOnOtherApp.toggle()
config.closeAppDrawer = binding.settingsCloseAppDrawerOnOtherApp.isChecked
}
}
private fun setupDrawerColumnCount() {
val currentColumnCount = config.drawerColumnCount
settings_drawer_column_count.text = currentColumnCount.toString()
settings_drawer_column_count_holder.setOnClickListener {
binding.settingsDrawerColumnCount.text = currentColumnCount.toString()
binding.settingsDrawerColumnCountHolder.setOnClickListener {
val items = ArrayList<RadioItem>()
for (i in 1..MAX_COLUMN_COUNT) {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
items.add(RadioItem(i, resources.getQuantityString(CommonsR.plurals.column_counts, i, i)))
}
RadioGroupDialog(this, items, currentColumnCount) {
@ -127,20 +131,20 @@ class SettingsActivity : SimpleActivity() {
private fun setupDrawerSearchBar() {
val showSearchBar = config.showSearchBar
settings_show_search_bar.isChecked = showSearchBar
settings_drawer_search_holder.setOnClickListener {
settings_show_search_bar.toggle()
config.showSearchBar = settings_show_search_bar.isChecked
binding.settingsShowSearchBar.isChecked = showSearchBar
binding.settingsDrawerSearchHolder.setOnClickListener {
binding.settingsShowSearchBar.toggle()
config.showSearchBar = binding.settingsShowSearchBar.isChecked
}
}
private fun setupHomeRowCount() {
val currentRowCount = config.homeRowCount
settings_home_screen_row_count.text = currentRowCount.toString()
settings_home_screen_row_count_holder.setOnClickListener {
binding.settingsHomeScreenRowCount.text = currentRowCount.toString()
binding.settingsHomeScreenRowCountHolder.setOnClickListener {
val items = ArrayList<RadioItem>()
for (i in MIN_ROW_COUNT..MAX_ROW_COUNT) {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.row_counts, i, i)))
items.add(RadioItem(i, resources.getQuantityString(CommonsR.plurals.row_counts, i, i)))
}
RadioGroupDialog(this, items, currentRowCount) {
@ -155,11 +159,11 @@ class SettingsActivity : SimpleActivity() {
private fun setupHomeColumnCount() {
val currentColumnCount = config.homeColumnCount
settings_home_screen_column_count.text = currentColumnCount.toString()
settings_home_screen_column_count_holder.setOnClickListener {
binding.settingsHomeScreenColumnCount.text = currentColumnCount.toString()
binding.settingsHomeScreenColumnCountHolder.setOnClickListener {
val items = ArrayList<RadioItem>()
for (i in MIN_COLUMN_COUNT..MAX_COLUMN_COUNT) {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
items.add(RadioItem(i, resources.getQuantityString(CommonsR.plurals.column_counts, i, i)))
}
RadioGroupDialog(this, items, currentColumnCount) {
@ -173,15 +177,15 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupLanguage() {
settings_language.text = Locale.getDefault().displayLanguage
settings_language_holder.beVisibleIf(isTiramisuPlus())
settings_language_holder.setOnClickListener {
binding.settingsLanguage.text = Locale.getDefault().displayLanguage
binding.settingsLanguageHolder.beVisibleIf(isTiramisuPlus())
binding.settingsLanguageHolder.setOnClickListener {
launchChangeAppLanguageIntent()
}
}
private fun setupManageHiddenIcons() {
settings_manage_hidden_icons_holder.setOnClickListener {
binding.settingsManageHiddenIconsHolder.setOnClickListener {
startActivity(Intent(this, HiddenIconsActivity::class.java))
}
}
@ -190,9 +194,9 @@ class SettingsActivity : SimpleActivity() {
val licenses = 0L
val faqItems = ArrayList<FAQItem>()
if (!resources.getBoolean(R.bool.hide_google_relations)) {
faqItems.add(FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons))
faqItems.add(FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons))
if (!resources.getBoolean(CommonsR.bool.hide_google_relations)) {
faqItems.add(FAQItem(CommonsR.string.faq_2_title_commons, CommonsR.string.faq_2_text_commons))
faqItems.add(FAQItem(CommonsR.string.faq_6_title_commons, CommonsR.string.faq_6_text_commons))
}
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)

View File

@ -15,9 +15,9 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.databinding.ItemHiddenIconBinding
import com.simplemobiletools.launcher.extensions.hiddenIconsDB
import com.simplemobiletools.launcher.models.HiddenIcon
import kotlinx.android.synthetic.main.item_hidden_icon.view.*
class HiddenIconsAdapter(
activity: BaseSimpleActivity,
@ -56,7 +56,9 @@ class HiddenIconsAdapter(
override fun onActionModeDestroyed() {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_hidden_icon, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return createViewHolder(ItemHiddenIconBinding.inflate(layoutInflater, parent, false).root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val folder = hiddenIcons[position]
@ -101,11 +103,11 @@ class HiddenIconsAdapter(
}
private fun setupView(view: View, icon: HiddenIcon) {
view.apply {
hidden_icon_holder?.isSelected = selectedKeys.contains(icon.hashCode())
hidden_icon_label.text = icon.title
hidden_icon_label.setTextColor(textColor)
hidden_icon.setPadding(iconPadding, iconPadding, iconPadding, 0)
ItemHiddenIconBinding.bind(view).apply {
hiddenIconHolder.isSelected = selectedKeys.contains(icon.hashCode())
hiddenIconLabel.text = icon.title
hiddenIconLabel.setTextColor(textColor)
hiddenIcon.setPadding(iconPadding, iconPadding, iconPadding, 0)
val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build()
@ -113,7 +115,7 @@ class HiddenIconsAdapter(
.load(icon.drawable)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.transition(DrawableTransitionOptions.withCrossFade(factory))
.into(hidden_icon)
.into(hiddenIcon)
}
}
}

View File

@ -14,11 +14,11 @@ import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.realScreenSize
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.SimpleActivity
import com.simplemobiletools.launcher.databinding.ItemLauncherLabelBinding
import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.interfaces.AllAppsListener
import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.android.synthetic.main.item_launcher_label.view.*
class LaunchersAdapter(
val activity: SimpleActivity,
@ -44,8 +44,8 @@ class LaunchersAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_launcher_label, parent, false)
return ViewHolder(view)
val binding = ItemLauncherLabelBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding.root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -103,10 +103,11 @@ class LaunchersAdapter(
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(launcher: AppLauncher): View {
val binding = ItemLauncherLabelBinding.bind(itemView)
itemView.apply {
launcher_label.text = launcher.title
launcher_label.setTextColor(textColor)
launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, 0)
binding.launcherLabel.text = launcher.title
binding.launcherLabel.setTextColor(textColor)
binding.launcherIcon.setPadding(iconPadding, iconPadding, iconPadding, 0)
val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build()
val placeholderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.placeholder_drawable, launcher.thumbnailColor)
@ -116,7 +117,7 @@ class LaunchersAdapter(
.placeholder(placeholderDrawable)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.transition(DrawableTransitionOptions.withCrossFade(factory))
.into(launcher_icon)
.into(binding.launcherIcon)
setOnClickListener { itemClick(launcher) }
setOnLongClickListener { view ->

View File

@ -9,15 +9,16 @@ import com.bumptech.glide.Glide
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.SimpleActivity
import com.simplemobiletools.launcher.databinding.ItemWidgetListItemsHolderBinding
import com.simplemobiletools.launcher.databinding.ItemWidgetListSectionBinding
import com.simplemobiletools.launcher.databinding.ItemWidgetPreviewBinding
import com.simplemobiletools.launcher.helpers.WIDGET_LIST_ITEMS_HOLDER
import com.simplemobiletools.launcher.helpers.WIDGET_LIST_SECTION
import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
import com.simplemobiletools.launcher.models.WidgetsListItem
import com.simplemobiletools.launcher.models.WidgetsListItemsHolder
import com.simplemobiletools.launcher.models.WidgetsListSection
import kotlinx.android.synthetic.main.item_widget_list_items_holder.view.*
import kotlinx.android.synthetic.main.item_widget_list_section.view.*
import kotlinx.android.synthetic.main.item_widget_preview.view.*
import com.simplemobiletools.commons.R as CommonsR
class WidgetsAdapter(
val activity: SimpleActivity,
@ -29,13 +30,13 @@ class WidgetsAdapter(
private var textColor = activity.getProperTextColor()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutId = when (viewType) {
WIDGET_LIST_SECTION -> R.layout.item_widget_list_section
else -> R.layout.item_widget_list_items_holder
val inflater = LayoutInflater.from(parent.context)
val binding = when (viewType) {
WIDGET_LIST_SECTION -> ItemWidgetListSectionBinding.inflate(inflater, parent, false)
else -> ItemWidgetListItemsHolderBinding.inflate(inflater, parent, false)
}
val view = LayoutInflater.from(parent.context).inflate(layoutId, parent, false)
return ViewHolder(view)
return ViewHolder(binding.root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -56,43 +57,44 @@ class WidgetsAdapter(
}
private fun setupListSection(view: View, section: WidgetsListSection) {
view.apply {
widget_app_title.text = section.appTitle
widget_app_title.setTextColor(textColor)
widget_app_icon.setImageDrawable(section.appIcon)
ItemWidgetListSectionBinding.bind(view).apply {
widgetAppTitle.text = section.appTitle
widgetAppTitle.setTextColor(textColor)
widgetAppIcon.setImageDrawable(section.appIcon)
}
}
private fun setupListItemsHolder(view: View, listItem: WidgetsListItemsHolder) {
view.widget_list_items_holder.removeAllViews()
view.widget_list_items_scroll_view.scrollX = 0
val binding = ItemWidgetListItemsHolderBinding.bind(view)
binding.widgetListItemsHolder.removeAllViews()
binding.widgetListItemsScrollView.scrollX = 0
listItem.widgets.forEachIndexed { index, widget ->
val imageSize = activity.resources.getDimension(R.dimen.widget_preview_size).toInt()
val widgetPreview = LayoutInflater.from(activity).inflate(R.layout.item_widget_preview, null)
view.widget_list_items_holder.addView(widgetPreview)
val widgetPreview = ItemWidgetPreviewBinding.inflate(LayoutInflater.from(activity))
binding.widgetListItemsHolder.addView(widgetPreview.root)
val endMargin = if (index == listItem.widgets.size - 1) {
activity.resources.getDimension(R.dimen.medium_margin).toInt()
activity.resources.getDimension(CommonsR.dimen.medium_margin).toInt()
} else {
0
}
widgetPreview.widget_title.apply {
widgetPreview.widgetTitle.apply {
text = widget.widgetTitle
setTextColor(textColor)
}
widgetPreview.widget_size.apply {
widgetPreview.widgetSize.apply {
text = if (widget.isShortcut) {
activity.getString(R.string.shortcut)
activity.getString(CommonsR.string.shortcut)
} else {
"${widget.widthCells} x ${widget.heightCells}"
}
setTextColor(textColor)
}
(widgetPreview.widget_image.layoutParams as RelativeLayout.LayoutParams).apply {
marginStart = activity.resources.getDimension(R.dimen.activity_margin).toInt()
(widgetPreview.widgetImage.layoutParams as RelativeLayout.LayoutParams).apply {
marginStart = activity.resources.getDimension(CommonsR.dimen.activity_margin).toInt()
marginEnd = endMargin
width = imageSize
height = imageSize
@ -100,11 +102,11 @@ class WidgetsAdapter(
Glide.with(activity)
.load(widget.widgetPreviewImage)
.into(widgetPreview.widget_image)
.into(widgetPreview.widgetImage)
widgetPreview.setOnClickListener { itemClick() }
widgetPreview.root.setOnClickListener { itemClick() }
widgetPreview.setOnLongClickListener { view ->
widgetPreview.root.setOnLongClickListener { view ->
widgetsFragmentListener.onWidgetLongPressed(widget)
true
}

View File

@ -2,41 +2,41 @@ package com.simplemobiletools.launcher.dialogs
import android.app.Activity
import android.app.AlertDialog
import android.view.ViewGroup
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.mydebug
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.databinding.DialogRenameItemBinding
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.android.synthetic.main.dialog_rename_item.view.*
import com.simplemobiletools.commons.R as CommonsR
class RenameItemDialog(val activity: Activity, val item: HomeScreenGridItem, val callback: () -> Unit) {
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_rename_item, null) as ViewGroup)
view.rename_item_edittext.setText(item.title)
val binding = DialogRenameItemBinding.inflate(activity.layoutInflater)
val view = binding.root
binding.renameItemEdittext.setText(item.title)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(CommonsR.string.ok, null)
.setNegativeButton(CommonsR.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.rename) { alertDialog ->
alertDialog.showKeyboard(view.rename_item_edittext)
activity.setupDialogStuff(view, this, CommonsR.string.rename) { alertDialog ->
alertDialog.showKeyboard(binding.renameItemEdittext)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.rename_item_edittext.value
if (!newTitle.isEmpty()) {
val newTitle = binding.renameItemEdittext.value
if (newTitle.isNotEmpty()) {
ensureBackgroundThread {
val result = activity.homeScreenGridItemsDB.updateItemTitle(newTitle, item.id!!)
if (result == 1) {
callback()
alertDialog.dismiss()
} else {
activity.toast(R.string.unknown_error_occurred)
activity.toast(CommonsR.string.unknown_error_occurred)
}
}
} else {
activity.toast(R.string.value_cannot_be_empty)
activity.toast(CommonsR.string.value_cannot_be_empty)
}
}
}

View File

@ -10,18 +10,18 @@ import android.view.WindowManager
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
import com.simplemobiletools.launcher.databinding.AllAppsFragmentBinding
import com.simplemobiletools.launcher.extensions.config
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
import kotlinx.android.synthetic.main.all_apps_fragment.view.*
import com.simplemobiletools.commons.R as CommonsR
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener {
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment<AllAppsFragmentBinding>(context, attributeSet), AllAppsListener {
private var lastTouchCoords = Pair(0f, 0f)
var touchDownY = -1
var ignoreTouches = false
@ -30,8 +30,9 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
@SuppressLint("ClickableViewAccessibility")
override fun setupFragment(activity: MainActivity) {
this.activity = activity
this.binding = AllAppsFragmentBinding.bind(this)
all_apps_grid.setOnTouchListener { v, event ->
binding.allAppsGrid.setOnTouchListener { v, event ->
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
touchDownY = -1
}
@ -42,30 +43,26 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
@SuppressLint("NotifyDataSetChanged")
fun onResume() {
if (all_apps_grid?.layoutManager == null || all_apps_grid?.adapter == null) {
if (binding.allAppsGrid.layoutManager == null || binding.allAppsGrid.adapter == null) {
return
}
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
val layoutManager = binding.allAppsGrid.layoutManager as MyGridLayoutManager
if (layoutManager.spanCount != context.config.drawerColumnCount) {
onConfigurationChanged()
// Force redraw due to changed item size
(all_apps_grid.adapter as LaunchersAdapter).notifyDataSetChanged()
(binding.allAppsGrid.adapter as LaunchersAdapter).notifyDataSetChanged()
}
}
fun onConfigurationChanged() {
if (all_apps_grid == null) {
return
}
all_apps_grid.scrollToPosition(0)
all_apps_fastscroller.resetManualScrolling()
binding.allAppsGrid.scrollToPosition(0)
binding.allAppsFastscroller.resetManualScrolling()
setupViews()
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
val layoutManager = binding.allAppsGrid.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context.config.drawerColumnCount
val launchers = (all_apps_grid.adapter as LaunchersAdapter).launchers
val launchers = (binding.allAppsGrid.adapter as LaunchersAdapter).launchers
setupAdapter(launchers)
}
@ -87,7 +84,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
// pull the whole fragment down if it is scrolled way to the top and the users pulls it even further
if (touchDownY != -1) {
shouldIntercept = touchDownY - event.y.toInt() < 0 && all_apps_grid.computeVerticalScrollOffset() == 0
shouldIntercept = touchDownY - event.y.toInt() < 0 && binding.allAppsGrid.computeVerticalScrollOffset() == 0
if (shouldIntercept) {
activity?.startHandlingTouches(touchDownY)
touchDownY = -1
@ -113,10 +110,10 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
activity?.runOnUiThread {
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
val layoutManager = binding.allAppsGrid.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context.config.drawerColumnCount
val currAdapter = all_apps_grid.adapter
val currAdapter = binding.allAppsGrid.adapter
if (currAdapter == null) {
LaunchersAdapter(activity!!, launchers, this) {
activity?.launchApp((it as AppLauncher).packageName, it.activityName)
@ -126,7 +123,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
ignoreTouches = false
touchDownY = -1
}.apply {
all_apps_grid.adapter = this
binding.allAppsGrid.adapter = this
}
} else {
(currAdapter as LaunchersAdapter).updateItems(launchers)
@ -135,7 +132,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
fun hideIcon(item: HomeScreenGridItem) {
(all_apps_grid.adapter as? LaunchersAdapter)?.hideIcon(item)
(binding.allAppsGrid.adapter as? LaunchersAdapter)?.hideIcon(item)
}
fun setupViews(addTopPadding: Boolean = hasTopPadding) {
@ -143,7 +140,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
return
}
all_apps_fastscroller.updateColors(context.getProperPrimaryColor())
binding.allAppsFastscroller.updateColors(context.getProperPrimaryColor())
var bottomListPadding = 0
var leftListPadding = 0
@ -169,29 +166,29 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
}
all_apps_grid.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding)
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
binding.allAppsGrid.setPadding(0, 0, resources.getDimension(CommonsR.dimen.medium_margin).toInt(), bottomListPadding)
binding.allAppsFastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
hasTopPadding = addTopPadding
val topPadding = if (addTopPadding) activity!!.statusBarHeight else 0
setPadding(0, topPadding, 0, 0)
background = ColorDrawable(context.getProperBackgroundColor())
(all_apps_grid.adapter as? LaunchersAdapter)?.updateTextColor(context.getProperTextColor())
(binding.allAppsGrid.adapter as? LaunchersAdapter)?.updateTextColor(context.getProperTextColor())
search_bar.beVisibleIf(context.config.showSearchBar)
search_bar.getToolbar()?.beGone()
search_bar.updateColors()
search_bar.setupMenu()
binding.searchBar.beVisibleIf(context.config.showSearchBar)
binding.searchBar.getToolbar()?.beGone()
binding.searchBar.updateColors()
binding.searchBar.setupMenu()
search_bar.onSearchTextChangedListener = {
(all_apps_grid.adapter as? LaunchersAdapter)?.updateSearchQuery(it)
binding.searchBar.onSearchTextChangedListener = {
(binding.allAppsGrid.adapter as? LaunchersAdapter)?.updateSearchQuery(it)
showNoResultsPlaceholderIfNeeded()
}
}
private fun showNoResultsPlaceholderIfNeeded() {
val itemCount = all_apps_grid.adapter?.itemCount
no_results_placeholder.beVisibleIf(itemCount != null && itemCount == 0)
val itemCount = binding.allAppsGrid.adapter?.itemCount
binding.noResultsPlaceholder.beVisibleIf(itemCount != null && itemCount == 0)
}
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
@ -217,12 +214,12 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
activity?.showHomeIconMenu(x, y, gridItem, true)
ignoreTouches = true
search_bar.closeSearch()
binding.searchBar.closeSearch()
}
fun onBackPressed(): Boolean {
if (search_bar.isSearchOpen) {
search_bar.closeSearch()
if (binding.searchBar.isSearchOpen) {
binding.searchBar.closeSearch()
return true
}

View File

@ -3,10 +3,12 @@ package com.simplemobiletools.launcher.fragments
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
import androidx.viewbinding.ViewBinding
import com.simplemobiletools.launcher.activities.MainActivity
abstract class MyFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
abstract class MyFragment<BINDING : ViewBinding>(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
protected var activity: MainActivity? = null
protected lateinit var binding: BINDING
abstract fun setupFragment(activity: MainActivity)
}

View File

@ -18,15 +18,15 @@ import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.adapters.WidgetsAdapter
import com.simplemobiletools.launcher.databinding.WidgetsFragmentBinding
import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.extensions.getInitialCellSize
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_SHORTCUT
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.*
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), WidgetsFragmentListener {
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment<WidgetsFragmentBinding>(context, attributeSet), WidgetsFragmentListener {
private var lastTouchCoords = Pair(0f, 0f)
var touchDownY = -1
var ignoreTouches = false
@ -35,9 +35,10 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
@SuppressLint("ClickableViewAccessibility")
override fun setupFragment(activity: MainActivity) {
this.activity = activity
this.binding = WidgetsFragmentBinding.bind(this)
getAppWidgets()
widgets_list.setOnTouchListener { v, event ->
binding.widgetsList.setOnTouchListener { v, event ->
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
touchDownY = -1
}
@ -47,14 +48,14 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
fun onConfigurationChanged() {
if (widgets_list == null) {
if (binding.widgetsList == null) {
return
}
widgets_list.scrollToPosition(0)
binding.widgetsList.scrollToPosition(0)
setupViews()
val appWidgets = (widgets_list.adapter as WidgetsAdapter).widgetListItems
val appWidgets = (binding.widgetsList.adapter as WidgetsAdapter).widgetListItems
setupAdapter(appWidgets)
}
@ -76,7 +77,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
// pull the whole fragment down if it is scrolled way to the top and the users pulls it even further
if (touchDownY != -1) {
shouldIntercept = touchDownY - event.y.toInt() < 0 && widgets_list.computeVerticalScrollOffset() == 0
shouldIntercept = touchDownY - event.y.toInt() < 0 && binding.widgetsList.computeVerticalScrollOffset() == 0
if (shouldIntercept) {
activity?.startHandlingTouches(touchDownY)
touchDownY = -1
@ -159,14 +160,14 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
private fun setupAdapter(widgetsListItems: ArrayList<WidgetsListItem>) {
activity?.runOnUiThread {
val currAdapter = widgets_list.adapter
val currAdapter = binding.widgetsList.adapter
if (currAdapter == null) {
WidgetsAdapter(activity!!, widgetsListItems, this) {
context.toast(R.string.touch_hold_widget)
ignoreTouches = false
touchDownY = -1
}.apply {
widgets_list.adapter = this
binding.widgetsList.adapter = this
}
} else {
(currAdapter as WidgetsAdapter).updateItems(widgetsListItems)
@ -179,7 +180,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
return
}
widgets_fastscroller.updateColors(context.getProperPrimaryColor())
binding.widgetsFastscroller.updateColors(context.getProperPrimaryColor())
var bottomListPadding = 0
var leftListPadding = 0
@ -205,14 +206,14 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
}
widgets_list.setPadding(0, 0, 0, bottomListPadding)
widgets_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
binding.widgetsList.setPadding(0, 0, 0, bottomListPadding)
binding.widgetsFastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
hasTopPadding = addTopPadding
val topPadding = if (addTopPadding) activity!!.statusBarHeight else 0
setPadding(0, topPadding, 0, 0)
background = ColorDrawable(context.getProperBackgroundColor())
(widgets_list.adapter as? WidgetsAdapter)?.updateTextColor(context.getProperTextColor())
(binding.widgetsList.adapter as? WidgetsAdapter)?.updateTextColor(context.getProperTextColor())
}
private fun getAppMetadataFromPackage(packageName: String): WidgetsListSection? {

View File

@ -31,20 +31,22 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isSPlus
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.databinding.HomeScreenGridBinding
import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
import com.simplemobiletools.launcher.helpers.*
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.android.synthetic.main.activity_main.view.*
import kotlin.math.abs
import kotlin.math.floor
import kotlin.math.max
import kotlin.math.min
import com.simplemobiletools.commons.R as CommonsR
class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
private lateinit var binding: HomeScreenGridBinding
private var columnCount = context.config.homeColumnCount
private var rowCount = context.config.homeRowCount
private var cellXCoords = ArrayList<Int>(columnCount)
@ -55,8 +57,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
private var extraYMargin = 0
private var iconMargin = (context.resources.getDimension(R.dimen.icon_side_margin) * 5 / columnCount).toInt()
private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
private var roundedCornerRadius = context.resources.getDimension(R.dimen.activity_margin)
private var labelSideMargin = context.resources.getDimension(CommonsR.dimen.small_margin).toInt()
private var roundedCornerRadius = context.resources.getDimension(CommonsR.dimen.activity_margin)
private var pageIndicatorRadius = context.resources.getDimension(R.dimen.page_indicator_dot_radius)
private var pageIndicatorMargin = context.resources.getDimension(R.dimen.page_indicator_margin)
private var textPaint: TextPaint
@ -117,13 +119,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.WHITE
textSize = context.resources.getDimension(R.dimen.smaller_text_size)
textSize = context.resources.getDimension(CommonsR.dimen.smaller_text_size)
setShadowLayer(2f, 0f, 0f, Color.BLACK)
}
dragShadowCirclePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = context.resources.getColor(R.color.hint_white)
strokeWidth = context.resources.getDimension(R.dimen.small_margin)
color = context.resources.getColor(CommonsR.color.hint_white)
strokeWidth = context.resources.getDimension(CommonsR.dimen.small_margin)
style = Paint.Style.STROKE
}
@ -131,11 +133,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
strokeWidth = context.resources.getDimension(R.dimen.page_indicator_stroke_width)
}
currentPageIndicatorPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = context.resources.getColor(R.color.white)
color = context.resources.getColor(android.R.color.white)
style = Paint.Style.FILL
}
val sideMargin = context.resources.getDimension(R.dimen.normal_margin).toInt()
val sideMargin = context.resources.getDimension(CommonsR.dimen.normal_margin).toInt()
sideMargins.apply {
top = context.statusBarHeight
bottom = context.navigationBarHeight
@ -146,6 +148,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
fetchGridItems()
}
override fun onFinishInflate() {
super.onFinishInflate()
binding = HomeScreenGridBinding.bind(this)
}
fun fetchGridItems() {
ensureBackgroundThread {
val providers = appWidgetManager.installedProviders
@ -304,20 +311,20 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
redrawGrid()
val widgetView = widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }
resize_frame.beGone()
binding.resizeFrame.beGone()
if (widgetView != null) {
val viewX = widgetView.x.toInt()
val viewY = widgetView.y.toInt()
val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height)
val otherGridItems = gridItems.filter { it.widgetId != item.widgetId }.toMutableList() as ArrayList<HomeScreenGridItem>
resize_frame.updateFrameCoords(frameRect, cellWidth, cellHeight, sideMargins, item, otherGridItems)
resize_frame.beVisible()
resize_frame.z = 1f // make sure the frame isnt behind the widget itself
resize_frame.onClickListener = {
binding.resizeFrame.updateFrameCoords(frameRect, cellWidth, cellHeight, sideMargins, item, otherGridItems)
binding.resizeFrame.beVisible()
binding.resizeFrame.z = 1f // make sure the frame isnt behind the widget itself
binding.resizeFrame.onClickListener = {
hideResizeLines()
}
resize_frame.onResizeListener = { cellsRect ->
binding.resizeFrame.onResizeListener = { cellsRect ->
item.left = cellsRect.left
item.top = cellsRect.top
item.right = cellsRect.right
@ -334,7 +341,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
widgetView.ignoreTouches = true
widgetView.setOnTouchListener { v, event ->
resize_frame.onTouchEvent(event)
binding.resizeFrame.onTouchEvent(event)
return@setOnTouchListener true
}
}
@ -345,7 +352,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
return
}
resize_frame.beGone()
binding.resizeFrame.beGone()
widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }?.apply {
ignoreTouches = false
setOnTouchListener(null)

View File

@ -13,6 +13,7 @@ import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.extensions.getCellCount
import com.simplemobiletools.launcher.helpers.MAX_CLICK_DURATION
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import com.simplemobiletools.commons.R as CommonsR
@SuppressLint("ViewConstructor")
class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
@ -48,7 +49,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
resizeWidgetLinePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.WHITE
strokeWidth = context.resources.getDimension(R.dimen.tiny_margin)
strokeWidth = context.resources.getDimension(CommonsR.dimen.tiny_margin)
style = Paint.Style.STROKE
}

View File

@ -4,18 +4,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simplemobiletools.launcher.views.HomeScreenGrid
<include
android:id="@+id/home_screen_grid"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simplemobiletools.launcher.views.MyAppWidgetResizeFrame
android:id="@+id/resize_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</com.simplemobiletools.launcher.views.HomeScreenGrid>
layout="@layout/home_screen_grid" />
<include
android:id="@+id/all_apps_fragment"

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.launcher.views.HomeScreenGrid xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_screen_grid"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simplemobiletools.launcher.views.MyAppWidgetResizeFrame
android:id="@+id/resize_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</com.simplemobiletools.launcher.views.HomeScreenGrid>

View File

@ -1,30 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

5
build.gradle.kts Normal file
View File

@ -0,0 +1,5 @@
plugins {
alias(libs.plugins.android).apply(false)
alias(libs.plugins.kotlinAndroid).apply(false)
alias(libs.plugins.ksp).apply(false)
}

37
gradle/libs.versions.toml Normal file
View File

@ -0,0 +1,37 @@
[versions]
#jetbrains
kotlin = "1.9.0"
#KSP
ksp = "1.9.0-1.0.12"
#Room
room = "2.6.0-alpha02"
#Simple tools
simple-commons = "c5a32fb1f3"
#Gradle
gradlePlugins-agp = "8.1.0"
#build
app-build-compileSDKVersion = "34"
app-build-targetSDK = "34"
app-build-minimumSDK = "26"
app-build-javaVersion = "VERSION_17"
app-build-kotlinJVMTarget = "17"
#versioning
app-version-appId = "com.simplemobiletools.launcher"
app-version-versionCode = "8"
app-version-versionName = "5.0.6"
[libraries]
#Room
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
#Simple Mobile Tools
simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" }
[bundles]
room = [
"androidx-room-ktx",
"androidx-room-runtime",
]
[plugins]
android = { id = "com.android.application", version.ref = "gradlePlugins-agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

View File

@ -1,6 +1,6 @@
#Mon Aug 01 22:01:46 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -1 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { setUrl("https://jitpack.io") }
}
}
include ':app'