Skip to content

Commit 65a3f53

Browse files
committed
feat:Add help icon to sync dialog
1 parent 26d61ce commit 65a3f53

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,27 @@ 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 customTitleView = LayoutInflater.from(context).inflate(R.layout.alert_dialog_title_with_help, null, false)
442443
setCustomTitle(customTitleView)
443444

445+
val titleIconView = customTitleView.findViewById<ImageView>(R.id.title_icon)
446+
if (icon != null) {
447+
titleIconView.setImageResource(icon)
448+
titleIconView.visibility = View.VISIBLE
449+
} else {
450+
titleIconView.visibility = View.GONE
451+
}
452+
444453
// apply a custom title
445454
val titleTextView = customTitleView.findViewById<TextView>(android.R.id.title)
446455

@@ -453,8 +462,9 @@ fun AlertDialog.Builder.titleWithHelpIcon(
453462
// set the action when clicking the help icon
454463
customTitleView.findViewById<ImageView>(R.id.help_icon).setOnClickListener { v ->
455464
Timber.i("dialog help icon click")
456-
block.onClick(v)
465+
onHelpClick.onClick(v)
457466
}
467+
return this
458468
}
459469

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

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,49 @@
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
77
style="?attr/materialAlertDialogTitlePanelStyle"
8-
android:orientation="horizontal"
98
android:paddingStart="24dp"
109
android:paddingEnd="8dp"
1110
android:paddingTop="24dp"
1211
android:paddingBottom="8dp">
1312

13+
<ImageView
14+
android:id="@+id/title_icon"
15+
android:layout_width="24dp"
16+
android:layout_height="24dp"
17+
android:visibility="gone"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="@android:id/title"
20+
app:layout_constraintBottom_toBottomOf="@android:id/title"
21+
app:tint="?attr/colorOnSurface"
22+
tools:visibility="visible"
23+
tools:src="@drawable/ic_sync_problem" />
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"
1930
android:textColor="?attr/colorOnSurface"
31+
android:layout_marginStart="12dp"
32+
app:layout_goneMarginStart="0dp"
2033
app:layout_constraintEnd_toStartOf="@+id/help_icon"
21-
app:layout_constraintStart_toStartOf="parent"
22-
tools:text="Reset Card Progress" />
34+
app:layout_constraintStart_toEndOf="@+id/title_icon"
35+
app:layout_constraintTop_toTopOf="parent"
36+
app:layout_constraintBottom_toBottomOf="parent"
37+
tools:text="Sync Conflict" />
2338

2439
<ImageView
2540
android:id="@+id/help_icon"
2641
style="?attr/materialAlertDialogTitleIconStyle"
2742
android:layout_width="wrap_content"
2843
android:layout_height="wrap_content"
29-
android:layout_marginEnd="8dp"
30-
android:background="?attr/selectableItemBackground"
44+
android:background="?attr/selectableItemBackgroundBorderless"
3145
android:padding="8dp"
3246
android:src="@drawable/ic_help_black_24dp"
3347
android:contentDescription="@string/help"
48+
app:tint="?attr/colorOnSurface"
3449
app:layout_constraintEnd_toEndOf="parent"
35-
app:layout_constraintBottom_toBottomOf="@android:id/title"
36-
app:layout_constraintTop_toTopOf="@android:id/title" />
50+
app:layout_constraintTop_toTopOf="@android:id/title"
51+
app:layout_constraintBottom_toBottomOf="@android:id/title" />
52+
3753
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 3 additions & 1 deletion
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>
@@ -348,7 +349,8 @@
348349
<item>android.permission.WRITE_EXTERNAL_STORAGE</item>
349350
</string-array>
350351
<string name="post_notification_permission">android.permission.POST_NOTIFICATIONS</string>
351-
<string name="record_audio_permission">android.permission.RECORD_AUDIO</string>
352+
<string name="record_audio_permission">android
353+
.permission.RECORD_AUDIO</string>
352354

353355

354356
<string-array name="import_cache_error_resolutions">

0 commit comments

Comments
 (0)