2020-07-21 00:35:48 +05:30
|
|
|
package code.name.monkey.retromusic
|
|
|
|
|
2020-08-21 17:13:51 +05:30
|
|
|
import androidx.room.Room
|
2020-08-23 13:31:42 +05:30
|
|
|
import androidx.room.RoomDatabase
|
|
|
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
2020-08-31 18:00:07 +05:30
|
|
|
import code.name.monkey.retromusic.db.BlackListStoreDao
|
2020-08-23 13:31:42 +05:30
|
|
|
import code.name.monkey.retromusic.db.BlackListStoreEntity
|
2020-08-20 15:22:38 +05:30
|
|
|
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
2020-08-21 17:13:51 +05:30
|
|
|
import code.name.monkey.retromusic.db.RetroDatabase
|
2020-08-13 22:38:37 +05:30
|
|
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
2020-08-11 23:59:44 +05:30
|
|
|
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-08-12 00:28:14 +05:30
|
|
|
import code.name.monkey.retromusic.fragments.search.SearchViewModel
|
2020-07-21 00:35:48 +05:30
|
|
|
import code.name.monkey.retromusic.model.Genre
|
2020-09-06 23:26:39 +05:30
|
|
|
import code.name.monkey.retromusic.network.*
|
2020-08-13 22:38:37 +05:30
|
|
|
import code.name.monkey.retromusic.repository.*
|
2020-08-23 13:31:42 +05:30
|
|
|
import code.name.monkey.retromusic.util.FilePathUtil
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
import kotlinx.coroutines.launch
|
2020-08-13 22:38:37 +05:30
|
|
|
import org.koin.android.ext.koin.androidContext
|
2020-07-26 01:52:37 +05:30
|
|
|
import org.koin.androidx.viewmodel.dsl.viewModel
|
|
|
|
import org.koin.dsl.bind
|
2020-07-21 00:35:48 +05:30
|
|
|
import org.koin.dsl.module
|
|
|
|
|
2020-09-06 23:26:39 +05:30
|
|
|
val networkModule = module {
|
|
|
|
|
|
|
|
factory {
|
|
|
|
provideDefaultCache()
|
|
|
|
}
|
|
|
|
factory {
|
|
|
|
provideOkHttp(get(), get())
|
|
|
|
}
|
|
|
|
single {
|
|
|
|
provideLastFmRetrofit(get())
|
|
|
|
}
|
|
|
|
single {
|
|
|
|
provideDeezerRest(get())
|
|
|
|
}
|
|
|
|
single {
|
|
|
|
provideLastFmRest(get())
|
|
|
|
}
|
|
|
|
single {
|
|
|
|
provideLyrics(get())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 17:13:51 +05:30
|
|
|
private val roomModule = module {
|
2020-08-23 13:31:42 +05:30
|
|
|
|
2020-08-21 17:13:51 +05:30
|
|
|
single {
|
|
|
|
Room.databaseBuilder(androidContext(), RetroDatabase::class.java, "playlist.db")
|
|
|
|
.allowMainThreadQueries()
|
2020-08-23 13:31:42 +05:30
|
|
|
.addCallback(object : RoomDatabase.Callback() {
|
|
|
|
override fun onOpen(db: SupportSQLiteDatabase) {
|
|
|
|
super.onOpen(db)
|
|
|
|
GlobalScope.launch(IO) {
|
|
|
|
FilePathUtil.blacklistFilePaths().map {
|
2020-08-31 18:00:07 +05:30
|
|
|
get<BlackListStoreDao>().insertBlacklistPath(BlackListStoreEntity(it))
|
2020-08-23 13:31:42 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-08-21 17:13:51 +05:30
|
|
|
.fallbackToDestructiveMigration()
|
|
|
|
.build()
|
|
|
|
}
|
2020-09-11 00:52:10 +05:30
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().lyricsDao()
|
|
|
|
}
|
2020-08-21 17:13:51 +05:30
|
|
|
|
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().playlistDao()
|
|
|
|
}
|
|
|
|
|
2020-08-31 18:00:07 +05:30
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().blackListStore()
|
|
|
|
}
|
|
|
|
|
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().playCountDao()
|
|
|
|
}
|
2020-09-06 16:33:24 +05:30
|
|
|
|
2020-09-06 16:17:06 +05:30
|
|
|
factory {
|
|
|
|
get<RetroDatabase>().historyDao()
|
|
|
|
}
|
2020-08-31 18:00:07 +05:30
|
|
|
|
2020-08-21 17:13:51 +05:30
|
|
|
single {
|
2020-09-11 00:52:10 +05:30
|
|
|
RealRoomRepository(get(), get(), get(), get(), get())
|
2020-08-31 18:00:07 +05:30
|
|
|
} bind RoomRepository::class
|
2020-08-21 17:13:51 +05:30
|
|
|
}
|
2020-08-20 12:19:08 +05:30
|
|
|
private val mainModule = module {
|
|
|
|
single {
|
|
|
|
androidContext().contentResolver
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-07-26 01:52:37 +05:30
|
|
|
private val dataModule = module {
|
|
|
|
single {
|
2020-09-06 23:26:39 +05:30
|
|
|
RealRepository(
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get(),
|
|
|
|
get()
|
|
|
|
)
|
2020-07-26 01:52:37 +05:30
|
|
|
} bind Repository::class
|
2020-08-13 22:38:37 +05:30
|
|
|
|
|
|
|
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-07-26 01:52:37 +05:30
|
|
|
}
|
2020-07-21 00:35:48 +05:30
|
|
|
|
2020-07-26 01:52:37 +05:30
|
|
|
private val viewModules = module {
|
2020-07-21 00:35:48 +05:30
|
|
|
|
|
|
|
viewModel {
|
|
|
|
LibraryViewModel(get())
|
|
|
|
}
|
|
|
|
|
2020-09-17 23:25:41 +02:00
|
|
|
viewModel { (albumId: Long) ->
|
2020-08-11 23:59:44 +05:30
|
|
|
AlbumDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
albumId
|
|
|
|
)
|
2020-07-21 00:35:48 +05:30
|
|
|
}
|
|
|
|
|
2020-09-17 23:25:41 +02:00
|
|
|
viewModel { (artistId: Long) ->
|
2020-08-11 23:59:44 +05:30
|
|
|
ArtistDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
artistId
|
|
|
|
)
|
2020-07-21 00:35:48 +05:30
|
|
|
}
|
|
|
|
|
2020-08-20 15:22:38 +05:30
|
|
|
viewModel { (playlist: PlaylistWithSongs) ->
|
2020-08-11 23:59:44 +05:30
|
|
|
PlaylistDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
playlist
|
|
|
|
)
|
2020-07-21 00:35:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
viewModel { (genre: Genre) ->
|
2020-08-11 23:59:44 +05:30
|
|
|
GenreDetailsViewModel(
|
|
|
|
get(),
|
|
|
|
genre
|
|
|
|
)
|
2020-07-21 00:35:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
viewModel {
|
|
|
|
SearchViewModel(get())
|
|
|
|
}
|
2020-07-26 01:52:37 +05:30
|
|
|
}
|
|
|
|
|
2020-08-21 17:13:51 +05:30
|
|
|
val appModules = listOf(mainModule, dataModule, viewModules, networkModule, roomModule)
|