Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/src/main/java/com/d4viddf/hyperbridge/data/AppPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,17 @@ class AppPreferences(context: Context) {

private val SHOW_PERMANENT_ISLAND = "show_permanent_island"
private val PERMANENT_ISLAND_WIDTH = "permanent_island_width"
private val HIDE_PERMANENT_ISLAND_LANDSCAPE = "hide_permanent_island_landscape"

val isPermanentIslandEnabledFlow: Flow<Boolean> = dao.getSettingFlow(SHOW_PERMANENT_ISLAND)
.map { it?.toBoolean() ?: false }

val permanentIslandWidthFlow: Flow<Int> = dao.getSettingFlow(PERMANENT_ISLAND_WIDTH)
.map { it?.toIntOrNull() ?: 0 }

val hidePermanentIslandLandscapeFlow: Flow<Boolean> = dao.getSettingFlow(HIDE_PERMANENT_ISLAND_LANDSCAPE)
.map { it?.toBoolean() ?: false }

suspend fun setPermanentIslandEnabled(value: Boolean) {
save(SHOW_PERMANENT_ISLAND, value.toString())
}
Expand All @@ -523,6 +527,14 @@ class AppPreferences(context: Context) {
save(PERMANENT_ISLAND_WIDTH, value.toString())
}

suspend fun setHidePermanentIslandLandscape(value: Boolean) {
save(HIDE_PERMANENT_ISLAND_LANDSCAPE, value.toString())
}

fun hidePermanentIslandLandscapeSync(): Boolean {
return memoryCache[HIDE_PERMANENT_ISLAND_LANDSCAPE]?.toBoolean() ?: false
}

// ========================================================================
// SYNCHRONOUS CACHE GETTERS
// ========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,23 @@ class NotificationReaderService : NotificationListenerService() {
}
}

private fun logStateChange(isLandscape: Boolean) {
val orientation = if (isLandscape) "Landscape" else "Portrait"
val isIslandExhibited = activeIslands.isNotEmpty() || activeWidgets.isNotEmpty() || nativeIslands.isNotEmpty() || permanentIslandManager.isIslandActive()
val islandState = if (isIslandExhibited) "Showing Island" else "No Island"
Log.d(TAG, "State: $orientation | $islandState")
}

private fun updatePermanentIsland() {
permanentIslandManager.onActiveNotificationsChanged(activeIslands.size + activeWidgets.size, nativeIslands.isNotEmpty())
val isLandscape = resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE
logStateChange(isLandscape)
}

override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
super.onConfigurationChanged(newConfig)
permanentIslandManager.onOrientationChanged()
logStateChange(newConfig.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE)
}

// =========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class PermanentIslandManager(
private var isPermanentIslandEnabled = false
private var isIslandActive = false
private var currentRealNotifications = 0

fun isIslandActive(): Boolean = isIslandActive
private var hasNativeIsland = false
private var currentWidth = 0
private var isHideInLandscapeEnabled = false

