allow removing hidden icons from the app settings

This commit is contained in:
tibbi 2022-10-26 16:24:24 +02:00
parent 0169862343
commit 68cf94bd74
6 changed files with 43 additions and 12 deletions

View file

@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.activities
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import com.simplemobiletools.commons.extensions.normalizeString
import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.MyGridLayoutManager
@ -31,7 +32,14 @@ class HiddenIconsActivity : SimpleActivity() {
private fun updateIcons() {
ensureBackgroundThread {
val hiddenIcons = hiddenIconsDB.getHiddenIcons().toMutableList() as ArrayList<HiddenIcon>
val hiddenIcons = hiddenIconsDB.getHiddenIcons().sortedWith(
compareBy({
it.title.normalizeString().lowercase()
}, {
it.packageName
})
).toMutableList() as ArrayList<HiddenIcon>
val intent = Intent(Intent.ACTION_MAIN, null)
intent.addCategory(Intent.CATEGORY_LAUNCHER)

View file

@ -11,8 +11,10 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.portrait
import com.simplemobiletools.commons.extensions.realScreenSize
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.extensions.hiddenIconsDB
import com.simplemobiletools.launcher.models.HiddenIcon
import kotlinx.android.synthetic.main.item_hidden_icon.view.*
@ -63,7 +65,21 @@ class HiddenIconsAdapter(
override fun getItemCount() = hiddenIcons.size
private fun unHideSelection() {}
private fun getSelectedItems() = hiddenIcons.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<HiddenIcon>
private fun unHideSelection() {
val positions = getSelectedItemPositions()
ensureBackgroundThread {
val selectedItems = getSelectedItems()
activity.hiddenIconsDB.removeHiddenIcons(selectedItems)
hiddenIcons.removeAll(selectedItems)
activity.runOnUiThread {
removeSelectedItems(positions)
}
}
}
private fun calculateIconWidth() {
val currentColumnCount = activity.resources.getInteger(

View file

@ -9,7 +9,7 @@ import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.simplemobiletools.launcher.helpers.Converters
import com.simplemobiletools.launcher.interfaces.AppLaunchersDao
import com.simplemobiletools.launcher.interfaces.HiddenIconDao
import com.simplemobiletools.launcher.interfaces.HiddenIconsDao
import com.simplemobiletools.launcher.interfaces.HomeScreenGridItemsDao
import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HiddenIcon
@ -23,7 +23,7 @@ abstract class AppsDatabase : RoomDatabase() {
abstract fun HomeScreenGridItemsDao(): HomeScreenGridItemsDao
abstract fun HiddenIconsDao(): HiddenIconDao
abstract fun HiddenIconsDao(): HiddenIconsDao
companion object {
private var db: AppsDatabase? = null

View file

@ -12,7 +12,7 @@ import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.databases.AppsDatabase
import com.simplemobiletools.launcher.helpers.Config
import com.simplemobiletools.launcher.interfaces.AppLaunchersDao
import com.simplemobiletools.launcher.interfaces.HiddenIconDao
import com.simplemobiletools.launcher.interfaces.HiddenIconsDao
import com.simplemobiletools.launcher.interfaces.HomeScreenGridItemsDao
val Context.config: Config get() = Config.newInstance(applicationContext)
@ -21,7 +21,7 @@ val Context.launchersDB: AppLaunchersDao get() = AppsDatabase.getInstance(applic
val Context.homeScreenGridItemsDB: HomeScreenGridItemsDao get() = AppsDatabase.getInstance(applicationContext).HomeScreenGridItemsDao()
val Context.hiddenIconsDB: HiddenIconDao get() = AppsDatabase.getInstance(applicationContext).HiddenIconsDao()
val Context.hiddenIconsDB: HiddenIconsDao get() = AppsDatabase.getInstance(applicationContext).HiddenIconsDao()
fun Context.getColumnCount(): Int {
return if (portrait) {

View file

@ -86,7 +86,14 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
fun gotLaunchers(appLaunchers: ArrayList<AppLauncher>) {
val sorted = appLaunchers.sortedBy { it.title.normalizeString().lowercase() }.toMutableList() as ArrayList<AppLauncher>
val sorted = appLaunchers.sortedWith(
compareBy({
it.title.normalizeString().lowercase()
}, {
it.packageName
})
).toMutableList() as ArrayList<AppLauncher>
setupAdapter(sorted)
}

View file

@ -1,16 +1,16 @@
package com.simplemobiletools.launcher.interfaces
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.*
import com.simplemobiletools.launcher.models.HiddenIcon
@Dao
interface HiddenIconDao {
interface HiddenIconsDao {
@Query("SELECT * FROM hidden_icons")
fun getHiddenIcons(): List<HiddenIcon>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(hiddenIcon: HiddenIcon): Long
@Delete
fun removeHiddenIcons(icons: List<HiddenIcon>)
}