Skip to content

Commit

Permalink
Fixing video player
Browse files Browse the repository at this point in the history
  • Loading branch information
kl3jvi committed Mar 20, 2022
1 parent bf023a5 commit f006ba0
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 260 deletions.
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.kl3jvi.animity.ui.adapters.testAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.ui.adapters.homeAdapter.HomeRecyclerViewItem
import kotlinx.parcelize.Parcelize

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.kl3jvi.animity.data.model.ui_models.AnimeMetaModel
import com.kl3jvi.animity.data.network.anime_service.AnimeApiClient
import com.kl3jvi.animity.utils.Constants
import com.kl3jvi.animity.utils.Constants.Companion.STARTING_PAGE_INDEX
import com.kl3jvi.animity.utils.Constants.Companion.getHeader
import com.kl3jvi.animity.utils.Constants.Companion.getNetworkHeader
import com.kl3jvi.animity.utils.parser.HtmlParser
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand All @@ -27,7 +27,7 @@ class SearchPagingSource(
val searchList = withContext(Dispatchers.IO) {
HtmlParser.parseMovie(
animeService.fetchSearchData(
header = getHeader(),
header = getNetworkHeader(),
keyword = query,
page = page
).string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.kl3jvi.animity.data.repository.fragment_repositories
import com.kl3jvi.animity.data.model.ui_models.toAnime
import com.kl3jvi.animity.data.network.anime_service.AnimeApiClient
import com.kl3jvi.animity.domain.repositories.fragment_repositories.HomeRepository
import com.kl3jvi.animity.ui.adapters.testAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.ui.adapters.homeAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_MOVIE
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_NEW_SEASON
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_POPULAR_ANIME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SearchRepositoryImpl @Inject constructor(
) : SearchRepository {

override fun fetchSearchData(
header: Map<String, String>,
keyword: String,
): Flow<PagingData<AnimeMetaModel>> {
return Pager(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kl3jvi.animity.domain.repositories.fragment_repositories

import com.kl3jvi.animity.data.model.ui_models.AnimeMetaModel
import com.kl3jvi.animity.ui.adapters.testAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.ui.adapters.homeAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.utils.parser.HtmlParser

interface HomeRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlinx.coroutines.flow.Flow

interface SearchRepository {
fun fetchSearchData(
header: Map<String, String>,
keyword: String,
): Flow<PagingData<AnimeMetaModel>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kl3jvi.animity.data.repository.fragment_repositories.DetailsRepositor
import com.kl3jvi.animity.persistence.AnimeRepository
import com.kl3jvi.animity.persistence.EpisodeDao
import com.kl3jvi.animity.utils.Constants
import com.kl3jvi.animity.utils.Constants.Companion.getNetworkHeader
import com.kl3jvi.animity.utils.Resource
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
Expand All @@ -27,7 +28,7 @@ class GetAnimeDetailsUseCase @Inject constructor(
fun fetchAnimeInfo(url: String): Flow<Resource<AnimeInfoModel>> = flow {
try {
emit(Resource.Loading())
val response = detailsRepository.fetchAnimeInfo(Constants.getHeader(), url)
val response = detailsRepository.fetchAnimeInfo(getNetworkHeader(), url)
emit(
Resource.Success(
data = response
Expand Down Expand Up @@ -56,7 +57,7 @@ class GetAnimeDetailsUseCase @Inject constructor(
try {
emit(Resource.Loading())
val response = detailsRepository.fetchEpisodeList(
header = Constants.getHeader(),
header = getNetworkHeader(),
id = id ?: "",
endEpisode = endEpisode ?: "0",
alias = alias ?: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.kl3jvi.animity.domain.use_cases

import com.kl3jvi.animity.data.repository.fragment_repositories.HomeRepositoryImpl
import com.kl3jvi.animity.ui.adapters.testAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.ui.adapters.homeAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.utils.Constants
import com.kl3jvi.animity.utils.Constants.Companion.getNetworkHeader
import com.kl3jvi.animity.utils.Resource
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.async
Expand All @@ -25,17 +26,17 @@ class GetAnimesUseCase @Inject constructor(

val recentSubDubDeferred = async {
homeRepository.fetchRecentSubOrDub(
Constants.getHeader(),
getNetworkHeader(),
1,
Constants.TYPE_RECENT_DUB
)
}
val newSeasonDeferred =
async { homeRepository.fetchNewSeason(Constants.getHeader(), 1) }
async { homeRepository.fetchNewSeason(getNetworkHeader(), 1) }
val moviesDeferred =
async { homeRepository.fetchMovies(Constants.getHeader(), 1) }
async { homeRepository.fetchMovies(getNetworkHeader(), 1) }
val popularDeferred =
async { homeRepository.fetchPopularFromAjax(Constants.getHeader(), 1) }
async { homeRepository.fetchPopularFromAjax(getNetworkHeader(), 1) }

val recentSub = recentSubDubDeferred.await()
val newSeason = newSeasonDeferred.await()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kl3jvi.animity.domain.use_cases

import android.util.Log
import com.kl3jvi.animity.data.repository.activity_repositories.PlayerRepositoryImpl
import com.kl3jvi.animity.utils.Constants
import com.kl3jvi.animity.utils.Constants.Companion.REFERER
import com.kl3jvi.animity.utils.Constants.Companion.getNetworkHeader
import com.kl3jvi.animity.utils.Resource
Expand All @@ -20,28 +20,31 @@ class GetEpisodeInfoUseCase @Inject constructor(
operator fun invoke(url: String) = flow {
emit(Resource.Loading())
try {
val response = playerRepository.fetchEpisodeMediaUrl(Constants.getHeader(), url)
val response = playerRepository.fetchEpisodeMediaUrl(getNetworkHeader(), url)
emit(Resource.Success(data = response))
} catch (e: Exception) {
emit(Resource.Error("Oops an error occurred, try again!"))
}
}.flowOn(ioDispatcher)
//

//
fun fetchM3U8(url: String?) = flow {
emit(Resource.Loading())
try {
val response = playerRepository.fetchM3u8Url(getNetworkHeader(), url ?: "")
Log.e("response", response.toString())
emit(Resource.Success(data = response.last()))
} catch (e: Exception) {
e.printStackTrace()
emit(Resource.Error("Couldn't find a Stream for this Anime"))
}
}.flowOn(ioDispatcher)
//

//
fun fetchEncryptedAjaxUrl(url: String?) = flow {
emit(Resource.Loading())
try {
val response = playerRepository.fetchEncryptedAjaxUrl(Constants.getHeader(), url ?: "")
val response = playerRepository.fetchEncryptedAjaxUrl(getNetworkHeader(), url ?: "")
val streamUrl = "${REFERER}encrypt-ajax.php?${response}"
emit(Resource.Success(data = streamUrl))
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.kl3jvi.animity.domain.use_cases
import androidx.paging.PagingData
import com.kl3jvi.animity.data.model.ui_models.AnimeMetaModel
import com.kl3jvi.animity.data.repository.fragment_repositories.SearchRepositoryImpl
import com.kl3jvi.animity.utils.Constants
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
Expand All @@ -17,9 +16,6 @@ class GetSearchResultUseCase @Inject constructor(

) {
operator fun invoke(searchQuery: String): Flow<PagingData<AnimeMetaModel>> {
return searchRepository.fetchSearchData(
Constants.getHeader(),
searchQuery
).flowOn(ioDispatcher)
return searchRepository.fetchSearchData(searchQuery).flowOn(ioDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
.appendPath("v2")
.appendPath("oauth")
.appendPath("authorize")
.appendQueryParameter("client_id", ANILIST_ID)
.appendQueryParameter("redirect_uri", REDIRECT_URI)
.appendQueryParameter("client_id", anilistid)
.appendQueryParameter("redirect_uri", redirecturi)
.appendQueryParameter("response_type", "code")
.build()
}

override fun onHandleAuthIntent(intent: Intent?) {
if (intent != null && intent.data != null) {
val uri = intent.data
if (uri.toString().startsWith(REDIRECT_URI)) {
if (uri.toString().startsWith(redirecturi)) {
val authorizationToken = uri?.getQueryParameter("code")
Log.e("AUTH TOKEN", authorizationToken.toString())
if (!authorizationToken.isNullOrEmpty()) {
collectFlow(
viewModel.getAccessToken(
grantType = AUTH_GRANT_TYPE,
clientId = ANILIST_ID.toInt(),
clientSecret = ANILIST_SECRET,
redirectUri = REDIRECT_URI,
clientId = anilistid.toInt(),
clientSecret = anilistsecret,
redirectUri = redirecturi,
authorizationToken = authorizationToken
)
) { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PlayerViewModel @Inject constructor(
fun getPlaybackPosition(episodeUrl: String): LiveData<Long> {
viewModelScope.launch(ioDispatcher) {
if (episodeDao.isEpisodeOnDatabase(episodeUrl)) {
_playBackPosition.value = episodeDao.getEpisodeContent(episodeUrl).watchedDuration
_playBackPosition.postValue(episodeDao.getEpisodeContent(episodeUrl).watchedDuration)
}
}
return _playBackPosition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kl3jvi.animity.ui.adapters.testAdapter
package com.kl3jvi.animity.ui.adapters.homeAdapter

import android.view.LayoutInflater
import android.view.ViewGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kl3jvi.animity.ui.adapters.testAdapter
package com.kl3jvi.animity.ui.adapters.homeAdapter

import android.graphics.Color
import android.view.View
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kl3jvi.animity.ui.adapters.testAdapter
package com.kl3jvi.animity.ui.adapters.homeAdapter

import com.kl3jvi.animity.data.model.ui_models.AnimeMetaModel
import com.kl3jvi.animity.data.model.ui_models.GenreModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.kl3jvi.animity.R
import com.kl3jvi.animity.databinding.FragmentHomeBinding
import com.kl3jvi.animity.ui.activities.main.MainActivity
import com.kl3jvi.animity.ui.adapters.testAdapter.HomeRecyclerViewAdapter
import com.kl3jvi.animity.ui.adapters.homeAdapter.HomeRecyclerViewAdapter
import com.kl3jvi.animity.ui.base.viewBinding
import com.kl3jvi.animity.utils.NetworkUtils.isConnectedToInternet
import com.kl3jvi.animity.utils.Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.kl3jvi.animity.domain.use_cases.GetAnimesUseCase
import com.kl3jvi.animity.ui.adapters.testAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.ui.adapters.homeAdapter.HomeRecyclerViewItem
import com.kl3jvi.animity.utils.Resource
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import android.view.*
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.apollographql.apollo3.api.ApolloResponse
import com.kl3jvi.animity.AnimeListCollectionQuery
import com.kl3jvi.animity.R
Expand All @@ -17,7 +14,6 @@ import com.kl3jvi.animity.databinding.FragmentProfileGuestBinding
import com.kl3jvi.animity.ui.activities.login.LoginActivity
import com.kl3jvi.animity.ui.activities.main.MainActivity
import com.kl3jvi.animity.ui.base.BaseFragment
import com.kl3jvi.animity.utils.Constants.Companion.DEFAULT_COVER
import com.kl3jvi.animity.utils.NetworkUtils.isConnectedToInternet
import com.kl3jvi.animity.utils.hide
import com.kl3jvi.animity.utils.launchActivity
Expand Down Expand Up @@ -64,18 +60,18 @@ class ProfileFragment : BaseFragment<ProfileViewModel, FragmentProfileBinding>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.spinner.onItemSelectedListener = this
// binding.spinner.onItemSelectedListener = this
}


private fun getProfileData() {
observeLiveData(viewModel.profileData, viewLifecycleOwner) {
binding.bgImage.load(
if (it.data?.user?.bannerImage.isNullOrEmpty())
DEFAULT_COVER
else
it.data?.user?.bannerImage
)
// binding.bgImage.load(
// if (it.data?.user?.bannerImage.isNullOrEmpty())
// DEFAULT_COVER
// else
// it.data?.user?.bannerImage
// )
binding.userData = it.data
}
}
Expand All @@ -84,11 +80,11 @@ class ProfileFragment : BaseFragment<ProfileViewModel, FragmentProfileBinding>()
observeLiveData(viewModel.animeList, viewLifecycleOwner) { animeCollectionResponse ->
binding.animeData = animeCollectionResponse.data
animeCollectionResponseGlobal = animeCollectionResponse
val animeRecyclerView = binding.watchedAnime
animeRecyclerView.layoutManager = LinearLayoutManager(
requireContext(),
RecyclerView.HORIZONTAL, false
)
// val animeRecyclerView = binding.watchedAnime
// animeRecyclerView.layoutManager = LinearLayoutManager(
// requireContext(),
// RecyclerView.HORIZONTAL, false
// )

animeCollectionResponse.data?.media?.lists?.toList()?.let { addSpinnerItems(it) }

Expand All @@ -115,15 +111,15 @@ class ProfileFragment : BaseFragment<ProfileViewModel, FragmentProfileBinding>()

private fun addSpinnerItems(passedArray: List<AnimeListCollectionQuery.List?>) {
val list = passedArray.map { it?.name }
val spinner = binding.spinner
// val spinner = binding.spinner
val spinnerArrayAdapter: ArrayAdapter<String> =
ArrayAdapter<String>(
requireContext(), R.layout.spinner_item,
R.id.textView2,
list
) //selected item will look like a spinner set from XML
spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item)
spinner.adapter = spinnerArrayAdapter
// spinner.adapter = spinnerArrayAdapter


}
Expand Down Expand Up @@ -166,11 +162,11 @@ class ProfileFragment : BaseFragment<ProfileViewModel, FragmentProfileBinding>()
private fun handleNetworkChanges() {
requireActivity().isConnectedToInternet(viewLifecycleOwner) { isConnected ->
if (!isGuestLogin() && isConnected) {
binding.hasInternet.show()
// binding.hasInternet.show()
binding.noInternet.hide()
} else {
binding.noInternet.show()
binding.hasInternet.hide()
// binding.hasInternet.hide()
}
}
}
Expand Down
Loading

0 comments on commit f006ba0

Please sign in to comment.