diff --git a/app/src/main/java/emu/skyline/AppDialog.kt b/app/src/main/java/emu/skyline/AppDialog.kt index d8adf607..cc3b5413 100644 --- a/app/src/main/java/emu/skyline/AppDialog.kt +++ b/app/src/main/java/emu/skyline/AppDialog.kt @@ -15,8 +15,6 @@ import android.view.KeyEvent import android.view.LayoutInflater import android.view.View 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.BottomSheetDialogFragment 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.icon ?: missingIcon) + binding.gameIcon.setImageBitmap(item.bitmapIcon) binding.gameTitle.text = item.title binding.gameVersion.text = item.version ?: item.loaderResultString(requireContext()) binding.gameTitleId.text = item.titleId @@ -94,7 +90,7 @@ class AppDialog : BottomSheetDialogFragment() { val info = ShortcutInfo.Builder(context, item.title) info.setShortLabel(item.title) 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) intent.data = item.uri diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index f84cb99a..42b6a0b6 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -61,8 +61,6 @@ class MainActivity : AppCompatActivity() { 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() private var formatFilter : RomFormat? = null @@ -97,7 +95,7 @@ class MainActivity : AppCompatActivity() { 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?) { // Need to create new instance of settings, dependency injection happens diff --git a/app/src/main/java/emu/skyline/adapter/AppViewItem.kt b/app/src/main/java/emu/skyline/adapter/AppViewItem.kt index 1bf792b5..137bb15e 100644 --- a/app/src/main/java/emu/skyline/adapter/AppViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/AppViewItem.kt @@ -89,7 +89,7 @@ class GridCompatBinding(parent : ViewGroup) : LayoutBinding Unit -class AppViewItem(var layoutType : LayoutType, private val item : AppItem, private val missingIcon : Bitmap, private val onClick : InteractionFunction, private val onLongClick : InteractionFunction) : GenericListItem>() { +class AppViewItem(var layoutType : LayoutType, private val item : AppItem, private val onClick : InteractionFunction, private val onLongClick : InteractionFunction) : GenericListItem>() { override fun getViewBindingFactory() = LayoutBindingFactory(layoutType) override fun bind(holder : GenericViewHolder>, position : Int) { @@ -102,7 +102,7 @@ class AppViewItem(var layoutType : LayoutType, private val item : AppItem, priva binding.textVersion.isSelected = true binding.textAuthor.isSelected = true - binding.icon.setImageBitmap(item.icon ?: missingIcon) + binding.icon.setImageBitmap(item.bitmapIcon) if (layoutType == LayoutType.List) { 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)) 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.show() diff --git a/app/src/main/java/emu/skyline/data/DataItem.kt b/app/src/main/java/emu/skyline/data/DataItem.kt index 3dfae683..d5b801ff 100644 --- a/app/src/main/java/emu/skyline/data/DataItem.kt +++ b/app/src/main/java/emu/skyline/data/DataItem.kt @@ -6,8 +6,12 @@ package emu.skyline.data 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.R +import emu.skyline.SkylineApplication import emu.skyline.loader.AppEntry import emu.skyline.loader.LoaderResult import java.io.Serializable @@ -17,6 +21,8 @@ import java.io.Serializable */ 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 class HeaderItem(val title : String) : DataItem() @@ -30,6 +36,8 @@ data class AppItem(private val meta : AppEntry) : DataItem() { */ val icon get() = meta.icon + val bitmapIcon : Bitmap get() = meta.icon ?: missingIcon + /** * The title of the application */