Skip to content

Commit

Permalink
refactor: clean up gradle and re-enable spotless configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed Sep 24, 2024
1 parent 03ffb78 commit 6d7e346
Show file tree
Hide file tree
Showing 1,136 changed files with 16,685 additions and 14,640 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ ij_kotlin_allow_trailing_comma_on_call_site=true
# Don't allow any wildcard imports
ij_kotlin_packages_to_use_import_on_demand = unset

ktlint_function_naming_ignore_when_annotated_with = Composable

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion android-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 AniTrend
* Copyright (C) 2019 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
32 changes: 16 additions & 16 deletions android-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 AniTrend
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

~ Copyright (C) 2019 AniTrend
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
Expand Down
26 changes: 15 additions & 11 deletions android-core/src/main/kotlin/co/anitrend/core/android/Extensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 AniTrend
* Copyright (C) 2020 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package co.anitrend.core.android

import android.view.ViewGroup
Expand All @@ -40,7 +39,7 @@ import java.util.Date
*/
inline fun <reified T> koinOf(
qualifier: Qualifier? = null,
noinline parameters: ParametersDefinition? = null
noinline parameters: ParametersDefinition? = null,
): T {
val context = KoinPlatformTools.defaultContext()
val koin = context.get()
Expand All @@ -55,7 +54,7 @@ inline fun <reified T> koinOf(
fun AiringSchedule.asPrettyTime(): String {
val prettyTime = koinOf<PrettyTime>()
return prettyTime.format(
Date(airingAt * 1000)
Date(airingAt * 1000),
)
}

Expand All @@ -72,15 +71,20 @@ fun Instant.asPrettyTime(): String {
/**
* Displays an error message for missing parameters otherwise runs [block]
*/
inline fun ISupportStateLayout.assureParamNotMissing(param: IParam?, block: () -> Unit) {
inline fun ISupportStateLayout.assureParamNotMissing(
param: IParam?,
block: () -> Unit,
) {
if (param == null) {
this as ViewGroup
loadStateFlow.value = LoadState.Error(
RequestError(
topic = context.getString(R.string.app_controller_heading_missing_param),
description = context.getString(R.string.app_controller_message_missing_param),
loadStateFlow.value =
LoadState.Error(
RequestError(
topic = context.getString(R.string.app_controller_heading_missing_param),
description = context.getString(R.string.app_controller_message_missing_param),
),
)
)
} else {
block()
}
else block()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 AniTrend
* Copyright (C) 2020 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package co.anitrend.core.android.animations

import android.animation.Animator
Expand All @@ -25,18 +24,22 @@ import co.anitrend.arch.theme.animator.contract.AbstractAnimator

class AlphaAnimator(
val from: Float = .85f,
val to: Float = 1f
val to: Float = 1f,
) : AbstractAnimator() {
override val interpolator = LinearInterpolator()

override fun getAnimators(view: View): Array<Animator> {
val animator = ObjectAnimator.ofFloat(
view, PROPERTY_NAME, from, to
)
val animator =
ObjectAnimator.ofFloat(
view,
PROPERTY_NAME,
from,
to,
)
return arrayOf(animator)
}

companion object {
private const val PROPERTY_NAME = "alpha"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 AniTrend
* Copyright (C) 2020 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,22 +14,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package co.anitrend.core.android.animations

import androidx.annotation.ColorInt
import androidx.annotation.FloatRange
import com.google.android.material.animation.ArgbEvaluatorCompat
import kotlin.math.roundToInt


/**
* Linearly interpolate between two values
*/
fun lerp(
startValue: Float,
endValue: Float,
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float,
): Float {
return startValue + fraction * (endValue - startValue)
}
Expand All @@ -40,7 +38,7 @@ fun lerp(
fun lerp(
startValue: Int,
endValue: Int,
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float,
): Int {
return (startValue + fraction * (endValue - startValue)).roundToInt()
}
Expand All @@ -55,10 +53,10 @@ fun lerp(
from = 0.0,
fromInclusive = true,
to = 1.0,
toInclusive = false
toInclusive = false,
) startFraction: Float,
@FloatRange(from = 0.0, fromInclusive = false, to = 1.0, toInclusive = true) endFraction: Float,
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float,
): Float {
if (fraction < startFraction) return startValue
if (fraction > endFraction) return endValue
Expand All @@ -76,10 +74,10 @@ fun lerp(
from = 0.0,
fromInclusive = true,
to = 1.0,
toInclusive = false
toInclusive = false,
) startFraction: Float,
@FloatRange(from = 0.0, fromInclusive = false, to = 1.0, toInclusive = true) endFraction: Float,
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float,
): Int {
if (fraction < startFraction) return startValue
if (fraction > endFraction) return endValue
Expand All @@ -98,18 +96,18 @@ fun lerpArgb(
from = 0.0,
fromInclusive = true,
to = 1.0,
toInclusive = false
toInclusive = false,
) startFraction: Float,
@FloatRange(from = 0.0, fromInclusive = false, to = 1.0, toInclusive = true) endFraction: Float,
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float,
): Int {
if (fraction < startFraction) return startColor
if (fraction > endFraction) return endColor

return ArgbEvaluatorCompat.getInstance().evaluate(
(fraction - startFraction) / (endFraction - startFraction),
startColor,
endColor
endColor,
)
}

Expand All @@ -124,7 +122,7 @@ fun Float.normalize(
inputMin: Float,
inputMax: Float,
outputMin: Float,
outputMax: Float
outputMax: Float,
): Float {
if (this < inputMin) {
return outputMin
Expand All @@ -133,5 +131,5 @@ fun Float.normalize(
}

return outputMin * (1 - (this - inputMin) / (inputMax - inputMin)) +
outputMax * ((this - inputMin) / (inputMax - inputMin))
}
outputMax * ((this - inputMin) / (inputMax - inputMin))
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 AniTrend
* Copyright (C) 2021 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package co.anitrend.core.android.behaviour

import android.content.Context
Expand All @@ -29,10 +28,9 @@ import co.anitrend.core.android.R
*/
class BottomOffsetBehavior(
private val context: Context,
private val attributeSet: AttributeSet
private val attributeSet: AttributeSet,
) : CoordinatorLayout.Behavior<View>() {

//TODO: Offsets don't seem to be getting applied on the bottom, not entirely sure what could be missing
// TODO: Offsets don't seem to be getting applied on the bottom, not entirely sure what could be missing

private lateinit var viewOffsetHelper: ViewOffsetHelper

Expand Down Expand Up @@ -60,33 +58,34 @@ class BottomOffsetBehavior(
override fun onLayoutChild(
parent: CoordinatorLayout,
child: View,
layoutDirection: Int
layoutDirection: Int,
): Boolean {
parent.onLayoutChild(child, layoutDirection)

if (!::viewOffsetHelper.isInitialized)
if (!::viewOffsetHelper.isInitialized) {
viewOffsetHelper = ViewOffsetHelper(child)
}

viewOffsetHelper.doOnInit()
viewOffsetHelper.applyOffsets()

return setBottomOffset(
context.resources.getDimensionPixelSize(
R.dimen.design_bottom_app_bar_height
)
R.dimen.design_bottom_app_bar_height,
),
)
}

private fun setBottomOffset(offset: Int): Boolean {
val offsetHelper = viewOffsetHelper
if (::viewOffsetHelper.isInitialized)
if (::viewOffsetHelper.isInitialized) {
return offsetHelper.setBottomOffset(offset)
}

return false
}

private class ViewOffsetHelper(private val view: View) {

private var layoutBottom = 0
private var offsetBottom = 0

Expand Down Expand Up @@ -117,4 +116,4 @@ class BottomOffsetBehavior(
return false
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 AniTrend
* Copyright (C) 2020 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package co.anitrend.core.android.binding

import androidx.viewbinding.ViewBinding
Expand All @@ -24,8 +23,7 @@ import androidx.viewbinding.ViewBinding
*
* @property binding The binding property that represents a view
*/
interface IBindingView<B: ViewBinding> {

interface IBindingView<B : ViewBinding> {
var binding: B?

/**
Expand All @@ -36,4 +34,4 @@ interface IBindingView<B: ViewBinding> {
*/
@Throws(IllegalArgumentException::class)
fun requireBinding(): B = requireNotNull(binding)
}
}
Loading

0 comments on commit 6d7e346

Please sign in to comment.