Skip to content

Commit fc9287f

Browse files
Feat: Enhance Private Space UI and Logic
This commit introduces several improvements to the Private Space feature: - **New Private Space FAB**: A Floating Action Button (FAB) is added to `fragment_home.xml` and managed in `HomeFragment.kt` to toggle the Private Space lock. Its visibility is dependent on Private Space being set up. The icon changes to reflect the locked/unlocked state. - **Toast Behavior Change**: Toasts for Private Space lock/unlock actions are now suppressed in `HomeFragment.kt` and `SettingsFragment.kt` when toggling the lock. The toast in `PrivateSpaceManager.kt` is now conditional based on the `showToast` parameter. - **Receiver Logic Update**: `PrivateSpaceReceiver.kt` now listens for `Intent.ACTION_USER_UNLOCKED` instead of `Intent.ACTION_PROFILE_AVAILABLE`. It will only show an "unlocked" toast if mLauncher is the default launcher. - **Settings Visibility**: The "TogglePrivateSpace" action and the Private Spaces settings item in `SettingsFragment.kt` now check `isPrivateSpaceSetUp()` instead of `isPrivateSpaceSupported()` to determine visibility, ensuring these options only appear if Private Space has been configured. - **Layout Adjustment**: The new `privateLayout` containing the FAB is included in the list of views whose margins are adjusted in `HomeFragment.kt`.
1 parent 9bf749c commit fc9287f

File tree

5 files changed

+69
-20
lines changed

5 files changed

+69
-20
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/helper/receivers/PrivateSpaceReceiver.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import android.content.Intent
66
import com.github.droidworksstudio.common.getLocalizedString
77
import com.github.droidworksstudio.common.showLongToast
88
import com.github.droidworksstudio.mlauncher.R
9+
import com.github.droidworksstudio.mlauncher.helper.ismlauncherDefault
910

