Always show toast in BottomSheet mode, Resolve #633
This commit is contained in:
1 parent
109398d955
commit
25f7e8b35c
3 files changed
+15
-8
No files matched your search
@@ -29,7 +29,7 @@ import com.hippo.ehviewer.UrlOpener
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail
|
||||
import com.hippo.util.tellClipboard
|
||||
import com.hippo.util.tellClipboardWithToast
|
||||
|
||||
class GalleryInfoBottomSheet(detail: GalleryDetail) : BottomSheetDialogFragment() {
|
||||
private var mKeys: ArrayList<String> = arrayListOf()
|
||||
@@ -117,7 +117,7 @@ class GalleryInfoBottomSheet(detail: GalleryDetail) : BottomSheetDialogFragment(
|
||||
if (position == INDEX_PARENT) {
|
||||
UrlOpener.openUrl(context, mValues[position], true)
|
||||
} else {
|
||||
requireActivity() tellClipboard mValues[position]
|
||||
requireActivity() tellClipboardWithToast mValues[position]
|
||||
if (position == INDEX_URL) {
|
||||
// Save it to avoid detect the gallery
|
||||
Settings.putClipboardTextHashCode(mValues[position].hashCode())
|
||||
|
||||
@@ -516,15 +516,17 @@ class MainActivity : StageActivity(), NavigationView.OnNavigationItemSelectedLis
|
||||
}
|
||||
}
|
||||
|
||||
fun showTip(@StringRes id: Int, length: Int) {
|
||||
showTip(getString(id), length)
|
||||
@JvmOverloads
|
||||
fun showTip(@StringRes id: Int, length: Int, useToast: Boolean = false) {
|
||||
showTip(getString(id), length, useToast)
|
||||
}
|
||||
|
||||
/**
|
||||
* If activity is running, show snack bar, otherwise show toast
|
||||
*/
|
||||
fun showTip(message: CharSequence, length: Int) {
|
||||
findViewById<View>(R.id.snackbar)?.apply {
|
||||
@JvmOverloads
|
||||
fun showTip(message: CharSequence, length: Int, useToast: Boolean = false) {
|
||||
findViewById<View>(R.id.snackbar)?.takeUnless { useToast }?.apply {
|
||||
Snackbar.make(
|
||||
this, message,
|
||||
if (length == BaseScene.LENGTH_LONG) Snackbar.LENGTH_LONG else Snackbar.LENGTH_SHORT
|
||||
|
||||
@@ -38,7 +38,12 @@ infix fun Context.tellClipboard(text: String?) {
|
||||
addTextToClipboard(text, false)
|
||||
}
|
||||
|
||||
fun Context.addTextToClipboard(text: String?, isSensitive: Boolean) {
|
||||
infix fun Context.tellClipboardWithToast(text: String?) {
|
||||
addTextToClipboard(text, false, true)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun Context.addTextToClipboard(text: String?, isSensitive: Boolean, useToast: Boolean = false) {
|
||||
getClipboardManager().apply {
|
||||
setPrimaryClip(ClipData.newPlainText(null, text).apply {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && isSensitive)
|
||||
@@ -50,7 +55,7 @@ fun Context.addTextToClipboard(text: String?, isSensitive: Boolean) {
|
||||
// Avoid double notify user since system have done that on Tiramisu above
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||
if (this is MainActivity) {
|
||||
showTip(R.string.copied_to_clipboard, BaseScene.LENGTH_SHORT)
|
||||
showTip(R.string.copied_to_clipboard, BaseScene.LENGTH_SHORT, useToast)
|
||||
} else if (this is SettingsActivity) {
|
||||
showTip(R.string.copied_to_clipboard, BaseScene.LENGTH_SHORT)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user