#915 comment - Add indicators in toots

This commit is contained in:
tom79 2019-05-12 11:39:25 +02:00
parent 452c7ba2b0
commit a894a75a82
10 changed files with 77 additions and 48 deletions

View File

@ -969,28 +969,7 @@ public class API {
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
statuses = new TimelineCacheDAO(context, db).get(max_id); statuses = new TimelineCacheDAO(context, db).get(max_id);
if( statuses == null){ if( statuses == null){
statuses = new ArrayList<>(); return getHomeTimeline(max_id);
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;
}else{ }else{
if( statuses.size() > 0) { if( statuses.size() > 0) {
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1)); apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1));

View File

@ -135,7 +135,7 @@ public class Status implements Parcelable{
private Poll poll = null; private Poll poll = null;
private int media_height; private int media_height;
private boolean iscached = false; private boolean cached = false;
@Override @Override
public void writeToParcel(Parcel dest, int flags) { 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.writeByte(this.isNotice ? (byte) 1 : (byte) 0);
dest.writeParcelable(this.poll, flags); dest.writeParcelable(this.poll, flags);
dest.writeInt(this.media_height); 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) { protected Status(Parcel in) {
@ -255,7 +255,7 @@ public class Status implements Parcelable{
this.isNotice = in.readByte() != 0; this.isNotice = in.readByte() != 0;
this.poll = in.readParcelable(Poll.class.getClassLoader()); this.poll = in.readParcelable(Poll.class.getClassLoader());
this.media_height = in.readInt(); this.media_height = in.readInt();
this.iscached = in.readByte() != 0; this.cached = in.readByte() != 0;
} }
public static final Creator<Status> CREATOR = new Creator<Status>() { public static final Creator<Status> CREATOR = new Creator<Status>() {
@ -1356,11 +1356,11 @@ public class Status implements Parcelable{
this.media_height = media_height; this.media_height = media_height;
} }
public boolean isIscached() { public boolean iscached() {
return iscached; return cached;
} }
public void setIscached(boolean iscached) { public void setcached(boolean cached) {
this.iscached = iscached; this.cached = cached;
} }
} }

View File

@ -359,7 +359,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
LinearLayout status_peertube_container; LinearLayout status_peertube_container;
TextView status_peertube_reply, status_peertube_delete, show_more_content; TextView status_peertube_reply, status_peertube_delete, show_more_content;
ImageView cached_status;
//Poll //Poll
LinearLayout poll_container, single_choice, multiple_choice, rated; 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); remaining_time = itemView.findViewById(R.id.remaining_time);
submit_vote = itemView.findViewById(R.id.submit_vote); submit_vote = itemView.findViewById(R.id.submit_vote);
refresh_poll = itemView.findViewById(R.id.refresh_poll); 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); changeDrawableColor(context, R.drawable.video_preview, R.color.white);
if (theme == Helper.THEME_BLACK) { 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, holder.status_remove, R.color.action_dark);
changeDrawableColor(context, R.drawable.ic_reply, R.color.action_black); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_black);
changeDrawableColor(context, holder.status_more, 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); changeDrawableColor(context, R.drawable.ic_translate, R.color.black);
holder.status_cardview.setBackgroundResource(R.drawable.card_border_black); holder.status_cardview.setBackgroundResource(R.drawable.card_border_black);
} else if (theme == Helper.THEME_DARK) { } 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, holder.status_remove, R.color.action_dark);
changeDrawableColor(context, R.drawable.ic_reply, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_dark);
changeDrawableColor(context, holder.status_more, 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_bookmark_border, R.color.mastodonC1);
changeDrawableColor(context, R.drawable.ic_translate, R.color.mastodonC1); changeDrawableColor(context, R.drawable.ic_translate, R.color.mastodonC1);
} else { } else {
changeDrawableColor(context, holder.cached_status, R.color.action_light);
changeDrawableColor(context, holder.status_remove, 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_fetch_more, R.color.action_light);
changeDrawableColor(context, R.drawable.ic_reply, 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 else
holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark_border)); 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) //Redraws top icons (boost/reply)
final float scale = context.getResources().getDisplayMetrics().density; final float scale = context.getResources().getDisplayMetrics().density;
holder.spark_button_fav.pressOnTouch(false); holder.spark_button_fav.pressOnTouch(false);
@ -967,10 +975,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
assert img != null; assert img != null;
img.setBounds(0, 0, (int) (20 * iconSizePercent / 100 * scale + 0.5f), (int) (15 * iconSizePercent / 100 * scale + 0.5f)); 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.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 { } else {
holder.status_account_displayname.setCompoundDrawables(null, null, null, null); 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())) { if( expand_media && status.isSensitive() || (status.getReblog() != null && status.getReblog().isSensitive())) {
changeDrawableColor(context, holder.hide_preview, R.color.red_1); changeDrawableColor(context, holder.hide_preview, R.color.red_1);

View File

@ -69,6 +69,7 @@ public class TimelineCacheDAO {
last_id = db.insert(Sqlite.TABLE_TIMELINE_CACHE, null, values); last_id = db.insert(Sqlite.TABLE_TIMELINE_CACHE, null, values);
}catch (Exception e) { }catch (Exception e) {
last_id = -1; last_id = -1;
e.printStackTrace();
} }
return last_id; return last_id;
} }
@ -126,7 +127,7 @@ public class TimelineCacheDAO {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context); String instance = Helper.getLiveInstance(context);
try { 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); return cursorToSingleStatus(c);
} catch (Exception e) { } catch (Exception e) {
return null; return null;
@ -146,6 +147,7 @@ public class TimelineCacheDAO {
Status status = null; Status status = null;
try { try {
status = API.parseStatuses(context, new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE)))); status = API.parseStatuses(context, new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
status.setcached(true);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -169,6 +171,7 @@ public class TimelineCacheDAO {
//Restore cached status //Restore cached status
try { try {
Status status = API.parseStatuses(context, new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE)))); Status status = API.parseStatuses(context, new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
status.setcached(true);
statuses.add(status); statuses.add(status);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,8l-4,4h3c0,3.31 -2.69,6 -6,6 -1.01,0 -1.97,-0.25 -2.8,-0.7l-1.46,1.46C8.97,19.54 10.43,20 12,20c4.42,0 8,-3.58 8,-8h3l-4,-4zM6,12c0,-3.31 2.69,-6 6,-6 1.01,0 1.97,0.25 2.8,0.7l1.46,-1.46C15.03,4.46 13.57,4 12,4c-4.42,0 -8,3.58 -8,8H1l4,4 4,-4H6z"/>
</vector>

View File

@ -148,18 +148,25 @@
android:textStyle="bold" android:textStyle="bold"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView
android:id="@+id/status_account_displayname_owner"
android:maxLines="1"
android:textStyle="bold"
android:drawablePadding="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageView
android:id="@+id/cached_status"
android:visibility="gone"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_cached_black"
android:contentDescription="@string/cached_status" />
<TextView
android:id="@+id/status_account_displayname_owner"
android:maxLines="1"
android:textStyle="bold"
android:drawablePadding="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView <TextView
android:textSize="12sp" android:textSize="12sp"
android:maxLines="1" android:maxLines="1"

View File

@ -152,17 +152,25 @@
android:textStyle="bold" android:textStyle="bold"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView
android:id="@+id/status_account_displayname_owner"
android:maxLines="1"
android:drawablePadding="2dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageView
android:src="@drawable/ic_cached_black"
android:id="@+id/cached_status"
android:visibility="gone"
android:layout_width="20dp"
android:layout_height="20dp"
android:contentDescription="@string/cached_status" />
<TextView
android:id="@+id/status_account_displayname_owner"
android:maxLines="1"
android:drawablePadding="2dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView <TextView
android:textSize="12sp" android:textSize="12sp"
android:maxLines="1" android:maxLines="1"

View File

@ -160,6 +160,13 @@
android:textStyle="bold" android:textStyle="bold"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<ImageView
android:id="@+id/cached_status"
android:src="@drawable/ic_cached_black"
android:visibility="gone"
android:layout_width="20dp"
android:layout_height="20dp"
android:contentDescription="@string/cached_status" />
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -95,6 +95,13 @@
android:layout_weight="1" android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<ImageView
android:id="@+id/cached_status"
android:visibility="gone"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_cached_black"
android:contentDescription="@string/cached_status" />
<TextView <TextView
android:id="@+id/status_account_displayname" android:id="@+id/status_account_displayname"
android:maxLines="1" android:maxLines="1"

View File

@ -945,6 +945,7 @@
<string name="add_timeline">Add a timeline</string> <string name="add_timeline">Add a timeline</string>
<string name="set_sensitive_content">Always mark media as sensitive</string> <string name="set_sensitive_content">Always mark media as sensitive</string>
<string name="gnu_instance">GNU instance</string> <string name="gnu_instance">GNU instance</string>
<string name="cached_status">Cached status</string>
<plurals name="number_of_vote"> <plurals name="number_of_vote">
<item quantity="one">%d vote</item> <item quantity="one">%d vote</item>