From a894a75a82470a68246519120b946ee084e77d1e Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 12 May 2019 11:39:25 +0200 Subject: [PATCH] #915 comment - Add indicators in toots --- .../fr/gouv/etalab/mastodon/client/API.java | 23 +------------------ .../mastodon/client/Entities/Status.java | 14 +++++------ .../mastodon/drawers/StatusListAdapter.java | 16 +++++++++---- .../mastodon/sqlite/TimelineCacheDAO.java | 5 +++- app/src/main/res/drawable/ic_cached_black.xml | 9 ++++++++ app/src/main/res/layout/drawer_status.xml | 21 +++++++++++------ .../main/res/layout/drawer_status_compact.xml | 22 ++++++++++++------ .../main/res/layout/drawer_status_console.xml | 7 ++++++ .../main/res/layout/drawer_status_focused.xml | 7 ++++++ app/src/main/res/values/strings.xml | 1 + 10 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 app/src/main/res/drawable/ic_cached_black.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 1cff80fe5..788e64c75 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -969,28 +969,7 @@ public class API { SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); statuses = new TimelineCacheDAO(context, db).get(max_id); if( statuses == null){ - statuses = new ArrayList<>(); - try { - HttpsConnection httpsConnection = new HttpsConnection(context); - 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); - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - if( apiResponse == null) - apiResponse = new APIResponse(); - apiResponse.setStatuses(statuses); - return apiResponse; + return getHomeTimeline(max_id); }else{ if( statuses.size() > 0) { apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1)); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index d4200bf09..4aa78ae10 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -135,7 +135,7 @@ public class Status implements Parcelable{ private Poll poll = null; private int media_height; - private boolean iscached = false; + private boolean cached = false; @Override public void writeToParcel(Parcel dest, int flags) { @@ -194,7 +194,7 @@ public class Status implements Parcelable{ dest.writeByte(this.isNotice ? (byte) 1 : (byte) 0); dest.writeParcelable(this.poll, flags); dest.writeInt(this.media_height); - dest.writeByte(this.iscached ? (byte) 1 : (byte) 0); + dest.writeByte(this.cached ? (byte) 1 : (byte) 0); } protected Status(Parcel in) { @@ -255,7 +255,7 @@ public class Status implements Parcelable{ this.isNotice = in.readByte() != 0; this.poll = in.readParcelable(Poll.class.getClassLoader()); this.media_height = in.readInt(); - this.iscached = in.readByte() != 0; + this.cached = in.readByte() != 0; } public static final Creator CREATOR = new Creator() { @@ -1356,11 +1356,11 @@ public class Status implements Parcelable{ this.media_height = media_height; } - public boolean isIscached() { - return iscached; + public boolean iscached() { + return cached; } - public void setIscached(boolean iscached) { - this.iscached = iscached; + public void setcached(boolean cached) { + this.cached = cached; } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index a3fe89a0b..5ce0d20e7 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -359,7 +359,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct LinearLayout status_peertube_container; TextView status_peertube_reply, status_peertube_delete, show_more_content; - + ImageView cached_status; //Poll LinearLayout poll_container, single_choice, multiple_choice, rated; @@ -466,6 +466,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct remaining_time = itemView.findViewById(R.id.remaining_time); submit_vote = itemView.findViewById(R.id.submit_vote); refresh_poll = itemView.findViewById(R.id.refresh_poll); + cached_status = itemView.findViewById(R.id.cached_status); } } @@ -829,6 +830,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct changeDrawableColor(context, R.drawable.video_preview, R.color.white); if (theme == Helper.THEME_BLACK) { + changeDrawableColor(context, holder.cached_status, R.color.action_dark); changeDrawableColor(context, holder.status_remove, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_black); changeDrawableColor(context, holder.status_more, R.color.action_black); @@ -856,6 +858,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct changeDrawableColor(context, R.drawable.ic_translate, R.color.black); holder.status_cardview.setBackgroundResource(R.drawable.card_border_black); } else if (theme == Helper.THEME_DARK) { + changeDrawableColor(context, holder.cached_status, R.color.action_dark); changeDrawableColor(context, holder.status_remove, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_dark); changeDrawableColor(context, holder.status_more, R.color.action_dark); @@ -883,6 +886,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct changeDrawableColor(context, R.drawable.ic_bookmark_border, R.color.mastodonC1); changeDrawableColor(context, R.drawable.ic_translate, R.color.mastodonC1); } else { + changeDrawableColor(context, holder.cached_status, R.color.action_light); changeDrawableColor(context, holder.status_remove, R.color.action_light); changeDrawableColor(context, R.drawable.ic_fetch_more, R.color.action_light); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_light); @@ -927,7 +931,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct else holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark_border)); - + if( status.iscached()){ + holder.cached_status.setVisibility(View.VISIBLE); + }else{ + holder.cached_status.setVisibility(View.GONE); + } //Redraws top icons (boost/reply) final float scale = context.getResources().getDisplayMetrics().density; holder.spark_button_fav.pressOnTouch(false); @@ -967,10 +975,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct assert img != null; img.setBounds(0, 0, (int) (20 * iconSizePercent / 100 * scale + 0.5f), (int) (15 * iconSizePercent / 100 * scale + 0.5f)); holder.status_account_displayname.setCompoundDrawables(img, null, null, null); - holder.status_account_displayname_owner.setCompoundDrawables(null, null, imgConversation, null); + holder.status_toot_date.setCompoundDrawables(imgConversation, null, null, null); } else { holder.status_account_displayname.setCompoundDrawables(null, null, null, null); - holder.status_account_displayname_owner.setCompoundDrawables(null, null, imgConversation, null); + holder.status_toot_date.setCompoundDrawables(imgConversation, null, null , null); } if( expand_media && status.isSensitive() || (status.getReblog() != null && status.getReblog().isSensitive())) { changeDrawableColor(context, holder.hide_preview, R.color.red_1); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/TimelineCacheDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/TimelineCacheDAO.java index 5173591ba..4e0b947cb 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/TimelineCacheDAO.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/TimelineCacheDAO.java @@ -69,6 +69,7 @@ public class TimelineCacheDAO { last_id = db.insert(Sqlite.TABLE_TIMELINE_CACHE, null, values); }catch (Exception e) { last_id = -1; + e.printStackTrace(); } return last_id; } @@ -126,7 +127,7 @@ public class TimelineCacheDAO { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = Helper.getLiveInstance(context); try { - Cursor c = db.query(Sqlite.TABLE_TIMELINE_CACHE, null, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\"", null, null, null, Sqlite.COL_STATUS_ID+ " DESC", "1"); + Cursor c = db.query(Sqlite.TABLE_TIMELINE_CACHE, null, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\" AND "+ Sqlite.COL_STATUS_ID + " ='" + statusId +"'", null, null, null, Sqlite.COL_STATUS_ID+ " DESC", "1"); return cursorToSingleStatus(c); } catch (Exception e) { return null; @@ -146,6 +147,7 @@ public class TimelineCacheDAO { Status status = null; try { status = API.parseStatuses(context, new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE)))); + status.setcached(true); } catch (JSONException e) { e.printStackTrace(); } @@ -169,6 +171,7 @@ public class TimelineCacheDAO { //Restore cached status try { Status status = API.parseStatuses(context, new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE)))); + status.setcached(true); statuses.add(status); } catch (JSONException e) { e.printStackTrace(); diff --git a/app/src/main/res/drawable/ic_cached_black.xml b/app/src/main/res/drawable/ic_cached_black.xml new file mode 100644 index 000000000..5e776beb1 --- /dev/null +++ b/app/src/main/res/drawable/ic_cached_black.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index efe3fb26e..94032b09f 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -148,18 +148,25 @@ android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" /> - + + - + + + + + Add a timeline Always mark media as sensitive GNU instance + Cached status %d vote