Skip to content

Commit

Permalink
Allow Tasker variables in input #7
Browse files Browse the repository at this point in the history
  • Loading branch information
RafhaanShah committed Apr 27, 2024
1 parent 4b89f81 commit 9de8872
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-ktx:1.13.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class AggregatedHealthDataActionRunner :
): TaskerPluginResult<AggregatedHealthDataOutput> {
Log.d(TAG, "run: $input")
val repository = HealthConnectRepository(context)
val offsetTime = daysToOffsetTime(input.regular.days)
val days = runCatching { input.regular.days.toLong() }.getOrElse {
Log.e(TAG, "invalid input: ${input.regular.days}")
return TaskerPluginResultErrorWithOutput(Throwable(it))
}
val offsetTime = daysToOffsetTime(days)

if (!repository.isAvailable() || runBlocking { !repository.hasPermissions() }) {
val errMessage = context.getString(R.string.health_connect_unavailable_or_permissions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AggregatedHealthDataActivity : AppCompatActivity(),
)

override fun assignFromInput(input: TaskerInput<AggregatedHealthDataInput>) {
binding.daysText.editText?.setText(input.regular.days.toString())
binding.daysText.editText?.setText(input.regular.days)
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -93,10 +93,8 @@ class AggregatedHealthDataActivity : AppCompatActivity(),
}
}

private fun getInputDays(): Long {
return runCatching {
binding.daysText.editText?.text.toString().toLong()
}.getOrDefault(0L)
private fun getInputDays(): String {
return binding.daysText.editText?.text.toString()
}

private fun hideKeyboard() {
Expand All @@ -110,7 +108,8 @@ class AggregatedHealthDataActivity : AppCompatActivity(),
binding.debugButton.isVisible = BuildConfig.DEBUG
binding.debugButton.setOnClickListener {
lifecycleScope.launch {
val startTime = AggregatedHealthDataActionRunner.daysToOffsetTime(getInputDays())
val startTime = AggregatedHealthDataActionRunner.daysToOffsetTime(
getInputDays().toLongOrNull() ?: 0L)
val endTime = Instant.now()
runCatching {
val output = repository.getAggregateData(startTime, endTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ class AggregatedHealthDataInput @JvmOverloads constructor(
key = "days",
labelResId = R.string.days,
descriptionResId = R.string.days_description
) var days: Long = 0L
)
) var days: String = "0"
) {
override fun toString(): String {
return "days: $days"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class AggregatedHealthDataOutput(
labelResId = R.string.aggregated_health_data,
htmlLabelResId = R.string.aggregated_health_data_description
) val aggregatedHealthData: String = "[]"
)
) {
override fun toString(): String {
return "aggregatedHealthData: $aggregatedHealthData"
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_aggregated_health_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>

<Button
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
}

plugins {
id 'com.android.application' version '8.2.1' apply false
id 'com.android.library' version '8.2.1' apply false
id 'com.android.application' version '8.3.2' apply false
id 'com.android.library' version '8.3.2' apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
}

Expand Down

0 comments on commit 9de8872

Please sign in to comment.