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:
parent
bd4576b7ac
commit
22b58265a5
@ -11,7 +11,7 @@ suspend inline fun <T : Any> alertDialog(
|
|||||||
context: Context,
|
context: Context,
|
||||||
crossinline build: AlertDialog.Builder.(resume: (T?) -> Unit) -> Unit
|
crossinline build: AlertDialog.Builder.(resume: (T?) -> Unit) -> Unit
|
||||||
): T? = withContext(Dispatchers.Main) {
|
): T? = withContext(Dispatchers.Main) {
|
||||||
suspendCoroutine<T?> { continuation ->
|
suspendCoroutine { continuation ->
|
||||||
AlertDialog.Builder(context).apply {
|
AlertDialog.Builder(context).apply {
|
||||||
setOnCancelListener {
|
setOnCancelListener {
|
||||||
continuation.resume(null)
|
continuation.resume(null)
|
||||||
|
@ -5,21 +5,22 @@ import android.os.Build
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun Context.applyLocale(localeName: String) {
|
fun Context.applyLocale(localeName: String) {
|
||||||
if (localeName.isNotEmpty()) {
|
if (localeName.isEmpty()) {
|
||||||
val localeParts = localeName.split("-")
|
return
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ fun exportCsv(
|
|||||||
exportCsv(outputStream, cursor, delimiter)
|
exportCsv(outputStream, cursor, delimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportCsv(cursor: Cursor, delimiter: String): String? {
|
fun exportCsv(cursor: Cursor, delimiter: String): String {
|
||||||
val outputStream = ByteArrayOutputStream()
|
val outputStream = ByteArrayOutputStream()
|
||||||
exportCsv(outputStream, cursor, delimiter)
|
exportCsv(outputStream, cursor, delimiter)
|
||||||
return outputStream.toString()
|
return outputStream.toString()
|
||||||
|
@ -273,4 +273,4 @@ private fun Bitmap.saveAsPng(outputStream: OutputStream, quality: Int = 90) {
|
|||||||
|
|
||||||
private val fileNameCharacters = "[^A-Za-z0-9]".toRegex()
|
private val fileNameCharacters = "[^A-Za-z0-9]".toRegex()
|
||||||
private fun encodeFileName(name: String): String =
|
private fun encodeFileName(name: String): String =
|
||||||
fileNameCharacters.replace(name, "_").take(16).trim('_').toLowerCase(Locale.getDefault())
|
fileNameCharacters.replace(name, "_").take(16).trim('_').lowercase(Locale.getDefault())
|
||||||
|
@ -349,7 +349,7 @@ private fun hexDump(bytes: ByteArray, charsPerLine: Int = 33): String {
|
|||||||
while (true) {
|
while (true) {
|
||||||
val ord = bytes[i]
|
val ord = bytes[i]
|
||||||
hex.append(String.format("%02X ", ord))
|
hex.append(String.format("%02X ", ord))
|
||||||
ascii.append(if (ord > 31) ord.toChar() else " ")
|
ascii.append(if (ord > 31) ord.toInt().toChar() else " ")
|
||||||
++i
|
++i
|
||||||
val posInLine = i % itemsPerLine
|
val posInLine = i % itemsPerLine
|
||||||
val atEnd = i >= len
|
val atEnd = i >= len
|
||||||
|
@ -51,7 +51,7 @@ class PreferencesFragment : PreferenceFragmentCompat() {
|
|||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
pref.isVisible = false
|
pref.isVisible = false
|
||||||
} else {
|
} else {
|
||||||
pref.setOnPreferenceClickListener { _ ->
|
pref.setOnPreferenceClickListener {
|
||||||
askToClearNetworkSuggestions(context)
|
askToClearNetworkSuggestions(context)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user