From 2ff06d54210dc192f0985e8da705fc84253bfa9e Mon Sep 17 00:00:00 2001 From: Willi Ye Date: Thu, 29 Apr 2021 22:50:00 +0200 Subject: [PATCH] Apply changed layout to all items * Fix memory leaks --- app/src/main/java/emu/skyline/MainActivity.kt | 2 +- .../emu/skyline/adapter/GenericAdapter.kt | 2 +- .../emu/skyline/input/dialog/ButtonDialog.kt | 10 +++++++-- .../emu/skyline/input/dialog/RumbleDialog.kt | 10 +++++++-- .../emu/skyline/input/dialog/StickDialog.kt | 22 ++++++++++++------- app/src/main/res/layout/main_activity.xml | 2 +- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index f1b33b93..a13a91d9 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -299,7 +299,7 @@ class MainActivity : AppCompatActivity() { super.onResume() var layoutTypeChanged = false - for (appViewItem in adapter.currentItems.filterIsInstance(AppViewItem::class.java)) { + for (appViewItem in adapter.allItems.filterIsInstance(AppViewItem::class.java)) { if (layoutType != appViewItem.layoutType) { appViewItem.layoutType = layoutType layoutTypeChanged = true diff --git a/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt b/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt index 463ec610..7745affc 100644 --- a/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt +++ b/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt @@ -32,7 +32,7 @@ class GenericAdapter : RecyclerView.Adapter>(), F private val asyncListDiffer = AsyncListDiffer(this, DIFFER) private val headerItems = mutableListOf>() - private val allItems = mutableListOf>() + val allItems = mutableListOf>() val currentItems : List> get() = asyncListDiffer.currentList var currentSearchTerm = "" diff --git a/app/src/main/java/emu/skyline/input/dialog/ButtonDialog.kt b/app/src/main/java/emu/skyline/input/dialog/ButtonDialog.kt index f0590ee3..f763700a 100644 --- a/app/src/main/java/emu/skyline/input/dialog/ButtonDialog.kt +++ b/app/src/main/java/emu/skyline/input/dialog/ButtonDialog.kt @@ -26,14 +26,15 @@ import kotlin.math.abs * @param item This is used to hold the [ControllerButtonViewItem] between instances */ class ButtonDialog @JvmOverloads constructor(private val item : ControllerButtonViewItem? = null) : BottomSheetDialogFragment() { - private lateinit var binding : ButtonDialogBinding + private var _binding : ButtonDialogBinding? = null + private val binding get() = _binding!! private val inputManager by lazy { requireContext().getInputManager() } /** * This inflates the layout of the dialog after initial view creation */ - override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = ButtonDialogBinding.inflate(inflater).also { binding = it }.root + override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = ButtonDialogBinding.inflate(inflater).also { _binding = it }.root /** * This expands the bottom sheet so that it's fully visible @@ -239,4 +240,9 @@ class ButtonDialog @JvmOverloads constructor(private val item : ControllerButton dismiss() } } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } diff --git a/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt b/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt index 9439a900..49a54825 100644 --- a/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt +++ b/app/src/main/java/emu/skyline/input/dialog/RumbleDialog.kt @@ -26,14 +26,15 @@ import emu.skyline.input.ControllerActivity * @param item This is used to hold the [ControllerGeneralViewItem] between instances */ class RumbleDialog @JvmOverloads constructor(val item : ControllerGeneralViewItem? = null) : BottomSheetDialogFragment() { - private lateinit var binding : RumbleDialogBinding + private var _binding : RumbleDialogBinding? = null + private val binding get() = _binding!! private val inputManager by lazy { requireContext().getInputManager() } /** * This inflates the layout of the dialog after initial view creation */ - override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = RumbleDialogBinding.inflate(inflater).also { binding = it }.root + override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = RumbleDialogBinding.inflate(inflater).also { _binding = it }.root /** * This expands the bottom sheet so that it's fully visible @@ -139,4 +140,9 @@ class RumbleDialog @JvmOverloads constructor(val item : ControllerGeneralViewIte dismiss() } } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } diff --git a/app/src/main/java/emu/skyline/input/dialog/StickDialog.kt b/app/src/main/java/emu/skyline/input/dialog/StickDialog.kt index b8713047..65982131 100644 --- a/app/src/main/java/emu/skyline/input/dialog/StickDialog.kt +++ b/app/src/main/java/emu/skyline/input/dialog/StickDialog.kt @@ -42,7 +42,8 @@ class StickDialog @JvmOverloads constructor(val item : ControllerStickViewItem? Stick(R.string.stick_preview); } - private lateinit var binding : StickDialogBinding + private var _binding : StickDialogBinding? = null + private val binding get() = _binding!! /** * This is the current stage of the dialog @@ -69,7 +70,7 @@ class StickDialog @JvmOverloads constructor(val item : ControllerStickViewItem? /** * This inflates the layout of the dialog after initial view creation */ - override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = StickDialogBinding.inflate(inflater).also { binding = it }.root + override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = StickDialogBinding.inflate(inflater).also { _binding = it }.root /** * This expands the bottom sheet so that it's fully visible @@ -95,12 +96,12 @@ class StickDialog @JvmOverloads constructor(val item : ControllerStickViewItem? stageAnimation?.let { handler.removeCallbacks(it) } binding.stickContainer.animate() - .scaleX(1f).scaleY(1f) - .alpha(1f) - .translationY(0f).translationX(0f) - .rotationX(0f) - .rotationY(0f) - .start() + .scaleX(1f).scaleY(1f) + .alpha(1f) + .translationY(0f).translationX(0f) + .rotationX(0f) + .rotationY(0f) + .start() when (stage) { DialogStage.Button -> { @@ -607,4 +608,9 @@ class StickDialog @JvmOverloads constructor(val item : ControllerStickViewItem? dismiss() } } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 598e0134..aa0680ec 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" - app:layout_scrollFlags="scroll"> + app:layout_scrollFlags="enterAlwaysCollapsed">