Improve error display

This commit is contained in:
Phillip Thelen 2022-07-18 11:55:55 +02:00
parent 19456dd357
commit 03f0ebe795
8 changed files with 23 additions and 24 deletions

View file

@ -23,14 +23,6 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do
Runs all the tests
### android testUpload
```sh
[bundle exec] fastlane android testUpload
```
### android staff
```sh

View file

@ -1,2 +1,2 @@
NAME=4.0
CODE=4210
CODE=4230

View file

@ -1,3 +1,3 @@
package com.habitrpg.wearos.habitica.models
data class DisplayedError(val title: String, val subtitle: String? = null)
data class DisplayedError(val icon: Int, val title: String, val subtitle: String? = null)

View file

@ -12,7 +12,6 @@ import com.google.android.gms.tasks.Tasks
import com.google.android.gms.wearable.CapabilityClient
import com.google.android.gms.wearable.MessageClient
import com.google.android.gms.wearable.Wearable
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.databinding.ActivityWrapperBinding
import com.habitrpg.wearos.habitica.managers.AppStateManager
import com.habitrpg.wearos.habitica.ui.viewmodels.BaseViewModel
@ -45,7 +44,7 @@ abstract class BaseActivity<B: ViewBinding, VM: BaseViewModel> : ComponentActivi
viewModel.errorValues.observe(this) {
val intent = Intent(this, ConfirmationActivity::class.java).apply {
putExtra("text", it.title)
putExtra("icon", R.drawable.error)
putExtra("icon", it.icon)
}
startActivity(intent)
}

View file

@ -83,16 +83,6 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
) {
openTasklist(TaskType.HABIT)
},
MenuItem(
TaskType.REWARD.value,
getString(R.string.rewards),
AppCompatResources.getDrawable(this, R.drawable.icon_rewards),
ContextCompat.getColor(this, R.color.watch_purple_200),
ContextCompat.getColor(this, R.color.watch_purple_700),
isHidden = true
) {
openTasklist(TaskType.REWARD)
},
MenuItem(
"stats",
getString(R.string.stats),

View file

@ -13,6 +13,7 @@ import com.habitrpg.wearos.habitica.managers.AppStateManager
import com.habitrpg.wearos.habitica.models.tasks.Task
import com.habitrpg.wearos.habitica.util.ExceptionHandlerBuilder
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
@ -56,6 +57,11 @@ class TaskListViewModel @Inject constructor(
task,
direction
)
if (result?.hasLeveledUp == true) {
launch(Dispatchers.Main) {
userRepository.retrieveUser()
}
}
onResult(result)
}
}

View file

@ -1,10 +1,12 @@
package com.habitrpg.wearos.habitica.util
import android.util.Log
import com.habitrpg.android.habitica.R
import com.habitrpg.wearos.habitica.managers.AppStateManager
import com.habitrpg.wearos.habitica.models.DisplayedError
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.CoroutineExceptionHandler
import java.io.IOException
import javax.inject.Inject
@ViewModelScoped
@ -19,7 +21,16 @@ class ExceptionHandlerBuilder @Inject constructor(val appStateManager: AppStateM
fun userFacing(errorPresenter: ErrorPresenter): CoroutineExceptionHandler {
return CoroutineExceptionHandler { _, throwable ->
Log.e("Coroutine Error", "Error: ${throwable.cause}", throwable)
errorPresenter.errorValues.value = throwable.message?.let { DisplayedError(it) }
if (throwable is IOException) {
errorPresenter.errorValues.value = throwable.message?.let {
DisplayedError(R.drawable.disconnected, "Disconnected")
}
} else {
errorPresenter.errorValues.value = throwable.message?.let {
DisplayedError(R.drawable.error, it)
}
}
appStateManager.endLoading()
}
}

View file

@ -19,7 +19,8 @@
android:text="@string/log_out_of_habitica"
android:fontFamily="sans-serif-medium"
android:textColor="@color/watch_white"
android:layout_marginBottom="18dp"/>
android:layout_marginBottom="18dp"
android:layout_marginHorizontal="@dimen/spacing_large"/>
<com.habitrpg.wearos.habitica.ui.views.TextActionChipView