/src/com/agh/is/android/logdroid/telephony/data/MMS.java
https://github.com/snuffix/Android_LogdroidProject · Java · 248 lines · 202 code · 46 blank · 0 comment · 5 complexity · b67d2be0fef5b8852ce47e34c49dac6b MD5 · raw file
- package com.agh.is.android.logdroid.telephony.data;
- import java.util.Date;
- import com.agh.is.android.logdroid.R;
- import com.agh.is.android.logdroid.telephony.data.MMS.MMSBuilder;
- import com.agh.is.android.logdroid.telephony.views.DisplayableData;
- import com.agh.is.android.logdroid.telephony.views.DisplayableDataType;
- import com.agh.is.android.logdroid.utilities.ExceptionUtilities;
- public class MMS implements Comparable<MMS>, DisplayableData, TelephoneData{
-
- private Date date;
- private String address="";
- private String body="";
- private MessageType messageType;
- private String contactName = "";
- private String subject = "";
- private MMSAddressType addressType = null;
- private String imagePath = "";
- private String imageTextUri = "";
- private String audioTextUri = "";
- private String audioName = "";
-
- public static class MMSBuilder {
-
- private Date date;
- private String address="";
- private String body="";
- private MessageType messageType;
- private String contactName = "";
- private String subject = "";
- private MMSAddressType addressType = null;
- private String imagePath = "";
- private String imageTextUri = "";
- private String audioTextUri = "";
- private String audioName = "";
-
- public MMSBuilder date(Date date) {
- this.date = date;
- return this;
- }
-
- public MMSBuilder address(String address) {
- this.address = address;
- return this;
- }
-
- public MMSBuilder body(String body) {
- this.body = body;
- return this;
- }
-
- public MMSBuilder messageType(MessageType messageType) {
- this.messageType = messageType;
- return this;
- }
-
- public MMSBuilder contactName(String contactName) {
- this.contactName = contactName;
- return this;
- }
-
- public MMSBuilder subject(String subject) {
- this.subject = subject;
- return this;
- }
-
- public MMSBuilder addressType(MMSAddressType addressType) {
- this.addressType = addressType;
- return this;
- }
-
- public MMSBuilder imagePath(String imagePath) {
- this.imagePath = imagePath;
- return this;
- }
-
- public MMSBuilder imageTextUri(String imageTextUri) {
- this.imageTextUri = imageTextUri;
- return this;
- }
-
- public MMSBuilder audioTextUri(String audioTextUri) {
- this.audioTextUri = audioTextUri;
- return this;
- }
-
- public MMSBuilder audioName(String audioName) {
- this.audioName = audioName;
- return this;
- }
-
- public MMS build() {
- return new MMS(this);
- }
- }
- public static enum MMSAddressType {
- EMAIL_ADDRESS, PHONE_NUMBER;
-
- public static MMSAddressType fromString(String address) {
- if (address.matches(EMAIL_ADDRESS_REGEXP)) {
- return MMSAddressType.EMAIL_ADDRESS;
- }
- else {
- return MMSAddressType.PHONE_NUMBER;
- }
- }
-
- private static final String EMAIL_ADDRESS_REGEXP =
- "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[a-z,A-Z]{2,})$";
- }
-
- private MMS(MMSBuilder builder) {
- this.date = builder.date;
- this.address = builder.address;
- this.contactName = builder.contactName;
- this.body = builder.body;
- this.messageType = builder.messageType;
- this.subject = builder.subject;
- this.addressType = builder.addressType;
- this.imagePath = builder.imagePath;
- this.imageTextUri = builder.imageTextUri;
- this.audioTextUri = builder.audioTextUri;
- this.audioName = builder.audioName;
-
- throwIllegalStateExceptionIfStateIsNotValid();
- }
-
- public String getContactName() {
- return contactName;
- }
-
- public String getAddress(){
- return address;
- }
-
- public String getBody(){
- return body;
- }
-
- public MessageType getMessageType(){
- return messageType;
- }
-
- public MMSAddressType getAddressType() {
- return addressType;
- }
-
- public String getImagePath() {
- return imagePath;
- }
-
- public String getAudioTextUri() {
- return audioTextUri;
- }
-
- public String getAudioName() {
- return audioName;
- }
-
- public String getImageTextUri() {
- return imageTextUri;
- }
-
- public String getSubject() {
- return subject;
- }
-
- public boolean containsAudio() {
- return !getAudioTextUri().equals("") && !getAudioName().equals("");
- }
- @Override
- public int getMainLabelLength() {
- return subject.length();
- }
- @Override
- public String getMainLabelText() {
- return subject;
- }
-
- @Override
- public int getDisplayPriority() {
- return 3;
- }
-
- @Override
- public int getDataTypeThumbnail() {
- return R.drawable.mms;
- }
- @Override
- public Date getDate() {
- return date;
- }
- @Override
- public String getDisplayedAddress() {
- return address;
- }
- @Override
- public DisplayableDataType getDisplayableDataType() {
- return messageType == MessageType.RECEIVED ? DisplayableDataType.RECEIVED : DisplayableDataType.SENT;
- }
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof MMS)) {
- return false;
- }
-
- MMS anotherMMS = (MMS)o;
- return date.equals(anotherMMS.getDate());
- }
-
- @Override
- public int compareTo(MMS another) {
- return (int)(date.getTime() - another.getDate().getTime());
- }
-
- private void throwIllegalStateExceptionIfStateIsNotValid() {
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("contactName can't be null"), contactName);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("body can't be null"), body);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("date can't be null"), date);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("messageType can't be null"), messageType);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("subject can't be null"), subject);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("addressType can't be null"), addressType);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("imagePath can't be null"), imagePath);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("audioTextUri can't be null"), audioTextUri);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("imageTextUri can't be null"), imageTextUri);
- ExceptionUtilities.throwRuntimeExceptionIfObjectIsNull(
- new IllegalStateException("audioName can't be null"), audioName);
- }
- }