Skip to content

Commit

Permalink
Merge branch 'main' into pr-templates-update
Browse files Browse the repository at this point in the history
  • Loading branch information
starry-shivam authored May 12, 2024
2 parents ea652b8 + e4dda6e commit 6d9a0d6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.starry.greenstash.ui.screens.settings.composables

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -332,6 +333,7 @@ private fun ThemePickerDialog(
}
}

@SuppressLint("InlinedApi")
@Composable
private fun LocaleSettings(viewModel: SettingsViewModel) {
val context = LocalContext.current
Expand Down Expand Up @@ -360,8 +362,14 @@ private fun LocaleSettings(viewModel: SettingsViewModel) {

SettingsContainer {
SettingsCategory(title = stringResource(id = R.string.locales_setting_title))
// App locale setting is only available on Android 13+.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// App locale setting is only available on Android 13+
// Also, it's not functional on MIUI devices even on Android 13,
// Thanks to Xiaomi's broken implementation of standard Android APIs.
// See: https://github.com/Pool-Of-Tears/GreenStash/issues/130 for more information.
val shouldShowAppLocaleSetting = remember {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !Utils.isMiui()
}
if (shouldShowAppLocaleSetting) {
SettingsItem(title = stringResource(id = R.string.app_locale_setting),
description = stringResource(id = R.string.app_locale_setting_desc),
icon = Icons.Filled.Language,
Expand Down
47 changes: 42 additions & 5 deletions app/src/main/java/com/starry/greenstash/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import android.os.Build
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_WEAK
import androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
Expand All @@ -43,12 +46,14 @@ import java.util.Currency
import java.util.Locale
import java.util.TimeZone


/**
* A collection of utility functions.
*/
object Utils {

/** Get validated number from the text.
/**
* Get validated number from the text.
*
* @param text The text to validate
* @return The validated number
Expand All @@ -69,7 +74,8 @@ object Utils {
}
}

/** Round the decimal number to two decimal places.
/**
* Round the decimal number to two decimal places.
*
* @param number The number to round
* @return The rounded number
Expand All @@ -81,7 +87,8 @@ object Utils {
return df.format(number).toDouble()
}

/** Format currency based on the currency code.
/**
* Format currency based on the currency code.
*
* @param amount The amount to format
* @param currencyCode The currency code
Expand Down Expand Up @@ -121,7 +128,8 @@ object Utils {
}


/** Get the epoch time from the LocalDateTime.
/**
* Get the epoch time from the LocalDateTime.
*
* @param dateTime The LocalDateTime object
* @return The epoch time
Expand All @@ -135,7 +143,8 @@ object Utils {
return dateTime.atZone(timeZone).toInstant().toEpochMilli()
}

/** Open the web link in the browser.
/**
* Open the web link in the browser.
*
* @param context The context
* @param url The URL to open
Expand All @@ -150,4 +159,32 @@ object Utils {
}
}

/**
* Check if the device is running on MIUI.
*
* By default, HyperOS is excluded from the check.
* If you want to include HyperOS in the check, set excludeHyperOS to false.
*
* @param excludeHyperOS Whether to exclude HyperOS
* @return True if the device is running on MIUI, false otherwise
*/
fun isMiui(excludeHyperOS: Boolean = true): Boolean {
val isMiui = !getProperty("ro.miui.ui.version.name").isNullOrBlank()
val isHyperOS = !getProperty("ro.mi.os.version.name").isNullOrBlank()
return isMiui && (!excludeHyperOS || !isHyperOS)
}

// Private function to get the property value from build.prop.
private fun getProperty(property: String): String? {
return try {
Runtime.getRuntime().exec("getprop $property").inputStream.use { input ->
BufferedReader(InputStreamReader(input), 1024).readLine()
}
} catch (e: IOException) {
e.printStackTrace()
null
}
}


}

0 comments on commit 6d9a0d6

Please sign in to comment.