Skip to content

Commit

Permalink
Fix the rotation/network behaviour on the message detail activity
Browse files Browse the repository at this point in the history
  • Loading branch information
judit-juhasz committed Jul 13, 2018
1 parent 6cfd5dd commit 8213f38
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class MessageDetailsFragment extends Fragment {

public static final String MESSAGE_DATA = "MESSAGE_DATA";

private static final String SAVE_MESSAGE_CONTENT_KEY = "SAVE_MESSAGE_CONTENT_KEY";

@BindView(R.id.tv_date)
TextView mDateTextView;
@BindView(R.id.tv_content)
Expand Down Expand Up @@ -57,10 +59,17 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
ButterKnife.bind(this, rootView);

if (null != mMessage) {
if (NetworkUtils.isNetworkAvailable(getContext())) {
showProgressBar();
} else {
final boolean hasValidSavedData =
(null != savedInstanceState && savedInstanceState.containsKey(SAVE_MESSAGE_CONTENT_KEY));
if (!NetworkUtils.isNetworkAvailable(getContext()) && !hasValidSavedData) {
showNotification(getString(R.string.internet_required));
} else if (hasValidSavedData) {
mDateTextView.setText(mMessage.getDate());
mSummaryTextView.setText(mMessage.getSummary());
mContentTextView.setText(savedInstanceState.getString(SAVE_MESSAGE_CONTENT_KEY));
showMessageDetails();
} else {
showProgressBar();
}
FirebaseUtils.queryMessageContent(mMessage.getId(), new FirebaseUtils.StringListener() {
@Override
Expand All @@ -81,6 +90,12 @@ public void onCancelled(@NonNull DatabaseError databaseError) {
return rootView;
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString(SAVE_MESSAGE_CONTENT_KEY, mContentTextView.getText().toString());
super.onSaveInstanceState(outState);
}

private void showNotification(@NonNull final String notificationText) {
mLoadProgressBar.setVisibility(View.INVISIBLE);
mMessageDetailsScrollView.setVisibility(View.GONE);
Expand Down

0 comments on commit 8213f38

Please sign in to comment.