Skip to content

Commit f644067

Browse files
committed
feat:Add help icon to sync dialog
1 parent f02839f commit f644067

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
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 */
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7-
style="?attr/materialAlertDialogTitlePanelStyle"
87
android:orientation="horizontal"
9-
android:paddingStart="24dp"
10-
android:paddingEnd="8dp"
11-
android:paddingTop="24dp"
12-
android:paddingBottom="8dp">
8+
style="?attr/materialAlertDialogTitlePanelStyle">
9+
10+
<ImageView
11+
android:id="@+id/title_icon"
12+
android:layout_width="24dp"
13+
android:layout_height="24dp"
14+
style="?attr/materialAlertDialogTitleIconStyle"
15+
android:visibility="gone"
16+
app:tint="?attr/colorOnSurface"
17+
tools:src="@drawable/ic_sync_problem"/>
1318

1419
<androidx.appcompat.widget.DialogTitleView
1520
android:id="@android:id/title"
1621
android:layout_width="0dp"
1722
android:layout_height="wrap_content"
18-
android:textAppearance="?attr/textAppearanceHeadlineSmall"
23+
android:layout_weight="1"
1924
android:textColor="?attr/colorOnSurface"
20-
app:layout_constraintEnd_toStartOf="@+id/help_icon"
21-
app:layout_constraintStart_toStartOf="parent"
22-
tools:text="Reset Card Progress" />
25+
style="?attr/materialAlertDialogTitleTextStyle"
26+
tools:text="Sync Conflict" />
2327

2428
<ImageView
2529
android:id="@+id/help_icon"
26-
style="?attr/materialAlertDialogTitleIconStyle"
27-
android:layout_width="wrap_content"
28-
android:layout_height="wrap_content"
29-
android:layout_marginEnd="8dp"
30-
android:background="?attr/selectableItemBackground"
31-
android:padding="8dp"
30+
android:layout_width="48dp"
31+
android:layout_height="match_parent"
32+
android:background="?attr/selectableItemBackgroundBorderless"
3233
android:src="@drawable/ic_help_black_24dp"
3334
android:contentDescription="@string/help"
34-
app:layout_constraintEnd_toEndOf="parent"
35-
app:layout_constraintBottom_toBottomOf="@android:id/title"
36-
app:layout_constraintTop_toTopOf="@android:id/title" />
37-
</androidx.constraintlayout.widget.ConstraintLayout>
35+
app:tint="?attr/colorOnSurface" />
36+
37+
</LinearLayout>

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)