Some fixes for 1.32.0-beta-1
This commit is contained in:
parent
8a684966fd
commit
f94bf32910
|
@ -7,8 +7,8 @@ android {
|
||||||
applicationId "fr.gouv.etalab.mastodon"
|
applicationId "fr.gouv.etalab.mastodon"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 193
|
versionCode 194
|
||||||
versionName "1.31.1"
|
versionName "1.32.0-beta-1"
|
||||||
}
|
}
|
||||||
flavorDimensions "default"
|
flavorDimensions "default"
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
@ -45,7 +45,7 @@ allprojects {
|
||||||
ext.supportLibraryVersion = '28.0.0'
|
ext.supportLibraryVersion = '28.0.0'
|
||||||
ext.glideLibraryVersion = '4.8.0'
|
ext.glideLibraryVersion = '4.8.0'
|
||||||
ext.conscryptLibraryVersion = '1.3.0'
|
ext.conscryptLibraryVersion = '1.3.0'
|
||||||
ext.evernoteLibraryVersion = '1.3.0-alpha08'
|
ext.evernoteLibraryVersion = '1.3.0-alpha09'
|
||||||
ext.gsonLibraryVersion = '2.8.2'
|
ext.gsonLibraryVersion = '2.8.2'
|
||||||
ext.guavaLibraryVersion = '24.1-android'
|
ext.guavaLibraryVersion = '24.1-android'
|
||||||
ext.photoViewLibraryVersion = '2.0.0'
|
ext.photoViewLibraryVersion = '2.0.0'
|
||||||
|
|
|
@ -42,9 +42,6 @@
|
||||||
<service
|
<service
|
||||||
android:name=".services.LiveNotificationService"
|
android:name=".services.LiveNotificationService"
|
||||||
android:exported="false"/>
|
android:exported="false"/>
|
||||||
<service
|
|
||||||
android:name=".services.CacheTootsService"
|
|
||||||
android:exported="false"/>
|
|
||||||
<service android:name=".services.BackupStatusService"
|
<service android:name=".services.BackupStatusService"
|
||||||
android:exported="false"/>
|
android:exported="false"/>
|
||||||
<service android:name=".services.BackupStatusInDataBaseService"
|
<service android:name=".services.BackupStatusInDataBaseService"
|
||||||
|
|
|
@ -15,8 +15,8 @@ package fr.gouv.etalab.mastodon.client;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
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.Status;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Tag;
|
import fr.gouv.etalab.mastodon.client.Entities.Tag;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
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());
|
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||||
statuses = parseStatuses(context, new JSONArray(response));
|
statuses = parseStatuses(context, new JSONArray(response));
|
||||||
if( response != null) {
|
if( response != null) {
|
||||||
Intent intent = new Intent(context, CacheTootsService.class);
|
Thread thread = new Thread() {
|
||||||
intent.putExtra("prefKeyOauthTokenT", prefKeyOauthTokenT);
|
@Override
|
||||||
intent.putExtra("response", response);
|
public void run() {
|
||||||
context.startService(intent);
|
try {
|
||||||
|
List<Status> statuses;
|
||||||
|
statuses = API.parseStatuses(context, new JSONArray(response));
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
|
||||||
|
List<Status> alreadyCached = new TimelineCacheDAO(context, db).getAllStatus(TimelineCacheDAO.HOME_TIMELINE);
|
||||||
|
ArrayList<String> 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) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
|
|
|
@ -661,7 +661,11 @@ public class Helper {
|
||||||
|
|
||||||
public static String dateDiffFull(Date dateToot){
|
public static String dateDiffFull(Date dateToot){
|
||||||
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault());
|
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault());
|
||||||
return df.format(dateToot);
|
try {
|
||||||
|
return df.format(dateToot);
|
||||||
|
}catch (Exception e){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
|
||||||
|
|
||||||
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<Status> 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<Status> alreadyCached = new TimelineCacheDAO(getApplicationContext(), db).getAllStatus(TimelineCacheDAO.HOME_TIMELINE);
|
|
||||||
ArrayList<String> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue