forked from recloudstream/cloudstream
fixed crash issue and poster and download bar
This commit is contained in:
parent
c4328ccd3c
commit
2f7f4a06a7
7 changed files with 107 additions and 119 deletions
|
@ -35,6 +35,7 @@ import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
||||||
import com.lagradost.cloudstream3.ui.APIRepository
|
import com.lagradost.cloudstream3.ui.APIRepository
|
||||||
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.removeKey
|
import com.lagradost.cloudstream3.utils.DataStore.removeKey
|
||||||
|
@ -117,15 +118,27 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
try {
|
||||||
|
if(isCastApiAvailable()) {
|
||||||
mCastSession = mSessionManager.currentCastSession
|
mCastSession = mSessionManager.currentCastSession
|
||||||
mSessionManager.addSessionManagerListener(mSessionManagerListener)
|
mSessionManager.addSessionManagerListener(mSessionManagerListener)
|
||||||
}
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
try {
|
||||||
|
if(isCastApiAvailable()) {
|
||||||
mSessionManager.removeSessionManagerListener(mSessionManagerListener)
|
mSessionManager.removeSessionManagerListener(mSessionManagerListener)
|
||||||
mCastSession = null
|
mCastSession = null
|
||||||
}
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var canEnterPipMode: Boolean = false
|
var canEnterPipMode: Boolean = false
|
||||||
|
@ -188,7 +201,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
fun Context.updateLocale() {
|
fun Context.updateLocale() {
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
val localeCode = settingsManager.getString(getString(R.string.locale_key), null)
|
val localeCode = settingsManager.getString(getString(R.string.locale_key), null)
|
||||||
println("LOCALE: " + localeCode)
|
|
||||||
setLocale(this, localeCode)
|
setLocale(this, localeCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,43 +231,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun AppCompatActivity.backPressed(): Boolean {
|
|
||||||
/*val currentFragment = supportFragmentManager.fragments.last {
|
|
||||||
it.isVisible
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentFragment is NavHostFragment) {
|
|
||||||
val child = currentFragment.childFragmentManager.fragments.last {
|
|
||||||
it.isVisible
|
|
||||||
}
|
|
||||||
if (child is DownloadChildFragment) {
|
|
||||||
val navController = findNavController(R.id.nav_host_fragment)
|
|
||||||
navController.navigate(R.id.navigation_downloads, Bundle(), navOptions)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if (child is SearchFragment || child is HomeFragment || child is DownloadFragment || child is SettingsFragment) {
|
|
||||||
this.finish()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentFragment != null && supportFragmentManager.fragments.size > 2) {
|
|
||||||
//MainActivity.showNavbar()
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.pop_enter, R.anim.pop_exit)
|
|
||||||
.remove(currentFragment)
|
|
||||||
.commitAllowingStateLoss()
|
|
||||||
backEvent.invoke(true)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
backEvent.invoke(false)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
this.updateLocale()
|
this.updateLocale()
|
||||||
if (backPressed()) return
|
backEvent.invoke(true)
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
this.updateLocale()
|
this.updateLocale()
|
||||||
}
|
}
|
||||||
|
@ -315,7 +293,13 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
) // THEME IS SET BEFORE VIEW IS CREATED TO APPLY THE THEME TO THE MAIN VIEW
|
) // THEME IS SET BEFORE VIEW IS CREATED TO APPLY THE THEME TO THE MAIN VIEW
|
||||||
updateLocale()
|
updateLocale()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
try {
|
||||||
|
if(isCastApiAvailable()) {
|
||||||
mSessionManager = CastContext.getSharedInstance(this).sessionManager
|
mSessionManager = CastContext.getSharedInstance(this).sessionManager
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
|
|
||||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class AllMoviesForYouProvider : MainAPI() {
|
||||||
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()?.times(10)?.toInt()
|
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()?.times(10)?.toInt()
|
||||||
val year = document.selectFirst("span.Date")?.text()
|
val year = document.selectFirst("span.Date")?.text()
|
||||||
val duration = document.selectFirst("span.Time").text()
|
val duration = document.selectFirst("span.Time").text()
|
||||||
val backgroundPoster = fixUrl(document.selectFirst("div.Image > figure > img").attr("src"))
|
val backgroundPoster = fixUrl(document.selectFirst("div.Image > figure > img").attr("data-src"))
|
||||||
|
|
||||||
if (type == TvType.TvSeries) {
|
if (type == TvType.TvSeries) {
|
||||||
val list = ArrayList<Pair<Int, String>>()
|
val list = ArrayList<Pair<Int, String>>()
|
||||||
|
|
|
@ -14,7 +14,6 @@ import android.widget.TextView
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
|
|
|
@ -53,6 +53,7 @@ class HomeViewModel : ViewModel() {
|
||||||
val resumeWatching: LiveData<List<SearchResponse>> = _resumeWatching
|
val resumeWatching: LiveData<List<SearchResponse>> = _resumeWatching
|
||||||
|
|
||||||
fun loadResumeWatching(context: Context) = viewModelScope.launch {
|
fun loadResumeWatching(context: Context) = viewModelScope.launch {
|
||||||
|
println("Resume::")
|
||||||
val resumeWatching = withContext(Dispatchers.IO) {
|
val resumeWatching = withContext(Dispatchers.IO) {
|
||||||
context.getAllResumeStateIds().mapNotNull { id ->
|
context.getAllResumeStateIds().mapNotNull { id ->
|
||||||
context.getLastWatched(id)
|
context.getLastWatched(id)
|
||||||
|
|
|
@ -70,10 +70,7 @@ import com.lagradost.cloudstream3.MainActivity.Companion.canEnterPipMode
|
||||||
import com.lagradost.cloudstream3.MainActivity.Companion.isInPIPMode
|
import com.lagradost.cloudstream3.MainActivity.Companion.isInPIPMode
|
||||||
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
|
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.mvvm.Resource
|
import com.lagradost.cloudstream3.mvvm.*
|
||||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
|
||||||
import com.lagradost.cloudstream3.mvvm.observe
|
|
||||||
import com.lagradost.cloudstream3.mvvm.observeDirectly
|
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultViewModel
|
import com.lagradost.cloudstream3.ui.result.ResultViewModel
|
||||||
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
|
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
|
||||||
|
@ -1046,6 +1043,7 @@ class PlayerFragment : Fragment() {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (activity?.isCastApiAvailable() == true && !isDownloadedFile) {
|
if (activity?.isCastApiAvailable() == true && !isDownloadedFile) {
|
||||||
|
try {
|
||||||
CastButtonFactory.setUpMediaRouteButton(activity, player_media_route_button)
|
CastButtonFactory.setUpMediaRouteButton(activity, player_media_route_button)
|
||||||
val castContext = CastContext.getSharedInstance(requireContext())
|
val castContext = CastContext.getSharedInstance(requireContext())
|
||||||
|
|
||||||
|
@ -1120,6 +1118,9 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isDownloadedFile = false
|
isDownloadedFile = false
|
||||||
|
|
|
@ -17,7 +17,6 @@ import android.view.View.VISIBLE
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
|
@ -37,8 +36,8 @@ import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
||||||
import com.lagradost.cloudstream3.APIHolder.getId
|
import com.lagradost.cloudstream3.APIHolder.getId
|
||||||
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
|
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
|
||||||
import com.lagradost.cloudstream3.MainActivity.Companion.updateLocale
|
|
||||||
import com.lagradost.cloudstream3.mvvm.Resource
|
import com.lagradost.cloudstream3.mvvm.Resource
|
||||||
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.mvvm.observe
|
import com.lagradost.cloudstream3.mvvm.observe
|
||||||
import com.lagradost.cloudstream3.ui.WatchType
|
import com.lagradost.cloudstream3.ui.WatchType
|
||||||
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
|
||||||
|
@ -304,6 +303,7 @@ class ResultFragment : Fragment() {
|
||||||
|
|
||||||
activity?.let {
|
activity?.let {
|
||||||
if (it.isCastApiAvailable()) {
|
if (it.isCastApiAvailable()) {
|
||||||
|
try {
|
||||||
CastButtonFactory.setUpMediaRouteButton(it, media_route_button)
|
CastButtonFactory.setUpMediaRouteButton(it, media_route_button)
|
||||||
val castContext = CastContext.getSharedInstance(it.applicationContext)
|
val castContext = CastContext.getSharedInstance(it.applicationContext)
|
||||||
|
|
||||||
|
@ -315,6 +315,9 @@ class ResultFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
logError(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,7 @@ object VideoDownloadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) {
|
if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) {
|
||||||
builder.setProgress(total.toInt(), progress.toInt(), false)
|
builder.setProgress((total / 1000).toInt(), (progress / 1000).toInt(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val rowTwoExtra = if (ep.name != null) " - ${ep.name}\n" else ""
|
val rowTwoExtra = if (ep.name != null) " - ${ep.name}\n" else ""
|
||||||
|
|
Loading…
Reference in a new issue