Skip to content

Commit

Permalink
feat: App hiding, closes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
axel358 committed Sep 25, 2024
1 parent 86e9cfe commit 6ef28ef
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/cu/axel/smartdock/adapters/AppAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import java.util.Locale

class AppAdapter(
private val context: Context,
private var apps: ArrayList<App>,
private var apps: List<App>,
private val listener: OnAppClickListener,
private val large: Boolean,
val iconPackUtils: IconPackUtils?
private val iconPackUtils: IconPackUtils?
) : RecyclerView.Adapter<AppAdapter.ViewHolder>() {
private val allApps: ArrayList<App> = ArrayList(apps)
private var iconBackground = 0
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/java/cu/axel/smartdock/services/DockService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import android.os.Handler
import android.os.Looper
import android.os.Process
import android.provider.Settings
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.Display
import android.view.GestureDetector
Expand Down Expand Up @@ -1171,7 +1170,11 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On

private fun updateAppMenu() {
CoroutineScope(Dispatchers.Default).launch {
val apps = fetchInstalledApps()
val hiddenApps = sharedPreferences.getStringSet(
"hidden_apps_grid",
setOf()
)!!
val apps = fetchInstalledApps().filterNot { hiddenApps.contains(it.packageName) }

withContext(Dispatchers.Main) {
val menuFullscreen = sharedPreferences.getBoolean("app_menu_fullscreen", false)
Expand Down Expand Up @@ -1212,6 +1215,13 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
val actions = ArrayList<Action>()
actions.add(Action(R.drawable.ic_arrow_back, ""))
actions.add(Action(R.drawable.ic_info, getString(R.string.app_info)))
if (sharedPreferences.getBoolean("enable_app_hiding_grid", false))
actions.add(
Action(
R.drawable.ic_hide,
getString(R.string.hide)
)
)
if (!AppUtils.isSystemApp(
context,
app.packageName
Expand Down Expand Up @@ -1253,6 +1263,27 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
.setData(Uri.parse("package:${app.packageName}"))
)
windowManager.removeView(view)
} else if (action.text == getString(R.string.hide)) {
val savedApps = sharedPreferences.getStringSet(
"hidden_apps_grid",
setOf()
)!!
val hiddenApps = mutableSetOf<String>()
hiddenApps.addAll(savedApps)
hiddenApps.add(app.packageName)

sharedPreferences.edit()
.putStringSet("hidden_apps_grid", hiddenApps).apply()

if (AppUtils.isPinned(this, app, AppUtils.PINNED_LIST))
AppUtils.unpinApp(this, app.packageName, AppUtils.PINNED_LIST)
if (AppUtils.isPinned(this, app, AppUtils.DOCK_PINNED_LIST))
AppUtils.unpinApp(this, app.packageName, AppUtils.DOCK_PINNED_LIST)
if (AppUtils.isPinned(this, app, AppUtils.DESKTOP_LIST))
AppUtils.unpinApp(this, app.packageName, AppUtils.DESKTOP_LIST)
updateAppMenu()
loadFavoriteApps()
windowManager.removeView(view)
} else if (action.text == getString(R.string.uninstall)) {
if (AppUtils.isSystemApp(context, app.packageName))
DeviceUtils.runAsRoot("pm uninstall --user 0 ${app.packageName}")
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_hide.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M2,5.27L3.28,4L20,20.72L18.73,22L15.65,18.92C14.5,19.3 13.28,19.5 12,19.5C7,19.5 2.73,16.39 1,12C1.69,10.24 2.79,8.69 4.19,7.46L2,5.27M12,9A3,3 0 0,1 15,12C15,12.35 14.94,12.69 14.83,13L11,9.17C11.31,9.06 11.65,9 12,9M12,4.5C17,4.5 21.27,7.61 23,12C22.18,14.08 20.79,15.88 19,17.19L17.58,15.76C18.94,14.82 20.06,13.54 20.82,12C19.17,8.64 15.76,6.5 12,6.5C10.91,6.5 9.84,6.68 8.84,7L7.3,5.47C8.74,4.85 10.33,4.5 12,4.5M3.18,12C4.83,15.36 8.24,17.5 12,17.5C12.69,17.5 13.37,17.43 14,17.29L11.72,15C10.29,14.85 9.15,13.71 9,12.28L5.6,8.87C4.61,9.72 3.78,10.78 3.18,12Z"/>
</vector>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,7 @@
<string name="choose_apps">Choose apps</string>
<string name="silenced_notifications_title">Silenced notifications</string>
<string name="hidden_notifications">Hidden notifications</string>
<string name="hidden_apps">Apps ocultas</string>
<string name="hide">Hide</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-pa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,7 @@
<string name="choose_apps">Choose apps</string>
<string name="silenced_notifications_title">Silenced notifications</string>
<string name="hidden_notifications">Hidden notifications</string>
<string name="hidden_apps">Hidden apps</string>
<string name="hide">Hide</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,7 @@
<string name="choose_apps">Choose apps</string>
<string name="silenced_notifications_title">Silenced notifications</string>
<string name="hidden_notifications">Hidden notifications</string>
<string name="hidden_apps">Hidden apps</string>
<string name="hide">Hide</string>

</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preferences_app_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@
android:defaultValue="default"
android:title="@string/user_avatar"/>
</PreferenceCategory>
<PreferenceCategory
android:title="App hiding">
<SwitchPreferenceCompat
android:title="Allow hiding apps"
android:key="enable_app_hiding_grid"/>
<cu.axel.smartdock.preferences.AppChooserMultiplePreference
android:key="hidden_apps_grid"
android:title="@string/hidden_apps"/>
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 6ef28ef

Please sign in to comment.