mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-26 10:24:33 +01:00
Testing IOS
This commit is contained in:
parent
751ba3512e
commit
f80675cd13
@ -7,7 +7,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
/*
|
/*
|
||||||
* Holder to call platform actions from anywhere
|
* Holder to call platform actions from anywhere
|
||||||
* */
|
* */
|
||||||
var methods: NativeAtomicReference<Actions> = NativeAtomicReference(stubActions().freeze())
|
val methods: NativeAtomicReference<Actions> = NativeAtomicReference(stubActions().freeze())
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Interface Having All Platform Dependent Functions
|
* Interface Having All Platform Dependent Functions
|
||||||
|
@ -23,6 +23,7 @@ import com.shabinder.common.di.providers.GaanaProvider
|
|||||||
import com.shabinder.common.di.providers.SpotifyProvider
|
import com.shabinder.common.di.providers.SpotifyProvider
|
||||||
import com.shabinder.common.di.providers.YoutubeMp3
|
import com.shabinder.common.di.providers.YoutubeMp3
|
||||||
import com.shabinder.common.di.providers.YoutubeMusic
|
import com.shabinder.common.di.providers.YoutubeMusic
|
||||||
|
import com.shabinder.common.models.NativeAtomicReference
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.features.HttpTimeout
|
import io.ktor.client.features.HttpTimeout
|
||||||
import io.ktor.client.features.json.JsonFeature
|
import io.ktor.client.features.json.JsonFeature
|
||||||
@ -35,6 +36,7 @@ import kotlinx.serialization.json.Json
|
|||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
import org.koin.dsl.KoinAppDeclaration
|
import org.koin.dsl.KoinAppDeclaration
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
import kotlin.native.concurrent.SharedImmutable
|
||||||
|
|
||||||
fun initKoin(enableNetworkLogs: Boolean = false, appDeclaration: KoinAppDeclaration = {}) =
|
fun initKoin(enableNetworkLogs: Boolean = false, appDeclaration: KoinAppDeclaration = {}) =
|
||||||
startKoin {
|
startKoin {
|
||||||
@ -58,6 +60,7 @@ fun commonModule(enableNetworkLogs: Boolean) = module {
|
|||||||
single { FetchPlatformQueryResult(get(), get(), get(), get(), get(), get()) }
|
single { FetchPlatformQueryResult(get(), get(), get(), get(), get(), get()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SharedImmutable
|
||||||
val kotlinxSerializer = KotlinxSerializer(
|
val kotlinxSerializer = KotlinxSerializer(
|
||||||
Json {
|
Json {
|
||||||
isLenient = true
|
isLenient = true
|
||||||
@ -82,5 +85,7 @@ fun createHttpClient(enableNetworkLogs: Boolean = false, serializer: KotlinxSeri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Client Active Throughout App's Lifetime*/
|
/*Client Active Throughout App's Lifetime*/
|
||||||
|
@SharedImmutable
|
||||||
val ktorHttpClient = HttpClient {}
|
val ktorHttpClient = HttpClient {}
|
||||||
|
@ -17,16 +17,17 @@
|
|||||||
package com.shabinder.common.di.providers
|
package com.shabinder.common.di.providers
|
||||||
|
|
||||||
import co.touchlab.kermit.Kermit
|
import co.touchlab.kermit.Kermit
|
||||||
|
import co.touchlab.stately.freeze
|
||||||
import com.shabinder.common.di.Dir
|
import com.shabinder.common.di.Dir
|
||||||
import com.shabinder.common.di.TokenStore
|
import com.shabinder.common.di.TokenStore
|
||||||
import com.shabinder.common.di.finalOutputDir
|
import com.shabinder.common.di.finalOutputDir
|
||||||
import com.shabinder.common.di.kotlinxSerializer
|
import com.shabinder.common.di.kotlinxSerializer
|
||||||
|
import com.shabinder.common.di.ktorHttpClient
|
||||||
import com.shabinder.common.di.spotify.SpotifyRequests
|
import com.shabinder.common.di.spotify.SpotifyRequests
|
||||||
import com.shabinder.common.di.spotify.authenticateSpotify
|
import com.shabinder.common.di.spotify.authenticateSpotify
|
||||||
import com.shabinder.common.models.AllPlatforms
|
import com.shabinder.common.models.NativeAtomicReference
|
||||||
import com.shabinder.common.models.PlatformQueryResult
|
import com.shabinder.common.models.PlatformQueryResult
|
||||||
import com.shabinder.common.models.TrackDetails
|
import com.shabinder.common.models.TrackDetails
|
||||||
import com.shabinder.common.models.methods
|
|
||||||
import com.shabinder.common.models.spotify.Album
|
import com.shabinder.common.models.spotify.Album
|
||||||
import com.shabinder.common.models.spotify.Image
|
import com.shabinder.common.models.spotify.Image
|
||||||
import com.shabinder.common.models.spotify.Source
|
import com.shabinder.common.models.spotify.Source
|
||||||
@ -35,10 +36,6 @@ import io.ktor.client.HttpClient
|
|||||||
import io.ktor.client.features.defaultRequest
|
import io.ktor.client.features.defaultRequest
|
||||||
import io.ktor.client.features.json.JsonFeature
|
import io.ktor.client.features.json.JsonFeature
|
||||||
import io.ktor.client.request.header
|
import io.ktor.client.request.header
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlin.native.concurrent.ThreadLocal
|
|
||||||
|
|
||||||
class SpotifyProvider(
|
class SpotifyProvider(
|
||||||
private val tokenStore: TokenStore,
|
private val tokenStore: TokenStore,
|
||||||
@ -55,11 +52,10 @@ class SpotifyProvider(
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
override suspend fun authenticateSpotifyClient(override: Boolean): HttpClient? {
|
override suspend fun authenticateSpotifyClient(override: Boolean) {
|
||||||
val token = if (override) authenticateSpotify() else tokenStore.getToken()
|
val token = if (override) authenticateSpotify() else tokenStore.getToken()
|
||||||
return if (token == null) {
|
if (token == null) {
|
||||||
logger.d { "Please Check your Network Connection" }
|
logger.d { "Please Check your Network Connection" }
|
||||||
null
|
|
||||||
} else {
|
} else {
|
||||||
logger.d { "Spotify Provider Created with $token" }
|
logger.d { "Spotify Provider Created with $token" }
|
||||||
HttpClient {
|
HttpClient {
|
||||||
@ -69,18 +65,14 @@ class SpotifyProvider(
|
|||||||
install(JsonFeature) {
|
install(JsonFeature) {
|
||||||
serializer = kotlinxSerializer
|
serializer = kotlinxSerializer
|
||||||
}
|
}
|
||||||
}.also { httpClient = it }
|
}.also { httpClientRef.value = it.freeze() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override lateinit var httpClient: HttpClient
|
override val httpClientRef = NativeAtomicReference(ktorHttpClient)
|
||||||
|
|
||||||
suspend fun query(fullLink: String): PlatformQueryResult? {
|
suspend fun query(fullLink: String): PlatformQueryResult? {
|
||||||
|
|
||||||
if (!this::httpClient.isInitialized) {
|
|
||||||
authenticateSpotifyClient()
|
|
||||||
}
|
|
||||||
|
|
||||||
var spotifyLink =
|
var spotifyLink =
|
||||||
"https://" + fullLink.substringAfterLast("https://").substringBefore(" ").trim()
|
"https://" + fullLink.substringAfterLast("https://").substringBefore(" ").trim()
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import io.ktor.client.features.json.JsonFeature
|
|||||||
import io.ktor.client.request.forms.FormDataContent
|
import io.ktor.client.request.forms.FormDataContent
|
||||||
import io.ktor.client.request.post
|
import io.ktor.client.request.post
|
||||||
import io.ktor.http.Parameters
|
import io.ktor.http.Parameters
|
||||||
|
import kotlin.native.concurrent.SharedImmutable
|
||||||
|
|
||||||
suspend fun authenticateSpotify(): TokenData? {
|
suspend fun authenticateSpotify(): TokenData? {
|
||||||
return try {
|
return try {
|
||||||
@ -37,6 +38,7 @@ suspend fun authenticateSpotify(): TokenData? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SharedImmutable
|
||||||
private val spotifyAuthClient by lazy {
|
private val spotifyAuthClient by lazy {
|
||||||
HttpClient {
|
HttpClient {
|
||||||
val clientId = "694d8bf4f6ec420fa66ea7fb4c68f89d"
|
val clientId = "694d8bf4f6ec420fa66ea7fb4c68f89d"
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.shabinder.common.di.spotify
|
package com.shabinder.common.di.spotify
|
||||||
|
|
||||||
import com.shabinder.common.di.gaana.corsApi
|
import com.shabinder.common.di.gaana.corsApi
|
||||||
|
import com.shabinder.common.models.NativeAtomicReference
|
||||||
import com.shabinder.common.models.spotify.Album
|
import com.shabinder.common.models.spotify.Album
|
||||||
import com.shabinder.common.models.spotify.PagingObjectPlaylistTrack
|
import com.shabinder.common.models.spotify.PagingObjectPlaylistTrack
|
||||||
import com.shabinder.common.models.spotify.Playlist
|
import com.shabinder.common.models.spotify.Playlist
|
||||||
@ -28,9 +29,10 @@ private val BASE_URL get() = "${corsApi}https://api.spotify.com/v1"
|
|||||||
|
|
||||||
interface SpotifyRequests {
|
interface SpotifyRequests {
|
||||||
|
|
||||||
val httpClient: HttpClient
|
val httpClientRef: NativeAtomicReference<HttpClient>
|
||||||
|
val httpClient get() = httpClientRef.value
|
||||||
|
|
||||||
suspend fun authenticateSpotifyClient(override: Boolean = false): HttpClient?
|
suspend fun authenticateSpotifyClient(override: Boolean = false)
|
||||||
|
|
||||||
suspend fun getPlaylist(playlistID: String): Playlist {
|
suspend fun getPlaylist(playlistID: String): Playlist {
|
||||||
return httpClient.get("$BASE_URL/playlists/$playlistID")
|
return httpClient.get("$BASE_URL/playlists/$playlistID")
|
||||||
|
@ -26,7 +26,9 @@ import com.arkivanov.decompose.router
|
|||||||
import com.arkivanov.decompose.statekeeper.Parcelable
|
import com.arkivanov.decompose.statekeeper.Parcelable
|
||||||
import com.arkivanov.decompose.statekeeper.Parcelize
|
import com.arkivanov.decompose.statekeeper.Parcelize
|
||||||
import com.arkivanov.decompose.value.Value
|
import com.arkivanov.decompose.value.Value
|
||||||
|
import com.shabinder.common.database.getLogger
|
||||||
import com.shabinder.common.di.Dir
|
import com.shabinder.common.di.Dir
|
||||||
|
import com.shabinder.common.di.createDirectories
|
||||||
import com.shabinder.common.list.SpotiFlyerList
|
import com.shabinder.common.list.SpotiFlyerList
|
||||||
import com.shabinder.common.main.SpotiFlyerMain
|
import com.shabinder.common.main.SpotiFlyerMain
|
||||||
import com.shabinder.common.models.Actions
|
import com.shabinder.common.models.Actions
|
||||||
@ -48,11 +50,17 @@ internal class SpotiFlyerRootImpl(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
methods.value = actions.freeze()
|
methods.value = actions.freeze()
|
||||||
GlobalScope.launch(Dispatchers.Default) {
|
GlobalScope.launch {
|
||||||
|
/*TESTING*/
|
||||||
|
getLogger().apply {
|
||||||
|
d("Hey...","Background Thread")
|
||||||
|
//d(directories.defaultDir(),"Background Thread")
|
||||||
|
d("Hey...","Background Thread")
|
||||||
|
}
|
||||||
//*Authenticate Spotify Client*//*
|
//*Authenticate Spotify Client*//*
|
||||||
/*if (methods.value.currentPlatform is AllPlatforms.Js) {
|
/*fetchPlatformQueryResult.spotifyProvider.authenticateSpotifyClient(
|
||||||
fetchPlatformQueryResult.spotifyProvider.authenticateSpotifyClient(override = true)
|
override = true //methods.value.currentPlatform is AllPlatforms.Js
|
||||||
} else fetchPlatformQueryResult.spotifyProvider.authenticateSpotifyClient()*/
|
)*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user