Skip to content

Commit e9a729d

Browse files
committed
Fixed the bug that caused stale state to persist when opening Direct Icon commands without sheet.
1 parent 5221c06 commit e9a729d

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

app/src/main/java/com/autosec/pie/DirectCommandActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ class DirectCommandActivity : ComponentActivity() {
9393
//Get the command from the list
9494

9595
scope.launch {
96-
delay(250L)
96+
delay(100L)
9797
if(commandId != null){
9898
Timber.d("Setting command to $commandId")
99-
val success = shareReceiverViewModel.selectCommandFromDirectActivity(commandId)
99+
val success = shareReceiverViewModel.selectCommandFromDirectActivity(commandId, activity)
100100
}
101101
}
102102

app/src/main/java/com/autosec/pie/autopieapp/presentation/screens/CommandDetailsSheet.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.ui.platform.LocalContext
2929
import androidx.compose.ui.text.font.FontWeight
3030
import androidx.compose.ui.unit.dp
3131
import androidx.compose.ui.unit.sp
32+
import com.autosec.pie.BuildConfig
3233
import com.autosec.pie.R
3334
import com.autosec.pie.autopieapp.data.CommandModel
3435
import com.autosec.pie.autopieapp.data.ShareInputs
@@ -73,7 +74,7 @@ fun CommandDetailsSheet(
7374
.setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
7475
.setIntent(
7576
Intent(Intent.ACTION_MAIN).apply {
76-
setClassName(context, context.packageName + ".DirectCommandActivity")
77+
setClassName(context, BuildConfig.APPLICATION_ID + ".DirectCommandActivity")
7778
putExtra("commandId", commandId)
7879
flags = Intent.FLAG_ACTIVITY_NEW_TASK
7980
}

app/src/main/java/com/autosec/pie/autopieapp/presentation/viewModels/ShareReceiverViewModel.kt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.autosec.pie.autopieapp.presentation.viewModels
22

3+
import android.app.Activity
34
import android.app.Application
45
import android.content.Intent
56
import android.os.Environment
@@ -170,32 +171,33 @@ class ShareReceiverViewModel(private val application1: Application) : ViewModel(
170171
}
171172
}
172173

173-
fun selectCommandFromDirectActivity(commandId: String): Boolean{
174-
val command = shareItemsResult.value.find { it.name == commandId }
174+
fun selectCommandFromDirectActivity(commandId: String, activity: Activity?): Boolean{
175+
try {
176+
val command = shareItemsResult.value.find { it.name == commandId }
175177

176-
if(command == null){
177-
Timber.d("Command not found: $commandId")
178-
return false
179-
}
178+
if(command == null){
179+
Timber.d("Command not found: $commandId")
180+
return false
181+
}
180182

181-
if (command.extras?.isNotEmpty() == true) {
182-
Timber.d("Opening Extras sheet for $commandId")
183-
currentExtrasDetails.value =
184-
Triple(true, command, ShareInputs(null, null))
185-
}else{
186-
onCommandClick(command, emptyList(), null) {
187-
viewModelScope.launch {
188-
// isLoading = true
189-
// delay(900)
190-
// Timber.d("CLOSING THE AUTOPIE COMMANDS SHEET.")
191-
// activity?.finish()
192-
193-
delay(1500L)
194-
currentExtrasDetails.value = null
183+
if (command.extras?.isNotEmpty() == true) {
184+
Timber.d("Opening Extras sheet for $commandId")
185+
currentExtrasDetails.value =
186+
Triple(true, command, ShareInputs(null, null))
187+
}else{
188+
onCommandClick(command, emptyList(), null) {
189+
viewModelScope.launch {
190+
delay(1000L)
191+
currentExtrasDetails.value = null
192+
activity?.finish()
193+
}
195194
}
196195
}
196+
return true
197+
}catch (e: Exception){
198+
Timber.e(e)
199+
return false
197200
}
198-
return true
199201
}
200202

201203

0 commit comments

Comments
 (0)