Fix crashes
This commit is contained in:
@@ -52,6 +52,7 @@ import org.koitharu.kotatsu.core.ui.dialog.buildAlertDialog
|
|||||||
import org.koitharu.kotatsu.core.util.ext.connectivityManager
|
import org.koitharu.kotatsu.core.util.ext.connectivityManager
|
||||||
import org.koitharu.kotatsu.core.util.ext.findActivity
|
import org.koitharu.kotatsu.core.util.ext.findActivity
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeDrawable
|
import org.koitharu.kotatsu.core.util.ext.getThemeDrawable
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
||||||
import org.koitharu.kotatsu.core.util.ext.toUriOrNull
|
import org.koitharu.kotatsu.core.util.ext.toUriOrNull
|
||||||
import org.koitharu.kotatsu.core.util.ext.withArgs
|
import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||||
@@ -614,9 +615,11 @@ class AppRouter private constructor(
|
|||||||
startActivity(Intent(contextOrNull() ?: return, activityClass))
|
startActivity(Intent(contextOrNull() ?: return, activityClass))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFragmentManager(): FragmentManager? {
|
private fun getFragmentManager(): FragmentManager? = runCatching {
|
||||||
return fragment?.childFragmentManager ?: activity?.supportFragmentManager
|
fragment?.childFragmentManager ?: activity?.supportFragmentManager
|
||||||
}
|
}.onFailure { exception ->
|
||||||
|
exception.printStackTraceDebug()
|
||||||
|
}.getOrNull()
|
||||||
|
|
||||||
private fun shareLink(link: String, title: String) {
|
private fun shareLink(link: String, title: String) {
|
||||||
val context = contextOrNull() ?: return
|
val context = contextOrNull() ?: return
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.fragment.app.DialogFragment
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.isOnScreen
|
||||||
|
|
||||||
inline val FragmentActivity.router: AppRouter
|
inline val FragmentActivity.router: AppRouter
|
||||||
get() = AppRouter(this)
|
get() = AppRouter(this)
|
||||||
@@ -26,14 +27,15 @@ tailrec fun Fragment.dismissParentDialog(): Boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scaleUpActivityOptionsOf(view: View): Bundle? = if (view.context.isAnimationsEnabled) {
|
fun scaleUpActivityOptionsOf(view: View): Bundle? {
|
||||||
ActivityOptions.makeScaleUpAnimation(
|
if (!view.context.isAnimationsEnabled || !view.isOnScreen()) {
|
||||||
view,
|
return null
|
||||||
0,
|
}
|
||||||
0,
|
return ActivityOptions.makeScaleUpAnimation(
|
||||||
view.width,
|
/* source = */ view,
|
||||||
view.height,
|
/* startX = */ 0,
|
||||||
|
/* startY = */ 0,
|
||||||
|
/* width = */ view.width,
|
||||||
|
/* height = */ view.height,
|
||||||
).toBundle()
|
).toBundle()
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package org.koitharu.kotatsu.core.util.ext
|
package org.koitharu.kotatsu.core.util.ext
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Point
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.MeasureSpec
|
import android.view.View.MeasureSpec
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.Checkable
|
import android.widget.Checkable
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.widget.ActionMenuView
|
import androidx.appcompat.widget.ActionMenuView
|
||||||
@@ -200,3 +203,24 @@ fun View.setContentDescriptionAndTooltip(@StringRes resId: Int) {
|
|||||||
contentDescription = text
|
contentDescription = text
|
||||||
TooltipCompat.setTooltipText(this, text)
|
TooltipCompat.setTooltipText(this, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun View.getWindowBounds(): Rect {
|
||||||
|
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
wm.currentWindowMetrics.bounds
|
||||||
|
} else {
|
||||||
|
val size = Point()
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
display.getSize(size)
|
||||||
|
Rect(0, 0, size.x, size.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.isOnScreen(): Boolean {
|
||||||
|
if (!isShown) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val actualPosition = Rect()
|
||||||
|
getGlobalVisibleRect(actualPosition)
|
||||||
|
return actualPosition.intersect(getWindowBounds())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user