[Bug] Unexpected line breaks in one-way sync message
Reproduction Steps
- Click on Manage Note Types option.
- Delete a note type.
The message warning the user that the action would require one-way sync has unexpected line breaks.

Debug info
AnkiDroid Version = 2.16alpha91
Android Version = 7.0
Manufacturer = motorola
Model = Moto C Plus
Hardware = mt6735
Webview User Agent = Mozilla/5.0 (Linux; Android 7.0; Moto C Plus Build/NRD90M.03.045; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/108.0.5359.128 Mobile Safari/537.36
ACRA UUID = f2e4f224-7a41-48c9-9812-264b40f7e5ba
New schema = true
Scheduler = std3
Crash Reports Enabled = true
DatabaseV2 Enabled = true
Research
Enter an [x] character to confirm the points below:
- [x] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid
- [x] I have checked the manual and the FAQ and could not find a solution to my issue
- [x] I have searched for similar existing issues here and on the user forum
- [ ] (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
To devs: Most longer strings are used in a HTML context, where whitespace is automatically collapsed. There are one or two places in the desktop code that convert newlines in a translation to spaces before using it, using something like:
def with_collapsed_whitespace(string: str) -> str:
return re.sub(r"\s+", " ", string)
You could do something similar here.
I will like to take up this issue
Go for it, @parthn2. Have a nice job there
Hi sir , i want to work on this project
Hi, I am having some trouble with reproducing this error. When deleting a note type, I am getting the message "The requested change will require a full upload of the database when you next synchronize your collection. If you have reviews or other changes waiting on another device that haven't been synchronized here yet, they will be lost. Continue?"
Do you have the new backend enabled?
No I don't think so, how can I do that?
- Install an alpha release newer than 2.16alpha82 from https://github.com/ankidroid/Anki-Android/releases
- Go to "Settings" --> "Advanced" and enable "Use the new backend" in "Experimental Settings"
Thank you for your help, I will do my best to solve this issue
HI, I am able to reproduce the issue but I am unable to find out how the text is being rendered in the Pop Up. I believe it is being produced due to something in the below code from ManageNotetypes.kt file but can not find out what it is. I also tried logging some message in console but nothing shows up. Can someone help me out?
private fun deleteNotetype(noteTypeUiModel: NoteTypeUiModel) {
launchCatchingTask {
val messageResourceId: Int? = if (userAcceptsSchemaChange()) {
withProgress {
withCol {
if (newBackend.getNotetypeNames().size <= 1) {
return@withCol null
}
R.string.model_delete_warning
}
}
} else {
return@launchCatchingTask
}
if (messageResourceId == null) {
showSnackbar(getString(R.string.toast_last_model))
return@launchCatchingTask
}
MaterialDialog(this@ManageNotetypes).show {
title(R.string.model_browser_delete)
message(res = messageResourceId)
positiveButton(R.string.dialog_ok) {
launchCatchingTask {
runAndRefreshAfter { newBackend.removeNotetype(noteTypeUiModel.id) }
}
}
negativeButton(R.string.dialog_cancel)
}
}
}
@Parthn2 The message is store in the string resource file with id R.string.model_delete_warning and from the code above it is conditionally assigned to the variable val messageResourceId: Int?.
The text is then rendered in the Pop Up by passing messageResourceId to the message method of the MaterialDialog. Check the code below.
MaterialDialog(this@ManageNotetypes).show {
title(R.string.model_browser_delete)
//**! This is the line you're looking for
message(res = messageResourceId)
positiveButton(R.string.dialog_ok) {
launchCatchingTask {
runAndRefreshAfter { newBackend.removeNotetype(noteTypeUiModel.id) }
}
}
negativeButton(R.string.dialog_cancel)
}
To actually solve this issue, what you might want to do first is use getString(messageResourceId) to retrieve the text and apply any necessary formatting to get rid of the line breaks before passing it to the message method of the MaterialDialog.
The MaterialDialog used in Anki is -> https://github.com/afollestad/material-dialogs and it's message method construct looks like this:
fun message(
@StringRes res: Int? = null,
text: CharSequence? = null,
applySettings: (DialogMessageSettings.() -> Unit)? = null
)
So instead of passing in a resource id, you can pass your processed text as a CharSequence to it.
MaterialDialog(this@ManageNotetypes).show {
title(R.string.model_browser_delete)
//**! It should look something like this
val rawMessageText = getString(messageResourceId)
val processedMessageText = removeWhiteSpace(awMessageTex)
message(text = processedMessageText)
positiveButton(R.string.dialog_ok) {
launchCatchingTask {
runAndRefreshAfter { newBackend.removeNotetype(noteTypeUiModel.id) }
}
}
negativeButton(R.string.dialog_cancel)
}
I know my explanation is unnecessarily verbose but I hope it helps :)
@ismailnurudeen Thank You for the detailed explanation, it really helped me to understand the code better.
I have found out that this pop-up message is not generated using the line which you marked out. I verified this by commenting on the line, and it did not affect the popup, which is expected, as far as I understand
message(res = messageResourceId)
If you haven't reproduced the issue yet, there are two popups which come during this process.
- This is the error pop-up in which the unexpected line break problem is.
- This comes after clicking 'OK' on the previous message and generally comes under normal conditions which is the "Delete note type" pop-up. This is affected by commenting the code and the error message is gone away.
One more thing is that there is no message shown in the pop-up present in the string resource file or even in the whole codebase of this repo. I tried it using the project search but can't find anything near it.
Please tell me if I am missing anything.
It is getting the string from TR.deckConfigWillRequireFullSync() in AnkiActivity.userAcceptsSchemaChange() defined in CoroutineHelpers.kt
To solve this issue either you can process the function call directly inside AnkiActivity.userAcceptsSchemaChange() like this:
MaterialDialog(this).show {
message(text = TR.deckConfigWillRequireFullSync().replace('\n',' '))
positiveButton(R.string.dialog_ok) { coroutine.resume(true) }
negativeButton(R.string.dialog_cancel) { coroutine.resume(false) }
onCancel { coroutine.resume(false) }
}
But this is more of an ad-hoc approach you will have to change it everywhere you call a function from TR which is part of ankidroid-backend'
So instead, change it in the source where it is all generated. It is I think the issue from 'ankidroid-backend'.
It is getting the string from
TR.deckConfigWillRequireFullSync()inAnkiActivity.userAcceptsSchemaChange()defined in CoroutineHelpers.ktTo solve this issue either you can process the function call directly inside
AnkiActivity.userAcceptsSchemaChange()like this:MaterialDialog(this).show { message(text = TR.deckConfigWillRequireFullSync().replace('\n',' ')) positiveButton(R.string.dialog_ok) { coroutine.resume(true) } negativeButton(R.string.dialog_cancel) { coroutine.resume(false) } onCancel { coroutine.resume(false) } }But this is more of an ad-hoc approach you will have to change it everywhere you call a function from
TRwhich is part of ankidroid-backend'So instead, change it in the source where it is all generated. It is I think the issue from 'ankidroid-backend'.
Thank you so much.
Hey!! I want to work on this issue. Kindly assign me this issue..
I want to work on this issue.
hey please assign this task to me