Screenshots managed with drawers

This commit is contained in:
tom79 2017-09-18 20:32:36 +02:00
parent 8ef7a2cfd1
commit 6faf3b5780
3 changed files with 322 additions and 373 deletions

View File

@ -57,6 +57,7 @@ public class Status implements Parcelable {
private boolean isTranslated = false;
private boolean isTranslationShown = false;
private boolean isNew = false;
private boolean isTakingScreenShot = false;
protected Status(Parcel in) {
id = in.readString();
@ -361,4 +362,12 @@ public class Status implements Parcelable {
public void setNew(boolean aNew) {
isNew = aNew;
}
public boolean isTakingScreenShot() {
return isTakingScreenShot;
}
public void setTakingScreenShot(boolean takingScreenShot) {
isTakingScreenShot = takingScreenShot;
}
}

View File

@ -200,7 +200,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.status_show_more = (Button) convertView.findViewById(R.id.status_show_more);
holder.status_more = (ImageView) convertView.findViewById(R.id.status_more);
holder.status_reblog_user = (TextView) convertView.findViewById(R.id.status_reblog_user);
holder.status_action_container = (LinearLayout) convertView.findViewById(R.id.status_action_container);
holder.status_prev1 = (ImageView) convertView.findViewById(R.id.status_prev1);
holder.status_prev2 = (ImageView) convertView.findViewById(R.id.status_prev2);
holder.status_prev3 = (ImageView) convertView.findViewById(R.id.status_prev3);
@ -278,7 +277,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.loader_replies.setVisibility(View.GONE);
holder.status_replies.setVisibility(View.GONE);
}
}
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4);
if( status.isNew())
@ -287,14 +285,12 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.new_element.setVisibility(View.INVISIBLE);
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_reply.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_reply.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12*textSizePercent/100);
@ -303,35 +299,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 && !status.isSpoilerShown()){
holder.status_content_container.setVisibility(View.GONE);
holder.status_spoiler_container.setVisibility(View.VISIBLE);
holder.status_spoiler_button.setVisibility(View.VISIBLE);
holder.status_spoiler.setVisibility(View.VISIBLE);
}else {
holder.status_spoiler_button.setVisibility(View.GONE);
holder.status_content_container.setVisibility(View.VISIBLE);
if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 )
holder.status_spoiler_container.setVisibility(View.VISIBLE);
else
holder.status_spoiler_container.setVisibility(View.GONE);
}
if( status.getSpoiler_text() != null)
holder.status_spoiler.setText(status.getSpoiler_text());
//Spoiler opens
holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
status.setSpoilerShown(true);
holder.status_spoiler_button.setVisibility(View.GONE);
statusListAdapter.notifyDataSetChanged();
}
});
if( translator != Helper.TRANS_NONE && currentLocale != null && status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale)){
holder.status_translate.setVisibility(View.VISIBLE);
}else {
holder.status_translate.setVisibility(View.GONE);
}
switch (translator)
{
@ -353,6 +321,376 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
break;
}
//Manages theme for icon colors
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK){
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_translate,R.color.dark_text);
}else {
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.black);
changeDrawableColor(context, R.drawable.ic_photo,R.color.white);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.white);
changeDrawableColor(context, R.drawable.ic_translate,R.color.white);
}
//Redraws top icons (boost/reply)
final float scale = context.getResources().getDisplayMetrics().density;
if( (status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null")) ){
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply);
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);
}else if( status.getReblog() != null){
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black);
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);
}else{
holder.status_account_displayname.setCompoundDrawables( null, null, null, null);
}
String content;
final String displayName;
final String username;
final String ppurl;
if( status.getReblog() != null){
content = status.getReblog().getContent();
displayName = Helper.shortnameToUnicode(status.getReblog().getAccount().getDisplay_name(), true);
username = status.getReblog().getAccount().getUsername();
holder.status_reblog_user.setText(displayName + " " +String.format("@%s",username));
ppurl = status.getReblog().getAccount().getAvatar();
holder.status_reblog_user.setVisibility(View.VISIBLE);
holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername()));
holder.status_account_username.setText( "");
}else {
ppurl = status.getAccount().getAvatar();
content = status.getContent();
displayName = Helper.shortnameToUnicode(status.getAccount().getDisplay_name(), true);
username = status.getAccount().getUsername();
holder.status_reblog_user.setVisibility(View.GONE);
holder.status_account_displayname.setText(displayName);
holder.status_account_username.setText(String.format("@%s",username));
}
if( status.getContent_translated() != null && status.getContent_translated().length() > 0){
holder.status_content_translated.setMovementMethod(null);
SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(),
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), false);
holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE);
holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.status_content_translated.setFocusableInTouchMode(true);
return false;
}
});
holder.status_content_translated.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.status_content_translated.setFocusableInTouchMode(false);
holder.status_content_translated.clearFocus();
}
return false;
}
});
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
}
content = content.replaceAll("</p>","<br/><br/>");
content = content.replaceAll("<p>","");
if( content.endsWith("<br/><br/>") )
content = content.substring(0,content.length() -10);
holder.status_content.setMovementMethod(null);
final SpannableString spannableString = Helper.clickableElements(context,content,
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), true);
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.status_content.setFocusableInTouchMode(true);
return false;
}
});
holder.status_content.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.status_content.setFocusableInTouchMode(false);
holder.status_content.clearFocus();
}
return false;
}
});
holder.status_content.setMovementMethod(LinkMovementMethod.getInstance());
if( status.getReblog() == null)
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
else
holder.status_favorite_count.setText(String.valueOf(status.getReblog().getFavourites_count()));
if( status.getReblog() == null)
holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count()));
else
holder.status_reblog_count.setText(String.valueOf(status.getReblog().getReblogs_count()));
holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at()));
if( status.getReblog() != null) {
imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options);
imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options);
holder.status_account_profile_boost.setVisibility(View.VISIBLE);
holder.status_account_profile_boost_by.setVisibility(View.VISIBLE);
holder.status_account_profile.setVisibility(View.GONE);
}else{
imageLoader.displayImage(ppurl, holder.status_account_profile, options);
holder.status_account_profile_boost.setVisibility(View.GONE);
holder.status_account_profile_boost_by.setVisibility(View.GONE);
holder.status_account_profile.setVisibility(View.VISIBLE);
}
if( status.isTakingScreenShot()){
holder.status_document_container.setVisibility(View.GONE);
holder.status_content.setVisibility(View.VISIBLE);
holder.status_content_translated_container.setVisibility(View.GONE);
holder.status_spoiler_button.setVisibility(View.GONE);
holder.status_content_container.setVisibility(View.VISIBLE);
holder.status_translate.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
}else {
if( translator != Helper.TRANS_NONE && currentLocale != null && status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale)){
holder.status_translate.setVisibility(View.VISIBLE);
}else {
holder.status_translate.setVisibility(View.GONE);
}
if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 && !status.isSpoilerShown()){
holder.status_content_container.setVisibility(View.GONE);
holder.status_spoiler_container.setVisibility(View.VISIBLE);
holder.status_spoiler_button.setVisibility(View.VISIBLE);
holder.status_spoiler.setVisibility(View.VISIBLE);
}else {
holder.status_spoiler_button.setVisibility(View.GONE);
holder.status_content_container.setVisibility(View.VISIBLE);
if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 )
holder.status_spoiler_container.setVisibility(View.VISIBLE);
else
holder.status_spoiler_container.setVisibility(View.GONE);
}
if( status.getSpoiler_text() != null)
holder.status_spoiler.setText(status.getSpoiler_text());
if( status.getReblog() == null) {
if (status.getMedia_attachments().size() < 1) {
holder.status_document_container.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
loadAttachments(status, holder);
holder.status_show_more.setVisibility(View.GONE);
status.setAttachmentShown(true);
} else {
//Text depending if toots is sensitive or not
String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
holder.status_show_more.setText(textShowMore);
if (!status.isAttachmentShown()) {
holder.status_show_more.setVisibility(View.VISIBLE);
holder.status_document_container.setVisibility(View.GONE);
} else {
loadAttachments(status, holder);
}
}
}
}else { //Attachments for reblogs
if (status.getReblog().getMedia_attachments().size() < 1) {
holder.status_document_container.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
if (!status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
loadAttachments(status.getReblog(), holder);
holder.status_show_more.setVisibility(View.GONE);
status.getReblog().setAttachmentShown(true);
} else {
//Text depending if toots is sensitive or not
String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
holder.status_show_more.setText(textShowMore);
if (!status.isAttachmentShown()) {
holder.status_show_more.setVisibility(View.VISIBLE);
holder.status_document_container.setVisibility(View.GONE);
} else {
loadAttachments(status.getReblog(), holder);
}
}
}
}
//Toot was translated and user asked to see it
if( status.isTranslationShown()){
holder.status_content.setVisibility(View.GONE);
holder.status_content_translated_container.setVisibility(View.VISIBLE);
}else { //Toot is not translated
holder.status_content.setVisibility(View.VISIBLE);
holder.status_content_translated_container.setVisibility(View.GONE);
}
switch (status.getVisibility()){
case "direct":
case "private":
holder.status_reblog_count.setVisibility(View.GONE);
break;
case "public":
case "unlisted":
holder.status_reblog_count.setVisibility(View.VISIBLE);
break;
default:
holder.status_reblog_count.setVisibility(View.VISIBLE);
}
switch (status.getVisibility()){
case "public":
holder.status_privacy.setImageResource(R.drawable.ic_action_globe);
break;
case "unlisted":
holder.status_privacy.setImageResource(R.drawable.ic_action_lock_open);
break;
case "private":
holder.status_privacy.setImageResource(R.drawable.ic_action_lock_closed);
break;
case "direct":
holder.status_privacy.setImageResource(R.drawable.ic_local_post_office);
break;
}
Drawable imgFav, imgReblog;
if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited()))
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow);
else
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_black);
if( status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_yellow);
else
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black);
imgFav.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
imgReblog.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null);
holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null);
if( theme == Helper.THEME_LIGHT) {
holder.status_show_more.setTextColor(ContextCompat.getColor(context, R.color.white));
holder.status_spoiler_button.setTextColor(ContextCompat.getColor(context, R.color.white));
}
boolean isOwner = status.getAccount().getId().equals(userId);
// Pinning toots is only available on Mastodon 1._6_.0 instances.
if (isOwner && Helper.canPin && (status.getVisibility().equals("public") || status.getVisibility().equals("unlisted"))) {
Drawable imgPin;
if( status.isPinned())
imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow);
else
imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_dark);
imgPin.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
holder.status_pin.setImageDrawable(imgPin);
holder.status_pin.setVisibility(View.VISIBLE);
}
else {
holder.status_pin.setVisibility(View.GONE);
}
}
//Click on a conversation
if( type != RetrieveFeedsAsyncTask.Type.CONTEXT ){
holder.status_content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if( status.getReblog() == null)
b.putString("statusId", status.getId());
else
b.putString("statusId", status.getReblog().getId());
intent.putExtras(b);
context.startActivity(intent);
}
});
holder.card_status_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if( status.getReblog() == null)
b.putString("statusId", status.getId());
else
b.putString("statusId", status.getReblog().getId());
intent.putExtras(b);
context.startActivity(intent);
}
});
}else {
if( theme == Helper.THEME_LIGHT){
if( position == ShowConversationActivity.position){
holder.main_container.setBackgroundResource(R.color.mastodonC3_);
}else {
holder.main_container.setBackgroundResource(R.color.mastodonC3__);
}
}else {
if( position == ShowConversationActivity.position){
holder.main_container.setBackgroundResource(R.color.mastodonC1_);
}else {
holder.main_container.setBackgroundResource(R.color.mastodonC1);
}
}
}
holder.status_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
if( status.getReblog() != null )
b.putParcelable("tootReply", status.getReblog());
else
b.putParcelable("tootReply", status);
intent.putExtras(b); //Put your id to your next Intent
context.startActivity(intent);
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
try {
//Avoid to open multi activities when replying in a conversation
((ShowConversationActivity)context).finish();
}catch (Exception ignored){}
}
}
});
holder.status_translate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -435,318 +773,15 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
context.startActivity(browserIntent);
}
});
//Toot was translated and user asked to see it
if( status.isTranslationShown()){
holder.status_content.setVisibility(View.GONE);
holder.status_content_translated_container.setVisibility(View.VISIBLE);
}else { //Toot is not translated
holder.status_content.setVisibility(View.VISIBLE);
holder.status_content_translated_container.setVisibility(View.GONE);
}
//Manages theme for icon colors
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_DARK){
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text);
changeDrawableColor(context, R.drawable.ic_translate,R.color.dark_text);
}else {
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_more,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black);
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black);
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black);
changeDrawableColor(context, R.drawable.ic_action_pin_dark, R.color.black);
changeDrawableColor(context, R.drawable.ic_photo,R.color.white);
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.white);
changeDrawableColor(context, R.drawable.ic_translate,R.color.white);
}
//Redraws top icons (boost/reply)
final float scale = context.getResources().getDisplayMetrics().density;
if( (status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null")) ){
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply);
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);
}else if( status.getReblog() != null){
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black);
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);
}else{
holder.status_account_displayname.setCompoundDrawables( null, null, null, null);
}
//Click on a conversation
if( type != RetrieveFeedsAsyncTask.Type.CONTEXT ){
holder.status_content.setOnClickListener(new View.OnClickListener() {
//Spoiler opens
holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if( status.getReblog() == null)
b.putString("statusId", status.getId());
else
b.putString("statusId", status.getReblog().getId());
intent.putExtras(b);
context.startActivity(intent);
status.setSpoilerShown(true);
holder.status_spoiler_button.setVisibility(View.GONE);
statusListAdapter.notifyDataSetChanged();
}
});
holder.card_status_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ShowConversationActivity.class);
Bundle b = new Bundle();
if( status.getReblog() == null)
b.putString("statusId", status.getId());
else
b.putString("statusId", status.getReblog().getId());
intent.putExtras(b);
context.startActivity(intent);
}
});
}else {
if( theme == Helper.THEME_LIGHT){
if( position == ShowConversationActivity.position){
holder.main_container.setBackgroundResource(R.color.mastodonC3_);
}else {
holder.main_container.setBackgroundResource(R.color.mastodonC3__);
}
}else {
if( position == ShowConversationActivity.position){
holder.main_container.setBackgroundResource(R.color.mastodonC1_);
}else {
holder.main_container.setBackgroundResource(R.color.mastodonC1);
}
}
}
String content;
final String displayName;
final String username;
final String ppurl;
if( status.getReblog() != null){
content = status.getReblog().getContent();
displayName = Helper.shortnameToUnicode(status.getReblog().getAccount().getDisplay_name(), true);
username = status.getReblog().getAccount().getUsername();
holder.status_reblog_user.setText(displayName + " " +String.format("@%s",username));
ppurl = status.getReblog().getAccount().getAvatar();
holder.status_reblog_user.setVisibility(View.VISIBLE);
holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername()));
holder.status_account_username.setText( "");
}else {
ppurl = status.getAccount().getAvatar();
content = status.getContent();
displayName = Helper.shortnameToUnicode(status.getAccount().getDisplay_name(), true);
username = status.getAccount().getUsername();
holder.status_reblog_user.setVisibility(View.GONE);
holder.status_account_displayname.setText(displayName);
holder.status_account_username.setText(String.format("@%s",username));
}
holder.status_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
if( status.getReblog() != null )
b.putParcelable("tootReply", status.getReblog());
else
b.putParcelable("tootReply", status);
intent.putExtras(b); //Put your id to your next Intent
context.startActivity(intent);
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
try {
//Avoid to open multi activities when replying in a conversation
((ShowConversationActivity)context).finish();
}catch (Exception ignored){}
}
}
});
if( status.getContent_translated() != null && status.getContent_translated().length() > 0){
holder.status_content_translated.setMovementMethod(null);
SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(),
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), false);
holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE);
holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.status_content_translated.setFocusableInTouchMode(true);
return false;
}
});
holder.status_content_translated.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.status_content_translated.setFocusableInTouchMode(false);
holder.status_content_translated.clearFocus();
}
return false;
}
});
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
}
content = content.replaceAll("</p>","<br/><br/>");
content = content.replaceAll("<p>","");
if( content.endsWith("<br/><br/>") )
content = content.substring(0,content.length() -10);
holder.status_content.setMovementMethod(null);
final SpannableString spannableString = Helper.clickableElements(context,content,
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), true);
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.status_content.setFocusableInTouchMode(true);
return false;
}
});
holder.status_content.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.status_content.setFocusableInTouchMode(false);
holder.status_content.clearFocus();
}
return false;
}
});
holder.status_content.setMovementMethod(LinkMovementMethod.getInstance());
if( status.getReblog() == null)
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
else
holder.status_favorite_count.setText(String.valueOf(status.getReblog().getFavourites_count()));
if( status.getReblog() == null)
holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count()));
else
holder.status_reblog_count.setText(String.valueOf(status.getReblog().getReblogs_count()));
holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at()));
if( status.getReblog() != null) {
imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options);
imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options);
holder.status_account_profile_boost.setVisibility(View.VISIBLE);
holder.status_account_profile_boost_by.setVisibility(View.VISIBLE);
holder.status_account_profile.setVisibility(View.GONE);
}else{
imageLoader.displayImage(ppurl, holder.status_account_profile, options);
holder.status_account_profile_boost.setVisibility(View.GONE);
holder.status_account_profile_boost_by.setVisibility(View.GONE);
holder.status_account_profile.setVisibility(View.VISIBLE);
}
if( status.getReblog() == null) {
if (status.getMedia_attachments().size() < 1) {
holder.status_document_container.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
loadAttachments(status, holder);
holder.status_show_more.setVisibility(View.GONE);
status.setAttachmentShown(true);
} else {
//Text depending if toots is sensitive or not
String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
holder.status_show_more.setText(textShowMore);
if (!status.isAttachmentShown()) {
holder.status_show_more.setVisibility(View.VISIBLE);
holder.status_document_container.setVisibility(View.GONE);
} else {
loadAttachments(status, holder);
}
}
}
}else { //Attachments for reblogs
if (status.getReblog().getMedia_attachments().size() < 1) {
holder.status_document_container.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
if (!status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
loadAttachments(status.getReblog(), holder);
holder.status_show_more.setVisibility(View.GONE);
status.getReblog().setAttachmentShown(true);
} else {
//Text depending if toots is sensitive or not
String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
holder.status_show_more.setText(textShowMore);
if (!status.isAttachmentShown()) {
holder.status_show_more.setVisibility(View.VISIBLE);
holder.status_document_container.setVisibility(View.GONE);
} else {
loadAttachments(status.getReblog(), holder);
}
}
}
}
switch (status.getVisibility()){
case "public":
holder.status_privacy.setImageResource(R.drawable.ic_action_globe);
break;
case "unlisted":
holder.status_privacy.setImageResource(R.drawable.ic_action_lock_open);
break;
case "private":
holder.status_privacy.setImageResource(R.drawable.ic_action_lock_closed);
break;
case "direct":
holder.status_privacy.setImageResource(R.drawable.ic_local_post_office);
break;
}
Drawable imgFav, imgReblog;
if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited()))
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow);
else
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_black);
if( status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_yellow);
else
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black);
imgFav.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
imgReblog.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null);
holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null);
if( theme == Helper.THEME_LIGHT) {
holder.status_show_more.setTextColor(ContextCompat.getColor(context, R.color.white));
holder.status_spoiler_button.setTextColor(ContextCompat.getColor(context, R.color.white));
}
boolean isOwner = status.getAccount().getId().equals(userId);
// Pinning toots is only available on Mastodon 1._6_.0 instances.
if (isOwner && Helper.canPin && (status.getVisibility().equals("public") || status.getVisibility().equals("unlisted"))) {
Drawable imgPin;
if( status.isPinned())
imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_yellow);
else
imgPin = ContextCompat.getDrawable(context, R.drawable.ic_action_pin_dark);
imgPin.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
holder.status_pin.setImageDrawable(imgPin);
holder.status_pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -757,12 +792,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
pinAction(status);
}
});
holder.status_pin.setVisibility(View.VISIBLE);
}
else {
holder.status_pin.setVisibility(View.GONE);
}
holder.status_show_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -801,7 +830,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.status_favorite_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
if( confirmation )
displayConfirmationDialog(FAVOURITE,status);
@ -809,7 +837,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
favouriteAction(status);
}
});
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -822,18 +849,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
});
switch (status.getVisibility()){
case "direct":
case "private":
holder.status_reblog_count.setVisibility(View.GONE);
break;
case "public":
case "unlisted":
holder.status_reblog_count.setVisibility(View.VISIBLE);
break;
default:
holder.status_reblog_count.setVisibility(View.VISIBLE);
}
final View finalConvertView = convertView;
holder.status_more.setOnClickListener(new View.OnClickListener() {
@ -1225,7 +1241,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
TextView status_reblog_user;
Button status_show_more;
ImageView status_more;
LinearLayout status_action_container;
LinearLayout status_document_container;
ImageView status_prev1;
ImageView status_prev2;
@ -1400,7 +1415,11 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return;
}else if( which == 3) {
status.setTakingScreenShot(true);
statusListAdapter.notifyDataSetChanged();
Bitmap bitmap = Helper.convertTootIntoBitmap(context, view);
status.setTakingScreenShot(false);
statusListAdapter.notifyDataSetChanged();
Intent intent = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
String fname = "tootmention_" + status.getId() +".jpg";
@ -1452,7 +1471,11 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return;
}else if( which == 5 ){
status.setTakingScreenShot(true);
statusListAdapter.notifyDataSetChanged();
Bitmap bitmap = Helper.convertTootIntoBitmap(context, view);
status.setTakingScreenShot(false);
statusListAdapter.notifyDataSetChanged();
Intent intent = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
String fname = "tootmention_" + status.getId() +".jpg";

View File

@ -1610,64 +1610,8 @@ public class Helper {
*/
public static Bitmap convertTootIntoBitmap(Context context, View view) {
int status_content_v = 0, status_content_translated_v = 0, yandex_translate_v = 0, google_translate_v = 0, status_content_translated_container_v = 0;
int status_spoiler_button_v = 0, status_show_more_v = 0, status_action_container_v = 0, status_content_container_v = 0, status_translate_v = 0, new_element_v = 0, notification_delete_v = 0;
int new_element_v = 0, notification_delete_v = 0;
//Removes some elements
TextView status_content = (TextView) view.findViewById(R.id.status_content);
if( status_content != null) {
status_content_v = status_content.getVisibility();
status_content.setVisibility(View.VISIBLE);
}
TextView status_content_translated = (TextView) view.findViewById(R.id.status_content_translated);
if( status_content_translated != null) {
status_content_translated_v = status_content_translated.getVisibility();
status_content_translated.setVisibility(View.GONE);
}
TextView yandex_translate = (TextView) view.findViewById(R.id.yandex_translate);
if( yandex_translate != null) {
yandex_translate_v = yandex_translate.getVisibility();
yandex_translate.setVisibility(View.GONE);
}
TextView google_translate = (TextView) view.findViewById(R.id.google_translate);
if( google_translate != null) {
google_translate_v = google_translate.getVisibility();
google_translate.setVisibility(View.GONE);
}
Button status_spoiler_button = (Button) view.findViewById(R.id.status_spoiler_button) ;
if( status_spoiler_button != null) {
status_spoiler_button_v = status_spoiler_button.getVisibility();
status_spoiler_button.setVisibility(View.GONE);
}
LinearLayout status_content_translated_container = (LinearLayout) view.findViewById(R.id.status_content_translated_container);
if( status_content_translated_container != null) {
status_content_translated_container_v = status_content_translated_container.getVisibility();
status_content_translated_container.setVisibility(View.VISIBLE);
}
LinearLayout status_action_container = (LinearLayout) view.findViewById(R.id.status_action_container);
if( status_action_container != null) {
status_action_container_v = status_action_container.getVisibility();
status_action_container.setVisibility(View.GONE);
}
LinearLayout status_content_container = (LinearLayout) view.findViewById(R.id.status_content_container);
if( status_content_container != null) {
status_content_container_v = status_content_container.getVisibility();
status_content_container.setVisibility(View.VISIBLE);
}
FloatingActionButton status_translate = (FloatingActionButton) view.findViewById(R.id.status_translate);
if( status_translate != null) {
status_translate_v = status_translate.getVisibility();
status_translate.setVisibility(View.GONE);
}
ImageView new_element = (ImageView) view.findViewById(R.id.new_element);
if( new_element != null) {
new_element_v = new_element.getVisibility();
@ -1679,12 +1623,6 @@ public class Helper {
notification_delete_v = notification_delete.getVisibility();
notification_delete.setVisibility(View.GONE);
}
Button status_show_more = (Button) view.findViewById(R.id.status_show_more);
if( status_show_more != null){
status_show_more_v = status_show_more.getVisibility();
status_show_more.setVisibility(View.GONE);
}
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable =view.getBackground();
@ -1701,31 +1639,10 @@ public class Helper {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
canvas.drawText("Via #Mastalab", view.getWidth()-230, view.getHeight() - 35, paint);
//Restores initial visibilities
if( status_content != null)
status_content.setVisibility(status_content_v);
if( status_content_translated != null)
status_content_translated.setVisibility(status_content_translated_v);
if( yandex_translate != null)
yandex_translate.setVisibility(yandex_translate_v);
if( google_translate != null)
google_translate.setVisibility(google_translate_v);
if( status_content_translated_container != null)
status_content_translated_container.setVisibility(status_content_translated_container_v);
if( status_action_container != null)
status_action_container.setVisibility(status_action_container_v);
if( status_content_container != null)
status_content_container.setVisibility(status_content_container_v);
if( status_translate != null)
status_translate.setVisibility(status_translate_v);
if( new_element != null)
new_element.setVisibility(new_element_v);
if( notification_delete != null)
notification_delete.setVisibility(notification_delete_v);
if( status_spoiler_button != null)
status_spoiler_button.setVisibility(status_spoiler_button_v);
if( status_show_more != null)
status_show_more.setVisibility(status_show_more_v);
return returnedBitmap;
}