Merge pull request #2716 from Trogel/show-pictures-button-state
Move save/restore of "show pictures" button state into MessageTopView Fixes #2685
This commit is contained in:
commit
8843ecb201
2 changed files with 56 additions and 79 deletions
|
@ -8,8 +8,6 @@ import android.content.ActivityNotFoundException;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ContextMenu;
|
||||
|
@ -68,7 +66,6 @@ public class MessageContainerView extends LinearLayout implements OnLayoutChange
|
|||
private boolean showingPictures;
|
||||
private LayoutInflater mInflater;
|
||||
private AttachmentViewCallback attachmentCallback;
|
||||
private SavedState mSavedState;
|
||||
private ClipboardManager mClipboardManager;
|
||||
private Map<AttachmentViewInfo, AttachmentView> attachmentViewMap = new HashMap<>();
|
||||
private Map<Uri, AttachmentViewInfo> attachments = new HashMap<>();
|
||||
|
@ -371,7 +368,7 @@ public class MessageContainerView extends LinearLayout implements OnLayoutChange
|
|||
}
|
||||
|
||||
public void displayMessageViewContainer(MessageViewInfo messageViewInfo,
|
||||
final OnRenderingFinishedListener onRenderingFinishedListener, boolean automaticallyLoadPictures,
|
||||
final OnRenderingFinishedListener onRenderingFinishedListener, boolean loadPictures,
|
||||
boolean hideUnsignedTextDivider, AttachmentViewCallback attachmentCallback) {
|
||||
|
||||
this.attachmentCallback = attachmentCallback;
|
||||
|
@ -380,18 +377,10 @@ public class MessageContainerView extends LinearLayout implements OnLayoutChange
|
|||
|
||||
renderAttachments(messageViewInfo);
|
||||
|
||||
if (mSavedState != null) {
|
||||
if (mSavedState.showingPictures) {
|
||||
setLoadPictures(true);
|
||||
}
|
||||
|
||||
mSavedState = null;
|
||||
}
|
||||
|
||||
String textToDisplay = messageViewInfo.text;
|
||||
if (textToDisplay != null && !isShowingPictures()) {
|
||||
if (Utility.hasExternalImages(textToDisplay)) {
|
||||
if (automaticallyLoadPictures) {
|
||||
if (loadPictures) {
|
||||
setLoadPictures(true);
|
||||
} else {
|
||||
hasHiddenExternalImages = true;
|
||||
|
@ -506,32 +495,6 @@ public class MessageContainerView extends LinearLayout implements OnLayoutChange
|
|||
clearDisplayedContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
|
||||
SavedState savedState = new SavedState(superState);
|
||||
|
||||
savedState.attachmentViewVisible = (mAttachmentsContainer != null &&
|
||||
mAttachmentsContainer.getVisibility() == View.VISIBLE);
|
||||
savedState.showingPictures = showingPictures;
|
||||
|
||||
return savedState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
if(!(state instanceof SavedState)) {
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
|
||||
SavedState savedState = (SavedState)state;
|
||||
super.onRestoreInstanceState(savedState.getSuperState());
|
||||
|
||||
mSavedState = savedState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChanged() {
|
||||
if (mMessageContentView != null) {
|
||||
|
@ -555,42 +518,6 @@ public class MessageContainerView extends LinearLayout implements OnLayoutChange
|
|||
return attachmentViewMap.get(attachment);
|
||||
}
|
||||
|
||||
static class SavedState extends BaseSavedState {
|
||||
boolean attachmentViewVisible;
|
||||
boolean showingPictures;
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||
new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
this.attachmentViewVisible = (in.readInt() != 0);
|
||||
this.showingPictures = (in.readInt() != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeInt((this.attachmentViewVisible) ? 1 : 0);
|
||||
out.writeInt((this.showingPictures) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
interface OnRenderingFinishedListener {
|
||||
void onLoadFinished();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.animation.AnimatorListenerAdapter;
|
|||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -49,6 +51,7 @@ public class MessageTopView extends LinearLayout {
|
|||
private AttachmentViewCallback attachmentCallback;
|
||||
private Button showPicturesButton;
|
||||
private boolean isShowingProgress;
|
||||
private boolean showPicturesButtonClicked;
|
||||
|
||||
private MessageCryptoPresenter messageCryptoPresenter;
|
||||
|
||||
|
@ -85,6 +88,7 @@ public class MessageTopView extends LinearLayout {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
showPicturesInAllContainerViews();
|
||||
showPicturesButtonClicked = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -107,8 +111,8 @@ public class MessageTopView extends LinearLayout {
|
|||
resetAndPrepareMessageView(messageViewInfo);
|
||||
|
||||
ShowPictures showPicturesSetting = account.getShowPictures();
|
||||
boolean automaticallyLoadPictures =
|
||||
shouldAutomaticallyLoadPictures(showPicturesSetting, messageViewInfo.message);
|
||||
boolean loadPictures = shouldAutomaticallyLoadPictures(showPicturesSetting, messageViewInfo.message) ||
|
||||
showPicturesButtonClicked;
|
||||
|
||||
MessageContainerView view = (MessageContainerView) mInflater.inflate(R.layout.message_container,
|
||||
containerView, false);
|
||||
|
@ -120,9 +124,9 @@ public class MessageTopView extends LinearLayout {
|
|||
public void onLoadFinished() {
|
||||
displayViewOnLoadFinished(true);
|
||||
}
|
||||
}, automaticallyLoadPictures, hideUnsignedTextDivider, attachmentCallback);
|
||||
}, loadPictures, hideUnsignedTextDivider, attachmentCallback);
|
||||
|
||||
if (view.hasHiddenExternalImages()) {
|
||||
if (view.hasHiddenExternalImages() && !showPicturesButtonClicked) {
|
||||
showShowPicturesButton();
|
||||
}
|
||||
}
|
||||
|
@ -328,4 +332,50 @@ public class MessageTopView extends LinearLayout {
|
|||
progressBar.setProgress(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
SavedState savedState = new SavedState(superState);
|
||||
savedState.showPicturesButtonClicked = showPicturesButtonClicked;
|
||||
return savedState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState savedState = (SavedState) state;
|
||||
super.onRestoreInstanceState(savedState.getSuperState());
|
||||
showPicturesButtonClicked = savedState.showPicturesButtonClicked;
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
boolean showPicturesButtonClicked;
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
|
||||
SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
this.showPicturesButtonClicked = (in.readInt() != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeInt((this.showPicturesButtonClicked) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue