* Add a dev setting to add medias
* fix some issues with the "Create fake media" dev options
fixes:
1. the preferences should be persistent in order to have their values saved so `Create the files` can work
2. A toast is shown instead of a snackbar because it is more visible if a dialog is active
3. Use `numberOfFiles` instead of `numberOfFilePreference` in the dialog message
the rest of the changes are nitpicks
* Fix minor issues
Append _key to the new preferences key names to be similar to other
keys.
Fix number of files shown in the success toast.
---------
Co-authored-by: Brayan Oliveira <69634269+brayandso@users.noreply.github.com>
Co-authored-by: lukstbit <52494258+lukstbit@users.noreply.github.com>
If detected, shows an IDE lint.
- Catches calls to col.* inside AnkiActivity contexts.
- Catches calls to methods of classes derived from AnkiActivity, eg
```
withCol {
someDeckPickerMethod()
}
```
- UI classes that don't inherit from AnkiActivity are not caught unless
they are also annotated with @UiThread. Eg SetNotetypeListener in
NoteEditor references col, but is not caught without an extra annotation.
It might be best to wait until 2.16 is out (and any quick follow-up
releases to address the inevitable regressions) before we start addressing
these issues in bulk; for now the code might be better left as-is unless
it's to address a known bug someone has reported.
Related: #13944, #13942, #13936
Code inside a withCol() block should not modify the UI, as it runs on
a background thread. withCol() should fetch and/or mutate collection
data, and then UI operations/program state changes should be performed
outside the withCol block, so they're serialized on the main thread and
the risk of race conditions is minimized. Recently mentioned on
https://github.com/ankidroid/Anki-Android/pull/13886#issuecomment-1555407973
launchWithCol() makes it a bit too easy to accidentally run UI code in
the background thread, as it provides both an async context and a collection
at the same time, and the user will be tempted to do both fetch-from-col
and update-UI steps inside the block. Removing it means a few extra characters
at each call site, but I think it's a bit less error-prone.
* lateinit textDeckname
* lateinit deckInfoLayout
* lateinit textETA
* lateinit textCongrats
* lateinit buttonStart
* lateinit textDeckDescription
* lateinit more variables
* make col null safe
* make mFullNewCountThread call safer
* remove null early return
inflate() takes a nullable "root" argument so there is no reason to early return
the documentation says that the root argument is an "*******Optional******* view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)"
so the view is inflated anyway if you give a null root (or container)
Asked by @Arthur-Milchior
The current label of the negative button of "Timebox reached" dialog is "Close",
but it misleads as if it merely closes the dialog.
(It actually finishes the review session and shows the deck picker screen.)
This commit will replace the label with "Finish",
which is used on the counterpart dialog in Anki Desktop.
The string is reused from Anki Desktop.
Incidentally, this commit will also add the title comment
to the section of Timebox in 02-string.xml, for organization.
During a storage migration, we had a case where `.nomedia` failed the
content equality checks.
We do not know why, could not reproduce this and could not see it in
any further crash reports.
To work around this case, log and ignore the failure.
We log to further understand the issue.
Fixes 13807
This wasn't available from Locale.getAvailableLocales() but creating a new locale using "und-fonipa" as a language tag
seems to be understood as IPA. Will appear in the language hint dialog as "IPA Phonetics" and will work with GBoard.
See https://en.wikipedia.org/wiki/International_Phonetic_Alphabet#IETF_language_tags
When migration fails, we used to be stuck in a kind of a limbo:
the migration is considered done (failed, but done) by the service,
but `userMigrationIsInProgress` still returned true, so the UI was not
updated to reflect the state of the migration.
To overcome the issue, this introduces the state of “migration is
paused due to an error”, which is saved in shared preferences.
In this state, the toolbar shows the same migrate button that offers
to resume migration, and the sync icon is hidden.
A few TODOs were also added.
Co-authored-by: Mike Hardy <github@mikehardy.net>
* test: aggregateExceptionStackTrace
Requested? in issue 13667
* AggregateException: Define message + localizedMessage
Requested in issue 13667
* Refactor AggregateException
This also creates concepts of translatable strings and translatable
exceptions.
I decided to drop the logic of former AggregateException.raise, which
would return the one exception from the given list if it only had one
element, or create a new AggregateException, because:
* the logic is only used in two places, and:
* in non-trivial cases which involve the creation of translatable
strings, we'd want to create them lazily as they might not be
always needed. This might be done, perhaps, with something like
the following:
fun getSingleOrAggregateException(
causes: List<Exception>,
ifManyCauses: TranslatableAggregateException.MessageBuilder.() -> Unit
): Exception {
require(causes.isNotEmpty()) { "The list of exceptions was empty" }
return if (causes.size == 1) {
causes.single()
} else {
val messageBuilder = TranslatableAggregateException.MessageBuilder()
ifManyCauses(messageBuilder)
TranslatableAggregateException(messageBuilder.message, messageBuilder.translatableMessage, causes)
}
}
I suggest that we do not employ complications like these unless
AggregateException is extensively used in the codebase.
* Show big, friendly error text in migration failed notification
* Remove multiple-argument `TranslatableString.by`
As discussed in the PR
https://github.com/ankidroid/Anki-Android/pull/13762#discussion_r1182926595,
this method was not subject to string format linting.
Plus minor renaming.
---------
Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com>
This is fixed by stopping the mutating m[Current]DeckList
This should fix the issue:
`IndexOutOfBoundsException: Inconsistency detected. Invalid item position [N]`
Fixes 13794
We did not need to access the collection for this.
We have a cache of the mapping, which was produced at the same
time as `mCurrentDeckList`
Which in turn removes a number of 'suspend' calls throughout the code
Cleanup for 70151c563e
While adding an advanced setting, I found confusing that the code appears in an
order that is not related to the order in the actual presentation. So I reorder
it.
Actual change will appear in a distinct PR.
This PR skips the 'Are you sure?' warning if the user is syncing
and their collection is safe
This is primarily documentation, the previous code has one minor
bug in that a user could be preserving legacy storage AND not syncing
AND had the ability to `MANAGE_EXTERNAL_STORAGE` then the 'backup'
dialog was shown when it was not necessary
Mostly making use of newer documented methods in `ScopedStorageService`
Fixes 13663