2020-10-03 11:58:34 +02:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
* Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
*/
|
|
|
|
|
|
|
|
package emu.skyline.data
|
|
|
|
|
2021-01-30 14:59:11 +01:00
|
|
|
import android.content.Context
|
2023-03-14 22:45:58 +01:00
|
|
|
import android.graphics.Bitmap
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
import androidx.core.graphics.drawable.toBitmap
|
2023-02-23 01:14:05 +01:00
|
|
|
import emu.skyline.BuildConfig
|
2021-01-30 14:59:11 +01:00
|
|
|
import emu.skyline.R
|
2023-03-14 22:45:58 +01:00
|
|
|
import emu.skyline.SkylineApplication
|
2021-01-30 14:59:11 +01:00
|
|
|
import emu.skyline.loader.AppEntry
|
|
|
|
import emu.skyline.loader.LoaderResult
|
2020-10-05 12:04:57 +02:00
|
|
|
import java.io.Serializable
|
|
|
|
|
2023-02-23 01:14:05 +01:00
|
|
|
/**
|
|
|
|
* The tag used to pass [AppItem]s between activities and fragments
|
|
|
|
*/
|
|
|
|
const val AppItemTag = BuildConfig.APPLICATION_ID + ".APP_ITEM"
|
|
|
|
|
2023-03-14 22:45:58 +01:00
|
|
|
private val missingIcon by lazy { ContextCompat.getDrawable(SkylineApplication.instance, R.drawable.default_icon)!!.toBitmap(256, 256) }
|
|
|
|
|
2021-01-30 14:59:11 +01:00
|
|
|
/**
|
|
|
|
* This class is a wrapper around [AppEntry], it is used for passing around game metadata
|
|
|
|
*/
|
2023-04-19 14:46:59 +02:00
|
|
|
@Suppress("SERIAL")
|
2023-04-19 14:40:10 +02:00
|
|
|
data class AppItem(private val meta : AppEntry) : Serializable {
|
2021-01-30 14:59:11 +01:00
|
|
|
/**
|
|
|
|
* The icon of the application
|
|
|
|
*/
|
|
|
|
val icon get() = meta.icon
|
|
|
|
|
2023-03-14 22:45:58 +01:00
|
|
|
val bitmapIcon : Bitmap get() = meta.icon ?: missingIcon
|
|
|
|
|
2021-01-30 14:59:11 +01:00
|
|
|
/**
|
|
|
|
* The title of the application
|
|
|
|
*/
|
|
|
|
val title get() = meta.name
|
|
|
|
|
2022-11-22 17:11:37 +01:00
|
|
|
/**
|
|
|
|
* The title ID of the application
|
|
|
|
*/
|
|
|
|
val titleId get() = meta.titleId
|
|
|
|
|
2022-08-21 13:40:32 +02:00
|
|
|
/**
|
|
|
|
* The application version
|
|
|
|
*/
|
|
|
|
val version get() = meta.version
|
|
|
|
|
2021-01-30 14:59:11 +01:00
|
|
|
/**
|
2022-08-25 15:02:15 +02:00
|
|
|
* The application author
|
2021-01-30 14:59:11 +01:00
|
|
|
*/
|
2022-08-25 15:02:15 +02:00
|
|
|
val author get() = meta.author
|
2021-01-30 14:59:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The URI of the application's image file
|
|
|
|
*/
|
|
|
|
val uri get() = meta.uri
|
|
|
|
|
2023-02-22 17:48:44 +01:00
|
|
|
/**
|
|
|
|
* The format of the application
|
|
|
|
*/
|
|
|
|
val format get() = meta.format
|
|
|
|
|
2021-01-30 14:59:11 +01:00
|
|
|
val loaderResult get() = meta.loaderResult
|
|
|
|
|
2023-02-22 17:48:44 +01:00
|
|
|
fun loaderResultString(context : Context) = context.getString(
|
|
|
|
when (meta.loaderResult) {
|
|
|
|
LoaderResult.Success -> R.string.metadata_missing
|
2021-01-30 14:59:11 +01:00
|
|
|
|
2023-02-22 17:48:44 +01:00
|
|
|
LoaderResult.ParsingError -> R.string.invalid_file
|
2021-01-30 14:59:11 +01:00
|
|
|
|
2023-02-22 17:48:44 +01:00
|
|
|
LoaderResult.MissingTitleKey -> R.string.missing_title_key
|
2021-01-30 14:59:11 +01:00
|
|
|
|
2023-02-22 17:48:44 +01:00
|
|
|
LoaderResult.MissingHeaderKey,
|
|
|
|
LoaderResult.MissingTitleKek,
|
|
|
|
LoaderResult.MissingKeyArea -> R.string.incomplete_prod_keys
|
|
|
|
}
|
|
|
|
)
|
2021-01-30 14:59:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and author is used as the key
|
|
|
|
*/
|
2023-03-17 02:45:27 +01:00
|
|
|
fun key() = "${meta.name}${meta.author.let { it ?: "" }}"
|
2021-01-30 14:59:11 +01:00
|
|
|
}
|