// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactsContract {
//     public static final String TABLE_NAME = "contacts";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 2;
//     public static final int URI_CODE = 3;
// 
//     public static class ContactEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String UUID = "uuid";
//         public static final String NAME = "name";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String UUID = "uuid";
//     public static final String NAME = "name";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessagesContract {
//     public static final String TABLE_NAME = "messages";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 0;
//     public static final int URI_CODE = 1;
// 
//     public static class MessageEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String SENDER_UUID = "sender_uuid";
//         public static final String SENDER_NAME = "sender_name";
//         public static final String MESSAGE = "message";
//         public static final String RECEIVED_TIME = "received_time";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessageEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String SENDER_UUID = "sender_uuid";
//     public static final String SENDER_NAME = "sender_name";
//     public static final String MESSAGE = "message";
//     public static final String RECEIVED_TIME = "received_time";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// public interface QueryContactsUuidsCallback {
// 
//     void onComplete(@NonNull final Set<String> uuids);
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java
// public final class Contact {
// 
//     @NonNull
//     private final String name;
// 
//     @NonNull
//     private final String uuid;
// 
//     public Contact(@NonNull final String name, @NonNull final String uuid) {
//         this.name = name;
//         this.uuid = uuid;
//     }
// 
//     @NonNull
//     public String getName() {
//         return name;
//     }
// 
//     @NonNull
//     public String getUuid() {
//         return uuid;
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java
// public final class Message {
// 
//     @NonNull
//     private final String senderUuid;
// 
//     @NonNull
//     private final String messageText;
// 
//     private final long receivedTime;
// 
//     public Message(@NonNull final String senderUuid,
//                    @NonNull final String messageText,
//                    final long receivedTime) {
//         this.senderUuid = senderUuid;
//         this.messageText = messageText;
//         this.receivedTime = receivedTime;
//     }
// 
//     @NonNull
//     public String getSenderUuid() {
//         return senderUuid;
//     }
// 
//     @NonNull
//     public String getMessageText() {
//         return messageText;
//     }
// 
//     public long getReceivedTime() {
//         return receivedTime;
//     }
// }


import org.onepf.pushchat.model.db.Message;
import java.util.HashSet;
import java.util.Set;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry;
import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback;
import org.onepf.pushchat.model.db.Contact;
                        null,
                        ContactsContract.TABLE_URI,
                        new String[]{ContactEntry.NAME},
                        ContactEntry.UUID + "=?",
                        new String[]{message.getSenderUuid()},
                        null
                );
    }

    private QueryContactNameQueryHandler.QueryContactNameCallback queryContactNameCallback(
            @NonNull final Message message
    ) {
        return new QueryContactNameQueryHandler.QueryContactNameCallback() {
            @Override
            public void onComplete(@NonNull final String name) {
                final ContentValues contentValues = new ContentValues();
                contentValues.put(MessageEntry.SENDER_UUID, message.getSenderUuid());
                contentValues.put(MessageEntry.SENDER_NAME, name);
                contentValues.put(MessageEntry.MESSAGE, message.getMessageText());
                contentValues.put(MessageEntry.RECEIVED_TIME, message.getReceivedTime());

                asyncQueryHandler.startInsert(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, contentValues);
            }
        };
    }

    public void deleteMessages() {
        asyncQueryHandler.startDelete(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, null, null);
    }

// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactsContract {
//     public static final String TABLE_NAME = "contacts";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 2;
//     public static final int URI_CODE = 3;
// 
//     public static class ContactEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String UUID = "uuid";
//         public static final String NAME = "name";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String UUID = "uuid";
//     public static final String NAME = "name";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessagesContract {
//     public static final String TABLE_NAME = "messages";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 0;
//     public static final int URI_CODE = 1;
// 
//     public static class MessageEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String SENDER_UUID = "sender_uuid";
//         public static final String SENDER_NAME = "sender_name";
//         public static final String MESSAGE = "message";
//         public static final String RECEIVED_TIME = "received_time";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessageEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String SENDER_UUID = "sender_uuid";
//     public static final String SENDER_NAME = "sender_name";
//     public static final String MESSAGE = "message";
//     public static final String RECEIVED_TIME = "received_time";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// public interface QueryContactsUuidsCallback {
// 
//     void onComplete(@NonNull final Set<String> uuids);
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java
// public final class Contact {
// 
//     @NonNull
//     private final String name;
// 
//     @NonNull
//     private final String uuid;
// 
//     public Contact(@NonNull final String name, @NonNull final String uuid) {
//         this.name = name;
//         this.uuid = uuid;
//     }
// 
//     @NonNull
//     public String getName() {
//         return name;
//     }
// 
//     @NonNull
//     public String getUuid() {
//         return uuid;
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java
// public final class Message {
// 
//     @NonNull
//     private final String senderUuid;
// 
//     @NonNull
//     private final String messageText;
// 
//     private final long receivedTime;
// 
//     public Message(@NonNull final String senderUuid,
//                    @NonNull final String messageText,
//                    final long receivedTime) {
//         this.senderUuid = senderUuid;
//         this.messageText = messageText;
//         this.receivedTime = receivedTime;
//     }
// 
//     @NonNull
//     public String getSenderUuid() {
//         return senderUuid;
//     }
// 
//     @NonNull
//     public String getMessageText() {
//         return messageText;
//     }
// 
//     public long getReceivedTime() {
//         return receivedTime;
//     }
// }


// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
import org.onepf.pushchat.model.db.Message;
import java.util.HashSet;
import java.util.Set;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry;
import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback;
import org.onepf.pushchat.model.db.Contact;

                        null,
                        ContactsContract.TABLE_URI,
                        new String[]{ContactEntry.NAME},
                        ContactEntry.UUID + "=?",
                        new String[]{message.getSenderUuid()},
                        null
                );
    }

    private QueryContactNameQueryHandler.QueryContactNameCallback queryContactNameCallback(
            @NonNull final Message message
    ) {
        return new QueryContactNameQueryHandler.QueryContactNameCallback() {
            @Override
            public void onComplete(@NonNull final String name) {
                final ContentValues contentValues = new ContentValues();
                contentValues.put(MessageEntry.SENDER_UUID, message.getSenderUuid());
                contentValues.put(MessageEntry.SENDER_NAME, name);
                contentValues.put(MessageEntry.MESSAGE, message.getMessageText());
                contentValues.put(MessageEntry.RECEIVED_TIME, message.getReceivedTime());

                asyncQueryHandler.startInsert(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, contentValues);
            }
        };
    }

    public void deleteMessages() {
        asyncQueryHandler.startDelete(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, null, null);
    }

    public void addContact(@NonNull final Contact contact) {