Skip to content

Commit

Permalink
Merge pull request #30 from jogrimst/master
Browse files Browse the repository at this point in the history
greenDAO 3.2.0
  • Loading branch information
literacyapp authored Dec 11, 2016
2 parents 121b027 + 42e6b6d commit 97f1883
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 158 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'

android {
compileSdkVersion 23
Expand Down Expand Up @@ -34,11 +35,10 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'org.greenrobot:greendao-gradle-plugin:3.0.0'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
}
}

apply plugin: 'org.greenrobot.greendao'
greendao {
schemaVersion android.defaultConfig.versionCode
targetGenDir = new File('app/src/main/java')
Expand All @@ -49,5 +49,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'org.greenrobot:greendao:3.0.1'
compile 'org.greenrobot:greendao:3.2.0'
}
44 changes: 22 additions & 22 deletions app/src/main/java/org/literacyapp/chat/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
import android.widget.ImageButton;
import android.widget.ListView;

import org.literacyapp.chat.dao.TextMessageDao;
import org.literacyapp.chat.model.TextMessage;
import org.literacyapp.chat.dao.MessageDao;
import org.literacyapp.chat.model.Message;
import org.literacyapp.chat.util.DeviceInfoHelper;

import java.util.Calendar;
import java.util.List;

public class ChatActivity extends Activity {

private TextMessageDao textMessageDao;
private MessageDao messageDao;

private List<TextMessage> textMessages;
private List<Message> messages;

private ArrayAdapter arrayAdapter;

private ListView mListPreviousMessages;

private EditText mTextMessage;
private EditText message;

private ImageButton mButtonSend;

Expand All @@ -41,10 +41,10 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_chat);

textMessageDao = ((ChatApplication) getApplication()).getDaoSession().getTextMessageDao();
messageDao = ((ChatApplication) getApplication()).getDaoSession().getMessageDao();

