@@ -14,8 +14,8 @@ import kotlinx.coroutines.withContext
1414import to.bitkit.data.SettingsStore
1515import to.bitkit.di.BgDispatcher
1616import to.bitkit.ext.rawId
17+ import to.bitkit.repositories.ActivityRepo
1718import to.bitkit.repositories.BlocktankRepo
18- import to.bitkit.services.CoreService
1919import to.bitkit.utils.AddressChecker
2020import to.bitkit.utils.Logger
2121import to.bitkit.utils.TxDetails
@@ -25,7 +25,7 @@ import javax.inject.Inject
2525class ActivityDetailViewModel @Inject constructor(
2626 @BgDispatcher private val bgDispatcher : CoroutineDispatcher ,
2727 private val addressChecker : AddressChecker ,
28- private val coreService : CoreService ,
28+ private val activityRepo : ActivityRepo ,
2929 private val settingsStore : SettingsStore ,
3030 private val blocktankRepo : BlocktankRepo ,
3131) : ViewModel() {
@@ -48,40 +48,41 @@ class ActivityDetailViewModel @Inject constructor(
4848 fun loadTags () {
4949 val id = activity?.rawId() ? : return
5050 viewModelScope.launch(bgDispatcher) {
51- try {
52- val activityTags = coreService.activity.tags(forActivityId = id)
53- _tags .value = activityTags
54- } catch (e: Exception ) {
55- Logger .error(" Failed to load tags for activity $id " , e, TAG )
56- _tags .value = emptyList()
57- }
51+ activityRepo.getActivityTags(id)
52+ .onSuccess { activityTags ->
53+ _tags .value = activityTags
54+ }
55+ .onFailure { e ->
56+ Logger .error(" Failed to load tags for activity $id " , e, TAG )
57+ _tags .value = emptyList()
58+ }
5859 }
5960 }
6061
6162 fun removeTag (tag : String ) {
6263 val id = activity?.rawId() ? : return
6364 viewModelScope.launch(bgDispatcher) {
64- try {
65- coreService.activity.dropTags(fromActivityId = id, tags = listOf (tag))
66- loadTags()
67- } catch (e: Exception ) {
68- Logger .error(" Failed to remove tag $tag from activity $id " , e, TAG )
69- }
65+ activityRepo.removeTagsFromActivity(id, listOf (tag))
66+ .onSuccess {
67+ loadTags()
68+ }
69+ .onFailure { e ->
70+ Logger .error(" Failed to remove tag $tag from activity $id " , e, TAG )
71+ }
7072 }
7173 }
7274
7375 fun addTag (tag : String ) {
7476 val id = activity?.rawId() ? : return
7577 viewModelScope.launch(bgDispatcher) {
76- try {
77- val result = coreService.activity.appendTags(toActivityId = id, tags = listOf (tag))
78- if (result.isSuccess) {
78+ activityRepo.addTagsToActivity(id, listOf (tag))
79+ .onSuccess {
7980 settingsStore.addLastUsedTag(tag)
8081 loadTags()
8182 }
82- } catch (e : Exception ) {
83- Logger .error(" Failed to add tag $tag to activity $id " , e, TAG )
84- }
83+ .onFailure { e ->
84+ Logger .error(" Failed to add tag $tag to activity $id " , e, TAG )
85+ }
8586 }
8687 }
8788
0 commit comments