style: format code

This commit is contained in:
Producdevity 2025-07-25 18:31:41 +02:00
parent eb3d221ec6
commit 0dda4fd3ce
9 changed files with 137 additions and 57 deletions

View file

@ -4,7 +4,6 @@
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project // SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
package org.yuzu.yuzu_emu.activities package org.yuzu.yuzu_emu.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
@ -58,7 +57,6 @@ import org.yuzu.yuzu_emu.utils.NativeConfig
import org.yuzu.yuzu_emu.utils.NfcReader import org.yuzu.yuzu_emu.utils.NfcReader
import org.yuzu.yuzu_emu.utils.ParamPackage import org.yuzu.yuzu_emu.utils.ParamPackage
import org.yuzu.yuzu_emu.utils.ThemeHelper import org.yuzu.yuzu_emu.utils.ThemeHelper
import org.yuzu.yuzu_emu.utils.PowerStateUtils
import java.text.NumberFormat import java.text.NumberFormat
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -421,7 +419,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
NetPlayManager.addNetPlayMessage(type, msg) NetPlayManager.addNetPlayMessage(type, msg)
} }
private var pictureInPictureReceiver = object : BroadcastReceiver() { private var pictureInPictureReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent) { override fun onReceive(context: Context?, intent: Intent) {
if (intent.action == actionPlay) { if (intent.action == actionPlay) {

View file

@ -28,8 +28,7 @@ class ChatMessage(
val username: String, // Username is the community/forum username val username: String, // Username is the community/forum username
val message: String, val message: String,
val timestamp: String = SimpleDateFormat("HH:mm", Locale.getDefault()).format(Date()) val timestamp: String = SimpleDateFormat("HH:mm", Locale.getDefault()).format(Date())
) { )
}
class ChatDialog(context: Context) : BottomSheetDialog(context) { class ChatDialog(context: Context) : BottomSheetDialog(context) {
private lateinit var binding: DialogChatBinding private lateinit var binding: DialogChatBinding
@ -50,7 +49,8 @@ class ChatDialog(context: Context) : BottomSheetDialog(context) {
behavior.state = BottomSheetBehavior.STATE_EXPANDED behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.state = BottomSheetBehavior.STATE_EXPANDED behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.skipCollapsed = context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE behavior.skipCollapsed =
context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
handler.post { handler.post {
chatAdapter.notifyDataSetChanged() chatAdapter.notifyDataSetChanged()
@ -133,10 +133,12 @@ class ChatAdapter(private val messages: List<ChatMessage>) :
fun bind(message: ChatMessage) { fun bind(message: ChatMessage) {
binding.usernameText.text = message.nickname binding.usernameText.text = message.nickname
binding.messageText.text = message.message binding.messageText.text = message.message
binding.userIcon.setImageResource(when (message.nickname) { binding.userIcon.setImageResource(
"System" -> R.drawable.ic_system when (message.nickname) {
else -> R.drawable.ic_user "System" -> R.drawable.ic_system
}) else -> R.drawable.ic_user
}
)
} }
} }
} }

View file

@ -63,13 +63,12 @@ enum class BooleanSetting(override val key: String) : AbstractBooleanSetting {
SHOW_SHADERS_BUILDING("show_shaders_building"), SHOW_SHADERS_BUILDING("show_shaders_building"),
DEBUG_FLUSH_BY_LINE("flush_lines"), DEBUG_FLUSH_BY_LINE("flush_lines"),
USE_LRU_CACHE("use_lru_cache"),; USE_LRU_CACHE("use_lru_cache");
external fun isRaiiEnabled(): Boolean external fun isRaiiEnabled(): Boolean
// external fun isFrameSkippingEnabled(): Boolean // external fun isFrameSkippingEnabled(): Boolean
external fun isFrameInterpolationEnabled(): Boolean external fun isFrameInterpolationEnabled(): Boolean
override fun getBoolean(needsGlobal: Boolean): Boolean = override fun getBoolean(needsGlobal: Boolean): Boolean =
NativeConfig.getBoolean(key, needsGlobal) NativeConfig.getBoolean(key, needsGlobal)

View file

@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2025 Eden Emulator Project // SPDX-FileCopyrightText: 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
package org.yuzu.yuzu_emu.fragments package org.yuzu.yuzu_emu.fragments
import android.content.ClipData import android.content.ClipData

View file

@ -33,7 +33,10 @@ class AddGameFolderDialogFragment : DialogFragment() {
.setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int -> .setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->
val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked) val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked)
homeViewModel.setGamesDirSelected(true) homeViewModel.setGamesDirSelected(true)
val calledFromGameFragment = requireArguments().getBoolean("calledFromGameFragment", false) val calledFromGameFragment = requireArguments().getBoolean(
"calledFromGameFragment",
false
)
gamesViewModel.addFolder(newGameDir, calledFromGameFragment) gamesViewModel.addFolder(newGameDir, calledFromGameFragment)
} }
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)

View file

@ -62,14 +62,14 @@ class DriverFetcherFragment : Fragment() {
val path: String = "", val path: String = "",
val sort: Int = 0, val sort: Int = 0,
val useTagName: Boolean = false, val useTagName: Boolean = false,
val sortMode: SortMode = SortMode.Default, val sortMode: SortMode = SortMode.Default
) )
private val repoList: List<DriverRepo> = listOf( private val repoList: List<DriverRepo> = listOf(
DriverRepo("Mr. Purple Turnip", "MrPurple666/purple-turnip", 0), DriverRepo("Mr. Purple Turnip", "MrPurple666/purple-turnip", 0),
DriverRepo("GameHub Adreno 8xx", "crueter/GameHub-8Elite-Drivers", 1), DriverRepo("GameHub Adreno 8xx", "crueter/GameHub-8Elite-Drivers", 1),
DriverRepo("KIMCHI Turnip", "K11MCH1/AdrenoToolsDrivers", 2, true, SortMode.PublishTime), DriverRepo("KIMCHI Turnip", "K11MCH1/AdrenoToolsDrivers", 2, true, SortMode.PublishTime),
DriverRepo("Weab-Chan Freedreno", "Weab-chan/freedreno_turnip-CI", 3), DriverRepo("Weab-Chan Freedreno", "Weab-chan/freedreno_turnip-CI", 3)
) )
private val driverMap = listOf( private val driverMap = listOf(
@ -81,7 +81,7 @@ class DriverFetcherFragment : Fragment() {
IntRange(700, 710) to "KIMCHI 25.2.0_r5", IntRange(700, 710) to "KIMCHI 25.2.0_r5",
IntRange(711, 799) to "Mr. Purple T21", IntRange(711, 799) to "Mr. Purple T21",
IntRange(800, 899) to "GameHub Adreno 8xx", IntRange(800, 899) to "GameHub Adreno 8xx",
IntRange(900, Int.MAX_VALUE) to "Unsupported", IntRange(900, Int.MAX_VALUE) to "Unsupported"
) )
private lateinit var driverGroupAdapter: DriverGroupAdapter private lateinit var driverGroupAdapter: DriverGroupAdapter
@ -124,7 +124,9 @@ class DriverFetcherFragment : Fragment() {
} }
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View { ): View {
_binding = FragmentDriverFetcherBinding.inflate(inflater) _binding = FragmentDriverFetcherBinding.inflate(inflater)
binding.badgeRecommendedDriver.text = recommendedDriver binding.badgeRecommendedDriver.text = recommendedDriver
@ -178,8 +180,12 @@ class DriverFetcherFragment : Fragment() {
} }
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
MaterialAlertDialogBuilder(requireActivity()).setTitle(getString(R.string.error_during_fetch)) MaterialAlertDialogBuilder(requireActivity()).setTitle(
.setMessage("${getString(R.string.failed_to_fetch)} ${name}:\n${e.message}") getString(R.string.error_during_fetch)
)
.setMessage(
"${getString(R.string.failed_to_fetch)} $name:\n${e.message}"
)
.setPositiveButton(getString(R.string.ok)) { dialog, _ -> dialog.cancel() } .setPositiveButton(getString(R.string.ok)) { dialog, _ -> dialog.cancel() }
.show() .show()
@ -188,7 +194,9 @@ class DriverFetcherFragment : Fragment() {
} }
val group = DriverGroup( val group = DriverGroup(
name, releases, sort name,
releases,
sort
) )
synchronized(driverGroups) { synchronized(driverGroups) {
@ -223,7 +231,9 @@ class DriverFetcherFragment : Fragment() {
binding.listDrivers.updateMargins(left = leftInsets, right = rightInsets) binding.listDrivers.updateMargins(left = leftInsets, right = rightInsets)
binding.listDrivers.updatePadding( binding.listDrivers.updatePadding(
bottom = barInsets.bottom + resources.getDimensionPixelSize(R.dimen.spacing_bottom_list_fab) bottom = barInsets.bottom + resources.getDimensionPixelSize(
R.dimen.spacing_bottom_list_fab
)
) )
windowInsets windowInsets
@ -239,11 +249,13 @@ class DriverFetcherFragment : Fragment() {
var artifacts: List<Artifact> = ArrayList(), var artifacts: List<Artifact> = ArrayList(),
var prerelease: Boolean = false, var prerelease: Boolean = false,
var latest: Boolean = false, var latest: Boolean = false,
var publishTime: LocalDateTime = LocalDateTime.now(), var publishTime: LocalDateTime = LocalDateTime.now()
) { ) {
companion object { companion object {
fun fromJsonArray( fun fromJsonArray(
jsonString: String, useTagName: Boolean, sortMode: SortMode jsonString: String,
useTagName: Boolean,
sortMode: SortMode
): ArrayList<Release> { ): ArrayList<Release> {
val mapper = jacksonObjectMapper() val mapper = jacksonObjectMapper()
@ -310,7 +322,16 @@ class DriverFetcherFragment : Fragment() {
} }
} }
return Release(tagName, titleName, title, body, artifacts, prerelease, false, localTime) return Release(
tagName,
titleName,
title,
body,
artifacts,
prerelease,
false,
localTime
)
} catch (e: Exception) { } catch (e: Exception) {
// TODO: handle malformed input. // TODO: handle malformed input.
e.printStackTrace() e.printStackTrace()
@ -324,6 +345,6 @@ class DriverFetcherFragment : Fragment() {
data class DriverGroup( data class DriverGroup(
val name: String, val name: String,
val releases: ArrayList<Release>, val releases: ArrayList<Release>,
val sort: Int, val sort: Int
) )
} }

View file

@ -25,7 +25,6 @@ import kotlinx.coroutines.withContext
import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.adapters.DriverAdapter import org.yuzu.yuzu_emu.adapters.DriverAdapter
import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding
import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.model.Settings
import org.yuzu.yuzu_emu.features.settings.model.StringSetting import org.yuzu.yuzu_emu.features.settings.model.StringSetting
import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver
@ -108,7 +107,9 @@ class DriverManagerFragment : Fragment() {
} }
binding.buttonFetch.setOnClickListener { binding.buttonFetch.setOnClickListener {
binding.root.findNavController().navigate(R.id.action_driverManagerFragment_to_driverFetcherFragment) binding.root.findNavController().navigate(
R.id.action_driverManagerFragment_to_driverFetcherFragment
)
} }
binding.listDrivers.apply { binding.listDrivers.apply {

View file

@ -197,7 +197,9 @@ object FileUtil {
*/ */
fun getFilename(uri: Uri): String { fun getFilename(uri: Uri): String {
if (uri.scheme == "file") { if (uri.scheme == "file") {
return uri.lastPathSegment?.takeIf { it.isNotEmpty() } ?: throw IOException("Invalid file URI: $uri") return uri.lastPathSegment?.takeIf { it.isNotEmpty() } ?: throw IOException(
"Invalid file URI: $uri"
)
} }
val resolver = YuzuApplication.appContext.contentResolver val resolver = YuzuApplication.appContext.contentResolver

View file

@ -76,7 +76,11 @@ class CarouselRecyclerView @JvmOverloads constructor(
private fun getLayoutManagerCenter(layoutManager: RecyclerView.LayoutManager): Int { private fun getLayoutManagerCenter(layoutManager: RecyclerView.LayoutManager): Int {
return if (layoutManager is LinearLayoutManager) { return if (layoutManager is LinearLayoutManager) {
calculateCenter(layoutManager.width, layoutManager.paddingStart, layoutManager.paddingEnd) calculateCenter(
layoutManager.width,
layoutManager.paddingStart,
layoutManager.paddingEnd
)
} else { } else {
width / 2 width / 2
} }
@ -121,13 +125,13 @@ class CarouselRecyclerView @JvmOverloads constructor(
fun shapingFunction(x: Float, option: Int = 0): Float { fun shapingFunction(x: Float, option: Int = 0): Float {
return when (option) { return when (option) {
0 -> 1f //Off 0 -> 1f // Off
1 -> 1f - x //linear descending 1 -> 1f - x // linear descending
2 -> (1f - x) * (1f - x) //Ease out 2 -> (1f - x) * (1f - x) // Ease out
3 -> if (x < 0.05f) 1f else (1f-x) * 0.8f 3 -> if (x < 0.05f) 1f else (1f - x) * 0.8f
4 -> kotlin.math.cos(x * Math.PI).toFloat() //Cosine 4 -> kotlin.math.cos(x * Math.PI).toFloat() // Cosine
5 -> kotlin.math.cos( (1.5f * x).coerceIn(0f, 1f) * Math.PI).toFloat() //Cosine 1.5x trimmed 5 -> kotlin.math.cos((1.5f * x).coerceIn(0f, 1f) * Math.PI).toFloat() // Cosine 1.5x trimmed
else -> 1f //Default to Off else -> 1f // Default to Off
} }
} }
@ -143,20 +147,36 @@ class CarouselRecyclerView @JvmOverloads constructor(
val center = getRecyclerViewCenter() val center = getRecyclerViewCenter()
val distance = abs(getChildDistanceToCenter(child)) val distance = abs(getChildDistanceToCenter(child))
val internalBorderScale = resources.getFraction(R.fraction.carousel_bordercards_scale, 1, 1) val internalBorderScale = resources.getFraction(R.fraction.carousel_bordercards_scale, 1, 1)
val borderScale = preferences.getFloat(CAROUSEL_BORDERCARDS_SCALE, internalBorderScale).coerceIn(0f, 1f) val borderScale = preferences.getFloat(CAROUSEL_BORDERCARDS_SCALE, internalBorderScale).coerceIn(
0f,
1f
)
val shapeInput = (distance / center).coerceIn(0f, 1f) val shapeInput = (distance / center).coerceIn(0f, 1f)
val internalShapeSetting = resources.getInteger(R.integer.carousel_cards_scaling_shape) val internalShapeSetting = resources.getInteger(R.integer.carousel_cards_scaling_shape)
val scalingShapeSetting = preferences.getInt(CAROUSEL_CARDS_SCALING_SHAPE, internalShapeSetting) val scalingShapeSetting = preferences.getInt(
CAROUSEL_CARDS_SCALING_SHAPE,
internalShapeSetting
)
val shapedScaling = shapingFunction(shapeInput, scalingShapeSetting) val shapedScaling = shapingFunction(shapeInput, scalingShapeSetting)
val scale = (borderScale + (1f - borderScale) * shapedScaling).coerceIn(0f, 1f) val scale = (borderScale + (1f - borderScale) * shapedScaling).coerceIn(0f, 1f)
val maxDistance = width / 2f val maxDistance = width / 2f
val alphaInput = (distance / maxDistance).coerceIn(0f, 1f) val alphaInput = (distance / maxDistance).coerceIn(0f, 1f)
val internalBordersAlpha = resources.getFraction(R.fraction.carousel_bordercards_alpha, 1, 1) val internalBordersAlpha = resources.getFraction(
val borderAlpha = preferences.getFloat(CAROUSEL_BORDERCARDS_ALPHA, internalBordersAlpha).coerceIn(0f, 1f) R.fraction.carousel_bordercards_alpha,
1,
1
)
val borderAlpha = preferences.getFloat(CAROUSEL_BORDERCARDS_ALPHA, internalBordersAlpha).coerceIn(
0f,
1f
)
val internalAlphaShapeSetting = resources.getInteger(R.integer.carousel_cards_alpha_shape) val internalAlphaShapeSetting = resources.getInteger(R.integer.carousel_cards_alpha_shape)
val alphaShapeSetting = preferences.getInt(CAROUSEL_CARDS_ALPHA_SHAPE, internalAlphaShapeSetting) val alphaShapeSetting = preferences.getInt(
CAROUSEL_CARDS_ALPHA_SHAPE,
internalAlphaShapeSetting
)
val shapedAlpha = shapingFunction(alphaInput, alphaShapeSetting) val shapedAlpha = shapingFunction(alphaInput, alphaShapeSetting)
val alpha = (borderAlpha + (1f - borderAlpha) * shapedAlpha).coerceIn(0f, 1f) val alpha = (borderAlpha + (1f - borderAlpha) * shapedAlpha).coerceIn(0f, 1f)
@ -185,16 +205,33 @@ class CarouselRecyclerView @JvmOverloads constructor(
val insets = rootWindowInsets val insets = rootWindowInsets
val bottomInset = insets?.getInsets(android.view.WindowInsets.Type.systemBars())?.bottom ?: 0 val bottomInset = insets?.getInsets(android.view.WindowInsets.Type.systemBars())?.bottom ?: 0
val internalFactor = resources.getFraction(R.fraction.carousel_card_size_factor, 1, 1) val internalFactor = resources.getFraction(R.fraction.carousel_card_size_factor, 1, 1)
val userFactor = preferences.getFloat(CAROUSEL_CARD_SIZE_FACTOR, internalFactor).coerceIn(0f, 1f) val userFactor = preferences.getFloat(CAROUSEL_CARD_SIZE_FACTOR, internalFactor).coerceIn(
0f,
1f
)
val cardSize = (userFactor * (height - bottomInset)).toInt() val cardSize = (userFactor * (height - bottomInset)).toInt()
gameAdapter?.setCardSize(cardSize) gameAdapter?.setCardSize(cardSize)
val internalOverlapFactor = resources.getFraction(R.fraction.carousel_overlap_factor, 1, 1) val internalOverlapFactor = resources.getFraction(
overlapFactor = preferences.getFloat(CAROUSEL_OVERLAP_FACTOR, internalOverlapFactor).coerceIn(0f, 1f) R.fraction.carousel_overlap_factor,
1,
1
)
overlapFactor = preferences.getFloat(CAROUSEL_OVERLAP_FACTOR, internalOverlapFactor).coerceIn(
0f,
1f
)
overlapPx = (cardSize * overlapFactor).toInt() overlapPx = (cardSize * overlapFactor).toInt()
val internalFlingMultiplier = resources.getFraction(R.fraction.carousel_fling_multiplier, 1, 1) val internalFlingMultiplier = resources.getFraction(
flingMultiplier = preferences.getFloat(CAROUSEL_FLING_MULTIPLIER, internalFlingMultiplier).coerceIn(1f, 5f) R.fraction.carousel_fling_multiplier,
1,
1
)
flingMultiplier = preferences.getFloat(
CAROUSEL_FLING_MULTIPLIER,
internalFlingMultiplier
).coerceIn(1f, 5f)
gameAdapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { gameAdapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() { override fun onChanged() {
@ -290,20 +327,28 @@ class CarouselRecyclerView @JvmOverloads constructor(
View.FOCUS_LEFT -> { View.FOCUS_LEFT -> {
if (position > 0) { if (position > 0) {
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
val repeatDetected = (now - lastFocusSearchTime) < resources.getInteger(R.integer.carousel_focus_search_repeat_threshold_ms) val repeatDetected = (now - lastFocusSearchTime) < resources.getInteger(
R.integer.carousel_focus_search_repeat_threshold_ms
)
lastFocusSearchTime = now lastFocusSearchTime = now
if (!repeatDetected) { //ensures the first run if (!repeatDetected) { // ensures the first run
val offset = focused.width - overlapPx val offset = focused.width - overlapPx
smoothScrollBy(-offset, 0) smoothScrollBy(-offset, 0)
} }
findViewHolderForAdapterPosition(position - 1)?.itemView ?: super.focusSearch(focused, direction) findViewHolderForAdapterPosition(position - 1)?.itemView ?: super.focusSearch(
focused,
direction
)
} else { } else {
focused focused
} }
} }
View.FOCUS_RIGHT -> { View.FOCUS_RIGHT -> {
if (position < itemCount - 1) { if (position < itemCount - 1) {
findViewHolderForAdapterPosition(position + 1)?.itemView ?: super.focusSearch(focused, direction) findViewHolderForAdapterPosition(position + 1)?.itemView ?: super.focusSearch(
focused,
direction
)
} else { } else {
focused focused
} }
@ -341,7 +386,10 @@ class CarouselRecyclerView @JvmOverloads constructor(
inner class OverlappingDecoration(private val overlap: Int) : ItemDecoration() { inner class OverlappingDecoration(private val overlap: Int) : ItemDecoration() {
override fun getItemOffsets( override fun getItemOffsets(
outRect: Rect, view: View, parent: RecyclerView, state: State outRect: Rect,
view: View,
parent: RecyclerView,
state: State
) { ) {
val position = parent.getChildAdapterPosition(view) val position = parent.getChildAdapterPosition(view)
if (position > 0) { if (position > 0) {
@ -378,12 +426,17 @@ class CarouselRecyclerView @JvmOverloads constructor(
return layoutManager.findViewByPosition(getClosestChildPosition()) return layoutManager.findViewByPosition(getClosestChildPosition())
} }
//NEEDED: fixes ghost movement when snapping, but breaks inertial scrolling // NEEDED: fixes ghost movement when snapping, but breaks inertial scrolling
override fun calculateDistanceToFinalSnap( override fun calculateDistanceToFinalSnap(
layoutManager: RecyclerView.LayoutManager, layoutManager: RecyclerView.LayoutManager,
targetView: View targetView: View
): IntArray? { ): IntArray? {
if (layoutManager !is LinearLayoutManager) return super.calculateDistanceToFinalSnap(layoutManager, targetView) if (layoutManager !is LinearLayoutManager) {
return super.calculateDistanceToFinalSnap(
layoutManager,
targetView
)
}
val out = IntArray(2) val out = IntArray(2)
out[0] = getChildDistanceToCenter(targetView).toInt() out[0] = getChildDistanceToCenter(targetView).toInt()
out[1] = 0 out[1] = 0
@ -399,11 +452,14 @@ class CarouselRecyclerView @JvmOverloads constructor(
if (layoutManager !is LinearLayoutManager) return RecyclerView.NO_POSITION if (layoutManager !is LinearLayoutManager) return RecyclerView.NO_POSITION
val closestPosition = this@CarouselRecyclerView.getClosestChildPosition() val closestPosition = this@CarouselRecyclerView.getClosestChildPosition()
val internalMaxFling = resources.getInteger(R.integer.carousel_max_fling_count) val internalMaxFling = resources.getInteger(R.integer.carousel_max_fling_count)
val maxFling = preferences.getInt(CAROUSEL_MAX_FLING_COUNT, internalMaxFling).coerceIn(1, 10) val maxFling = preferences.getInt(CAROUSEL_MAX_FLING_COUNT, internalMaxFling).coerceIn(
1,
10
)
val rawFlingCount = if (velocityX == 0) 0 else velocityX / 2000 val rawFlingCount = if (velocityX == 0) 0 else velocityX / 2000
val flingCount = rawFlingCount.coerceIn(-maxFling, maxFling) val flingCount = rawFlingCount.coerceIn(-maxFling, maxFling)
var targetPos = (closestPosition + flingCount).coerceIn(0, layoutManager.itemCount - 1) var targetPos = (closestPosition + flingCount).coerceIn(0, layoutManager.itemCount - 1)
return targetPos return targetPos
} }
} }
} }