질문이 없데이트 된 것 같네요...원하는 기능을 보면, 굳이 비트맵 자체를 비교하실 필요는 없어 보이네요. 단순히 입력한 내용을 받아서 서버로 올려주면 되는 기능같은데요.
앞에 말씀드렸다 시피 이미지에 정보를 같는 클래스를 하나 만드시고 ID필드와 Image filePath필드를 추가하세요.
public class ImageInfo {
private final String id;
private final String title;
private final String description;
private final String filePath; //Uri 를 사용하실 수도 있을 거예요
public ImageInfo(String id, String title, String description, String filePath) {
this.id = id;
this.title = title;
this.description = description;
this.filePath = filePath;
}
// getters
@Override
public boolean equals(Object other) {
if (other == null || other instanceof ImageInfo) return false;
return this.id != null && !this.id.isEmpty() && this.id.equals(((ImageInfo) other).id);
}
@Override
public int hashCode() {
return id != null && id.isEmpty() ?: Objects.hasCode(this) : id.hashCode();
}
public Boolean actuallyChanged(ImageInfo oldItem) {
return isSameContent(oldItem.id, this.id) &&
isSameContent(oldItem.title, this.title) &&
isSameContent(oldItem.description, this.description) &&
isSameContent(oldItem.filePath, this.filePath);
}
}
public static boolean isSameContent(String oldItem, String newItem) {
return oldItem != null && !oldItem.isEmpty() && oldItem.equals(newItem);
}
id는 서버에서 식별되는 고유값이 될거구요. 새로운 입력이라면 없을 거구, 업데이트라면 존재하겠죠.
filePath는 사용자가 선택한 이미지에 대한 파일이름(경로포함)을 보관합니다. 만약 업데이트 모드라면 서버에 보관된 파일이름으로 초기화가 되어있겠죠.
만약 사용자의 입력이 실제로 변경이 된 것인지까지 체크하시려면 이 클래스의 인스터스를 두개 만드세요. 하나는 업데이트 모드에서 서버에 있는 정보를 가지고 있는 클래스, 다른 하나는 사용자의 입력을 받는 클래스. 이 두개를 비교하셔서 실제 변경여부를 파악하시면 됩니다.
이미지가 아무 것도 없을 때 place holder를 보여주시는 거는 사용자 입력용 ImageInfo class의 filePath가 아무 것도 없을 때 해주시면 됩니다.
void setImage(ImageInfo imageInfo) {
if (TextUtils.isEmpty(imageInfo.filePath)) {
showPlaceHolder();
return;
}
boolean isUpdateMode = !TextUtils.isEmpty(imageInfo.id)
if (isUpdateMode) {
//업데이트 모드일 때는 filePath는 아마도 이미지 URL이겠죠.
Glide.... //Glide같은 라이브러리를 사용하는 것이 편합니다.
return;
}
Glide... // 로컬 이미지를 보여주면 됩니다.
}
위의 코드는 그냥 설명을 위해 작성한 것 뿐이구요. filePath가 데이터의 저장여부에 따라 URL이나 local file path가 될 수 있기 때문에 이 부분은 부모 클래스를 하나 만드셔서 자식 클래스를 두개 만드시거나 enum 같은 걸로 종류를 구분하시면 처리하시면 좋을 듯 합니다.
public interface class ImageFilePath {
String getFilePath();
}
public class LocalFilePath implements ImageFilePath {
...
}
public class LocalFilePath implements RemoteFilePath {
...
}
// enum을 사용할 수도 있을 듯
public enum ImagePathType {
LOCAL,
REMOTE
}
public class ImageFilePath {
private final pathType: ImagePathType
private final String filePath;
// Constructor
public static createLocalPath(filePath) {
return new ImageFilePath(ImagePathType.LOCAL, filepath);
}
public static createRemotePath(filePath) {
return new ImageFilePath(ImagePathType.REMOTE, filepath);
}
}
잘 살펴보시면 많은 부분은 캡슐화 하거나 중복을 줄이실 수 있을 겁니다.