From 0dda4fd3cedd4116e6183ac05c1d02e1e18e3137 Mon Sep 17 00:00:00 2001 From: Producdevity Date: Fri, 25 Jul 2025 18:31:41 +0200 Subject: [PATCH] style: format code --- .../yuzu_emu/activities/EmulationActivity.kt | 3 - .../org/yuzu/yuzu_emu/dialogs/ChatDialog.kt | 16 +-- .../features/settings/model/BooleanSetting.kt | 3 +- .../yuzu/yuzu_emu/fragments/AboutFragment.kt | 1 - .../fragments/AddGameFolderDialogFragment.kt | 5 +- .../fragments/DriverFetcherFragment.kt | 47 +++++--- .../fragments/DriverManagerFragment.kt | 5 +- .../java/org/yuzu/yuzu_emu/utils/FileUtil.kt | 4 +- .../yuzu_emu/views/CarouselRecyclerView.kt | 110 +++++++++++++----- 9 files changed, 137 insertions(+), 57 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index 40200931b7..1aa300f82d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt @@ -4,7 +4,6 @@ // SPDX-FileCopyrightText: 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later - package org.yuzu.yuzu_emu.activities 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.ParamPackage import org.yuzu.yuzu_emu.utils.ThemeHelper -import org.yuzu.yuzu_emu.utils.PowerStateUtils import java.text.NumberFormat import kotlin.math.roundToInt @@ -421,7 +419,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { NetPlayManager.addNetPlayMessage(type, msg) } - private var pictureInPictureReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent) { if (intent.action == actionPlay) { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/dialogs/ChatDialog.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/dialogs/ChatDialog.kt index 2ae0377a95..5d6679bd28 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/dialogs/ChatDialog.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/dialogs/ChatDialog.kt @@ -28,8 +28,7 @@ class ChatMessage( val username: String, // Username is the community/forum username val message: String, val timestamp: String = SimpleDateFormat("HH:mm", Locale.getDefault()).format(Date()) -) { -} +) class ChatDialog(context: Context) : BottomSheetDialog(context) { 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.skipCollapsed = context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + behavior.skipCollapsed = + context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE handler.post { chatAdapter.notifyDataSetChanged() @@ -133,10 +133,12 @@ class ChatAdapter(private val messages: List) : fun bind(message: ChatMessage) { binding.usernameText.text = message.nickname binding.messageText.text = message.message - binding.userIcon.setImageResource(when (message.nickname) { - "System" -> R.drawable.ic_system - else -> R.drawable.ic_user - }) + binding.userIcon.setImageResource( + when (message.nickname) { + "System" -> R.drawable.ic_system + else -> R.drawable.ic_user + } + ) } } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt index a558afab47..c31c534bfc 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/BooleanSetting.kt @@ -63,13 +63,12 @@ enum class BooleanSetting(override val key: String) : AbstractBooleanSetting { SHOW_SHADERS_BUILDING("show_shaders_building"), DEBUG_FLUSH_BY_LINE("flush_lines"), - USE_LRU_CACHE("use_lru_cache"),; + USE_LRU_CACHE("use_lru_cache"); external fun isRaiiEnabled(): Boolean // external fun isFrameSkippingEnabled(): Boolean external fun isFrameInterpolationEnabled(): Boolean - override fun getBoolean(needsGlobal: Boolean): Boolean = NativeConfig.getBoolean(key, needsGlobal) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt index 2879310007..0ec9984607 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2025 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later - package org.yuzu.yuzu_emu.fragments import android.content.ClipData diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt index cc95544d25..e2cb5f600d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt @@ -33,7 +33,10 @@ class AddGameFolderDialogFragment : DialogFragment() { .setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int -> val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked) homeViewModel.setGamesDirSelected(true) - val calledFromGameFragment = requireArguments().getBoolean("calledFromGameFragment", false) + val calledFromGameFragment = requireArguments().getBoolean( + "calledFromGameFragment", + false + ) gamesViewModel.addFolder(newGameDir, calledFromGameFragment) } .setNegativeButton(android.R.string.cancel, null) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverFetcherFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverFetcherFragment.kt index 91670b207d..b8d0f2197e 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverFetcherFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverFetcherFragment.kt @@ -62,14 +62,14 @@ class DriverFetcherFragment : Fragment() { val path: String = "", val sort: Int = 0, val useTagName: Boolean = false, - val sortMode: SortMode = SortMode.Default, + val sortMode: SortMode = SortMode.Default ) private val repoList: List = listOf( DriverRepo("Mr. Purple Turnip", "MrPurple666/purple-turnip", 0), DriverRepo("GameHub Adreno 8xx", "crueter/GameHub-8Elite-Drivers", 1), 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( @@ -81,7 +81,7 @@ class DriverFetcherFragment : Fragment() { IntRange(700, 710) to "KIMCHI 25.2.0_r5", IntRange(711, 799) to "Mr. Purple T21", 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 @@ -124,7 +124,9 @@ class DriverFetcherFragment : Fragment() { } override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View { _binding = FragmentDriverFetcherBinding.inflate(inflater) binding.badgeRecommendedDriver.text = recommendedDriver @@ -178,8 +180,12 @@ class DriverFetcherFragment : Fragment() { } } catch (e: Exception) { withContext(Dispatchers.Main) { - MaterialAlertDialogBuilder(requireActivity()).setTitle(getString(R.string.error_during_fetch)) - .setMessage("${getString(R.string.failed_to_fetch)} ${name}:\n${e.message}") + MaterialAlertDialogBuilder(requireActivity()).setTitle( + 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() } .show() @@ -188,7 +194,9 @@ class DriverFetcherFragment : Fragment() { } val group = DriverGroup( - name, releases, sort + name, + releases, + sort ) synchronized(driverGroups) { @@ -223,7 +231,9 @@ class DriverFetcherFragment : Fragment() { binding.listDrivers.updateMargins(left = leftInsets, right = rightInsets) 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 @@ -239,11 +249,13 @@ class DriverFetcherFragment : Fragment() { var artifacts: List = ArrayList(), var prerelease: Boolean = false, var latest: Boolean = false, - var publishTime: LocalDateTime = LocalDateTime.now(), + var publishTime: LocalDateTime = LocalDateTime.now() ) { companion object { fun fromJsonArray( - jsonString: String, useTagName: Boolean, sortMode: SortMode + jsonString: String, + useTagName: Boolean, + sortMode: SortMode ): ArrayList { 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) { // TODO: handle malformed input. e.printStackTrace() @@ -324,6 +345,6 @@ class DriverFetcherFragment : Fragment() { data class DriverGroup( val name: String, val releases: ArrayList, - val sort: Int, + val sort: Int ) -} \ No newline at end of file +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt index 47b84a403a..f521343272 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/DriverManagerFragment.kt @@ -25,7 +25,6 @@ import kotlinx.coroutines.withContext import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.adapters.DriverAdapter 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.StringSetting import org.yuzu.yuzu_emu.model.Driver.Companion.toDriver @@ -108,7 +107,9 @@ class DriverManagerFragment : Fragment() { } 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 { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt index feed8b3cf8..a30eaf5890 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt @@ -197,7 +197,9 @@ object FileUtil { */ fun getFilename(uri: Uri): String { 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 diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/CarouselRecyclerView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/CarouselRecyclerView.kt index ae40fcb498..c406baac58 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/CarouselRecyclerView.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/CarouselRecyclerView.kt @@ -76,7 +76,11 @@ class CarouselRecyclerView @JvmOverloads constructor( private fun getLayoutManagerCenter(layoutManager: RecyclerView.LayoutManager): Int { return if (layoutManager is LinearLayoutManager) { - calculateCenter(layoutManager.width, layoutManager.paddingStart, layoutManager.paddingEnd) + calculateCenter( + layoutManager.width, + layoutManager.paddingStart, + layoutManager.paddingEnd + ) } else { width / 2 } @@ -121,13 +125,13 @@ class CarouselRecyclerView @JvmOverloads constructor( fun shapingFunction(x: Float, option: Int = 0): Float { return when (option) { - 0 -> 1f //Off - 1 -> 1f - x //linear descending - 2 -> (1f - x) * (1f - x) //Ease out - 3 -> if (x < 0.05f) 1f else (1f-x) * 0.8f - 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 - else -> 1f //Default to Off + 0 -> 1f // Off + 1 -> 1f - x // linear descending + 2 -> (1f - x) * (1f - x) // Ease out + 3 -> if (x < 0.05f) 1f else (1f - x) * 0.8f + 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 + else -> 1f // Default to Off } } @@ -143,20 +147,36 @@ class CarouselRecyclerView @JvmOverloads constructor( val center = getRecyclerViewCenter() val distance = abs(getChildDistanceToCenter(child)) 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 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 scale = (borderScale + (1f - borderScale) * shapedScaling).coerceIn(0f, 1f) val maxDistance = width / 2f val alphaInput = (distance / maxDistance).coerceIn(0f, 1f) - val internalBordersAlpha = resources.getFraction(R.fraction.carousel_bordercards_alpha, 1, 1) - val borderAlpha = preferences.getFloat(CAROUSEL_BORDERCARDS_ALPHA, internalBordersAlpha).coerceIn(0f, 1f) + val internalBordersAlpha = resources.getFraction( + 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 alphaShapeSetting = preferences.getInt(CAROUSEL_CARDS_ALPHA_SHAPE, internalAlphaShapeSetting) + val alphaShapeSetting = preferences.getInt( + CAROUSEL_CARDS_ALPHA_SHAPE, + internalAlphaShapeSetting + ) val shapedAlpha = shapingFunction(alphaInput, alphaShapeSetting) val alpha = (borderAlpha + (1f - borderAlpha) * shapedAlpha).coerceIn(0f, 1f) @@ -185,16 +205,33 @@ class CarouselRecyclerView @JvmOverloads constructor( val insets = rootWindowInsets val bottomInset = insets?.getInsets(android.view.WindowInsets.Type.systemBars())?.bottom ?: 0 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() gameAdapter?.setCardSize(cardSize) - val internalOverlapFactor = resources.getFraction(R.fraction.carousel_overlap_factor, 1, 1) - overlapFactor = preferences.getFloat(CAROUSEL_OVERLAP_FACTOR, internalOverlapFactor).coerceIn(0f, 1f) + val internalOverlapFactor = resources.getFraction( + R.fraction.carousel_overlap_factor, + 1, + 1 + ) + overlapFactor = preferences.getFloat(CAROUSEL_OVERLAP_FACTOR, internalOverlapFactor).coerceIn( + 0f, + 1f + ) overlapPx = (cardSize * overlapFactor).toInt() - val internalFlingMultiplier = resources.getFraction(R.fraction.carousel_fling_multiplier, 1, 1) - flingMultiplier = preferences.getFloat(CAROUSEL_FLING_MULTIPLIER, internalFlingMultiplier).coerceIn(1f, 5f) + val internalFlingMultiplier = resources.getFraction( + R.fraction.carousel_fling_multiplier, + 1, + 1 + ) + flingMultiplier = preferences.getFloat( + CAROUSEL_FLING_MULTIPLIER, + internalFlingMultiplier + ).coerceIn(1f, 5f) gameAdapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onChanged() { @@ -290,20 +327,28 @@ class CarouselRecyclerView @JvmOverloads constructor( View.FOCUS_LEFT -> { if (position > 0) { 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 - if (!repeatDetected) { //ensures the first run + if (!repeatDetected) { // ensures the first run val offset = focused.width - overlapPx smoothScrollBy(-offset, 0) } - findViewHolderForAdapterPosition(position - 1)?.itemView ?: super.focusSearch(focused, direction) + findViewHolderForAdapterPosition(position - 1)?.itemView ?: super.focusSearch( + focused, + direction + ) } else { focused } } View.FOCUS_RIGHT -> { if (position < itemCount - 1) { - findViewHolderForAdapterPosition(position + 1)?.itemView ?: super.focusSearch(focused, direction) + findViewHolderForAdapterPosition(position + 1)?.itemView ?: super.focusSearch( + focused, + direction + ) } else { focused } @@ -341,7 +386,10 @@ class CarouselRecyclerView @JvmOverloads constructor( inner class OverlappingDecoration(private val overlap: Int) : ItemDecoration() { override fun getItemOffsets( - outRect: Rect, view: View, parent: RecyclerView, state: State + outRect: Rect, + view: View, + parent: RecyclerView, + state: State ) { val position = parent.getChildAdapterPosition(view) if (position > 0) { @@ -378,12 +426,17 @@ class CarouselRecyclerView @JvmOverloads constructor( 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( layoutManager: RecyclerView.LayoutManager, targetView: View ): IntArray? { - if (layoutManager !is LinearLayoutManager) return super.calculateDistanceToFinalSnap(layoutManager, targetView) + if (layoutManager !is LinearLayoutManager) { + return super.calculateDistanceToFinalSnap( + layoutManager, + targetView + ) + } val out = IntArray(2) out[0] = getChildDistanceToCenter(targetView).toInt() out[1] = 0 @@ -399,11 +452,14 @@ class CarouselRecyclerView @JvmOverloads constructor( if (layoutManager !is LinearLayoutManager) return RecyclerView.NO_POSITION val closestPosition = this@CarouselRecyclerView.getClosestChildPosition() 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 flingCount = rawFlingCount.coerceIn(-maxFling, maxFling) var targetPos = (closestPosition + flingCount).coerceIn(0, layoutManager.itemCount - 1) return targetPos } } -} \ No newline at end of file +}