Notification count support for Notification Dots (#2587)

* Add notification dot counter to preferences

Co-authored-by: Daria Hamrah Paytakht <info@dariarnd.ir>

* Add counter support to notification dots

Co-authored-by: Daria Hamrah Paytakht <info@dariarnd.ir>

Co-authored-by: Daria Hamrah Paytakht <info@dariarnd.ir>
This commit is contained in:
YASAN
2022-05-16 23:17:02 +07:00
committed by GitHub
co-authored by Daria Hamrah Paytakht
parent 37c4bf7544
commit 074a102ded
9 changed files with 39 additions and 9 deletions
+1
View File
@@ -44,6 +44,7 @@
<bool name="config_default_dark_status_bar">false</bool>
<bool name="config_default_dock_search_bar">true</bool>
<bool name="config_default_show_notification_count">false</bool>
<bool name="config_default_themed_hotseat_qsb">false</bool>
<bool name="config_default_dock_search_bar_force_website">false</bool>
<bool name="config_default_rounded_widgets">true</bool>
+1
View File
@@ -225,6 +225,7 @@
<string name="always_open_website_description">Open search providers website even if their app is installed.</string>
<string name="search_provider">Search Provider</string>
<string name="status_bar_label">Status Bar</string>
<string name="show_notification_count">Show Notification Count</string>
<string name="icon_picker_load_failed">Couldnt load more icons.</string>
<string name="reset_custom_icons">Reset Custom Icons</string>
<string name="reset_custom_icons_confirmation">All custom icons will be reset. Do you want to continue?</string>
@@ -78,6 +78,12 @@ class PreferenceManager2(private val context: Context) : PreferenceManager {
save = { it.toString() },
)
val showNotificationCount = preference(
key = booleanPreferencesKey(name = "show_notification_count"),
defaultValue = context.resources.getBoolean(R.bool.config_default_show_notification_count),
onSet = { reloadHelper.reloadGrid() },
)
val themedHotseatQsb = preference(
key = booleanPreferencesKey(name = "themed_hotseat_qsb"),
defaultValue = context.resources.getBoolean(R.bool.config_default_themed_hotseat_qsb),
@@ -21,6 +21,8 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavGraphBuilder
import app.lawnchair.preferences.getAdapter
@@ -52,7 +54,6 @@ fun GeneralPreferences() {
label = stringResource(id = R.string.home_screen_rotation_label),
description = stringResource(id = R.string.home_screen_rotaton_description),
)
NotificationDotsPreference()
NavigationActionPreference(
label = stringResource(id = R.string.icon_pack),
destination = subRoute(name = GeneralRoutes.ICON_PACK),
@@ -67,6 +68,18 @@ fun GeneralPreferences() {
)
}
}
PreferenceGroup(heading = stringResource(id = R.string.notification_dots)) {
val context = LocalContext.current
val enabled by remember { notificationDotsEnabled(context) }.collectAsState(initial = false)
val serviceEnabled = notificationServiceEnabled()
NotificationDotsPreference(enabled = enabled, serviceEnabled = serviceEnabled)
if (enabled && serviceEnabled) {
SwitchPreference(
adapter = prefs2.showNotificationCount.getAdapter(),
label = stringResource(id = R.string.show_notification_count),
)
}
}
PreferenceGroup(heading = stringResource(id = R.string.colors)) {
ThemePreference()
AccentColorPreference()
@@ -48,11 +48,9 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
@Composable
fun NotificationDotsPreference() {
fun NotificationDotsPreference(enabled: Boolean, serviceEnabled: Boolean) {
val bottomSheetHandler = bottomSheetHandler
val context = LocalContext.current
val enabled by remember { notificationDotsEnabled(context) }.collectAsState(initial = false)
val serviceEnabled = notificationServiceEnabled()
val showWarning = enabled && !serviceEnabled
val summary = when {
showWarning -> R.string.missing_notification_access_description
@@ -571,7 +571,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
final int scrollX = getScrollX();
final int scrollY = getScrollY();
canvas.translate(scrollX, scrollY);
mDotRenderer.draw(canvas, mDotParams);
mDotRenderer.draw(canvas, mDotParams, mDotInfo == null ? -1 : mDotInfo.getNotificationCount());
canvas.translate(-scrollX, -scrollY);
}
}
+13 -2
View File
@@ -31,8 +31,10 @@ import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.DisplayMetrics;
import android.view.Surface;
import androidx.core.content.res.ResourcesCompat;
import com.android.launcher3.CellLayout.ContainerType;
import com.android.launcher3.DevicePaddings.DevicePadding;
@@ -487,11 +489,20 @@ public class DeviceProfile {
flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
R.dimen.drag_flingToDeleteMinVelocity);
// Check if notification dots should show the notification count
boolean showNotificationCount = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getShowNotificationCount());
// Load the default font to use on notification dots
Typeface typeface = null;
if (showNotificationCount) {
typeface = ResourcesCompat.getFont(context, R.font.inter_regular);
}
// This is done last, after iconSizePx is calculated above.
Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE, showNotificationCount, typeface);
mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE, showNotificationCount, typeface);
}
private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
@@ -640,7 +640,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
// If we are animating to the accepting state, animate the dot out.
mDotParams.scale = Math.max(0, mDotScale - mBackground.getScaleProgress());
mDotParams.color = mBackground.getDotColor();
mDotRenderer.draw(canvas, mDotParams);
mDotRenderer.draw(canvas, mDotParams, mDotInfo == null ? -1 : mDotInfo.getNotificationCount());
}
}