|
|
|
@ -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) { |
|
|
|
|