Skip to content

Commit 34af09d

Browse files
committed
Merge branch 'feature/1980-notification-panel-constraint' into develop
2 parents 7ad0623 + dad0126 commit 34af09d

15 files changed

Lines changed: 737 additions & 310 deletions

File tree

CHANGELOG.md

Lines changed: 623 additions & 310 deletions
Large diffs are not rendered by default.

base/src/main/java/io/github/sds100/keymapper/base/constraints/ChooseConstraintViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ class ChooseConstraintViewModel @Inject constructor(
277277
ConstraintId.LOCK_SCREEN_NOT_SHOWING ->
278278
returnResult.emit(ConstraintData.LockScreenNotShowing)
279279

280+
ConstraintId.NOTIFICATION_PANEL_SHOWING ->
281+
returnResult.emit(ConstraintData.NotificationPanelShowing)
282+
283+
ConstraintId.NOTIFICATION_PANEL_NOT_SHOWING ->
284+
returnResult.emit(ConstraintData.NotificationPanelNotShowing)
285+
280286
ConstraintId.TIME -> {
281287
timeConstraintState = ConstraintData.Time(
282288
startHour = 0,

base/src/main/java/io/github/sds100/keymapper/base/constraints/Constraint.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ sealed class ConstraintData {
219219
override val id: ConstraintId = ConstraintId.HINGE_OPEN
220220
}
221221

222+
@Serializable
223+
data object NotificationPanelShowing : ConstraintData() {
224+
override val id: ConstraintId = ConstraintId.NOTIFICATION_PANEL_SHOWING
225+
}
226+
227+
@Serializable
228+
data object NotificationPanelNotShowing : ConstraintData() {
229+
override val id: ConstraintId = ConstraintId.NOTIFICATION_PANEL_NOT_SHOWING
230+
}
231+
222232
@Serializable
223233
data class Time(
224234
val startHour: Int,
@@ -405,6 +415,10 @@ object ConstraintEntityMapper {
405415
ConstraintEntity.HINGE_CLOSED -> ConstraintData.HingeClosed
406416
ConstraintEntity.HINGE_OPEN -> ConstraintData.HingeOpen
407417

418+
ConstraintEntity.NOTIFICATION_PANEL_SHOWING -> ConstraintData.NotificationPanelShowing
419+
ConstraintEntity.NOTIFICATION_PANEL_NOT_SHOWING ->
420+
ConstraintData.NotificationPanelNotShowing
421+
408422
ConstraintEntity.TIME -> {
409423
val startTime =
410424
entity.extras.getData(ConstraintEntity.EXTRA_START_TIME).valueOrNull()!!
@@ -725,6 +739,16 @@ object ConstraintEntityMapper {
725739
ConstraintEntity.HINGE_OPEN,
726740
)
727741

742+
is ConstraintData.NotificationPanelShowing -> ConstraintEntity(
743+
uid = constraint.uid,
744+
ConstraintEntity.NOTIFICATION_PANEL_SHOWING,
745+
)
746+
747+
is ConstraintData.NotificationPanelNotShowing -> ConstraintEntity(
748+
uid = constraint.uid,
749+
ConstraintEntity.NOTIFICATION_PANEL_NOT_SHOWING,
750+
)
751+
728752
is ConstraintData.Time -> ConstraintEntity(
729753
uid = constraint.uid,
730754
type = ConstraintEntity.TIME,

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintDependency.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ enum class ConstraintDependency {
1919
RINGER_MODE,
2020
CHARGING_STATE,
2121
HINGE_STATE,
22+
NOTIFICATION_PANEL_STATE,
2223
}

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintId.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ enum class ConstraintId {
6464
HINGE_CLOSED,
6565
HINGE_OPEN,
6666

67+
NOTIFICATION_PANEL_SHOWING,
68+
NOTIFICATION_PANEL_NOT_SHOWING,
69+
6770
TIME,
6871
}

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintSnapshot.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class LazyConstraintSnapshot(
7979
lockScreenAdapter.isLockScreenShowing()
8080
}
8181

82+
private val isNotificationShadeExpanded: Boolean by lazy {
83+
accessibilityService.isNotificationShadeExpanded.firstBlocking()
84+
}
85+
8286
private val localTime = LocalTime.now()
8387

8488
private fun isMediaPlaying(): Boolean {
@@ -205,6 +209,9 @@ class LazyConstraintSnapshot(
205209
!isLockscreenShowing ||
206210
appInForeground != "com.android.systemui"
207211

212+
is ConstraintData.NotificationPanelShowing -> isNotificationShadeExpanded
213+
is ConstraintData.NotificationPanelNotShowing -> !isNotificationShadeExpanded
214+
208215
is ConstraintData.Time ->
209216
if (constraint.data.startTime.isAfter(constraint.data.endTime)) {
210217
localTime.isAfter(constraint.data.startTime) ||

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintUiHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ class ConstraintUiHelper(
177177
is ConstraintData.LockScreenNotShowing -> getString(
178178
R.string.constraint_lock_screen_not_showing,
179179
)
180+
is ConstraintData.NotificationPanelShowing ->
181+
getString(R.string.constraint_notification_panel_showing)
182+
is ConstraintData.NotificationPanelNotShowing ->
183+
getString(R.string.constraint_notification_panel_not_showing)
180184
is ConstraintData.Time -> getString(
181185
R.string.constraint_time_formatted,
182186
arrayOf(

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintUtils.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ object ConstraintUtils {
117117
ConstraintId.HINGE_OPEN,
118118
-> ConstraintCategory.DEVICE
119119

120+
ConstraintId.NOTIFICATION_PANEL_SHOWING,
121+
ConstraintId.NOTIFICATION_PANEL_NOT_SHOWING,
122+
-> ConstraintCategory.DISPLAY
123+
120124
ConstraintId.TIME -> ConstraintCategory.TIME
121125
}
122126

@@ -200,6 +204,12 @@ object ConstraintUtils {
200204
Icons.Outlined.ScreenLockPortrait,
201205
)
202206
ConstraintId.LOCK_SCREEN_NOT_SHOWING -> ComposeIconInfo.Vector(Icons.Outlined.LockOpen)
207+
208+
ConstraintId.NOTIFICATION_PANEL_SHOWING ->
209+
ComposeIconInfo.Vector(Icons.Outlined.Notifications)
210+
ConstraintId.NOTIFICATION_PANEL_NOT_SHOWING ->
211+
ComposeIconInfo.Vector(Icons.Outlined.NotificationsOff)
212+
203213
ConstraintId.TIME -> ComposeIconInfo.Vector(Icons.Outlined.Timer)
204214
}
205215

@@ -254,6 +264,10 @@ object ConstraintUtils {
254264
ConstraintId.HINGE_OPEN -> R.string.constraint_hinge_open
255265
ConstraintId.LOCK_SCREEN_SHOWING -> R.string.constraint_lock_screen_showing
256266
ConstraintId.LOCK_SCREEN_NOT_SHOWING -> R.string.constraint_lock_screen_not_showing
267+
ConstraintId.NOTIFICATION_PANEL_SHOWING ->
268+
R.string.constraint_notification_panel_showing
269+
ConstraintId.NOTIFICATION_PANEL_NOT_SHOWING ->
270+
R.string.constraint_notification_panel_not_showing
257271
ConstraintId.TIME -> R.string.constraint_time
258272
}
259273
}

base/src/main/java/io/github/sds100/keymapper/base/constraints/DetectConstraintsUseCase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class DetectConstraintsUseCaseImpl @AssistedInject constructor(
105105
}
106106
ConstraintDependency.KEYBOARD_VISIBLE ->
107107
accessibilityService.isInputMethodVisible.map { dependency }
108+
ConstraintDependency.NOTIFICATION_PANEL_STATE ->
109+
accessibilityService.isNotificationShadeExpanded.map { dependency }
108110
}
109111
}
110112
}

base/src/main/java/io/github/sds100/keymapper/base/sorting/comparators/KeyMapConstraintsComparator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class KeyMapConstraintsComparator(
144144
is ConstraintData.PhysicalOrientation -> Success(
145145
constraint.data.physicalOrientation.toString(),
146146
)
147+
ConstraintData.NotificationPanelShowing -> Success("")
148+
ConstraintData.NotificationPanelNotShowing -> Success("")
147149
}
148150
}
149151
}

0 commit comments

Comments
 (0)