init {
scope.launch {
Expand All @@ -40,6 +43,14 @@ class PermanentIslandManager(
}
}
}
scope.launch {
preferences.hidePermanentIslandLandscapeFlow.collectLatest { hide ->
if (isHideInLandscapeEnabled != hide) {
isHideInLandscapeEnabled = hide
updateState()
}
}
}
scope.launch {
preferences.permanentIslandWidthFlow.collectLatest { width ->
if (currentWidth != width) {
Expand All @@ -58,8 +69,19 @@ class PermanentIslandManager(
updateState()
}

fun onOrientationChanged() {
updateState()
}
private fun updateState() {
if (isPermanentIslandEnabled && currentRealNotifications == 0 && !hasNativeIsland) {
val isLandscape = context.resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE
val shouldShow = isPermanentIslandEnabled &&
currentRealNotifications == 0 &&
!hasNativeIsland &&
!(isHideInLandscapeEnabled && isLandscape)

Log.d(TAG, "updateState: shouldShow=$shouldShow, isLandscape=$isLandscape, isHideInLandscapeEnabled=$isHideInLandscapeEnabled")

if (shouldShow) {
if (!isIslandActive) {
dispatchPermanentIsland()
isIslandActive = true
Expand All @@ -71,7 +93,6 @@ class PermanentIslandManager(
}
}
}

@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
private fun dispatchPermanentIsland() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ fun PermanentIslandConfigScreen(

val isEnabled by prefs.isPermanentIslandEnabledFlow.collectAsState(initial = false)
val islandWidth by prefs.permanentIslandWidthFlow.collectAsState(initial = 0)
val hideInLandscape by prefs.hidePermanentIslandLandscapeFlow.collectAsState(initial = false)

PermanentIslandConfigContent(
isEnabled = isEnabled,
islandWidth = islandWidth,
hideInLandscape = hideInLandscape,
onEnabledChange = { checked ->
scope.launch {
prefs.setPermanentIslandEnabled(checked)
Expand All @@ -62,6 +64,11 @@ fun PermanentIslandConfigScreen(
prefs.setPermanentIslandWidth(width)
}
},
onHideInLandscapeChange = { hide ->
scope.launch {
prefs.setHidePermanentIslandLandscape(hide)
}
},
onBack = onBack
)
}
Expand All @@ -71,8 +78,10 @@ fun PermanentIslandConfigScreen(
fun PermanentIslandConfigContent(
isEnabled: Boolean,
islandWidth: Int,
hideInLandscape: Boolean,
onEnabledChange: (Boolean) -> Unit,
onWidthChange: (Int) -> Unit,
onHideInLandscapeChange: (Boolean) -> Unit,
onBack: () -> Unit
) {
var sliderValue by androidx.compose.runtime.remember { androidx.compose.runtime.mutableFloatStateOf(0f) }
Expand Down Expand Up @@ -105,8 +114,6 @@ fun PermanentIslandConfigContent(
PermanentIslandPreview(islandWidthValue = if (isDragging) sliderValue.toInt() else islandWidth)

Spacer(Modifier.height(24.dp))



Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),
Expand All @@ -125,7 +132,6 @@ fun PermanentIslandConfigContent(
style = MaterialTheme.typography.titleMedium,
fontWeight = androidx.compose.ui.text.font.FontWeight.Medium
)

}
Switch(
checked = isEnabled,
Expand All @@ -152,6 +158,24 @@ fun PermanentIslandConfigContent(
},
valueRange = 0f..20f
)
Spacer(Modifier.height(16.dp))
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = stringResource(R.string.permanent_island_hide_landscape),
style = MaterialTheme.typography.titleSmall,
fontWeight = androidx.compose.ui.text.font.FontWeight.Medium
)
}
Switch(
checked = hideInLandscape,
onCheckedChange = onHideInLandscapeChange
)
}
}
}
}
Expand All @@ -161,7 +185,6 @@ fun PermanentIslandConfigContent(
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)

}
}
}
Expand All @@ -173,9 +196,13 @@ fun PermanentIslandConfigScreenPreview() {
PermanentIslandConfigContent(
isEnabled = true,
islandWidth = 10,
hideInLandscape = false,
onEnabledChange = {},
onWidthChange = {},
onHideInLandscapeChange = {},
onBack = {}
)
}
}


1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="permanent_island_desc">Mantenha a Ilha Dinâmica permanentemente visível na tela quando não houver notificações ativas.</string>
<string name="permanent_island_screen_desc">Quando ativada, uma Ilha Dinâmica vazia será exibida permanentemente na sua tela. Ela se ocultará automaticamente quando notificações reais chegarem e reaparecerá quando todas as notificações forem apagadas. Ela não ficará visível na sua área de notificações.</string>
<string name="permanent_island_width">Largura da ilha</string>
<string name="permanent_island_hide_landscape">Ocultar na Horizontal</string>
<string name="group_about">Sobre</string>
<string name="developer">Desenvolvedor</string>
<string name="developer_subtitle">Visite d4viddf.com</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<string name="permanent_island_desc">Keep the Dynamic Island permanently visible on screen when there are no active notifications.</string>
<string name="permanent_island_screen_desc">When enabled, an empty Dynamic Island will be shown permanently on your screen. It will automatically hide when real notifications arrive and reappear when all notifications are cleared. It will not be visible in your notification shade.</string>
<string name="permanent_island_width">Island Width</string>
<string name="permanent_island_hide_landscape">Hide in Landscape</string>

<string name="group_about">About</string>
<string name="developer">Developer</string>
Expand Down