using LoganSquare
This commit is contained in:
parent
e2f600ad0e
commit
fbe9163e2a
|
@ -6,9 +6,9 @@ import android.support.annotation.CallSuper;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.bluelinelabs.logansquare.LoganSquare;
|
||||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||||
|
|
||||||
import org.mariotaku.commons.logansquare.LoganSquareMapperFinder;
|
|
||||||
import org.mariotaku.twidere.annotation.CustomTabType;
|
import org.mariotaku.twidere.annotation.CustomTabType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,10 +27,10 @@ public abstract class TabExtras implements Parcelable {
|
||||||
public static TabExtras parse(@NonNull @CustomTabType String type, String json) throws IOException {
|
public static TabExtras parse(@NonNull @CustomTabType String type, String json) throws IOException {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CustomTabType.NOTIFICATIONS_TIMELINE: {
|
case CustomTabType.NOTIFICATIONS_TIMELINE: {
|
||||||
return LoganSquareMapperFinder.mapperFor(InteractionsTabExtras.class).parse(json);
|
return LoganSquare.parse(json, InteractionsTabExtras.class);
|
||||||
}
|
}
|
||||||
case CustomTabType.HOME_TIMELINE: {
|
case CustomTabType.HOME_TIMELINE: {
|
||||||
return LoganSquareMapperFinder.mapperFor(HomeTabExtras.class).parse(json);
|
return LoganSquare.parse(json, HomeTabExtras.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.bluelinelabs.logansquare.JsonMapper;
|
import com.bluelinelabs.logansquare.LoganSquare;
|
||||||
|
|
||||||
import org.mariotaku.library.objectcursor.converter.CursorFieldConverter;
|
import org.mariotaku.library.objectcursor.converter.CursorFieldConverter;
|
||||||
import org.mariotaku.twidere.model.Draft;
|
import org.mariotaku.twidere.model.Draft;
|
||||||
|
@ -12,7 +12,6 @@ import org.mariotaku.twidere.model.draft.ActionExtra;
|
||||||
import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtra;
|
import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtra;
|
||||||
import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra;
|
import org.mariotaku.twidere.model.draft.UpdateStatusActionExtra;
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts;
|
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts;
|
||||||
import org.mariotaku.commons.logansquare.LoganSquareMapperFinder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
@ -22,46 +21,32 @@ import java.lang.reflect.ParameterizedType;
|
||||||
*/
|
*/
|
||||||
public class DraftExtrasConverter implements CursorFieldConverter<ActionExtra> {
|
public class DraftExtrasConverter implements CursorFieldConverter<ActionExtra> {
|
||||||
@Override
|
@Override
|
||||||
public ActionExtra parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) {
|
public ActionExtra parseField(Cursor cursor, int columnIndex, ParameterizedType fieldType) throws IOException {
|
||||||
final String actionType = cursor.getString(cursor.getColumnIndex(Drafts.ACTION_TYPE));
|
final String actionType = cursor.getString(cursor.getColumnIndex(Drafts.ACTION_TYPE));
|
||||||
if (TextUtils.isEmpty(actionType)) return null;
|
if (TextUtils.isEmpty(actionType)) return null;
|
||||||
try {
|
switch (actionType) {
|
||||||
switch (actionType) {
|
case "0":
|
||||||
case "0":
|
case "1":
|
||||||
case "1":
|
case Draft.Action.UPDATE_STATUS:
|
||||||
case Draft.Action.UPDATE_STATUS:
|
case Draft.Action.REPLY:
|
||||||
case Draft.Action.REPLY:
|
case Draft.Action.QUOTE: {
|
||||||
case Draft.Action.QUOTE: {
|
final String string = cursor.getString(columnIndex);
|
||||||
final String string = cursor.getString(columnIndex);
|
if (TextUtils.isEmpty(string)) return null;
|
||||||
if (TextUtils.isEmpty(string)) return null;
|
return LoganSquare.parse(string, UpdateStatusActionExtra.class);
|
||||||
final JsonMapper<UpdateStatusActionExtra> mapper = LoganSquareMapperFinder
|
}
|
||||||
.mapperFor(UpdateStatusActionExtra.class);
|
case "2":
|
||||||
return mapper.parse(string);
|
case Draft.Action.SEND_DIRECT_MESSAGE: {
|
||||||
}
|
final String string = cursor.getString(columnIndex);
|
||||||
case "2":
|
if (TextUtils.isEmpty(string)) return null;
|
||||||
case Draft.Action.SEND_DIRECT_MESSAGE: {
|
return LoganSquare.parse(string, SendDirectMessageActionExtra.class);
|
||||||
final String string = cursor.getString(columnIndex);
|
|
||||||
if (TextUtils.isEmpty(string)) return null;
|
|
||||||
final JsonMapper<SendDirectMessageActionExtra> mapper = LoganSquareMapperFinder
|
|
||||||
.mapperFor(SendDirectMessageActionExtra.class);
|
|
||||||
return mapper.parse(string);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeField(ContentValues values, ActionExtra object, String columnName, ParameterizedType fieldType) {
|
public void writeField(ContentValues values, ActionExtra object, String columnName, ParameterizedType fieldType) throws IOException {
|
||||||
if (object == null) return;
|
if (object == null) return;
|
||||||
try {
|
values.put(columnName, LoganSquare.serialize(object));
|
||||||
//noinspection unchecked
|
|
||||||
final JsonMapper<ActionExtra> mapper = (JsonMapper<ActionExtra>) LoganSquareMapperFinder.mapperFor(object.getClass());
|
|
||||||
values.put(columnName, mapper.serialize(object));
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue