Skip to content

Commit

Permalink
fix: edge to edge padding bottom inclusion and typo in calError => ca…
Browse files Browse the repository at this point in the history
…llError
  • Loading branch information
CraZyLegenD committed Nov 23, 2020
1 parent 945b58e commit adbb93b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.crazylegend.customviews.databinding.CustomizableCardViewBinding
import com.crazylegend.kotlinextensions.context.getCompatColor
import com.crazylegend.kotlinextensions.context.isGestureNavigationEnabled
import com.crazylegend.kotlinextensions.delegates.activityAVM
import com.crazylegend.kotlinextensions.effects.circularRevealEnter
import com.crazylegend.kotlinextensions.exhaustive
import com.crazylegend.kotlinextensions.gestureNavigation.EdgeToEdge
import com.crazylegend.kotlinextensions.log.debug
Expand Down Expand Up @@ -96,12 +97,12 @@ class MainAbstractActivity : AppCompatActivity() {
debug("SECURITY isDebuggable ${isDebuggable()}")
debug("SECURITY isDebuggerAttached ${isDebuggerAttached()}")
debug("SECURITY zygoteCallCount ${zygoteCallCount()}")
debug("SECURITY getSingInfoMD5 ${getSingInfoMD5(BuildConfig.APPLICATION_ID)}")
debug("SECURITY getSingInfoMD5 ${getSingInfoMD5("com.crazylegend.setofusefulkotlinextensions")}")
debug("SECURITY isEmulator ${isEmulator()}")
debug("SECURITY getShaSignature ${getShaSignature(BuildConfig.APPLICATION_ID)}")
debug("SECURITY getShaSignature ${getShaSignature("com.crazylegend.setofusefulkotlinextensions")}")

activityMainBinding.test.setOnClickListenerCooldown {
testAVM.getposts()
it.circularRevealEnter()
}
lifecycleScope.launchWhenResumed {
testAVM.posts.collect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,45 +83,42 @@ insets
}
*/
object EdgeToEdge
: EdgeToEdgeImpl by if (Build.VERSION.SDK_INT >= 21) EdgeToEdgeApi21() else EdgeToEdgeBase()
object EdgeToEdge : EdgeToEdgeImpl by EdgeToEdgeApi21()

private interface EdgeToEdgeImpl {

/**
* Configures a root view of an Activity in edge-to-edge display.
* @param root A root view of an Activity.
*/
fun setUpRoot(root: ViewGroup) {}
fun setUpRoot(root: ViewGroup)

@RequiresApi(Build.VERSION_CODES.R)
fun setUpRoot(activity: Activity, root: ViewGroup, @ColorRes navBarColor: Int = android.R.color.transparent) {
}
fun setUpRoot(activity: Activity, root: ViewGroup, @ColorRes navBarColor: Int = android.R.color.transparent)

/**
* Configures an app bar and a toolbar for edge-to-edge display.
* @param appBar An [AppBarLayout].
* @param toolbar A [Toolbar] in the [appBar].
*/
fun setUpAppBar(appBar: AppBarLayout, toolbar: Toolbar) {}
fun setUpAppBar(appBar: AppBarLayout, toolbar: Toolbar)

/**
* Configures a scrolling content for edge-to-edge display.
* @param scrollingContent A scrolling ViewGroup. This is typically a RecyclerView or a
* ScrollView. It should be as wide as the screen, and should touch the bottom edge of
* the screen.
*/
fun setUpScrollingContent(scrollingContent: ViewGroup) {}
fun setUpScrollingContent(scrollingContent: ViewGroup, includePaddingBottom: Boolean = false)

/**
* Tell the window that we want to handle/fit any system windows
*/
fun setDecorFitsSystemWindows(window: Window, setDecor: Boolean = true) {}
fun setDecorFitsSystemWindows(window: Window, setDecor: Boolean = true)
fun setDecorFitsSystemWindows(activity: Activity, setDecor: Boolean = true)
}

private class EdgeToEdgeBase : EdgeToEdgeImpl

@RequiresApi(21)
@Suppress("DEPRECATION")
private class EdgeToEdgeApi21 : EdgeToEdgeImpl {

override fun setUpRoot(root: ViewGroup) {
Expand Down Expand Up @@ -161,27 +158,39 @@ private class EdgeToEdgeApi21 : EdgeToEdgeImpl {
}
}

override fun setDecorFitsSystemWindows(activity: Activity, setDecor: Boolean) {
WindowCompat.setDecorFitsSystemWindows(activity.window, setDecor)

}

override fun setDecorFitsSystemWindows(window: Window, setDecor: Boolean) {
WindowCompat.setDecorFitsSystemWindows(window, setDecor)
}

override fun setUpScrollingContent(scrollingContent: ViewGroup) {
override fun setUpScrollingContent(scrollingContent: ViewGroup, includePaddingBottom: Boolean) {
val originalPaddingLeft = scrollingContent.paddingLeft
val originalPaddingRight = scrollingContent.paddingRight
val originalPaddingBottom = scrollingContent.paddingBottom
val originalPaddingTop = scrollingContent.paddingTop


scrollingContent.setOnApplyWindowInsetsListener { _, windowInsets ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val insets = windowInsets.getInsets(WindowInsets.Type.systemBars())
val bottomPadding = if (includePaddingBottom) originalPaddingBottom + insets.bottom else originalPaddingBottom
scrollingContent.updatePadding(
left = originalPaddingLeft + insets.left,
right = originalPaddingRight + insets.right,
bottom = originalPaddingBottom + insets.bottom
bottom = bottomPadding,
top = originalPaddingTop + insets.top
)
} else {
val paddingBottomCompat = if (includePaddingBottom) originalPaddingBottom + windowInsets.systemWindowInsetBottom else originalPaddingBottom
scrollingContent.updatePadding(
left = originalPaddingLeft + windowInsets.systemWindowInsetLeft,
right = originalPaddingRight + windowInsets.systemWindowInsetRight,
bottom = originalPaddingBottom + windowInsets.systemWindowInsetBottom
bottom = paddingBottomCompat,
top = originalPaddingTop + windowInsets.systemWindowInsetTop
)
}
windowInsets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fun PagingStateResult.handle(
loadingMore: () -> Unit,
cantLoadMore: () -> Unit,
emptyData: () -> Unit,
calError: (throwable: Throwable) -> Unit = { _ -> },
callError: (throwable: Throwable) -> Unit = { _ -> },
apiError: (errorBody: ResponseBody?, responseCode: Int) -> Unit = { _, _ -> },
success: () -> Unit
) {
Expand All @@ -37,7 +37,7 @@ fun PagingStateResult.handle(
emptyData()
}
is PagingStateResult.Error -> {
calError(throwable)
callError(throwable)
}
is PagingStateResult.ApiError -> {
apiError(errorBody, responseCode)
Expand Down Expand Up @@ -157,7 +157,7 @@ fun MutableLiveData<PagingStateResult>.cantLoadMore() {
fun <T> MutableLiveData<PagingStateResult>.subscribe(response: Response<T>?, includeEmptyData: Boolean = false) {
response?.let { serverResponse ->
if (serverResponse.isSuccessful) {
serverResponse.body()?.apply {
serverResponse.body().apply {
value = if (includeEmptyData) {
if (this == null) {
PagingStateResult.EmptyData
Expand All @@ -177,7 +177,7 @@ fun <T> MutableLiveData<PagingStateResult>.subscribe(response: Response<T>?, inc
fun <T> MutableLiveData<PagingStateResult>.subscribePost(response: Response<T>?, includeEmptyData: Boolean = false) {
response?.let { serverResponse ->
if (serverResponse.isSuccessful) {
serverResponse.body()?.apply {
serverResponse.body().apply {
if (includeEmptyData) {
if (this == null) {
postValue(PagingStateResult.EmptyData)
Expand All @@ -198,7 +198,7 @@ fun <T> MutableLiveData<PagingStateResult>.subscribePost(response: Response<T>?,
fun <T> MutableLiveData<PagingStateResult>.subscribeList(response: Response<T>?, includeEmptyData: Boolean = false) {
response?.let { serverResponse ->
if (serverResponse.isSuccessful) {
serverResponse.body()?.apply {
serverResponse.body().apply {
if (includeEmptyData) {
value = if (this == null) {
PagingStateResult.EmptyData
Expand Down Expand Up @@ -228,7 +228,7 @@ fun <T> MutableLiveData<PagingStateResult>.subscribeList(response: Response<T>?,
fun <T> MutableLiveData<PagingStateResult>.subscribeListPost(response: Response<T>?, includeEmptyData: Boolean = false) {
response?.let { serverResponse ->
if (serverResponse.isSuccessful) {
serverResponse.body()?.apply {
serverResponse.body().apply {
if (includeEmptyData) {
if (this == null) {
postValue(PagingStateResult.EmptyData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import retrofit2.Response
inline fun <T> RetrofitResult<T>.handle(
loading: () -> Unit = {},
emptyData: () -> Unit = {},
calError: (throwable: Throwable) -> Unit = { _ -> },
callError: (throwable: Throwable) -> Unit = { _ -> },
apiError: (errorBody: ResponseBody?, responseCode: Int) -> Unit = { _, _ -> },
success: T.() -> Unit
) {
Expand All @@ -32,7 +32,7 @@ inline fun <T> RetrofitResult<T>.handle(
emptyData()
}
is RetrofitResult.Error -> {
calError(throwable)
callError(throwable)
}
is RetrofitResult.ApiError -> {
apiError(errorBody, responseCode)
Expand Down

0 comments on commit adbb93b

Please sign in to comment.