diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt index c43bdf9a8038..aa7c8489d6ce 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt @@ -203,12 +203,11 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener { tags = note.tags, fillEmpty = true ) - val fragment = TemplatePreviewerFragment.newInstance(args) + val backgroundColor = ThemeUtils.getThemeAttrColor(this@CardTemplateEditor, R.attr.alternativeBackgroundColor) + val fragment = TemplatePreviewerFragment.newInstance(args, backgroundColor) supportFragmentManager.commitNow { replace(R.id.fragment_container, fragment) } - val backgroundColor = ThemeUtils.getThemeAttrColor(this@CardTemplateEditor, R.attr.alternativeBackgroundColor) - fragment.requireView().setBackgroundColor(backgroundColor) } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/TemplatePreviewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/TemplatePreviewerFragment.kt index dbf185a6847c..ee58f788af81 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/TemplatePreviewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/TemplatePreviewerFragment.kt @@ -29,6 +29,7 @@ import com.ichi2.anki.cardviewer.CardMediaPlayer import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider import com.ichi2.anki.snackbar.SnackbarBuilder import com.ichi2.anki.utils.ext.sharedPrefs +import com.ichi2.utils.BundleUtils.getNullableInt import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -65,14 +66,28 @@ class TemplatePreviewerFragment : if (sharedPrefs().getBoolean("safeDisplay", false)) { view.findViewById(R.id.webview_container).elevation = 0F } + + arguments?.getNullableInt(ARG_BACKGROUND_OVERRIDE_COLOR)?.let { color -> + view.setBackgroundColor(color) + } } companion object { const val ARGS_KEY = "templatePreviewerArgs" + private const val ARG_BACKGROUND_OVERRIDE_COLOR = "arg_background_override_color" - fun newInstance(arguments: TemplatePreviewerArguments): TemplatePreviewerFragment { + /** + * @param backgroundOverrideColor optional color to be used as background on the root view + * of this fragment + */ + fun newInstance( + arguments: TemplatePreviewerArguments, + backgroundOverrideColor: Int? = null + ): TemplatePreviewerFragment { return TemplatePreviewerFragment().apply { - this.arguments = bundleOf(ARGS_KEY to arguments) + val args = bundleOf(ARGS_KEY to arguments) + backgroundOverrideColor?.let { args.putInt(ARG_BACKGROUND_OVERRIDE_COLOR, backgroundOverrideColor) } + this.arguments = args } } }