* refactor: viewModel to use generic media terms and livedata
* refactor: use reselect string instead of restart
* refactor: extract MenuProvider class
* refactor: show multimedia bottomsheet in case result is cancelled
-Added right-click support for all existing long click listeners.
-Created an OnContextAndLongClickListener interface to handle both context click and long click events consistently.
-This interface includes an onAction method to define the common action (context and long click).
-The interface ensures that both listeners are set without duplicating code.
-Applied the OnContextAndLongClickListener interface to handle right-click and long-click events uniformly.
* Set .gitattributes to automatically detect text files, enabling git to
remove CRLF.
* Keep CRLF for .bat files
* Use .editorconfig to avoid further introduction of CRLF
Use the existing "Gallery" string which is translatable in Crowdin for:
- the "Gallery" option label in the menu of "Select image" in "Image Occlusion" note type
- the "Gallery" option label in the menu of multimedia file attachment in the note editor
8e0b537b1d introduced a call to `updateMenuState()` at the
loadDeckCounts job to update the undo label state when the deck is
reloaded.
Following the method name, the whole menu is updated instead of only the
undo label, which includes checking if there are changes to sync
remotely, and that takes time, so it shouldn't be done if not necessary.
The plugin hasn't been updated for quite some time and it currently
breaks the build and apk publishing. This PR removes it along its
configuration and any additional setup code.
The plugin was already removed from the publishing process as it
didn't work anymore. See https://github.com/ankidroid/Anki-Android/issues/14161
Refactored NoteEditor integration with NoteEditorLauncher interface to centralize configuration for various entry points.
Introduced NoteEditorLauncher as a sealed interface to streamline and unify configurations for opening NoteEditor from different contexts. Provides clear and standardized methods (e.g., AddNote, EditCard) for invoking NoteEditor with specific behaviors and data, improving code clarity and reducing potential errors in bundle creation. Promotes modularization by consolidating NoteEditor-related logic into a single location (noteeditor folder), enhancing maintainability and reducing redundancy across fragments and activities.
- ImageOcclusion: Handles opening NoteEditor with an image URI for creating an image occlusion.
- PassArguments: Directly passes arguments to the NoteEditor for scenarios like sharing text or processing text.
- AddNote: Opens NoteEditor from DeckPicker with optional deck ID.
- AddNoteFromCardBrowser: Opens NoteEditor from CardBrowser, optionally passing search terms and last deck ID.
- AddNoteFromReviewer: Opens NoteEditor from Reviewer, optionally specifying activity transition animation.
- AddInstantNote: Opens NoteEditor for instant note creation with shared text.
- EditCard: Edits a card in NoteEditor, specifying card ID and animation direction.
- EditNoteFromPreviewer: Edits a note in NoteEditor from Previewer, using the card ID.
- CopyNote: Copies a note in NoteEditor, optionally specifying deck ID, field texts, and tags.
1. AnkiFragment:
- Introduced a base class for fragments (`AnkiFragment`) with a `@param layout` documentation referencing `CardViewerFragment`. This base class consolidates common functionality and methods for all future fragments by inheriting `AnkiFragment`.
- Extracted methods from NoteEditor to AnkiFragment for potential reuse in other fragments.
2. NoteEditor Fragment:
- Implemented `OnMenuItemClickListener` to handle toolbar menu item clicks.
- Implemented `DispatchKeyEventListener` to manage key events.
- Initialized Onboarding after the view is created to prevent initialization errors.
- Split `onCreate()` into `onCreate()` and `onViewCreated()` to accommodate differences between activities and fragments in Android. In fragments, the view hierarchy setup (`onViewCreated()`) occurs separately from initialization (`onCreate()`), ensuring operations requiring access to the fragment's view are correctly handled post-creation.
- Replaced `IntentCompat` with `BundleCompat` to handle null data scenarios.
- Utilized `Bundle` instead of `Intent` in `openNewNoteEditor()` to avoid null data issues with `intent.extras`.
5. Intent Handling:
- Updated `SingleFragmentActivity.getIntent()` to support optional `intentAction` parameters, enabling dynamic intent actions like sharing text, images, and processing text.
- Created `IntentHandler2` for:
- Sharing text to NoteEditor
- Sharing image to NoteEditor
- Sharing process text to NoteEditor
- `Add Note` shortcut
- Created AbstractIntentHandler:
- Extract common initialization from IntentHandler and IntentHandler2 into AbstractIntentHandler.
6. NavigationDrawerActivity:
- Resolved error triggering when opening NoteEditor from a shortcut (`Long press AnkiDroid App -> Add`) by redirecting the intent target from NoteEditor to IntentHandler2.
7. ManifestFile:
- Removed NoteEditor from the manifest file due to its transition from an Activity to a Fragment.
- Moved `NoteEditor` specific intent filters from `NoteEditor` to `IntentHandler2`
8. Testing:
- Updated test files under the guidance of David in discord channel and feedback to ensure comprehensive test coverage aligns with the updated architecture and intent handling in AnkiDroid.
- CardBrowserTest: The addIntent returns both SingleFragmentActivity.FRAGMENT_NAME_EXTRA and SingleFragmentActivity.FRAGMENT_ARGS_EXTRA. Since NoteEditor.EXTRA_DID is located within SingleFragmentActivity.FRAGMENT_ARGS_EXTRA, the assertions needed to be adjusted to extract and verify the arguments bundle directly.
This commit refactors NoteEditor into a Fragment, improves intent handling across activities, and enhances fragment lifecycle management for consistent behavior and performance in AnkiDroid.
Used requireContext() when a method or parameter specifically requires a Context
Used requireActivity() when a method or parameter needs to interact with the hosting Activity is required
Used requireArguments() to retrieve fragment arguments. Replaced intent.extras with requireArguments because intent.extras returns both SingleFragmentActivity.FRAGMENT_NAME_EXTRA and SingleFragmentAcitivity.FRAGMENT_ARGS_EXTRA but we need only SingleFragmentAcitivity.FRAGMENT_ARGS_EXTRA
requireContext() and requireActivity() ensure that the Fragment is currently attached and prevent null pointer exceptions, providing safer access to the Context or Activity
First, I wanted to replace
`isEmpty` by `containsNoCard`. It seems interesting to note that this
may still contains non-default note-type and decks, and still consider
the collection empty.
This makes me look at Pairs, and found that, often, destructing the
Pair seems more readable to me than using `.first` and
`.second`. Especially when it eiher allows to have a single non-null
assertion, or allows to have name value instead.
I also added some `@NotLibAnki` instead of comments, as I just
dicovered that annotation.
The workflow was fetching the opened pull requests in the repository
but the returned results were per page with the default page value(30)
being used. This meant that the worflow would check only the oldest 30
opened pull requests. The per page value was changed to the maximum
value of 100.
See https://octokit.github.io/rest.js/v20#pulls-list
This still means the workflow doesn't handle over 100 opened pull
requests, but we shouldn't get there anyway.
Adds a withProgress call for the initial part of importing a collection
(where the file to import is copied). This was done on a background
thread so the UI wasn't blocked but the user also didn't know that
something was happening related to the import he just initiated.
This avoids the UI being "blocked" while saving the exported collection or
apkg, issue which becomes "visible" to the user when dealing with bigger
collections.
Used only in tests.
The initializer functions code used to create the models in StdModels
were refactored as standalone functions to be used by interested tests.
Note: StdModels were both used in unit and instrumented tests. As
there's only one usage in an instrumented test I duplicated the code
to avoid the use of the testlib.
The strings for the model names were removed because we don't need
translations for strings used in tests. The "front" and "back" names
are used in CardTemplateEditor, should probably be moved to one of
the other files to not have a strings file with just two strings in
it.
After reproducing #16702, I discovered that actually, the part of the
code where the NPE occurred should not have been reached.
newModel and oldModel are two distinct objects representing the same
note type. And JSonObject's equality is defined as pointer
equality. Using id instead of actual note type repair the bug.
Since, in AnkiDroid, editing the note type through the reviewer, can't
lead to adding or removing field, this is safe to consider that if the
id is equal, the objects are equal as far as the list of field is concerned.
I fear I don't see how to test it easily. It seems it require
AndroidTest and not unit tests, and I can't find example of note editor
test. Furthermore note editor will be replaced soon, so I don't expect
it's such a big deal.
* Fixed#16702