implementata libreria compatibilità LocalDate
This commit is contained in:
parent
8aad7337bf
commit
79ec6430f6
@ -41,6 +41,7 @@ android {
|
|||||||
versionName appVersionName
|
versionName appVersionName
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
signingConfig signingConfigs.release
|
signingConfig signingConfigs.release
|
||||||
|
multiDexEnabled true
|
||||||
|
|
||||||
javaCompileOptions {
|
javaCompileOptions {
|
||||||
annotationProcessorOptions {
|
annotationProcessorOptions {
|
||||||
@ -66,7 +67,7 @@ android {
|
|||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_11
|
sourceCompatibility JavaVersion.VERSION_11
|
||||||
targetCompatibility JavaVersion.VERSION_11
|
targetCompatibility JavaVersion.VERSION_11
|
||||||
//coreLibraryDesugaringEnabled true
|
coreLibraryDesugaringEnabled true
|
||||||
}
|
}
|
||||||
|
|
||||||
productFlavors {
|
productFlavors {
|
||||||
@ -115,7 +116,7 @@ dependencies {
|
|||||||
implementation 'com.google.android.gms:play-services-basement:18.1.0'
|
implementation 'com.google.android.gms:play-services-basement:18.1.0'
|
||||||
|
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'com.google.android.material:material:1.8.0'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
@ -188,7 +189,7 @@ dependencies {
|
|||||||
// RxJava is also required.
|
// RxJava is also required.
|
||||||
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
|
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
|
||||||
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
|
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
|
||||||
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package it.integry.integrywmsnative.core.rest;
|
package it.integry.integrywmsnative.core.rest;
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
@ -62,11 +60,14 @@ public class RESTBuilder {
|
|||||||
String endpoint = "http://" + host + ":" + port + "/" + (addEmsApi ? "ems-api/" : "");
|
String endpoint = "http://" + host + ":" + port + "/" + (addEmsApi ? "ems-api/" : "");
|
||||||
|
|
||||||
|
|
||||||
GsonBuilder builder = new GsonBuilder().setDateFormat("dd/MM/yyyy HH:mm:ss").excludeFieldsWithModifiers(Modifier.TRANSIENT);
|
Gson gson = new GsonBuilder()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
.setDateFormat("dd/MM/yyyy HH:mm:ss")
|
||||||
builder.registerTypeAdapter(LocalDate.class, new LocalDateDeserializer()).registerTypeAdapter(LocalDate.class, new LocalDateSerializer()).registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer());
|
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||||
}
|
.registerTypeAdapter(LocalDate.class, new LocalDateDeserializer())
|
||||||
Gson gson = builder.create();
|
.registerTypeAdapter(LocalDate.class, new LocalDateSerializer())
|
||||||
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer())
|
||||||
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer())
|
||||||
|
.create();
|
||||||
|
|
||||||
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(endpoint).client(client).build();
|
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(endpoint).client(client).build();
|
||||||
|
|
||||||
|
|||||||
@ -103,8 +103,7 @@ public class UtilityDate {
|
|||||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
return sdf.format(dateToFormat);
|
return sdf.format(dateToFormat);
|
||||||
}
|
} else return null;
|
||||||
else return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -131,8 +130,6 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String formatDate(LocalDate dateToFormat, String format) {
|
public static String formatDate(LocalDate dateToFormat, String format) {
|
||||||
if (dateToFormat != null) {
|
if (dateToFormat != null) {
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||||
@ -185,7 +182,6 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static LocalDate getNow() {
|
public static LocalDate getNow() {
|
||||||
return Instant.now()
|
return Instant.now()
|
||||||
.atZone(currentZone)
|
.atZone(currentZone)
|
||||||
@ -197,6 +193,7 @@ public class UtilityDate {
|
|||||||
.atZone(currentZone)
|
.atZone(currentZone)
|
||||||
.toLocalDateTime();
|
.toLocalDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalDate timeToLocalDate(long time, @Nullable String timezone) {
|
public static LocalDate timeToLocalDate(long time, @Nullable String timezone) {
|
||||||
return Instant.ofEpochSecond(time)
|
return Instant.ofEpochSecond(time)
|
||||||
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
||||||
@ -210,7 +207,6 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static long localDateTimeToTime(LocalDateTime localDateTime, @Nullable String timezone) {
|
public static long localDateTimeToTime(LocalDateTime localDateTime, @Nullable String timezone) {
|
||||||
return localDateTime
|
return localDateTime
|
||||||
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user