Improve conversation + non compact mode by default

This commit is contained in:
stom79 2018-11-10 16:49:21 +01:00
parent 8e07ce60a0
commit 97cfcc92ec
14 changed files with 132 additions and 45 deletions

View File

@ -39,7 +39,6 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
@ -338,7 +337,9 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
mLayoutManager = new LinearLayoutManager(this);
lv_status.setLayoutManager(mLayoutManager);
lv_status.addItemDecoration(new ConversationDecoration(ShowConversationActivity.this));
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
boolean compactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
lv_status.addItemDecoration(new ConversationDecoration(ShowConversationActivity.this, theme, compactMode));
lv_status.setAdapter(statusListAdapter);
if( isRefreshed){

View File

@ -16,8 +16,9 @@ package fr.gouv.etalab.mastodon.client.Entities;
import android.app.Activity;
import android.content.*;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
@ -33,10 +34,8 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.View;
import com.bumptech.glide.Glide;
@ -119,6 +118,7 @@ public class Status implements Parcelable{
private String content, contentCW, contentTranslated;
private SpannableString contentSpan, displayNameSpan, contentSpanCW, contentSpanTranslated;
private RetrieveFeedsAsyncTask.Type type;
private int itemViewType;
public Status(){
this.status = this;
@ -138,6 +138,7 @@ public class Status implements Parcelable{
content = in.readString();
contentTranslated = in.readString();
reblogs_count = in.readInt();
itemViewType = in.readInt();
favourites_count = in.readInt();
replies_count = in.readInt();
reblogged = in.readByte() != 0;
@ -371,6 +372,7 @@ public class Status implements Parcelable{
dest.writeString(content);
dest.writeString(contentTranslated);
dest.writeInt(reblogs_count);
dest.writeInt(itemViewType);
dest.writeInt(favourites_count);
dest.writeInt(replies_count);
dest.writeByte((byte) (reblogged ? 1 : 0));
@ -1069,4 +1071,12 @@ public class Status implements Parcelable{
public void setWebviewURL(String webviewURL) {
this.webviewURL = webviewURL;
}
public int getItemViewType() {
return itemViewType;
}
public void setItemViewType(int itemViewType) {
this.itemViewType = itemViewType;
}
}

View File

@ -16,17 +16,21 @@ package fr.gouv.etalab.mastodon.drawers;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.helper.Helper;
import static fr.gouv.etalab.mastodon.drawers.StatusListAdapter.FOCUSED_STATUS;
/**
* Created by Thomas on 08/09/2018.
* Adapter for thread decoration
@ -35,20 +39,33 @@ public class ConversationDecoration extends RecyclerView.ItemDecoration{
private Drawable divider;
private Context context;
private boolean compactMode;
public ConversationDecoration(Context context){
divider = ContextCompat.getDrawable(context,R.drawable.line_divider);
public ConversationDecoration(Context context, int theme, boolean compactMode){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( theme == Helper.THEME_BLACK)
divider = ContextCompat.getDrawable(context,R.drawable.line_divider_black);
else if(theme == Helper.THEME_DARK)
divider = ContextCompat.getDrawable(context,R.drawable.line_divider_dark);
else if(theme == Helper.THEME_LIGHT)
divider = ContextCompat.getDrawable(context,R.drawable.line_divider_light);
this.compactMode = compactMode;
this.context = context;
}
@Override
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int left = parent.getPaddingLeft() + (int)Helper.convertDpToPixel(12, context);
int leftSide;
if( compactMode)
leftSide = (int) Helper.convertDpToPixel(12, context);
else
leftSide = (int) Helper.convertDpToPixel(28, context);
int left = parent.getPaddingLeft() + leftSide;
int right = left + (int)Helper.convertDpToPixel(4, context);
int childCount = parent.getChildCount();
int offSet = (int) Helper.convertDpToPixel(30, context);
for (int i = 0; i < childCount; i++) {
@ -62,20 +79,31 @@ public class ConversationDecoration extends RecyclerView.ItemDecoration{
int top, bottom;
if( status != null){
int itemViewType = status.getItemViewType();
Status statusBefore = null;
if( position > 0)
statusBefore = adapter.getItem(position - 1);
top = (statusBefore != null && statusBefore.getId().equals(status.getIn_reply_to_id()))?
child.getTop(): (child.getTop() + offSet);
Status statusAfter = null;
if( adapter.getItemCount() > position+1)
statusAfter = adapter.getItem(position + 1);
bottom = (statusAfter != null && status.getId().equals(statusAfter.getIn_reply_to_id()) )?
child.getBottom():child.getTop()+offSet;
if( position == 0 && childCount > 1)
top = bottom - (int)Helper.convertDpToPixel(14, context);
if( position == 0 && childCount <= 1 )
top = bottom;
Log.v(Helper.TAG,"itemViewType: " + itemViewType);
Log.v(Helper.TAG,"position: " + position);
Log.v(Helper.TAG,"content: " + status.getContent());
if( itemViewType != FOCUSED_STATUS || position == 0){
if( position > 0)
statusBefore = adapter.getItem(position - 1);
top = (statusBefore != null && statusBefore.getId().equals(status.getIn_reply_to_id()))?
child.getTop(): (child.getTop() + offSet);
Status statusAfter = null;
if( adapter.getItemCount() > position+1)
statusAfter = adapter.getItem(position + 1);
bottom = (statusAfter != null && status.getId().equals(statusAfter.getIn_reply_to_id()) )?
child.getBottom():child.getTop()+offSet;
if( position == 0 && childCount > 1)
top = bottom - (int)Helper.convertDpToPixel(14, context);
if( position == 0 && childCount <= 1 )
top = bottom;
}else{
top = child.getTop();
bottom = top + (int)Helper.convertDpToPixel(14, context);
}
divider.setBounds(left, top, right, bottom);
divider.draw(canvas);
}

View File

@ -142,9 +142,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private RetrieveFeedsAsyncTask.Type type;
private String targetedId;
private final int HIDDEN_STATUS = 0;
private final int DISPLAYED_STATUS = 1;
private final int FOCUSED_STATUS = 2;
private final int COMPACT_STATUS = 3;
public static final int DISPLAYED_STATUS = 1;
public static final int FOCUSED_STATUS = 2;
public static final int COMPACT_STATUS = 3;
private int conversationPosition;
private List<String> timedMute;
private boolean redraft;
@ -387,7 +387,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
public int getItemViewType(int position) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition)
return FOCUSED_STATUS;
else if( !Helper.filterToots(context, statuses.get(position), timedMute, type))
@ -421,11 +421,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
status.setItemViewType(viewHolder.getItemViewType());
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, true);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !isCompactMode && displayBookmarkButton)
holder.status_bookmark.setVisibility(View.VISIBLE);
@ -456,14 +457,14 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) != FOCUSED_STATUS && position != 0 ){
if( isCompactMode && type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) != FOCUSED_STATUS && position != 0 ){
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins((int)Helper.convertDpToPixel(25, context), 0, 0, 0);
holder.main_container.setLayoutParams(params);
}else if(type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) == FOCUSED_STATUS && position != 0 ){
}else if(isCompactMode && type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) == FOCUSED_STATUS && position != 0 ){
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
@ -529,7 +530,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_favorite_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
holder.status_reblog_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
holder.status_reply.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
changeDrawableColor(context, R.drawable.ic_fetch_more,R.color.dark_icon);
holder.status_cardview_title.setTextColor(ContextCompat.getColor(context, R.color.mastodonC2));
holder.status_cardview_content.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
holder.status_cardview_url.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
@ -545,6 +546,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
changeDrawableColor(context, R.drawable.ic_photo,R.color.mastodonC4);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.mastodonC4);
changeDrawableColor(context, R.drawable.ic_translate,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_fetch_more,R.color.mastodonC4);
holder.status_favorite_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
holder.status_reblog_count.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
holder.status_reply.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
@ -553,6 +555,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_cardview_content.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
holder.status_cardview_url.setTextColor(ContextCompat.getColor(context, R.color.dark_icon));
}else {
changeDrawableColor(context, R.drawable.ic_fetch_more,R.color.black);
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
changeDrawableColor(context, R.drawable.ic_more_horiz,R.color.black);
changeDrawableColor(context, holder.status_more, R.color.black);
@ -890,7 +893,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_spoiler_container.setVisibility(View.VISIBLE);
if( !status.isSpoilerShown() && !expand_cw) {
holder.status_content_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
if( status.getMentions().size() > 0 )
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
else
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler));
}else {
holder.status_content_container.setVisibility(View.VISIBLE);
@ -907,7 +913,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_spoiler_container.setVisibility(View.VISIBLE);
if( !status.isSpoilerShown() && !expand_cw) {
holder.status_content_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
if( status.getMentions().size() > 0 )
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
else
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler));
}else {
holder.status_content_container.setVisibility(View.VISIBLE);

View File

@ -284,7 +284,7 @@ public class SettingsFragment extends Fragment {
}
});
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
final CheckBox set_compact_mode = rootView.findViewById(R.id.set_compact_mode);
set_compact_mode.setChecked(compact_mode);

View File

@ -1296,6 +1296,8 @@ public class Helper {
cw_mention = String.format("@%s %s",mention.getUsername(),cw_mention);
}
SpannableString spannableString = new SpannableString(cw_mention);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
for (final Mention mention : mentions) {
String targetedAccount = "@" + mention.getUsername();
if (spannableString.toString().contains(targetedAccount)) {
@ -1315,6 +1317,13 @@ public class Helper {
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
},
startPosition, endPosition,

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="#FFFFFFFF"
android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z"/>
</vector>

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="#FFFFFFFF"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
</vector>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="4dp" />
<solid android:color="@color/mastodonC4" />
</shape>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="4dp" />
<solid android:color="@color/mastodonC4" />
</shape>

View File

@ -510,7 +510,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:src="@drawable/ic_remove_red_eye"
android:src="@drawable/ic_remove_red_eye_img"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
</RelativeLayout>
@ -547,7 +547,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:src="@drawable/ic_remove_red_eye"
android:src="@drawable/ic_remove_red_eye_img"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
</RelativeLayout>
@ -730,8 +730,8 @@
android:id="@+id/fetch_more"
android:visibility="gone"
android:textAllCaps="false"
android:drawableLeft="@drawable/ic_expand_more"
android:drawableStart="@drawable/ic_expand_more"
android:drawableLeft="@drawable/ic_fetch_more"
android:drawableStart="@drawable/ic_fetch_more"
android:gravity="center"
android:layout_gravity="center"
android:drawablePadding="5dp"

View File

@ -477,7 +477,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:src="@drawable/ic_remove_red_eye"
android:src="@drawable/ic_remove_red_eye_img"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
</RelativeLayout>
@ -514,7 +514,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:src="@drawable/ic_remove_red_eye"
android:src="@drawable/ic_remove_red_eye_img"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
</RelativeLayout>
@ -740,8 +740,8 @@
android:id="@+id/fetch_more"
android:visibility="gone"
android:textAllCaps="false"
android:drawableLeft="@drawable/ic_expand_more"
android:drawableStart="@drawable/ic_expand_more"
android:drawableLeft="@drawable/ic_fetch_more"
android:drawableStart="@drawable/ic_fetch_more"
android:gravity="center"
android:layout_gravity="center"
android:drawablePadding="5dp"

View File

@ -400,7 +400,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:src="@drawable/ic_remove_red_eye"
android:src="@drawable/ic_remove_red_eye_img"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
</RelativeLayout>
@ -437,7 +437,7 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:src="@drawable/ic_remove_red_eye"
android:src="@drawable/ic_remove_red_eye_img"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
</RelativeLayout>
@ -637,8 +637,8 @@
android:id="@+id/fetch_more"
android:visibility="gone"
android:textAllCaps="false"
android:drawableLeft="@drawable/ic_expand_more"
android:drawableStart="@drawable/ic_expand_more"
android:drawableLeft="@drawable/ic_fetch_more"
android:drawableStart="@drawable/ic_fetch_more"
android:gravity="center"
android:layout_gravity="center"
android:drawablePadding="5dp"