Skip to content

Commit 155035b

Browse files
committed
feat:Add help icon to sync dialog
1 parent 90df467 commit 155035b

4 files changed

Lines changed: 50 additions & 16 deletions

File tree

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

Lines changed: 13 additions & 3 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,11 +94,20 @@ 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+
.titleWithHelpIcon(
98+
text = getString(R.string.sync_conflict_title_new),
99+
icon = R.drawable.ic_sync_problem,
100+
) {
101+
requireContext().openUrl(getString(R.string.link_sync_conflict_help))
102+
}.setMessage(R.string.sync_conflict_message_new)
97103
.setPositiveButton(R.string.sync_conflict_keep_local_new) { _, _ ->
98-
requireSyncErrorDialogListener().showSyncErrorDialog(DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_LOCAL)
104+
requireSyncErrorDialogListener().showSyncErrorDialog(
105+
DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_LOCAL,
106+
)
99107
}.setNegativeButton(R.string.sync_conflict_keep_remote_new) { _, _ ->
100-
requireSyncErrorDialogListener().showSyncErrorDialog(DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_REMOTE)
108+
requireSyncErrorDialogListener().showSyncErrorDialog(
109+
DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_REMOTE,
110+
)
101111
}.setNeutralButton(R.string.dialog_cancel) { _, _ ->
102112
activity?.dismissAllDialogFragments()
103113
}.create()

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,26 @@ fun AlertDialog.Builder.listItemsAndMessage(
429429
* }
430430
* ```
431431
*
432-
* @param block action executed when the help icon is clicked
432+
* @param onHelpClick action executed when the help icon is clicked
433433
*
434434
*/
435435
fun AlertDialog.Builder.titleWithHelpIcon(
436436
@StringRes stringRes: Int? = null,
437437
text: String? = null,
438-
block: View.OnClickListener,
439-
) {
438+
@DrawableRes icon: Int? = null,
439+
onHelpClick: View.OnClickListener,
440+
): AlertDialog.Builder {
440441
// setup the view for the dialog
441442
val binding = AlertDialogTitleWithHelpBinding.inflate(LayoutInflater.from(context))
442443
setCustomTitle(binding.root)
443444

445+
if (icon != null) {
446+
binding.titleIcon.setImageResource(icon)
447+
binding.titleIcon.visibility = View.VISIBLE
448+
} else {
449+
binding.titleIcon.visibility = View.GONE
450+
}
451+
444452
// apply a custom title
445453
if (stringRes != null) {
446454
binding.title.setText(stringRes)
@@ -451,8 +459,9 @@ fun AlertDialog.Builder.titleWithHelpIcon(
451459
// set the action when clicking the help icon
452460
binding.helpIcon.setOnClickListener { v ->
453461
Timber.i("dialog help icon click")
454-
block.onClick(v)
462+
onHelpClick.onClick(v)
455463
}
464+
return this
456465
}
457466

458467
/** Calls [AlertDialog.dismiss], ignoring errors */
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
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"
26-
style="?attr/materialAlertDialogTitleIconStyle"
2740
android:layout_width="wrap_content"
2841
android:layout_height="wrap_content"
29-
android:layout_marginEnd="8dp"
3042
android:background="?attr/selectableItemBackground"
43+
style="?attr/materialAlertDialogTitleIconStyle"
3144
android:padding="8dp"
3245
android:src="@drawable/ic_help_black_24dp"
33-
android:contentDescription="@string/help"
3446
app:layout_constraintEnd_toEndOf="parent"
47+
app:layout_constraintTop_toTopOf="@android:id/title"
3548
app:layout_constraintBottom_toBottomOf="@android:id/title"
36-
app:layout_constraintTop_toTopOf="@android:id/title" />
49+
android:contentDescription="@string/help" />
50+
3751
</androidx.constraintlayout.widget.ConstraintLayout>

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://docs.ankiweb.net/syncing.html#conflicts</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)