Skip to content

Commit

Permalink
I have no idea why that crashes for some people...
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Dec 31, 2023
1 parent 7dbf951 commit 7228817
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.internal.ViewUtils
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.*
import nl.joery.animatedbottombar.AnimatedBottomBar
import java.io.*
Expand Down Expand Up @@ -783,35 +784,40 @@ fun toast(string: String?) {
}

fun snackString(s: String?, activity: Activity? = null, clipboard: String? = null) {
if (s != null) {
(activity ?: currActivity())?.apply {
runOnUiThread {
val snackBar = Snackbar.make(
window.decorView.findViewById(android.R.id.content),
s,
Snackbar.LENGTH_SHORT
)
snackBar.view.apply {
updateLayoutParams<FrameLayout.LayoutParams> {
gravity = (Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM)
width = WRAP_CONTENT
}
translationY = -(navBarHeight.dp + 32f)
translationZ = 32f
updatePadding(16f.px, right = 16f.px)
setOnClickListener {
snackBar.dismiss()
}
setOnLongClickListener {
copyToClipboard(clipboard ?: s, false)
toast(getString(R.string.copied_to_clipboard))
true
try { //I have no idea why this sometimes crashes for some people...
if (s != null) {
(activity ?: currActivity())?.apply {
runOnUiThread {
val snackBar = Snackbar.make(
window.decorView.findViewById(android.R.id.content),
s,
Snackbar.LENGTH_SHORT
)
snackBar.view.apply {
updateLayoutParams<FrameLayout.LayoutParams> {
gravity = (Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM)
width = WRAP_CONTENT
}
translationY = -(navBarHeight.dp + 32f)
translationZ = 32f
updatePadding(16f.px, right = 16f.px)
setOnClickListener {
snackBar.dismiss()
}
setOnLongClickListener {
copyToClipboard(clipboard ?: s, false)
toast(getString(R.string.copied_to_clipboard))
true
}
}
snackBar.show()
}
snackBar.show()
}
logger(s)
}
logger(s)
} catch (e: Exception) {
logger(e.stackTraceToString())
FirebaseCrashlytics.getInstance().recordException(e)
}
}

Expand Down

0 comments on commit 7228817

Please sign in to comment.