7 changed files with 259 additions and 3 deletions
@ -0,0 +1,54 @@ |
|||
/* |
|||
* ************************************************************************ |
|||
* EqualizerDao.kt |
|||
* ************************************************************************* |
|||
* Copyright © 2024 VLC authors and VideoLAN |
|||
* Author: Nicolas POMEPUY |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
* ************************************************************************** |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
package org.videolan.vlc.database |
|||
|
|||
import androidx.room.Dao |
|||
import androidx.room.Delete |
|||
import androidx.room.Insert |
|||
import androidx.room.OnConflictStrategy |
|||
import androidx.room.Query |
|||
import androidx.room.Transaction |
|||
import kotlinx.coroutines.flow.Flow |
|||
import org.videolan.vlc.mediadb.models.EqualizerBand |
|||
import org.videolan.vlc.mediadb.models.EqualizerEntry |
|||
import org.videolan.vlc.mediadb.models.EqualizerWithBands |
|||
|
|||
@Dao |
|||
interface EqualizerDao { |
|||
@Insert(onConflict = OnConflictStrategy.REPLACE) |
|||
fun insert(equalizerEntry: EqualizerEntry): Long |
|||
|
|||
@Insert(onConflict = OnConflictStrategy.REPLACE) |
|||
fun insertBands(equalizerBand: EqualizerBand) |
|||
|
|||
@Delete |
|||
fun delete(equalizerEntry: EqualizerEntry) |
|||
|
|||
@Transaction |
|||
@Query("SELECT * FROM equalizer_entry") |
|||
fun getAllEqualizerEntries(): Flow<List<EqualizerWithBands>> |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
/* |
|||
* ************************************************************************ |
|||
* EqualizerBand.kt |
|||
* ************************************************************************* |
|||
* Copyright © 2024 VLC authors and VideoLAN |
|||
* Author: Nicolas POMEPUY |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
* ************************************************************************** |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
package org.videolan.vlc.mediadb.models |
|||
|
|||
import androidx.room.ColumnInfo |
|||
import androidx.room.Entity |
|||
import androidx.room.ForeignKey |
|||
|
|||
@Entity( |
|||
tableName = "equalizer_band", |
|||
primaryKeys = ["index", "equalizer_entry"], |
|||
foreignKeys = [ForeignKey(entity = EqualizerEntry::class, |
|||
parentColumns = ["id"], |
|||
childColumns = ["equalizer_entry"], |
|||
onDelete = ForeignKey.CASCADE)] |
|||
) |
|||
data class EqualizerBand( |
|||
@ColumnInfo(name = "index") |
|||
val index: Int, |
|||
@ColumnInfo(name = "value") |
|||
val bandValue: Float, |
|||
) { |
|||
@ColumnInfo(name = "equalizer_entry") |
|||
var equalizerEntry: Long = 0 |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
/* |
|||
* ************************************************************************ |
|||
* EqualizerEntry.kt |
|||
* ************************************************************************* |
|||
* Copyright © 2024 VLC authors and VideoLAN |
|||
* Author: Nicolas POMEPUY |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
* ************************************************************************** |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
package org.videolan.vlc.mediadb.models |
|||
|
|||
import androidx.room.ColumnInfo |
|||
import androidx.room.Entity |
|||
import androidx.room.Index |
|||
import androidx.room.PrimaryKey |
|||
|
|||
@Entity(tableName = "equalizer_entry", indices = [Index(value = ["name"], unique = true)]) |
|||
data class EqualizerEntry( |
|||
|
|||
@ColumnInfo(name = "name") |
|||
val name: String, |
|||
@ColumnInfo(name = "preamp") |
|||
val preamp: Float, |
|||
@ColumnInfo(name = "preset_index") |
|||
val presetIndex: Int = -1, |
|||
@ColumnInfo(name = "is_disabled") |
|||
val isDisabled: Boolean = false, |
|||
) { |
|||
@PrimaryKey(autoGenerate = true) |
|||
var id: Long = 0 |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/* |
|||
* ************************************************************************ |
|||
* EqualizerWithBands.kt |
|||
* ************************************************************************* |
|||
* Copyright © 2024 VLC authors and VideoLAN |
|||
* Author: Nicolas POMEPUY |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
* ************************************************************************** |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
package org.videolan.vlc.mediadb.models |
|||
|
|||
import androidx.room.Embedded |
|||
import androidx.room.Relation |
|||
|
|||
data class EqualizerWithBands( |
|||
@Embedded val equalizerEntry: EqualizerEntry, |
|||
@Relation( |
|||
parentColumn = "id", |
|||
entityColumn = "equalizer_entry" |
|||
) |
|||
val bands: List<EqualizerBand> |
|||
) |
|||
@ -0,0 +1,56 @@ |
|||
/* |
|||
* ************************************************************************ |
|||
* EqualizerRepository.kt |
|||
* ************************************************************************* |
|||
* Copyright © 2024 VLC authors and VideoLAN |
|||
* Author: Nicolas POMEPUY |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
* ************************************************************************** |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
package org.videolan.vlc.repository |
|||
|
|||
import android.content.Context |
|||
import org.videolan.tools.CoroutineContextProvider |
|||
import org.videolan.tools.SingletonHolder |
|||
import org.videolan.vlc.database.EqualizerDao |
|||
import org.videolan.vlc.database.MediaDatabase |
|||
import org.videolan.vlc.mediadb.models.EqualizerEntry |
|||
import org.videolan.vlc.mediadb.models.EqualizerWithBands |
|||
|
|||
class EqualizerRepository(private val equalizerDao: EqualizerDao, private val coroutineContextProvider: CoroutineContextProvider = CoroutineContextProvider()) { |
|||
|
|||
|
|||
val equalizerEntries by lazy { |
|||
equalizerDao.getAllEqualizerEntries() |
|||
} |
|||
|
|||
fun addOrUpdateEqualizer(equalizer:EqualizerWithBands) { |
|||
val id = equalizerDao.insert(equalizer.equalizerEntry) |
|||
equalizer.bands.forEach { |
|||
it.equalizerEntry = id |
|||
equalizerDao.insertBands(it) |
|||
} |
|||
} |
|||
|
|||
fun delete(equalizerEntry: EqualizerEntry) { |
|||
equalizerDao.delete(equalizerEntry) |
|||
} |
|||
|
|||
|
|||
companion object : SingletonHolder<EqualizerRepository, Context>({ EqualizerRepository(MediaDatabase.getInstance(it).equalizerDao()) }) |
|||
} |
|||
Loading…
Reference in new issue