Skip to content

Commit

Permalink
fix some build errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRezaMousavi committed Sep 10, 2024
1 parent a0a2e86 commit e4a1a69
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 108 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
Expand Down Expand Up @@ -103,8 +105,10 @@ ksp {
}

composeCompiler {
enableStrongSkippingMode = true
enableNonSkippingGroupOptimization = true
featureFlags.addAll(
ComposeFeatureFlag.StrongSkipping,
ComposeFeatureFlag.OptimizeNonSkippingGroups
)

if (project.findProperty("enableComposeCompilerReports") == "true") {
val dest = layout.buildDirectory.dir("compose_metrics")
Expand Down
82 changes: 7 additions & 75 deletions app/schemas/app.banafsh.android.DatabaseInitializer/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "fee48b09836f856f36971192954afe4e",
"identityHash": "9e031eabcd85865fe7bfd89f6fbd7a8e",
"entities": [
{
"tableName": "Song",
Expand Down Expand Up @@ -505,7 +505,7 @@
},
{
"tableName": "QueuedSong",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`itemId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `position` INTEGER, `id` TEXT NOT NULL, `title` TEXT NOT NULL, `artistsText` TEXT, `durationText` TEXT, `thumbnailUrl` TEXT, `dateModified` INTEGER, `likedAt` INTEGER, `totalPlayTimeMs` INTEGER NOT NULL, `loudnessBoost` REAL, `blacklisted` INTEGER NOT NULL DEFAULT false, `explicit` INTEGER NOT NULL DEFAULT false, `path` TEXT)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`itemId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `songId` TEXT NOT NULL, `position` INTEGER)",
"fields": [
{
"fieldPath": "itemId",
Expand All @@ -514,83 +514,15 @@
"notNull": true
},
{
"fieldPath": "position",
"columnName": "position",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "song.id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "song.title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "song.artistsText",
"columnName": "artistsText",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "song.durationText",
"columnName": "durationText",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "song.thumbnailUrl",
"columnName": "thumbnailUrl",
"fieldPath": "songId",
"columnName": "songId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "song.dateModified",
"columnName": "dateModified",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "song.likedAt",
"columnName": "likedAt",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "song.totalPlayTimeMs",
"columnName": "totalPlayTimeMs",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "song.loudnessBoost",
"columnName": "loudnessBoost",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "song.blacklisted",
"columnName": "blacklisted",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "false"
},
{
"fieldPath": "song.explicit",
"columnName": "explicit",
"fieldPath": "position",
"columnName": "position",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "false"
},
{
"fieldPath": "song.path",
"columnName": "path",
"affinity": "TEXT",
"notNull": false
}
],
Expand Down Expand Up @@ -839,7 +771,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'fee48b09836f856f36971192954afe4e')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9e031eabcd85865fe7bfd89f6fbd7a8e')"
]
}
}
5 changes: 1 addition & 4 deletions app/src/main/kotlin/app/banafsh/android/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
Expand All @@ -31,8 +30,6 @@ import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
Expand Down Expand Up @@ -64,6 +61,7 @@ import app.banafsh.android.lib.compose.persist.PersistMap
import app.banafsh.android.lib.compose.preferences.PreferencesHolder
import app.banafsh.android.lib.core.ui.Dimensions
import app.banafsh.android.lib.core.ui.LocalAppearance
import app.banafsh.android.lib.core.ui.LocalRippleTheme
import app.banafsh.android.lib.core.ui.SystemBarAppearance
import app.banafsh.android.lib.core.ui.appearance
import app.banafsh.android.lib.core.ui.rippleTheme
Expand Down Expand Up @@ -235,7 +233,6 @@ class MainActivity : ComponentActivity(), MonetColorsChangedListener {
}

CompositionLocalProvider(
LocalIndication provides rememberRipple(),
LocalRippleTheme provides rippleTheme(),
LocalShimmerTheme provides shimmerTheme(),
LocalPlayerServiceBinder provides vm.binder,
Expand Down
188 changes: 186 additions & 2 deletions app/src/main/kotlin/app/banafsh/android/lib/core/ui/Ripple.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package app.banafsh.android.lib.core.ui

import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance

@Composable
fun rippleTheme(appearance: Appearance = LocalAppearance.current) = remember(
Expand All @@ -25,3 +28,184 @@ fun rippleTheme(appearance: Appearance = LocalAppearance.current) = remember(
)
}
}

interface RippleTheme {
/**
* @return the default ripple color at the call site's position in the hierarchy.
* This color will be used when a color is not explicitly set in the ripple itself.
* @see defaultRippleColor
*/
@Composable
fun defaultColor(): Color

/**
* @return the [RippleAlpha] used to calculate the alpha for the ripple depending on the
* [Interaction] for a given component. This will be set as the alpha channel for
* [defaultColor] or the color explicitly provided to the ripple.
* @see defaultRippleAlpha
*/
@Composable
fun rippleAlpha(): RippleAlpha

companion object {
/**
* Represents the default color that will be used for a ripple if a color has not been
* explicitly set on the ripple instance.
*
* @param contentColor the color of content (text or iconography) in the component that
* contains the ripple.
* @param lightTheme whether the theme is light or not
*/
fun defaultRippleColor(
contentColor: Color,
lightTheme: Boolean
): Color {
val contentLuminance = contentColor.luminance()
// If we are on a colored surface (typically indicated by low luminance content), the
// ripple color should be white.
return if (!lightTheme && contentLuminance < 0.5) {
Color.White
// Otherwise use contentColor
} else {
contentColor
}
}

/**
* Represents the default [RippleAlpha] that will be used for a ripple to indicate different
* states.
*
* @param contentColor the color of content (text or iconography) in the component that
* contains the ripple.
* @param lightTheme whether the theme is light or not
*/
fun defaultRippleAlpha(contentColor: Color, lightTheme: Boolean): RippleAlpha {
return when {
lightTheme -> {
if (contentColor.luminance() > 0.5) {
LightThemeHighContrastRippleAlpha
} else {
LightThemeLowContrastRippleAlpha
}
}

else -> {
DarkThemeRippleAlpha
}
}
}
}
}

