// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static Date getDateFromData(String key, Map<String, Object> data){
//     Date date = new Date();
//     String strDate = null;
//     long timeSince1970 = System.currentTimeMillis();
//     try{
//         timeSince1970 = (long) data.get(key);
//         date = new Date(timeSince1970);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
// 
//     if (date == null) date = new Date();
// 
//     return date;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static int getIntFromData(String key, Map<String, Object> data){
//     Integer value = 0;
//     try{
//         String strValue = data.get(key).toString();
//         value = Integer.parseInt(strValue);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     if(value == null) value = 0;
//     return value;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static String getStringFromData(String key, Map<String, Object> data){
//     String value = "?";
//     try{
//         value = (String) data.get(key);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     return  value;
// }


import android.net.Uri;
import java.io.File;
import java.util.Date;
import java.util.Map;
import static com.raffler.app.models.ChatType.PERSONAL;
import static com.raffler.app.models.MessageStatus.SENDING;
import static com.raffler.app.models.MessageType.TEXT;
import static com.raffler.app.models.UserType.OTHER;
import static com.raffler.app.models.UserType.SELF;
import static com.raffler.app.utils.Util.getDateFromData;
import static com.raffler.app.utils.Util.getIntFromData;
import static com.raffler.app.utils.Util.getStringFromData;
package com.raffler.app.models;





/**
 * Created by Ghost on 16/8/2017.
 */

public class Message {

    private String idx, uid, text, resource;
    private ChatType chatType = PERSONAL;
    private MessageType messageType = TEXT;
    private MessageStatus status = SENDING;
    private UserType userType = SELF;
    private String senderId, senderName, senderPhoto;
    private Date createdAt, updatedAt;
    private Uri attachFilePath;

    public Message(String userId, Map<String, Object> data){
        this.uid = userId;
        this.updateValue(data);
    }

    public void updateValue(Map<String, Object> data){
        this.idx = getStringFromData("idx", data);
        this.text = getStringFromData("text", data);
        this.resource = getStringFromData("resource", data);
        this.senderId = getStringFromData("senderId", data);
        this.senderName = getStringFromData("senderName", data);
        this.senderPhoto = getStringFromData("senderPhoto", data);
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static Date getDateFromData(String key, Map<String, Object> data){
//     Date date = new Date();
//     String strDate = null;
//     long timeSince1970 = System.currentTimeMillis();
//     try{
//         timeSince1970 = (long) data.get(key);
//         date = new Date(timeSince1970);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
// 
//     if (date == null) date = new Date();
// 
//     return date;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static int getIntFromData(String key, Map<String, Object> data){
//     Integer value = 0;
//     try{
//         String strValue = data.get(key).toString();
//         value = Integer.parseInt(strValue);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     if(value == null) value = 0;
//     return value;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static String getStringFromData(String key, Map<String, Object> data){
//     String value = "?";
//     try{
//         value = (String) data.get(key);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     return  value;
// }


// Path: app/src/main/java/com/raffler/app/models/Message.java
import android.net.Uri;
import java.io.File;
import java.util.Date;
import java.util.Map;
import static com.raffler.app.models.ChatType.PERSONAL;
import static com.raffler.app.models.MessageStatus.SENDING;
import static com.raffler.app.models.MessageType.TEXT;
import static com.raffler.app.models.UserType.OTHER;
import static com.raffler.app.models.UserType.SELF;
import static com.raffler.app.utils.Util.getDateFromData;
import static com.raffler.app.utils.Util.getIntFromData;
import static com.raffler.app.utils.Util.getStringFromData;

package com.raffler.app.models;





/**
 * Created by Ghost on 16/8/2017.
 */

public class Message {

    private String idx, uid, text, resource;
    private ChatType chatType = PERSONAL;
    private MessageType messageType = TEXT;
    private MessageStatus status = SENDING;
    private UserType userType = SELF;
    private String senderId, senderName, senderPhoto;
    private Date createdAt, updatedAt;
    private Uri attachFilePath;

    public Message(String userId, Map<String, Object> data){
        this.uid = userId;
        this.updateValue(data);
    }

    public void updateValue(Map<String, Object> data){
        this.idx = getStringFromData("idx", data);
        this.text = getStringFromData("text", data);
        this.resource = getStringFromData("resource", data);
        this.senderId = getStringFromData("senderId", data);
        this.senderName = getStringFromData("senderName", data);
        this.senderPhoto = getStringFromData("senderPhoto", data);
        this.chatType = ChatType.values()[getIntFromData("chatType", data)];