Skip to content

Commit

Permalink
fix lifecycleOwner for java
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jul 18, 2020
1 parent eff7fad commit eb726f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ public void onClick(View view) {
}
});

mViewModel.getSuggestions().observe(this, new Observer<List<SmartReplySuggestion>>() {
mViewModel.getSuggestions().observe(getViewLifecycleOwner(), new Observer<List<SmartReplySuggestion>>() {
@Override
public void onChanged(List<SmartReplySuggestion> suggestions) {
mChipAdapter.setSuggestions(suggestions);
}
});

mViewModel.getMessages().observe(this, new Observer<List<Message>>() {
mViewModel.getMessages().observe(getViewLifecycleOwner(), new Observer<List<Message>>() {
@Override
public void onChanged(List<Message> messages) {
mChatAdapter.setMessages(messages);
Expand All @@ -155,7 +155,7 @@ public void onChanged(List<Message> messages) {
}
});

mViewModel.getEmulatingRemoteUser().observe(this, new Observer<Boolean>() {
mViewModel.getEmulatingRemoteUser().observe(getViewLifecycleOwner(), new Observer<Boolean>() {
@Override
public void onChanged(Boolean isEmulatingRemoteUser) {
if (isEmulatingRemoteUser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
final Spinner sourceLangSelector = view.findViewById(R.id.sourceLangSelector);
final Spinner targetLangSelector = view.findViewById(R.id.targetLangSelector);

final TranslateViewModel viewModel =
ViewModelProviders.of(this).get(TranslateViewModel.class);
final TranslateViewModel viewModel = ViewModelProviders.of(this).get(TranslateViewModel.class);

// Get available language list and set up source and target language spinners
// with default selections.
Expand Down Expand Up @@ -162,7 +161,7 @@ public void afterTextChanged(Editable s) {
viewModel.sourceText.postValue(s.toString());
}
});
viewModel.translatedText.observe(this, new Observer<TranslateViewModel.ResultOrError>() {
viewModel.translatedText.observe(getViewLifecycleOwner(), new Observer<TranslateViewModel.ResultOrError>() {
@Override
public void onChanged(TranslateViewModel.ResultOrError resultOrError) {
if (resultOrError.error != null) {
Expand All @@ -174,7 +173,7 @@ public void onChanged(TranslateViewModel.ResultOrError resultOrError) {
});

// Update sync toggle button states based on downloaded models list.
viewModel.availableModels.observe(this, new Observer<List<String>>() {
viewModel.availableModels.observe(getViewLifecycleOwner(), new Observer<List<String>>() {
@Override
public void onChanged(@Nullable List<String> translateRemoteModels) {
String output = getContext().getString(R.string.downloaded_models_label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class TranslateFragment : Fragment() {
}
})

viewModel.translatedText.observe(this, Observer { resultOrError ->
viewModel.translatedText.observe(viewLifecycleOwner, Observer { resultOrError ->
resultOrError?.let {
if (it.error != null) {
sourceText.error = resultOrError.error?.localizedMessage
Expand All @@ -159,7 +159,7 @@ class TranslateFragment : Fragment() {
})

// Update sync toggle button states based on downloaded models list.
viewModel.availableModels.observe(this, Observer { translateRemoteModels ->
viewModel.availableModels.observe(viewLifecycleOwner, Observer { translateRemoteModels ->
val output = context!!.getString(
R.string.downloaded_models_label, translateRemoteModels
)
Expand Down

0 comments on commit eb726f2

Please sign in to comment.