From d983b81864845b59606cfc4f4142889ed16962c3 Mon Sep 17 00:00:00 2001 From: Robozinho <65715921+RobozinhoD@users.noreply.github.com> Date: Fri, 3 May 2024 06:47:20 -0300 Subject: [PATCH] fix sync tooltip text --- .../src/main/java/com/ichi2/anki/DeckPicker.kt | 18 ++++++++++-------- .../java/com/ichi2/anki/SyncActionProvider.kt | 7 +++++++ .../main/res/layout/sync_progress_layout.xml | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt index d17d8a25b570..9f081f8533d6 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt @@ -995,14 +995,16 @@ open class DeckPicker : } menuItem.isVisible = true - menuItem.setTitle( - when (state.syncIcon) { - SyncIconState.Normal, SyncIconState.PendingChanges -> R.string.button_sync - SyncIconState.OneWay -> R.string.sync_menu_title_one_way_sync - SyncIconState.NotLoggedIn -> R.string.sync_menu_title_no_account - } - ) - val provider = MenuItemCompat.getActionProvider(menuItem) as? SyncActionProvider ?: return + val provider = MenuItemCompat.getActionProvider(menuItem) as? SyncActionProvider + ?: return + val tooltipText = when (state.syncIcon) { + SyncIconState.Normal, SyncIconState.PendingChanges -> R.string.button_sync + SyncIconState.OneWay -> R.string.sync_menu_title_one_way_sync + SyncIconState.NotLoggedIn -> R.string.sync_menu_title_no_account + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + provider.setTooltipText(getString(tooltipText)) + } when (state.syncIcon) { SyncIconState.Normal -> { BadgeDrawableBuilder.removeBadge(provider) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/SyncActionProvider.kt b/AnkiDroid/src/main/java/com/ichi2/anki/SyncActionProvider.kt index 2f0df31b7d81..b5d1267b0dd4 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/SyncActionProvider.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/SyncActionProvider.kt @@ -18,9 +18,11 @@ package com.ichi2.anki import android.app.Activity import android.content.Context import android.graphics.drawable.Drawable +import android.os.Build import android.view.LayoutInflater import android.view.MenuItem import android.view.View +import androidx.annotation.RequiresApi import androidx.appcompat.widget.AppCompatImageButton import androidx.core.view.isVisible import com.google.android.material.progressindicator.LinearProgressIndicator @@ -57,4 +59,9 @@ class SyncActionProvider(context: Context) : ActionProviderCompat(context) { return view } + + @RequiresApi(Build.VERSION_CODES.O) + fun setTooltipText(value: CharSequence) { + syncButton?.tooltipText = value + } } diff --git a/AnkiDroid/src/main/res/layout/sync_progress_layout.xml b/AnkiDroid/src/main/res/layout/sync_progress_layout.xml index c0f43bf4c3e1..18c3414e24b6 100644 --- a/AnkiDroid/src/main/res/layout/sync_progress_layout.xml +++ b/AnkiDroid/src/main/res/layout/sync_progress_layout.xml @@ -12,6 +12,7 @@ android:layout_height="@dimen/touch_target" app:srcCompat="@drawable/ic_sync" style="@android:style/Widget.ActionButton" + android:tooltipText="@string/button_sync" android:tint="@color/white" tools:tint="?attr/colorControlNormal" />