diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 8f8acc335..2d167cee7 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -593,28 +593,25 @@ public class Helper { * @return Date */ public static Date mstStringToDate(Context context, String date) throws ParseException { - Locale userLocale; - if (date == null ) + if (date == null) return null; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - userLocale = context.getResources().getConfiguration().getLocales().get(0); - } else { - //noinspection deprecation - userLocale = context.getResources().getConfiguration().locale; - } + String STRING_DATE_FORMAT; - if( !date.contains("+")) + Locale local = Locale.getDefault(); + if (!date.contains("+")) { STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; - else //GNU date format + } else{ //GNU date format STRING_DATE_FORMAT = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, userLocale); + local = Locale.ENGLISH; + } + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, local); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); simpleDateFormat.setLenient(true); try { return simpleDateFormat.parse(date); }catch (Exception e){ String newdate = date.split("\\+")[0].trim(); - simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", userLocale); + simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", local); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); simpleDateFormat.setLenient(true); return simpleDateFormat.parse(newdate); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java index 3f3837eb3..058fc7caf 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java @@ -20,6 +20,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList; +import java.util.Date; import java.util.List; import fr.gouv.etalab.mastodon.client.Entities.Account; @@ -51,7 +52,10 @@ public class AccountDAO { public boolean insertAccount(Account account) { ContentValues values = new ContentValues(); - + if( account.getCreated_at() == null) + account.setCreated_at(new Date()); + if( account.getNote() == null) + account.setNote(""); values.put(Sqlite.COL_USER_ID, account.getId()); values.put(Sqlite.COL_USERNAME, account.getUsername()); values.put(Sqlite.COL_ACCT, account.getAcct()); @@ -97,7 +101,10 @@ public class AccountDAO { public int updateAccount(Account account) { ContentValues values = new ContentValues(); - + if( account.getNote() == null) + account.setNote(""); + if( account.getCreated_at() == null) + account.setCreated_at(new Date()); values.put(Sqlite.COL_ACCT, account.getAcct()); values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplay_name()); values.put(Sqlite.COL_LOCKED,account.isLocked());