Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11922 from t895/kotlin-model
Android: Convert "model" package to Kotlin
  • Loading branch information
JosJuice committed Aug 25, 2023
2 parents 260bad7 + 6a19629 commit b149ea5
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 357 deletions.
Expand Up @@ -61,12 +61,12 @@ class GameAdapter(private val mActivity: FragmentActivity) : RecyclerView.Adapte

holder.apply {
if (BooleanSetting.MAIN_SHOW_GAME_TITLES.boolean) {
binding.textGameTitle.text = gameFile.title
binding.textGameTitle.text = gameFile.getTitle()
binding.textGameTitle.visibility = View.VISIBLE
binding.textGameTitleInner.visibility = View.GONE
binding.textGameCaption.visibility = View.VISIBLE
} else {
binding.textGameTitleInner.text = gameFile.title
binding.textGameTitleInner.text = gameFile.getTitle()
binding.textGameTitleInner.visibility = View.VISIBLE
binding.textGameTitle.visibility = View.GONE
binding.textGameCaption.visibility = View.GONE
Expand Down Expand Up @@ -94,9 +94,9 @@ class GameAdapter(private val mActivity: FragmentActivity) : RecyclerView.Adapte
holder.apply {
if (GameFileCacheManager.findSecondDisc(gameFile) != null) {
binding.textGameCaption.text =
context.getString(R.string.disc_number, gameFile.discNumber + 1)
context.getString(R.string.disc_number, gameFile.getDiscNumber() + 1)
} else {
binding.textGameCaption.text = gameFile.company
binding.textGameCaption.text = gameFile.getCompany()
}
holder.gameFile = gameFile
binding.root.onFocusChangeListener =
Expand Down
Expand Up @@ -48,7 +48,7 @@ class GameRowPresenter(private val mActivity: FragmentActivity) : Presenter() {

holder.apply {
imageScreenshot.setImageDrawable(null)
cardParent.titleText = gameFile.title
cardParent.titleText = gameFile.getTitle()
holder.gameFile = gameFile

// Set the background color of the card
Expand All @@ -64,9 +64,9 @@ class GameRowPresenter(private val mActivity: FragmentActivity) : Presenter() {

if (GameFileCacheManager.findSecondDisc(gameFile) != null) {
holder.cardParent.contentText =
context.getString(R.string.disc_number, gameFile.discNumber + 1)
context.getString(R.string.disc_number, gameFile.getDiscNumber() + 1)
} else {
holder.cardParent.contentText = gameFile.company
holder.cardParent.contentText = gameFile.getCompany()
}
}

Expand Down
Expand Up @@ -25,8 +25,8 @@ class GameDetailsDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val gameFile = GameFileCacheManager.addOrGet(requireArguments().getString(ARG_GAME_PATH))

val country = resources.getStringArray(R.array.countryNames)[gameFile.country]
val fileSize = NativeLibrary.FormatSize(gameFile.fileSize, 2)
val country = resources.getStringArray(R.array.countryNames)[gameFile.getCountry()]
val fileSize = NativeLibrary.FormatSize(gameFile.getFileSize(), 2)

// TODO: Remove dialog_game_details_tv if we switch to an AppCompatActivity for leanback
val binding: DialogGameDetailsBinding
Expand All @@ -35,16 +35,16 @@ class GameDetailsDialog : DialogFragment() {
if (requireActivity() is AppCompatActivity) {
binding = DialogGameDetailsBinding.inflate(layoutInflater)
binding.apply {
textGameTitle.text = gameFile.title
textDescription.text = gameFile.description
if (gameFile.description.isEmpty()) {
textGameTitle.text = gameFile.getTitle()
textDescription.text = gameFile.getDescription()
if (gameFile.getDescription().isEmpty()) {
textDescription.visibility = View.GONE
}

textCountry.text = country
textCompany.text = gameFile.company
textGameId.text = gameFile.gameId
textRevision.text = gameFile.revision.toString()
textCompany.text = gameFile.getCompany()
textGameId.text = gameFile.getGameId()
textRevision.text = gameFile.getRevision().toString()

if (!gameFile.shouldShowFileFormatDetails()) {
labelFileFormat.setText(R.string.game_details_file_size)
Expand All @@ -55,19 +55,19 @@ class GameDetailsDialog : DialogFragment() {
labelBlockSize.visibility = View.GONE
textBlockSize.visibility = View.GONE
} else {
val blockSize = gameFile.blockSize
val compression = gameFile.compressionMethod
val blockSize = gameFile.getBlockSize()
val compression = gameFile.getCompressionMethod()

textFileFormat.text = resources.getString(
R.string.game_details_size_and_format,
gameFile.fileFormatName,
gameFile.getFileFormatName(),
fileSize
)

if (compression.isEmpty()) {
textCompression.setText(R.string.game_details_no_compression)
} else {
textCompression.text = gameFile.compressionMethod
textCompression.text = gameFile.getCompressionMethod()
}

if (blockSize > 0) {
Expand All @@ -87,16 +87,16 @@ class GameDetailsDialog : DialogFragment() {
} else {
tvBinding = DialogGameDetailsTvBinding.inflate(layoutInflater)
tvBinding.apply {
textGameTitle.text = gameFile.title
textDescription.text = gameFile.description
if (gameFile.description.isEmpty()) {
textGameTitle.text = gameFile.getTitle()
textDescription.text = gameFile.getDescription()
if (gameFile.getDescription().isEmpty()) {
tvBinding.textDescription.visibility = View.GONE
}

textCountry.text = country
textCompany.text = gameFile.company
textGameId.text = gameFile.gameId
textRevision.text = gameFile.revision.toString()
textCompany.text = gameFile.getCompany()
textGameId.text = gameFile.getGameId()
textRevision.text = gameFile.getRevision().toString()

if (!gameFile.shouldShowFileFormatDetails()) {
labelFileFormat.setText(R.string.game_details_file_size)
Expand All @@ -107,19 +107,19 @@ class GameDetailsDialog : DialogFragment() {
labelBlockSize.visibility = View.GONE
textBlockSize.visibility = View.GONE
} else {
val blockSize = gameFile.blockSize
val compression = gameFile.compressionMethod
val blockSize = gameFile.getBlockSize()
val compression = gameFile.getCompressionMethod()

textFileFormat.text = resources.getString(
R.string.game_details_size_and_format,
gameFile.fileFormatName,
gameFile.getFileFormatName(),
fileSize
)

if (compression.isEmpty()) {
textCompression.setText(R.string.game_details_no_compression)
} else {
textCompression.text = gameFile.compressionMethod
textCompression.text = gameFile.getCompressionMethod()
}

if (blockSize > 0) {
Expand All @@ -141,9 +141,9 @@ class GameDetailsDialog : DialogFragment() {
}

private suspend fun loadGameBanner(imageView: ImageView, gameFile: GameFile) {
val vector = gameFile.banner
val width = gameFile.bannerWidth
val height = gameFile.bannerHeight
val vector = gameFile.getBanner()
val width = gameFile.getBannerWidth()
val height = gameFile.getBannerHeight()

imageView.scaleType = ImageView.ScaleType.FIT_CENTER
val request = ImageRequest.Builder(imageView.context)
Expand Down
Expand Up @@ -210,7 +210,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
R.array.convertFormatValues,
format
)
if (gameFile.blobType == BLOB_TYPE_ISO) {
if (gameFile.getBlobType() == BLOB_TYPE_ISO) {
setDropdownSelection(
binding.dropdownFormat,
format,
Expand Down Expand Up @@ -240,6 +240,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
binding.dropdownBlockSize.adapter.getItem(0).toString(), false
)
}

BLOB_TYPE_WIA -> {
populateDropdown(
binding.blockSize,
Expand All @@ -253,6 +254,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
binding.dropdownBlockSize.adapter.getItem(0).toString(), false
)
}

BLOB_TYPE_RVZ -> {
populateDropdown(
binding.blockSize,
Expand All @@ -266,6 +268,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
binding.dropdownBlockSize.adapter.getItem(2).toString(), false
)
}

else -> clearDropdown(binding.blockSize, binding.dropdownBlockSize, blockSize)
}
}
Expand All @@ -285,6 +288,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
binding.dropdownCompression.adapter.getItem(0).toString(), false
)
}

BLOB_TYPE_WIA -> {
populateDropdown(
binding.compression,
Expand All @@ -298,6 +302,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
binding.dropdownCompression.adapter.getItem(0).toString(), false
)
}

BLOB_TYPE_RVZ -> {
populateDropdown(
binding.compression,
Expand All @@ -311,6 +316,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
binding.dropdownCompression.adapter.getItem(4).toString(), false
)
}

else -> clearDropdown(
binding.compression,
binding.dropdownCompression,
Expand All @@ -336,6 +342,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
).toString(), false
)
}

COMPRESSION_ZSTD -> {
// TODO: Query DiscIO for the supported compression levels, like we do in DolphinQt?
populateDropdown(
Expand All @@ -352,6 +359,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
).toString(), false
)
}

else -> clearDropdown(
binding.compressionLevel,
binding.dropdownCompressionLevel,
Expand All @@ -362,7 +370,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {

private fun populateRemoveJunkData() {
val scrubbingAllowed = format.getValue(requireContext()) != BLOB_TYPE_RVZ &&
!gameFile.isDatelDisc
!gameFile.isDatelDisc()

binding.switchRemoveJunkData.isEnabled = scrubbingAllowed
if (!scrubbingAllowed) binding.switchRemoveJunkData.isChecked = false
Expand All @@ -374,11 +382,11 @@ class ConvertFragment : Fragment(), View.OnClickListener {

var action = Runnable { showSavePrompt() }

if (gameFile.isNKit) {
if (gameFile.isNKit()) {
action = addAreYouSureDialog(action, R.string.convert_warning_nkit)
}

if (!scrub && format == BLOB_TYPE_GCZ && !gameFile.isDatelDisc && gameFile.platform == Platform.WII.toInt()) {
if (!scrub && format == BLOB_TYPE_GCZ && !gameFile.isDatelDisc() && gameFile.getPlatform() == Platform.WII.toInt()) {
action = addAreYouSureDialog(action, R.string.convert_warning_gcz)
}

Expand All @@ -401,7 +409,7 @@ class ConvertFragment : Fragment(), View.OnClickListener {
}

private fun showSavePrompt() {
val originalPath = gameFile.path
val originalPath = gameFile.getPath()

val filename = StringBuilder(File(originalPath).name)
val dotIndex = filename.lastIndexOf(".")
Expand Down Expand Up @@ -449,9 +457,9 @@ class ConvertFragment : Fragment(), View.OnClickListener {

thread = Thread {
val success = NativeLibrary.ConvertDiscImage(
gameFile.path,
gameFile.getPath(),
outPath,
gameFile.platform,
gameFile.getPlatform(),
format.getValue(context),
blockSize.getValueOr(context, 0),
compression.getValueOr(context, 0),
Expand Down

This file was deleted.

0 comments on commit b149ea5

Please sign in to comment.