diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt index 69fd1b51a..e73e4f945 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDetailsController.kt @@ -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) { - addPreferencesForSource(screen, source, multiSource) + try { + addPreferencesForSource(screen, source, multiSource) + } catch (e: AbstractMethodError) { + Timber.e("Source did not implement [addPreferencesForSource]: ${source.name}") + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index a2632b469..a69ce7993 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -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) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index 318a44ec4..8c3ac34ef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index be08c93bb..af7dba3cf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 6bff0a3cc..a34245726 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 8f9e087b7..2e069de7b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -264,8 +264,10 @@ class MainActivity : BaseActivity() { 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() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 924951176..ced45dc86 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/Pager.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/Pager.kt index b89bc9ee0..85fa20621 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/Pager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/Pager.kt @@ -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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 8c704b396..6fc503aa8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index b4a6c9d69..8af6e3028 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -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)) { - val intent = Intent().apply { - action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS - data = Uri.parse("package:$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) } - startActivity(intent) } else { context.toast(R.string.battery_optimization_disabled) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index b47f031c3..b4b2da228 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -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() { @SuppressLint("SetJavaScriptEnabled") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - binding = WebviewActivityBinding.inflate(layoutInflater) - setContentView(binding.root) + + 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) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65bf5ae51..6a1419100 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -356,6 +356,7 @@ Disable battery optimization Helps with background library updates and backups Battery optimization is already disabled + Couldn\'t open device settings Website