Skip to content

Commit

Permalink
feat(android): add quick presets
Browse files Browse the repository at this point in the history
This adds an option to show a notification with buttons for predefined
ambient sound mode, noise canceling mode, or equalizer profiles.

The number of quick presets is limited to two due to the limit of three
buttons on a notification. If more than two quick presets are needed in
the future, a custom notification layout may be necessary.
  • Loading branch information
Oppzippy committed Jul 6, 2023
1 parent 402ec9f commit e5b8c5f
Show file tree
Hide file tree
Showing 37 changed files with 987 additions and 138 deletions.
88 changes: 88 additions & 0 deletions android/app/schemas/com.oppzippy.openscq30.room.AppDatabase/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "ee376b5d213217c100cea5afb6fb0b09",
"entities": [
{
"tableName": "equalizer_custom_profile",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `values` BLOB NOT NULL, PRIMARY KEY(`name`))",
"fields": [
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "values",
"columnName": "values",
"affinity": "BLOB",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"name"
]
},
"indices": [
{
"name": "index_equalizer_custom_profile_values",
"unique": true,
"columnNames": [
"values"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_equalizer_custom_profile_values` ON `${TABLE_NAME}` (`values`)"
}
],
"foreignKeys": []
},
{
"tableName": "quick_preset",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `ambientSoundMode` TEXT, `noiseCancelingMode` TEXT, `equalizerProfileName` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "ambientSoundMode",
"columnName": "ambientSoundMode",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "noiseCancelingMode",
"columnName": "noiseCancelingMode",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "equalizerProfileName",
"columnName": "equalizerProfileName",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"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, 'ee376b5d213217c100cea5afb6fb0b09')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.performClick
import com.oppzippy.openscq30.lib.AmbientSoundMode
import com.oppzippy.openscq30.lib.NoiseCancelingMode
import com.oppzippy.openscq30.ui.devicesettings.composables.SoundModeSettings
import com.oppzippy.openscq30.ui.soundmode.SoundModeSettings
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.junit4.MockKRule
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.oppzippy.openscq30.features.quickpresets.storage

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.oppzippy.openscq30.lib.AmbientSoundMode
import com.oppzippy.openscq30.lib.NoiseCancelingMode

@Entity(
tableName = "quick_preset",
)
data class QuickPreset(
@PrimaryKey val id: Int,
val ambientSoundMode: AmbientSoundMode? = null,
val noiseCancelingMode: NoiseCancelingMode? = null,
val equalizerProfileName: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.oppzippy.openscq30.features.quickpresets.storage

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface QuickPresetDao {
@Query("SELECT * FROM quick_preset")
suspend fun getAll(): List<QuickPreset>

@Query("SELECT * FROM quick_preset WHERE id = :id")
suspend fun get(id: Int): QuickPreset?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(customProfile: QuickPreset)

@Query("DELETE FROM quick_preset WHERE id = :id")
suspend fun delete(id: Int)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.oppzippy.openscq30.features.quickpresets.storage

import com.oppzippy.openscq30.room.AppDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object QuickPresetDaoModule {
@Provides
@Singleton
fun provideQuickPresetDao(database: AppDatabase): QuickPresetDao {
return database.quickPresetDao()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class DeviceConnectionManager @Inject constructor(
}
}

fun setSoundMode(ambientSoundMode: AmbientSoundMode, noiseCancelingMode: NoiseCancelingMode) {
device?.setSoundMode(ambientSoundMode, noiseCancelingMode)
}

fun setAmbientSoundMode(ambientSoundMode: AmbientSoundMode) {
device?.state?.noiseCancelingMode()?.let { noiseCancelingMode ->
device?.setSoundMode(ambientSoundMode, noiseCancelingMode)
Expand Down
Loading

0 comments on commit e5b8c5f

Please sign in to comment.