mListPreviousMessages = (ListView) findViewById(R.id.listPreviousMessages);
mTextMessage = (EditText) findViewById(R.id.textMessage);
message = (EditText) findViewById(R.id.message);
mButtonSend = (ImageButton) findViewById(R.id.buttonSend);

}
Expand All @@ -57,15 +57,15 @@ protected void onStart() {
// Load messages sent within the last 24 hours
Calendar calendar24HoursAgo = Calendar.getInstance();
calendar24HoursAgo.add(Calendar.HOUR_OF_DAY, -24);
textMessages = textMessageDao.queryBuilder()
.where(TextMessageDao.Properties.TimeSent.gt(calendar24HoursAgo.getTimeInMillis()))
messages = messageDao.queryBuilder()
.where(MessageDao.Properties.TimeSent.gt(calendar24HoursAgo.getTimeInMillis()))
.list();
Log.i(getClass().getName(), "textMessages.size(): " + textMessages.size());
Log.i(getClass().getName(), "messages.size(): " + messages.size());

arrayAdapter = new MessageListArrayAdapter(getApplicationContext(), textMessages);
arrayAdapter = new MessageListArrayAdapter(getApplicationContext(), messages);
mListPreviousMessages.setAdapter(arrayAdapter);

mTextMessage.addTextChangedListener(new TextWatcher() {
message.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

Expand Down Expand Up @@ -93,24 +93,24 @@ public void afterTextChanged(Editable editable) {
public void onClick(View view) {
Log.i(getClass().getName(), "mButtonSend onClick");

String text = mTextMessage.getText().toString();
String text = message.getText().toString();
Log.i(getClass().getName(), "text: " + text);

// Check if EditText is empty
if(!TextUtils.isEmpty(text)){
TextMessage textMessage = new TextMessage();
textMessage.setDeviceId(DeviceInfoHelper.getDeviceId(getApplicationContext()));
textMessage.setTimeSent(Calendar.getInstance());
textMessage.setText(text);
Message message = new Message();
message.setDeviceId(DeviceInfoHelper.getDeviceId(getApplicationContext()));
message.setTimeSent(Calendar.getInstance());
message.setText(text);

// Store in database
textMessageDao.insert(textMessage);
messageDao.insert(message);

// Add to UI
addToMessageListAndRefresh(textMessage);
addToMessageListAndRefresh(message);

// Reset input field
mTextMessage.setText("");
ChatActivity.this.message.setText("");

} else {
mButtonSend.setVisibility(View.GONE);
Expand All @@ -121,8 +121,8 @@ public void onClick(View view) {
});
}

private void addToMessageListAndRefresh(TextMessage textMessage) {
textMessages.add(textMessage);
private void addToMessageListAndRefresh(Message message) {
messages.add(message);
refreshMessageList();
}

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/literacyapp/chat/ChatApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public void onCreate() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int oldVersionCode = sharedPreferences.getInt(PREF_APP_VERSION_CODE, 0);
int newVersionCode = VersionHelper.getAppVersionCode(getApplicationContext());
if ((oldVersionCode > 0) && (oldVersionCode < newVersionCode)) {
if (oldVersionCode == 0) {
sharedPreferences.edit().putInt(PREF_APP_VERSION_CODE, newVersionCode).commit();
oldVersionCode = newVersionCode;
}
if (oldVersionCode < newVersionCode) {
Log.i(getClass().getName(), "Upgrading application from version " + oldVersionCode + " to " + newVersionCode);
// if (newVersionCode == ???) {
// // Put relevant tasks required for upgrading here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
import android.widget.ImageView;
import android.widget.TextView;

import org.literacyapp.chat.model.TextMessage;
import org.literacyapp.chat.model.Message;

import java.util.List;

public class MessageListArrayAdapter extends ArrayAdapter<TextMessage> {
public class MessageListArrayAdapter extends ArrayAdapter<Message> {

private Context context;

private List<TextMessage> textMessages;
private List<Message> messages;

static class ViewHolder {
ImageView imageViewAvatar;
TextView textViewListItem;
}

public MessageListArrayAdapter(Context context, List<TextMessage> textMessages) {
super(context, R.layout.activity_chat_list_item, textMessages);
public MessageListArrayAdapter(Context context, List<Message> messages) {
super(context, R.layout.activity_chat_list_item, messages);
Log.i(getClass().getName(), "MessageListArrayAdapter");

this.context = context;
this.textMessages = textMessages;
this.messages = messages;
}

@Override
Expand All @@ -46,10 +46,10 @@ public View getView(int position, View convertView, ViewGroup parent) {
listItem.setTag(viewHolder);
}

TextMessage textMessage = textMessages.get(position);
Message message = messages.get(position);

ViewHolder viewHolder = (ViewHolder) listItem.getTag();
viewHolder.textViewListItem.setText(textMessage.getText());
viewHolder.textViewListItem.setText(message.getText());

return listItem;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/literacyapp/chat/dao/DaoMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class DaoMaster extends AbstractDaoMaster {

/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
TextMessageDao.createTable(db, ifNotExists);
MessageDao.createTable(db, ifNotExists);
}

/** Drops underlying database table using DAOs. */
public static void dropAllTables(Database db, boolean ifExists) {
TextMessageDao.dropTable(db, ifExists);
MessageDao.dropTable(db, ifExists);
}

/**
Expand All @@ -45,7 +45,7 @@ public DaoMaster(SQLiteDatabase db) {

public DaoMaster(Database db) {
super(db, SCHEMA_VERSION);
registerDaoClass(TextMessageDao.class);
registerDaoClass(MessageDao.class);
}

public DaoSession newSession() {
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/org/literacyapp/chat/dao/DaoSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;

import org.literacyapp.chat.model.TextMessage;
import org.literacyapp.chat.model.Message;

import org.literacyapp.chat.dao.TextMessageDao;
import org.literacyapp.chat.dao.MessageDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

Expand All @@ -21,28 +21,28 @@
*/
public class DaoSession extends AbstractDaoSession {

private final DaoConfig textMessageDaoConfig;
private final DaoConfig messageDaoConfig;

private final TextMessageDao textMessageDao;
private final MessageDao messageDao;

public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
daoConfigMap) {
super(db);

textMessageDaoConfig = daoConfigMap.get(TextMessageDao.class).clone();
textMessageDaoConfig.initIdentityScope(type);
messageDaoConfig = daoConfigMap.get(MessageDao.class).clone();
messageDaoConfig.initIdentityScope(type);

textMessageDao = new TextMessageDao(textMessageDaoConfig, this);
messageDao = new MessageDao(messageDaoConfig, this);

registerDao(TextMessage.class, textMessageDao);
registerDao(Message.class, messageDao);
}

public void clear() {
textMessageDaoConfig.getIdentityScope().clear();
messageDaoConfig.clearIdentityScope();
}

public TextMessageDao getTextMessageDao() {
return textMessageDao;
public MessageDao getMessageDao() {
return messageDao;
}

}
Loading

0 comments on commit 97f1883

Please sign in to comment.