mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-11 23:04:32 +02:00
implement #98 - hide lock icon when 'hide private space when locked' setting is set
This commit is contained in:
parent
6cd17343fc
commit
c7af387a94
3 changed files with 57 additions and 32 deletions
|
@ -13,6 +13,7 @@ import androidx.appcompat.content.res.AppCompatResources
|
||||||
import de.jrpie.android.launcher.Application
|
import de.jrpie.android.launcher.Application
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.apps.AppFilter
|
import de.jrpie.android.launcher.apps.AppFilter
|
||||||
|
import de.jrpie.android.launcher.apps.hidePrivateSpaceWhenLocked
|
||||||
import de.jrpie.android.launcher.apps.isPrivateSpaceSupported
|
import de.jrpie.android.launcher.apps.isPrivateSpaceSupported
|
||||||
import de.jrpie.android.launcher.apps.togglePrivateSpaceLock
|
import de.jrpie.android.launcher.apps.togglePrivateSpaceLock
|
||||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||||
|
@ -66,7 +67,11 @@ enum class LauncherAction(
|
||||||
R.string.list_other_list_private_space,
|
R.string.list_other_list_private_space,
|
||||||
R.drawable.baseline_security_24,
|
R.drawable.baseline_security_24,
|
||||||
{ context ->
|
{ context ->
|
||||||
openAppsList(context, private = true)
|
if ((context.applicationContext as Application).privateSpaceLocked.value != true
|
||||||
|
|| !hidePrivateSpaceWhenLocked(context)
|
||||||
|
) {
|
||||||
|
openAppsList(context, private = true)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
available = { _ ->
|
available = { _ ->
|
||||||
isPrivateSpaceSupported()
|
isPrivateSpaceSupported()
|
||||||
|
@ -83,31 +88,31 @@ enum class LauncherAction(
|
||||||
"volume_up",
|
"volume_up",
|
||||||
R.string.list_other_volume_up,
|
R.string.list_other_volume_up,
|
||||||
R.drawable.baseline_volume_up_24,
|
R.drawable.baseline_volume_up_24,
|
||||||
{ context -> audioVolumeAdjust(context, true)}
|
{ context -> audioVolumeAdjust(context, true) }
|
||||||
),
|
),
|
||||||
VOLUME_DOWN(
|
VOLUME_DOWN(
|
||||||
"volume_down",
|
"volume_down",
|
||||||
R.string.list_other_volume_down,
|
R.string.list_other_volume_down,
|
||||||
R.drawable.baseline_volume_down_24,
|
R.drawable.baseline_volume_down_24,
|
||||||
{ context -> audioVolumeAdjust(context, false)}
|
{ context -> audioVolumeAdjust(context, false) }
|
||||||
),
|
),
|
||||||
TRACK_PLAY_PAUSE(
|
TRACK_PLAY_PAUSE(
|
||||||
"play_pause_track",
|
"play_pause_track",
|
||||||
R.string.list_other_track_play_pause,
|
R.string.list_other_track_play_pause,
|
||||||
R.drawable.baseline_play_arrow_24,
|
R.drawable.baseline_play_arrow_24,
|
||||||
{ context -> audioManagerPressKey(context, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)}
|
{ context -> audioManagerPressKey(context, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) }
|
||||||
),
|
),
|
||||||
TRACK_NEXT(
|
TRACK_NEXT(
|
||||||
"next_track",
|
"next_track",
|
||||||
R.string.list_other_track_next,
|
R.string.list_other_track_next,
|
||||||
R.drawable.baseline_skip_next_24,
|
R.drawable.baseline_skip_next_24,
|
||||||
{ context -> audioManagerPressKey(context, KeyEvent.KEYCODE_MEDIA_NEXT)}
|
{ context -> audioManagerPressKey(context, KeyEvent.KEYCODE_MEDIA_NEXT) }
|
||||||
),
|
),
|
||||||
TRACK_PREV(
|
TRACK_PREV(
|
||||||
"previous_track",
|
"previous_track",
|
||||||
R.string.list_other_track_previous,
|
R.string.list_other_track_previous,
|
||||||
R.drawable.baseline_skip_previous_24,
|
R.drawable.baseline_skip_previous_24,
|
||||||
{ context -> audioManagerPressKey(context, KeyEvent.KEYCODE_MEDIA_PREVIOUS)}
|
{ context -> audioManagerPressKey(context, KeyEvent.KEYCODE_MEDIA_PREVIOUS) }
|
||||||
),
|
),
|
||||||
EXPAND_NOTIFICATIONS_PANEL(
|
EXPAND_NOTIFICATIONS_PANEL(
|
||||||
"expand_notifications_panel",
|
"expand_notifications_panel",
|
||||||
|
|
|
@ -95,6 +95,12 @@ fun lockPrivateSpace(context: Context, lock: Boolean) {
|
||||||
if (!isPrivateSpaceSupported()) {
|
if (!isPrivateSpaceSupported()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// silently return when trying to unlock but hide when locked is set
|
||||||
|
if (!lock && hidePrivateSpaceWhenLocked(context)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||||
val privateSpaceUser = getPrivateSpaceUser(context) ?: return
|
val privateSpaceUser = getPrivateSpaceUser(context) ?: return
|
||||||
userManager.requestQuietModeEnabled(lock, privateSpaceUser)
|
userManager.requestQuietModeEnabled(lock, privateSpaceUser)
|
||||||
|
@ -116,3 +122,11 @@ fun togglePrivateSpaceLock(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hidePrivateSpaceWhenLocked(context: Context): Boolean {
|
||||||
|
// TODO: perhaps this should be cached
|
||||||
|
|
||||||
|
// https://cs.android.com/android/platform/superproject/main/+/main:packages/apps/Launcher3/src/com/android/launcher3/util/SettingsCache.java;l=61;drc=56bf7ad33bc9d5ed3c18e7abefeec5c177ec75d7
|
||||||
|
val key = "hide_privatespace_entry_point"
|
||||||
|
return Settings.Secure.getInt(context.contentResolver, key, 0) == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.REQUEST_UNINSTALL
|
import de.jrpie.android.launcher.REQUEST_UNINSTALL
|
||||||
import de.jrpie.android.launcher.actions.LauncherAction
|
import de.jrpie.android.launcher.actions.LauncherAction
|
||||||
import de.jrpie.android.launcher.apps.AppFilter
|
import de.jrpie.android.launcher.apps.AppFilter
|
||||||
|
import de.jrpie.android.launcher.apps.hidePrivateSpaceWhenLocked
|
||||||
import de.jrpie.android.launcher.apps.isPrivateSpaceLocked
|
import de.jrpie.android.launcher.apps.isPrivateSpaceLocked
|
||||||
import de.jrpie.android.launcher.apps.isPrivateSpaceSetUp
|
import de.jrpie.android.launcher.apps.isPrivateSpaceSetUp
|
||||||
import de.jrpie.android.launcher.apps.togglePrivateSpaceLock
|
import de.jrpie.android.launcher.apps.togglePrivateSpaceLock
|
||||||
|
@ -34,10 +35,12 @@ import de.jrpie.android.launcher.ui.list.other.ListFragmentOther
|
||||||
|
|
||||||
// TODO: Better solution for this intercommunication functionality (used in list-fragments)
|
// TODO: Better solution for this intercommunication functionality (used in list-fragments)
|
||||||
var intention = ListActivity.ListActivityIntention.VIEW
|
var intention = ListActivity.ListActivityIntention.VIEW
|
||||||
var favoritesVisibility: AppFilter.Companion.AppSetVisibility = AppFilter.Companion.AppSetVisibility.VISIBLE
|
var favoritesVisibility: AppFilter.Companion.AppSetVisibility =
|
||||||
|
AppFilter.Companion.AppSetVisibility.VISIBLE
|
||||||
var privateSpaceVisibility: AppFilter.Companion.AppSetVisibility =
|
var privateSpaceVisibility: AppFilter.Companion.AppSetVisibility =
|
||||||
AppFilter.Companion.AppSetVisibility.VISIBLE
|
AppFilter.Companion.AppSetVisibility.VISIBLE
|
||||||
var hiddenVisibility: AppFilter.Companion.AppSetVisibility = AppFilter.Companion.AppSetVisibility.HIDDEN
|
var hiddenVisibility: AppFilter.Companion.AppSetVisibility =
|
||||||
|
AppFilter.Companion.AppSetVisibility.HIDDEN
|
||||||
var forGesture: String? = null
|
var forGesture: String? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,6 +55,23 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
|
|
||||||
|
|
||||||
private fun updateLockIcon(locked: Boolean) {
|
private fun updateLockIcon(locked: Boolean) {
|
||||||
|
if (
|
||||||
|
// only show lock for VIEW intention
|
||||||
|
(intention != ListActivityIntention.VIEW)
|
||||||
|
// hide lock when private space does not exist
|
||||||
|
|| !isPrivateSpaceSetUp(this)
|
||||||
|
// hide lock when private space apps are hidden from the main list and we are not in the private space list
|
||||||
|
|| (LauncherPreferences.apps().hidePrivateSpaceApps()
|
||||||
|
&& privateSpaceVisibility != AppFilter.Companion.AppSetVisibility.EXCLUSIVE)
|
||||||
|
// hide lock when private space is locked and the hidden when locked setting is set
|
||||||
|
|| (locked && hidePrivateSpaceWhenLocked(this))
|
||||||
|
) {
|
||||||
|
binding.listLock.visibility = View.GONE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.listLock.visibility = View.VISIBLE
|
||||||
|
|
||||||
binding.listLock.setImageDrawable(
|
binding.listLock.setImageDrawable(
|
||||||
AppCompatResources.getDrawable(
|
AppCompatResources.getDrawable(
|
||||||
this,
|
this,
|
||||||
|
@ -74,7 +94,6 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum class ListActivityIntention(val titleResource: Int) {
|
enum class ListActivityIntention(val titleResource: Int) {
|
||||||
VIEW(R.string.list_title_view), /* view list of apps */
|
VIEW(R.string.list_title_view), /* view list of apps */
|
||||||
PICK(R.string.list_title_pick) /* choose app or action to associate to a gesture */
|
PICK(R.string.list_title_pick) /* choose app or action to associate to a gesture */
|
||||||
|
@ -119,20 +138,6 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
LauncherAction.SETTINGS.launch(this@ListActivity)
|
LauncherAction.SETTINGS.launch(this@ListActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.listLock.visibility =
|
|
||||||
if (intention != ListActivityIntention.VIEW) {
|
|
||||||
View.GONE
|
|
||||||
} else if (!isPrivateSpaceSetUp(this)) {
|
|
||||||
View.GONE
|
|
||||||
} else if (LauncherPreferences.apps().hidePrivateSpaceApps()) {
|
|
||||||
if (privateSpaceVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
|
||||||
View.VISIBLE
|
|
||||||
} else {
|
|
||||||
View.GONE
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
if (privateSpaceVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
if (privateSpaceVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
||||||
isPrivateSpaceSetUp(this, showToast = true, launchSettings = true)
|
isPrivateSpaceSetUp(this, showToast = true, launchSettings = true)
|
||||||
|
@ -200,15 +205,16 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
fun updateTitle() {
|
fun updateTitle() {
|
||||||
var titleResource = intention.titleResource
|
var titleResource = intention.titleResource
|
||||||
if (intention == ListActivityIntention.VIEW) {
|
if (intention == ListActivityIntention.VIEW) {
|
||||||
titleResource = if (hiddenVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
titleResource =
|
||||||
R.string.list_title_hidden
|
if (hiddenVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
||||||
} else if (privateSpaceVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
R.string.list_title_hidden
|
||||||
R.string.list_title_private_space
|
} else if (privateSpaceVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
||||||
} else if (favoritesVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
R.string.list_title_private_space
|
||||||
R.string.list_title_favorite
|
} else if (favoritesVisibility == AppFilter.Companion.AppSetVisibility.EXCLUSIVE) {
|
||||||
} else {
|
R.string.list_title_favorite
|
||||||
R.string.list_title_view
|
} else {
|
||||||
}
|
R.string.list_title_view
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.listHeading.text = getString(titleResource)
|
binding.listHeading.text = getString(titleResource)
|
||||||
|
|
Loading…
Add table
Reference in a new issue