Skip to content

Commit 636ede6

Browse files
committed
Displaying error details in Reset fragment
1 parent e80469d commit 636ede6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

sample/src/main/java/io/runtime/mcumgr/sample/fragment/mcumgr/ResetFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import io.runtime.mcumgr.sample.databinding.FragmentCardResetBinding;
2222
import io.runtime.mcumgr.sample.di.Injectable;
23+
import io.runtime.mcumgr.sample.utils.StringUtils;
2324
import io.runtime.mcumgr.sample.viewmodel.mcumgr.McuMgrViewModelFactory;
2425
import io.runtime.mcumgr.sample.viewmodel.mcumgr.ResetViewModel;
2526

@@ -52,7 +53,7 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
5253
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
5354
super.onViewCreated(view, savedInstanceState);
5455

55-
viewModel.getError().observe(getViewLifecycleOwner(), s -> binding.resetError.setText(s));
56+
viewModel.getError().observe(getViewLifecycleOwner(), e -> binding.resetError.setText(StringUtils.toString(requireContext(), e)));
5657
viewModel.getBusyState().observe(getViewLifecycleOwner(), busy -> binding.actionReset.setEnabled(!busy));
5758
binding.actionReset.setOnClickListener(v -> viewModel.reset());
5859
}

sample/src/main/java/io/runtime/mcumgr/sample/viewmodel/mcumgr/ResetViewModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class ResetViewModel extends McuMgrViewModel {
2323
private final DefaultManager manager;
2424

25-
private final MutableLiveData<String> errorLiveData = new MutableLiveData<>();
25+
private final MutableLiveData<McuMgrException> errorLiveData = new MutableLiveData<>();
2626

2727
@Inject
2828
ResetViewModel(final DefaultManager manager,
@@ -32,7 +32,7 @@ public class ResetViewModel extends McuMgrViewModel {
3232
}
3333

3434
@NonNull
35-
public LiveData<String> getError() {
35+
public LiveData<McuMgrException> getError() {
3636
return errorLiveData;
3737
}
3838

@@ -57,7 +57,7 @@ public void onDisconnected() {
5757

5858
@Override
5959
public void onError(@NonNull final McuMgrException error) {
60-
errorLiveData.postValue(error.getMessage());
60+
errorLiveData.postValue(error);
6161
postReady();
6262
}
6363
});

0 commit comments

Comments
 (0)