Skip to content

Commit

Permalink
Move sourceSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeyatogod committed Oct 28, 2023
1 parent 0c129bb commit a6acbf7
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.talent.animescrapsources.animesources
package com.talent.animescrap_common.source

import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.talent.animescrapsources

import android.content.Context
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrapsources.animesources.*

class SourceSelector(context: Context) {
private val sourceMap: Map<String, AnimeSource> = hashMapOf(
"yugen" to YugenSource(),
"allanime" to AllAnimeSource(),
"enime" to EnimeSource(),
"kiss_kh" to KissKhSource(),
"animepahe" to AnimePaheSource(context),
"kawaiifu" to KawaiifuSource(context),
"marin_moe" to MarinMoeSource(),
"asian_load" to AsianLoad(),
"my_asian_tv" to MyAsianTvSource(),
)

fun getSelectedSource(selectedSource: String): AnimeSource {
if (selectedSource in sourceMap.keys) {
return sourceMap[selectedSource]!!
}
return sourceMap["yugen"]!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.talent.animescrapsources.animesources
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrap_common.utils.Utils.getJson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.talent.animescrap_common.sourceutils.CloudflareInterceptor
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrap_common.utils.Utils.getJson
import com.talent.animescrap_common.utils.Utils.httpClient
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.talent.animescrapsources.animesources.sourceCommonExtractors.AsianExt
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrap_common.utils.Utils.get
import org.jsoup.Jsoup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.talent.animescrapsources.animesources
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrap_common.utils.Utils.getJson
import com.talent.animescrap_common.utils.Utils.getJsoup
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.talent.animescrap_common.sourceutils.CloudflareInterceptor
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrapsources.animesources.AnimeSource
import com.talent.animescrap_common.source.AnimeSource
import okhttp3.OkHttpClient
import okhttp3.Request
import org.jsoup.Jsoup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.utils.Utils.getJson
import com.talent.animescrapsources.animesources.AnimeSource
import com.talent.animescrap_common.source.AnimeSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.utils.Utils.httpClient
import com.talent.animescrapsources.animesources.AnimeSource
import com.talent.animescrap_common.source.AnimeSource
import okhttp3.Request
import okhttp3.Response
import org.jsoup.Jsoup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.talent.animescrapsources.animesources.sourceCommonExtractors.AsianExt
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrap_common.utils.Utils.get
import org.jsoup.Jsoup
import org.jsoup.select.Elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.utils.Utils.getJsoup
import com.talent.animescrap_common.utils.Utils.postJson
import com.talent.animescrapsources.animesources.AnimeSource
import com.talent.animescrap_common.source.AnimeSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.gson.JsonParser
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrap_common.utils.Utils.getJson
import com.talent.animescrap_common.utils.Utils.getJsoup
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ import com.talent.animescrap.room.LinkDao
import com.talent.animescrap_common.model.AnimeDetails
import com.talent.animescrap_common.model.AnimeStreamLink
import com.talent.animescrap_common.model.SimpleAnime
import com.talent.animescrapsources.animesources.AllAnimeSource
import com.talent.animescrapsources.animesources.AnimePaheSource
import com.talent.animescrapsources.animesources.AnimeSource
import com.talent.animescrapsources.animesources.AsianLoad
import com.talent.animescrapsources.animesources.EnimeSource
import com.talent.animescrapsources.animesources.KawaiifuSource
import com.talent.animescrapsources.animesources.KissKhSource
import com.talent.animescrapsources.animesources.MarinMoeSource
import com.talent.animescrapsources.animesources.MyAsianTvSource
import com.talent.animescrapsources.animesources.YugenSource
import com.talent.animescrapsources.SourceSelector
import com.talent.animescrap_common.source.AnimeSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -56,42 +48,7 @@ class AnimeRepositoryImpl @Inject constructor(
.getDefaultSharedPreferences(application)
.getString("source", "yugen")

private val animeSource: AnimeSource =
when (selectedSource) {
"yugen" -> {
YugenSource()
}
// "zoro" -> {
// ZoroSource()
// }
"allanime" -> {
AllAnimeSource()
}
"enime" -> {
EnimeSource()
}
"kiss_kh" -> {
KissKhSource()
}
"animepahe" -> {
AnimePaheSource(application as Context)
}
"kawaiifu" -> {
KawaiifuSource(application as Context)
}
"marin_moe" -> {
MarinMoeSource()
}
"asian_load" -> {
AsianLoad()
}
"my_asian_tv" -> {
MyAsianTvSource()
}
else -> {
YugenSource()
}
}
private val animeSource : AnimeSource = SourceSelector(application as Context).getSelectedSource(selectedSource ?: "yugen")

override suspend fun getAnimeDetailsFromSite(contentLink: String) =
withContext(Dispatchers.IO) {
Expand Down

0 comments on commit a6acbf7

Please sign in to comment.