Skip to content

Commit 2537be1

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 Opus 4.8 - all
1 parent 0590e9e commit 2537be1

9 files changed

Lines changed: 56 additions & 65 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/account/AccountActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package com.ichi2.anki.account
1919

2020
import android.content.Context
2121
import android.content.Intent
22-
import androidx.core.os.bundleOf
22+
import android.os.Bundle
2323
import com.ichi2.anki.SingleFragmentActivity
2424
import com.ichi2.anki.isLoggedIn
2525

@@ -47,9 +47,9 @@ class AccountActivity : SingleFragmentActivity() {
4747
context = context,
4848
fragmentClass = if (isLoggedIn()) LoggedInFragment::class else LoginFragment::class,
4949
arguments =
50-
bundleOf(
51-
START_FROM_DECKPICKER to forResult,
52-
),
50+
Bundle().apply {
51+
putBoolean(START_FROM_DECKPICKER, forResult)
52+
},
5353
)
5454
}
5555
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.ichi2.anki.dialogs
1818

1919
import android.os.Bundle
2020
import androidx.appcompat.app.AlertDialog
21-
import androidx.core.os.bundleOf
2221
import androidx.fragment.app.DialogFragment
2322
import com.ichi2.anki.AnkiActivity
2423
import com.ichi2.anki.R
@@ -42,7 +41,7 @@ class ExportReadyDialog : DialogFragment() {
4241
.positiveButton(R.string.export_choice_save_to) {
4342
parentFragmentManager.setFragmentResult(
4443
REQUEST_EXPORT_SAVE,
45-
bundleOf(KEY_EXPORT_PATH to exportPath),
44+
Bundle().apply { putString(KEY_EXPORT_PATH, exportPath) },
4645
)
4746
}.negativeButton(R.string.export_choice_share) {
4847
parentFragmentManager.setFragmentResult(

AnkiDroid/src/main/java/com/ichi2/anki/export/ExportDialogFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import android.widget.TextView
2424
import androidx.annotation.IdRes
2525
import androidx.annotation.LayoutRes
2626
import androidx.appcompat.app.AlertDialog
27-
import androidx.core.os.bundleOf
2827
import androidx.core.text.HtmlCompat
2928
import androidx.core.view.isVisible
3029
import androidx.fragment.app.DialogFragment
@@ -450,7 +449,7 @@ class ExportDialogFragment : DialogFragment() {
450449
*/
451450
fun newInstance(did: DeckId) =
452451
ExportDialogFragment().apply {
453-
arguments = bundleOf(ARG_DECK_ID to did)
452+
arguments = Bundle().apply { putLong(ARG_DECK_ID, did) }
454453
}
455454

456455
/**

AnkiDroid/src/main/java/com/ichi2/anki/filtered/FilteredDeckOptionsFragment.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import android.widget.CheckBox
2828
import android.widget.Spinner
2929
import androidx.activity.OnBackPressedCallback
3030
import androidx.appcompat.app.AlertDialog
31-
import androidx.core.os.bundleOf
3231
import androidx.core.view.isVisible
3332
import androidx.core.widget.doOnTextChanged
3433
import androidx.fragment.app.Fragment
@@ -405,11 +404,11 @@ class FilteredDeckOptionsFragment : Fragment(R.layout.fragment_filtered_deck_opt
405404
context = context,
406405
fragmentClass = FilteredDeckOptionsFragment::class,
407406
arguments =
408-
bundleOf(
409-
ARG_DECK_ID to did,
410-
ARG_SEARCH to search,
411-
ARG_SEARCH_2 to search2,
412-
),
407+
Bundle().apply {
408+
putLong(ARG_DECK_ID, did)
409+
putString(ARG_SEARCH, search)
410+
putString(ARG_SEARCH_2, search2)
411+
},
413412
)
414413
}
415414
}

AnkiDroid/src/main/java/com/ichi2/anki/introduction/SetupCollectionFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.ichi2.anki.introduction
2020
import android.os.Bundle
2121
import android.os.Parcelable
2222
import android.view.View
23-
import androidx.core.os.bundleOf
2423
import androidx.fragment.app.Fragment
2524
import androidx.fragment.app.setFragmentResult
2625
import com.ichi2.anki.R
@@ -56,7 +55,7 @@ class SetupCollectionFragment : Fragment(R.layout.fragment_introduction) {
5655
}
5756

5857
private fun setResult(option: CollectionSetupOption) {
59-
setFragmentResult(FRAGMENT_KEY, bundleOf(RESULT_KEY to option))
58+
setFragmentResult(FRAGMENT_KEY, Bundle().apply { putParcelable(RESULT_KEY, option) })
6059
}
6160

6261
@Parcelize

AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.ichi2.anki.multimedia
2020
import android.content.Context
2121
import android.content.Intent
2222
import android.os.Bundle
23-
import androidx.core.os.bundleOf
2423
import androidx.fragment.app.Fragment
2524
import androidx.fragment.app.commit
2625
import com.google.android.material.button.MaterialButton
@@ -92,10 +91,10 @@ class MultimediaActivity :
9291
val fragment =
9392
FragmentFactoryUtils.instantiate<Fragment>(this, fragmentClassName).apply {
9493
arguments =
95-
bundleOf(
96-
MULTIMEDIA_ARGS_EXTRA to intent.multimediaArgsExtra,
97-
EXTRA_MEDIA_OPTIONS to intent.mediaOptionsExtra,
98-
)
94+
Bundle().apply {
95+
putSerializable(MULTIMEDIA_ARGS_EXTRA, intent.multimediaArgsExtra)
96+
putSerializable(EXTRA_MEDIA_OPTIONS, intent.mediaOptionsExtra)
97+
}
9998
}
10099

101100
supportFragmentManager.commit {

AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/NoteEditorLauncher.kt

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import android.content.Intent
2121
import android.net.Uri
2222
import android.os.Bundle
2323
import android.os.Parcelable
24-
import androidx.core.os.bundleOf
2524
import com.ichi2.anim.ActivityTransitionAnimation
2625
import com.ichi2.anki.AnkiActivity
2726
import com.ichi2.anki.NoteEditorActivity
@@ -68,10 +67,10 @@ sealed interface NoteEditorLauncher : Destination {
6867
val imageUri: Uri?,
6968
) : NoteEditorLauncher {
7069
override fun toBundle(): Bundle =
71-
bundleOf(
72-
NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.IMG_OCCLUSION.value,
73-
NoteEditorFragment.EXTRA_IMG_OCCLUSION to imageUri,
74-
)
70+
Bundle().apply {
71+
putInt(NoteEditorFragment.EXTRA_CALLER, NoteEditorCaller.IMG_OCCLUSION.value)
72+
putParcelable(NoteEditorFragment.EXTRA_IMG_OCCLUSION, imageUri)
73+
}
7574
}
7675

7776
/**
@@ -92,10 +91,9 @@ sealed interface NoteEditorLauncher : Destination {
9291
val deckId: DeckId? = null,
9392
) : NoteEditorLauncher {
9493
override fun toBundle(): Bundle =
95-
bundleOf(
96-
NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.DECKPICKER.value,
97-
).also { bundle ->
98-
deckId?.let { deckId -> bundle.putLong(NoteEditorFragment.EXTRA_DID, deckId) }
94+
Bundle().apply {
95+
putInt(NoteEditorFragment.EXTRA_CALLER, NoteEditorCaller.DECKPICKER.value)
96+
deckId?.let { deckId -> putLong(NoteEditorFragment.EXTRA_DID, deckId) }
9997
}
10098
}
10199

@@ -140,10 +138,10 @@ sealed interface NoteEditorLauncher : Destination {
140138
val sharedText: String,
141139
) : NoteEditorLauncher {
142140
override fun toBundle(): Bundle =
143-
bundleOf(
144-
NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.INSTANT_NOTE_EDITOR.value,
145-
Intent.EXTRA_TEXT to sharedText,
146-
)
141+
Bundle().apply {
142+
putInt(NoteEditorFragment.EXTRA_CALLER, NoteEditorCaller.INSTANT_NOTE_EDITOR.value)
143+
putString(Intent.EXTRA_TEXT, sharedText)
144+
}
147145
}
148146

149147
/**
@@ -158,15 +156,15 @@ sealed interface NoteEditorLauncher : Destination {
158156
val inCardBrowserActivity: Boolean = false,
159157
) : NoteEditorLauncher {
160158
override fun toBundle(): Bundle =
161-
bundleOf(
162-
NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.EDIT.value,
159+
Bundle().apply {
160+
putInt(NoteEditorFragment.EXTRA_CALLER, NoteEditorCaller.EDIT.value)
163161
// To handle single card selection
164-
NoteEditorFragment.EXTRA_CARD_ID to cardIds.first(),
162+
putLong(NoteEditorFragment.EXTRA_CARD_ID, cardIds.first())
165163
// To handle multi select and note edit
166-
NoteEditorFragment.EXTRA_CARD_IDS to cardIds.toLongArray(),
167-
AnkiActivity.FINISH_ANIMATION_EXTRA to animation as Parcelable,
168-
NoteEditorFragment.IN_CARD_BROWSER_ACTIVITY to inCardBrowserActivity,
169-
)
164+
putLongArray(NoteEditorFragment.EXTRA_CARD_IDS, cardIds.toLongArray())
165+
putParcelable(AnkiActivity.FINISH_ANIMATION_EXTRA, animation as Parcelable)
166+
putBoolean(NoteEditorFragment.IN_CARD_BROWSER_ACTIVITY, inCardBrowserActivity)
167+
}
170168
}
171169

172170
/**
@@ -177,10 +175,10 @@ sealed interface NoteEditorLauncher : Destination {
177175
val cardId: CardId,
178176
) : NoteEditorLauncher {
179177
override fun toBundle(): Bundle =
180-
bundleOf(
181-
NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.PREVIEWER_EDIT.value,
182-
NoteEditorFragment.EXTRA_EDIT_FROM_CARD_ID to cardId,
183-
)
178+
Bundle().apply {
179+
putInt(NoteEditorFragment.EXTRA_CALLER, NoteEditorCaller.PREVIEWER_EDIT.value)
180+
putLong(NoteEditorFragment.EXTRA_EDIT_FROM_CARD_ID, cardId)
181+
}
184182
}
185183

186184
/**
@@ -195,12 +193,11 @@ sealed interface NoteEditorLauncher : Destination {
195193
val tags: List<String>? = null,
196194
) : NoteEditorLauncher {
197195
override fun toBundle(): Bundle =
198-
bundleOf(
199-
NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.NOTEEDITOR.value,
200-
NoteEditorFragment.EXTRA_DID to deckId,
201-
NoteEditorFragment.EXTRA_CONTENTS to fieldsText,
202-
).also { bundle ->
203-
tags?.let { tags -> bundle.putStringArray(NoteEditorFragment.EXTRA_TAGS, tags.toTypedArray()) }
196+
Bundle().apply {
197+
putInt(NoteEditorFragment.EXTRA_CALLER, NoteEditorCaller.NOTEEDITOR.value)
198+
putLong(NoteEditorFragment.EXTRA_DID, deckId)
199+
putString(NoteEditorFragment.EXTRA_CONTENTS, fieldsText)
200+
tags?.let { tags -> putStringArray(NoteEditorFragment.EXTRA_TAGS, tags.toTypedArray()) }
204201
}
205202
}
206203
}

AnkiDroid/src/main/java/com/ichi2/anki/scheduling/ForgetCardsDialog.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.ichi2.anki.scheduling
1919
import android.app.Dialog
2020
import android.os.Bundle
2121
import androidx.core.content.edit
22-
import androidx.core.os.bundleOf
2322
import androidx.fragment.app.DialogFragment
2423
import androidx.fragment.app.Fragment
2524
import androidx.fragment.app.FragmentActivity
@@ -127,10 +126,10 @@ class ForgetCardsDialog : DialogFragment() {
127126
}
128127
parentFragmentManager.setFragmentResult(
129128
REQUEST_KEY_FORGET,
130-
bundleOf(
131-
ARG_RESTORE_ORIGINAL to restoreOriginalPositionIfPossible,
132-
ARG_RESET_REPETITION to resetRepetitionAndLapseCounts,
133-
),
129+
Bundle().apply {
130+
putBoolean(ARG_RESTORE_ORIGINAL, restoreOriginalPositionIfPossible)
131+
putBoolean(ARG_RESET_REPETITION, resetRepetitionAndLapseCounts)
132+
},
134133
)
135134
}
136135
negativeButton(R.string.dialog_cancel)

AnkiDroid/src/main/java/com/ichi2/anki/scheduling/SetDueDateDialog.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import android.view.inputmethod.EditorInfo
2929
import android.widget.EditText
3030
import androidx.annotation.CheckResult
3131
import androidx.core.content.ContextCompat
32-
import androidx.core.os.bundleOf
3332
import androidx.core.view.isVisible
3433
import androidx.core.widget.doOnTextChanged
3534
import androidx.fragment.app.DialogFragment
@@ -250,13 +249,14 @@ class SetDueDateDialog : DialogFragment() {
250249
suspend fun newInstance(cardIds: List<CardId>) =
251250
SetDueDateDialog().apply {
252251
arguments =
253-
bundleOf(
254-
ARG_CARD_IDS to cardIds.toLongArray(),
255-
ARG_FSRS to (
252+
Bundle().apply {
253+
putLongArray(ARG_CARD_IDS, cardIds.toLongArray())
254+
putBoolean(
255+
ARG_FSRS,
256256
getFSRSStatus()
257-
?: false.also { Timber.w("FSRS Status error") }
258-
),
259-
)
257+
?: false.also { Timber.w("FSRS Status error") },
258+
)
259+
}
260260
Timber.i("Showing 'set due date' dialog for %d cards", cardIds.size)
261261
}
262262
}
@@ -313,7 +313,7 @@ class SetDueDateDialog : DialogFragment() {
313313
) {
314314
parentFragmentManager.setFragmentResult(
315315
RESULT_SUBMIT_DUE_DATE,
316-
bundleOf(),
316+
Bundle(),
317317
)
318318
true
319319
} else {
@@ -388,7 +388,7 @@ class SetDueDateDialog : DialogFragment() {
388388
) {
389389
parentFragmentManager.setFragmentResult(
390390
RESULT_SUBMIT_DUE_DATE,
391-
bundleOf(),
391+
Bundle(),
392392
)
393393
true
394394
} else {

0 commit comments

Comments
 (0)