Kotlin: more kotlin migration.

tmp
Tom Hacohen 5 years ago
parent 093eee6409
commit f0a0717541

@ -201,7 +201,7 @@ public class JournalModel {
@Override
public SyncEntry convertToMapped(Class<? extends SyncEntry> type, String value) {
return value == null ? null : SyncEntry.fromJson(value);
return value == null ? null : SyncEntry.Companion.fromJson(value);
}
}
}

@ -1,62 +0,0 @@
package com.etesync.syncadapter.model;
import com.etesync.syncadapter.GsonHelper;
import com.etesync.syncadapter.journalmanager.Crypto;
import com.etesync.syncadapter.journalmanager.JournalEntryManager;
import java.io.Serializable;
public class SyncEntry implements Serializable {
private String content;
private Actions action;
public String getContent() {
return content;
}
public Actions getAction() {
return action;
}
public enum Actions {
ADD("ADD"),
CHANGE("CHANGE"),
DELETE("DELETE");
private final String text;
Actions(final String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
@SuppressWarnings("unused")
private SyncEntry() {
}
public SyncEntry(String content, Actions action) {
this.content = content;
this.action = action;
}
public boolean isAction(Actions action) {
return this.action.equals(action);
}
public static SyncEntry fromJournalEntry(Crypto.CryptoManager crypto, JournalEntryManager.Entry entry) {
return fromJson(entry.getContent(crypto));
}
static SyncEntry fromJson(String json) {
return GsonHelper.gson.fromJson(json, SyncEntry.class);
}
public String toJson() {
return GsonHelper.gson.toJson(this, this.getClass());
}
}

@ -0,0 +1,52 @@
package com.etesync.syncadapter.model
import com.etesync.syncadapter.GsonHelper
import com.etesync.syncadapter.journalmanager.Crypto
import com.etesync.syncadapter.journalmanager.JournalEntryManager
import java.io.Serializable
class SyncEntry : Serializable {
val content: String
val action: Actions
enum class Actions constructor(private val text: String) {
ADD("ADD"),
CHANGE("CHANGE"),
DELETE("DELETE");
override fun toString(): String {
return text
}
}
private constructor() {
this.content = ""
this.action = Actions.ADD
}
constructor(content: String, action: Actions) {
this.content = content
this.action = action
}
fun isAction(action: Actions): Boolean {
return this.action == action
}
fun toJson(): String {
return GsonHelper.gson.toJson(this, this.javaClass)
}
companion object {
@JvmStatic
fun fromJournalEntry(crypto: Crypto.CryptoManager, entry: JournalEntryManager.Entry): SyncEntry {
return fromJson(entry.getContent(crypto))
}
@JvmStatic
fun fromJson(json: String): SyncEntry {
return GsonHelper.gson.fromJson(json, SyncEntry::class.java)
}
}
}
Loading…
Cancel
Save