Fix cache issue
This commit is contained in:
parent
49c5acdd47
commit
c15120f459
|
@ -26,13 +26,11 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
|
||||
import fr.gouv.etalab.mastodon.helper.FilterToots;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.TimelineCacheDAO;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -143,7 +141,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
switch (action){
|
||||
case HOME:
|
||||
if( !Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()))){
|
||||
/*if( !Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get()))){
|
||||
new TimelineCacheDAO(contextReference.get(), db).cleanDoublon();
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = new TimelineCacheDAO(contextReference.get(), db).getAllCachedStatus(max_id);
|
||||
if( statuses == null || statuses.size() == 0)
|
||||
|
@ -155,7 +153,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
}else{
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
}
|
||||
}*/
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
break;
|
||||
case LOCAL:
|
||||
apiResponse = api.getPublicTimeline(true, max_id);
|
||||
|
|
|
@ -16,7 +16,6 @@ package fr.gouv.etalab.mastodon.client;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -57,8 +56,6 @@ 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.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.TimelineCacheDAO;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -751,7 +748,7 @@ public class API {
|
|||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
if( response != null) {
|
||||
/*if( response != null) {
|
||||
Thread thread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -779,7 +776,7 @@ public class API {
|
|||
}
|
||||
};
|
||||
thread.start();
|
||||
}
|
||||
}*/
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
|
|
@ -1,171 +0,0 @@
|
|||
/* 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>. */
|
||||
package fr.gouv.etalab.mastodon.client.Entities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 29/11/2018.
|
||||
* Manage preferences
|
||||
*/
|
||||
public class Preferences {
|
||||
|
||||
private String userId;
|
||||
private boolean displayBookmarkButton, fullAttachement, isCompactMode, trans_forced, expand_cw, expand_media, display_card, display_video_preview, share_details;
|
||||
private int iconSizePercent, textSizePercent, theme, truncate_toots_size, timeout;
|
||||
|
||||
|
||||
public Preferences(Context context){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false);
|
||||
fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
|
||||
isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
|
||||
iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
|
||||
textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
|
||||
trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false);
|
||||
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
|
||||
expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
||||
display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
|
||||
display_video_preview = sharedpreferences.getBoolean(Helper.SET_DISPLAY_VIDEO_PREVIEWS, true);
|
||||
truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0);
|
||||
timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
||||
share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isDisplayBookmarkButton() {
|
||||
return displayBookmarkButton;
|
||||
}
|
||||
|
||||
public void setDisplayBookmarkButton(boolean displayBookmarkButton) {
|
||||
this.displayBookmarkButton = displayBookmarkButton;
|
||||
}
|
||||
|
||||
public boolean isFullAttachement() {
|
||||
return fullAttachement;
|
||||
}
|
||||
|
||||
public void setFullAttachement(boolean fullAttachement) {
|
||||
this.fullAttachement = fullAttachement;
|
||||
}
|
||||
|
||||
public boolean isCompactMode() {
|
||||
return isCompactMode;
|
||||
}
|
||||
|
||||
public void setCompactMode(boolean compactMode) {
|
||||
isCompactMode = compactMode;
|
||||
}
|
||||
|
||||
public boolean isTrans_forced() {
|
||||
return trans_forced;
|
||||
}
|
||||
|
||||
public void setTrans_forced(boolean trans_forced) {
|
||||
this.trans_forced = trans_forced;
|
||||
}
|
||||
|
||||
public boolean isExpand_cw() {
|
||||
return expand_cw;
|
||||
}
|
||||
|
||||
public void setExpand_cw(boolean expand_cw) {
|
||||
this.expand_cw = expand_cw;
|
||||
}
|
||||
|
||||
public boolean isExpand_media() {
|
||||
return expand_media;
|
||||
}
|
||||
|
||||
public void setExpand_media(boolean expand_media) {
|
||||
this.expand_media = expand_media;
|
||||
}
|
||||
|
||||
public boolean isDisplay_card() {
|
||||
return display_card;
|
||||
}
|
||||
|
||||
public void setDisplay_card(boolean display_card) {
|
||||
this.display_card = display_card;
|
||||
}
|
||||
|
||||
public boolean isDisplay_video_preview() {
|
||||
return display_video_preview;
|
||||
}
|
||||
|
||||
public void setDisplay_video_preview(boolean display_video_preview) {
|
||||
this.display_video_preview = display_video_preview;
|
||||
}
|
||||
|
||||
public boolean isShare_details() {
|
||||
return share_details;
|
||||
}
|
||||
|
||||
public void setShare_details(boolean share_details) {
|
||||
this.share_details = share_details;
|
||||
}
|
||||
|
||||
public int getIconSizePercent() {
|
||||
return iconSizePercent;
|
||||
}
|
||||
|
||||
public void setIconSizePercent(int iconSizePercent) {
|
||||
this.iconSizePercent = iconSizePercent;
|
||||
}
|
||||
|
||||
public int getTextSizePercent() {
|
||||
return textSizePercent;
|
||||
}
|
||||
|
||||
public void setTextSizePercent(int textSizePercent) {
|
||||
this.textSizePercent = textSizePercent;
|
||||
}
|
||||
|
||||
public int getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
public void setTheme(int theme) {
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public int getTruncate_toots_size() {
|
||||
return truncate_toots_size;
|
||||
}
|
||||
|
||||
public void setTruncate_toots_size(int truncate_toots_size) {
|
||||
this.truncate_toots_size = truncate_toots_size;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
|
@ -103,7 +103,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Preferences;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
|
@ -151,9 +150,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
private List<String> timedMute;
|
||||
private boolean redraft;
|
||||
private Status toot;
|
||||
private Preferences preferences;
|
||||
|
||||
public StatusListAdapter(Context context, Preferences preferences, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
super();
|
||||
this.context = context;
|
||||
this.statuses = statuses;
|
||||
|
@ -165,10 +163,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
this.targetedId = targetedId;
|
||||
this.translator = translator;
|
||||
redraft = false;
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public StatusListAdapter(Context context, Preferences preferences, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
this.context = context;
|
||||
this.statuses = statuses;
|
||||
this.isOnWifi = isOnWifi;
|
||||
|
@ -180,7 +177,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
this.targetedId = targetedId;
|
||||
this.translator = translator;
|
||||
redraft = false;
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public void updateMuted(List<String> timedMute){
|
||||
|
@ -432,9 +428,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
status.setItemViewType(viewHolder.getItemViewType());
|
||||
|
||||
final String userId = preferences.getUserId();
|
||||
boolean displayBookmarkButton = preferences.isDisplayBookmarkButton();
|
||||
boolean fullAttachement = preferences.isFullAttachement();
|
||||
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
boolean displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false);
|
||||
boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
|
||||
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
|
||||
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
|
||||
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.json.JSONObject;
|
|||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -65,12 +64,10 @@ import fr.gouv.etalab.mastodon.activities.MainActivity;
|
|||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.TimelineCacheDAO;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_TARGETED_ACCOUNT;
|
||||
|
@ -393,7 +390,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
event = Helper.EventStreaming.UPDATE;
|
||||
status = API.parseStatuses(getApplicationContext(), new JSONObject(response.get("payload").toString()));
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
if(userId != null && instance != null && userId.equals(account.getId()) && instance.equals(account.getInstance())){
|
||||
/*if(userId != null && instance != null && userId.equals(account.getId()) && instance.equals(account.getInstance())){
|
||||
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<>();
|
||||
|
@ -405,7 +402,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
if(!cachedId.contains(status.getId())){
|
||||
new TimelineCacheDAO(getApplicationContext(), db).insertStatus(TimelineCacheDAO.HOME_TIMELINE, status, account.getToken());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
status.setNew(true);
|
||||
b.putParcelable("data", status);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue