mirror of https://github.com/tasks/tasks
Refactored ClientToServer message to be an abstract class holding information common to all ClientToServer messages
parent
189acd1367
commit
42ef792707
@ -1,7 +1,41 @@
|
||||
package com.todoroo.astrid.actfm.sync.messages;
|
||||
|
||||
public interface ClientToServerMessage {
|
||||
import com.todoroo.astrid.dao.RemoteModelDao;
|
||||
import com.todoroo.astrid.data.RemoteModel;
|
||||
|
||||
public void sendMessage();
|
||||
public abstract class ClientToServerMessage<TYPE extends RemoteModel> {
|
||||
|
||||
protected final Class<TYPE> modelClass;
|
||||
protected final long id;
|
||||
protected final String uuid;
|
||||
protected final long pushedAt;
|
||||
|
||||
public ClientToServerMessage(long id, Class<TYPE> modelClass, RemoteModelDao<TYPE> modelDao) {
|
||||
this.id = id;
|
||||
this.modelClass = modelClass;
|
||||
|
||||
TYPE entity = getEntity(id, modelDao);
|
||||
if (entity == null) {
|
||||
this.uuid = RemoteModel.NO_UUID;
|
||||
this.pushedAt = 0;
|
||||
} else {
|
||||
this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY);
|
||||
this.pushedAt = entity.getValue(RemoteModel.PUSHED_AT_PROPERTY);
|
||||
}
|
||||
}
|
||||
|
||||
private TYPE getEntity(long localId, RemoteModelDao<TYPE> modelDao) {
|
||||
return modelDao.fetch(localId, RemoteModel.UUID_PROPERTY, RemoteModel.PUSHED_AT_PROPERTY);
|
||||
}
|
||||
|
||||
public final String getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public final long getPushedAt() {
|
||||
return pushedAt;
|
||||
}
|
||||
|
||||
public abstract void sendMessage();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue