Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,30 @@ internal class OverlayMenuResizeController(
val width = if (firstChild == null || firstChild.id == resizedContainer.id) {
resizedContainer.width
} else {
firstChild.children.fold(0) { acc, child ->
acc + (
if (child.isGone) 0
else child.width + child.marginStart + child.marginEnd
)
}
firstChild.visibleHorizontalContentSpan()
}

return Size(width, height)
}
}

private fun ViewGroup.visibleHorizontalContentSpan(): Int {
var leftBound = Int.MAX_VALUE
var rightBound = Int.MIN_VALUE

children
.filterNot { it.isGone }
.forEach { child ->
leftBound = minOf(leftBound, child.left - child.marginStart)
rightBound = maxOf(rightBound, child.right + child.marginEnd)
}

return if (leftBound == Int.MAX_VALUE) 0 else rightBound - leftBound
}

private data class OverlayTransition(
val viewId: Int,
val transitionType: Int,
)

private const val TAG = "OverlayMenuResizeController"
private const val TAG = "OverlayMenuResizeController"
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ class AccessibilityTroubleshootingDialog : DialogFragment() {
}

private fun showDontKillMyApp() {
context?.safeStartWebBrowserActivity("https://dontkillmyapp.com")
context?.safeStartWebBrowserActivity("https://dontkillmyapp.com?app=Klick%27r")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ interface DumbScenarioDao {
*
* @return the scenario stats.
*/
@Query("SELECT * FROM dumb_scenario_stats_table WHERE id=:scenarioId")
@Query("SELECT * FROM dumb_scenario_stats_table WHERE dumb_scenario_id=:scenarioId")
suspend fun getScenarioStats(scenarioId: Long): DumbScenarioStatsEntity?

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ interface ScenarioDao {
*
* @return the scenario stats.
*/
@Query("SELECT * FROM $SCENARIO_USAGE_TABLE WHERE id=:scenarioId")
@Query("SELECT * FROM $SCENARIO_USAGE_TABLE WHERE scenario_id=:scenarioId")
suspend fun getScenarioStats(scenarioId: Long): ScenarioStatsEntity?

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class BackupEngine(appDataDir: File, private val contentResolver: Conte
// Create the zip file containing the scenarios and their events conditions.
withContext(Dispatchers.IO) {
try {
ZipOutputStream(contentResolver.openOutputStream(zipFileUri)).use { zipStream ->
ZipOutputStream(contentResolver.openOutputStream(zipFileUri, "wt")).use { zipStream ->
dumbScenarios.forEach { dumbScenario ->
Log.d(TAG, "Backup dumb scenario ${dumbScenario.scenario.id}")

Expand All @@ -83,9 +83,9 @@ internal class BackupEngine(appDataDir: File, private val contentResolver: Conte
currentProgress++
progress.onProgressChanged(currentProgress, smartScenarios.size)
}

progress.onCompleted(dumbScenarios, smartScenarios, 0, false)
}

progress.onCompleted(dumbScenarios, smartScenarios, 0, false)
} catch (ioEx: IOException) {
Log.e(TAG, "Error while creating backup archive.")
progress.onError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ internal class SmartBackupDataSource(
}

if (!screenCompatWarning) {
screenCompatWarning = screenSize != Point(backup.screenWidth, backup.screenHeight)
screenCompatWarning = hasDifferentScreenSize(
currentWidth = screenSize.x,
currentHeight = screenSize.y,
backupWidth = backup.screenWidth,
backupHeight = backup.screenHeight,
)
}

Log.i(TAG, "Smart scenario is valid, has warnings: $screenCompatWarning")
Expand Down Expand Up @@ -157,4 +162,16 @@ internal class SmartBackupDataSource(
}

/** Tag for logs. */
private const val TAG = "SmartBackupEngine"
private const val TAG = "SmartBackupEngine"

internal fun hasDifferentScreenSize(
currentWidth: Int,
currentHeight: Int,
backupWidth: Int,
backupHeight: Int,
): Boolean {
val sameOrientation = currentWidth == backupWidth && currentHeight == backupHeight
val rotatedOrientation = currentWidth == backupHeight && currentHeight == backupWidth

return !sameOrientation && !rotatedOrientation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2026 Kevin Buzeau
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.buzbuz.smartautoclicker.feature.backup.data.smart

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class SmartBackupDataSourceTests {

@Test
fun sameScreenSize_sameOrientation_noWarning() {
assertFalse(hasDifferentScreenSize(1080, 2400, 1080, 2400))
}

@Test
fun sameScreenSize_differentOrientation_noWarning() {
assertFalse(hasDifferentScreenSize(1080, 2400, 2400, 1080))
}

@Test
fun differentScreenSize_warning() {
assertTrue(hasDifferentScreenSize(1080, 2400, 1440, 3200))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.buzbuz.smartautoclicker.feature.smart.config.databinding.IncludeScree
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.condition.UiScreenCondition
import com.buzbuz.smartautoclicker.core.ui.utils.setColorIndicatorDrawable
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toEffectDescription
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString

import kotlinx.coroutines.Job

Expand Down Expand Up @@ -79,7 +80,7 @@ fun IncludeScreenConditionCardBinding.bind(
conditionText.visibility = View.VISIBLE

conditionText.text = condition.comparisonOperation
.toEffectDescription(root.context, operand = condition.counterValue.value.toString())
.toEffectDescription(root.context, operand = condition.counterValue.toNaturalDisplayString())
null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.bindings.coun
import com.buzbuz.smartautoclicker.core.base.extensions.setLeftCompoundDrawable
import com.buzbuz.smartautoclicker.feature.smart.config.R
import com.buzbuz.smartautoclicker.feature.smart.config.databinding.IncludeCounterSelectionBinding
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.counter.UiStaticOrCounterSelection

import androidx.appcompat.R as AppCompatR
Expand All @@ -40,8 +41,8 @@ fun IncludeCounterSelectionBinding.setCounter(uiState: UiStaticOrCounterSelectio
title.setLeftCompoundDrawable(null)
description.text = root.context.getString(
R.string.field_counter_selection_desc,
uiState.counter.defaultValue,
uiState.counter.defaultValue.toNaturalDisplayString(maxFractionDigits = 2),
)
description.setTextColor(MaterialColors.getColor(root, MaterialR.attr.colorOnSurfaceVariant))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.buzbuz.smartautoclicker.core.ui.bindings.fields.setText
import com.buzbuz.smartautoclicker.core.ui.utils.NumberInputFilter
import com.buzbuz.smartautoclicker.feature.smart.config.R
import com.buzbuz.smartautoclicker.feature.smart.config.databinding.IncludeStaticOrCounterSelectionBinding
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.counter.UiOperandType
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.counter.UiCounterOperatorDropdownItem
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.counter.UiStaticOrCounterSelection
Expand Down Expand Up @@ -104,9 +105,9 @@ fun IncludeStaticOrCounterSelectionBinding.setValueInfo(uiState: UiStaticOrCount
counterValueLayout.root.visibility = View.GONE

staticValueLayout.setText(
uiState.value.toString(),
uiState.value.toNaturalDisplayString(),
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL,
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2026 Kevin Buzeau
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters

import com.buzbuz.smartautoclicker.core.domain.model.counter.CounterOperationValue

import java.math.BigDecimal
import java.math.RoundingMode

fun Double.toNaturalDisplayString(maxFractionDigits: Int? = null): String {
if (!isFinite()) return toString()

val value = maxFractionDigits
?.let { BigDecimal.valueOf(this).setScale(it, RoundingMode.HALF_UP) }
?: BigDecimal.valueOf(this)

return value.stripTrailingZeros().toPlainString()
}

fun CounterOperationValue.toNaturalDisplayString(): String =
when (this) {
is CounterOperationValue.Counter -> value
is CounterOperationValue.Number -> value.toNaturalDisplayString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ internal fun CounterOperationValue.toEffectDescription(context: Context, operati
is CounterOperationValue.Number -> context.getString(
R.string.message_number_condition_static_value_desc,
context.getString(operation.toFullNameRes()),
value.toString(),
value.toNaturalDisplayString(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Context
import androidx.annotation.DrawableRes
import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter
import com.buzbuz.smartautoclicker.feature.smart.config.R
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString


@DrawableRes
Expand All @@ -36,5 +37,5 @@ internal fun ChangeCounter.getDescription(context: Context, inError: Boolean): S
ChangeCounter.OperationType.MINUS -> "-"
ChangeCounter.OperationType.SET -> "="
},
operationValue.value.toString(),
)
operationValue.toNaturalDisplayString(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.buzbuz.smartautoclicker.core.domain.model.condition.TriggerCondition
import com.buzbuz.smartautoclicker.core.domain.model.counter.ComparisonOperation.*
import com.buzbuz.smartautoclicker.core.ui.utils.formatDuration
import com.buzbuz.smartautoclicker.feature.smart.config.R
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString


data class UiTriggerCondition(
Expand Down Expand Up @@ -52,7 +53,7 @@ private fun TriggerCondition.getTriggerConditionDescription(context: Context): S
R.string.item_counter_reached_details,
counterName,
getComparisonOperationDisplayName(context),
counterValue.value.toString(),
counterValue.toNaturalDisplayString(),
)

is TriggerCondition.OnTimerReached -> context.getString(
Expand All @@ -76,4 +77,4 @@ private fun TriggerCondition.OnBroadcastReceived.toBroadcastActionDisplayName():
return if (lastDotIndex != -1 && lastDotIndex != intentAction.lastIndex)
intentAction.substring(lastDotIndex + 1)
else intentAction
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.counter

import com.buzbuz.smartautoclicker.core.domain.model.counter.Counter
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString

sealed class UiStaticOrCounterSelection {
data class StaticValue(val value: Double): UiStaticOrCounterSelection()
Expand All @@ -31,6 +32,6 @@ enum class UiOperandType {
fun UiStaticOrCounterSelection.toDisplayValue(): String =
when (this) {
is UiStaticOrCounterSelection.CounterValue -> counter?.counterName ?: "?"
is UiStaticOrCounterSelection.StaticValue -> value.toString()
is UiStaticOrCounterSelection.StaticValue -> value.toNaturalDisplayString()
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.buzbuz.smartautoclicker.core.ui.views.itembrief.renderers.TextConditi
import com.buzbuz.smartautoclicker.feature.smart.config.domain.EditionRepository
import com.buzbuz.smartautoclicker.feature.smart.config.domain.model.EditedListState
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toEffectDescription
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.condition.toUiScreenCondition

import dagger.hilt.android.qualifiers.ApplicationContext
Expand Down Expand Up @@ -263,6 +264,9 @@ private fun ScreenCondition.Text.toTextItemDescription(): TextConditionDescripti

private fun ScreenCondition.Number.toTextItemDescription(context: Context): TextConditionDescription =
TextConditionDescription(
conditionText = comparisonOperation.toEffectDescription(context, operand = counterValue.value.toString()),
conditionText = comparisonOperation.toEffectDescription(
context = context,
operand = counterValue.toNaturalDisplayString(),
),
conditionDetectionArea = detectionArea,
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import com.buzbuz.smartautoclicker.core.ui.bindings.fields.setOnTextChangedListe
import com.buzbuz.smartautoclicker.core.ui.bindings.fields.setText
import com.buzbuz.smartautoclicker.feature.smart.config.R
import com.buzbuz.smartautoclicker.feature.smart.config.databinding.ItemCounterConfigBinding
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString

import com.google.android.material.textfield.TextInputLayout
import java.util.Locale

/**
* Adapter for the list of counters in the configuration.
Expand Down Expand Up @@ -132,7 +132,7 @@ class CountersConfigViewHolder(
readByButton.visibility = View.VISIBLE
deleteButton.visibility = View.VISIBLE

val startingValueText = String.format(Locale.getDefault(), "%s", newItem.startingValue)
val startingValueText = newItem.startingValue.toNaturalDisplayString()
layoutStartingValue.setText(startingValueText, InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
} else {
buttonExpandCollapse.setIconResource(R.drawable.ic_chevron_down)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.buzbuz.smartautoclicker.feature.smart.config.domain.usecase.counter.G
import com.buzbuz.smartautoclicker.feature.smart.config.domain.usecase.counter.model.CounterReference
import com.buzbuz.smartautoclicker.feature.smart.config.domain.usecase.counter.GetCounterWriteReferencesUseCase
import com.buzbuz.smartautoclicker.feature.smart.config.domain.usecase.counter.ReplaceCounterUseCase
import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.formatters.toNaturalDisplayString

import dagger.hilt.android.qualifiers.ApplicationContext

Expand Down Expand Up @@ -171,8 +172,10 @@ private fun Context.getDescription(referencesCount: Int, isExpanded: Boolean, st
if (referencesCount == 0) getString(R.string.item_counter_desc_expanded_no_reference)
else getString(R.string.item_counter_desc_expanded_referenced, referencesCount)
} else {
if (referencesCount == 0) getString(R.string.item_counter_desc_collapsed_no_reference, startingValue)
else getString(R.string.item_counter_desc_collapsed_referenced, referencesCount, startingValue)
val startingValueText = startingValue.toNaturalDisplayString(maxFractionDigits = 2)

if (referencesCount == 0) getString(R.string.item_counter_desc_collapsed_no_reference, startingValueText)
else getString(R.string.item_counter_desc_collapsed_referenced, referencesCount, startingValueText)
}

private fun Context.getSetByButtonText(actionsCount: Int): String =
Expand All @@ -185,4 +188,4 @@ private fun Context.getReadByButtonText(conditionsCount: Int): String =

private fun Context.getDeleteButtonText(referencesCount: Int): String =
if (referencesCount == 0) getString(R.string.button_text_counter_delete)
else getString(R.string.button_text_counter_delete_and_replace)
else getString(R.string.button_text_counter_delete_and_replace)
Loading