2020-07-20 19:05:48 +00:00
|
|
|
package code.name.monkey.retromusic
|
|
|
|
|
2020-08-21 11:43:51 +00:00
|
|
|
import androidx.room.Room
|
2020-08-23 08:01:42 +00:00
|
|
|
import androidx.room.RoomDatabase
|
|
|
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
2021-09-08 18:30:20 +00:00
|
|
|
import code.name.monkey.retromusic.auto.AutoMusicProvider
|
2020-08-31 12:30:07 +00:00
|
|
|
import code.name.monkey.retromusic.db.BlackListStoreDao
|
2020-08-23 08:01:42 +00:00
|
|
|
import code.name.monkey.retromusic.db.BlackListStoreEntity
|
2020-08-20 09:52:38 +00:00
|
|
|
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
2020-08-21 11:43:51 +00:00
|
|
|
import code.name.monkey.retromusic.db.RetroDatabase
|
2020-08-13 17:08:37 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
2020-08-11 18:29:44 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.albums.AlbumDetailsViewModel
|
|
|
|
import code.name.monkey.retromusic.fragments.artists.ArtistDetailsViewModel
|
|
|
|
import code.name.monkey.retromusic.fragments.genres.GenreDetailsViewModel
|
|
|
|
import code.name.monkey.retromusic.fragments.playlists.PlaylistDetailsViewModel
|
2020-07-20 19:05:48 +00:00
|
|
|
import code.name.monkey.retromusic.model.Genre
|
2020-09-24 12:09:05 +00:00
|
|
|
import code.name.monkey.retromusic.network.provideDefaultCache
|
|
|
|
import code.name.monkey.retromusic.network.provideLastFmRest
|
|
|
|
import code.name.monkey.retromusic.network.provideLastFmRetrofit
|
|
|
|
import code.name.monkey.retromusic.network.provideOkHttp
|
2020-08-13 17:08:37 +00:00
|
|
|
import code.name.monkey.retromusic.repository.*
|
2020-08-23 08:01:42 +00:00
|
|
|
import code.name.monkey.retromusic.util.FilePathUtil
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
import kotlinx.coroutines.launch
|
2020-08-13 17:08:37 +00:00
|
|
|
import org.koin.android.ext.koin.androidContext
|
2020-07-25 20:22:37 +00:00
|
|
|
import org.koin.androidx.viewmodel.dsl.viewModel
|
|
|
|
import org.koin.dsl.bind
|
2020-07-20 19:05:48 +00:00
|
|
|
import org.koin.dsl.module
|
|
|
|
|
2020-09-06 17:56:39 +00:00
|
|
|
val networkModule = module {
|
|
|
|
|
|
|
|
factory {
|
|
|
|
provideDefaultCache()
|
|
|
|
}
|
|
|
|
factory {
|
|
|
|
provideOkHttp(get(), get())
|
|
|
|
}
|
|
|
|
single {
|
|
|
|
provideLastFmRetrofit(get())
|
|
|
|
}
|
|
|
|
single {
|
|
|
|
provideLastFmRest(get())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 11:43:51 +00:00
|
|
|
private val roomModule = module {
|
2020-08-23 08:01:42 +00:00
|
|
|
|
2020-08-21 11:43:51 +00:00
|
|
|
single {
|
|
|
|
Room.databaseBuilder(androidContext(), RetroDatabase::class.java, "playlist.db")
|
|
|
|
.allowMainThreadQueries()
|
2020-08-23 08:01:42 +00:00
|
|
|
.addCallback(object : RoomDatabase.Callback() {
|
|
|
|
override fun onOpen(db: SupportSQLiteDatabase) {
|
|
|
|
super.onOpen(db)
|
|
|
|
GlobalScope.launch(IO) {
|
|
|
|
FilePathUtil.blacklistFilePaths().map {
|
2020-08-31 12:30:07 +00:00
|
|
|
get<BlackListStoreDao>().insertBlacklistPath(BlackListStoreEntity(it))
|
2020-08-23 08:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-08-21 11:43:51 +00:00
|
|
|
.fallbackToDestructiveMigration()
|
|
|
|
.build()
|
|
|
|
}
|
2020-09-10 19:22:10 +00:00
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().lyricsDao()
|
|
|
|
}
|
2020-08-21 11:43:51 +00:00
|
|
|
|
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().playlistDao()
|
|
|
|
}
|
|
|
|
|
2020-08-31 12:30:07 +00:00
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().blackListStore()
|
|
|
|
}
|
|
|
|
|
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().playCountDao()
|
|
|
|
}
|
2020-09-06 11:03:24 +00:00
|
|
|
|
2020-09-06 10:47:06 +00:00
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().historyDao()
|
|
|
|
}
|
2020-08-31 12:30:07 +00:00
|
|
|
|
2020-08-21 11:43:51 +00:00
|
|
|
single {
|
2020-09-10 19:22:10 +00:00
|
|
|
RealRoomRepository(get(), get(), get(), get(), get())
|
2020-08-31 12:30:07 +00:00
|
|
|
} bind RoomRepository::class
|
2020-08-21 11:43:51 +00:00
|
|
|
}
|
2021-09-08 18:30:20 +00:00
|
|
|
private val autoModule = module {
|
|
|
|
single {
|
|
|
|
AutoMusicProvider(androidContext(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 06:49:08 +00:00
|
|
|
private val mainModule = module {
|
|
|
|
single {
|
|
|
|
androidContext().contentResolver
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 20:22:37 +00:00
|
|
|
private val dataModule = module {
|
|
|
|
single {
|
2020-09-06 17:56:39 +00:00
|
|
|
RealRepository(
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
2020-09-24 10:53:23 +00:00
|
|
|
get(),
|
2020-09-06 17:56:39 +00:00
|
|
|
)
|
2020-07-25 20:22:37 +00:00
|
|
|
} bind Repository::class
|
2020-08-13 17:08:37 +00:00
|
|
|
|
|
|
|
single {
|
|
|
|
RealSongRepository(get())
|
|
|
|
} bind SongRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealGenreRepository(get(), get())
|
|
|
|
} bind GenreRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealAlbumRepository(get())
|
|
|
|
} bind AlbumRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealArtistRepository(get(), get())
|
|
|
|
} bind ArtistRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealPlaylistRepository(get())
|
|
|
|
} bind PlaylistRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealTopPlayedRepository(get(), get(), get(), get())
|
|
|
|
} bind TopPlayedRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealLastAddedRepository(
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get()
|
|
|
|
)
|
|
|
|
} bind LastAddedRepository::class
|
|
|
|
|
|
|
|
single {
|
|
|
|
RealSearchRepository(
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get()
|
|
|
|
)
|
|
|
|
}
|
2020-09-24 10:53:23 +00:00
|
|
|
single {
|
|
|
|
RealLocalDataRepository(get())
|
|
|
|
} bind LocalDataRepository::class
|
2020-07-25 20:22:37 +00:00
|
|
|
}
|
2020-07-20 19:05:48 +00:00
|
|
|
|
2020-07-25 20:22:37 +00:00
|
|
|
private val viewModules = module {
|
2020-07-20 19:05:48 +00:00
|
|
|
|
|
|
|
viewModel {
|
|
|
|
LibraryViewModel(get())
|
|
|
|
}
|
|
|
|
|
2020-09-17 21:25:41 +00:00
|
|
|
viewModel { (albumId: Long) ->
|
2020-08-11 18:29:44 +00:00
|
|
|
AlbumDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
albumId
|
|
|
|
)
|
2020-07-20 19:05:48 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 18:30:20 +00:00
|
|
|
viewModel { (artistId: Long?, artistName: String?) ->
|
2020-08-11 18:29:44 +00:00
|
|
|
ArtistDetailsViewModel(
|
|
|
|
get(),
|
2021-09-08 18:30:20 +00:00
|
|
|
artistId,
|
|
|
|
artistName
|
2020-08-11 18:29:44 +00:00
|
|
|
)
|
2020-07-20 19:05:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 09:52:38 +00:00
|
|
|
viewModel { (playlist: PlaylistWithSongs) ->
|
2020-08-11 18:29:44 +00:00
|
|
|
PlaylistDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
playlist
|
|
|
|
)
|
2020-07-20 19:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
viewModel { (genre: Genre) ->
|
2020-08-11 18:29:44 +00:00
|
|
|
GenreDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
genre
|
|
|
|
)
|
2020-07-20 19:05:48 +00:00
|
|
|
}
|
2020-07-25 20:22:37 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 18:30:20 +00:00
|
|
|
val appModules = listOf(mainModule, dataModule, autoModule, viewModules, networkModule, roomModule)
|