mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-28 10:45:28 +03:00
Centralize missingIcon and condition for use in DataItem
`One missing Bitmap to rule them all and one condition to find them.` Also eliminates passing that condition between methods. The data class can simply return the same instance every time it's necessary.
This commit is contained in:
parent
905c0a47fa
commit
e68baf9088
@ -15,8 +15,6 @@ import android.view.KeyEvent
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@ -65,9 +63,7 @@ class AppDialog : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val missingIcon = ContextCompat.getDrawable(requireActivity(), R.drawable.default_icon)!!.toBitmap(256, 256)
|
binding.gameIcon.setImageBitmap(item.bitmapIcon)
|
||||||
|
|
||||||
binding.gameIcon.setImageBitmap(item.icon ?: missingIcon)
|
|
||||||
binding.gameTitle.text = item.title
|
binding.gameTitle.text = item.title
|
||||||
binding.gameVersion.text = item.version ?: item.loaderResultString(requireContext())
|
binding.gameVersion.text = item.version ?: item.loaderResultString(requireContext())
|
||||||
binding.gameTitleId.text = item.titleId
|
binding.gameTitleId.text = item.titleId
|
||||||
@ -94,7 +90,7 @@ class AppDialog : BottomSheetDialogFragment() {
|
|||||||
val info = ShortcutInfo.Builder(context, item.title)
|
val info = ShortcutInfo.Builder(context, item.title)
|
||||||
info.setShortLabel(item.title)
|
info.setShortLabel(item.title)
|
||||||
info.setActivity(ComponentName(requireContext(), EmulationActivity::class.java))
|
info.setActivity(ComponentName(requireContext(), EmulationActivity::class.java))
|
||||||
info.setIcon(Icon.createWithAdaptiveBitmap(item.icon ?: missingIcon))
|
info.setIcon(Icon.createWithAdaptiveBitmap(item.bitmapIcon))
|
||||||
|
|
||||||
val intent = Intent(context, EmulationActivity::class.java)
|
val intent = Intent(context, EmulationActivity::class.java)
|
||||||
intent.data = item.uri
|
intent.data = item.uri
|
||||||
|
@ -61,8 +61,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private val layoutType get() = LayoutType.values()[appSettings.layoutType]
|
private val layoutType get() = LayoutType.values()[appSettings.layoutType]
|
||||||
|
|
||||||
private val missingIcon by lazy { ContextCompat.getDrawable(this, R.drawable.default_icon)!!.toBitmap(256, 256) }
|
|
||||||
|
|
||||||
private val viewModel by viewModels<MainViewModel>()
|
private val viewModel by viewModels<MainViewModel>()
|
||||||
|
|
||||||
private var formatFilter : RomFormat? = null
|
private var formatFilter : RomFormat? = null
|
||||||
@ -97,7 +95,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (appSettings.refreshRequired) loadRoms(false)
|
if (appSettings.refreshRequired) loadRoms(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun AppItem.toViewItem() = AppViewItem(layoutType, this, missingIcon, ::selectStartGame, ::selectShowGameDialog)
|
private fun AppItem.toViewItem() = AppViewItem(layoutType, this, ::selectStartGame, ::selectShowGameDialog)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState : Bundle?) {
|
override fun onCreate(savedInstanceState : Bundle?) {
|
||||||
// Need to create new instance of settings, dependency injection happens
|
// Need to create new instance of settings, dependency injection happens
|
||||||
|
@ -89,7 +89,7 @@ class GridCompatBinding(parent : ViewGroup) : LayoutBinding<AppItemGridCompactBi
|
|||||||
|
|
||||||
private typealias InteractionFunction = (appItem : AppItem) -> Unit
|
private typealias InteractionFunction = (appItem : AppItem) -> Unit
|
||||||
|
|
||||||
class AppViewItem(var layoutType : LayoutType, private val item : AppItem, private val missingIcon : Bitmap, private val onClick : InteractionFunction, private val onLongClick : InteractionFunction) : GenericListItem<LayoutBinding<*>>() {
|
class AppViewItem(var layoutType : LayoutType, private val item : AppItem, private val onClick : InteractionFunction, private val onLongClick : InteractionFunction) : GenericListItem<LayoutBinding<*>>() {
|
||||||
override fun getViewBindingFactory() = LayoutBindingFactory(layoutType)
|
override fun getViewBindingFactory() = LayoutBindingFactory(layoutType)
|
||||||
|
|
||||||
override fun bind(holder : GenericViewHolder<LayoutBinding<*>>, position : Int) {
|
override fun bind(holder : GenericViewHolder<LayoutBinding<*>>, position : Int) {
|
||||||
@ -102,7 +102,7 @@ class AppViewItem(var layoutType : LayoutType, private val item : AppItem, priva
|
|||||||
binding.textVersion.isSelected = true
|
binding.textVersion.isSelected = true
|
||||||
binding.textAuthor.isSelected = true
|
binding.textAuthor.isSelected = true
|
||||||
|
|
||||||
binding.icon.setImageBitmap(item.icon ?: missingIcon)
|
binding.icon.setImageBitmap(item.bitmapIcon)
|
||||||
|
|
||||||
if (layoutType == LayoutType.List) {
|
if (layoutType == LayoutType.List) {
|
||||||
binding.icon.setOnClickListener { showIconDialog(it.context, item) }
|
binding.icon.setOnClickListener { showIconDialog(it.context, item) }
|
||||||
@ -123,7 +123,7 @@ class AppViewItem(var layoutType : LayoutType, private val item : AppItem, priva
|
|||||||
builder.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
builder.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||||
|
|
||||||
val imageView = ImageView(context)
|
val imageView = ImageView(context)
|
||||||
imageView.setImageBitmap(appItem.icon ?: missingIcon)
|
imageView.setImageBitmap(appItem.bitmapIcon)
|
||||||
|
|
||||||
builder.addContentView(imageView, RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
builder.addContentView(imageView, RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
builder.show()
|
builder.show()
|
||||||
|
@ -6,8 +6,12 @@
|
|||||||
package emu.skyline.data
|
package emu.skyline.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import emu.skyline.BuildConfig
|
import emu.skyline.BuildConfig
|
||||||
import emu.skyline.R
|
import emu.skyline.R
|
||||||
|
import emu.skyline.SkylineApplication
|
||||||
import emu.skyline.loader.AppEntry
|
import emu.skyline.loader.AppEntry
|
||||||
import emu.skyline.loader.LoaderResult
|
import emu.skyline.loader.LoaderResult
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
@ -17,6 +21,8 @@ import java.io.Serializable
|
|||||||
*/
|
*/
|
||||||
const val AppItemTag = BuildConfig.APPLICATION_ID + ".APP_ITEM"
|
const val AppItemTag = BuildConfig.APPLICATION_ID + ".APP_ITEM"
|
||||||
|
|
||||||
|
private val missingIcon by lazy { ContextCompat.getDrawable(SkylineApplication.instance, R.drawable.default_icon)!!.toBitmap(256, 256) }
|
||||||
|
|
||||||
sealed class DataItem : Serializable
|
sealed class DataItem : Serializable
|
||||||
|
|
||||||
class HeaderItem(val title : String) : DataItem()
|
class HeaderItem(val title : String) : DataItem()
|
||||||
@ -30,6 +36,8 @@ data class AppItem(private val meta : AppEntry) : DataItem() {
|
|||||||
*/
|
*/
|
||||||
val icon get() = meta.icon
|
val icon get() = meta.icon
|
||||||
|
|
||||||
|
val bitmapIcon : Bitmap get() = meta.icon ?: missingIcon
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The title of the application
|
* The title of the application
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user