Fix issue #933
This commit is contained in:
parent
c37f1584d1
commit
4c848f8ac8
|
@ -819,7 +819,8 @@ public class API {
|
|||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", statusId)), 60, null, prefKeyOauthTokenT);
|
||||
Status status = parseStatuses(context, new JSONObject(response));
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelineCacheDAO(context, db).update(status.getId(), response);
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
new TimelineCacheDAO(context, db).update(status.getId(), response, account.getId(), account.getInstance());
|
||||
statuses.add(status);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -1078,7 +1079,7 @@ public class API {
|
|||
String response = httpsConnection.get(getAbsoluteUrl("/timelines/home"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
statuses = parseStatuses(context, new JSONArray(response), true);
|
||||
statuses = parseStatusesForCache(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -2203,7 +2204,8 @@ public class API {
|
|||
intentBC.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelineCacheDAO(context, db).update(targetedId, resp);
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
new TimelineCacheDAO(context, db).update(targetedId, resp, account.getId(), account.getInstance());
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
@ -2366,8 +2368,9 @@ public class API {
|
|||
intentBC.putExtras(b);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Status alreadyCached = new TimelineCacheDAO(context, db).getSingle(status.getId());
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
if (alreadyCached != null) {
|
||||
new TimelineCacheDAO(context, db).update(status.getId(), response);
|
||||
new TimelineCacheDAO(context, db).update(status.getId(), response, account.getId(), account.getInstance());
|
||||
}
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
|
||||
return parsePoll(context, new JSONObject(response));
|
||||
|
@ -3856,7 +3859,7 @@ public class API {
|
|||
* @param jsonArray JSONArray
|
||||
* @return List<Status>
|
||||
*/
|
||||
private static List<Status> parseStatuses(Context context, JSONArray jsonArray, boolean cached){
|
||||
private List<Status> parseStatusesForCache(Context context, JSONArray jsonArray){
|
||||
|
||||
List<Status> statuses = new ArrayList<>();
|
||||
try {
|
||||
|
@ -3865,12 +3868,11 @@ public class API {
|
|||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Status status = parseStatuses(context, resobj);
|
||||
if( cached) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Status alreadyCached = new TimelineCacheDAO(context, db).getSingle(status.getId());
|
||||
if (alreadyCached == null) {
|
||||
new TimelineCacheDAO(context, db).insert(status.getId(), resobj.toString());
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Status alreadyCached = new TimelineCacheDAO(context, db).getSingle(status.getId());
|
||||
if (alreadyCached == null) {
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
new TimelineCacheDAO(context, db).insert(status.getId(), resobj.toString(), account.getId(), account.getInstance());
|
||||
}
|
||||
i++;
|
||||
statuses.add(status);
|
||||
|
|
|
@ -1395,7 +1395,8 @@ public class GNUAPI {
|
|||
intentBC.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelineCacheDAO(context, db).update(targetedId, resp);
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
new TimelineCacheDAO(context, db).update(targetedId, resp, account.getId(), account.getToken());
|
||||
}else if( statusAction == API.StatusAction.UNSTATUS){
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelineCacheDAO(context, db).remove(targetedId);
|
||||
|
|
|
@ -53,10 +53,7 @@ public class TimelineCacheDAO {
|
|||
* Insert a status in database
|
||||
* @return boolean
|
||||
*/
|
||||
public long insert(String statusId, String jsonString) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
public long insert(String statusId, String jsonString, String userId, String instance) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Sqlite.COL_INSTANCE, instance);
|
||||
values.put(Sqlite.COL_STATUS_ID, statusId);
|
||||
|
@ -78,10 +75,7 @@ public class TimelineCacheDAO {
|
|||
/**
|
||||
* Update a status in database
|
||||
*/
|
||||
public void update(String statusId, String jsonString) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
public void update(String statusId, String jsonString, String userId, String instance) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Sqlite.COL_DATE, Helper.dateToString(new Date()));
|
||||
values.put(Sqlite.COL_CACHE, jsonString);
|
||||
|
|
Loading…
Reference in New Issue