Cleanups
This commit is contained in:
1 parent
56244ad892
commit
6f5b85e43b
24 files changed
+217
-154
No files matched your search
@@ -15,6 +15,9 @@ trim_trailing_whitespace = false
|
||||
ij_kotlin_imports_layout = *
|
||||
ij_kotlin_allow_trailing_comma = true
|
||||
ij_kotlin_allow_trailing_comma_on_call_site = true
|
||||
ij_kotlin_name_count_to_use_star_import = 999
|
||||
ij_kotlin_name_count_to_use_star_import_for_members = 999
|
||||
ij_kotlin_packages_to_use_import_on_demand = unset
|
||||
ktlint_code_style = intellij_idea
|
||||
ktlint_standard_discouraged-comment-location = disabled
|
||||
ktlint_function_naming_ignore_when_annotated_with = Composable
|
||||
|
||||
@@ -37,7 +37,6 @@ import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import app.lawnchair.backup.LawnchairBackup
|
||||
import app.lawnchair.preferences.PreferenceManager
|
||||
import app.lawnchair.ui.preferences.LocalNavController
|
||||
@@ -56,6 +55,7 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
@Composable
|
||||
fun CreateBackupScreen(
|
||||
|
||||
@@ -35,7 +35,7 @@ sealed class GestureHandlerOption(
|
||||
GestureHandlerConfig.OpenApp::class.java,
|
||||
) {
|
||||
override suspend fun buildConfig(activity: Activity): GestureHandlerConfig? {
|
||||
val intent = PreferenceActivity.createIntent(activity, "${Routes.PICK_APP_FOR_GESTURE}")
|
||||
val intent = PreferenceActivity.createIntent(activity, Routes.PICK_APP_FOR_GESTURE)
|
||||
val result = BlankActivity.startBlankActivityForResult(activity, intent)
|
||||
val configString = result.data?.getStringExtra("config") ?: return null
|
||||
return kotlinxJson.decodeFromString(configString)
|
||||
|
||||
@@ -122,7 +122,7 @@ class LawnchairSearchAdapterProvider(
|
||||
LayoutType.THUMBNAIL to SEARCH_RESULT_FILE_TILE,
|
||||
LayoutType.ICON_SLICE to SEARCH_RESULT_SETTINGS_TILE,
|
||||
LayoutType.WIDGET_LIVE to SEARCH_RESULT_RECENT_TILE,
|
||||
LayoutType.CALCULATOR to SEARCH_RESULT_CALCULATOR
|
||||
LayoutType.CALCULATOR to SEARCH_RESULT_CALCULATOR,
|
||||
)
|
||||
|
||||
fun setFirstItemQuickLaunch(items: List<SearchAdapterItem>) {
|
||||
|
||||
@@ -78,7 +78,7 @@ class GenerateSearchTarget(private val context: Context) {
|
||||
return createCalculatorTarget(
|
||||
id,
|
||||
action,
|
||||
extras
|
||||
extras,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ sealed class LawnchairSearchAlgorithm(
|
||||
fileIndices: List<Int>,
|
||||
settingIndices: List<Int>,
|
||||
recentIndices: List<Int>,
|
||||
calculator: List<Int>
|
||||
calculator: List<Int>,
|
||||
): SearchItemBackground = when {
|
||||
layoutType == TEXT_HEADER || layoutType == ICON_SINGLE_VERTICAL_TEXT || layoutType == EMPTY_DIVIDER -> iconBackground
|
||||
layoutType == SMALL_ICON_HORIZONTAL_TEXT -> getGroupedBackground(index, smallIconIndices)
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package app.lawnchair.search.algorithms.data.calculator
|
||||
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.*
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.Evaluator
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.Expr
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.Function
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.Parser
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.Scanner
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.Token
|
||||
import java.math.BigDecimal
|
||||
import java.math.MathContext
|
||||
import java.math.RoundingMode
|
||||
|
||||
class ExpressionException(message: String)
|
||||
: RuntimeException(message)
|
||||
class ExpressionException(message: String) :
|
||||
RuntimeException(message)
|
||||
|
||||
@Suppress("unused")
|
||||
class Expressions {
|
||||
@@ -17,87 +21,92 @@ class Expressions {
|
||||
define("pi", Math.PI)
|
||||
define("e", Math.E)
|
||||
|
||||
evaluator.addFunction("abs", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.size != 1) throw ExpressionException(
|
||||
"abs requires one argument")
|
||||
|
||||
return arguments.first().abs()
|
||||
evaluator.addFunction("abs") { arguments ->
|
||||
if (arguments.size != 1) {
|
||||
throw ExpressionException(
|
||||
"abs requires one argument",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
evaluator.addFunction("sum", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.isEmpty()) throw ExpressionException(
|
||||
"sum requires at least one argument")
|
||||
arguments.first().abs()
|
||||
}
|
||||
|
||||
return arguments.reduce { sum, bigDecimal ->
|
||||
sum.add(bigDecimal)
|
||||
}
|
||||
evaluator.addFunction("sum") { arguments ->
|
||||
if (arguments.isEmpty()) {
|
||||
throw ExpressionException(
|
||||
"sum requires at least one argument",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
evaluator.addFunction("floor", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.size != 1) throw ExpressionException(
|
||||
"floor requires one argument")
|
||||
|
||||
return arguments.first().setScale(0, RoundingMode.FLOOR)
|
||||
arguments.reduce { sum, bigDecimal ->
|
||||
sum.add(bigDecimal)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
evaluator.addFunction("ceil", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.size != 1) throw ExpressionException(
|
||||
"ceil requires one argument")
|
||||
|
||||
return arguments.first().setScale(0, RoundingMode.CEILING)
|
||||
evaluator.addFunction("floor") { arguments ->
|
||||
if (arguments.size != 1) {
|
||||
throw ExpressionException(
|
||||
"floor requires one argument",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
evaluator.addFunction("round", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.size !in listOf(1, 2)) throw ExpressionException(
|
||||
"round requires either one or two arguments")
|
||||
arguments.first().setScale(0, RoundingMode.FLOOR)
|
||||
}
|
||||
|
||||
val value = arguments.first()
|
||||
val scale = if (arguments.size == 2) arguments.last().toInt() else 0
|
||||
|
||||
return value.setScale(scale, roundingMode)
|
||||
evaluator.addFunction("ceil") { arguments ->
|
||||
if (arguments.size != 1) {
|
||||
throw ExpressionException(
|
||||
"ceil requires one argument",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
evaluator.addFunction("min", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.isEmpty()) throw ExpressionException(
|
||||
"min requires at least one argument")
|
||||
arguments.first().setScale(0, RoundingMode.CEILING)
|
||||
}
|
||||
|
||||
return arguments.minOrNull()!!
|
||||
evaluator.addFunction("round") { arguments ->
|
||||
if (arguments.size !in listOf(1, 2)) {
|
||||
throw ExpressionException(
|
||||
"round requires either one or two arguments",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
evaluator.addFunction("max", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
if (arguments.isEmpty()) throw ExpressionException(
|
||||
"max requires at least one argument")
|
||||
val value = arguments.first()
|
||||
val scale = if (arguments.size == 2) arguments.last().toInt() else 0
|
||||
|
||||
return arguments.maxOrNull()!!
|
||||
value.setScale(scale, roundingMode)
|
||||
}
|
||||
|
||||
evaluator.addFunction("min") { arguments ->
|
||||
if (arguments.isEmpty()) {
|
||||
throw ExpressionException(
|
||||
"min requires at least one argument",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
evaluator.addFunction("if", object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
val condition = arguments[0]
|
||||
val thenValue = arguments[1]
|
||||
val elseValue = arguments[2]
|
||||
arguments.minOrNull()!!
|
||||
}
|
||||
|
||||
return if (condition != BigDecimal.ZERO) {
|
||||
thenValue
|
||||
} else {
|
||||
elseValue
|
||||
}
|
||||
evaluator.addFunction("max") { arguments ->
|
||||
if (arguments.isEmpty()) {
|
||||
throw ExpressionException(
|
||||
"max requires at least one argument",
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
arguments.maxOrNull()!!
|
||||
}
|
||||
|
||||
evaluator.addFunction("if") { arguments ->
|
||||
val condition = arguments[0]
|
||||
val thenValue = arguments[1]
|
||||
val elseValue = arguments[2]
|
||||
|
||||
if (condition != BigDecimal.ZERO) {
|
||||
thenValue
|
||||
} else {
|
||||
elseValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val precision: Int
|
||||
@@ -109,7 +118,6 @@ class Expressions {
|
||||
fun setPrecision(precision: Int): Expressions {
|
||||
evaluator.mathContext = MathContext(precision, roundingMode)
|
||||
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -151,12 +159,7 @@ class Expressions {
|
||||
}
|
||||
|
||||
fun addFunction(name: String, func: (List<BigDecimal>) -> BigDecimal): Expressions {
|
||||
evaluator.addFunction(name, object : Function() {
|
||||
override fun call(arguments: List<BigDecimal>): BigDecimal {
|
||||
return func(arguments)
|
||||
}
|
||||
|
||||
})
|
||||
evaluator.addFunction(name) { arguments -> func(arguments) }
|
||||
|
||||
return this
|
||||
}
|
||||
@@ -175,7 +178,7 @@ class Expressions {
|
||||
return try {
|
||||
evaluator.eval(parse(expression)).round(evaluator.mathContext).stripTrailingZeros()
|
||||
.toEngineeringString()
|
||||
}catch (e:Throwable){
|
||||
} catch (e: Throwable) {
|
||||
e.cause?.message ?: e.message ?: "unknown error"
|
||||
}
|
||||
}
|
||||
|
||||
+32
-15
@@ -1,12 +1,28 @@
|
||||
package app.lawnchair.search.algorithms.data.calculator.internal
|
||||
|
||||
import app.lawnchair.search.algorithms.data.calculator.ExpressionException
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.*
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.AMP_AMP
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.BAR_BAR
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EQUAL_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EXPONENT
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.GREATER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.GREATER_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LESS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LESS_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.MINUS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.MODULO
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.NOT_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.PLUS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.SLASH
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.SQUARE_ROOT
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.STAR
|
||||
import java.math.BigDecimal
|
||||
import java.math.MathContext
|
||||
import java.math.RoundingMode
|
||||
import java.util.Locale
|
||||
import kotlin.math.pow
|
||||
|
||||
internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
internal class Evaluator : ExprVisitor<BigDecimal> {
|
||||
internal var mathContext: MathContext = MathContext.DECIMAL64
|
||||
|
||||
private val variables: LinkedHashMap<String, BigDecimal> = linkedMapOf()
|
||||
@@ -17,13 +33,13 @@ internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
}
|
||||
|
||||
fun define(name: String, expr: Expr): Evaluator {
|
||||
define(name.toLowerCase(), eval(expr))
|
||||
define(name.lowercase(Locale.ROOT), eval(expr))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
fun addFunction(name: String, function: Function): Evaluator {
|
||||
functions += name.toLowerCase() to function
|
||||
functions += name.lowercase(Locale.ROOT) to function
|
||||
|
||||
return this
|
||||
}
|
||||
@@ -48,7 +64,8 @@ internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
BAR_BAR -> left or right
|
||||
AMP_AMP -> left and right
|
||||
else -> throw ExpressionException(
|
||||
"Invalid logical operator '${expr.operator.lexeme}'")
|
||||
"Invalid logical operator '${expr.operator.lexeme}'",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +87,8 @@ internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
LESS -> (left < right).toBigDecimal()
|
||||
LESS_EQUAL -> (left <= right).toBigDecimal()
|
||||
else -> throw ExpressionException(
|
||||
"Invalid binary operator '${expr.operator.lexeme}'")
|
||||
"Invalid binary operator '${expr.operator.lexeme}'",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +108,8 @@ internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
|
||||
override fun visitCallExpr(expr: CallExpr): BigDecimal {
|
||||
val name = expr.name
|
||||
val function = functions[name.toLowerCase()] ?:
|
||||
throw ExpressionException("Undefined function '$name'")
|
||||
val function = functions[name.lowercase(Locale.ROOT)]
|
||||
?: throw ExpressionException("Undefined function '$name'")
|
||||
|
||||
return function.call(expr.arguments.map { eval(it) })
|
||||
}
|
||||
@@ -103,8 +121,8 @@ internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
override fun visitVariableExpr(expr: VariableExpr): BigDecimal {
|
||||
val name = expr.name.lexeme
|
||||
|
||||
return variables[name.toLowerCase()] ?:
|
||||
throw ExpressionException("Undefined variable '$name'")
|
||||
return variables[name.lowercase(Locale.ROOT)]
|
||||
?: throw ExpressionException("Undefined variable '$name'")
|
||||
}
|
||||
|
||||
override fun visitGroupingExpr(expr: GroupingExpr): BigDecimal {
|
||||
@@ -144,14 +162,13 @@ internal class Evaluator() : ExprVisitor<BigDecimal> {
|
||||
val remainderOfRight = right.remainder(BigDecimal.ONE)
|
||||
val n2IntPart = right.subtract(remainderOfRight)
|
||||
val intPow = pow(n2IntPart.intValueExact(), mathContext)
|
||||
val doublePow = BigDecimal(Math
|
||||
.pow(toDouble(), remainderOfRight.toDouble()))
|
||||
val doublePow = BigDecimal(toDouble().pow(remainderOfRight.toDouble()))
|
||||
|
||||
var result = intPow.multiply(doublePow, mathContext)
|
||||
if (signOfRight == -1) result = BigDecimal
|
||||
.ONE.divide(result, mathContext.precision, RoundingMode.HALF_UP)
|
||||
if (signOfRight == -1) {
|
||||
result = BigDecimal.ONE.divide(result, mathContext.precision, RoundingMode.HALF_UP)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,54 +5,58 @@ import java.math.BigDecimal
|
||||
internal sealed class Expr {
|
||||
|
||||
abstract fun <R> accept(visitor: ExprVisitor<R>): R
|
||||
|
||||
}
|
||||
|
||||
internal class AssignExpr(val name: Token,
|
||||
val value: Expr) : Expr() {
|
||||
internal class AssignExpr(
|
||||
val name: Token,
|
||||
val value: Expr,
|
||||
) : Expr() {
|
||||
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitAssignExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class LogicalExpr(val left: Expr,
|
||||
val operator: Token,
|
||||
val right: Expr) : Expr() {
|
||||
internal class LogicalExpr(
|
||||
val left: Expr,
|
||||
val operator: Token,
|
||||
val right: Expr,
|
||||
) : Expr() {
|
||||
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitLogicalExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class BinaryExpr(val left: Expr,
|
||||
val operator: Token,
|
||||
val right: Expr) : Expr() {
|
||||
internal class BinaryExpr(
|
||||
val left: Expr,
|
||||
val operator: Token,
|
||||
val right: Expr,
|
||||
) : Expr() {
|
||||
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitBinaryExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class UnaryExpr(val operator: Token,
|
||||
val right: Expr) : Expr() {
|
||||
internal class UnaryExpr(
|
||||
val operator: Token,
|
||||
val right: Expr,
|
||||
) : Expr() {
|
||||
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitUnaryExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class CallExpr(val name: String,
|
||||
val arguments: List<Expr>) : Expr() {
|
||||
internal class CallExpr(
|
||||
val name: String,
|
||||
val arguments: List<Expr>,
|
||||
) : Expr() {
|
||||
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitCallExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class LiteralExpr(val value: BigDecimal) : Expr() {
|
||||
@@ -60,7 +64,6 @@ internal class LiteralExpr(val value: BigDecimal) : Expr() {
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitLiteralExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class VariableExpr(val name: Token) : Expr() {
|
||||
@@ -68,7 +71,6 @@ internal class VariableExpr(val name: Token) : Expr() {
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitVariableExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class GroupingExpr(val expression: Expr) : Expr() {
|
||||
@@ -76,7 +78,6 @@ internal class GroupingExpr(val expression: Expr) : Expr() {
|
||||
override fun <R> accept(visitor: ExprVisitor<R>): R {
|
||||
return visitor.visitGroupingExpr(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal interface ExprVisitor<out R> {
|
||||
@@ -96,5 +97,4 @@ internal interface ExprVisitor<out R> {
|
||||
fun visitVariableExpr(expr: VariableExpr): R
|
||||
|
||||
fun visitGroupingExpr(expr: GroupingExpr): R
|
||||
|
||||
}
|
||||
@@ -2,8 +2,7 @@ package app.lawnchair.search.algorithms.data.calculator.internal
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
abstract class Function {
|
||||
|
||||
abstract fun call(arguments: List<BigDecimal>): BigDecimal
|
||||
fun interface Function {
|
||||
|
||||
fun call(arguments: List<BigDecimal>): BigDecimal
|
||||
}
|
||||
@@ -1,7 +1,28 @@
|
||||
package app.lawnchair.search.algorithms.data.calculator.internal
|
||||
|
||||
import app.lawnchair.search.algorithms.data.calculator.ExpressionException
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.*
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.AMP_AMP
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.ASSIGN
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.BAR_BAR
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.COMMA
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EOF
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EQUAL_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EXPONENT
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.GREATER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.GREATER_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.IDENTIFIER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LEFT_PAREN
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LESS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LESS_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.MINUS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.MODULO
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.NOT_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.NUMBER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.PLUS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.RIGHT_PAREN
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.SLASH
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.SQUARE_ROOT
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.STAR
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal class Parser(private val tokens: List<Token>) {
|
||||
@@ -243,5 +264,4 @@ internal class Parser(private val tokens: List<Token>) {
|
||||
private fun previous() = tokens[current - 1]
|
||||
|
||||
private fun previousTwo() = Pair(tokens[current - 2], tokens[current - 1])
|
||||
|
||||
}
|
||||
@@ -1,15 +1,38 @@
|
||||
package app.lawnchair.search.algorithms.data.calculator.internal
|
||||
|
||||
import java.math.MathContext
|
||||
import app.lawnchair.search.algorithms.data.calculator.ExpressionException
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.*
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.AMP_AMP
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.ASSIGN
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.BAR_BAR
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.COMMA
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EOF
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EQUAL_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.EXPONENT
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.GREATER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.GREATER_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.IDENTIFIER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LEFT_PAREN
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LESS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.LESS_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.MINUS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.MODULO
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.NOT_EQUAL
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.NUMBER
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.PLUS
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.RIGHT_PAREN
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.SLASH
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.SQUARE_ROOT
|
||||
import app.lawnchair.search.algorithms.data.calculator.internal.TokenType.STAR
|
||||
import java.math.MathContext
|
||||
|
||||
private fun invalidToken(c: Char) {
|
||||
throw ExpressionException("Invalid token '$c'")
|
||||
}
|
||||
|
||||
internal class Scanner(private val source: String,
|
||||
private val mathContext: MathContext) {
|
||||
internal class Scanner(
|
||||
private val source: String,
|
||||
private val mathContext: MathContext,
|
||||
) {
|
||||
|
||||
private val tokens: MutableList<Token> = mutableListOf()
|
||||
private var start = 0
|
||||
@@ -30,12 +53,11 @@ internal class Scanner(private val source: String,
|
||||
|
||||
private fun scanToken() {
|
||||
start = current
|
||||
val c = advance()
|
||||
|
||||
when (c) {
|
||||
when (val c = advance()) {
|
||||
' ',
|
||||
'\r',
|
||||
'\t' -> {
|
||||
'\t',
|
||||
-> {
|
||||
// Ignore whitespace.
|
||||
}
|
||||
'+' -> addToken(PLUS)
|
||||
@@ -64,14 +86,16 @@ internal class Scanner(private val source: String,
|
||||
}
|
||||
}
|
||||
|
||||
private fun isDigit(char: Char,
|
||||
previousChar: Char = '\u0000',
|
||||
nextChar: Char = '\u0000'): Boolean {
|
||||
private fun isDigit(
|
||||
char: Char,
|
||||
previousChar: Char = '\u0000',
|
||||
nextChar: Char = '\u0000',
|
||||
): Boolean {
|
||||
return char.isDigit() || when (char) {
|
||||
'.' -> true
|
||||
'.' -> true
|
||||
'e', 'E' -> previousChar.isDigit() && (nextChar.isDigit() || nextChar == '+' || nextChar == '-')
|
||||
'+', '-' -> (previousChar == 'e' || previousChar == 'E') && nextChar.isDigit()
|
||||
else -> false
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +157,9 @@ internal class Scanner(private val source: String,
|
||||
|
||||
private fun Char.isAlphaNumeric() = isAlpha() || isDigit()
|
||||
|
||||
private fun Char.isAlpha() = this in 'a'..'z'
|
||||
|| this in 'A'..'Z'
|
||||
|| this == '_'
|
||||
private fun Char.isAlpha() = this in 'a'..'z' ||
|
||||
this in 'A'..'Z' ||
|
||||
this == '_'
|
||||
|
||||
private fun Char.isDigit() = this == '.' || this in '0'..'9'
|
||||
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package app.lawnchair.search.algorithms.data.calculator.internal
|
||||
|
||||
internal class Token(val type: TokenType,
|
||||
val lexeme: String,
|
||||
val literal: Any?) {
|
||||
internal class Token(
|
||||
val type: TokenType,
|
||||
val lexeme: String,
|
||||
val literal: Any?,
|
||||
) {
|
||||
|
||||
override fun toString(): String {
|
||||
return type.toString() + " " + lexeme + " " + literal
|
||||
return "$type $lexeme $literal"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,5 @@ internal enum class TokenType {
|
||||
NUMBER,
|
||||
IDENTIFIER,
|
||||
|
||||
EOF
|
||||
|
||||
EOF,
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class SmartspacePreferencesShortcut : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
startActivity(PreferenceActivity.createIntent(this, "${Routes.SMARTSPACE_WIDGET}"))
|
||||
startActivity(PreferenceActivity.createIntent(this, Routes.SMARTSPACE_WIDGET))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class SmartspaceViewContainer @JvmOverloads constructor(
|
||||
R.drawable.ic_setting,
|
||||
StatsLogManager.LauncherEvent.IGNORE,
|
||||
) {
|
||||
context.startActivity(PreferenceActivity.createIntent(context, "${Routes.SMARTSPACE}"))
|
||||
context.startActivity(PreferenceActivity.createIntent(context, Routes.SMARTSPACE))
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class SmartspacerView(context: Context, attrs: AttributeSet?) : BcSmartspaceView
|
||||
R.drawable.ic_setting,
|
||||
StatsLogManager.LauncherEvent.IGNORE,
|
||||
) {
|
||||
context.startActivity(PreferenceActivity.createIntent(context, "${Routes.SMARTSPACE}"))
|
||||
context.startActivity(PreferenceActivity.createIntent(context, Routes.SMARTSPACE))
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class NowPlayingProvider(context: Context) : SmartspaceDataSource(
|
||||
notificationDotsEnabled(context = context).first().not()
|
||||
|
||||
override suspend fun startSetup(activity: Activity) {
|
||||
val intent = PreferenceActivity.createIntent(activity, "${Routes.GENERAL}")
|
||||
val intent = PreferenceActivity.createIntent(activity, Routes.GENERAL)
|
||||
val message = activity.getString(
|
||||
R.string.event_provider_missing_notification_dots,
|
||||
activity.getString(providerName),
|
||||
|
||||
@@ -47,7 +47,7 @@ class SmartspaceProvider private constructor(context: Context) {
|
||||
headerAction = SmartspaceAction(
|
||||
id = "smartspaceSetupAction",
|
||||
title = context.getString(R.string.smartspace_requires_setup),
|
||||
intent = PreferenceActivity.createIntent(context, "${Routes.SMARTSPACE}"),
|
||||
intent = PreferenceActivity.createIntent(context, Routes.SMARTSPACE),
|
||||
),
|
||||
score = 999f,
|
||||
featureType = SmartspaceTarget.FeatureType.FEATURE_TIPS,
|
||||
|
||||
@@ -16,7 +16,6 @@ import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ private fun HexColorPicker(
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
capitalization = KeyboardCapitalization.Characters,
|
||||
autoCorrect = false,
|
||||
autoCorrectEnabled = false,
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
|
||||
@@ -93,7 +93,7 @@ private class NestedScrollStretchConnection(context: Context, invalidate: Runnab
|
||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||
val availableY = available.y
|
||||
when {
|
||||
source != NestedScrollSource.Drag || height == 0 -> return Offset.Zero
|
||||
source != NestedScrollSource.UserInput || height == 0 -> return Offset.Zero
|
||||
availableY != 0f -> {
|
||||
if (availableY < 0f) {
|
||||
val consumed = topEdgeEffect.onPullDistance(availableY / height, 0f)
|
||||
@@ -117,7 +117,7 @@ private class NestedScrollStretchConnection(context: Context, invalidate: Runnab
|
||||
): Offset {
|
||||
val availableY = available.y
|
||||
when {
|
||||
source != NestedScrollSource.Drag || height == 0 -> return Offset.Zero
|
||||
source != NestedScrollSource.UserInput || height == 0 -> return Offset.Zero
|
||||
availableY != 0f -> {
|
||||
if (availableY > 0f) {
|
||||
topEdgeEffect.onPull(availableY / height)
|
||||
|
||||
@@ -21,7 +21,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import app.lawnchair.preferences.getAdapter
|
||||
import app.lawnchair.preferences.not
|
||||
import app.lawnchair.preferences.preferenceManager
|
||||
import app.lawnchair.preferences2.preferenceManager2
|
||||
import app.lawnchair.ui.preferences.components.NavigationActionPreference
|
||||
|
||||
@@ -10,10 +10,10 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
|
||||
private val LocalLifecycleState = compositionLocalOf<Lifecycle.State> {
|
||||
error("CompositionLocal LocalLifecycleState not present")
|
||||
|
||||
Reference in new issue
Block a user