Added Koin
This commit is contained in:
parent
17a66450d4
commit
0ebcbd9434
21 changed files with 108 additions and 151 deletions
|
@ -20,6 +20,7 @@ import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||||
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
|
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
|
||||||
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
||||||
|
import code.name.monkey.retromusic.network.networkModule
|
||||||
import code.name.monkey.retromusic.providers.provideModules
|
import code.name.monkey.retromusic.providers.provideModules
|
||||||
import com.anjlab.android.iab.v3.BillingProcessor
|
import com.anjlab.android.iab.v3.BillingProcessor
|
||||||
import com.anjlab.android.iab.v3.TransactionDetails
|
import com.anjlab.android.iab.v3.TransactionDetails
|
||||||
|
@ -36,7 +37,7 @@ class App : MultiDexApplication() {
|
||||||
|
|
||||||
startKoin {
|
startKoin {
|
||||||
androidContext(this@App)
|
androidContext(this@App)
|
||||||
modules(listOf(mainModule, provideModules))
|
modules(listOf(mainModule, provideModules, networkModule))
|
||||||
}
|
}
|
||||||
// default theme
|
// default theme
|
||||||
if (!ThemeStore.isConfigured(this, 3)) {
|
if (!ThemeStore.isConfigured(this, 3)) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ object Constants {
|
||||||
const val APP_TWITTER_LINK = "https://twitter.com/retromusicapp"
|
const val APP_TWITTER_LINK = "https://twitter.com/retromusicapp"
|
||||||
const val FAQ_LINK = "https://github.com/h4h13/RetroMusicPlayer/blob/master/FAQ.md"
|
const val FAQ_LINK = "https://github.com/h4h13/RetroMusicPlayer/blob/master/FAQ.md"
|
||||||
const val PINTEREST = "https://in.pinterest.com/retromusicapp/"
|
const val PINTEREST = "https://in.pinterest.com/retromusicapp/"
|
||||||
|
const val BASE_URL = "https://ws.audioscrobbler.com/2.0/"
|
||||||
|
|
||||||
const val IS_MUSIC =
|
const val IS_MUSIC =
|
||||||
MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"
|
MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"
|
||||||
|
|
|
@ -36,7 +36,7 @@ import code.name.monkey.retromusic.helper.SortOrder.AlbumSongSortOrder
|
||||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.model.Artist
|
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.*
|
||||||
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
||||||
import com.afollestad.materialcab.MaterialCab
|
import com.afollestad.materialcab.MaterialCab
|
||||||
|
|
|
@ -8,7 +8,7 @@ import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.providers.RepositoryImpl
|
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.Deferred
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
|
|
@ -30,7 +30,7 @@ import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||||
import code.name.monkey.retromusic.model.Artist
|
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.*
|
||||||
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
||||||
import com.afollestad.materialcab.MaterialCab
|
import com.afollestad.materialcab.MaterialCab
|
||||||
|
|
|
@ -7,7 +7,7 @@ import androidx.lifecycle.viewModelScope
|
||||||
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.providers.RepositoryImpl
|
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.Deferred
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
|
|
@ -15,12 +15,7 @@
|
||||||
package code.name.monkey.retromusic.dialogs
|
package code.name.monkey.retromusic.dialogs
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.Bundle
|
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 androidx.fragment.app.DialogFragment
|
||||||
import code.name.monkey.retromusic.EXTRA_SONG
|
import code.name.monkey.retromusic.EXTRA_SONG
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
@ -43,33 +38,8 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||||
for (p in playlists) {
|
for (p in playlists) {
|
||||||
playlistNames.add(p.name)
|
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)
|
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 ->
|
.setItems(playlistNames.toTypedArray()) { _, which ->
|
||||||
val songs = extraNotNull<ArrayList<Song>>(EXTRA_SONG).value
|
val songs = extraNotNull<ArrayList<Song>>(EXTRA_SONG).value
|
||||||
if (which == 0) {
|
if (which == 0) {
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
package code.name.monkey.retromusic.glide.artistimage
|
package code.name.monkey.retromusic.glide.artistimage
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import code.name.monkey.retromusic.deezer.Data
|
|
||||||
import code.name.monkey.retromusic.deezer.DeezerApiService
|
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.MusicUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import com.bumptech.glide.Priority
|
import com.bumptech.glide.Priority
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
* See the GNU General Public License for more details.
|
* 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.network.model.LastFmAlbum
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
import code.name.monkey.retromusic.network.model.LastFmArtist
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Header
|
import retrofit2.http.Header
|
||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
|
@ -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
|
||||||
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
* See the GNU General Public License for more details.
|
* 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.Expose;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
|
@ -12,7 +12,7 @@
|
||||||
* See the GNU General Public License for more details.
|
* 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.Expose;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
|
@ -12,7 +12,7 @@
|
||||||
* See the GNU General Public License for more details.
|
* 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.Expose;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
|
@ -35,13 +35,13 @@ import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.extensions.colorButtons
|
import code.name.monkey.retromusic.extensions.colorButtons
|
||||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
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.fragments.AlbumCoverStyle.*
|
import code.name.monkey.retromusic.fragments.AlbumCoverStyle.*
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.util.ViewUtil
|
import code.name.monkey.retromusic.util.ViewUtil
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
|
|
||||||
class AlbumCoverStylePreference @JvmOverloads constructor(
|
class AlbumCoverStylePreference @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -80,9 +80,7 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
||||||
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||||
viewPager.currentItem = PreferenceUtil.albumCoverStyle.ordinal
|
viewPager.currentItem = PreferenceUtil.albumCoverStyle.ordinal
|
||||||
|
|
||||||
return MaterialAlertDialogBuilder(requireActivity(),
|
return materialDialog(R.string.pref_title_album_cover_style)
|
||||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert)
|
|
||||||
.setTitle(R.string.pref_title_album_cover_style)
|
|
||||||
.setPositiveButton(R.string.set) { _, _ ->
|
.setPositiveButton(R.string.set) { _, _ ->
|
||||||
val coverStyle = values()[viewPagerPosition]
|
val coverStyle = values()[viewPagerPosition]
|
||||||
if (isAlbumCoverStyle(coverStyle)) {
|
if (isAlbumCoverStyle(coverStyle)) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog
|
import code.name.monkey.retromusic.dialogs.BlacklistFolderChooserDialog
|
||||||
import code.name.monkey.retromusic.extensions.colorButtons
|
import code.name.monkey.retromusic.extensions.colorButtons
|
||||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
import code.name.monkey.retromusic.extensions.colorControlNormal
|
||||||
|
import code.name.monkey.retromusic.extensions.materialDialog
|
||||||
import code.name.monkey.retromusic.providers.BlacklistStore
|
import code.name.monkey.retromusic.providers.BlacklistStore
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -60,20 +61,12 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
|
||||||
childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog?
|
childFragmentManager.findFragmentByTag("FOLDER_CHOOSER") as BlacklistFolderChooserDialog?
|
||||||
chooserDialog?.setCallback(this)
|
chooserDialog?.setCallback(this)
|
||||||
refreshBlacklistData()
|
refreshBlacklistData()
|
||||||
return MaterialAlertDialogBuilder(
|
return materialDialog(R.string.blacklist)
|
||||||
requireActivity(),
|
|
||||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
|
||||||
)
|
|
||||||
.setTitle(R.string.blacklist)
|
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
.setNeutralButton(R.string.clear_action) { _, _ ->
|
.setNeutralButton(R.string.clear_action) { _, _ ->
|
||||||
MaterialAlertDialogBuilder(
|
materialDialog(R.string.clear_blacklist)
|
||||||
requireActivity(),
|
|
||||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
|
||||||
)
|
|
||||||
.setTitle(R.string.clear_blacklist)
|
|
||||||
.setMessage(R.string.do_you_want_to_clear_the_blacklist)
|
.setMessage(R.string.do_you_want_to_clear_the_blacklist)
|
||||||
.setPositiveButton(R.string.clear_action) { _, _ ->
|
.setPositiveButton(R.string.clear_action) { _, _ ->
|
||||||
BlacklistStore.getInstance(
|
BlacklistStore.getInstance(
|
||||||
|
@ -91,10 +84,7 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
|
||||||
dialog.show(requireActivity().supportFragmentManager, "FOLDER_CHOOSER")
|
dialog.show(requireActivity().supportFragmentManager, "FOLDER_CHOOSER")
|
||||||
}
|
}
|
||||||
.setItems(paths.toTypedArray()) { _, which ->
|
.setItems(paths.toTypedArray()) { _, which ->
|
||||||
MaterialAlertDialogBuilder(
|
materialDialog(R.string.remove_from_blacklist)
|
||||||
requireActivity(),
|
|
||||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
|
||||||
).setTitle(R.string.remove_from_blacklist)
|
|
||||||
.setMessage(
|
.setMessage(
|
||||||
HtmlCompat.fromHtml(
|
HtmlCompat.fromHtml(
|
||||||
String.format(
|
String.format(
|
||||||
|
|
|
@ -31,9 +31,9 @@ import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.adapter.CategoryInfoAdapter
|
import code.name.monkey.retromusic.adapter.CategoryInfoAdapter
|
||||||
import code.name.monkey.retromusic.extensions.colorButtons
|
import code.name.monkey.retromusic.extensions.colorButtons
|
||||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
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.model.CategoryInfo
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
|
|
||||||
|
|
||||||
class LibraryPreference @JvmOverloads constructor(
|
class LibraryPreference @JvmOverloads constructor(
|
||||||
|
@ -65,11 +65,7 @@ class LibraryPreferenceDialog : DialogFragment() {
|
||||||
categoryAdapter.attachToRecyclerView(recyclerView)
|
categoryAdapter.attachToRecyclerView(recyclerView)
|
||||||
|
|
||||||
|
|
||||||
return MaterialAlertDialogBuilder(
|
return materialDialog(R.string.library_categories)
|
||||||
requireContext(),
|
|
||||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
|
||||||
)
|
|
||||||
.setTitle(R.string.library_categories)
|
|
||||||
.setNeutralButton(
|
.setNeutralButton(
|
||||||
R.string.reset_action
|
R.string.reset_action
|
||||||
) { _, _ ->
|
) { _, _ ->
|
||||||
|
|
|
@ -34,13 +34,13 @@ import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.extensions.colorButtons
|
import code.name.monkey.retromusic.extensions.colorButtons
|
||||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
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.fragments.NowPlayingScreen.*
|
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.util.ViewUtil
|
import code.name.monkey.retromusic.util.ViewUtil
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
|
|
||||||
class NowPlayingScreenPreference @JvmOverloads constructor(
|
class NowPlayingScreenPreference @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -87,11 +87,7 @@ class NowPlayingScreenPreferenceDialog : DialogFragment(), ViewPager.OnPageChang
|
||||||
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||||
viewPager.currentItem = PreferenceUtil.nowPlayingScreen.ordinal
|
viewPager.currentItem = PreferenceUtil.nowPlayingScreen.ordinal
|
||||||
|
|
||||||
return MaterialAlertDialogBuilder(
|
return materialDialog(R.string.pref_title_now_playing_screen_appearance)
|
||||||
requireContext(),
|
|
||||||
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
|
||||||
)
|
|
||||||
.setTitle(R.string.pref_title_now_playing_screen_appearance)
|
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.set) { _, _ ->
|
.setPositiveButton(R.string.set) { _, _ ->
|
||||||
val nowPlayingScreen = values()[viewPagerPosition]
|
val nowPlayingScreen = values()[viewPagerPosition]
|
||||||
|
|
|
@ -6,6 +6,6 @@ import org.koin.dsl.module
|
||||||
|
|
||||||
val provideModules = module {
|
val provideModules = module {
|
||||||
single {
|
single {
|
||||||
RepositoryImpl(get())
|
RepositoryImpl(get(), get())
|
||||||
} bind Repository::class
|
} bind Repository::class
|
||||||
}
|
}
|
|
@ -20,12 +20,15 @@ import code.name.monkey.retromusic.adapter.HomeAdapter
|
||||||
import code.name.monkey.retromusic.loaders.*
|
import code.name.monkey.retromusic.loaders.*
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.model.*
|
||||||
import code.name.monkey.retromusic.model.smartplaylist.NotRecentlyPlayedPlaylist
|
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.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)
|
override suspend fun allAlbums(): List<Album> = AlbumLoader.getAllAlbums(context)
|
||||||
|
|
||||||
|
@ -121,12 +124,12 @@ class RepositoryImpl constructor(private val context: Context) : Repository {
|
||||||
name: String,
|
name: String,
|
||||||
lang: String?,
|
lang: String?,
|
||||||
cache: String?
|
cache: String?
|
||||||
): LastFmArtist = LastFmClient.getApiService().artistInfo(name, lang, cache)
|
): LastFmArtist = lastFMService.artistInfo(name, lang, cache)
|
||||||
|
|
||||||
|
|
||||||
override suspend fun albumInfo(
|
override suspend fun albumInfo(
|
||||||
artist: String,
|
artist: String,
|
||||||
album: String
|
album: String
|
||||||
): LastFmAlbum = LastFmClient.getApiService().albumInfo(artist, album)
|
): LastFmAlbum = lastFMService.albumInfo(artist, album)
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,8 +15,8 @@
|
||||||
package code.name.monkey.retromusic.providers.interfaces
|
package code.name.monkey.retromusic.providers.interfaces
|
||||||
|
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.model.*
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmAlbum
|
import code.name.monkey.retromusic.network.model.LastFmAlbum
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
import code.name.monkey.retromusic.network.model.LastFmArtist
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 11/08/17.
|
* Created by hemanths on 11/08/17.
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue