Skip to content

Commit

Permalink
Merge pull request #18 from Fmaldonado6/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Fmaldonado6 authored May 31, 2021
2 parents ba66967 + d654389 commit b99b791
Show file tree
Hide file tree
Showing 29 changed files with 658 additions and 257 deletions.
11 changes: 9 additions & 2 deletions mobile_app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId "com.fmaldonado.akiyama"
minSdkVersion 23
targetSdkVersion 30
versionCode 8
versionName "v2.1.5"
versionCode 11
versionName "v2.1.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -81,6 +81,11 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

//ExoPlayer
implementation 'com.google.android.exoplayer:exoplayer-core:2.13.3'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.13.3'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3'

//Room
implementation "androidx.room:room-runtime:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
Expand All @@ -89,6 +94,8 @@ dependencies {
//Webview
implementation 'org.adblockplus:adblock-android-webview:3.14'

//JSOUP
implementation 'org.jsoup:jsoup:1.13.1'

//Default
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Expand Down
Binary file modified mobile_app/app/release/app-release.apk
Binary file not shown.
6 changes: 3 additions & 3 deletions mobile_app/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"kind": "Directory"
},
"applicationId": "com.fmaldonado.akiyama",
"variantName": "processReleaseResources",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 8,
"versionName": "v2.1.5",
"versionCode": 10,
"versionName": "v2.1.7",
"outputFile": "app-release.apk"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fmaldonado.akiyama.data.models.video

data class VideoResponse(
val file: String = "",
val useWebView:Boolean = false
)

data class FembedVideoResponse(
val data: List<FembedData>
)

data class FembedData(
val label: String,
val file: String
)

enum class ServerTypes(val value: String) {
GoCdn("gocdn"),
Fembed("fembed"),
Mega("Mega"),
Stape("stape"),
Okru("okru"),
Netu("netu")
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface NetworkDataSource {
@GET("search/{title}")
suspend fun getSearch(@Path("title") title: String): List<Anime>

@GET("animeInfo/{animeId}/{animeTitle}")
@GET("{animeId}/{animeTitle}")
suspend fun getAnimeInfo(
@Path("animeId") animeId: String,
@Path("animeTitle") title: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.fmaldonado.akiyama.data.network

import android.util.Log
import com.fmaldonado.akiyama.data.models.video.FembedVideoResponse
import com.fmaldonado.akiyama.data.models.video.VideoResponse
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import org.jsoup.Jsoup
import ru.gildor.coroutines.okhttp.await
import java.lang.Exception
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext

class VideoDataSource
@Inject
constructor(
private val client: OkHttpClient,
private val gson: Gson
) {
private val goCdnUrl = "https://streamium.xyz/gocdn.php?v="
private val fembedUrl = "https://www.fembed.com/api/source/"
private val hdLabel = "720p"

suspend fun fetchGocdnVideo(id: String): VideoResponse {

val req = Request.Builder().url(goCdnUrl + id).build()
val response = client.newCall(req).await()
val body = withContext(Dispatchers.IO) {
kotlin.runCatching { response.body()?.string() }.getOrThrow()
}
return gson.fromJson(body, VideoResponse::class.java)
}

suspend fun fetchFembedVideo(id: String): VideoResponse {
val req =
Request.Builder().url(fembedUrl + id)
.post(RequestBody.create(null, byteArrayOf())).build()
val response = client.newCall(req).await()
val body = withContext(Dispatchers.IO) {
kotlin.runCatching { response.body()?.string() }.getOrThrow()
}
val fembedVideoResponse = gson.fromJson(body, FembedVideoResponse::class.java)

var videoResponse = VideoResponse(fembedVideoResponse.data.first().file)

if (fembedVideoResponse.data.size == 1)
return videoResponse

fembedVideoResponse.data.forEach {
if (it.label == hdLabel)
videoResponse = VideoResponse(it.file)
}

return videoResponse
}

suspend fun fetchStapeVideo(url: String) {
Log.d("Url", url)
val req = Request.Builder().url("https://streamtape.com/e/VrGka6PrmLIKd6O").build()
val response = client.newCall(req).await()
val body = withContext(Dispatchers.IO) {
kotlin.runCatching { response.body()?.string() }.getOrThrow()
}
val document = Jsoup.parse(body)
val link = document.getElementById("videolink")
Log.d("Link", link.html())
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fmaldonado.akiyama.data.network.interceptor

import android.util.Log
import com.fmaldonado.akiyama.data.network.exceptions.AppError
import com.fmaldonado.akiyama.data.network.exceptions.BadInput
import com.fmaldonado.akiyama.data.network.exceptions.EmptySearch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ constructor(
return networkDataSource.getServers(split.first(), split.last())
}

suspend fun getAnimeInfo(fullAnimeId: String, animeTitle: String): Anime {
val animeId = fullAnimeId.split("/").last()
return networkDataSource.getAnimeInfo(animeId, animeTitle)
}

suspend fun makeSearch(search: String) {
currentSearchQuery = search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import androidx.lifecycle.MutableLiveData
import com.fmaldonado.akiyama.data.models.content.Anime
import com.fmaldonado.akiyama.data.persistence.dao.FavoritesDao
import com.fmaldonado.akiyama.data.persistence.mappers.FavoritesMapper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -16,6 +19,12 @@ constructor(
private var _favorites = mutableListOf<Anime>()
val favorites = MutableLiveData<List<Anime>>()

init {
GlobalScope.launch(Dispatchers.IO) {
loadFavorites()
}
}

suspend fun addFavorite(anime: Anime) {
val favorite = FavoritesMapper.animeToFavoritesMapper(anime)
favoritesDao.insertFullFavorite(favorite)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.fmaldonado.akiyama.data.repositories.videos

import android.util.Log
import com.fmaldonado.akiyama.data.models.content.Server
import com.fmaldonado.akiyama.data.models.video.ServerTypes
import com.fmaldonado.akiyama.data.models.video.VideoResponse
import com.fmaldonado.akiyama.data.network.VideoDataSource
import javax.inject.Inject

class VideoRepository
@Inject
constructor(
private val videoDataSource: VideoDataSource
) {

suspend fun getVideoUrl(server: Server): VideoResponse {
return when (server.server) {
ServerTypes.GoCdn.value -> getGoCdnVideo(server.code)
ServerTypes.Fembed.value -> getFembedVideo(server.code)
else -> VideoResponse(server.code, true)
}
}

suspend fun getGoCdnVideo(url: String): VideoResponse {
val value = url.split("#").last()
return videoDataSource.fetchGocdnVideo(value)
}

suspend fun getFembedVideo(url: String): VideoResponse {
val value = url.split("/").last()
return videoDataSource.fetchFembedVideo(value)
}

suspend fun getStapeVideo(url: String): VideoResponse {
videoDataSource.fetchStapeVideo(url)
return VideoResponse("")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fmaldonado.akiyama.BuildConfig
import com.fmaldonado.akiyama.data.network.LatestVersionDataSource
import com.fmaldonado.akiyama.data.network.NetworkDataSource
import com.fmaldonado.akiyama.data.network.interceptor.NetworkInterceptor
import com.google.gson.Gson
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -62,4 +63,8 @@ object NetworkModule {
@Provides
fun provideNetworkInterceptor(): NetworkInterceptor = NetworkInterceptor()

@Singleton
@Provides
fun provideGson(): Gson = Gson()

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.fmaldonado.akiyama.ui.activities.animeDetail.adapters.EpisodesAdapter
import com.fmaldonado.akiyama.ui.activities.animeDetail.adapters.GenresAdapter
import com.fmaldonado.akiyama.ui.common.FavoritesStatus
import com.fmaldonado.akiyama.ui.common.ParcelableKeys
import com.fmaldonado.akiyama.ui.common.Status
import com.fmaldonado.akiyama.ui.common.fragments.serverBottomSheet.ServersBottomSheet
import com.google.android.material.snackbar.Snackbar
import com.xwray.groupie.GroupieAdapter
Expand Down Expand Up @@ -49,7 +50,6 @@ class AnimeDetailActivity : AppCompatActivity() {
else
resources.getString(R.string.finished_text)
setupGenresRecycler(it.genres)
setupEpisodesRecyler(it.episodes)
Glide.with(this)
.load(byteArray)
.centerCrop()
Expand All @@ -61,8 +61,11 @@ class AnimeDetailActivity : AppCompatActivity() {
.into(binding.animeCover)
}

binding.backButton.setOnClickListener {
finish()
binding.backButton.setOnClickListener { finish() }

binding.swipeToRefresh.setOnRefreshListener {
anime?.let { viewModel.getAnimeEpisodes(it) }
binding.swipeToRefresh.isRefreshing = false
}

binding.moreButton.setOnClickListener {
Expand Down Expand Up @@ -94,7 +97,19 @@ class AnimeDetailActivity : AppCompatActivity() {
).show()
})

viewModel.isFavorite.observe(this, { binding.isFavorite = it })
viewModel.isFavorite.observe(this, { isFavorite ->
binding.isFavorite = isFavorite
anime?.let { anime ->
if (isFavorite)
viewModel.getAnimeEpisodes(anime)
else
viewModel.setAnimeEpisodes(anime.episodes)
}
})

viewModel.episodesStatus.observe(this, { binding.episodeStatus = it })

viewModel.episodes.observe(this, { setupEpisodesRecyler(it) })


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.fmaldonado.akiyama.data.models.content.Anime
import com.fmaldonado.akiyama.data.models.content.Episode
import com.fmaldonado.akiyama.data.repositories.anime.AnimeRepository
import com.fmaldonado.akiyama.data.repositories.favorites.FavoritesRepository
import com.fmaldonado.akiyama.ui.common.FavoritesStatus
import com.fmaldonado.akiyama.ui.common.Status
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -17,22 +20,51 @@ import javax.inject.Inject
class AnimeDetailViewModel
@Inject
constructor(
private val favoritesRepository: FavoritesRepository
private val favoritesRepository: FavoritesRepository,
private val animeRepository: AnimeRepository
) : ViewModel() {

val showToast = MutableLiveData<FavoritesStatus>()

var gettingFavorite = true
val isFavorite = MutableLiveData<Boolean>(false)

val episodes = MutableLiveData<List<Episode>>()
val episodesStatus = MutableLiveData(Status.Loading)

fun getIsFavorite(animeId: String) {
viewModelScope.launch {
try {
gettingFavorite = true
isFavorite.postValue(favoritesRepository.isFavorite(animeId))
gettingFavorite = false
} catch (e: Exception) {
Log.d("AnimeDetailVieModel", "Error get favorite", e)
}
}
}

fun getAnimeEpisodes(anime: Anime) {
episodesStatus.postValue(Status.Loading)
viewModelScope.launch(Dispatchers.IO) {
try {
val info = animeRepository.getAnimeInfo(anime.id, anime.title)
setAnimeEpisodes(info.episodes)
} catch (e: Exception) {
Log.e("Error", "Error", e)
setAnimeEpisodes(anime.episodes)
}
}
}

fun setAnimeEpisodes(episodes: List<Episode>) {
if (gettingFavorite)
return

this.episodes.postValue(episodes)
episodesStatus.postValue(Status.Loaded)
}

fun addFavorite(anime: Anime) {
viewModelScope.launch(Dispatchers.IO) {
try {
Expand All @@ -49,7 +81,7 @@ constructor(

}
} catch (e: Exception) {
Log.e("E","error",e)
Log.e("E", "error", e)
showToast.postValue(FavoritesStatus.Error)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class FavoritesFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.getFavorites()
viewModel.favorites.observe(viewLifecycleOwner, {
when (it.isEmpty()) {
true -> viewModel.currentStatus.value = Status.Empty
Expand Down
Loading

0 comments on commit b99b791

Please sign in to comment.