@@ -121,7 +121,6 @@ import com.ichi2.libanki.ChangeManager
121121import com.ichi2.libanki.Collection
122122import com.ichi2.libanki.DeckId
123123import com.ichi2.libanki.DeckNameId
124- import com.ichi2.libanki.NoteId
125124import com.ichi2.libanki.SortOrder
126125import com.ichi2.libanki.undoableOp
127126import com.ichi2.ui.CardBrowserSearchView
@@ -131,10 +130,8 @@ import com.ichi2.utils.dp
131130import com.ichi2.utils.increaseHorizontalPaddingOfOverflowMenuIcons
132131import com.ichi2.utils.updatePaddingRelative
133132import com.ichi2.widget.WidgetStatus.updateInBackground
134- import kotlinx.coroutines.Dispatchers
135133import kotlinx.coroutines.Job
136134import kotlinx.coroutines.launch
137- import kotlinx.coroutines.withContext
138135import net.ankiweb.rsdroid.RustCleanup
139136import net.ankiweb.rsdroid.Translations
140137import timber.log.Timber
@@ -1547,84 +1544,16 @@ open class CardBrowser :
15471544 if (! viewModel.hasSelectedAnyRows()) {
15481545 Timber .d(" showEditTagsDialog: called with empty selection" )
15491546 }
1550-
1551- var progressMax: Int? = null // this can be made null to blank the dialog
1552- var progress = 0
1553-
1554- fun onProgress (progressContext : ProgressContext ) {
1555- val max = progressMax
1556- if (max == null ) {
1557- progressContext.amount = null
1558- progressContext.text = getString(R .string.dialog_processing)
1559- } else {
1560- progressContext.amount = Pair (progress, max)
1561- }
1562- }
1563- launchCatchingTask {
1564- withProgress(extractProgress = ::onProgress) {
1565- val allTags = withCol { tags.all() }
1566- val selectedNoteIds = viewModel.queryAllSelectedNoteIds()
1567-
1568- progressMax = selectedNoteIds.size * 2
1569- // TODO!! This is terribly slow on AnKing
1570- val checkedTags =
1571- withCol {
1572- selectedNoteIds
1573- .asSequence() // reduce memory pressure
1574- .flatMap { nid ->
1575- progress++
1576- getNote(nid).tags // requires withCol
1577- }.distinct()
1578- .toList()
1579- }
1580-
1581- if (selectedNoteIds.size == 1 ) {
1582- Timber .d(" showEditTagsDialog: edit tags for one note" )
1583- tagsDialogListenerAction = TagsDialogListenerAction .EDIT_TAGS
1584- val dialog =
1585- tagsDialogFactory.newTagsDialog().withArguments(
1586- this @CardBrowser,
1587- type = TagsDialog .DialogType .EDIT_TAGS ,
1588- checkedTags = checkedTags,
1589- allTags = allTags,
1590- )
1591- showDialogFragment(dialog)
1592- return @withProgress
1593- }
1594- // TODO!! This is terribly slow on AnKing
1595- // PERF: This MUST be combined with the above sequence - this becomes O(2n) on a
1596- // database operation performed over 30k times
1597- val uncheckedTags =
1598- withCol {
1599- selectedNoteIds
1600- .asSequence() // reduce memory pressure
1601- .flatMap { nid: NoteId ->
1602- progress++
1603- val note = getNote(nid) // requires withCol
1604- val noteTags = note.tags.toSet()
1605- allTags.filter { t: String? -> ! noteTags.contains(t) }
1606- }.distinct()
1607- .toList()
1608- }
1609-
1610- progressMax = null
1611-
1612- Timber .d(" showEditTagsDialog: edit tags for multiple note" )
1613- tagsDialogListenerAction = TagsDialogListenerAction .EDIT_TAGS
1614-
1615- // withArguments performs IO, can be 18 seconds
1616- val dialog =
1617- withContext(Dispatchers .IO ) {
1618- tagsDialogFactory.newTagsDialog().withArguments(
1619- context = this @CardBrowser,
1620- type = TagsDialog .DialogType .EDIT_TAGS ,
1621- checkedTags = checkedTags,
1622- uncheckedTags = uncheckedTags,
1623- allTags = allTags,
1624- )
1625- }
1626- showDialogFragment(dialog)
1627- }
1547+ tagsDialogListenerAction = TagsDialogListenerAction .EDIT_TAGS
1548+ lifecycleScope.launch {
1549+ val noteIds = viewModel.queryAllSelectedNoteIds()
1550+ val dialog =
1551+ tagsDialogFactory.newTagsDialog().withArguments(
1552+ this @CardBrowser,
1553+ type = TagsDialog .DialogType .EDIT_TAGS ,
1554+ noteIds = noteIds,
1555+ )
1556+ showDialogFragment(dialog)
16281557 }
16291558 }
16301559
@@ -1635,8 +1564,7 @@ open class CardBrowser :
16351564 tagsDialogFactory.newTagsDialog().withArguments(
16361565 context = this @CardBrowser,
16371566 type = TagsDialog .DialogType .FILTER_BY_TAG ,
1638- checkedTags = ArrayList (0 ),
1639- allTags = withCol { tags.all() },
1567+ noteIds = emptyList(),
16401568 )
16411569 showDialogFragment(dialog)
16421570 }
0 commit comments