Fixed Toast.getView() and Html.fromHtml() is deprecated

* We already handled the deprecation of `fromHtml`, we have a string's extension function to handle the this so we are now using that function.
* Since `Toast.getView()` is no longer supported after Android 11 (it always returns null on Android 11 and above devices), we no longer need to show the toast on the ZIM file that is clicked by the user for UI enhancement. Therefore, we have removed this function and are now using the context class extension function to display the toast message.
This commit is contained in:
MohitMaliFtechiz 2023-06-23 18:49:58 +05:30 committed by Kelson
parent 4723d869d2
commit 36803af9e2
2 changed files with 8 additions and 27 deletions

View File

@ -18,18 +18,14 @@
package org.kiwix.kiwixmobile.zimManager.libraryView.adapter
import android.annotation.SuppressLint
import android.view.Gravity
import android.view.View
import android.view.View.MeasureSpec
import android.widget.Toast
import androidx.annotation.StringRes
import com.tonyodev.fetch2.Status
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.base.adapter.BaseViewHolder
import org.kiwix.kiwixmobile.core.downloader.model.Base64String
import org.kiwix.kiwixmobile.core.extensions.setBitmap
import org.kiwix.kiwixmobile.core.extensions.setTextAndVisibility
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.utils.BookUtils
import org.kiwix.kiwixmobile.core.zim_manager.KiloByte
import org.kiwix.kiwixmobile.databinding.ItemDownloadBinding
@ -75,9 +71,10 @@ sealed class LibraryViewHolder<in T : LibraryListItem>(containerView: View) :
else
View.VISIBLE
itemLibraryBinding.unableToDownload.setOnLongClickListener {
val context = itemLibraryBinding.root.context
when (item.fileSystemState) {
CannotWrite4GbFile -> it.centreToast(R.string.file_system_does_not_support_4gb)
DetectingFileSystem -> it.centreToast(R.string.detecting_file_system)
CannotWrite4GbFile -> context.toast(R.string.file_system_does_not_support_4gb)
DetectingFileSystem -> context.toast(R.string.detecting_file_system)
else -> {
if (item.canBeDownloaded && !hasAvailableSpaceInStorage) {
clickAction.invoke(item)
@ -119,21 +116,3 @@ sealed class LibraryViewHolder<in T : LibraryListItem>(containerView: View) :
}
}
}
@SuppressLint("ShowToast")
private fun View.centreToast(@StringRes id: Int) {
val locationXAndY = intArrayOf(0, 0)
getLocationOnScreen(locationXAndY)
val midX = locationXAndY[0] + width / 2
val midY = locationXAndY[1] + height / 2
Toast.makeText(context, id, Toast.LENGTH_LONG).apply {
view?.let { view ->
view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
setGravity(
Gravity.TOP or Gravity.START,
midX - view.measuredWidth / 2,
midY - view.measuredHeight
)
}
}.show()
}

View File

@ -18,12 +18,12 @@
package org.kiwix.kiwixmobile.core.utils.dialog
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.ClipData
import android.content.ClipboardManager
import android.net.Uri
import android.text.Html
import android.view.Gravity
import android.view.ViewGroup.LayoutParams
import android.widget.FrameLayout
@ -33,6 +33,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.getAttribute
import org.kiwix.kiwixmobile.core.utils.StyleUtils.fromHtml
import javax.inject.Inject
class AlertDialogShower @Inject constructor(private val activity: Activity) :
@ -89,7 +90,8 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :
).show()
true
}
text = Html.fromHtml("</br><a href=$uri> <b>$uri</b>")
@SuppressLint("SetTextI18n")
text = "</br><a href=$uri> <b>$uri</b>".fromHtml()
}
frameLayout.addView(textView)
setView(frameLayout)