/**
* RippleAlpha defines the alpha of the ripple / state layer for different [Interaction]s.
*
* On Android, because the press ripple is drawn using the framework's RippleDrawable, there are
* constraints / different behaviours for the actual press alpha used on different API versions.
* Note that this *only* affects [pressedAlpha] - the other values are guaranteed to be consistent,
* as they do not rely on framework code. Specifically:
*
* API 21-27: The actual ripple is split into two 'layers', with the alpha applied to both layers,
* so there is no uniform 'alpha'.
* API 28-32: The ripple is just one layer, but the alpha is clamped to a maximum of 0.5f - it is
* not possible to have a fully opaque ripple.
* API 33: There is a bug where the ripple is clamped to a *minimum* of 0.5, instead of a maximum
* like before - this should be resolved in future versions.
*
* @property draggedAlpha the alpha used when the ripple is dragged
* @property focusedAlpha the alpha used when the ripple is focused
* @property hoveredAlpha the alpha used when the ripple is hovered
* @property pressedAlpha the alpha used when the ripple is pressed
*/
@Immutable
class RippleAlpha(
val draggedAlpha: Float,
val focusedAlpha: Float,
val hoveredAlpha: Float,
val pressedAlpha: Float
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is RippleAlpha) return false

if (draggedAlpha != other.draggedAlpha) return false
if (focusedAlpha != other.focusedAlpha) return false
if (hoveredAlpha != other.hoveredAlpha) return false
if (pressedAlpha != other.pressedAlpha) return false

return true
}

override fun hashCode(): Int {
var result = draggedAlpha.hashCode()
result = 31 * result + focusedAlpha.hashCode()
result = 31 * result + hoveredAlpha.hashCode()
result = 31 * result + pressedAlpha.hashCode()
return result
}

override fun toString(): String = "RippleAlpha(draggedAlpha=$draggedAlpha, focusedAlpha=$focusedAlpha, " +
"hoveredAlpha=$hoveredAlpha, pressedAlpha=$pressedAlpha)"
}

val LocalRippleTheme: ProvidableCompositionLocal<RippleTheme> =
staticCompositionLocalOf { DebugRippleTheme }

/**
* Alpha values for high luminance content in a light theme.
*
* This content will typically be placed on colored surfaces, so it is important that the
* contrast here is higher to meet accessibility standards, and increase legibility.
*
* These levels are typically used for text / iconography in primary colored tabs /
* bottom navigation / etc.
*/
private val LightThemeHighContrastRippleAlpha = RippleAlpha(
pressedAlpha = 0.24f,
focusedAlpha = 0.24f,
draggedAlpha = 0.16f,
hoveredAlpha = 0.08f
)

/**
* Alpha levels for low luminance content in a light theme.
*
* This content will typically be placed on grayscale surfaces, so the contrast here can be lower
* without sacrificing accessibility and legibility.
*
* These levels are typically used for body text on the main surface (white in light theme, grey
* in dark theme) and text / iconography in surface colored tabs / bottom navigation / etc.
*/
private val LightThemeLowContrastRippleAlpha = RippleAlpha(
pressedAlpha = 0.12f,
focusedAlpha = 0.12f,
draggedAlpha = 0.08f,
hoveredAlpha = 0.04f
)

/**
* Alpha levels for all content in a dark theme.
*/
private val DarkThemeRippleAlpha = RippleAlpha(
pressedAlpha = 0.10f,
focusedAlpha = 0.12f,
draggedAlpha = 0.08f,
hoveredAlpha = 0.04f
)

/**
* Simple debug indication that will assume black content color and light theme. You should
* instead provide your own theme with meaningful values - this exists as an alternative to
* crashing if no theme is provided.
*/
@Immutable
private object DebugRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = RippleTheme.defaultRippleColor(Color.Black, lightTheme = true)

@Composable
override fun rippleAlpha(): RippleAlpha = RippleTheme.defaultRippleAlpha(
Color.Black,
lightTheme = true
)
}
3 changes: 1 addition & 2 deletions app/src/main/kotlin/app/banafsh/android/models/QueuedSong.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package app.banafsh.android.models

import androidx.compose.runtime.Immutable
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey

@Immutable
@Entity
class QueuedSong(
@PrimaryKey(autoGenerate = true) val itemId: Long = 0,
@Embedded val song: Song,
val songId: String,
var position: Long?
)
Loading

0 comments on commit e4a1a69

Please sign in to comment.