music: connect update tracker to service

This commit is contained in:
Alexander Capehart 2025-01-01 13:55:07 -07:00
parent 04e81916f7
commit 2401f9031f
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 90 additions and 22 deletions

View file

@ -18,16 +18,11 @@
package org.oxycblt.auxio.music
import android.content.Context
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.oxycblt.musikr.cache.StoredCache
import org.oxycblt.musikr.playlist.db.StoredPlaylists
@Module
@InstallIn(SingletonComponent::class)
@ -36,15 +31,3 @@ interface MusicModule {
@Binds fun settings(musicSettingsImpl: MusicSettingsImpl): MusicSettings
}
@Module
@InstallIn(SingletonComponent::class)
class MusikrShimModule {
@Singleton
@Provides
fun storedCache(@ApplicationContext context: Context) = StoredCache.from(context)
@Singleton
@Provides
fun storedPlaylists(@ApplicationContext context: Context) = StoredPlaylists.from(context)
}

View file

@ -32,26 +32,29 @@ import org.oxycblt.auxio.ForegroundServiceNotification
import org.oxycblt.auxio.music.IndexingState
import org.oxycblt.auxio.music.MusicRepository
import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.auxio.music.shim.UpdateTrackerFactory
import org.oxycblt.auxio.playback.state.PlaybackStateManager
import org.oxycblt.auxio.util.getSystemServiceCompat
import org.oxycblt.musikr.MusicParent
import org.oxycblt.musikr.fs.MusicLocation
import org.oxycblt.musikr.track.UpdateTracker
import timber.log.Timber as L
class IndexingHolder
private constructor(
private val workerContext: Context,
workerContext: Context,
private val foregroundListener: ForegroundListener,
private val playbackManager: PlaybackStateManager,
private val musicRepository: MusicRepository,
private val musicSettings: MusicSettings,
private val imageLoader: ImageLoader,
private val updateTracker: UpdateTracker
updateTrackerFactory: UpdateTrackerFactory
) :
MusicRepository.IndexingWorker,
MusicRepository.IndexingListener,
MusicRepository.UpdateListener,
MusicSettings.Listener {
MusicSettings.Listener,
UpdateTracker.Callback {
class Factory
@Inject
constructor(
@ -59,7 +62,7 @@ private constructor(
private val musicRepository: MusicRepository,
private val musicSettings: MusicSettings,
private val imageLoader: ImageLoader,
private val updateTracker: UpdateTracker
private val updateTrackerFactory: UpdateTrackerFactory
) {
fun create(context: Context, listener: ForegroundListener) =
IndexingHolder(
@ -69,7 +72,7 @@ private constructor(
musicRepository,
musicSettings,
imageLoader,
updateTracker)
updateTrackerFactory)
}
private val indexJob = Job()
@ -82,6 +85,7 @@ private constructor(
.getSystemServiceCompat(PowerManager::class)
.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":IndexingComponent")
private val updateTracker = updateTrackerFactory.create(this)
fun attach() {
musicSettings.registerListener(this)
@ -164,6 +168,12 @@ private constructor(
}
}
override fun onUpdate(location: MusicLocation) {
if (musicSettings.shouldBeObserving) {
musicRepository.requestIndex(true)
}
}
override fun onMusicLocationsChanged() {
super.onMusicLocationsChanged()
updateTracker.track(musicSettings.musicLocations)

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2025 Auxio Project
* MusikrShimModule.kt is part of Auxio.
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.shim
import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.oxycblt.musikr.cache.StoredCache
import org.oxycblt.musikr.playlist.db.StoredPlaylists
@Module
@InstallIn(SingletonComponent::class)
class MusikrShimModule {
@Singleton
@Provides
fun storedCache(@ApplicationContext context: Context) = StoredCache.from(context)
@Singleton
@Provides
fun storedPlaylists(@ApplicationContext context: Context) = StoredPlaylists.from(context)
@Provides
fun updateTrackerFactory(@ApplicationContext context: Context): UpdateTrackerFactory =
UpdateTrackerFactoryImpl(context)
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2025 Auxio Project
* UpdateTrackerFactory.kt is part of Auxio.
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.shim
import android.content.Context
import org.oxycblt.musikr.track.UpdateTracker
interface UpdateTrackerFactory {
fun create(callback: UpdateTracker.Callback): UpdateTracker
}
class UpdateTrackerFactoryImpl(private val context: Context) : UpdateTrackerFactory {
override fun create(callback: UpdateTracker.Callback) = UpdateTracker.from(context, callback)
}