feat: show state of already installed driver
All checks were successful
eden-license / license-header (pull_request) Successful in 25s
All checks were successful
eden-license / license-header (pull_request) Successful in 25s
This commit is contained in:
parent
1c3ca17cfb
commit
c912055d78
3 changed files with 49 additions and 2 deletions
|
@ -143,8 +143,21 @@ class ReleaseAdapter(
|
||||||
binding.containerDownloads.removeAllViews()
|
binding.containerDownloads.removeAllViews()
|
||||||
|
|
||||||
release.artifacts.forEach { artifact ->
|
release.artifacts.forEach { artifact ->
|
||||||
|
val alreadyInstalled = try {
|
||||||
|
// Prefer fast check via ViewModel list; fallback to helper if needed
|
||||||
|
driverViewModel.driverData.any {
|
||||||
|
File(it.first).name.equals(artifact.name, ignoreCase = true)
|
||||||
|
} || GpuDriverHelper.isDriverZipInstalledByName(artifact.name)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
val button = MaterialButton(binding.root.context).apply {
|
val button = MaterialButton(binding.root.context).apply {
|
||||||
text = artifact.name
|
text = if (alreadyInstalled) {
|
||||||
|
context.getString(R.string.installed_label, artifact.name)
|
||||||
|
} else {
|
||||||
|
artifact.name
|
||||||
|
}
|
||||||
setTextAppearance(
|
setTextAppearance(
|
||||||
com.google.android.material.R.style.TextAppearance_Material3_LabelLarge
|
com.google.android.material.R.style.TextAppearance_Material3_LabelLarge
|
||||||
)
|
)
|
||||||
|
@ -154,7 +167,7 @@ class ReleaseAdapter(
|
||||||
com.google.android.material.R.color.m3_button_background_color_selector
|
com.google.android.material.R.color.m3_button_background_color_selector
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
setIconResource(R.drawable.ic_import)
|
setIconResource(if (alreadyInstalled) R.drawable.ic_check else R.drawable.ic_import)
|
||||||
iconTint = ColorStateList.valueOf(
|
iconTint = ColorStateList.valueOf(
|
||||||
MaterialColors.getColor(
|
MaterialColors.getColor(
|
||||||
this,
|
this,
|
||||||
|
@ -167,7 +180,22 @@ class ReleaseAdapter(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
)
|
)
|
||||||
|
isEnabled = !alreadyInstalled
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
|
// Double-check just before starting (race-proof)
|
||||||
|
if (GpuDriverHelper.isDriverZipInstalledByName(artifact.name)) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.driver_already_installed),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
// Update UI to reflect installed state
|
||||||
|
this.isEnabled = false
|
||||||
|
this.text = context.getString(R.string.installed_label, artifact.name)
|
||||||
|
this.setIconResource(R.drawable.ic_check)
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
val dialogBinding =
|
val dialogBinding =
|
||||||
DialogProgressBinding.inflate(LayoutInflater.from(context))
|
DialogProgressBinding.inflate(LayoutInflater.from(context))
|
||||||
dialogBinding.progressBar.isIndeterminate = true
|
dialogBinding.progressBar.isIndeterminate = true
|
||||||
|
@ -233,6 +261,10 @@ class ReleaseAdapter(
|
||||||
driverViewModel.onDriverAdded(Pair(driverPath, driverData))
|
driverViewModel.onDriverAdded(Pair(driverPath, driverData))
|
||||||
|
|
||||||
progressDialog.dismiss()
|
progressDialog.dismiss()
|
||||||
|
// Update button to installed state
|
||||||
|
this@apply.isEnabled = false
|
||||||
|
this@apply.text = context.getString(R.string.installed_label, artifact.name)
|
||||||
|
this@apply.setIconResource(R.drawable.ic_check)
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
context.getString(
|
context.getString(
|
||||||
|
|
|
@ -238,4 +238,18 @@ object GpuDriverHelper {
|
||||||
driverStorageDirectory.mkdirs()
|
driverStorageDirectory.mkdirs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a driver zip with the given filename is already present and valid in the
|
||||||
|
* internal driver storage directory. Validation requires a readable meta.json with a name.
|
||||||
|
*/
|
||||||
|
fun isDriverZipInstalledByName(fileName: String): Boolean {
|
||||||
|
// Normalize separators in case upstream sent a path
|
||||||
|
val baseName = fileName.substringAfterLast('/')
|
||||||
|
.substringAfterLast('\\')
|
||||||
|
val candidate = File("$driverStoragePath$baseName")
|
||||||
|
if (!candidate.exists() || candidate.length() == 0L) return false
|
||||||
|
val metadata = getMetadataFromZip(candidate)
|
||||||
|
return metadata.name != null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -678,6 +678,7 @@
|
||||||
<string name="select_gpu_driver_use_default">Using default GPU driver</string>
|
<string name="select_gpu_driver_use_default">Using default GPU driver</string>
|
||||||
<string name="select_gpu_driver_error">Invalid driver selected</string>
|
<string name="select_gpu_driver_error">Invalid driver selected</string>
|
||||||
<string name="driver_already_installed">Driver already installed</string>
|
<string name="driver_already_installed">Driver already installed</string>
|
||||||
|
<string name="installed_label">%1$s (Installed)</string>
|
||||||
<string name="system_gpu_driver">System GPU driver</string>
|
<string name="system_gpu_driver">System GPU driver</string>
|
||||||
<string name="installing_driver">Installing driver…</string>
|
<string name="installing_driver">Installing driver…</string>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue