Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.ichi2.anki.dialogs.SyncErrorDialog.Type.DIALOG_SYNC_SANITY_ERROR_CONF
import com.ichi2.anki.dialogs.SyncErrorDialog.Type.DIALOG_USER_NOT_LOGGED_IN_SYNC
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
import com.ichi2.anki.utils.openUrl
import com.ichi2.utils.titleWithHelpIcon

class SyncErrorDialog : AsyncDialogFragment() {
interface SyncErrorDialogListener {
Expand Down Expand Up @@ -93,8 +94,12 @@ class SyncErrorDialog : AsyncDialogFragment() {
DIALOG_SYNC_CONFLICT_RESOLUTION -> {
// Sync conflict; allow user to cancel, or choose between local and remote versions
dialog
.setIcon(R.drawable.ic_sync_problem)
.setPositiveButton(R.string.sync_conflict_keep_local_new) { _, _ ->
.titleWithHelpIcon(
text = getString(R.string.sync_conflict_title_new),
startIcon = R.drawable.ic_sync_problem,
) {
requireContext().openUrl(getString(R.string.link_sync_conflict_help))
}.setPositiveButton(R.string.sync_conflict_keep_local_new) { _, _ ->
requireSyncErrorDialogListener().showSyncErrorDialog(DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_LOCAL)
}.setNegativeButton(R.string.sync_conflict_keep_remote_new) { _, _ ->
requireSyncErrorDialogListener().showSyncErrorDialog(DIALOG_SYNC_CONFLICT_CONFIRM_KEEP_REMOTE)
Expand Down
17 changes: 12 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/utils/AlertDialogFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,24 @@ fun AlertDialog.Builder.listItemsAndMessage(
* }
* ```
*
* @param block action executed when the help icon is clicked
*
* @param onHelpClick action executed when the help icon is clicked
* @param startIcon optional icon to display at the start of the title
*/
fun AlertDialog.Builder.titleWithHelpIcon(
@StringRes stringRes: Int? = null,
text: String? = null,
block: View.OnClickListener,
) {
@DrawableRes startIcon: Int? = null,
onHelpClick: View.OnClickListener,
): AlertDialog.Builder {
// setup the view for the dialog
val binding = AlertDialogTitleWithHelpBinding.inflate(LayoutInflater.from(context))
setCustomTitle(binding.root)

if (startIcon != null) {
binding.titleIcon.setImageResource(startIcon)
binding.titleIcon.visibility = View.VISIBLE
}

// apply a custom title
if (stringRes != null) {
binding.title.setText(stringRes)
Expand All @@ -477,8 +483,9 @@ fun AlertDialog.Builder.titleWithHelpIcon(
// set the action when clicking the help icon
binding.helpIcon.setOnClickListener { v ->
Timber.i("dialog help icon click")
block.onClick(v)
onHelpClick.onClick(v)
}
return this
}

/** Calls [AlertDialog.dismiss], ignoring errors */
Expand Down
25 changes: 19 additions & 6 deletions AnkiDroid/src/main/res/layout/alert_dialog_title_with_help.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?attr/materialAlertDialogTitlePanelStyle"
android:orientation="horizontal"
android:paddingStart="24dp"
android:paddingEnd="8dp"
android:paddingTop="24dp"
android:paddingBottom="8dp">

<ImageView
android:id="@+id/title_icon"
android:layout_width="24dp"
android:layout_height="24dp"
style="?attr/materialAlertDialogTitleIconStyle"
android:visibility="gone"
tools:src="@drawable/ic_sync_problem"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@android:id/title"
app:layout_constraintBottom_toBottomOf="@android:id/title"/>

<androidx.appcompat.widget.DialogTitleView
android:id="@android:id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceHeadlineSmall"
android:textColor="?attr/colorOnSurface"
app:layout_constraintEnd_toStartOf="@+id/help_icon"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="12dp"
app:layout_goneMarginStart="0dp"
app:layout_constraintStart_toEndOf="@id/title_icon"
app:layout_constraintEnd_toStartOf="@id/help_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="Reset Card Progress" />

<ImageView
android:id="@+id/help_icon"
Comment thread
Fandroid745 marked this conversation as resolved.
style="?attr/materialAlertDialogTitleIconStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="?attr/selectableItemBackground"
android:padding="8dp"
android:src="@drawable/ic_help_black_24dp"
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<string name="link_manual_ar">https://docs.ankidroid.org/manual-ar.html</string>
<string name="link_manual_note_format_toolbar">https://docs.ankidroid.org/manual.html#noteFormattingToolbar</string>
<string name="link_manual_browser_find_replace">https://docs.ankiweb.net/browsing.html#find-and-replace</string>
<string name="link_sync_conflict_help">https://ankidroid.org/#AnkiWebConflicts</string>
<string name="link_user_actions_help">https://docs.ankidroid.org/#userActions</string>
<string name="link_faq_tts">https://github.com/ankidroid/Anki-Android/wiki/FAQ#tts--text-to-speech-is-not-speaking</string>
<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>
Expand Down
Loading