<commit_before>/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package app.tivi.ui.epoxy

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.graphics.drawable.Drawable
import android.util.Log
import android.view.View
import androidx.annotation.ColorInt
import app.tivi.ui.animations.lerp
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.EpoxyTouchHelper
import kotlin.math.roundToInt

abstract class SwipeAwayCallbacks<T : EpoxyModel<*>>(
    private val icon: Drawable,
    private val padding: Int,
    @ColorInt private val backgroundColor: Int,
    @ColorInt private val accentColor: Int
) : EpoxyTouchHelper.SwipeCallbacks<T>() {
    private val rect = RectF()
    private val iconBounds = Rect()

    private val iconHeight = icon.intrinsicHeight
    private val iconWidth = icon.intrinsicWidth

    private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = backgroundColor
    }

    private val foregroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = accentColor
    }

    companion object {
        const val MAX_ICON_SCALE = 1.3f
        const val MIN_ICON_SCALE = 0.8f
    }

    override fun onSwipeProgressChanged(
        model: T,
        itemView: View,
        swipeProgress: Float,
        canvas: Canvas
    ) {
        Log.d("SwipeAwayCallbacks", "progress: $swipeProgress")
        rect.set(itemView.left.toFloat(), itemView.top.toFloat(), itemView.right.toFloat(), itemView.bottom.toFloat())
        rect.offset(itemView.translationX, itemView.translationY)

        if (rect.left == 0f || rect.right == canvas.width.toFloat()) {
            return
        }

        var radius = 0f

        val save = canvas.save()



        if (rect.left > 0) {
            // Swiping left-to-right
            rect.right = rect.left
            rect.left = 0f

            canvas.clipRect(rect)

            val startValue = iconBounds.right + padding / 2<commit_msg>Fix code style<commit_after>/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package app.tivi.ui.epoxy

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.graphics.drawable.Drawable
import android.util.Log
import android.view.View
import androidx.annotation.ColorInt
import app.tivi.ui.animations.lerp
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.EpoxyTouchHelper
import kotlin.math.roundToInt

abstract class SwipeAwayCallbacks<T : EpoxyModel<*>>(
    private val icon: Drawable,
    private val padding: Int,
    @ColorInt private val backgroundColor: Int,
    @ColorInt private val accentColor: Int
) : EpoxyTouchHelper.SwipeCallbacks<T>() {
    private val rect = RectF()
    private val iconBounds = Rect()

    private val iconHeight = icon.intrinsicHeight
    private val iconWidth = icon.intrinsicWidth

    private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = backgroundColor
    }

    private val foregroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = accentColor
    }

    companion object {
        const val MAX_ICON_SCALE = 1.3f
        const val MIN_ICON_SCALE = 0.8f
    }

    override fun onSwipeProgressChanged(
        model: T,
        itemView: View,
        swipeProgress: Float,
        canvas: Canvas
    ) {
        Log.d("SwipeAwayCallbacks", "progress: $swipeProgress")
        rect.set(itemView.left.toFloat(), itemView.top.toFloat(), itemView.right.toFloat(), itemView.bottom.toFloat())
        rect.offset(itemView.translationX, itemView.translationY)

        if (rect.left == 0f || rect.right == canvas.width.toFloat()) {
            return
        }

        var radius = 0f

        val save = canvas.save()

        if (rect.left > 0) {
            // Swiping left-to-right
            rect.right = rect.left
            rect.left = 0f

            canvas.clipRect(rect)

            val startValue = iconBounds.right + padding / 2
{'fraction_non_alphanumeric': 0.08673569056456339, 'fraction_numerical': 0.006641922250439539, 'mean_word_length': 2.941493456505004, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5524115', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1448, 'n_words': 435}