Skip to content

Commit

Permalink
Merge pull request #85 from anilibria/fix/new-crashes
Browse files Browse the repository at this point in the history
Fix/new crashes
  • Loading branch information
RadiationX authored Dec 28, 2022
2 parents 1f24b5c + 1bb4e0b commit b1af202
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.devbrackets.android.exomedia.ui.widget.VideoControlsCore
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.analytics.AnalyticsListener
import com.google.android.exoplayer2.source.MediaSourceEventListener
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -162,6 +163,8 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {

private var pictureInPictureParams: PictureInPictureParams.Builder? = null

private var releaseDataJob: Job? = null

private fun getStatisticByDomain(host: String): MutableList<Pair<AnalyticsQuality, Long>> {
if (!loadingStatistics.contains(host)) {
loadingStatistics[host] = mutableListOf()
Expand Down Expand Up @@ -305,10 +308,6 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {
}
handleIntent(intent)
updateUiFlags()

releaseInteractor.observeFull(releaseData.id, releaseData.code).onEach {
releaseData = it
}.launchIn(lifecycleScope)
}

override fun onNewIntent(intent: Intent?) {
Expand Down Expand Up @@ -346,6 +345,10 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {
binding.player.setOnCompletionListener(null)
binding.player.setOnVideoSizedChangedListener(null)
binding.player.setAnalyticsListener(null)
try {
unregisterReceiver(mReceiver)
} catch (ignore: Exception) {
}

videoControls?.apply {
setOpeningListener(null)
Expand Down Expand Up @@ -400,6 +403,11 @@ class MyPlayerActivity : BaseActivity(R.layout.activity_myplayer) {
this.currentEpisodeId = episodeId
this.currentQuality = quality
this.playFlag = playFlag

releaseDataJob?.cancel()
releaseDataJob = releaseInteractor.observeFull(releaseData.id, releaseData.code).onEach {
releaseData = it
}.launchIn(lifecycleScope)
}

private fun handleIntent(intent: Intent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.view.*
import androidx.core.view.WindowCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import by.kirich1409.viewbindingdelegate.viewBinding
Expand All @@ -20,7 +23,6 @@ import ru.radiationx.anilibria.R
import ru.radiationx.anilibria.databinding.ActivityMainBinding
import ru.radiationx.anilibria.di.LocaleModule
import ru.radiationx.anilibria.extension.disableItemChangeAnimation
import ru.radiationx.shared.ktx.android.getCompatColor
import ru.radiationx.anilibria.navigation.BaseAppScreen
import ru.radiationx.anilibria.navigation.Screens
import ru.radiationx.anilibria.ui.activities.BaseActivity
Expand All @@ -41,6 +43,7 @@ import ru.radiationx.data.system.LocaleHolder
import ru.radiationx.quill.inject
import ru.radiationx.quill.installModules
import ru.radiationx.quill.viewModel
import ru.radiationx.shared.ktx.android.getCompatColor
import ru.radiationx.shared.ktx.android.gone
import ru.radiationx.shared.ktx.android.immutableFlag
import ru.radiationx.shared.ktx.android.visible
Expand Down Expand Up @@ -137,13 +140,19 @@ class MainActivity : BaseActivity(R.layout.activity_main) {
highlightTab(it)
}.launchIn(lifecycleScope)

viewModel.state.map { it.needConfig }.distinctUntilChanged().onEach {
if (it) {
showConfiguring()
} else {
hideConfiguring()
// lifecycle needs for fragment manager
viewModel.state
.map { it.needConfig }
.distinctUntilChanged()
.flowWithLifecycle(lifecycle, Lifecycle.State.RESUMED)
.onEach {
if (it) {
showConfiguring()
} else {
hideConfiguring()
}
}
}.launchIn(lifecycleScope)
.launchIn(lifecycleScope)

viewModel.state.map { it.mainLogicCompleted }.filter { it }.distinctUntilChanged().onEach {
onMainLogicCompleted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VkCommentsFragment : BaseDimensionsFragment(R.layout.fragment_vk_comments)

viewModel.reloadEvent.onEach {
binding.webView.reload()
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

override fun onSaveInstanceState(outState: Bundle) {
Expand All @@ -138,8 +138,11 @@ class VkCommentsFragment : BaseDimensionsFragment(R.layout.fragment_vk_comments)
}

override fun onDestroyView() {
binding.webView.endWork()
super.onDestroyView()
binding.webView.endWork()
binding.webView.setJsLifeCycleListener(null)
binding.webView.webViewClient = WebViewClient()
binding.webView.webChromeClient = WebChromeClient()
}

private fun showState(state: VkCommentsScreenState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ class PageFragment : BaseToolbarFragment<FragmentWebviewBinding>(R.layout.fragme
}
}

override fun onDestroyView() {
super.onDestroyView()
binding.webView.endWork()
binding.webView.setJsLifeCycleListener(null)
binding.webView.webViewClient = WebViewClient()
binding.webView.webChromeClient = WebChromeClient()
}

override fun onDomContentComplete(actions: ArrayList<String>) {

}
Expand Down
1 change: 0 additions & 1 deletion lapism-search/src/main/res/layout/search_menu_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">

<!-- TODO -->
Expand Down

0 comments on commit b1af202

Please sign in to comment.