diff --git a/app/build.gradle b/app/build.gradle
index 477e55036..0f0b3819f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,8 +7,8 @@ android {
applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15
targetSdkVersion 28
- versionCode 193
- versionName "1.31.1"
+ versionCode 194
+ versionName "1.32.0-beta-1"
}
flavorDimensions "default"
buildTypes {
@@ -45,7 +45,7 @@ allprojects {
ext.supportLibraryVersion = '28.0.0'
ext.glideLibraryVersion = '4.8.0'
ext.conscryptLibraryVersion = '1.3.0'
-ext.evernoteLibraryVersion = '1.3.0-alpha08'
+ext.evernoteLibraryVersion = '1.3.0-alpha09'
ext.gsonLibraryVersion = '2.8.2'
ext.guavaLibraryVersion = '24.1-android'
ext.photoViewLibraryVersion = '2.0.0'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5935d25ea..5f97632e6 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -42,9 +42,6 @@
-
. */
import android.content.Context;
-import android.content.Intent;
import android.content.SharedPreferences;
+import android.database.sqlite.SQLiteDatabase;
import org.json.JSONArray;
import org.json.JSONException;
@@ -57,7 +57,8 @@ import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.Tag;
import fr.gouv.etalab.mastodon.helper.Helper;
-import fr.gouv.etalab.mastodon.services.CacheTootsService;
+import fr.gouv.etalab.mastodon.sqlite.Sqlite;
+import fr.gouv.etalab.mastodon.sqlite.TimelineCacheDAO;
/**
@@ -751,10 +752,33 @@ public class API {
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
if( response != null) {
- Intent intent = new Intent(context, CacheTootsService.class);
- intent.putExtra("prefKeyOauthTokenT", prefKeyOauthTokenT);
- intent.putExtra("response", response);
- context.startService(intent);
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ List statuses;
+ statuses = API.parseStatuses(context, new JSONArray(response));
+ SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
+
+ List alreadyCached = new TimelineCacheDAO(context, db).getAllStatus(TimelineCacheDAO.HOME_TIMELINE);
+ ArrayList cachedId = new ArrayList<>();
+ if(alreadyCached != null){
+ for(Status status: alreadyCached){
+ cachedId.add(status.getId());
+ }
+ }
+ for(Status status: statuses){
+ if(!cachedId.contains(status.getId())){
+ new TimelineCacheDAO(context, db).insertStatus(TimelineCacheDAO.HOME_TIMELINE, status, prefKeyOauthTokenT);
+ }
+ }
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ thread.start();
}
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
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 a93974b7d..7ebf091de 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
@@ -661,7 +661,11 @@ public class Helper {
public static String dateDiffFull(Date dateToot){
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault());
- return df.format(dateToot);
+ try {
+ return df.format(dateToot);
+ }catch (Exception e){
+ return "";
+ }
}
/***
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/CacheTootsService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/CacheTootsService.java
deleted file mode 100644
index 1762a82b9..000000000
--- a/app/src/main/java/fr/gouv/etalab/mastodon/services/CacheTootsService.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package fr.gouv.etalab.mastodon.services;
-/* Copyright 2018 Thomas Schneider
- *
- * This file is a part of Mastalab
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with Mastalab; if not,
- * see . */
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.database.sqlite.SQLiteDatabase;
-import android.support.annotation.Nullable;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.net.ssl.HttpsURLConnection;
-
-import fr.gouv.etalab.mastodon.client.API;
-import fr.gouv.etalab.mastodon.client.Entities.Account;
-import fr.gouv.etalab.mastodon.client.Entities.Status;
-import fr.gouv.etalab.mastodon.helper.Helper;
-import fr.gouv.etalab.mastodon.sqlite.Sqlite;
-import fr.gouv.etalab.mastodon.sqlite.TimelineCacheDAO;
-
-
-/**
- * Created by Thomas on 17/11/2018.
- * Manage service for caching status
- */
-
-public class CacheTootsService extends IntentService {
-
- static {
- Helper.installProvider();
- }
- /**
- * Creates an IntentService. Invoked by your subclass's constructor.
- *
- * @param name Used to name the worker thread, important only for debugging.
- */
- @SuppressWarnings("unused")
- public CacheTootsService(String name) {
- super(name);
- }
- @SuppressWarnings("unused")
- public CacheTootsService() {
- super("CacheTootsService");
- }
-
- private static HttpsURLConnection httpsURLConnection;
- protected Account account;
-
- public void onCreate() {
- super.onCreate();
- }
-
-
- @Override
- protected void onHandleIntent(@Nullable Intent intent) {
- if( intent == null || intent.getExtras() == null)
- return;
- String response = intent.getExtras().getString("response");
- String payload = intent.getExtras().getString("payload");
- String prefKeyOauthTokenT = intent.getExtras().getString("prefKeyOauthTokenT");
-
- if( (payload == null && response == null) || prefKeyOauthTokenT == null )
- return;
- try {
- List statuses;
- if( response != null)
- statuses = API.parseStatuses(getApplicationContext(), new JSONArray(response));
- else {
- statuses = new ArrayList<>();
- Status status = API.parseStatuses(getApplicationContext(), new JSONObject(payload));
- statuses.add(status);
- }
- SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
-
- List alreadyCached = new TimelineCacheDAO(getApplicationContext(), db).getAllStatus(TimelineCacheDAO.HOME_TIMELINE);
- ArrayList cachedId = new ArrayList<>();
- if(alreadyCached != null){
- for(Status status: alreadyCached){
- cachedId.add(status.getId());
- }
- }
- for(Status status: statuses){
- if(!cachedId.contains(status.getId())){
- new TimelineCacheDAO(getApplicationContext(), db).insertStatus(TimelineCacheDAO.HOME_TIMELINE, status, prefKeyOauthTokenT);
- }
- }
-
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
-}