music: connect update tracker to service
This commit is contained in:
parent
04e81916f7
commit
2401f9031f
4 changed files with 90 additions and 22 deletions
|
@ -18,16 +18,11 @@
|
||||||
|
|
||||||
package org.oxycblt.auxio.music
|
package org.oxycblt.auxio.music
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import dagger.Binds
|
import dagger.Binds
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import org.oxycblt.musikr.cache.StoredCache
|
|
||||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
|
@ -36,15 +31,3 @@ interface MusicModule {
|
||||||
|
|
||||||
@Binds fun settings(musicSettingsImpl: MusicSettingsImpl): MusicSettings
|
@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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,26 +32,29 @@ import org.oxycblt.auxio.ForegroundServiceNotification
|
||||||
import org.oxycblt.auxio.music.IndexingState
|
import org.oxycblt.auxio.music.IndexingState
|
||||||
import org.oxycblt.auxio.music.MusicRepository
|
import org.oxycblt.auxio.music.MusicRepository
|
||||||
import org.oxycblt.auxio.music.MusicSettings
|
import org.oxycblt.auxio.music.MusicSettings
|
||||||
|
import org.oxycblt.auxio.music.shim.UpdateTrackerFactory
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||||
import org.oxycblt.auxio.util.getSystemServiceCompat
|
import org.oxycblt.auxio.util.getSystemServiceCompat
|
||||||
import org.oxycblt.musikr.MusicParent
|
import org.oxycblt.musikr.MusicParent
|
||||||
|
import org.oxycblt.musikr.fs.MusicLocation
|
||||||
import org.oxycblt.musikr.track.UpdateTracker
|
import org.oxycblt.musikr.track.UpdateTracker
|
||||||
import timber.log.Timber as L
|
import timber.log.Timber as L
|
||||||
|
|
||||||
class IndexingHolder
|
class IndexingHolder
|
||||||
private constructor(
|
private constructor(
|
||||||
private val workerContext: Context,
|
workerContext: Context,
|
||||||
private val foregroundListener: ForegroundListener,
|
private val foregroundListener: ForegroundListener,
|
||||||
private val playbackManager: PlaybackStateManager,
|
private val playbackManager: PlaybackStateManager,
|
||||||
private val musicRepository: MusicRepository,
|
private val musicRepository: MusicRepository,
|
||||||
private val musicSettings: MusicSettings,
|
private val musicSettings: MusicSettings,
|
||||||
private val imageLoader: ImageLoader,
|
private val imageLoader: ImageLoader,
|
||||||
private val updateTracker: UpdateTracker
|
updateTrackerFactory: UpdateTrackerFactory
|
||||||
) :
|
) :
|
||||||
MusicRepository.IndexingWorker,
|
MusicRepository.IndexingWorker,
|
||||||
MusicRepository.IndexingListener,
|
MusicRepository.IndexingListener,
|
||||||
MusicRepository.UpdateListener,
|
MusicRepository.UpdateListener,
|
||||||
MusicSettings.Listener {
|
MusicSettings.Listener,
|
||||||
|
UpdateTracker.Callback {
|
||||||
class Factory
|
class Factory
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -59,7 +62,7 @@ private constructor(
|
||||||
private val musicRepository: MusicRepository,
|
private val musicRepository: MusicRepository,
|
||||||
private val musicSettings: MusicSettings,
|
private val musicSettings: MusicSettings,
|
||||||
private val imageLoader: ImageLoader,
|
private val imageLoader: ImageLoader,
|
||||||
private val updateTracker: UpdateTracker
|
private val updateTrackerFactory: UpdateTrackerFactory
|
||||||
) {
|
) {
|
||||||
fun create(context: Context, listener: ForegroundListener) =
|
fun create(context: Context, listener: ForegroundListener) =
|
||||||
IndexingHolder(
|
IndexingHolder(
|
||||||
|
@ -69,7 +72,7 @@ private constructor(
|
||||||
musicRepository,
|
musicRepository,
|
||||||
musicSettings,
|
musicSettings,
|
||||||
imageLoader,
|
imageLoader,
|
||||||
updateTracker)
|
updateTrackerFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val indexJob = Job()
|
private val indexJob = Job()
|
||||||
|
@ -82,6 +85,7 @@ private constructor(
|
||||||
.getSystemServiceCompat(PowerManager::class)
|
.getSystemServiceCompat(PowerManager::class)
|
||||||
.newWakeLock(
|
.newWakeLock(
|
||||||
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":IndexingComponent")
|
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":IndexingComponent")
|
||||||
|
private val updateTracker = updateTrackerFactory.create(this)
|
||||||
|
|
||||||
fun attach() {
|
fun attach() {
|
||||||
musicSettings.registerListener(this)
|
musicSettings.registerListener(this)
|
||||||
|
@ -164,6 +168,12 @@ private constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onUpdate(location: MusicLocation) {
|
||||||
|
if (musicSettings.shouldBeObserving) {
|
||||||
|
musicRepository.requestIndex(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onMusicLocationsChanged() {
|
override fun onMusicLocationsChanged() {
|
||||||
super.onMusicLocationsChanged()
|
super.onMusicLocationsChanged()
|
||||||
updateTracker.track(musicSettings.musicLocations)
|
updateTracker.track(musicSettings.musicLocations)
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in a new issue