diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimeSource.kt b/AnimeScrapCommon/src/main/java/com/talent/animescrap_common/source/AnimeSource.kt similarity index 92% rename from animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimeSource.kt rename to AnimeScrapCommon/src/main/java/com/talent/animescrap_common/source/AnimeSource.kt index d808a74..0a71b0a 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimeSource.kt +++ b/AnimeScrapCommon/src/main/java/com/talent/animescrap_common/source/AnimeSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/SourceSelector.kt b/animeSources/src/main/java/com/talent/animescrapsources/SourceSelector.kt new file mode 100644 index 0000000..408d7b1 --- /dev/null +++ b/animeSources/src/main/java/com/talent/animescrapsources/SourceSelector.kt @@ -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 = 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"]!! + } +} \ No newline at end of file diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AllAnimeSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/AllAnimeSource.kt index 2ea4293..87af826 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AllAnimeSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/AllAnimeSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimePaheSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimePaheSource.kt index c859fdf..d140112 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimePaheSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/AnimePaheSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AsianLoad.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/AsianLoad.kt index f9cb200..455772e 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/AsianLoad.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/AsianLoad.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/EnimeSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/EnimeSource.kt index 91df236..1ecbba5 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/EnimeSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/EnimeSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/KawaiifuSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/KawaiifuSource.kt index e367410..29d8584 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/KawaiifuSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/KawaiifuSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/KissKhSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/KissKhSource.kt index 901de09..e58ec55 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/KissKhSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/KissKhSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/MarinMoeSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/MarinMoeSource.kt index bb4700e..acfb255 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/MarinMoeSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/MarinMoeSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/MyAsianTvSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/MyAsianTvSource.kt index a031a3c..fd8e338 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/MyAsianTvSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/MyAsianTvSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/YugenSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/YugenSource.kt index 9e05514..1f663b7 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/YugenSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/YugenSource.kt @@ -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 diff --git a/animeSources/src/main/java/com/talent/animescrapsources/animesources/ZoroSource.kt b/animeSources/src/main/java/com/talent/animescrapsources/animesources/ZoroSource.kt index 0a038fe..8f1caae 100644 --- a/animeSources/src/main/java/com/talent/animescrapsources/animesources/ZoroSource.kt +++ b/animeSources/src/main/java/com/talent/animescrapsources/animesources/ZoroSource.kt @@ -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 diff --git a/app/src/main/java/com/talent/animescrap/repo/AnimeRepositoryImpl.kt b/app/src/main/java/com/talent/animescrap/repo/AnimeRepositoryImpl.kt index c99c952..a31ee8c 100644 --- a/app/src/main/java/com/talent/animescrap/repo/AnimeRepositoryImpl.kt +++ b/app/src/main/java/com/talent/animescrap/repo/AnimeRepositoryImpl.kt @@ -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 @@ -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) {