Skip to content

Commit 5c3d8fb

Browse files
david-allisoncriticalAY
authored andcommitted
refactor: replace 'bundleOf' with Bundle()
Deprecated in androidx:core 1.18.0 https://developer.android.com/jetpack/androidx/releases/core#core_and_core-ktx_version_118_2 Assisted-by: Claude Fable 5 - all
1 parent 2537be1 commit 5c3d8fb

6 files changed

Lines changed: 33 additions & 39 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/BrowserOptionsDialog.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.ichi2.anki.dialogs
1919
import android.app.Dialog
2020
import android.os.Bundle
2121
import androidx.appcompat.app.AppCompatDialogFragment
22-
import androidx.core.os.bundleOf
2322
import androidx.fragment.app.activityViewModels
2423
import com.google.android.material.dialog.MaterialAlertDialogBuilder
2524
import com.ichi2.anki.CollectionManager.TR
@@ -140,10 +139,10 @@ class BrowserOptionsDialog : AppCompatDialogFragment(R.layout.dialog_browser_opt
140139
Timber.i("BrowserOptionsDialog::newInstance")
141140
return BrowserOptionsDialog().apply {
142141
arguments =
143-
bundleOf(
144-
CARDS_OR_NOTES_KEY to (cardsOrNotes == CardsOrNotes.CARDS),
145-
IS_TRUNCATED_KEY to isTruncated,
146-
)
142+
Bundle().apply {
143+
putBoolean(CARDS_OR_NOTES_KEY, cardsOrNotes == CardsOrNotes.CARDS)
144+
putBoolean(IS_TRUNCATED_KEY, isTruncated)
145+
}
147146
}
148147
}
149148
}

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/ChangeNoteTypeDialog.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import android.widget.Spinner
3434
import androidx.annotation.CheckResult
3535
import androidx.annotation.StringRes
3636
import androidx.annotation.VisibleForTesting
37-
import androidx.core.os.bundleOf
3837
import androidx.core.view.isVisible
3938
import androidx.fragment.app.Fragment
4039
import androidx.fragment.app.viewModels
@@ -146,7 +145,7 @@ class ChangeNoteTypeDialog : AnalyticsDialogFragment(R.layout.dialog_change_note
146145
launchCatchingTask {
147146
viewModel.closeDialogFlow.filterNotNull().collect {
148147
Timber.i("Dismissing dialog")
149-
parentFragmentManager.setFragmentResult(REQUEST_KEY_NOTE_TYPE_CHANGED, bundleOf())
148+
parentFragmentManager.setFragmentResult(REQUEST_KEY_NOTE_TYPE_CHANGED, Bundle())
150149
dismiss()
151150
}
152151
}
@@ -315,9 +314,9 @@ class ChangeNoteTypeDialog : AnalyticsDialogFragment(R.layout.dialog_change_note
315314
ChangeNoteTypeDialog().apply {
316315
val ids = noteIds.distinct()
317316
arguments =
318-
bundleOf(
319-
ARG_NOTE_IDS to ids.toLongArray(),
320-
)
317+
Bundle().apply {
318+
putLongArray(ARG_NOTE_IDS, ids.toLongArray())
319+
}
321320
Timber.i("Showing 'change note type' dialog for %d notes", ids.size)
322321
}
323322
}

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import androidx.annotation.VisibleForTesting
2121
import androidx.annotation.VisibleForTesting.Companion.PRIVATE
2222
import androidx.appcompat.app.AlertDialog
2323
import androidx.core.content.edit
24-
import androidx.core.os.bundleOf
2524
import androidx.core.view.isVisible
2625
import androidx.core.view.updatePadding
2726
import androidx.core.widget.doAfterTextChanged
@@ -456,7 +455,7 @@ class CustomStudyDialog : AnalyticsDialogFragment() {
456455
STUDY_FORGOT, STUDY_AHEAD, STUDY_PREVIEW, STUDY_TAGS -> CustomStudyAction.CUSTOM_STUDY_SESSION
457456
}
458457

459-
setFragmentResult(CustomStudyAction.REQUEST_KEY, bundleOf(CustomStudyAction.BUNDLE_KEY to action.ordinal))
458+
setFragmentResult(CustomStudyAction.REQUEST_KEY, Bundle().apply { putInt(CustomStudyAction.BUNDLE_KEY, action.ordinal) })
460459

461460
// save the default values (not in upstream)
462461
when (contextMenuOption) {

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/TagLimitFragment.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import android.app.Dialog
1919
import android.content.Context
2020
import android.os.Bundle
2121
import androidx.appcompat.app.AlertDialog
22-
import androidx.core.os.bundleOf
2322
import androidx.core.view.isVisible
2423
import androidx.fragment.app.DialogFragment
2524
import androidx.fragment.app.setFragmentResult
@@ -115,10 +114,10 @@ class TagLimitFragment : DialogFragment() {
115114
// send the selection to the custom study dialog to setup the session
116115
setFragmentResult(
117116
REQUEST_CUSTOM_STUDY_TAGS,
118-
bundleOf(
119-
KEY_INCLUDED_TAGS to ArrayList(tagsToInclude),
120-
KEY_EXCLUDED_TAGS to ArrayList(tagsToExclude),
121-
),
117+
Bundle().apply {
118+
putStringArrayList(KEY_INCLUDED_TAGS, ArrayList(tagsToInclude))
119+
putStringArrayList(KEY_EXCLUDED_TAGS, ArrayList(tagsToExclude))
120+
},
122121
)
123122
dismiss()
124123
}
@@ -157,7 +156,7 @@ class TagLimitFragment : DialogFragment() {
157156

158157
fun newInstance(deckId: DeckId) =
159158
TagLimitFragment().apply {
160-
arguments = bundleOf(ARG_DECK_ID to deckId)
159+
arguments = Bundle().apply { putLong(ARG_DECK_ID, deckId) }
161160
}
162161
}
163162
}

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/help/HelpDialog.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import androidx.activity.addCallback
2222
import androidx.annotation.VisibleForTesting
2323
import androidx.appcompat.app.AlertDialog
2424
import androidx.core.os.BundleCompat
25-
import androidx.core.os.bundleOf
2625
import androidx.fragment.app.DialogFragment
2726
import androidx.fragment.app.Fragment
2827
import androidx.fragment.app.commit
@@ -111,7 +110,7 @@ class HelpDialog : DialogFragment() {
111110
private fun newHelpPage(items: Array<HelpItem>) {
112111
val menuPage =
113112
HelpPageFragment().apply {
114-
arguments = bundleOf(ARG_MENU_ITEMS to items)
113+
arguments = Bundle().apply { putParcelableArray(ARG_MENU_ITEMS, items) }
115114
}
116115
childFragmentManager.commit {
117116
replace(R.id.fragment_container, menuPage, PAGE_TAG).addToBackStack(null)
@@ -127,10 +126,10 @@ class HelpDialog : DialogFragment() {
127126
UsageAnalytics.sendAnalyticsEvent(Category.LINK_CLICKED, Actions.OPENED_HELP_DIALOG)
128127
return HelpDialog().apply {
129128
arguments =
130-
bundleOf(
131-
ARG_MENU_TITLE to R.string.help,
132-
ARG_MENU_ITEMS to mainHelpMenuItems,
133-
)
129+
Bundle().apply {
130+
putInt(ARG_MENU_TITLE, R.string.help)
131+
putParcelableArray(ARG_MENU_ITEMS, mainHelpMenuItems)
132+
}
134133
}
135134
}
136135

@@ -140,10 +139,10 @@ class HelpDialog : DialogFragment() {
140139
val privacyItems = childHelpMenuItems.filter { it.parentId == privacyId }
141140
return HelpDialog().apply {
142141
arguments =
143-
bundleOf(
144-
ARG_MENU_TITLE to R.string.help_title_privacy,
145-
ARG_MENU_ITEMS to privacyItems.toTypedArray(),
146-
)
142+
Bundle().apply {
143+
putInt(ARG_MENU_TITLE, R.string.help_title_privacy)
144+
putParcelableArray(ARG_MENU_ITEMS, privacyItems.toTypedArray())
145+
}
147146
}
148147
}
149148

@@ -158,10 +157,10 @@ class HelpDialog : DialogFragment() {
158157
val actualMenuItems = supportMenuItems.filterNot { it.action is Rate && !canRateApp }
159158
return HelpDialog().apply {
160159
arguments =
161-
bundleOf(
162-
ARG_MENU_TITLE to R.string.help_title_support_ankidroid,
163-
ARG_MENU_ITEMS to actualMenuItems.toTypedArray(),
164-
)
160+
Bundle().apply {
161+
putInt(ARG_MENU_TITLE, R.string.help_title_support_ankidroid)
162+
putParcelableArray(ARG_MENU_ITEMS, actualMenuItems.toTypedArray())
163+
}
165164
}
166165
}
167166
}
@@ -204,7 +203,7 @@ class HelpPageFragment : Fragment(R.layout.fragment_help_page) {
204203
UsageAnalytics.sendAnalyticsEvent(Category.LINK_CLICKED, menuItem.analyticsId)
205204
parentFragmentManager.setFragmentResult(
206205
REQUEST_HELP_PAGE,
207-
bundleOf(ARG_SELECTED_MENU_ITEM to menuItem),
206+
Bundle().apply { putParcelable(ARG_SELECTED_MENU_ITEM, menuItem) },
208207
)
209208
}
210209
binding.pageContent.addView(this)

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/tags/TagsDialog.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import androidx.appcompat.widget.SearchView
2020
import androidx.appcompat.widget.Toolbar
2121
import androidx.core.content.ContextCompat
2222
import androidx.core.os.BundleCompat
23-
import androidx.core.os.bundleOf
2423
import androidx.core.view.isVisible
2524
import androidx.core.widget.doAfterTextChanged
2625
import androidx.fragment.app.viewModels
@@ -146,11 +145,11 @@ class TagsDialog : AnalyticsDialogFragment {
146145
): TagsDialog {
147146
// TODO: checkedTags is unbounded and could exceed the bundle size
148147
val file = IdsFile(context.cacheDir, noteIds)
149-
arguments = this.arguments ?: bundleOf(
150-
ARG_TAGS_FILE to file,
151-
ARG_DIALOG_TYPE to type,
152-
ARG_CHECKED_TAGS to checkedTags,
153-
)
148+
arguments = this.arguments ?: Bundle().apply {
149+
putParcelable(ARG_TAGS_FILE, file)
150+
putParcelable(ARG_DIALOG_TYPE, type)
151+
putStringArrayList(ARG_CHECKED_TAGS, checkedTags)
152+
}
154153
return this
155154
}
156155

0 commit comments

Comments
 (0)