Apply changed layout to all items

* Fix memory leaks
This commit is contained in:
Willi Ye 2021-04-29 22:50:00 +02:00 committed by ◱ Mark
parent 686d61b893
commit 2ff06d5421
6 changed files with 33 additions and 15 deletions

View File

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

View File

@ -32,7 +32,7 @@ class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>(), F
private val asyncListDiffer = AsyncListDiffer(this, DIFFER)
private val headerItems = mutableListOf<GenericListItem<out ViewBinding>>()
private val allItems = mutableListOf<GenericListItem<out ViewBinding>>()
val allItems = mutableListOf<GenericListItem<out ViewBinding>>()
val currentItems : List<GenericListItem<in ViewBinding>> get() = asyncListDiffer.currentList
var currentSearchTerm = ""

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"