0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00
Commit Graph

16099 Commits

Author SHA1 Message Date
David Allison
5576868421 refactor: Rename ExportingTest.java to .kt
com.ichi2.libanki.ExportingTest
2022-08-17 18:42:38 +05:30
Arthur Milchior
2656c0d9d5 NF: replace Long by NotetypeId
NotetypeId is defined upstream in models.py.

Since we may not convert Models.java, using the definition from PythonTypes is
the best solution.

Those variables were found by searching for "mid: Long" and "odelId: Long".
2022-08-17 00:26:14 +01:00
Damien Elmes
f827d5528b Fix time taken in v3 scheduler being capped to maximum
Closes #12024
2022-08-16 15:59:38 -05:00
Mike Hardy
5ad4ffc802 Bumped version to 2.16alpha78 2022-08-16 15:27:53 +00:00
Mike Hardy
20c618399d
Dependency updates 20220816 (#12036)
* Bump gradle from 7.2.1 to 7.2.2

Bumps gradle from 7.2.1 to 7.2.2.

---
updated-dependencies:
- dependency-name: com.android.tools.build:gradle
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump lint_version from 30.2.1 to 30.2.2

Bumps `lint_version` from 30.2.1 to 30.2.2.

Updates `lint-api` from 30.2.1 to 30.2.2

Updates `lint` from 30.2.1 to 30.2.2

Updates `lint-tests` from 30.2.1 to 30.2.2

---
updated-dependencies:
- dependency-name: com.android.tools.lint:lint-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: com.android.tools.lint:lint
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: com.android.tools.lint:lint-tests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump protobuf-kotlin from 3.21.4 to 3.21.5

Bumps protobuf-kotlin from 3.21.4 to 3.21.5.

---
updated-dependencies:
- dependency-name: com.google.protobuf:protobuf-kotlin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump fragments_version from 1.5.1 to 1.5.2

Bumps `fragments_version` from 1.5.1 to 1.5.2.

Updates `fragment-ktx` from 1.5.1 to 1.5.2

Updates `fragment-testing` from 1.5.1 to 1.5.2

---
updated-dependencies:
- dependency-name: androidx.fragment:fragment-ktx
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: androidx.fragment:fragment-testing
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump mockito-inline from 4.6.1 to 4.7.0

Bumps [mockito-inline](https://github.com/mockito/mockito) from 4.6.1 to 4.7.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v4.6.1...v4.7.0)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-inline
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-16 10:23:02 -05:00
Damien Elmes
771056c641 Delay pop-up of progress window
Closes #12027
2022-08-16 09:48:12 -05:00
Damien Elmes
3e7ad6a9e6 Shift launchCatchingTask to FragmentActivity; hook undo up in StudyOptions
Change based on https://github.com/ankidroid/Anki-Android/pull/12011#issuecomment-1214170607
2022-08-16 09:48:12 -05:00
Damien Elmes
061abf87c3 Fix error when undoing in card browser 2022-08-16 09:48:12 -05:00
Damien Elmes
e62024b909 Remove invalidateOptionsMenu() call
Theoretically it should be unnecessary, as it's called in refreshState()
2022-08-16 09:48:12 -05:00
Damien Elmes
55d5aab7d0 Unify isOnMainThread implementations 2022-08-16 09:48:12 -05:00
Damien Elmes
c55edd262b Remove wildcard import 2022-08-16 09:48:12 -05:00
Damien Elmes
d782901b2b Catch IO errors in media check with new schema
Closes #12026
2022-08-16 09:48:12 -05:00
Damien Elmes
f84baf6a07 Legacy undo & v2 queues must be cleared on backend op
Fixes #12007
2022-08-16 09:48:12 -05:00
Damien Elmes
06741b6c2d Fix deck picker options flickering + error on full sync
https://github.com/ankidroid/Anki-Android/pull/11849#issuecomment-1211775736

Android's onCreateOptionsMenu does not play well with coroutines, as
it expects the menu to have been fully configured by the time the routine
returns. This results in flicker, as the menu gets blanked out, and then
configured a moment later when the coroutine runs. To work around this,
the current state is stored in the deck picker, so that we can redraw the
menu immediately, and then make any potential changes in the background.

Other changes:
- refactored onCreateOptionsMenu to make it simpler
- instead of the sdCardAvailable checks (which I assume is a proxy for
"col is available"), the entire menu is wrapped in a group, and the
visibility of the group is toggled depending on whether the col is available
or not. This also fixes the error on a full sync.
- there are three sets of unit tests (one for search icon, one for sync icon,
one for entire menu) that have been a pain since I originally introduced
this PR, and and I've sunk a number of hours into trying to get them to work
properly at this point. The issue appears to be that when mixing coroutine
calls and invalidateOptionsMenu(), onCreateOptionsMenu() is not getting called
before trying to await the job, leading to a hang or stale data. I tried
advancing robolectric, but it did not help. Maybe someone more experienced
in this area can figure it out, but for now I've changed these routines
to be more of a unit test and less of an integration test: rather than
checking the menu itself, they directly invoke the function that updates
the menu state, and check the state instead. This takes onCreateOptionsMenu()
out of the loop, and avoids the problems (and probably allows these tests
to be re-enabled on Windows as well). The sync tests I've removed, as the
entire menu is hidden/shown now when the col is closed, so they are redundant.
2022-08-16 09:48:12 -05:00
Damien Elmes
c69f273496 Fix expand state not updating in V16
This regressed in 9644f5724c

+ Fix incorrect private find() implementation in CardContentProvider, and
move into shared file.

Closes #11999
2022-08-16 09:48:12 -05:00
Damien Elmes
cfb21276ad Rely on the backend to fetch the current deck id
Fixes a startup crash when the current deck ID is set to an invalid value
2022-08-16 09:48:12 -05:00
Damien Elmes
3d7c534699 Re-enable card template editor GUI in V16 schema
The unit tests were re-enabled some time back, but this was missed.
2022-08-16 09:48:12 -05:00
Damien Elmes
0a5ac3ab03 Fix play icons not appearing with V16
Closes #11979
2022-08-16 09:48:12 -05:00
Damien Elmes
065b0d0ea2 Fix crash after changing theme
Closes #11981
2022-08-16 09:48:12 -05:00
Damien Elmes
deb3a539ec Add script to test all commits in a branch
It skips lint-rules:test, as it still doesn't seem to work for me.
2022-08-16 09:48:12 -05:00
Damien Elmes
60b1ac3aed Skip a flaky v3 test for 2 hours of the day 2022-08-16 09:48:12 -05:00
Damien Elmes
747c41086b Use backend to update sync status; trigger media sync on auto full sync
+ Update sync status after normal media sync completes

Closes #11902
2022-08-16 09:48:12 -05:00
Damien Elmes
d86e6181ec Hook apkg/colpkg exports up to UI 2022-08-16 09:48:12 -05:00
Damien Elmes
036b882677 Introduce CollectionManager for preventing concurrent access
Currently there are many instances in the AnkiDroid codebase where
the collection is accessed a) on the UI thread, blocking the UI, and
b) in unsafe ways (eg by checking to see if the collection is open,
and then assuming it will remain open for the rest of a method call.
"Fix full download crashing in new schema case" (159a108dcb) demonstrates
a few of these cases.

This PR is an attempt at addressing those issues. It introduces
a `withCol` function that is intended to be used instead of
CollectionHelper.getCol(). For example, code that previously looked
like:

        val col = CollectionHelper.getInstance().getCol(this)
        val count = col.decks.count()

Can now be used like this:

        val count = withCol { decks.count() }

The block is run on a background thread, and other withCol calls made
in parallel will be queued up and executed sequentially. Because of
the exclusive access, routines can safely close and reopen the
collection inside the block without fear of affecting other callers.

It's not practical to update all the legacy code to use withCol
immediately - too much work is required, and coroutines are not
accessible from Java code. The intention here is that this new path is
gradually bought into. Legacy code can continue calling CollectionHelper.
getCol(), which internally delegates to CollectionManager.

Two caveats to be aware of:
- Legacy callers will wait for other pending operations to complete
before they receive the collection handle, but because they retain it,
subsequent access is not guaranteed to be exclusive.
- Because getCol() and colIsOpen() are often used on the main thread,
they will block the UI if a background operation is already running.
Logging has been added to help diagnose this, eg messages like:

E/CollectionManager: blocked main thread for 2626ms:
    com.ichi2.anki.DeckPicker.onCreateOptionsMenu(DeckPicker.kt:624)

Other changes:

- simplified CoroutineHelpers
- added TR function for accessing translations without a col reference
- onCreateOptionsMenu() needed refactoring to avoid blocking the UI.
- The blocking colIsOpen() call in onPrepareOptionsMenu() had to be
removed. I can not reproduce the issue it reports, and the code checks
for col in onCreateOptionsMenu().
- The subscribers in ChangeManager need to be cleared out at the start
of each test, or two tests are flaky when run with the new schema.
2022-08-16 09:48:12 -05:00
AnkiDroid Translations
dcb0c81331 Updated strings from Crowdin 2022-08-16 09:47:18 -05:00
yshubham8419
80123471b5 fixing #10767 unnecessary rebuild after opening filter deck option 2022-08-16 08:46:38 -05:00
Arthur Milchior
e954b44970 NF: replace Long by CardId
CardId is defined in cards.py upstream. Since Cards.java may not be converted,
Consts.kt may be the better place for it.

Values were found by searching "cid: Long" and "ardId: Long".
2022-08-16 14:08:48 +01:00
Arthur Milchior
d3aad45466 NF: remove queryWithNullSelection
It was a KotlinCleanup for DB migration.
2022-08-16 10:49:40 +01:00
Arthur Milchior
c826b88f5f NF: executeInTransaction returns value
I expect it to be useful in a commit soon
2022-08-16 07:42:22 +03:00
Brayan Oliveira
8c84ef6cbb Move dev options visibility configuration to the Preferences activity
Ideally, one fragment should call other fragments by the common parent activity, not directly.

This reduces the code duplication and organizes better the classes' responsibilities.
2022-08-15 17:36:59 +03:00
Brayan Oliveira
b7fa500f7b Move "Open changelog" to the about screen
Replaced it with "Send feedback". As "Send feedback" can be found on the "Help" dialog on the navigation drawer too, it shouldn't be a problem
2022-08-15 17:36:59 +03:00
Brayan Oliveira
1d485aeabc Reload activity immediately after directory change on preference
This leads to a better UX and simplifies the code.

Before the change, it was only restarted after the user tapped the back button
2022-08-15 17:36:59 +03:00
Brayan Oliveira
23e2e10aae Use MaterialDialog instead of AlertDialog on AdvancedSettingsFragment 2022-08-15 17:36:59 +03:00
Brayan Oliveira
8aa45daf16 cleanup on AdvancedSettingsFragment.kt
1. Fix/Simplify "Third-party API apps" configuration
- It crashed if the user's browser couldn't handle the link. Tested it by setting "MX player" (a video player that can be found on play store) as my browser.
- And as we already have a method that handles the lack of a browser that doesn't crash, just reuse it
2. Move `removeUnnecessaryAdvancedPrefs` to the top of `initSubscreen`, just to make it more visible
2022-08-15 17:36:59 +03:00
Brayan Oliveira
adabfbd656 NF: custom fonts cleanup 2022-08-15 17:36:59 +03:00
Brayan Oliveira
ae88a94ede Recreate Preferences activity instead of just closing it on language change
- As helper.closeCollection() already saves the collection and is called before closePreferences(), calling the latter method isn't necessary
2022-08-15 17:36:59 +03:00
Brayan Oliveira
a7bb22b868 Remove onBackStackChangedListener removal at Preferences.onDestroy()
Useless call, as the fragmentManager is destroyed together with the activity
2022-08-15 17:36:59 +03:00
Brayan Oliveira
8ebc1ac25f Embed the preferences search bar on the toolbar
So the user can search preferences from any screen

Changes' description:
- Move the search bar configuration from HeaderFragment.kt to the preferences activity
   - a change made to it was disabling the search history, as it was poor
- Remove the previous SearchPreference bar
- Embed the searchBar by creating a new menu (preferences.xml) and a new SearchView (PreferencesSearchView)
2022-08-15 14:54:36 +03:00
Brayan Oliveira
a08496e826 Test if getFragmentFromXmlRes() lead to the correct fragments
And add a utility method to access private/protected java fields with reflection
2022-08-15 14:54:36 +03:00
Brayan Oliveira
4ddc356a69 Add a search bar to the settings screen
It's necessary for all "PreferenceScreen" to have keys, so they are being added to the screens which hadn't a key

search:ignore is an attribute that allows to skip a preference indexing on a XML file. It is added to subscreens' preferences to avoid duplication of the results of the screens themselves and the preferences that open them

Added as well to "Day" and "Night" preferences to avoid duplication of their entries and "Theme" preference's entries
2022-08-15 14:54:36 +03:00
Brayan Oliveira
ab5bfc3ef4 Move addAllControlPreferencesToCategory to ControlPreference.kt
The method should be a responsibility of the screen's class, not of the individual preference's class
2022-08-15 14:54:36 +03:00
Brayan Oliveira
2201b53f2a Rename AdaptionUtil.isRestrictedLearningDevice
And add a javadoc to explain what it does.

Currently it is only used to hide some preferences which aren't usable on "Xiaomi AI teacher" devices.
2022-08-15 14:54:36 +03:00
AnkiDroid Translations
8a1ef83ed8 Updated strings from Crowdin 2022-08-14 20:01:06 -05:00
Mike Hardy
f830827f06 test: LeakCanary channels are auto-created / okay to have 2022-08-14 07:49:33 -05:00
Arthur Milchior
2e82380e2e NF: uses NoteId instead of Long
It's used upstream. It was defined in notes.py, but since Notes.java may not get
converted, consts is the most relevant place to put it.

Those ones were found by searching for "nodeId: Long", "NoteId: Long" and "nid:
Long".
2022-08-14 13:43:31 +01:00
Arthur Milchior
886773c691 refactor: Convert DB to Kotlin
com.ichi2.libanki.DB
2022-08-14 13:39:54 +01:00
Arthur Milchior
2cdeca6d0b refactor: Rename DB.java to .kt
com.ichi2.libanki.DB
2022-08-14 13:39:54 +01:00
Brayan Oliveira
3f946efe18 NF: refactor androidX custom preferences
- rename "formattedSummary" to "summaryFormat"
- simplify SeekBarPreferenceCompat and NumberRangePreferenceCompat constructors and declare styleable attributes for "useSimpleSummaryProvider" and "summaryFormat" so they can be previewed on Android Studio's layout viewer
2022-08-14 08:22:44 +03:00
Brayan Oliveira
3b6b2106a5 Move preferences headers' summary configuration to the XMLs
with the bonus that now the summaries can be previewed on Android Studio layout viewer

note: buildCategorySummary was renamed to buildHeaderSummary
2022-08-14 08:22:44 +03:00
Arthur Milchior
e701342531 NF: export without scheduling: remove all system tags
This is obviously what was expected to be done. Instead of removing the tags
from the same note over and over again.
2022-08-13 15:51:26 +01:00