From 27bac4fffb782119dc7964f43dbd13dc1c7d3f82 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 22 Jul 2022 22:46:53 -0400 Subject: [PATCH] Remove unused legacy ActionModeWithToolbar --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 6 - .../tachiyomi/widget/ActionModeWithToolbar.kt | 169 ------------------ .../res/layout-sw720dp/action_toolbar.xml | 40 ----- .../main/res/layout-sw720dp/main_activity.xml | 6 - app/src/main/res/layout/action_toolbar.xml | 27 --- app/src/main/res/layout/main_activity.xml | 6 - 6 files changed, 254 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/ActionModeWithToolbar.kt delete mode 100644 app/src/main/res/layout-sw720dp/action_toolbar.xml delete mode 100644 app/src/main/res/layout/action_toolbar.xml 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 57e901a01..e4a28a822 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 @@ -68,7 +68,6 @@ import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat -import eu.kanade.tachiyomi.widget.ActionModeWithToolbar import kotlinx.coroutines.delay import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.launchIn @@ -533,11 +532,6 @@ class MainActivity : BaseActivity() { super.onSupportActionModeFinished(mode) } - fun startActionModeAndToolbar(modeCallback: ActionModeWithToolbar.Callback): ActionModeWithToolbar { - binding.actionToolbar.start(modeCallback) - return binding.actionToolbar - } - private suspend fun resetExitConfirmation() { isConfirmingExit = true val toast = toast(R.string.confirm_exit, Toast.LENGTH_LONG) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ActionModeWithToolbar.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ActionModeWithToolbar.kt deleted file mode 100644 index 0cd50e5b7..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ActionModeWithToolbar.kt +++ /dev/null @@ -1,169 +0,0 @@ -package eu.kanade.tachiyomi.widget - -import android.content.Context -import android.util.AttributeSet -import android.view.LayoutInflater -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem -import android.view.animation.Animation -import android.view.animation.AnimationUtils -import android.widget.FrameLayout -import androidx.annotation.IdRes -import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.view.ActionMode -import androidx.core.view.isVisible -import dev.chrisbanes.insetter.applyInsetter -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.databinding.ActionToolbarBinding -import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale -import eu.kanade.tachiyomi.widget.ActionModeWithToolbar.Callback -import eu.kanade.tachiyomi.widget.listener.SimpleAnimationListener - -/** - * A toolbar holding only menu items. This view is supposed to be paired with [AppCompatActivity]'s [ActionMode]. - * - * @see Callback - */ -class ActionModeWithToolbar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - FrameLayout(context, attrs) { - - init { - clipToPadding = false - applyInsetter { - type(navigationBars = true) { - padding(bottom = true, horizontal = true) - } - } - } - - private val binding = ActionToolbarBinding.inflate(LayoutInflater.from(context), this, true) - - private var callback: Callback? = null - - private var actionMode: ActionMode? = null - private val actionModeCallback = object : ActionMode.Callback { - override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - callback?.onCreateActionToolbar(mode.menuInflater, binding.menu.menu) - binding.menu.setOnMenuItemClickListener { onActionItemClicked(mode, it) } - binding.root.isVisible = true - val bottomAnimation = AnimationUtils.loadAnimation(context, R.anim.bottom_sheet_slide_in) - bottomAnimation.applySystemAnimatorScale(context) - binding.root.startAnimation(bottomAnimation) - - return callback?.onCreateActionMode(mode, menu) ?: false - } - - override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - callback?.onPrepareActionToolbar(this@ActionModeWithToolbar, binding.menu.menu) - return callback?.onPrepareActionMode(mode, menu) ?: false - } - - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - return callback?.onActionItemClicked(mode, item) ?: false - } - - override fun onDestroyActionMode(mode: ActionMode) { - callback?.onDestroyActionMode(mode) - - val bottomAnimation = AnimationUtils.loadAnimation(context, R.anim.bottom_sheet_slide_out).apply { - applySystemAnimatorScale(context) - setAnimationListener( - object : SimpleAnimationListener() { - override fun onAnimationEnd(animation: Animation) { - binding.root.isVisible = false - binding.menu.menu.clear() - binding.menu.setOnMenuItemClickListener(null) - - callback?.onDestroyActionToolbar() - callback = null - actionMode = null - } - }, - ) - } - binding.root.startAnimation(bottomAnimation) - } - } - - fun start(callback: Callback) { - val context = context - if (context !is AppCompatActivity) { - throw IllegalStateException("AppCompatActivity is needed to start this view") - } - if (actionMode == null) { - this.callback = callback - actionMode = context.startSupportActionMode(actionModeCallback) - } - } - - fun finish() { - actionMode?.finish() - } - - /** - * Gets a menu item if found. - */ - fun findToolbarItem(@IdRes itemId: Int): MenuItem? { - return binding.menu.menu.findItem(itemId) - } - - override fun invalidate() { - super.invalidate() - actionMode?.invalidate() - } - - interface Callback { - /** - * Called when action mode is first created. The menu supplied will be used to - * generate action buttons for the action mode. - * - * @param mode ActionMode being created - * @param menu Menu used to populate action buttons - * @return true if the action mode should be created, false if entering this - * mode should be aborted. - */ - fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean - - /** - * [onCreateActionMode] but for the bottom toolbar - */ - fun onCreateActionToolbar(menuInflater: MenuInflater, menu: Menu) - - /** - * Called to refresh an action mode's action menu whenever it is invalidated. - * - * @param mode ActionMode being prepared - * @param menu Menu used to populate action buttons - * @return true if the menu or action mode was updated, false otherwise. - */ - fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean - - /** - * [onPrepareActionMode] but for the bottom toolbar - */ - fun onPrepareActionToolbar(toolbar: ActionModeWithToolbar, menu: Menu) - - /** - * Called to report a user click on an action button. - * - * @param mode The current ActionMode - * @param item The item that was clicked - * @return true if this callback handled the event, false if the standard MenuItem - * invocation should continue. - */ - fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean - - /** - * Called when an action mode is about to be exited and destroyed. - * - * @param mode The current ActionMode being destroyed - */ - fun onDestroyActionMode(mode: ActionMode) - - /** - * Called when the action toolbar is finished exiting - */ - fun onDestroyActionToolbar() {} - } -} diff --git a/app/src/main/res/layout-sw720dp/action_toolbar.xml b/app/src/main/res/layout-sw720dp/action_toolbar.xml deleted file mode 100644 index 31f695c9e..000000000 --- a/app/src/main/res/layout-sw720dp/action_toolbar.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout-sw720dp/main_activity.xml b/app/src/main/res/layout-sw720dp/main_activity.xml index 691cdb7c2..2c0f60db2 100644 --- a/app/src/main/res/layout-sw720dp/main_activity.xml +++ b/app/src/main/res/layout-sw720dp/main_activity.xml @@ -81,12 +81,6 @@ - - diff --git a/app/src/main/res/layout/action_toolbar.xml b/app/src/main/res/layout/action_toolbar.xml deleted file mode 100644 index 301154bf1..000000000 --- a/app/src/main/res/layout/action_toolbar.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index ef195ec46..f1e6fb3bc 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -65,12 +65,6 @@ android:id="@+id/fab_layout" layout="@layout/main_activity_fab" /> - -