Skip to content

Commit

Permalink
fix: Toast on non-main thread
Browse files Browse the repository at this point in the history
Change-Id: I859fc6eb25856b47dd266b3ac0ae035eae496960
  • Loading branch information
XayahSuSuSu committed Dec 2, 2024
1 parent 5ee40e9 commit 7f3b5e9
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.xayah.core.rootservice.service.RemoteRootService
import com.xayah.core.ui.route.MainRoutes
import com.xayah.core.util.decodeURL
import com.xayah.core.util.launchOnDefault
import com.xayah.core.util.withMainContext
import com.xayah.feature.main.details.DetailsUiState.Error
import com.xayah.feature.main.details.DetailsUiState.Loading
import com.xayah.feature.main.details.DetailsUiState.Success
Expand Down Expand Up @@ -130,7 +131,9 @@ class DetailsViewModel @Inject constructor(
fun addLabel(label: String) {
viewModelScope.launchOnDefault {
if (label.trim().isEmpty() || labelsRepo.addLabel(label.trim()) == -1L) {
Toast.makeText(context, context.getString(R.string.failed), Toast.LENGTH_SHORT).show()
withMainContext {
Toast.makeText(context, context.getString(R.string.failed), Toast.LENGTH_SHORT).show()
}
}
}
}
Expand Down

0 comments on commit 7f3b5e9

Please sign in to comment.