0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-20 12:02:17 +02:00

Clean up code

According to Android Studio recommendations.
This commit is contained in:
Markus Fisch 2021-07-15 20:29:17 +02:00
parent bd4576b7ac
commit 22b58265a5
6 changed files with 22 additions and 21 deletions

View File

@ -11,7 +11,7 @@ suspend inline fun <T : Any> alertDialog(
context: Context,
crossinline build: AlertDialog.Builder.(resume: (T?) -> Unit) -> Unit
): T? = withContext(Dispatchers.Main) {
suspendCoroutine<T?> { continuation ->
suspendCoroutine { continuation ->
AlertDialog.Builder(context).apply {
setOnCancelListener {
continuation.resume(null)

View File

@ -5,21 +5,22 @@ import android.os.Build
import java.util.*
fun Context.applyLocale(localeName: String) {
if (localeName.isNotEmpty()) {
val localeParts = localeName.split("-")
val locale = if (localeParts.size == 2) {
Locale(localeParts[0], localeParts[1])
} else {
Locale(localeName)
}
Locale.setDefault(locale)
val conf = resources.configuration
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
conf.locale = locale
} else {
conf.setLocale(locale)
}
resources.updateConfiguration(conf, resources.displayMetrics)
if (localeName.isEmpty()) {
return
}
val localeParts = localeName.split("-")
val locale = if (localeParts.size == 2) {
Locale(localeParts[0], localeParts[1])
} else {
Locale(localeName)
}
Locale.setDefault(locale)
val conf = resources.configuration
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
conf.locale = locale
} else {
conf.setLocale(locale)
}
resources.updateConfiguration(conf, resources.displayMetrics)
}

View File

@ -16,7 +16,7 @@ fun exportCsv(
exportCsv(outputStream, cursor, delimiter)
}
fun exportCsv(cursor: Cursor, delimiter: String): String? {
fun exportCsv(cursor: Cursor, delimiter: String): String {
val outputStream = ByteArrayOutputStream()
exportCsv(outputStream, cursor, delimiter)
return outputStream.toString()

View File

@ -273,4 +273,4 @@ private fun Bitmap.saveAsPng(outputStream: OutputStream, quality: Int = 90) {
private val fileNameCharacters = "[^A-Za-z0-9]".toRegex()
private fun encodeFileName(name: String): String =
fileNameCharacters.replace(name, "_").take(16).trim('_').toLowerCase(Locale.getDefault())
fileNameCharacters.replace(name, "_").take(16).trim('_').lowercase(Locale.getDefault())

View File

@ -349,7 +349,7 @@ private fun hexDump(bytes: ByteArray, charsPerLine: Int = 33): String {
while (true) {
val ord = bytes[i]
hex.append(String.format("%02X ", ord))
ascii.append(if (ord > 31) ord.toChar() else " ")
ascii.append(if (ord > 31) ord.toInt().toChar() else " ")
++i
val posInLine = i % itemsPerLine
val atEnd = i >= len

View File

@ -51,7 +51,7 @@ class PreferencesFragment : PreferenceFragmentCompat() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
pref.isVisible = false
} else {
pref.setOnPreferenceClickListener { _ ->
pref.setOnPreferenceClickListener {
askToClearNetworkSuggestions(context)
true
}