diff --git a/app/src/main/java/io/legado/app/base/BaseFragment.kt b/app/src/main/java/io/legado/app/base/BaseFragment.kt index 1f3ff2dcb..d870939d0 100644 --- a/app/src/main/java/io/legado/app/base/BaseFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseFragment.kt @@ -1,29 +1,40 @@ package io.legado.app.base -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem +import android.os.Bundle +import android.view.* import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import io.legado.app.utils.applyTint import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.MainScope -import kotlinx.coroutines.cancel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlin.coroutines.CoroutineContext abstract class BaseFragment(layoutID: Int) : Fragment(layoutID), - CoroutineScope by MainScope() { - + CoroutineScope { + lateinit var job: Job var supportToolbar: Toolbar? = null private set val menuInflater: MenuInflater get() = SupportMenuInflater(requireContext()) + override val coroutineContext: CoroutineContext + get() = job + Dispatchers.Main + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + job = Job() + return super.onCreateView(inflater, container, savedInstanceState) + } override fun onDestroy() { super.onDestroy() - cancel() + job.cancel() } fun setSupportToolbar(toolbar: Toolbar) {