Repository navigation
ADFA-6729: List only .cgp/.cgt files when installing from Downloads #2177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+846
−75
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0488520
ADFA-6729: Accept file:// picks in the Manager install paths
yaturner ccd778b
ADFA-6729: List only .cgp/.cgt files when installing from Downloads
yaturner 8e65d94
Merge branch 'stage' into ADFA-6729-filter-addon-install-picker
jimturner-adfa 3388e0f
ADFA-6729: Fail the kept-source test if the install never finishes
yaturner 5112ea0
ADFA-6729: Rename PluginInstallSource.ContentUri to PickedUri
yaturner 1727ce4
ADFA-6729: Skip pending, trashed and core.cgt files in add-on listings
yaturner da64774
ADFA-6729: Update the Manager screen KDocs for the Download picker
yaturner 7330b50
ADFA-6729: Shorten the wait in the gated-repeat test
yaturner c51bda9
ADFA-6729: Show help on long-press in the Download picker
yaturner b87cd77
ADFA-6729: Keep installed template collections with hidden names
yaturner a398625
Merge branch 'stage' into ADFA-6729-filter-addon-install-picker
jimturner-adfa ef570b4
ADFA-6729: Skip only MediaProvider placeholders, not every hidden name
yaturner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/itsaky/androidide/repositories/AddonFiles.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.itsaky.androidide.repositories | ||
|
|
||
| import org.adfa.constants.TEMPLATE_CORE_ARCHIVE | ||
| import java.io.File | ||
|
|
||
| /** | ||
| * Add-on archives directly in [dir] (not its subfolders) whose extension is [extension], ignoring | ||
| * case. Shared by the Templates tab and the Manager screen's + picker so the two list the same | ||
| * files. Empty if [dir] is missing or unreadable. | ||
| * | ||
| * Leaves out: | ||
| * - MediaProvider's placeholders. On Android 11+ it keeps a download still in progress, or a file | ||
| * in the trash, in its folder as `.pending-<expiry>-<name>` or `.trashed-<expiry>-<name>`, which | ||
| * keep the add-on extension. Offering one would install a partial archive, or a file the user | ||
| * deleted. Only that exact form is skipped, not every hidden name: the installer accepts a | ||
| * collection named `.name`, stored as `.name.cgt`, and uninstalling moves it to Downloads. | ||
| * - The bundled core.cgt (ADFA-5645). It ships with the IDE, and installing a copy fails on its | ||
| * reserved name. | ||
| */ | ||
| internal fun addonFilesIn( | ||
| dir: File, | ||
| extension: String, | ||
| ): List<File> = | ||
| dir | ||
| // Name checks first: they are free, and isFile is a stat per entry. | ||
| .listFiles { file -> | ||
| !MEDIA_STORE_PLACEHOLDER.matches(file.name) && | ||
| file.extension.equals(extension, ignoreCase = true) && | ||
| !file.name.equals(TEMPLATE_CORE_ARCHIVE, ignoreCase = true) && | ||
| file.isFile | ||
| }.orEmpty() | ||
| .toList() | ||
|
|
||
| // AOSP MediaProvider's FileUtils.PATTERN_EXPIRES_FILE, which names these files ".%s-%d-%s". | ||
| private val MEDIA_STORE_PLACEHOLDER = Regex("""^\.(pending|trashed)-\d+-.+$""", RegexOption.IGNORE_CASE) |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/itsaky/androidide/repositories/DownloadFilesRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.itsaky.androidide.repositories | ||
|
|
||
| import java.io.File | ||
|
|
||
| /** A file in the Downloads folder, as offered by the Manager screen's install picker. */ | ||
| data class DownloadedFile( | ||
| val file: File, | ||
| val sizeBytes: Long, | ||
| val lastModified: Long, | ||
| ) { | ||
| val name: String get() = file.name | ||
| } | ||
|
|
||
| /** | ||
| * Lists add-on files in the Downloads folder by extension. | ||
| * | ||
| * The system file picker cannot do this: SAF filters by MIME type, and neither `.cgp` nor `.cgt` | ||
| * has a registered one, so it lists every file (ADFA-6729). | ||
| */ | ||
| interface DownloadFilesRepository { | ||
| /** | ||
| * Files directly in the Downloads folder (not its subfolders) whose extension is [extension], | ||
| * ignoring case, newest first. Hidden files and the bundled core.cgt are left out; see | ||
| * [addonFilesIn]. Empty if the folder is missing or unreadable. | ||
| */ | ||
| suspend fun list(extension: String): List<DownloadedFile> | ||
| } |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/itsaky/androidide/repositories/DownloadFilesRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.itsaky.androidide.repositories | ||
|
|
||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.withContext | ||
| import java.io.File | ||
|
|
||
| class DownloadFilesRepositoryImpl( | ||
| private val downloadDir: File, | ||
| ) : DownloadFilesRepository { | ||
| override suspend fun list(extension: String): List<DownloadedFile> = | ||
| withContext(Dispatchers.IO) { | ||
| addonFilesIn(downloadDir, extension) | ||
| .map { file -> DownloadedFile(file, file.length(), file.lastModified()) } | ||
| // Newest first: the file the user just downloaded is the one they are looking for. | ||
| .sortedByDescending { it.lastModified } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
app/src/main/java/com/itsaky/androidide/ui/compose/DownloadPickerDialog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package com.itsaky.androidide.ui.compose | ||
|
|
||
| import android.text.format.DateUtils | ||
| import android.text.format.Formatter | ||
| import android.view.View | ||
| import androidx.compose.foundation.ExperimentalFoundationApi | ||
| import androidx.compose.foundation.combinedClickable | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material3.AlertDialog | ||
| import androidx.compose.material3.CircularProgressIndicator | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextButton | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.platform.LocalView | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.semantics.Role | ||
| import androidx.compose.ui.unit.dp | ||
| import com.itsaky.androidide.R | ||
| import com.itsaky.androidide.repositories.DownloadedFile | ||
| import com.itsaky.androidide.ui.models.AddonFileKind | ||
| import com.itsaky.androidide.ui.models.DownloadPickerUiState | ||
|
|
||
| /** | ||
| * The + button's picker: the open tab's add-on files in Downloads, plus a way out to the system | ||
| * picker for files kept anywhere else. | ||
| * | ||
| * Long-press on a file row or on Browse other folders calls [onShowHelp] with the dialog's own | ||
| * view, to anchor the help popup above the dialog. | ||
| */ | ||
| @Composable | ||
| fun DownloadPickerDialog( | ||
|
jimturner-adfa marked this conversation as resolved.
Resolved
|
||
| state: DownloadPickerUiState.Open, | ||
| onPick: (DownloadedFile) -> Unit, | ||
| onBrowse: () -> Unit, | ||
| onDismiss: () -> Unit, | ||
| onShowHelp: (anchor: View) -> Unit, | ||
| ) { | ||
| AlertDialog( | ||
| onDismissRequest = onDismiss, | ||
| title = { | ||
| Text( | ||
| stringResource( | ||
| when (state.kind) { | ||
| AddonFileKind.PLUGIN -> R.string.title_choose_plugin_file | ||
| AddonFileKind.TEMPLATE -> R.string.title_choose_template_file | ||
| }, | ||
| ), | ||
| ) | ||
| }, | ||
| text = { | ||
| val files = state.files | ||
| when { | ||
| files == null -> { | ||
| Box(modifier = Modifier.fillMaxWidth().padding(16.dp), contentAlignment = Alignment.Center) { | ||
| CircularProgressIndicator() | ||
| } | ||
| } | ||
|
|
||
| files.isEmpty() -> { | ||
| Text( | ||
| stringResource(R.string.msg_no_download_files, ".${state.kind.extension}"), | ||
| style = MaterialTheme.typography.bodyMedium, | ||
| ) | ||
| } | ||
|
|
||
| // Scrolls: Downloads can hold many add-ons, and rows grow with the font size. | ||
| else -> { | ||
| LazyColumn { | ||
| items(files, key = { it.file.absolutePath }) { file -> | ||
| DownloadFileRow(file = file, onClick = { onPick(file) }, onShowHelp = onShowHelp) | ||
| HorizontalDivider() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| confirmButton = { | ||
| val view = LocalView.current | ||
| val longPressAwareClick = rememberLongPressInteractionSource { onShowHelp(view) } | ||
| TextButton( | ||
| onClick = { | ||
| // TextButton's clickable() fires on the lift that ends the long press; drop that one. | ||
| if (longPressAwareClick.consumeIfSuppressed()) return@TextButton | ||
| onBrowse() | ||
| }, | ||
| interactionSource = longPressAwareClick.interactionSource, | ||
| ) { | ||
| Text(stringResource(R.string.action_browse_other_folders)) | ||
| } | ||
| }, | ||
| dismissButton = { | ||
| TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) } | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| @OptIn(ExperimentalFoundationApi::class) | ||
| @Composable | ||
| private fun DownloadFileRow( | ||
| file: DownloadedFile, | ||
| onClick: () -> Unit, | ||
| onShowHelp: (anchor: View) -> Unit, | ||
| ) { | ||
| val context = LocalContext.current | ||
| val view = LocalView.current | ||
| val size = Formatter.formatShortFileSize(context, file.sizeBytes) | ||
| val date = | ||
| DateUtils.formatDateTime( | ||
| context, | ||
| file.lastModified, | ||
| DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_ABBREV_MONTH, | ||
| ) | ||
| Column( | ||
| modifier = | ||
| Modifier | ||
| .fillMaxWidth() | ||
| .combinedClickable( | ||
| role = Role.Button, | ||
| onClickLabel = stringResource(R.string.action_install), | ||
| onLongClickLabel = stringResource(R.string.cd_show_tooltip), | ||
| onClick = onClick, | ||
| onLongClick = { onShowHelp(view) }, | ||
| ).padding(vertical = 12.dp), | ||
| ) { | ||
| // Not ellipsized: names like "fun-and-games-libgdx-v2.cgt" differ only at the end. | ||
| Text(file.name, style = MaterialTheme.typography.titleSmall) | ||
| Text( | ||
| stringResource(R.string.label_download_file_details, size, date), | ||
| style = MaterialTheme.typography.bodySmall, | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.