Skip to content

Commit

Permalink
Cleanup web view binding on destroy view
Browse files Browse the repository at this point in the history
  • Loading branch information
sictiru committed Jun 27, 2024
1 parent 71233a0 commit 7d472de
Showing 1 changed file with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.newsblur.fragment

import android.content.*
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Typeface
Expand All @@ -9,8 +11,12 @@ import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.*
import android.view.ContextMenu
import android.view.ContextMenu.ContextMenuInfo
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView.HitTestResult
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.PopupMenu
Expand Down Expand Up @@ -38,8 +44,20 @@ import com.newsblur.service.NbSyncManager.UPDATE_SOCIAL
import com.newsblur.service.NbSyncManager.UPDATE_STORY
import com.newsblur.service.NbSyncManager.UPDATE_TEXT
import com.newsblur.service.OriginalTextService
import com.newsblur.util.*
import com.newsblur.util.DefaultFeedView
import com.newsblur.util.FeedSet
import com.newsblur.util.FeedUtils
import com.newsblur.util.FileCache
import com.newsblur.util.Font
import com.newsblur.util.ImageLoader
import com.newsblur.util.MarkStoryReadBehavior
import com.newsblur.util.PrefConstants.ThemeValue
import com.newsblur.util.PrefsUtils
import com.newsblur.util.ReadingTextSize
import com.newsblur.util.StoryChangesState
import com.newsblur.util.StoryUtils
import com.newsblur.util.UIUtils
import com.newsblur.util.executeAsyncTask
import dagger.hilt.android.AndroidEntryPoint
import java.util.regex.Pattern
import javax.inject.Inject
Expand Down Expand Up @@ -104,8 +122,11 @@ class ReadingItemFragment : NbFragment(), PopupMenu.OnMenuItemClickListener {
private var savedScrollPosRel = 0f
private val webViewContentMutex = Any()

private lateinit var binding: FragmentReadingitemBinding
private lateinit var readingItemActionsBinding: ReadingItemActionsBinding
private var _binding: FragmentReadingitemBinding? = null
private var _readingItemActionsBinding: ReadingItemActionsBinding? = null
private val binding get() = _binding!!
private val readingItemActionsBinding get() = _readingItemActionsBinding!!


private lateinit var markStoryReadBehavior: MarkStoryReadBehavior
private var sampledQueue: SampledQueue? = null
Expand Down Expand Up @@ -145,16 +166,11 @@ class ReadingItemFragment : NbFragment(), PopupMenu.OnMenuItemClickListener {

override fun onDestroyView() {
sampledQueue?.close()
_readingItemActionsBinding = null
_binding = null
super.onDestroyView()
}

override fun onDestroy() {
binding.readingWebview.setOnTouchListener(null)
binding.root.setOnTouchListener(null)
requireActivity().window.decorView.setOnSystemUiVisibilityChangeListener(null)
super.onDestroy()
}

// WebViews don't automatically pause content like audio and video when they lose focus. Chain our own
// state into the webview so it behaves.
override fun onPause() {
Expand All @@ -169,9 +185,8 @@ class ReadingItemFragment : NbFragment(), PopupMenu.OnMenuItemClickListener {
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_readingitem, container, false)
binding = FragmentReadingitemBinding.bind(view)
readingItemActionsBinding = ReadingItemActionsBinding.bind(binding.root)
_binding = FragmentReadingitemBinding.inflate(inflater, container, false)
_readingItemActionsBinding = ReadingItemActionsBinding.bind(binding.root)

val readingActivity = requireActivity() as Reading
fs = readingActivity.fs
Expand All @@ -194,7 +209,7 @@ class ReadingItemFragment : NbFragment(), PopupMenu.OnMenuItemClickListener {

binding.readingScrollview.registerScrollChangeListener(readingActivity)

return view
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down

0 comments on commit 7d472de

Please sign in to comment.