diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt index ceff39e..1bc42cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt @@ -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 + val hiddenIcons = hiddenIconsDB.getHiddenIcons().sortedWith( + compareBy({ + it.title.normalizeString().lowercase() + }, { + it.packageName + }) + ).toMutableList() as ArrayList + val intent = Intent(Intent.ACTION_MAIN, null) intent.addCategory(Intent.CATEGORY_LAUNCHER) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt index 1c272e3..3e96e5f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt @@ -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 + + 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( diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt index 95d9d76..de46cc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Context.kt index 7e567c4..72aa0e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Context.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt index 98a590a..f6e2fa9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt @@ -86,7 +86,14 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment } fun gotLaunchers(appLaunchers: ArrayList) { - val sorted = appLaunchers.sortedBy { it.title.normalizeString().lowercase() }.toMutableList() as ArrayList + val sorted = appLaunchers.sortedWith( + compareBy({ + it.title.normalizeString().lowercase() + }, { + it.packageName + }) + ).toMutableList() as ArrayList + setupAdapter(sorted) } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconsDao.kt similarity index 67% rename from app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt rename to app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconsDao.kt index 0a695b2..e88cac7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconsDao.kt @@ -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 @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(hiddenIcon: HiddenIcon): Long + + @Delete + fun removeHiddenIcons(icons: List) }