Skip to content

Commit

Permalink
kiwix#3668 Added setToolTip function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagar0-0 committed Feb 3, 2024
1 parent feb816c commit cf65632
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package org.kiwix.kiwixmobile.core.extensions

import android.annotation.SuppressLint
import android.os.Build
import android.view.View
import androidx.annotation.ColorInt
import androidx.appcompat.widget.TooltipCompat
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar

Expand Down Expand Up @@ -69,3 +71,11 @@ fun View.snack(
})
}.show()
}

fun View.setToolTip(description: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
TooltipCompat.setTooltipText(this, description)
} else {
contentDescription = description
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import androidx.annotation.AnimRes
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.appcompat.widget.TooltipCompat
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.Group
import androidx.coordinatorlayout.widget.CoordinatorLayout
Expand Down Expand Up @@ -115,6 +114,7 @@ import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.observeNavigatio
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.requestNotificationPermission
import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.findFirstTextView
import org.kiwix.kiwixmobile.core.extensions.isFileExist
import org.kiwix.kiwixmobile.core.extensions.setToolTip
import org.kiwix.kiwixmobile.core.extensions.snack
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.main.DocumentParser.SectionsListener
Expand Down Expand Up @@ -693,6 +693,7 @@ abstract class CoreReaderFragment :
)
setDisplayShowTitleEnabled(false)
}
closeAllTabsButton?.setToolTip(resources.getString(R.string.close_all_tabs))
// Set a negative top margin to the web views to remove
// the unwanted blank space caused by the toolbar.
setTopMarginToWebViews(-requireActivity().getToolbarHeight())
Expand Down Expand Up @@ -769,11 +770,6 @@ abstract class CoreReaderFragment :
setImageDrawable(
ContextCompat.getDrawable(requireActivity(), R.drawable.ic_close_black_24dp)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
TooltipCompat.setTooltipText(this, resources.getString(R.string.close_all_tabs))
} else {
contentDescription = resources.getString(R.string.close_all_tabs)
}
}
tabSwitcherRoot?.let {
if (it.visibility == View.VISIBLE) {
Expand Down Expand Up @@ -937,22 +933,27 @@ abstract class CoreReaderFragment :
hideTabSwitcher()
return FragmentActivityExtensions.Super.ShouldNotCall
}

isInFullScreenMode() -> {
closeFullScreen()
return FragmentActivityExtensions.Super.ShouldNotCall
}

compatCallback?.isActive == true -> {
compatCallback?.finish()
return FragmentActivityExtensions.Super.ShouldNotCall
}

drawerLayout?.isDrawerOpen(GravityCompat.END) == true -> {
drawerLayout?.closeDrawers()
return FragmentActivityExtensions.Super.ShouldNotCall
}

getCurrentWebView()?.canGoBack() == true -> {
getCurrentWebView()?.goBack()
return FragmentActivityExtensions.Super.ShouldNotCall
}

else -> return FragmentActivityExtensions.Super.ShouldCall
}
}
Expand Down Expand Up @@ -1024,6 +1025,7 @@ abstract class CoreReaderFragment :
pauseTTSButton?.setText(R.string.tts_resume)
setActionAndStartTTSService(ACTION_PAUSE_OR_RESUME_TTS, true)
}

AudioManager.AUDIOFOCUS_GAIN -> {
pauseTTSButton?.setText(R.string.tts_pause)
setActionAndStartTTSService(ACTION_PAUSE_OR_RESUME_TTS, false)
Expand Down Expand Up @@ -1309,12 +1311,14 @@ abstract class CoreReaderFragment :
startReadAloud()
}
}

View.VISIBLE -> {
if (isBackToTopEnabled) {
backToTopButton?.show()
}
tts?.stop()
}

else -> {}
}
}
Expand Down Expand Up @@ -1585,6 +1589,7 @@ abstract class CoreReaderFragment :
}
}
}