1011
class PrivateSpaceReceiver : BroadcastReceiver() {
1112
override fun onReceive(context: Context, intent: Intent?) {
12-
// Check if the received action is for managed profile availability
13-
if (intent?.action == Intent.ACTION_PROFILE_AVAILABLE) {
14-
// Handle the event when the managed profile is available
15-
context.showLongToast(getLocalizedString(R.string.toast_private_space_unlocked))
13+
if (intent == null) return
14+
15+
if (intent.action == Intent.ACTION_USER_UNLOCKED) {
16+
// Check if mLauncher is the default launcher
17+
if (ismlauncherDefault(context)) {
18+
// Notify the user that mLauncher is now accessible in the private space
19+
val message = getLocalizedString(R.string.toast_private_space_unlocked)
20+
context.showLongToast(message)
21+
}
1622
}
1723
}
1824
}

app/src/main/java/com/github/droidworksstudio/mlauncher/helper/utils/PrivateSpaceManager.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ class PrivateSpaceManager(private val context: Context) {
126126
val lock = isPrivateSpaceLocked()
127127
lockPrivateSpace(!lock)
128128

129-
Handler(Looper.getMainLooper()).post {
130-
if (isPrivateSpaceLocked() == !lock) {
131-
context.showLongToast(getLocalizedString(R.string.toast_private_space_locked))
129+
if (showToast) {
130+
Handler(Looper.getMainLooper()).post {
131+
if (isPrivateSpaceLocked() == !lock) {
132+
context.showLongToast(getLocalizedString(R.string.toast_private_space_locked))
133+
}
132134
}
133135
}
134136
}

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/HomeFragment.kt

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
705705
Action.ShowNotification -> expandNotificationDrawer(requireContext())
706706
Action.LockScreen -> lockPhone()
707707
Action.TogglePrivateSpace -> PrivateSpaceManager(requireContext()).togglePrivateSpaceLock(
708-
showToast = true,
709-
launchSettings = true
708+
showToast = false,
709+
launchSettings = false
710710
)
711711

712712
Action.ShowAppList -> showAppList(AppDrawerFlag.LaunchApp, includeHiddenApps = false)
@@ -850,18 +850,39 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
850850

851851
private fun adjustTextViewMargins() {
852852
binding.apply {
853-
val homeAppsLayout = homeAppsLayout
854-
val homeScreenPager = homeScreenPager
855-
val totalScreenTime = totalScreenTime
856-
val setDefaultLauncher = setDefaultLauncher
857-
val fabLayout = fabLayout
853+
854+
privateLayout.apply {
855+
// Set visibility
856+
isVisible = PrivateSpaceManager(requireContext()).isPrivateSpaceSetUp()
857+
858+
// Initial icon
859+
fun updatePrivateFabIcon() {
860+
val isLocked = PrivateSpaceManager(requireContext()).isPrivateSpaceLocked()
861+
val iconRes = if (isLocked) R.drawable.private_profile_on
862+
else R.drawable.private_profile_off
863+
privateFab.setImageResource(iconRes)
864+
}
865+
866+
updatePrivateFabIcon() // set initial icon
867+
868+
privateFab.setOnClickListener {
869+
// Toggle lock
870+
PrivateSpaceManager(requireContext()).togglePrivateSpaceLock(
871+
showToast = false,
872+
launchSettings = false
873+
)
874+
// Update icon after toggle
875+
updatePrivateFabIcon()
876+
}
877+
}
858878

859879
val views = listOf(
860880
setDefaultLauncher,
861881
totalScreenTime,
862882
homeScreenPager,
863883
fabLayout,
864-
homeAppsLayout
884+
homeAppsLayout,
885+
privateLayout
865886
)
866887

867888
// Check if device is using gesture navigation or 3-button navigation

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/SettingsFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class SettingsFragment : BaseFragment() {
299299

300300
// Filter out 'TogglePrivateSpace' if private space is not supported
301301
val filteredActions =
302-
if (!PrivateSpaceManager(requireContext()).isPrivateSpaceSupported() || !ismlauncherDefault(requireContext())) {
302+
if (!PrivateSpaceManager(requireContext()).isPrivateSpaceSetUp() || !ismlauncherDefault(requireContext())) {
303303
actions.filter { it != Action.TogglePrivateSpace }
304304
} else {
305305
actions
@@ -411,19 +411,19 @@ class SettingsFragment : BaseFragment() {
411411
)
412412

413413
// 5. Private Spaces (if supported)
414-
if (PrivateSpaceManager(context).isPrivateSpaceSupported()) {
414+
if (PrivateSpaceManager(context).isPrivateSpaceSetUp()) {
415415
SettingsHomeItem(
416416
title = getLocalizedString(R.string.private_space, getLocalizedString(setPrivateSpacesStatus)),
417417
imageVector = ImageVector.vectorResource(id = setPrivateSpacesIcon),
418418
titleFontSize = titleFontSize,
419419
descriptionFontSize = descriptionFontSize,
420420
iconSize = iconSize,
421421
onClick = {
422-
if (PrivateSpaceManager(context).isPrivateSpaceSetUp(showToast = true, launchSettings = false)) {
422+
if (PrivateSpaceManager(context).isPrivateSpaceSetUp(showToast = false, launchSettings = false)) {
423423

424424
PrivateSpaceManager(context).togglePrivateSpaceLock(
425-
showToast = true,
426-
launchSettings = true
425+
showToast = false,
426+
launchSettings = false
427427
)
428428
toggledPrivateSpaces = !toggledPrivateSpaces
429429
}

app/src/main/res/layout/fragment_home.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@
177177
android:text="@string/advanced_settings_set_as_default_launcher"
178178
android:visibility="gone" />
179179

180+
<LinearLayout
181+
android:id="@+id/privateLayout"
182+
android:layout_width="match_parent"
183+
android:layout_height="wrap_content"
184+
android:layout_gravity="bottom|center_horizontal"
185+
android:gravity="center_horizontal"
186+
android:orientation="horizontal"
187+
android:padding="32dp"
188+
android:visibility="gone">
189+
190+
<ImageView
191+
android:id="@+id/privateFab"
192+
android:layout_width="26dp"
193+
android:layout_height="26dp"
194+
android:layout_margin="8dp"
195+
android:contentDescription="@string/show"
196+
android:elevation="6dp"
197+
android:src="@drawable/private_profile_on" />
198+
</LinearLayout>
199+
180200
<LinearLayout
181201
android:id="@+id/fabLayout"
182202
android:layout_width="match_parent"

0 commit comments

Comments
 (0)