Skip to content

Commit

Permalink
Fix deprecated detekt rules (#710)
Browse files Browse the repository at this point in the history
**Background**

Fix deprecated detekt rules

**Changes**

Remove detekt rules and/or replace on actual

**Test plan**

Try run detektFormat
  • Loading branch information
Programistich authored Sep 29, 2023
1 parent b2b4179 commit 2437354
Show file tree
Hide file tree
Showing 46 changed files with 126 additions and 260 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [FIX] Fix wearos font issue
- [FIX] New mehanism emulate in Wear OS
- [FIX] New button texts on fap errors dialog
- [FIX] Deprecated detekt rules
- [FIX] Fix apostrophe in text "What’s New"

# 1.6.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ fun getTabStateFromFlipperBottomTab(
hubHasNotification: Boolean
): TabState {
return when (bottomTab) {
FlipperBottomTab.DEVICE -> {
connectionApi.getConnectionTabState()
}
FlipperBottomTab.DEVICE -> connectionApi.getConnectionTabState()
FlipperBottomTab.ARCHIVE -> TabState.Static(
selectedIcon = R.drawable.ic_archive_selected,
notSelectedIcon = R.drawable.ic_archive_unselected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ enum class FlipperFileType {
fun getByExtension(extension: String): FlipperFileType {
return when (extension) {
SHADOW_FILE_EXTENSION -> SHADOW_NFC
else -> {
if (FlipperKeyType.getByExtension(extension) != null) {
KEY
} else {
OTHER
}
else -> if (FlipperKeyType.getByExtension(extension) != null) {
KEY
} else {
OTHER
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,10 @@ class FlipperListingDelegate @Inject constructor() {
info { "Listing request for $pathOnFlipper with $response was not found" }
listOf()
}

response.commandStatus != Flipper.CommandStatus.OK -> {
response.commandStatus != Flipper.CommandStatus.OK ->
error("Listing request failed for $pathOnFlipper with $response")
}

response.hasStorageListResponse() -> {
response.storageListResponse.fileList
}

else -> {
error("Can't find storage list response, $response")
}
response.hasStorageListResponse() -> response.storageListResponse.fileList
else -> error("Can't find storage list response, $response")
}
}.flatten()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@ fun FlipperStorageInformation.isExtStorageEnding(): Boolean = isStorageEnding(fl
private fun isStorageEnding(flash: StorageStats?): Boolean {
return when (flash) {
StorageStats.Error -> false
is StorageStats.Loaded -> {
flash.free <= ENDING
}
is StorageStats.Loaded -> flash.free <= ENDING
null -> false
}
}

fun StorageStats.toString(context: Context): String {
return when (this) {
StorageStats.Error -> {
context.getString(R.string.info_device_info_flash_not_found)
}
StorageStats.Error -> context.getString(R.string.info_device_info_flash_not_found)
is StorageStats.Loaded -> {
val usedHumanReadable = max(0L, total - free).toFormattedSize()
val totalHumanReadable = total.toFormattedSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class AndroidKeyStorage @Inject constructor(
FlipperFileType.KEY -> simpleKeyApi.getKey(
FlipperKeyPath(filePath, deleted = false)
)?.mainFile?.content ?: error("Can't found $filePath")
FlipperFileType.SHADOW_NFC -> {
flipperFileApi.getFile(filePath).content
}
FlipperFileType.SHADOW_NFC -> flipperFileApi.getFile(filePath).content
FlipperFileType.OTHER ->
error("I cannot process a file that is neither a key nor a shadow file: $filePath")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ suspend fun <T> Flow<ResultWithProgress<T>>.trackProgressAndReturn(
var resultObject: T? = null
collect { result ->
when (result) {
is ResultWithProgress.InProgress -> {
onProgressUpdate(result)
}
is ResultWithProgress.Completed -> {
resultObject = result.result
}
is ResultWithProgress.InProgress -> onProgressUpdate(result)
is ResultWithProgress.Completed -> resultObject = result.result
}
}
return resultObject ?: error("Result for flow with progress can't be null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ fun ComposableUnsupportedDialog(
}

when (supportedState) {
FlipperSupportedState.DEPRECATED_FLIPPER -> {
FlipperDialog(
imageId = DesignSystem.drawable.ic_firmware_flipper_deprecated,
titleId = R.string.dialog_unsupported_title,
textId = R.string.dialog_unsupported_description,
buttonTextId = R.string.dialog_unsupported_btn,
onDismissRequest = { showDialog = false },
onClickButton = { showDialog = false }
)
}
FlipperSupportedState.DEPRECATED_FLIPPER -> FlipperDialog(
imageId = DesignSystem.drawable.ic_firmware_flipper_deprecated,
titleId = R.string.dialog_unsupported_title,
textId = R.string.dialog_unsupported_description,
buttonTextId = R.string.dialog_unsupported_btn,
onDismissRequest = { showDialog = false },
onClickButton = { showDialog = false }
)
FlipperSupportedState.DEPRECATED_APPLICATION -> {
val url = stringResource(R.string.dialog_unsupported_application_link)
val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import android.os.Build
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getDefaultAdapter()
fun BluetoothManager?.getBluetoothAdapter(): BluetoothAdapter {
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
@Suppress("DEPRECATION")
this?.adapter ?: BluetoothAdapter.getDefaultAdapter()
}
else -> {
else ->
@Suppress("DEPRECATION")
BluetoothAdapter.getDefaultAdapter()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ import java.io.Serializable

inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? {
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> {
getParcelable(key, T::class.java)
}
else -> {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelable(key, T::class.java)
else ->
@Suppress("DEPRECATION")
getParcelable(key)
}
}
}

inline fun <reified T : Serializable> Bundle.serializable(key: String): T {
val value = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ->
getSerializable(key, T::class.java)
}
else -> {
else ->
@Suppress("DEPRECATION")
getSerializable(key) as T?
}
}
return requireNotNull(value) { "Value for serialization key $key is null" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ fun Intent.toFullString(): String {

inline fun <reified T : Parcelable> Intent.parcelableExtra(key: String): T? {
return when {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> {
getParcelableExtra(key, T::class.java)
}
else -> {
SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableExtra(key, T::class.java)
else ->
@Suppress("DEPRECATION")
getParcelableExtra(key)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,21 @@ sealed class DeeplinkContent : Parcelable {

fun openStream(contentResolver: ContentResolver): InputStream? {
return when (this) {
is ExternalUri -> {
contentResolver.openInputStream(uri)
}
is InternalStorageFile -> {
file.inputStream()
}
is ExternalUri -> contentResolver.openInputStream(uri)
is InternalStorageFile -> file.inputStream()
is FFFContent -> flipperFileFormat.openStream()
is FFFCryptoContent -> null
}
}

fun cleanUp(contentResolver: ContentResolver) {
when (this) {
is ExternalUri -> {
is ExternalUri ->
contentResolver.releasePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
)
}
is InternalStorageFile -> {
file.delete()
}
is InternalStorageFile -> file.delete()
is FFFContent -> {} // Noting
is FFFCryptoContent -> {} // Noting
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ internal fun ComposableFapButton(
onCancel = { statusViewModel.cancel(config) }
)

FapState.Installed -> {
FapState.Installed ->
ComposableInstalledButton(
config = config,
fapButtonSize = fapButtonSize,
modifier = modifier
)
}

FapState.ReadyToInstall -> ComposableFapInstallButton(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal fun ComposableInstalledButton(
}

when (val localState = state) {
is OpenFapState.InProgress -> {
is OpenFapState.InProgress ->
if (localState.config == config) {
ComposableFapOpeningButton(
modifier = modifier,
Expand All @@ -49,25 +49,21 @@ internal fun ComposableInstalledButton(
onClick = { viewModel.open(config, navController) }
)
}
}
OpenFapState.NotSupported -> {
OpenFapState.NotSupported ->
ComposableFapInstalledButton(
modifier = modifier,
fapButtonSize = fapButtonSize
)
}
OpenFapState.Loading -> {
OpenFapState.Loading ->
ComposableFapInstalledButton(
modifier = modifier.placeholderConnecting(),
fapButtonSize = fapButtonSize
)
}
OpenFapState.Ready -> {
OpenFapState.Ready ->
ComposableFapOpenButton(
modifier = modifier,
fapButtonSize = fapButtonSize,
onClick = { viewModel.open(config, navController) }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,13 @@ class OpenFapHelperImpl @Inject constructor(
rpcVersionFlow,
) { currentApp, rpcVersion ->
return@combine when {
fapButtonConfig == null -> {
fapButtonConfig == null -> OpenFapState.NotSupported
rpcVersion == null || rpcVersion < Constants.API_SUPPORTED_LOAD_FAP ->
OpenFapState.NotSupported
}
rpcVersion == null || rpcVersion < Constants.API_SUPPORTED_LOAD_FAP -> {
fapButtonConfig.version.buildState != FapBuildState.READY ->
OpenFapState.NotSupported
}
fapButtonConfig.version.buildState != FapBuildState.READY -> {
OpenFapState.NotSupported
}
currentApp != null -> {
currentApp != null ->
OpenFapState.InProgress(fapButtonConfig)
}
else -> OpenFapState.Ready
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ class OpenFapViewModel @VMInject constructor(
navController.navigate(screenStreamingFeatureEntry.ROUTE.name)
}
}
OpenFapResult.Error -> {
info { "Error on open app" }
}
OpenFapResult.Error -> info { "Error on open app" }
OpenFapResult.FlipperIsBusy -> {
info { "Flipper is busy" }
busyDialogState.emit(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FapManifestEnrichedHelper(
return@withLock
}

is FapManifestState.Loaded -> {
is FapManifestState.Loaded ->
fapManifestState.emit(
FapManifestState.Loaded(
manifestState.items
Expand All @@ -93,7 +93,6 @@ class FapManifestEnrichedHelper(
).toImmutableList()
)
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fun ComposableInstalledTabScreen(

is FapInstalledScreenState.Loaded,
FapInstalledScreenState.Loading,
is FapInstalledScreenState.LoadedOffline -> {
is FapInstalledScreenState.LoadedOffline ->
SwipeRefresh(
modifier = screenModifier,
onRefresh = { viewModel.refresh(true) }
Expand All @@ -90,7 +90,6 @@ fun ComposableInstalledTabScreen(
)
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,23 @@ fun ComposableUpdateAllButton(
modifier: Modifier = Modifier
) {
when (state) {
FapBatchUpdateButtonState.Offline -> {
ComposableOfflineButtonText(modifier)
}
FapBatchUpdateButtonState.Offline -> ComposableOfflineButtonText(modifier)

FapBatchUpdateButtonState.NoUpdates -> {}

FapBatchUpdateButtonState.Loading -> {
ComposableCancelAllButton(
modifier.placeholderConnecting()
)
}
FapBatchUpdateButtonState.Loading -> ComposableCancelAllButton(
modifier.placeholderConnecting()
)

is FapBatchUpdateButtonState.ReadyToUpdate -> {
is FapBatchUpdateButtonState.ReadyToUpdate ->
ComposableUpdateAllButtonPending(
pendingCount = state.count,
modifier = modifier.clickableRipple(onClick = onUpdateAll)
)
}

FapBatchUpdateButtonState.UpdatingInProgress -> {
FapBatchUpdateButtonState.UpdatingInProgress ->
ComposableCancelAllButton(
modifier = modifier.clickableRipple(onClick = onCancelAll)
)
}
}
}
Loading

0 comments on commit 2437354

Please sign in to comment.