Bunch of crash fixes
This commit is contained in:
parent
6cd34614f6
commit
ce0090f0ca
@ -35,6 +35,7 @@ import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
import timber.log.Timber
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||
@ -97,7 +98,11 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||
|
||||
for (source in extension.sources) {
|
||||
if (source is ConfigurableSource) {
|
||||
try {
|
||||
addPreferencesForSource(screen, source, multiSource)
|
||||
} catch (e: AbstractMethodError) {
|
||||
Timber.e("Source did not implement [addPreferencesForSource]: ${source.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,10 +113,14 @@ class SourceController :
|
||||
}
|
||||
|
||||
override fun onItemClick(view: View, position: Int): Boolean {
|
||||
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
||||
onItemClick(position)
|
||||
return false
|
||||
}
|
||||
|
||||
private fun onItemClick(position: Int) {
|
||||
val item = adapter?.getItem(position) as? SourceItem ?: return
|
||||
val source = item.source
|
||||
openCatalogue(source, BrowseSourceController(source))
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onItemLongClick(position: Int) {
|
||||
@ -165,7 +169,7 @@ class SourceController :
|
||||
* Called when browse is clicked in [SourceAdapter]
|
||||
*/
|
||||
override fun onBrowseClick(position: Int) {
|
||||
onItemClick(view!!, position)
|
||||
onItemClick(position)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,8 +41,8 @@ import uy.kohesive.injekt.api.get
|
||||
* Presenter of [BrowseSourceController].
|
||||
*/
|
||||
open class BrowseSourcePresenter(
|
||||
sourceId: Long,
|
||||
sourceManager: SourceManager = Injekt.get(),
|
||||
private val sourceId: Long,
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val db: DatabaseHelper = Injekt.get(),
|
||||
private val prefs: PreferencesHelper = Injekt.get(),
|
||||
private val coverCache: CoverCache = Injekt.get()
|
||||
@ -51,7 +51,7 @@ open class BrowseSourcePresenter(
|
||||
/**
|
||||
* Selected source.
|
||||
*/
|
||||
val source = sourceManager.get(sourceId) as CatalogueSource
|
||||
lateinit var source: CatalogueSource
|
||||
|
||||
/**
|
||||
* Query from the view.
|
||||
@ -109,6 +109,8 @@ open class BrowseSourcePresenter(
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
|
||||
source = sourceManager.get(sourceId) as? CatalogueSource ?: return
|
||||
|
||||
sourceFilters = source.getFilterList()
|
||||
|
||||
if (savedState != null) {
|
||||
|
@ -302,13 +302,13 @@ class DownloadController :
|
||||
override fun onMenuItemClick(position: Int, menuItem: MenuItem) {
|
||||
when (menuItem.itemId) {
|
||||
R.id.move_to_top, R.id.move_to_bottom -> {
|
||||
val download = adapter?.getItem(position) ?: return
|
||||
val items = adapter?.currentItems?.toMutableList() ?: return
|
||||
val item = items[position]
|
||||
items.remove(item)
|
||||
items.remove(download)
|
||||
if (menuItem.itemId == R.id.move_to_top) {
|
||||
items.add(0, item)
|
||||
items.add(0, download)
|
||||
} else {
|
||||
items.add(item)
|
||||
items.add(download)
|
||||
}
|
||||
|
||||
val adapter = adapter ?: return
|
||||
|
@ -318,7 +318,7 @@ class LibraryController(
|
||||
binding.actionToolbar.show(
|
||||
actionMode!!,
|
||||
R.menu.library_selection
|
||||
) { onActionItemClicked(actionMode!!, it!!) }
|
||||
) { onActionItemClicked(it!!) }
|
||||
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
|
||||
}
|
||||
}
|
||||
@ -419,6 +419,10 @@ class LibraryController(
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return onActionItemClicked(item)
|
||||
}
|
||||
|
||||
private fun onActionItemClicked(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_edit_cover -> {
|
||||
changeSelectedCover()
|
||||
|
@ -264,8 +264,10 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding.bottomNav.setOnNavigationItemSelectedListener(null)
|
||||
binding.toolbar.setNavigationOnClickListener(null)
|
||||
|
||||
// Binding sometimes isn't actually instantiated yet somehow
|
||||
binding?.bottomNav.setOnNavigationItemSelectedListener(null)
|
||||
binding?.toolbar.setNavigationOnClickListener(null)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
|
@ -86,6 +86,9 @@ class ChaptersController :
|
||||
override fun onViewCreated(view: View) {
|
||||
super.onViewCreated(view)
|
||||
|
||||
val ctrl = parentController as MangaController
|
||||
if (ctrl.manga == null || ctrl.source == null) return
|
||||
|
||||
// Init RecyclerView and adapter
|
||||
adapter = ChaptersAdapter(this, view.context)
|
||||
|
||||
@ -379,7 +382,7 @@ class ChaptersController :
|
||||
binding.actionToolbar.show(
|
||||
actionMode!!,
|
||||
R.menu.chapter_selection
|
||||
) { onActionItemClicked(actionMode!!, it!!) }
|
||||
) { onActionItemClicked(it!!) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,6 +421,10 @@ class ChaptersController :
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return onActionItemClicked(item)
|
||||
}
|
||||
|
||||
private fun onActionItemClicked(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_select_all -> selectAll()
|
||||
R.id.action_select_inverse -> selectInverse()
|
||||
|
@ -84,6 +84,8 @@ open class Pager(
|
||||
override fun onTouchEvent(ev: MotionEvent): Boolean {
|
||||
return try {
|
||||
super.onTouchEvent(ev)
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
false
|
||||
} catch (e: IllegalArgumentException) {
|
||||
false
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ class UpdatesController :
|
||||
binding.actionToolbar.show(
|
||||
actionMode!!,
|
||||
R.menu.updates_chapter_selection
|
||||
) { onActionItemClicked(actionMode!!, it!!) }
|
||||
) { onActionItemClicked(it!!) }
|
||||
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
|
||||
}
|
||||
|
||||
@ -333,6 +333,10 @@ class UpdatesController :
|
||||
* @param item item from ActionMode.
|
||||
*/
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return onActionItemClicked(item)
|
||||
}
|
||||
|
||||
private fun onActionItemClicked(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_select_all -> selectAll()
|
||||
R.id.action_select_inverse -> selectInverse()
|
||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context.POWER_SERVICE
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
@ -97,11 +98,15 @@ class SettingsAdvancedController : SettingsController() {
|
||||
val packageName: String = context.packageName
|
||||
val pm = context.getSystemService(POWER_SERVICE) as PowerManager?
|
||||
if (!pm!!.isIgnoringBatteryOptimizations(packageName)) {
|
||||
try {
|
||||
val intent = Intent().apply {
|
||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
data = Uri.parse("package:$packageName")
|
||||
}
|
||||
startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
context.toast(R.string.battery_optimization_setting_activity_not_found)
|
||||
}
|
||||
} else {
|
||||
context.toast(R.string.battery_optimization_disabled)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import eu.kanade.tachiyomi.ui.main.ForceCloseActivity
|
||||
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||
@ -38,8 +39,14 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
try {
|
||||
binding = WebviewActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
} catch (e: Exception) {
|
||||
// Potentially throws errors like "Error inflating class android.webkit.WebView"
|
||||
ForceCloseActivity.closeApp(this)
|
||||
}
|
||||
|
||||
title = intent.extras?.getString(TITLE_KEY)
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
@ -356,6 +356,7 @@
|
||||
<string name="pref_disable_battery_optimization">Disable battery optimization</string>
|
||||
<string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string>
|
||||
<string name="battery_optimization_disabled">Battery optimization is already disabled</string>
|
||||
<string name="battery_optimization_setting_activity_not_found">Couldn\'t open device settings</string>
|
||||
|
||||
<!-- About section -->
|
||||
<string name="website">Website</string>
|
||||
|
Loading…
Reference in New Issue
Block a user