REQUEST_POST_NOTIFICATION_PERMISSION -> {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
onReadAloudMenuClicked()
Expand Down Expand Up @@ -1736,18 +1741,22 @@ abstract class CoreReaderFragment :
// see https://github.com/kiwix/kiwix-android/issues/2607
intent.action = null
}

CoreSearchWidget.TEXT_CLICKED -> {
goToSearch(false)
intent.action = null
}

CoreSearchWidget.STAR_CLICKED -> {
goToBookmarks()
intent.action = null
}

CoreSearchWidget.MIC_CLICKED -> {
goToSearch(true)
intent.action = null
}

Intent.ACTION_VIEW -> if (intent.type == null ||
intent.type != "application/octet-stream"
) {
Expand Down Expand Up @@ -2055,10 +2064,12 @@ abstract class CoreReaderFragment :
// This is my web site, so do not override; let my WebView load the page
handleEvent = true
}

url.startsWith("file://") -> {
// To handle help page (loaded from resources)
handleEvent = true
}

url.startsWith(ZimFileReader.UI_URI.toString()) -> {
handleEvent = true
}
Expand Down
10 changes: 3 additions & 7 deletions core/src/main/java/org/kiwix/kiwixmobile/core/main/MainMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ package org.kiwix.kiwixmobile.core.main

import android.app.Activity
import android.content.res.Configuration
import android.os.Build
import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.isVisible
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.setToolTip
import org.kiwix.kiwixmobile.core.reader.ZimFileReader

const val REQUEST_FILE_SEARCH = 1236
Expand Down Expand Up @@ -102,11 +101,7 @@ class MainMenu(
)
tabSwitcher?.actionView?.apply {
setOnClickListener { menuClickListener.onTabMenuClicked() }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
TooltipCompat.setTooltipText(this, resources.getText(R.string.switch_tabs))
} else {
contentDescription = resources.getText(R.string.switch_tabs)
}
setToolTip(resources.getString(R.string.switch_tabs))
}
addNote.menuItemClickListener { menuClickListener.onAddNoteMenuClicked() }
randomArticle.menuItemClickListener { menuClickListener.onRandomArticleMenuClicked() }
Expand All @@ -126,6 +121,7 @@ class MainMenu(
menuClickListener.onHomeMenuClicked()
true
}

else -> false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.kiwix.kiwixmobile.core.main

import android.annotation.SuppressLint
import android.os.Build
import android.text.TextUtils
import android.util.TypedValue
import android.view.View
Expand All @@ -27,7 +26,6 @@ import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.TooltipCompat
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.ConstraintSet.BOTTOM
Expand All @@ -40,6 +38,7 @@ import com.google.android.material.card.MaterialCardView
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.getAttribute
import org.kiwix.kiwixmobile.core.extensions.setImageDrawableCompat
import org.kiwix.kiwixmobile.core.extensions.setToolTip
import org.kiwix.kiwixmobile.core.extensions.tint
import org.kiwix.kiwixmobile.core.utils.DimenUtils.getToolbarHeight
import org.kiwix.kiwixmobile.core.utils.DimenUtils.getWindowHeight
Expand Down Expand Up @@ -68,11 +67,7 @@ class TabsAdapter internal constructor(
.apply {
id = R.id.tabsAdapterCloseImageView
setImageDrawableCompat(R.drawable.ic_clear_white_24dp)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
TooltipCompat.setTooltipText(this, "Close Tab")
} else {
contentDescription = "Close Tab"
}
setToolTip(resources.getString(R.string.close_tab))
val outValue = TypedValue()
context.theme.resolveAttribute(android.R.attr.actionBarItemBackground, outValue, true)
setBackgroundResource(outValue.resourceId)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<string name="search_bookmarks">Search bookmarks</string>
<string name="switch_tabs">Switch tabs</string>
<string name="close_all_tabs">Close all tabs</string>
<string name="close_tab">Close tab</string>
<string name="pending_state">Pending</string>
<string name="running_state">In Progress</string>
<string name="complete">Complete</string>
Expand Down

0 comments on commit cf65632

Please sign in to comment.