diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessage.java b/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessage.java index 6fc02ab2..c76fb0e8 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessage.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/FixableMessage.java @@ -24,13 +24,12 @@ package org.solovyev.android.calculator; import android.os.Parcel; import android.os.Parcelable; +import org.solovyev.common.msg.Message; +import org.solovyev.common.msg.MessageType; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.solovyev.common.msg.Message; -import org.solovyev.common.msg.MessageType; - /** * User: serso * Date: 11/17/12 @@ -70,14 +69,8 @@ public class FixableMessage implements Parcelable { public FixableMessage(@Nonnull Message message) { this.message = message.getLocalizedMessage(); - int messageLevel = message.getMessageLevel().getMessageLevel(); - if (messageLevel < MessageType.info.getMessageLevel()) { - this.messageType = MessageType.info; - } else if (messageLevel < MessageType.warning.getMessageLevel()) { - this.messageType = MessageType.warning; - } else { - this.messageType = MessageType.error; - } + final int messageLevel = message.getMessageLevel().getMessageLevel(); + this.messageType = CalculatorMessages.toMessageType(messageLevel); this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode()); } diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/ParcelableDialogData.java b/android-app-core/src/main/java/org/solovyev/android/calculator/ParcelableDialogData.java index 1205883a..38c03794 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/ParcelableDialogData.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/ParcelableDialogData.java @@ -24,13 +24,12 @@ package org.solovyev.android.calculator; import android.os.Parcel; import android.os.Parcelable; +import org.solovyev.common.msg.MessageLevel; +import org.solovyev.common.msg.MessageType; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.solovyev.common.msg.MessageLevel; -import org.solovyev.common.msg.MessageType; - /** * User: serso * Date: 1/20/13 @@ -93,7 +92,7 @@ public final class ParcelableDialogData implements DialogData, Parcelable { @Nonnull public static ParcelableDialogData fromParcel(@Nonnull Parcel in) { final String message = in.readString(); - final MessageType messageType = MessageType.values()[in.readInt()]; + final MessageType messageType = CalculatorMessages.toMessageType(in.readInt()); final String title = in.readString(); return wrap(StringDialogData.newInstance(message, messageType, title)); } diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java index c2de3808..1e8cb14e 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorMessages.java @@ -31,6 +31,10 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import static org.solovyev.common.msg.MessageType.error; +import static org.solovyev.common.msg.MessageType.info; +import static org.solovyev.common.msg.MessageType.warning; + /** * User: serso * Date: 9/20/12 @@ -94,6 +98,17 @@ public final class CalculatorMessages { @Nonnull public static CalculatorMessage newErrorMessage(@Nonnull String messageCode, @Nullable Object... parameters) { - return new CalculatorMessage(messageCode, MessageType.error, parameters); + return new CalculatorMessage(messageCode, error, parameters); + } + + @Nonnull + static MessageType toMessageType(int messageLevel) { + if (messageLevel < info.getMessageLevel()) { + return info; + } else if (messageLevel < warning.getMessageLevel()) { + return warning; + } + + return error; } }