Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d08b7df5f0 | |
|
|
333cb3fa64 | |
|
|
098db7d2e3 | |
|
|
e1eed0c37f |
|
|
@ -15,6 +15,7 @@ android {
|
|||
|
||||
repositories {
|
||||
maven { url 'https://maven.fabric.io/public' }
|
||||
maven { url "http://dl.bintray.com/touchin/touchin-tools" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
@ -34,7 +35,7 @@ dependencies {
|
|||
}
|
||||
|
||||
compileOnly 'com.facebook.fresco:fresco:1.5.0'
|
||||
compileOnly 'com.bluelinelabs:logansquare:1.3.7'
|
||||
compileOnly 'ru.touchin:logansquare:1.4.1'
|
||||
|
||||
compileOnly 'com.scottyab:aes-crypto:0.0.4'
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ package ru.touchin.templates;
|
|||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorRes;
|
||||
|
|
@ -62,9 +62,14 @@ public abstract class TouchinActivity<TLogic extends Logic> extends ViewControll
|
|||
* @param primaryColorRes Color of application to show in task bar.
|
||||
*/
|
||||
protected void setupTaskDescriptor(@NonNull final String label, @DrawableRes final int iconRes, @ColorRes final int primaryColorRes) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
final ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(label,
|
||||
((BitmapDrawable) ContextCompat.getDrawable(this, iconRes)).getBitmap(),
|
||||
iconRes,
|
||||
ContextCompat.getColor(this, primaryColorRes));
|
||||
setTaskDescription(taskDescription);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
final ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(label,
|
||||
BitmapFactory.decodeResource(getResources(), iconRes),
|
||||
ContextCompat.getColor(this, primaryColorRes));
|
||||
setTaskDescription(taskDescription);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class LoganSquareJodaTimeConverter implements TypeConverter<DateTime> {
|
|||
@Override
|
||||
public DateTime parse(@NonNull final JsonParser jsonParser) throws IOException {
|
||||
final String dateString = jsonParser.getValueAsString();
|
||||
if (dateString == null) {
|
||||
if (dateString == null || dateString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
|
@ -60,9 +60,9 @@ public class LoganSquareJodaTimeConverter implements TypeConverter<DateTime> {
|
|||
@NonNull final JsonGenerator jsonGenerator)
|
||||
throws IOException {
|
||||
if (fieldName != null) {
|
||||
jsonGenerator.writeStringField(fieldName, object != null ? object.toString() : null);
|
||||
jsonGenerator.writeStringField(fieldName, object != null && !object.toString().isEmpty() ? object.toString() : null);
|
||||
} else {
|
||||
jsonGenerator.writeString(object != null ? object.toString() : null);
|
||||
jsonGenerator.writeString(object != null && !object.toString().isEmpty() ? object.toString() : null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,15 @@
|
|||
package ru.touchin.templates.logansquare;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.bluelinelabs.logansquare.ConverterUtils;
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
|
@ -42,7 +44,7 @@ import ru.touchin.templates.retrofit.JsonResponseBodyConverter;
|
|||
|
||||
/**
|
||||
* Created by Gavriil Sitnikov on 2/06/2016.
|
||||
* LoganSquareConverter class to use with {@link Retrofit} to parse and generate models based on Google Jackson library {@link JacksonFactory}.
|
||||
* LoganSquareConverter class to use with {@link Retrofit} to parse and generate models based on Logan Square library.
|
||||
*/
|
||||
public class LoganSquareJsonFactory extends Converter.Factory {
|
||||
|
||||
|
|
@ -63,6 +65,16 @@ public class LoganSquareJsonFactory extends Converter.Factory {
|
|||
return new LoganSquareRequestBodyConverter<>();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Converter<?, String> stringConverter(@NonNull final Type type, @NonNull final Annotation[] annotations, @NonNull final Retrofit retrofit) {
|
||||
if (type instanceof Class && ((Class) type).getSuperclass() == Enum.class) {
|
||||
return new LoganSquareStringEnumConverter<>();
|
||||
} else {
|
||||
return super.stringConverter(type, annotations, retrofit);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoganSquareJsonResponseBodyConverter<T> extends JsonResponseBodyConverter<T> {
|
||||
|
||||
@NonNull
|
||||
|
|
@ -101,11 +113,29 @@ public class LoganSquareJsonFactory extends Converter.Factory {
|
|||
public static class LoganSquareRequestBodyConverter<T> extends JsonRequestBodyConverter<T> {
|
||||
|
||||
@Override
|
||||
protected void writeValueToByteArray(@NonNull final T value, @NonNull final ByteArrayOutputStream byteArrayOutputStream)
|
||||
throws IOException {
|
||||
protected void writeValueToByteArray(@NonNull final T value, @NonNull final ByteArrayOutputStream byteArrayOutputStream) throws IOException {
|
||||
LoganSquare.serialize(value, byteArrayOutputStream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static class LoganSquareStringEnumConverter<T> implements Converter<T, String> {
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings({"unchecked", "TryFinallyCanBeTryWithResources"})
|
||||
@Override
|
||||
public String convert(@NonNull final T value) throws IOException {
|
||||
final StringWriter writer = new StringWriter();
|
||||
try {
|
||||
final JsonGenerator generator = LoganSquare.JSON_FACTORY.createGenerator(writer);
|
||||
LoganSquare.typeConverterFor((Class<T>) value.getClass()).serialize(value, null, false, generator);
|
||||
generator.close();
|
||||
return writer.toString().replaceAll("\"", "");
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue