Added Koin

This commit is contained in:
Hemanth S 2020-07-21 01:21:15 +05:30
parent 17a66450d4
commit 0ebcbd9434
21 changed files with 108 additions and 151 deletions

View file

@ -20,6 +20,7 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.network.networkModule
import code.name.monkey.retromusic.providers.provideModules
import com.anjlab.android.iab.v3.BillingProcessor
import com.anjlab.android.iab.v3.TransactionDetails
@ -36,7 +37,7 @@ class App : MultiDexApplication() {
startKoin {
androidContext(this@App)
modules(listOf(mainModule, provideModules))
modules(listOf(mainModule, provideModules, networkModule))
}
// default theme
if (!ThemeStore.isConfigured(this, 3)) {

View file

@ -31,6 +31,7 @@ object Constants {
const val APP_TWITTER_LINK = "https://twitter.com/retromusicapp"
const val FAQ_LINK = "https://github.com/h4h13/RetroMusicPlayer/blob/master/FAQ.md"
const val PINTEREST = "https://in.pinterest.com/retromusicapp/"
const val BASE_URL = "https://ws.audioscrobbler.com/2.0/"
const val IS_MUSIC =
MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"

View file

@ -36,7 +36,7 @@ import code.name.monkey.retromusic.helper.SortOrder.AlbumSongSortOrder
import code.name.monkey.retromusic.interfaces.CabHolder
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.network.model.LastFmAlbum
import code.name.monkey.retromusic.util.*
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import com.afollestad.materialcab.MaterialCab

View file

@ -8,7 +8,7 @@ import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.providers.RepositoryImpl
import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.network.model.LastFmAlbum
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async

View file

@ -30,7 +30,7 @@ import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.interfaces.CabHolder
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.rest.model.LastFmArtist
import code.name.monkey.retromusic.network.model.LastFmArtist
import code.name.monkey.retromusic.util.*
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import com.afollestad.materialcab.MaterialCab

View file

@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.providers.RepositoryImpl
import code.name.monkey.retromusic.rest.model.LastFmArtist
import code.name.monkey.retromusic.network.model.LastFmArtist
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async

View file

@ -15,12 +15,7 @@
package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.EXTRA_SONG
import code.name.monkey.retromusic.R
@ -43,33 +38,8 @@ class AddToPlaylistDialog : DialogFragment() {
for (p in playlists) {
playlistNames.add(p.name)
}
val adapter: ArrayAdapter<String> = object : ArrayAdapter<String>(
requireContext(),
R.layout.dialog_list_item,
playlistNames
) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = super.getView(position, convertView, parent)
view.findViewById<TextView>(android.R.id.text1).setTextColor(Color.RED)
return view
}
}
return materialDialog(R.string.add_playlist_title)
/*.setAdapter(adapter) { _, which ->
val songs = extraNotNull<ArrayList<Song>>(EXTRA_SONG).value
if (which == 0) {
CreatePlaylistDialog.create(songs)
.show(requireActivity().supportFragmentManager, "ADD_TO_PLAYLIST")
} else {
PlaylistsUtil.addToPlaylist(
requireContext(),
songs,
playlists[which - 1].id,
true
)
}
dismiss()
}*/
.setItems(playlistNames.toTypedArray()) { _, which ->
val songs = extraNotNull<ArrayList<Song>>(EXTRA_SONG).value
if (which == 0) {

View file

@ -15,8 +15,8 @@
package code.name.monkey.retromusic.glide.artistimage
import android.content.Context
import code.name.monkey.retromusic.deezer.Data
import code.name.monkey.retromusic.deezer.DeezerApiService
import code.name.monkey.retromusic.deezer.Data
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import com.bumptech.glide.Priority

View file

@ -12,10 +12,10 @@
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.rest.service
package code.name.monkey.retromusic.network
import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.rest.model.LastFmArtist
import code.name.monkey.retromusic.network.model.LastFmAlbum
import code.name.monkey.retromusic.network.model.LastFmArtist
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

View file

@ -0,0 +1,71 @@
package code.name.monkey.retromusic.network
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.Constants.BASE_URL
import com.google.gson.Gson
import okhttp3.Cache
import okhttp3.ConnectionPool
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.io.File
import java.util.concurrent.TimeUnit
private const val TIMEOUT: Long = 700
val networkModule = module {
factory {
provideHttpClient(get(), get())
}
factory {
provideCacheControlInterceptor()
}
factory {
provideDefaultCache()
}
factory {
provideLastFmService(get())
}
single {
providerRetrofit(get())
}
}
fun provideLastFmService(retrofit: Retrofit): LastFMService =
retrofit.create(LastFMService::class.java)
fun providerRetrofit(okHttpClient: OkHttpClient.Builder): Retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.callFactory(okHttpClient.build())
.addConverterFactory(GsonConverterFactory.create(Gson()))
.build()
fun provideHttpClient(
cache: Cache,
interceptor: Interceptor
): OkHttpClient.Builder = OkHttpClient.Builder()
.connectionPool(ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
.retryOnConnectionFailure(true)
.connectTimeout(TIMEOUT, TimeUnit.MINUTES)
.writeTimeout(TIMEOUT, TimeUnit.MINUTES)
.readTimeout(TIMEOUT, TimeUnit.MINUTES)
.cache(cache)
.addInterceptor(interceptor)
fun provideCacheControlInterceptor(): Interceptor = Interceptor { chain: Interceptor.Chain ->
val modifiedRequest = chain.request().newBuilder()
.addHeader("Cache-Control", "max-age=31536000, max-stale=31536000")
.build()
chain.proceed(modifiedRequest)
}
fun provideDefaultCache(): Cache? {
val cacheDir = File(App.getContext().cacheDir.absolutePath, "/okhttp-lastfm/")
if (cacheDir.mkdirs() || cacheDir.isDirectory) {
return Cache(cacheDir, 1024 * 1024 * 10)
}
return null
}

View file

@ -12,7 +12,7 @@
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.rest.model;
package code.name.monkey.retromusic.network.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

View file

@ -12,7 +12,7 @@
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.rest.model;
package code.name.monkey.retromusic.network.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

View file

@ -12,7 +12,7 @@
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.rest.model;
package code.name.monkey.retromusic.network.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

View file

@ -35,13 +35,13 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.colorButtons
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.materialDialog
import code.name.monkey.retromusic.fragments.AlbumCoverStyle
import code.name.monkey.retromusic.fragments.AlbumCoverStyle.*
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.ViewUtil
import com.bumptech.glide.Glide
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AlbumCoverStylePreference @JvmOverloads constructor(
context: Context,
@ -80,9 +80,7 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
viewPager.currentItem = PreferenceUtil.albumCoverStyle.ordinal
return MaterialAlertDialogBuilder(requireActivity(),
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert)
.setTitle(R.string.pref_title_album_cover_style)
return materialDialog(R.string.pref_title_album_cover_style)
.setPositiveButton(R.string.set) { _, _ ->
val coverStyle = values()[viewPagerPosition]
if (isAlbumCoverStyle(coverStyle)) {

View file

@ -27,6 +27,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog
import code.name.monkey.retromusic.extensions.colorButtons
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.materialDialog
import code.name.monkey.retromusic.providers.BlacklistStore
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File
@ -60,20 +61,12 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog?
chooserDialog?.setCallback(this)
refreshBlacklistData()
return MaterialAlertDialogBuilder(
requireActivity(),
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
)
.setTitle(R.string.blacklist)
return materialDialog(R.string.blacklist)
.setPositiveButton(android.R.string.ok) { _, _ ->
dismiss()
}
.setNeutralButton(R.string.clear_action) { _, _ ->
MaterialAlertDialogBuilder(
requireActivity(),
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
)
.setTitle(R.string.clear_blacklist)
materialDialog(R.string.clear_blacklist)
.setMessage(R.string.do_you_want_to_clear_the_blacklist)
.setPositiveButton(R.string.clear_action) { _, _ ->
BlacklistStore.getInstance(
@ -91,10 +84,7 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
dialog.show(requireActivity().supportFragmentManager, "FOLDER_CHOOSER")
}
.setItems(paths.toTypedArray()) { _, which ->
MaterialAlertDialogBuilder(
requireActivity(),
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
).setTitle(R.string.remove_from_blacklist)
materialDialog(R.string.remove_from_blacklist)
.setMessage(
HtmlCompat.fromHtml(
String.format(

View file

@ -31,9 +31,9 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.CategoryInfoAdapter
import code.name.monkey.retromusic.extensions.colorButtons
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.materialDialog
import code.name.monkey.retromusic.model.CategoryInfo
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class LibraryPreference @JvmOverloads constructor(
@ -65,11 +65,7 @@ class LibraryPreferenceDialog : DialogFragment() {
categoryAdapter.attachToRecyclerView(recyclerView)
return MaterialAlertDialogBuilder(
requireContext(),
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
)
.setTitle(R.string.library_categories)
return materialDialog(R.string.library_categories)
.setNeutralButton(
R.string.reset_action
) { _, _ ->

View file

@ -34,13 +34,13 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.colorButtons
import code.name.monkey.retromusic.extensions.colorControlNormal
import code.name.monkey.retromusic.extensions.materialDialog
import code.name.monkey.retromusic.fragments.NowPlayingScreen
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.ViewUtil
import com.bumptech.glide.Glide
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class NowPlayingScreenPreference @JvmOverloads constructor(
context: Context,
@ -87,11 +87,7 @@ class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChang
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
viewPager.currentItem = PreferenceUtil.nowPlayingScreen.ordinal
return MaterialAlertDialogBuilder(
requireContext(),
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
)
.setTitle(R.string.pref_title_now_playing_screen_appearance)
return materialDialog(R.string.pref_title_now_playing_screen_appearance)
.setCancelable(false)
.setPositiveButton(R.string.set) { _, _ ->
val nowPlayingScreen = values()[viewPagerPosition]

View file

@ -6,6 +6,6 @@ import org.koin.dsl.module
val provideModules = module {
single {
RepositoryImpl(get())
RepositoryImpl(get(), get())
} bind Repository::class
}

View file

@ -20,12 +20,15 @@ import code.name.monkey.retromusic.adapter.HomeAdapter
import code.name.monkey.retromusic.loaders.*
import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.model.smartplaylist.NotRecentlyPlayedPlaylist
import code.name.monkey.retromusic.network.LastFMService
import code.name.monkey.retromusic.network.model.LastFmAlbum
import code.name.monkey.retromusic.network.model.LastFmArtist
import code.name.monkey.retromusic.providers.interfaces.Repository
import code.name.monkey.retromusic.rest.LastFmClient
import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.rest.model.LastFmArtist
class RepositoryImpl constructor(private val context: Context) : Repository {
class RepositoryImpl(
private val context: Context,
private val lastFMService: LastFMService
) : Repository {
override suspend fun allAlbums(): List<Album> = AlbumLoader.getAllAlbums(context)
@ -121,12 +124,12 @@ class RepositoryImpl constructor(private val context: Context) : Repository {
name: String,
lang: String?,
cache: String?
): LastFmArtist = LastFmClient.getApiService().artistInfo(name, lang, cache)
): LastFmArtist = lastFMService.artistInfo(name, lang, cache)
override suspend fun albumInfo(
artist: String,
album: String
): LastFmAlbum = LastFmClient.getApiService().albumInfo(artist, album)
): LastFmAlbum = lastFMService.albumInfo(artist, album)
}

View file

@ -15,8 +15,8 @@
package code.name.monkey.retromusic.providers.interfaces
import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.rest.model.LastFmArtist
import code.name.monkey.retromusic.network.model.LastFmAlbum
import code.name.monkey.retromusic.network.model.LastFmArtist
/**
* Created by hemanths on 11/08/17.

View file

@ -1,69 +0,0 @@
package code.name.monkey.retromusic.rest
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.rest.service.LastFMService
import com.google.gson.Gson
import okhttp3.Cache
import okhttp3.ConnectionPool
import okhttp3.Interceptor
import okhttp3.Interceptor.Chain
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.io.File
import java.util.concurrent.TimeUnit
object LastFmClient {
private const val baseUrl = "https://ws.audioscrobbler.com/2.0/"
private var lastFMService: LastFMService
fun getApiService(): LastFMService {
return lastFMService
}
init {
lastFMService = Retrofit.Builder()
.baseUrl(baseUrl)
.callFactory(createDefaultOkHttpClientBuilder().build())
.addConverterFactory(GsonConverterFactory.create(Gson()))
.build()
.create(LastFMService::class.java)
}
private fun createDefaultOkHttpClientBuilder(): OkHttpClient.Builder {
return OkHttpClient.Builder()
.connectionPool(ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
.retryOnConnectionFailure(true)
.connectTimeout(1, TimeUnit.MINUTES) // connect timeout
.writeTimeout(1, TimeUnit.MINUTES) // write timeout
.readTimeout(1, TimeUnit.MINUTES) // read timeout
.cache(createDefaultCache())
.addInterceptor(createCacheControlInterceptor())
.addInterceptor(createLogInterceptor())
}
private fun createLogInterceptor(): Interceptor {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BASIC
return interceptor
}
private fun createCacheControlInterceptor(): Interceptor {
return Interceptor { chain: Chain ->
val modifiedRequest = chain.request().newBuilder()
.addHeader("Cache-Control", "max-age=31536000, max-stale=31536000")
.build()
chain.proceed(modifiedRequest)
}
}
private fun createDefaultCache(): Cache? {
val cacheDir = File(App.getContext().cacheDir.absolutePath, "/okhttp-lastfm/")
if (cacheDir.mkdirs() || cacheDir.isDirectory) {
return Cache(cacheDir, 1024 * 1024 * 10)
}
return null
}
}