Skip to content

Commit d5d0a66

Browse files
Fandroid745david-allison
authored andcommitted
feat(sync): add help icon to sync conflict dialog
Fixes 17544
1 parent 26cd8c5 commit d5d0a66

4 files changed

Lines changed: 39 additions & 13 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.ichi2.anki.dialogs.SyncErrorDialog.Type.DIALOG_SYNC_SANITY_ERROR_CONF
3838
import com.ichi2.anki.dialogs.SyncErrorDialog.Type.DIALOG_USER_NOT_LOGGED_IN_SYNC
3939
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
4040
import com.ichi2.anki.utils.openUrl
41+
import com.ichi2.utils.titleWithHelpIcon
4142

4243
class SyncErrorDialog : AsyncDialogFragment() {
4344
interface SyncErrorDialogListener {
@@ -93,8 +94,12 @@ class SyncErrorDialog : AsyncDialogFragment() {
9394
DIALOG_SYNC_CONFLICT_RESOLUTION -> {
9495
// Sync conflict; allow user to cancel, or choose between local and remote versions
9596
dialog
96-
.setIcon(R.drawable.ic_sync_problem)
97-
.setPositiveButton(R.string.sync_conflict_keep_local_new) { _, _ ->
97+
.titleWithHelpIcon(
98+
text = getString(R.string.sync_conflict_title_new),
99+
startIcon = R.drawable.ic_sync_problem,
100+
) {
101+
requireContext().openUrl(getString(R.string.link_sync_conflict_help))
102+
}.setPositiveButton(R.string.sync_conflict_keep_local_new) { _, _ ->
98103
requireSyncErrorDialogListener().showSyncErrorDialog(DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_LOCAL)
99104
}.setNegativeButton(R.string.sync_conflict_keep_remote_new) { _, _ ->
100105
requireSyncErrorDialogListener().showSyncErrorDialog(DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_REMOTE)

AnkiDroid/src/main/java/com/ichi2/utils/AlertDialogFacade.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,24 @@ fun AlertDialog.Builder.listItemsAndMessage(
455455
* }
456456
* ```
457457
*
458-
* @param block action executed when the help icon is clicked
459-
*
458+
* @param onHelpClick action executed when the help icon is clicked
459+
* @param startIcon optional icon to display at the start of the title
460460
*/
461461
fun AlertDialog.Builder.titleWithHelpIcon(
462462
@StringRes stringRes: Int? = null,
463463
text: String? = null,
464-
block: View.OnClickListener,
465-
) {
464+
@DrawableRes startIcon: Int? = null,
465+
onHelpClick: View.OnClickListener,
466+
): AlertDialog.Builder {
466467
// setup the view for the dialog
467468
val binding = AlertDialogTitleWithHelpBinding.inflate(LayoutInflater.from(context))
468469
setCustomTitle(binding.root)
469470

471+
if (startIcon != null) {
472+
binding.titleIcon.setImageResource(startIcon)
473+
binding.titleIcon.visibility = View.VISIBLE
474+
}
475+
470476
// apply a custom title
471477
if (stringRes != null) {
472478
binding.title.setText(stringRes)
@@ -477,8 +483,9 @@ fun AlertDialog.Builder.titleWithHelpIcon(
477483
// set the action when clicking the help icon
478484
binding.helpIcon.setOnClickListener { v ->
479485
Timber.i("dialog help icon click")
480-
block.onClick(v)
486+
onHelpClick.onClick(v)
481487
}
488+
return this
482489
}
483490

484491
/** Calls [AlertDialog.dismiss], ignoring errors */

AnkiDroid/src/main/res/layout/alert_dialog_title_with_help.xml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
67
android:layout_height="wrap_content"
78
style="?attr/materialAlertDialogTitlePanelStyle"
8-
android:orientation="horizontal"
99
android:paddingStart="24dp"
1010
android:paddingEnd="8dp"
1111
android:paddingTop="24dp"
1212
android:paddingBottom="8dp">
1313

14+
<ImageView
15+
android:id="@+id/title_icon"
16+
android:layout_width="24dp"
17+
android:layout_height="24dp"
18+
style="?attr/materialAlertDialogTitleIconStyle"
19+
android:visibility="gone"
20+
tools:src="@drawable/ic_sync_problem"
21+
app:layout_constraintStart_toStartOf="parent"
22+
app:layout_constraintTop_toTopOf="@android:id/title"
23+
app:layout_constraintBottom_toBottomOf="@android:id/title"/>
24+
1425
<androidx.appcompat.widget.DialogTitleView
1526
android:id="@android:id/title"
1627
android:layout_width="0dp"
1728
android:layout_height="wrap_content"
1829
android:textAppearance="?attr/textAppearanceHeadlineSmall"
19-
android:textColor="?attr/colorOnSurface"
20-
app:layout_constraintEnd_toStartOf="@+id/help_icon"
21-
app:layout_constraintStart_toStartOf="parent"
30+
android:layout_marginStart="12dp"
31+
app:layout_goneMarginStart="0dp"
32+
app:layout_constraintStart_toEndOf="@id/title_icon"
33+
app:layout_constraintEnd_toStartOf="@id/help_icon"
34+
app:layout_constraintTop_toTopOf="parent"
35+
app:layout_constraintBottom_toBottomOf="parent"
2236
tools:text="Reset Card Progress" />
2337

2438
<ImageView
2539
android:id="@+id/help_icon"
2640
style="?attr/materialAlertDialogTitleIconStyle"
2741
android:layout_width="wrap_content"
2842
android:layout_height="wrap_content"
29-
android:layout_marginEnd="8dp"
3043
android:background="?attr/selectableItemBackground"
3144
android:padding="8dp"
3245
android:src="@drawable/ic_help_black_24dp"

AnkiDroid/src/main/res/values/constants.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<string name="link_manual_ar">https://docs.ankidroid.org/manual-ar.html</string>
117117
<string name="link_manual_note_format_toolbar">https://docs.ankidroid.org/manual.html#noteFormattingToolbar</string>
118118
<string name="link_manual_browser_find_replace">https://docs.ankiweb.net/browsing.html#find-and-replace</string>
119+
<string name="link_sync_conflict_help">https://ankidroid.org/#AnkiWebConflicts</string>
119120
<string name="link_user_actions_help">https://docs.ankidroid.org/#userActions</string>
120121
<string name="link_faq_tts">https://github.com/ankidroid/Anki-Android/wiki/FAQ#tts--text-to-speech-is-not-speaking</string>
121122
<string name="link_faq_missing_media" tools:ignore="Typos">https://github.com/ankidroid/Anki-Android/wiki/FAQ#why-doesnt-my-sound-or-image-work-on-ankidroid</string>

0 commit comments

Comments
 (0)