From bc665351ab629bfb5c272c7e3eb2680cb912f443 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 Dec 2019 20:59:25 +0800 Subject: [PATCH] up --- .../java/io/legado/app/base/BaseFragment.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) 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) {