fedilab-Android-App/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java

2242 lines
129 KiB
Java
Raw Normal View History

2017-05-05 16:36:04 +02:00
package fr.gouv.etalab.mastodon.drawers;
/* Copyright 2017 Thomas Schneider
*
2017-07-10 10:33:24 +02:00
* This file is a part of Mastalab
2017-05-05 16:36:04 +02:00
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
2017-07-10 10:33:24 +02:00
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2017-05-05 16:36:04 +02:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2017-08-04 11:11:27 +02:00
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
2017-05-05 16:36:04 +02:00
* see <http://www.gnu.org/licenses>. */
2017-10-24 11:29:56 +02:00
import android.annotation.SuppressLint;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
2017-09-16 12:10:01 +02:00
import android.graphics.Bitmap;
2017-09-19 19:21:58 +02:00
import android.os.Handler;
import android.support.annotation.NonNull;
2017-08-15 18:07:23 +02:00
import android.support.v7.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
2017-05-05 16:36:04 +02:00
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
2017-05-05 16:36:04 +02:00
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
2017-05-05 16:36:04 +02:00
import android.support.v4.content.ContextCompat;
2017-10-29 09:48:44 +01:00
import android.support.v7.widget.PopupMenu;
2017-10-14 14:36:48 +02:00
import android.support.v7.widget.RecyclerView;
2017-05-05 16:36:04 +02:00
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
2017-10-15 11:16:43 +02:00
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
2017-08-15 18:23:15 +02:00
import android.util.TypedValue;
2017-05-05 16:36:04 +02:00
import android.view.LayoutInflater;
import android.view.MenuItem;
2018-08-30 17:49:56 +02:00
import android.view.MotionEvent;
2017-05-05 16:36:04 +02:00
import android.view.View;
import android.view.ViewGroup;
2017-12-26 09:09:51 +01:00
import android.webkit.WebView;
import android.webkit.WebViewClient;
2017-05-05 16:36:04 +02:00
import android.widget.Button;
import android.widget.DatePicker;
2017-05-05 16:36:04 +02:00
import android.widget.EditText;
2017-12-26 09:09:51 +01:00
import android.widget.FrameLayout;
import android.widget.ImageButton;
2017-05-05 16:36:04 +02:00
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
2017-12-02 11:02:25 +01:00
import com.bumptech.glide.Glide;
2018-10-29 18:32:55 +01:00
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
2017-12-25 12:06:35 +01:00
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
2018-10-29 18:32:55 +01:00
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
2017-11-29 15:06:30 +01:00
import com.github.stom79.mytransl.MyTransL;
import com.github.stom79.mytransl.client.HttpsConnectionException;
import com.github.stom79.mytransl.client.Results;
import com.github.stom79.mytransl.translate.Translate;
import java.io.File;
import java.io.FileOutputStream;
2017-05-05 16:36:04 +02:00
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
2017-05-05 16:36:04 +02:00
import java.util.List;
2017-08-21 17:32:09 +02:00
import java.util.regex.Matcher;
2017-10-15 11:16:43 +02:00
import java.util.regex.Pattern;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
import fr.gouv.etalab.mastodon.activities.MediaActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.activities.TootInfoActivity;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Application;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
2018-01-21 09:38:03 +01:00
import fr.gouv.etalab.mastodon.client.Entities.Card;
2017-11-01 19:19:37 +01:00
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
import fr.gouv.etalab.mastodon.client.Entities.Error;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.client.Entities.Status;
2017-12-06 16:56:59 +01:00
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
2017-10-04 10:23:12 +02:00
import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.CustomTextView;
import fr.gouv.etalab.mastodon.helper.Helper;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
2018-01-21 09:38:03 +01:00
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveCardInterface;
2017-10-20 19:58:46 +02:00
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
2017-10-28 10:10:50 +02:00
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
2018-08-14 14:33:52 +02:00
import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO;
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
2018-09-25 18:37:03 +02:00
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
2018-05-11 11:28:05 +02:00
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK;
2018-10-31 10:52:23 +01:00
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
2017-07-01 15:24:28 +02:00
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
2018-01-26 11:13:07 +01:00
import static fr.gouv.etalab.mastodon.helper.Helper.getLiveInstance;
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 24/04/2017.
* Adapter for Status
*/
2018-09-14 19:12:39 +02:00
public class StatusListAdapter extends RecyclerView.Adapter implements OnPostActionInterface, OnRetrieveFeedsInterface, OnRetrieveEmojiInterface, OnRetrieveRepliesInterface, OnRetrieveCardInterface {
2017-05-05 16:36:04 +02:00
private Context context;
private List<Status> statuses;
private LayoutInflater layoutInflater;
private boolean isOnWifi;
2017-08-25 16:08:40 +02:00
private int translator;
2017-05-05 16:36:04 +02:00
private int behaviorWithAttachments;
private StatusListAdapter statusListAdapter;
private RetrieveFeedsAsyncTask.Type type;
private String targetedId;
private final int DISPLAYED_STATUS = 1;
private final int FOCUSED_STATUS = 2;
2018-05-12 09:41:47 +02:00
private final int COMPACT_STATUS = 3;
private int conversationPosition;
2018-01-05 09:46:59 +01:00
private List<String> timedMute;
2018-08-14 14:33:52 +02:00
private boolean redraft;
2018-08-18 20:12:37 +02:00
private Status toot;
2017-08-25 16:08:40 +02:00
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
2017-10-14 14:36:48 +02:00
super();
2017-05-05 16:36:04 +02:00
this.context = context;
this.statuses = statuses;
this.isOnWifi = isOnWifi;
this.behaviorWithAttachments = behaviorWithAttachments;
layoutInflater = LayoutInflater.from(this.context);
statusListAdapter = this;
this.type = type;
this.targetedId = targetedId;
2017-08-25 16:08:40 +02:00
this.translator = translator;
2018-08-14 14:33:52 +02:00
redraft = false;
2017-05-05 16:36:04 +02:00
}
public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
this.context = context;
this.statuses = statuses;
this.isOnWifi = isOnWifi;
this.behaviorWithAttachments = behaviorWithAttachments;
layoutInflater = LayoutInflater.from(this.context);
statusListAdapter = this;
this.type = RetrieveFeedsAsyncTask.Type.CONTEXT;
this.conversationPosition = position;
this.targetedId = targetedId;
this.translator = translator;
2018-08-14 14:33:52 +02:00
redraft = false;
}
2017-05-05 16:36:04 +02:00
2018-01-05 09:46:59 +01:00
public void updateMuted(List<String> timedMute){
this.timedMute = timedMute;
}
2017-05-05 16:36:04 +02:00
@Override
2017-10-14 14:36:48 +02:00
public long getItemId(int position) {
return position;
2017-05-05 16:36:04 +02:00
}
@Override
2017-10-14 14:36:48 +02:00
public int getItemCount() {
return statuses.size();
2017-05-05 16:36:04 +02:00
}
private Status getItemAt(int position){
if( statuses.size() > position)
return statuses.get(position);
else
return null;
}
2017-10-28 10:10:50 +02:00
@Override
public void onRetrieveReplies(APIResponse apiResponse) {
2017-10-28 10:10:50 +02:00
if( apiResponse.getError() != null || apiResponse.getStatuses() == null || apiResponse.getStatuses().size() == 0){
return;
}
List<Status> modifiedStatus = apiResponse.getStatuses();
notifyStatusChanged(modifiedStatus.get(0));
2017-10-28 10:10:50 +02:00
}
2017-10-14 14:36:48 +02:00
private class ViewHolderEmpty extends RecyclerView.ViewHolder{
ViewHolderEmpty(View itemView) {
super(itemView);
}
2017-05-05 16:36:04 +02:00
}
2018-01-25 13:47:34 +01:00
@Override
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
2018-01-25 13:47:34 +01:00
super.onViewAttachedToWindow(holder);
2018-05-12 09:41:47 +02:00
if( holder.getItemViewType() == DISPLAYED_STATUS || holder.getItemViewType() == COMPACT_STATUS) {
final ViewHolder viewHolder = (ViewHolder) holder;
// Bug workaround for losing text selection ability, see:
// https://code.google.com/p/android/issues/detail?id=208169
viewHolder.status_content.setEnabled(false);
viewHolder.status_content.setEnabled(true);
viewHolder.status_spoiler.setEnabled(false);
viewHolder.status_spoiler.setEnabled(true);
}
2018-01-25 13:47:34 +01:00
}
2017-10-14 14:36:48 +02:00
class ViewHolder extends RecyclerView.ViewHolder{
LinearLayout status_content_container;
LinearLayout status_spoiler_container;
2018-10-28 11:32:23 +01:00
CustomTextView status_spoiler;
2017-10-14 14:36:48 +02:00
Button status_spoiler_button;
2018-10-28 11:32:23 +01:00
CustomTextView status_content;
2017-10-14 14:36:48 +02:00
TextView status_content_translated;
LinearLayout status_content_translated_container;
TextView status_account_username;
2018-11-01 11:13:02 +01:00
TextView status_account_displayname, status_account_displayname_owner;
2017-10-14 14:36:48 +02:00
ImageView status_account_profile;
ImageView status_account_profile_boost;
ImageView status_account_profile_boost_by;
TextView status_favorite_count;
TextView status_reblog_count;
TextView status_toot_date;
Button status_show_more;
ImageView status_more;
LinearLayout status_document_container;
RelativeLayout status_horizontal_document_container;
2017-10-14 14:36:48 +02:00
ImageView status_prev1;
ImageView status_prev2;
ImageView status_prev3;
ImageView status_prev4;
ImageView status_prev1_play;
ImageView status_prev2_play;
ImageView status_prev3_play;
ImageView status_prev4_play;
ImageView status_prev1_h;
ImageView status_prev2_h;
ImageView status_prev3_h;
ImageView status_prev4_h;
2018-10-29 18:32:55 +01:00
LinearLayout conversation_pp_2_container, conversation_pp_3_container;
ImageView status_prev1_play_h;
ImageView status_prev2_play_h;
ImageView status_prev3_play_h;
ImageView status_prev4_play_h;
2018-10-29 18:32:55 +01:00
ImageView conversation_pp_1;
ImageView conversation_pp_2;
ImageView conversation_pp_3;
ImageView conversation_pp_4;
LinearLayout conversation_pp;
2017-10-14 14:36:48 +02:00
RelativeLayout status_prev4_container;
2017-10-28 09:23:52 +02:00
TextView status_reply;
2017-10-14 14:36:48 +02:00
ImageView status_pin;
ImageView status_privacy;
2018-09-26 14:53:41 +02:00
ImageButton status_translate, status_bookmark;
2017-10-14 14:36:48 +02:00
LinearLayout status_container2;
LinearLayout status_container3;
LinearLayout main_container;
TextView yandex_translate;
LinearLayout status_action_container;
Button fetch_more;
2017-10-14 14:36:48 +02:00
ImageView new_element;
LinearLayout status_spoiler_mention_container;
TextView status_mention_spoiler;
2017-12-20 13:57:28 +01:00
LinearLayout status_cardview;
ImageView status_cardview_image;
TextView status_cardview_title, status_cardview_content, status_cardview_url;
2017-12-26 09:09:51 +01:00
FrameLayout status_cardview_video;
WebView status_cardview_webview;
ImageView hide_preview, hide_preview_h;
TextView status_toot_app;
2018-11-07 11:03:32 +01:00
RelativeLayout webview_preview;
ImageView webview_preview_card;
2017-10-25 13:28:45 +02:00
public View getView(){
return itemView;
}
2017-10-14 14:36:48 +02:00
ViewHolder(View itemView) {
super(itemView);
2018-11-07 11:03:32 +01:00
fetch_more = itemView.findViewById(R.id.fetch_more);
webview_preview_card = itemView.findViewById(R.id.webview_preview_card);
webview_preview = itemView.findViewById(R.id.webview_preview);
status_horizontal_document_container = itemView.findViewById(R.id.status_horizontal_document_container);
2017-10-24 11:29:56 +02:00
status_document_container = itemView.findViewById(R.id.status_document_container);
status_horizontal_document_container = itemView.findViewById(R.id.status_horizontal_document_container);
2017-10-24 11:29:56 +02:00
status_content = itemView.findViewById(R.id.status_content);
status_content_translated = itemView.findViewById(R.id.status_content_translated);
status_account_username = itemView.findViewById(R.id.status_account_username);
status_account_displayname = itemView.findViewById(R.id.status_account_displayname);
2018-11-01 11:13:02 +01:00
status_account_displayname_owner = itemView.findViewById(R.id.status_account_displayname_owner);
2017-10-24 11:29:56 +02:00
status_account_profile = itemView.findViewById(R.id.status_account_profile);
status_account_profile_boost = itemView.findViewById(R.id.status_account_profile_boost);
status_account_profile_boost_by = itemView.findViewById(R.id.status_account_profile_boost_by);
status_favorite_count = itemView.findViewById(R.id.status_favorite_count);
status_reblog_count = itemView.findViewById(R.id.status_reblog_count);
status_pin = itemView.findViewById(R.id.status_pin);
status_toot_date = itemView.findViewById(R.id.status_toot_date);
status_show_more = itemView.findViewById(R.id.status_show_more);
status_more = itemView.findViewById(R.id.status_more);
status_prev1 = itemView.findViewById(R.id.status_prev1);
status_prev2 = itemView.findViewById(R.id.status_prev2);
status_prev3 = itemView.findViewById(R.id.status_prev3);
status_prev4 = itemView.findViewById(R.id.status_prev4);
status_prev1_play = itemView.findViewById(R.id.status_prev1_play);
status_prev2_play = itemView.findViewById(R.id.status_prev2_play);
status_prev3_play = itemView.findViewById(R.id.status_prev3_play);
status_prev4_play = itemView.findViewById(R.id.status_prev4_play);
status_prev1_h = itemView.findViewById(R.id.status_prev1_h);
status_prev2_h = itemView.findViewById(R.id.status_prev2_h);
status_prev3_h = itemView.findViewById(R.id.status_prev3_h);
status_prev4_h = itemView.findViewById(R.id.status_prev4_h);
status_prev1_play_h = itemView.findViewById(R.id.status_prev1_play_h);
status_prev2_play_h = itemView.findViewById(R.id.status_prev2_play_h);
status_prev3_play_h = itemView.findViewById(R.id.status_prev3_play_h);
status_prev4_play_h = itemView.findViewById(R.id.status_prev4_play_h);
2017-10-24 11:29:56 +02:00
status_container2 = itemView.findViewById(R.id.status_container2);
status_container3 = itemView.findViewById(R.id.status_container3);
status_prev4_container = itemView.findViewById(R.id.status_prev4_container);
status_reply = itemView.findViewById(R.id.status_reply);
status_privacy = itemView.findViewById(R.id.status_privacy);
status_translate = itemView.findViewById(R.id.status_translate);
status_bookmark = itemView.findViewById(R.id.status_bookmark);
2017-10-24 11:29:56 +02:00
status_content_translated_container = itemView.findViewById(R.id.status_content_translated_container);
main_container = itemView.findViewById(R.id.main_container);
status_spoiler_container = itemView.findViewById(R.id.status_spoiler_container);
status_content_container = itemView.findViewById(R.id.status_content_container);
status_spoiler = itemView.findViewById(R.id.status_spoiler);
status_spoiler_button = itemView.findViewById(R.id.status_spoiler_button);
yandex_translate = itemView.findViewById(R.id.yandex_translate);
new_element = itemView.findViewById(R.id.new_element);
status_action_container = itemView.findViewById(R.id.status_action_container);
status_spoiler_mention_container = itemView.findViewById(R.id.status_spoiler_mention_container);
status_mention_spoiler = itemView.findViewById(R.id.status_mention_spoiler);
2017-12-20 13:57:28 +01:00
status_cardview = itemView.findViewById(R.id.status_cardview);
status_cardview_image = itemView.findViewById(R.id.status_cardview_image);
status_cardview_title = itemView.findViewById(R.id.status_cardview_title);
status_cardview_content = itemView.findViewById(R.id.status_cardview_content);
status_cardview_url = itemView.findViewById(R.id.status_cardview_url);
2017-12-26 09:09:51 +01:00
status_cardview_video = itemView.findViewById(R.id.status_cardview_video);
status_cardview_webview = itemView.findViewById(R.id.status_cardview_webview);
hide_preview = itemView.findViewById(R.id.hide_preview);
hide_preview_h = itemView.findViewById(R.id.hide_preview_h);
status_toot_app = itemView.findViewById(R.id.status_toot_app);
2018-10-29 18:32:55 +01:00
conversation_pp = itemView.findViewById(R.id.conversation_pp);
conversation_pp_1 = itemView.findViewById(R.id.conversation_pp_1);
conversation_pp_2 = itemView.findViewById(R.id.conversation_pp_2);
conversation_pp_3 = itemView.findViewById(R.id.conversation_pp_3);
conversation_pp_4 = itemView.findViewById(R.id.conversation_pp_4);
conversation_pp_2_container = itemView.findViewById(R.id.conversation_pp_2_container);
conversation_pp_3_container = itemView.findViewById(R.id.conversation_pp_3_container);
2017-10-14 14:36:48 +02:00
}
}
2017-08-16 18:08:16 +02:00
2018-09-08 11:30:58 +02:00
public Status getItem(int position){
if( statuses.size() > position && position >= 0)
2018-10-26 16:24:52 +02:00
return statuses.get(position);
else return null;
2018-09-08 11:30:58 +02:00
}
@Override
public int getItemViewType(int position) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
2018-09-26 13:45:13 +02:00
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition)
return FOCUSED_STATUS;
2018-09-25 18:37:03 +02:00
else
2018-05-12 09:41:47 +02:00
return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS;
}
2017-10-04 10:23:12 +02:00
@NonNull
2017-10-14 14:36:48 +02:00
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
2017-10-14 14:36:48 +02:00
if( viewType == DISPLAYED_STATUS)
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_status, parent, false));
2018-05-12 09:41:47 +02:00
else if(viewType == COMPACT_STATUS)
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_status_compact, parent, false));
else if(viewType == FOCUSED_STATUS)
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_status_focused, parent, false));
2017-10-14 14:36:48 +02:00
else
2017-10-24 11:29:56 +02:00
return new ViewHolderEmpty(layoutInflater.inflate(R.layout.drawer_empty, parent, false));
2017-10-14 14:36:48 +02:00
}
2017-10-04 10:23:12 +02:00
2018-10-25 14:09:41 +02:00
2017-12-26 09:09:51 +01:00
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int position) {
2017-10-14 14:36:48 +02:00
2018-05-12 09:41:47 +02:00
if( viewHolder.getItemViewType() == DISPLAYED_STATUS || viewHolder.getItemViewType() == FOCUSED_STATUS || viewHolder.getItemViewType() == COMPACT_STATUS){
2017-10-14 14:36:48 +02:00
final ViewHolder holder = (ViewHolder) viewHolder;
final Status status = statuses.get(position);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
2017-10-28 10:10:50 +02:00
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
2018-11-01 15:52:22 +01:00
boolean displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false);
boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
2018-11-03 16:22:54 +01:00
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
2018-11-03 16:22:54 +01:00
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !isCompactMode && displayBookmarkButton)
holder.status_bookmark.setVisibility(View.VISIBLE);
else
holder.status_bookmark.setVisibility(View.GONE);
holder.status_reply.setText("");
//Display a preview for accounts that have replied *if enabled and only for home timeline*
2018-09-09 14:19:24 +02:00
2018-02-15 15:27:46 +01:00
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
2018-02-17 18:08:06 +01:00
Status statusBookmarked = new StatusCacheDAO(context, db).getStatus(StatusCacheDAO.BOOKMARK_CACHE, status.getId());
2018-02-15 15:27:46 +01:00
if( statusBookmarked != null)
status.setBookmarked(true);
else
status.setBookmarked(false);
2018-05-11 11:28:05 +02:00
if( status.isNew())
holder.new_element.setVisibility(View.VISIBLE);
else
2017-10-15 11:57:03 +02:00
holder.new_element.setVisibility(View.GONE);
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
2017-12-03 14:17:57 +01:00
final boolean trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false);
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);
2018-11-03 16:22:54 +01:00
2018-10-25 14:09:41 +02:00
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) != FOCUSED_STATUS && position != 0 ){
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
2018-11-03 17:42:59 +01:00
params.setMargins((int)Helper.convertDpToPixel(25, context), 0, 0, 0);
2018-10-25 14:09:41 +02:00
holder.main_container.setLayoutParams(params);
}else if(type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) == FOCUSED_STATUS && position != 0 ){
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
2018-11-03 17:42:59 +01:00
params.setMargins((int)Helper.convertDpToPixel(20, context), 0, 0, 0);
2018-10-25 14:09:41 +02:00
holder.main_container.setLayoutParams(params);
}
2018-08-29 16:15:11 +02:00
if( getItemViewType(position) == FOCUSED_STATUS ) {
holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16*textSizePercent/100);
holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16 * textSizePercent / 100);
holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100);
holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16*textSizePercent/100);
}else {
holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100);
holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12 * textSizePercent / 100);
holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12*textSizePercent/100);
holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
}
2018-08-29 16:15:11 +02:00
holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14*textSizePercent/100);
2017-11-03 15:00:53 +01:00
switch (translator) {
case Helper.TRANS_NONE:
holder.yandex_translate.setVisibility(View.GONE);
break;
case Helper.TRANS_YANDEX:
holder.yandex_translate.setVisibility(View.VISIBLE);
break;
default:
2018-08-14 16:20:53 +02:00
holder.yandex_translate.setVisibility(View.GONE);
}
//Manages theme for icon colors
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2018-05-11 11:28:05 +02:00
if( theme == Helper.THEME_BLACK)
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.dark_icon);
else
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4);
2018-05-12 09:41:47 +02:00
if( getItemViewType(position) == COMPACT_STATUS )
holder.status_privacy.setVisibility(View.GONE);
else
holder.status_privacy.setVisibility(View.VISIBLE);
2018-02-09 17:39:09 +01:00
boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
2018-09-15 09:33:53 +02:00
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
2018-11-02 14:42:29 +01:00
if( theme == Helper.THEME_BLACK){
2017-10-15 10:24:38 +02:00
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_icon);
2017-11-02 14:06:59 +01:00
changeDrawableColor(context, holder.status_more, R.color.dark_icon);
changeDrawableColor(context, holder.status_privacy, R.color.dark_icon);
2017-10-28 17:15:06 +02:00
changeDrawableColor(context, R.drawable.ic_repeat,R.color.dark_icon);
2018-11-02 14:42:29 +01:00
changeDrawableColor(context, R.drawable.ic_repeat_head_toot,R.color.black_text_toot_header);
changeDrawableColor(context, R.drawable.ic_star_border,R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_plus_one,R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.dark_icon);
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);
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));
2018-11-08 18:40:02 +01:00
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));
2018-11-02 14:42:29 +01:00
}else if( theme == Helper.THEME_DARK ){
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_icon);
changeDrawableColor(context, holder.status_more, R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_repeat,R.color.dark_icon);
changeDrawableColor(context, holder.status_privacy, R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_repeat_head_toot,R.color.dark_text_toot_header);
2017-10-28 17:15:06 +02:00
changeDrawableColor(context, R.drawable.ic_star_border,R.color.dark_icon);
changeDrawableColor(context, R.drawable.ic_plus_one,R.color.dark_icon);
2017-10-28 19:22:02 +02:00
changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.dark_icon);
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);
2017-12-03 10:56:54 +01:00
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));
2018-11-08 18:40:02 +01:00
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));
}else {
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
2017-10-28 14:54:28 +02:00
changeDrawableColor(context, R.drawable.ic_more_horiz,R.color.black);
2017-11-02 14:06:59 +01:00
changeDrawableColor(context, holder.status_more, R.color.black);
changeDrawableColor(context, holder.status_privacy, R.color.black);
2017-10-28 17:15:06 +02:00
changeDrawableColor(context, R.drawable.ic_repeat,R.color.black);
2018-11-02 14:42:29 +01:00
changeDrawableColor(context, R.drawable.ic_repeat_head_toot,R.color.black);
changeDrawableColor(context, R.drawable.ic_plus_one,R.color.black);
2017-10-28 17:15:06 +02:00
changeDrawableColor(context, R.drawable.ic_star_border,R.color.black);
2017-10-28 19:22:02 +02:00
changeDrawableColor(context, R.drawable.ic_pin_drop, R.color.black);
2017-10-29 17:10:09 +01:00
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.black);
changeDrawableColor(context, R.drawable.ic_bookmark,R.color.black);
changeDrawableColor(context, R.drawable.ic_bookmark_border,R.color.black);
2017-12-03 10:56:54 +01:00
holder.status_favorite_count.setTextColor(ContextCompat.getColor(context, R.color.black));
holder.status_reblog_count.setTextColor(ContextCompat.getColor(context, R.color.black));
holder.status_reply.setTextColor(ContextCompat.getColor(context, R.color.black));
2018-11-08 18:40:02 +01:00
holder.status_cardview_title.setTextColor(ContextCompat.getColor(context, R.color.black));
holder.status_cardview_content.setTextColor(ContextCompat.getColor(context, R.color.black));
holder.status_cardview_url.setTextColor(ContextCompat.getColor(context, R.color.black));
2018-11-02 14:42:29 +01:00
}
if( theme == THEME_DARK) {
holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.dark_text_toot_header));
holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.dark_text_toot_header));
}else if( theme == THEME_BLACK) {
holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.black_text_toot_header));
holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.black_text_toot_header));
}else if( theme == THEME_LIGHT) {
2017-12-03 10:56:54 +01:00
holder.status_account_displayname.setTextColor(ContextCompat.getColor(context, R.color.black));
2018-11-02 14:42:29 +01:00
holder.status_toot_date.setTextColor(ContextCompat.getColor(context, R.color.black));
}
if( status.isBookmarked())
holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark));
else
holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark_border));
//Redraws top icons (boost/reply)
final float scale = context.getResources().getDisplayMetrics().density;
if( status.getReblog() != null){
2018-11-02 14:42:29 +01:00
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_repeat_head_toot);
2017-12-03 10:56:54 +01:00
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);
2018-09-09 19:34:14 +02:00
}else{
holder.status_account_displayname.setCompoundDrawables( null, null, null, null);
}
2017-07-01 15:24:28 +02:00
2017-12-03 10:56:54 +01:00
if( !status.isClickable())
status.makeClickable(context);
if( !status.isEmojiFound())
status.makeEmojis(context, StatusListAdapter.this);
2017-05-05 16:36:04 +02:00
2018-09-15 17:45:33 +02:00
holder.status_content.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) {
try{view.requestFocus();}catch (Exception ignored){}
}
return false;
}
});
//Click on a conversation
if( (getItemViewType(position) == DISPLAYED_STATUS || getItemViewType(position) == COMPACT_STATUS)) {
2018-09-15 17:45:33 +02:00
holder.status_content.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
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);
if (type == RetrieveFeedsAsyncTask.Type.CONTEXT)
((Activity) context).finish();
context.startActivity(intent);
}else {
CrossActions.doCrossConversation(context,status);
}
2018-09-15 17:45:33 +02:00
}
});
holder.main_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
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);
if (type == RetrieveFeedsAsyncTask.Type.CONTEXT)
((Activity) context).finish();
context.startActivity(intent);
}else {
CrossActions.doCrossConversation(context,status);
}
2018-09-15 17:45:33 +02:00
}
});
}
if( status.getContent().trim().equals("") || status.getContent().trim().length() == 0){
holder.status_content_container.setVisibility(View.GONE);
}else {
holder.status_content_container.setVisibility(View.VISIBLE);
}
2017-12-03 14:17:57 +01:00
holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE);
2017-12-03 14:17:57 +01:00
holder.status_spoiler.setText(status.getContentSpanCW(), TextView.BufferType.SPANNABLE);
2018-09-09 15:41:26 +02:00
holder.status_content.setMovementMethod(LinkMovementMethod.getInstance());
2018-01-25 13:47:34 +01:00
holder.status_spoiler.setMovementMethod(LinkMovementMethod.getInstance());
2018-05-12 09:41:47 +02:00
2017-12-03 11:14:52 +01:00
holder.status_translate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-05-12 09:41:47 +02:00
translateToot(status);
2017-12-03 11:14:52 +01:00
}
});
holder.status_bookmark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-02-15 15:27:46 +01:00
if( type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
status.setBookmarked(!status.isBookmarked());
2018-10-03 09:16:24 +02:00
try {
if (status.isBookmarked()) {
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
Toast.makeText(context, R.string.status_bookmarked, Toast.LENGTH_LONG).show();
} else {
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status);
Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show();
}
notifyStatusChanged(status);
}catch (Exception e){
e.printStackTrace();
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
2018-02-15 15:27:46 +01:00
}
}else {
2018-02-15 15:27:46 +01:00
int position = 0;
for (Status statustmp : statuses) {
if (statustmp.getId().equals(status.getId())) {
statuses.remove(status);
statusListAdapter.notifyItemRemoved(position);
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp);
Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show();
break;
}
position++;
}
}
}
});
2018-09-28 19:35:13 +02:00
holder.status_bookmark.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
CrossActions.doCrossBookmark(context, status, statusListAdapter);
return false;
}
});
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
2017-12-03 11:14:52 +01:00
//-------- END -> Manages translations
2018-10-25 14:09:41 +02:00
if( status.getAccount() == null) {
Account account = new AccountDAO(context, db).getAccountByID(sharedpreferences.getString(Helper.PREF_KEY_ID, null));
status.setAccount(account);
}
2017-12-03 10:56:54 +01:00
//Displays name & emoji in toot header
final String ppurl;
if( status.getReblog() != null){
ppurl = status.getReblog().getAccount().getAvatar();
2018-11-02 14:42:29 +01:00
holder.status_account_displayname.setVisibility(View.VISIBLE);
holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername()));
2018-11-01 11:13:02 +01:00
if( status.getReblog().getAccount().getDisplay_name().length() > 0)
holder.status_account_displayname_owner.setText( status.getDisplayNameSpan(), TextView.BufferType.SPANNABLE);
2018-11-01 11:13:02 +01:00
else
holder.status_account_displayname_owner.setText( status.getReblog().getAccount().getAcct().replace("@",""));
holder.status_account_displayname_owner.setVisibility(View.VISIBLE);
}else {
ppurl = status.getAccount().getAvatar();
2018-11-02 14:42:29 +01:00
holder.status_account_displayname.setVisibility(View.GONE);
if( status.getAccount().getdisplayNameSpan() == null || status.getAccount().getdisplayNameSpan().toString().trim().length() == 0)
2018-11-02 14:42:29 +01:00
holder.status_account_displayname_owner.setText(status.getAccount().getUsername().replace("@",""), TextView.BufferType.SPANNABLE);
else
2018-11-02 14:42:29 +01:00
holder.status_account_displayname_owner.setText(status.getAccount().getdisplayNameSpan(), TextView.BufferType.SPANNABLE);
}
2017-12-03 10:56:54 +01:00
//-------- END -> Displays name & emoji in toot header
2017-10-15 11:16:43 +02:00
2017-12-03 10:56:54 +01:00
//Change the color in gray for accounts in DARK Theme only
Spannable wordtoSpan;
2018-10-31 10:52:23 +01:00
Pattern hashAcct;
2018-11-01 11:13:02 +01:00
if( status.getReblog() != null) {
wordtoSpan = new SpannableString("@" + status.getReblog().getAccount().getAcct());
2018-11-01 11:13:02 +01:00
hashAcct = Pattern.compile("(@" + status.getReblog().getAccount().getAcct() + ")");
}else {
wordtoSpan = new SpannableString("@" + status.getAccount().getAcct());
hashAcct = Pattern.compile("(@" + status.getAccount().getAcct() + ")");
}
if( hashAcct != null){
2018-10-31 10:52:23 +01:00
Matcher matcherAcct = hashAcct.matcher(wordtoSpan);
while (matcherAcct.find()){
int matchStart = matcherAcct.start(1);
int matchEnd = matcherAcct.end();
if( wordtoSpan.length() >= matchEnd && matchStart < matchEnd){
if( theme == THEME_LIGHT)
2018-08-19 10:57:24 +02:00
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_icon)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2018-11-02 14:42:29 +01:00
else if( theme == THEME_DARK)
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_text_toot_header)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == THEME_BLACK)
wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_text_toot_header)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2018-08-19 10:57:24 +02:00
}
2018-10-31 10:52:23 +01:00
2017-10-15 11:16:43 +02:00
}
}
holder.status_account_username.setText(wordtoSpan);
2017-05-05 16:36:04 +02:00
2017-12-03 10:56:54 +01:00
//-------- END -> Change the color in gray for accounts in DARK Theme only
if( status.isFetchMore()) {
holder.fetch_more.setVisibility(View.VISIBLE);
holder.fetch_more.setEnabled(true);
2017-12-06 19:12:52 +01:00
}else {
holder.fetch_more.setVisibility(View.GONE);
2017-12-06 19:12:52 +01:00
}
holder.fetch_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
status.setFetchMore(false);
holder.fetch_more.setEnabled(false);
holder.fetch_more.setVisibility(View.GONE);
DisplayStatusFragment homeFragment = ((BaseMainActivity) context).getHomeFragment();
if( homeFragment != null)
homeFragment.fetchMore(status.getId());
}
});
holder.status_mention_spoiler.setText(Helper.makeMentionsClick(context,status.getMentions()), TextView.BufferType.SPANNABLE);
holder.status_mention_spoiler.setMovementMethod(LinkMovementMethod.getInstance());
2018-09-09 14:19:24 +02:00
if( getItemViewType(position) != COMPACT_STATUS ) {
2017-12-22 07:00:02 +01:00
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()));
}
2018-04-25 15:28:21 +02:00
if( getItemViewType(position) == FOCUSED_STATUS) {
String fullDate_tmp = Helper.dateDiffFull(status.getCreated_at());
String fullDate = fullDate_tmp.substring(0,1).toUpperCase() + fullDate_tmp.substring(1);
holder.status_toot_date.setText(fullDate);
}else {
holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at()));
Helper.absoluteDateTimeReveal(context, holder.status_toot_date, status.getCreated_at());
}
if( status.getReblog() != null) {
Helper.loadGiF(context, ppurl, holder.status_account_profile_boost);
Helper.loadGiF(context, status.getAccount().getAvatar(), holder.status_account_profile_boost_by);
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{
Helper.loadGiF(context, ppurl, holder.status_account_profile);
holder.status_account_profile_boost.setVisibility(View.GONE);
holder.status_account_profile_boost_by.setVisibility(View.GONE);
holder.status_account_profile.setVisibility(View.VISIBLE);
2017-09-18 20:32:36 +02:00
}
2018-10-29 18:32:55 +01:00
if( type == RetrieveFeedsAsyncTask.Type.CONVERSATION && status.getConversationProfilePicture() != null){
holder.status_account_profile.setVisibility(View.GONE);
holder.conversation_pp.setVisibility(View.VISIBLE);
if( status.getConversationProfilePicture().size() == 1) {
holder.conversation_pp_1.setVisibility(View.VISIBLE);
holder.conversation_pp_1.setScaleType(ImageView.ScaleType.CENTER_CROP);
holder.conversation_pp_2_container.setVisibility(View.GONE);
holder.conversation_pp_3_container.setVisibility(View.GONE);
holder.conversation_pp_2.setVisibility(View.GONE);
holder.conversation_pp_3.setVisibility(View.GONE);
holder.conversation_pp_4.setVisibility(View.GONE);
Glide.with(context)
.load(status.getConversationProfilePicture().get(0))
.apply(new RequestOptions().transforms(new FitCenter(), new RoundedCorners(10)))
.into(holder.conversation_pp_1);
}else if( status.getConversationProfilePicture().size() == 2) {
holder.conversation_pp_2_container.setVisibility(View.VISIBLE);
holder.conversation_pp_3_container.setVisibility(View.GONE);
holder.conversation_pp_1.setVisibility(View.VISIBLE);
holder.conversation_pp_2.setVisibility(View.VISIBLE);
holder.conversation_pp_3.setVisibility(View.GONE);
holder.conversation_pp_4.setVisibility(View.GONE);
Helper.loadGiF(context, status.getConversationProfilePicture().get(0), holder.conversation_pp_1);
Helper.loadGiF(context, status.getConversationProfilePicture().get(1), holder.conversation_pp_2);
}else if( status.getConversationProfilePicture().size() == 3) {
holder.conversation_pp_4.setVisibility(View.GONE);
holder.conversation_pp_1.setVisibility(View.VISIBLE);
holder.conversation_pp_2.setVisibility(View.VISIBLE);
holder.conversation_pp_3.setVisibility(View.VISIBLE);
holder.conversation_pp_4.setVisibility(View.GONE);
holder.conversation_pp_2_container.setVisibility(View.VISIBLE);
holder.conversation_pp_3_container.setVisibility(View.VISIBLE);
Helper.loadGiF(context, status.getConversationProfilePicture().get(0), holder.conversation_pp_1);
Helper.loadGiF(context, status.getConversationProfilePicture().get(1), holder.conversation_pp_2);
Helper.loadGiF(context, status.getConversationProfilePicture().get(2), holder.conversation_pp_3);
}else if( status.getConversationProfilePicture().size() == 4) {
holder.conversation_pp_1.setVisibility(View.VISIBLE);
holder.conversation_pp_2.setVisibility(View.VISIBLE);
holder.conversation_pp_3.setVisibility(View.VISIBLE);
holder.conversation_pp_4.setVisibility(View.VISIBLE);
holder.conversation_pp_2_container.setVisibility(View.VISIBLE);
holder.conversation_pp_3_container.setVisibility(View.VISIBLE);
Helper.loadGiF(context, status.getConversationProfilePicture().get(0), holder.conversation_pp_1);
Helper.loadGiF(context, status.getConversationProfilePicture().get(1), holder.conversation_pp_2);
Helper.loadGiF(context, status.getConversationProfilePicture().get(2), holder.conversation_pp_3);
Helper.loadGiF(context, status.getConversationProfilePicture().get(3), holder.conversation_pp_4);
}
}
2018-01-26 08:10:37 +01:00
holder.status_action_container.setVisibility(View.VISIBLE);
2018-05-12 09:41:47 +02:00
if( ( getItemViewType(position) != COMPACT_STATUS ) && (trans_forced || (translator != Helper.TRANS_NONE && currentLocale != null && status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale)))){
2018-01-26 08:10:37 +01:00
holder.status_translate.setVisibility(View.VISIBLE);
}else {
2018-01-26 08:10:37 +01:00
holder.status_translate.setVisibility(View.GONE);
}
if( expand_cw)
holder.status_spoiler_button.setVisibility(View.GONE);
2018-01-26 08:10:37 +01:00
if( status.getReblog() == null) {
if (status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 ) {
holder.status_spoiler_container.setVisibility(View.VISIBLE);
2018-02-09 17:39:09 +01:00
if( !status.isSpoilerShown() && !expand_cw) {
2018-01-26 08:10:37 +01:00
holder.status_content_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler));
}else {
2017-11-02 15:35:23 +01:00
holder.status_content_container.setVisibility(View.VISIBLE);
2017-12-25 09:45:49 +01:00
holder.status_spoiler_mention_container.setVisibility(View.GONE);
2018-01-26 08:10:37 +01:00
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler_less));
}
} else {
holder.status_spoiler_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_content_container.setVisibility(View.VISIBLE);
}
}else {
if (status.getReblog().getSpoiler_text() != null && status.getReblog().getSpoiler_text().trim().length() > 0) {
holder.status_spoiler_container.setVisibility(View.VISIBLE);
2018-02-09 17:39:09 +01:00
if( !status.isSpoilerShown() && !expand_cw) {
2018-01-26 08:10:37 +01:00
holder.status_content_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.VISIBLE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler));
}else {
2017-12-25 09:45:49 +01:00
holder.status_content_container.setVisibility(View.VISIBLE);
2018-01-26 08:10:37 +01:00
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_spoiler_button.setText(context.getString(R.string.load_attachment_spoiler_less));
2017-11-02 15:35:23 +01:00
}
2018-01-26 08:10:37 +01:00
} else {
holder.status_spoiler_container.setVisibility(View.GONE);
holder.status_spoiler_mention_container.setVisibility(View.GONE);
holder.status_content_container.setVisibility(View.VISIBLE);
}
2018-01-26 08:10:37 +01:00
}
if( status.getReblog() == null) {
if (status.getMedia_attachments().size() < 1) {
if( fullAttachement )
holder.status_horizontal_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.GONE);
2018-01-26 08:10:37 +01:00
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
2018-09-15 09:33:53 +02:00
if (expand_media || !status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
2018-01-26 08:10:37 +01:00
loadAttachments(status, holder);
2017-09-18 20:32:36 +02:00
holder.status_show_more.setVisibility(View.GONE);
2018-01-26 08:10:37 +01:00
status.setAttachmentShown(true);
2017-09-18 20:32:36 +02:00
} else {
2018-01-26 08:10:37 +01:00
//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);
if( fullAttachement )
holder.status_horizontal_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.GONE);
} else {
2018-01-26 08:10:37 +01:00
loadAttachments(status, holder);
2017-09-18 20:32:36 +02:00
}
}
2018-01-26 08:10:37 +01:00
}
}else { //Attachments for reblogs
2017-12-03 10:56:54 +01:00
2018-01-26 08:10:37 +01:00
if (status.getReblog().getMedia_attachments().size() < 1) {
if( fullAttachement )
holder.status_horizontal_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.GONE);
2018-01-26 08:10:37 +01:00
holder.status_show_more.setVisibility(View.GONE);
} else {
//If medias are loaded without any conditions or if device is on wifi
if (expand_media || !status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
2018-01-26 08:10:37 +01:00
loadAttachments(status.getReblog(), holder);
2017-09-18 20:32:36 +02:00
holder.status_show_more.setVisibility(View.GONE);
2018-04-02 09:59:31 +02:00
status.setAttachmentShown(true);
2017-09-18 20:32:36 +02:00
} else {
2018-01-26 08:10:37 +01:00
//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);
if( fullAttachement )
holder.status_horizontal_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.GONE);
} else {
2018-01-26 08:10:37 +01:00
loadAttachments(status.getReblog(), holder);
2017-09-18 20:32:36 +02:00
}
}
2017-05-05 16:36:04 +02:00
}
2018-01-26 08:10:37 +01:00
}
2017-10-12 07:22:59 +02:00
if(!fullAttachement)
holder.hide_preview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
status.setAttachmentShown(!status.isAttachmentShown());
if( status.getReblog() != null)
status.getReblog().setSensitive(true);
else
status.setSensitive(true);
2018-04-02 09:59:31 +02:00
2018-05-11 11:28:05 +02:00
if( theme == Helper.THEME_DARK || theme == Helper.THEME_BLACK)
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
else
changeDrawableColor(context, R.drawable.ic_photo,R.color.mastodonC4);
notifyStatusChanged(status);
}
});
else
holder.hide_preview_h.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
status.setAttachmentShown(!status.isAttachmentShown());
if( status.getReblog() != null)
status.getReblog().setSensitive(true);
else
status.setSensitive(true);
2018-05-11 11:28:05 +02:00
if( theme == Helper.THEME_DARK || theme == Helper.THEME_BLACK)
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
else
changeDrawableColor(context, R.drawable.ic_photo,R.color.mastodonC4);
notifyStatusChanged(status);
}
});
2018-01-25 11:24:53 +01:00
2018-01-26 08:10:37 +01:00
//Toot was translated and user asked to see it
2017-05-05 16:36:04 +02:00
2018-01-26 08:10:37 +01:00
if( status.isTranslationShown() && status.getContentSpanTranslated() != null){
holder.status_content_translated.setText(status.getContentSpanTranslated(), TextView.BufferType.SPANNABLE);
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);
}
2017-05-05 16:36:04 +02:00
2018-01-26 08:10:37 +01:00
switch (status.getVisibility()){
case "direct":
holder.status_reblog_count.setVisibility(View.GONE);
2018-11-05 19:11:46 +01:00
break;
case "private":
boolean isOwner = status.getAccount().getId().equals(userId);
if( isOwner)
holder.status_reblog_count.setVisibility(View.VISIBLE);
else
holder.status_reblog_count.setVisibility(View.GONE);
2018-01-26 08:10:37 +01:00
break;
case "public":
case "unlisted":
holder.status_reblog_count.setVisibility(View.VISIBLE);
break;
default:
holder.status_reblog_count.setVisibility(View.VISIBLE);
}
2018-01-26 08:10:37 +01:00
switch (status.getVisibility()){
case "public":
holder.status_privacy.setImageResource(R.drawable.ic_public);
break;
case "unlisted":
holder.status_privacy.setImageResource(R.drawable.ic_lock_open);
break;
case "private":
holder.status_privacy.setImageResource(R.drawable.ic_lock_outline);
break;
case "direct":
holder.status_privacy.setImageResource(R.drawable.ic_mail_outline);
break;
}
2017-05-05 16:36:04 +02:00
2018-01-26 08:10:37 +01:00
Drawable imgFav, imgReblog, imgReply;
if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) {
changeDrawableColor(context, R.drawable.ic_star,R.color.marked_icon);
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_star);
}else {
2018-05-11 11:28:05 +02:00
if( theme == THEME_DARK || theme == THEME_BLACK)
2018-01-26 08:10:37 +01:00
changeDrawableColor(context, R.drawable.ic_star_border,R.color.dark_icon);
else
changeDrawableColor(context, R.drawable.ic_star_border,R.color.black);
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_star_border);
}
2017-10-28 19:22:02 +02:00
2018-01-26 08:10:37 +01:00
if( status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged())) {
changeDrawableColor(context, R.drawable.ic_repeat_boost,R.color.boost_icon);
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_repeat_boost);
}else {
2018-05-11 11:28:05 +02:00
if( theme == THEME_DARK || theme == THEME_BLACK)
2018-01-26 08:10:37 +01:00
changeDrawableColor(context, R.drawable.ic_repeat,R.color.dark_icon);
2017-10-28 09:23:52 +02:00
else
2018-01-26 08:10:37 +01:00
changeDrawableColor(context, R.drawable.ic_repeat,R.color.black);
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_repeat);
}
2017-10-28 09:23:52 +02:00
2017-10-04 10:23:12 +02:00
2018-05-11 11:28:05 +02:00
if( theme == THEME_DARK || theme == THEME_BLACK)
2018-01-26 08:10:37 +01:00
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_icon);
else
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
imgReply = ContextCompat.getDrawable(context, R.drawable.ic_reply);
2018-01-26 08:10:37 +01:00
assert imgFav != null;
imgFav.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
assert imgReblog != null;
imgReblog.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
assert imgReply != null;
imgReply.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (20 * iconSizePercent/100 * scale + 0.5f));
2017-09-18 20:32:36 +02:00
2018-01-26 08:10:37 +01:00
holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null);
holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null);
2017-09-18 20:32:36 +02:00
2018-09-09 14:19:24 +02:00
if(isCompactMode && ((status.getReblog() == null && status.getReplies_count() > 1) || (status.getReblog() != null && status.getReblog().getReplies_count() > 1))){
Drawable img = context.getResources().getDrawable( R.drawable.ic_plus_one );
holder.status_reply.setCompoundDrawablesWithIntrinsicBounds( imgReply, null, img, null);
}else{
holder.status_reply.setCompoundDrawablesWithIntrinsicBounds( imgReply, null, null, null);
}
2018-09-09 14:19:24 +02:00
if( isCompactMode){
if( ((status.getReblog() == null && status.getReplies_count() == 1) || (status.getReblog() != null && status.getReblog().getReplies_count() == 1)))
2018-09-09 14:32:34 +02:00
holder.status_reply.setText(String.valueOf( status.getReblog() != null? status.getReblog().getReplies_count():status.getReplies_count()));
2018-09-09 14:19:24 +02:00
}else {
if( status.getReplies_count() > 0 || (status.getReblog() != null && status.getReblog().getReplies_count() > 0 ) )
2018-09-09 14:32:34 +02:00
holder.status_reply.setText(String.valueOf( status.getReblog() != null? status.getReblog().getReplies_count():status.getReplies_count()));
2018-09-09 14:19:24 +02:00
}
2018-01-26 08:10:37 +01:00
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")) && status.getReblog() == null) {
Drawable imgPin;
if( status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned())) {
changeDrawableColor(context, R.drawable.ic_pin_drop_p,R.color.marked_icon);
imgPin = ContextCompat.getDrawable(context, R.drawable.ic_pin_drop_p);
}else {
2018-05-11 11:28:05 +02:00
if( theme == THEME_DARK || theme == THEME_BLACK)
2018-01-26 08:10:37 +01:00
changeDrawableColor(context, R.drawable.ic_pin_drop,R.color.dark_icon);
else
changeDrawableColor(context, R.drawable.ic_pin_drop,R.color.black);
imgPin = ContextCompat.getDrawable(context, R.drawable.ic_pin_drop);
}
2018-01-26 08:10:37 +01:00
assert imgPin != null;
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);
2017-09-18 20:32:36 +02:00
}
2018-11-07 18:09:21 +01:00
boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
2018-01-26 08:10:37 +01:00
2018-11-07 11:03:32 +01:00
if( status.getWebviewURL() != null){
holder.status_cardview_webview.loadUrl(status.getWebviewURL());
holder.status_cardview_webview.setVisibility(View.VISIBLE);
holder.status_cardview_video.setVisibility(View.VISIBLE);
holder.webview_preview.setVisibility(View.GONE);
}else {
holder.status_cardview_webview.setVisibility(View.GONE);
holder.status_cardview_video.setVisibility(View.GONE);
holder.webview_preview.setVisibility(View.VISIBLE);
}
2018-11-07 08:26:20 +01:00
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT || display_card){
2018-09-15 17:45:33 +02:00
2018-11-08 18:40:02 +01:00
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT)
holder.status_cardview_content.setVisibility(View.VISIBLE);
else
holder.status_cardview_content.setVisibility(View.GONE);
2018-11-07 08:26:20 +01:00
if( position == conversationPosition || display_card){
2018-11-07 11:03:32 +01:00
2018-11-07 08:26:20 +01:00
Card card = status.getReblog()!= null?status.getReblog().getCard():status.getCard();
if( card != null){
2017-12-26 10:06:22 +01:00
2018-11-07 08:26:20 +01:00
holder.status_cardview_content.setText(card.getDescription());
holder.status_cardview_title.setText(card.getTitle());
holder.status_cardview_url.setText(card.getUrl());
if( card.getImage() != null && card.getImage().length() > 10) {
2017-12-20 13:57:28 +01:00
holder.status_cardview_image.setVisibility(View.VISIBLE);
2018-11-07 08:26:20 +01:00
if( !((Activity)context).isFinishing())
2018-09-06 19:04:30 +02:00
Glide.with(holder.status_cardview_image.getContext())
2018-11-07 08:26:20 +01:00
.load(card.getImage())
2018-11-08 18:40:02 +01:00
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners((int)Helper.convertDpToPixel(7, context))))
2018-09-06 19:04:30 +02:00
.into(holder.status_cardview_image);
2017-12-20 13:57:28 +01:00
}else
holder.status_cardview_image.setVisibility(View.GONE);
2018-11-07 08:26:20 +01:00
if( !card.getType().equals("video")) {
2017-12-26 09:09:51 +01:00
holder.status_cardview.setVisibility(View.VISIBLE);
holder.status_cardview_video.setVisibility(View.GONE);
holder.status_cardview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
2018-11-07 08:26:20 +01:00
Helper.openBrowser(context, card.getUrl());
2017-12-26 09:09:51 +01:00
}
});
}else {
2018-11-07 11:03:32 +01:00
Glide.with(holder.status_cardview_image.getContext())
.load(card.getImage())
.into(holder.webview_preview_card);
2017-12-26 09:09:51 +01:00
holder.status_cardview.setVisibility(View.GONE);
holder.status_cardview_video.setVisibility(View.VISIBLE);
holder.status_cardview_webview.getSettings().setJavaScriptEnabled(true);
2018-11-07 08:26:20 +01:00
String html = card.getHtml();
String src = card.getUrl();
2017-12-26 09:09:51 +01:00
if( html != null){
Matcher matcher = Pattern.compile("src=\"([^\"]+)\"").matcher(html);
if( matcher.find())
src = matcher.group(1);
2017-12-20 13:57:28 +01:00
}
2017-12-26 09:22:10 +01:00
final String finalSrc = src;
holder.status_cardview_webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
holder.status_cardview_video.setVisibility(View.GONE);
}
});
2018-11-07 11:03:32 +01:00
holder.webview_preview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
status.setWebviewURL(finalSrc);
notifyStatusChanged(status);
}
});
2017-12-26 09:09:51 +01:00
}
}else {
2017-12-20 13:57:28 +01:00
holder.status_cardview.setVisibility(View.GONE);
2017-12-26 09:09:51 +01:00
holder.status_cardview_video.setVisibility(View.GONE);
}
2017-12-20 13:57:28 +01:00
}else {
holder.status_cardview.setVisibility(View.GONE);
holder.status_cardview_video.setVisibility(View.GONE);
}
2017-09-18 20:32:36 +02:00
}
holder.status_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CrossActions.doCrossReply(context, status, type, true);
}
});
holder.status_favorite_count.setOnClickListener(new View.OnClickListener() {
2017-09-18 20:32:36 +02:00
@Override
public void onClick(View v) {
2018-08-21 16:20:20 +02:00
CrossActions.doCrossAction(context, type, status, null, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, true);
2017-09-18 20:32:36 +02:00
}
});
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-08-21 16:20:20 +02:00
CrossActions.doCrossAction(context, type, status, null, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true);
2017-09-18 20:32:36 +02:00
}
});
holder.status_pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-08-21 16:20:20 +02:00
CrossActions.doCrossAction(context, type, status, null, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true);
2017-09-18 20:32:36 +02:00
}
});
2017-12-26 08:06:05 +01:00
if( !status.getVisibility().equals("direct"))
holder.status_favorite_count.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
2018-08-21 16:20:20 +02:00
CrossActions.doCrossAction(context, type, status, null, API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false);
return true;
}
});
2017-12-26 08:06:05 +01:00
if( !status.getVisibility().equals("direct"))
holder.status_reblog_count.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
2018-08-21 16:20:20 +02:00
CrossActions.doCrossAction(context, type, status, null, API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false);
return true;
}
});
2017-12-26 08:06:05 +01:00
if( !status.getVisibility().equals("direct"))
holder.status_reply.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
CrossActions.doCrossReply(context, status, type, false);
return true;
}
});
holder.yandex_translate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/"));
context.startActivity(browserIntent);
}
});
//Spoiler opens
holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2017-12-25 09:45:49 +01:00
status.setSpoilerShown(!status.isSpoilerShown());
notifyStatusChanged(status);
}
});
2017-10-04 10:23:12 +02:00
holder.status_show_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
status.setAttachmentShown(true);
2017-12-25 09:45:49 +01:00
notifyStatusChanged(status);
/*
Added a Countdown Timer, so that Sensitive (NSFW)
images only get displayed for user set time,
giving the user time to click on them to expand them,
if they want. Images are then hidden again.
-> Default value is set to 5 seconds
*/
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
if (timeout > 0) {
new CountDownTimer((timeout * 1000), 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
status.setAttachmentShown(false);
2017-12-25 09:45:49 +01:00
notifyStatusChanged(status);
}
}.start();
}
}
});
2018-11-03 14:45:55 +01:00
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
style = R.style.DialogBlack;
}else {
style = R.style.Dialog;
}
2018-08-21 19:01:39 +02:00
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
holder.status_more.setVisibility(View.GONE);
2017-10-04 10:23:12 +02:00
final View attached = holder.status_more;
holder.status_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(context, attached);
final boolean isOwner = status.getAccount().getId().equals(userId);
popup.getMenuInflater()
.inflate(R.menu.option_toot, popup.getMenu());
if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
}
if( status.isBookmarked())
popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_remove);
else
popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_add);
final String[] stringArrayConf;
if( isOwner) {
popup.getMenu().findItem(R.id.action_block).setVisible(false);
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false);
2018-01-05 09:46:59 +01:00
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
2018-09-26 19:07:22 +02:00
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
}else {
2018-08-14 14:33:52 +02:00
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
2018-09-26 19:07:22 +02:00
//Same instance
2018-09-26 19:18:54 +02:00
if(status.getAccount().getAcct().split("@").length <2 )
2018-09-26 19:07:22 +02:00
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
2018-01-05 09:46:59 +01:00
if( type != RetrieveFeedsAsyncTask.Type.HOME){
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
}
}
2018-09-28 19:35:13 +02:00
MenuItem itemBookmark = popup.getMenu().findItem(R.id.action_bookmark);
if( itemBookmark.getActionView() != null)
itemBookmark.getActionView().setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
CrossActions.doCrossBookmark(context, status, statusListAdapter);
return true;
}
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builderInner;
final API.StatusAction doAction;
switch (item.getItemId()) {
2018-08-14 14:33:52 +02:00
case R.id.action_redraft:
2018-11-03 14:45:55 +01:00
builderInner = new AlertDialog.Builder(context, style);
2018-08-14 14:33:52 +02:00
builderInner.setTitle(stringArrayConf[1]);
redraft = true;
doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_info:
Intent intent = new Intent(context, TootInfoActivity.class);
Bundle b = new Bundle();
2018-11-07 07:55:39 +01:00
if( status.getReblog() != null) {
b.putString("toot_id", status.getReblog().getId());
2018-11-07 07:55:39 +01:00
b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count());
b.putInt("toot_favorites_count", status.getReblog().getFavourites_count());
}else {
b.putString("toot_id", status.getId());
2018-11-07 07:55:39 +01:00
b.putInt("toot_reblogs_count", status.getReblogs_count());
b.putInt("toot_favorites_count", status.getFavourites_count());
}
intent.putExtras(b);
context.startActivity(intent);
return true;
2018-09-01 08:32:00 +02:00
case R.id.action_open_browser:
Helper.openBrowser(context, status.getReblog()!=null?status.getReblog().getUrl():status.getUrl());
2018-09-01 08:32:00 +02:00
return true;
case R.id.action_remove:
2018-11-03 14:45:55 +01:00
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
2018-09-26 19:07:22 +02:00
case R.id.action_block_domain:
2018-11-03 14:45:55 +01:00
builderInner = new AlertDialog.Builder(context, style);
2018-09-26 19:07:22 +02:00
builderInner.setTitle(stringArrayConf[3]);
doAction = API.StatusAction.BLOCK_DOMAIN;
String domain = status.getAccount().getAcct().split("@")[1];
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
break;
case R.id.action_mute:
2018-11-03 14:45:55 +01:00
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.MUTE;
break;
case R.id.action_bookmark:
if( type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
status.setBookmarked(!status.isBookmarked());
2018-09-19 08:50:10 +02:00
try {
if (status.isBookmarked()) {
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
Toast.makeText(context, R.string.status_bookmarked, Toast.LENGTH_LONG).show();
} else {
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status);
Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show();
}
notifyStatusChanged(status);
}catch (Exception e){
2018-09-22 19:13:55 +02:00
e.printStackTrace();
2018-09-19 08:50:10 +02:00
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
}
}else {
int position = 0;
for (Status statustmp : statuses) {
if (statustmp.getId().equals(status.getId())) {
statuses.remove(status);
statusListAdapter.notifyItemRemoved(position);
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp);
Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show();
break;
}
position++;
}
}
return true;
case R.id.action_timed_mute:
2018-11-03 14:45:55 +01:00
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.datetime_picker, null);
dialogBuilder.setView(dialogView);
final AlertDialog alertDialog = dialogBuilder.create();
final DatePicker datePicker = dialogView.findViewById(R.id.date_picker);
final TimePicker timePicker = dialogView.findViewById(R.id.time_picker);
timePicker.setIs24HourView(true);
Button date_time_cancel = dialogView.findViewById(R.id.date_time_cancel);
final ImageButton date_time_previous = dialogView.findViewById(R.id.date_time_previous);
final ImageButton date_time_next = dialogView.findViewById(R.id.date_time_next);
final ImageButton date_time_set = dialogView.findViewById(R.id.date_time_set);
//Buttons management
date_time_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
date_time_next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePicker.setVisibility(View.GONE);
timePicker.setVisibility(View.VISIBLE);
date_time_previous.setVisibility(View.VISIBLE);
date_time_next.setVisibility(View.GONE);
date_time_set.setVisibility(View.VISIBLE);
}
});
date_time_previous.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePicker.setVisibility(View.VISIBLE);
timePicker.setVisibility(View.GONE);
date_time_previous.setVisibility(View.GONE);
date_time_next.setVisibility(View.VISIBLE);
date_time_set.setVisibility(View.GONE);
}
});
date_time_set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int hour, minute;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
hour = timePicker.getHour();
minute = timePicker.getMinute();
}else {
//noinspection deprecation
hour = timePicker.getCurrentHour();
//noinspection deprecation
minute = timePicker.getCurrentMinute();
}
Calendar calendar = new GregorianCalendar(datePicker.getYear(),
datePicker.getMonth(),
datePicker.getDayOfMonth(),
hour,
minute);
long time = calendar.getTimeInMillis();
if( (time - new Date().getTime()) < 60000 ){
Toast.makeText(context, R.string.timed_mute_date_error, Toast.LENGTH_LONG).show();
}else {
//Store the toot as draft first
String targeted_id = status.getAccount().getId();
Date date_mute = new Date(time);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(context, db).getAccountByID(userId);
new TempMuteDAO(context, db).insert(account, targeted_id, new Date(time));
2018-01-05 09:46:59 +01:00
if( timedMute != null && !timedMute.contains(account.getId()))
timedMute.add(targeted_id);
else if (timedMute == null){
timedMute = new ArrayList<>();
timedMute.add(targeted_id);
}
2018-04-28 16:54:06 +02:00
Toast.makeText(context,context.getString(R.string.timed_mute_date,status.getAccount().getAcct(),Helper.dateToString(date_mute)), Toast.LENGTH_LONG).show();
alertDialog.dismiss();
2018-01-04 18:55:28 +01:00
notifyDataSetChanged();
}
}
});
alertDialog.show();
return true;
case R.id.action_block:
2018-11-03 14:45:55 +01:00
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]);
doAction = API.StatusAction.BLOCK;
break;
2018-05-12 09:41:47 +02:00
case R.id.action_translate:
translateToot(status);
return true;
case R.id.action_report:
2018-11-03 14:45:55 +01:00
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[2]);
doAction = API.StatusAction.REPORT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_copy:
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
2018-01-26 11:13:07 +01:00
final String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
content = Html.fromHtml(status.getContent()).toString();
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
2017-10-27 13:59:14 +02:00
if( clipboard != null) {
clipboard.setPrimaryClip(clip);
Toast.makeText(context, R.string.clipboard, Toast.LENGTH_LONG).show();
}
return true;
case R.id.action_share:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
String url;
if( status.getReblog() != null) {
if( status.getReblog().getUri().startsWith("http"))
url = status.getReblog().getUri();
else
url = status.getReblog().getUrl();
}else {
if( status.getUri().startsWith("http"))
url = status.getUri();
else
url = status.getUrl();
}
2018-05-12 11:11:17 +02:00
String extra_text;
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
if( share_details) {
extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct();
if (extra_text.split("@").length == 1)
extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context);
else
extra_text = "@" + extra_text;
extra_text += " " + Helper.shortnameToUnicode(":link:", true) + " " + url + "\r\n-\n";
final String contentToot;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString();
extra_text += contentToot;
}else {
extra_text = url;
}
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
case R.id.action_mention:
2017-11-04 19:04:04 +01:00
// Get a handler that can be used to post to the main thread
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
2018-01-26 10:13:32 +01:00
String name = "@"+(status.getReblog()!=null?status.getReblog().getAccount().getAcct():status.getAccount().getAcct());
2018-01-26 11:13:07 +01:00
if( name.split("@", -1).length - 1 == 1)
name = name + "@" + getLiveInstance(context);
2018-01-26 10:13:32 +01:00
Bitmap bitmap = Helper.convertTootIntoBitmap(context, name, holder.status_content);
Intent intent = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
String fname = "tootmention_" + status.getId() +".jpg";
File file = new File (context.getCacheDir() + "/", fname);
if (file.exists ()) //noinspection ResultOfMethodCallIgnored
file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
assert bitmap != null;
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
2017-12-02 14:54:25 +01:00
} catch (Exception ignored) {}
b.putString("fileMention", fname);
b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct());
b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl());
intent.putExtras(b);
context.startActivity(intent);
}
2017-11-04 19:04:04 +01:00
}, 500);
return true;
default:
return true;
}
//Text for report
EditText input = null;
if( doAction == API.StatusAction.REPORT){
input = new EditText(context);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
builderInner.setView(input);
}
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.dismiss();
}
});
final EditText finalInput = input;
builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
if(doAction == API.StatusAction.UNSTATUS ){
String targetedId = status.getId();
new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2018-08-14 14:33:52 +02:00
if( redraft ){
2018-08-18 14:41:02 +02:00
if( status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")){
2018-08-18 20:12:37 +02:00
toot = new Status();
toot.setIn_reply_to_id(status.getIn_reply_to_id());
toot.setSensitive(status.isSensitive());
toot.setMedia_attachments(status.getMedia_attachments());
if( status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0)
toot.setSpoiler_text(status.getSpoiler_text().trim());
toot.setContent(status.getContent());
toot.setVisibility(status.getVisibility());
2018-08-18 14:41:02 +02:00
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
2018-08-18 20:12:37 +02:00
toot = new Status();
toot.setSensitive(status.isSensitive());
toot.setMedia_attachments(status.getMedia_attachments());
if( status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0)
toot.setSpoiler_text(status.getSpoiler_text().trim());
toot.setVisibility(status.getVisibility());
toot.setContent(status.getContent());
long id = new StatusStoredDAO(context, db).insertStatus(toot, null);
2018-08-18 14:41:02 +02:00
Intent intentToot = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
b.putLong("restored", id);
2018-08-18 20:12:37 +02:00
b.putBoolean("removed", true);
2018-08-18 14:41:02 +02:00
intentToot.putExtras(b);
context.startActivity(intentToot);
}
2018-08-14 14:33:52 +02:00
}
}else if(doAction == API.StatusAction.REPORT ){
String comment = null;
if( finalInput.getText() != null)
comment = finalInput.getText().toString();
new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
2018-09-26 19:07:22 +02:00
String targetedId;
if( item.getItemId() == R.id.action_block_domain){
targetedId = status.getAccount().getAcct().split("@")[1];
}else {
targetedId = status.getAccount().getId();
}
new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
dialog.dismiss();
}
});
builderInner.show();
return true;
}
});
popup.show();
}
});
2017-05-05 16:36:04 +02:00
2018-08-22 09:04:43 +02:00
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
holder.status_account_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-08-22 09:04:43 +02:00
if (targetedId == null || !targetedId.equals(status.getAccount().getId())) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", status.getAccount().getId());
intent.putExtras(b);
context.startActivity(intent);
}
}
2018-08-22 09:04:43 +02:00
});
2018-08-22 09:04:43 +02:00
holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", status.getReblog().getAccount().getId());
intent.putExtras(b);
context.startActivity(intent);
}
}
2018-08-22 09:04:43 +02:00
});
}else{
holder.status_account_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (targetedId == null || !targetedId.equals(status.getAccount().getId())) {
Account account = status.getAccount();
2018-09-22 19:13:55 +02:00
Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})");
2018-08-22 09:04:43 +02:00
Matcher matcher = instanceHost.matcher(status.getUrl());
String instance = null;
while (matcher.find()){
instance = matcher.group(1);
}
account.setInstance(instance);
CrossActions.doCrossProfile(context, account);
}
}
});
holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) {
Account account = status.getReblog().getAccount();
2018-09-22 19:13:55 +02:00
Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})");
2018-08-22 09:04:43 +02:00
Matcher matcher = instanceHost.matcher(status.getUrl());
String instance = null;
while (matcher.find()){
instance = matcher.group(1);
}
account.setInstance(instance);
CrossActions.doCrossProfile(context, account);
}
}
});
}
2018-11-03 17:42:59 +01:00
if( getItemViewType(position) == FOCUSED_STATUS && status.getApplication() != null && status.getApplication().getName() != null && status.getApplication().getName().length() > 0){
Application application = status.getApplication();
holder.status_toot_app.setText(application.getName());
2018-10-31 16:13:11 +01:00
if( application.getWebsite() != null && !application.getWebsite().trim().equals("null") && application.getWebsite().trim().length() == 0) {
holder.status_toot_app.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.openBrowser(context, application.getWebsite());
}
});
}
2018-11-03 17:42:59 +01:00
holder.status_toot_app.setVisibility(View.VISIBLE);
2018-05-12 09:41:47 +02:00
}else {
holder.status_toot_app.setVisibility(View.GONE);
}
}
2017-05-05 16:36:04 +02:00
}
2017-05-05 16:36:04 +02:00
private void loadAttachments(final Status status, final ViewHolder holder){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
2017-05-05 16:36:04 +02:00
List<Attachment> attachments = status.getMedia_attachments();
2017-05-05 16:36:04 +02:00
if( attachments != null && attachments.size() > 0){
int i = 0;
if(fullAttachement)
holder.status_horizontal_document_container.setVisibility(View.VISIBLE);
else
holder.status_document_container.setVisibility(View.VISIBLE);
if( attachments.size() == 1 ){
if( !fullAttachement)
holder.status_container2.setVisibility(View.GONE);
else {
holder.status_prev1_h.setVisibility(View.VISIBLE);
holder.status_prev2_h.setVisibility(View.GONE);
holder.status_prev3_h.setVisibility(View.GONE);
holder.status_prev4_h.setVisibility(View.GONE);
}
if( attachments.get(0).getUrl().trim().contains("missing.png"))
if(fullAttachement)
holder.status_horizontal_document_container.setVisibility(View.GONE);
else
holder.status_document_container.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
}else if(attachments.size() == 2){
if( !fullAttachement) {
holder.status_container2.setVisibility(View.VISIBLE);
holder.status_container3.setVisibility(View.GONE);
holder.status_prev4_container.setVisibility(View.GONE);
if (attachments.get(1).getUrl().trim().contains("missing.png"))
holder.status_container2.setVisibility(View.GONE);
}else {
holder.status_prev1_h.setVisibility(View.VISIBLE);
holder.status_prev2_h.setVisibility(View.VISIBLE);
holder.status_prev3_h.setVisibility(View.GONE);
holder.status_prev4_h.setVisibility(View.GONE);
if (attachments.get(1).getUrl().trim().contains("missing.png"))
holder.status_prev2_h.setVisibility(View.GONE);
}
}else if( attachments.size() == 3 ){
if( !fullAttachement) {
holder.status_container2.setVisibility(View.VISIBLE);
holder.status_container3.setVisibility(View.VISIBLE);
holder.status_prev4_container.setVisibility(View.GONE);
if (attachments.get(2).getUrl().trim().contains("missing.png"))
holder.status_container3.setVisibility(View.GONE);
}else {
holder.status_prev1_h.setVisibility(View.VISIBLE);
holder.status_prev2_h.setVisibility(View.VISIBLE);
holder.status_prev3_h.setVisibility(View.VISIBLE);
holder.status_prev4_h.setVisibility(View.GONE);
if (attachments.get(2).getUrl().trim().contains("missing.png"))
holder.status_prev3_h.setVisibility(View.GONE);
}
}else {
if(!fullAttachement) {
holder.status_container2.setVisibility(View.VISIBLE);
holder.status_container3.setVisibility(View.VISIBLE);
holder.status_prev4_container.setVisibility(View.VISIBLE);
if (attachments.get(2).getUrl().trim().contains("missing.png"))
holder.status_prev4_container.setVisibility(View.GONE);
}else {
holder.status_prev1_h.setVisibility(View.VISIBLE);
holder.status_prev2_h.setVisibility(View.VISIBLE);
holder.status_prev3_h.setVisibility(View.VISIBLE);
holder.status_prev4_h.setVisibility(View.VISIBLE);
if (attachments.get(2).getUrl().trim().contains("missing.png"))
holder.status_prev3_h.setVisibility(View.GONE);
}
2017-05-05 16:36:04 +02:00
}
int position = 1;
2017-05-05 16:36:04 +02:00
for(final Attachment attachment: attachments){
ImageView imageView;
2017-06-16 19:23:41 +02:00
if( i == 0) {
imageView = fullAttachement?holder.status_prev1_h:holder.status_prev1;
2017-10-18 16:59:47 +02:00
if( attachment.getType().equals("image") || attachment.getType().equals("unknown"))
if( fullAttachement)
holder.status_prev1_play_h.setVisibility(View.GONE);
else
holder.status_prev1_play.setVisibility(View.GONE);
2017-06-16 19:23:41 +02:00
else
if( fullAttachement)
holder.status_prev1_play_h.setVisibility(View.VISIBLE);
else
holder.status_prev1_play.setVisibility(View.VISIBLE);
2017-06-16 19:23:41 +02:00
}else if( i == 1) {
imageView = fullAttachement?holder.status_prev2_h:holder.status_prev2;
2017-10-18 16:59:47 +02:00
if( attachment.getType().equals("image") || attachment.getType().equals("unknown"))
if( fullAttachement)
holder.status_prev2_play_h.setVisibility(View.GONE);
else
holder.status_prev2_play.setVisibility(View.GONE);
2017-06-16 19:23:41 +02:00
else
if( fullAttachement)
holder.status_prev2_play_h.setVisibility(View.VISIBLE);
else
holder.status_prev2_play.setVisibility(View.VISIBLE);
2017-06-16 19:23:41 +02:00
}else if(i == 2) {
imageView = fullAttachement?holder.status_prev3_h:holder.status_prev3;
2017-10-18 16:59:47 +02:00
if( attachment.getType().equals("image") || attachment.getType().equals("unknown"))
if( fullAttachement)
holder.status_prev3_play_h.setVisibility(View.GONE);
else
holder.status_prev3_play.setVisibility(View.GONE);
2017-06-16 19:23:41 +02:00
else
if( fullAttachement)
holder.status_prev3_play_h.setVisibility(View.VISIBLE);
else
holder.status_prev3_play.setVisibility(View.VISIBLE);
2017-06-16 19:23:41 +02:00
}else {
imageView = fullAttachement?holder.status_prev4_h:holder.status_prev4;
2017-10-18 16:59:47 +02:00
if( attachment.getType().equals("image") || attachment.getType().equals("unknown"))
if( fullAttachement)
holder.status_prev4_play_h.setVisibility(View.GONE);
else
holder.status_prev4_play.setVisibility(View.GONE);
2017-06-16 19:23:41 +02:00
else
if( fullAttachement)
holder.status_prev4_play_h.setVisibility(View.VISIBLE);
else
holder.status_prev4_play.setVisibility(View.VISIBLE);
2017-06-16 19:23:41 +02:00
}
2017-05-05 16:36:04 +02:00
String url = attachment.getPreview_url();
2017-10-18 17:07:50 +02:00
if( url == null || url.trim().equals("") )
2017-05-05 16:36:04 +02:00
url = attachment.getUrl();
2017-10-18 17:07:50 +02:00
else if( attachment.getType().equals("unknown"))
url = attachment.getRemote_url();
if( fullAttachement){
imageView.setImageBitmap(null);
if( !url.trim().contains("missing.png") && !((Activity)context).isFinishing() )
Glide.with(imageView.getContext())
.asBitmap()
.load(url)
.thumbnail(0.1f)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
DrawableTransitionOptions.withCrossFade();
int width = resource.getWidth();
int height = resource.getHeight();
if( height < Helper.convertDpToPixel(200, context)){
double ratio = ((double)Helper.convertDpToPixel(200, context) / (double)height);
width = (int)(ratio * width);
height = (int) Helper.convertDpToPixel(200, context);
resource = Bitmap.createScaledBitmap(resource, width, height, false);
}
imageView.setImageBitmap(resource);
}
});
}else {
if (!url.trim().contains("missing.png") && !((Activity) context).isFinishing())
Glide.with(imageView.getContext())
.load(url)
.thumbnail(0.1f)
.transition(DrawableTransitionOptions.withCrossFade())
.into(imageView);
}
final int finalPosition = position;
2017-10-27 13:24:01 +02:00
if( attachment.getDescription() != null && !attachment.getDescription().equals("null"))
imageView.setContentDescription(attachment.getDescription());
2017-05-05 16:36:04 +02:00
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
intent.putParcelableArrayListExtra("mediaArray", status.getMedia_attachments());
b.putInt("position", finalPosition);
intent.putExtras(b);
context.startActivity(intent);
2017-05-05 16:36:04 +02:00
}
});
i++;
position++;
2017-05-05 16:36:04 +02:00
}
}else{
holder.status_horizontal_document_container.setVisibility(View.GONE);
holder.status_document_container.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
}
holder.status_show_more.setVisibility(View.GONE);
2017-12-06 19:12:52 +01:00
2017-05-05 16:36:04 +02:00
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
2018-08-18 14:41:02 +02:00
if( apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0){
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
2018-08-18 20:12:37 +02:00
long id = new StatusStoredDAO(context, db).insertStatus(toot, apiResponse.getStatuses().get(0));
2018-08-18 14:41:02 +02:00
Intent intentToot = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
b.putLong("restored", id);
2018-08-18 20:12:37 +02:00
b.putBoolean("removed", true);
2018-08-18 14:41:02 +02:00
intentToot.putExtras(b);
context.startActivity(intentToot);
}
2018-01-21 09:38:03 +01:00
}
2018-01-25 13:47:34 +01:00
2018-01-21 09:38:03 +01:00
@Override
public void onRetrieveAccount(Card card) {
2018-01-21 11:34:00 +01:00
if( conversationPosition < this.statuses.size() && card != null)
2018-01-21 09:38:03 +01:00
this.statuses.get(conversationPosition).setCard(card);
if( conversationPosition < this.statuses.size())
statusListAdapter.notifyItemChanged(conversationPosition);
}
2018-01-21 09:38:03 +01:00
2017-05-05 16:36:04 +02:00
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( error != null){
2018-09-09 13:58:29 +02:00
Toast.makeText(context, error.getError(),Toast.LENGTH_LONG).show();
return;
}
2017-05-05 16:36:04 +02:00
Helper.manageMessageStatusCode(context, statusCode, statusAction);
//When muting or blocking an account, its status are removed from the list
List<Status> statusesToRemove = new ArrayList<>();
if( statusAction == API.StatusAction.MUTE || statusAction == API.StatusAction.BLOCK){
for(Status status: statuses){
if( status.getAccount().getId().equals(targetedId))
statusesToRemove.add(status);
}
statuses.removeAll(statusesToRemove);
statusListAdapter.notifyDataSetChanged();
}else if( statusAction == API.StatusAction.UNSTATUS ){
int position = 0;
2017-05-05 16:36:04 +02:00
for(Status status: statuses){
if( status.getId().equals(targetedId)) {
statuses.remove(status);
statusListAdapter.notifyItemRemoved(position);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
//Remove the status from cache also
try {
new StatusCacheDAO(context, db).remove(StatusCacheDAO.ARCHIVE_CACHE,status);
}catch (Exception ignored){}
break;
}
position++;
2017-05-05 16:36:04 +02:00
}
}
else if ( statusAction == API.StatusAction.PIN || statusAction == API.StatusAction.UNPIN ) {
int position = 0;
for (Status status: statuses) {
if (status.getId().equals(targetedId)) {
if (statusAction == API.StatusAction.PIN)
status.setPinned(true);
else
status.setPinned(false);
statusListAdapter.notifyItemChanged(position);
break;
}
position++;
}
}
if( statusAction == API.StatusAction.REBLOG){
int position = 0;
for(Status status: statuses){
if( status.getId().equals(targetedId)) {
status.setReblogs_count(status.getReblogs_count() + 1);
statusListAdapter.notifyItemChanged(position);
break;
}
position++;
}
}else if( statusAction == API.StatusAction.UNREBLOG){
int position = 0;
for(Status status: statuses){
if( status.getId().equals(targetedId)) {
2017-10-04 15:57:53 +02:00
if( status.getReblogs_count() - 1 >= 0)
status.setReblogs_count(status.getReblogs_count() - 1);
statusListAdapter.notifyItemChanged(position);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
//Remove the status from cache also
try {
new StatusCacheDAO(context, db).remove(StatusCacheDAO.ARCHIVE_CACHE,status);
}catch (Exception ignored){}
break;
}
position++;
}
}else if( statusAction == API.StatusAction.FAVOURITE){
int position = 0;
for(Status status: statuses){
if( status.getId().equals(targetedId)) {
status.setFavourites_count(status.getFavourites_count() + 1);
statusListAdapter.notifyItemChanged(position);
break;
}
position++;
}
statusListAdapter.notifyDataSetChanged();
}else if( statusAction == API.StatusAction.UNFAVOURITE){
int position = 0;
for(Status status: statuses){
if( status.getId().equals(targetedId)) {
2017-10-04 15:57:53 +02:00
if( status.getFavourites_count() - 1 >= 0)
status.setFavourites_count(status.getFavourites_count() - 1);
statusListAdapter.notifyItemChanged(position);
break;
}
position++;
}
}
2017-05-05 16:36:04 +02:00
}
2018-09-28 19:35:13 +02:00
public void notifyStatusChanged(Status status){
2017-12-03 14:17:57 +01:00
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
2018-01-05 09:46:59 +01:00
//noinspection ConstantConditions
2017-12-03 14:17:57 +01:00
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
try {
statusListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}
}
}
}
2017-10-20 19:58:46 +02:00
@Override
2017-12-03 14:17:57 +01:00
public void onRetrieveEmoji(Status status, boolean fromTranslation) {
2018-08-17 16:22:26 +02:00
if( status != null) {
if( !fromTranslation) {
status.setEmojiFound(true);
}else {
status.setEmojiTranslateFound(true);
}
notifyStatusChanged(status);
}
/* if( !fromTranslation) {
2017-12-03 14:17:57 +01:00
if (!status.isEmojiFound()) {
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
2018-01-05 09:46:59 +01:00
//noinspection ConstantConditions
2017-12-03 14:17:57 +01:00
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
2018-01-05 09:46:59 +01:00
//noinspection ConstantConditions
statusListAdapter.getItemAt(i).setEmojiFound(true);
2017-12-02 14:09:52 +01:00
try {
statusListAdapter.notifyItemChanged(i);
2017-12-03 14:17:57 +01:00
} catch (Exception ignored) {}
}
}
}
}else {
if (!status.isEmojiTranslateFound()) {
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
2018-01-05 09:46:59 +01:00
//noinspection ConstantConditions
2017-12-03 14:17:57 +01:00
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
2018-01-05 09:46:59 +01:00
//noinspection ConstantConditions
2017-12-03 14:17:57 +01:00
statusListAdapter.getItemAt(i).setEmojiTranslateFound(true);
try {
statusListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {}
}
}
}
2018-08-17 16:22:26 +02:00
}*/
2017-10-20 19:58:46 +02:00
}
2017-11-01 19:19:37 +01:00
@Override
public void onRetrieveSearchEmoji(List<Emojis> emojis) {
}
2018-05-12 09:41:47 +02:00
private void translateToot(Status status){
//Manages translations
2018-08-14 16:20:53 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int trans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
MyTransL.translatorEngine et = MyTransL.translatorEngine.YANDEX;
String api_key = null;
if( trans == Helper.TRANS_YANDEX) {
et = MyTransL.translatorEngine.YANDEX;
}else if( trans == Helper.TRANS_DEEPL) {
et = MyTransL.translatorEngine.DEEPL;
}
final MyTransL myTransL = MyTransL.getInstance(et);
2018-05-12 09:41:47 +02:00
myTransL.setObfuscation(true);
2018-08-14 16:20:53 +02:00
if( trans == Helper.TRANS_YANDEX) {
api_key = sharedpreferences.getString(Helper.SET_YANDEX_API_KEY, Helper.YANDEX_KEY);
myTransL.setYandexAPIKey(api_key);
}else if( trans == Helper.TRANS_DEEPL) {
api_key = sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, "");
myTransL.setDeeplAPIKey(api_key);
}
2018-05-12 09:41:47 +02:00
if( !status.isTranslated() ){
String statusToTranslate;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
statusToTranslate = Html.fromHtml(status.getReblog() != null ?status.getReblog().getContent():status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
statusToTranslate = Html.fromHtml(status.getReblog() != null ?status.getReblog().getContent():status.getContent()).toString();
//TODO: removes the replaceAll once fixed with the lib
myTransL.translate(statusToTranslate, myTransL.getLocale(), new Results() {
@Override
public void onSuccess(Translate translate) {
if( translate.getTranslatedContent() != null) {
status.setTranslated(true);
status.setTranslationShown(true);
status.setContentTranslated(translate.getTranslatedContent());
status.makeClickableTranslation(context);
status.makeEmojisTranslation(context, StatusListAdapter.this);
notifyStatusChanged(status);
}else {
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
}
}
@Override
public void onFail(HttpsConnectionException e) {
2018-08-14 16:20:53 +02:00
e.printStackTrace();
2018-05-12 09:41:47 +02:00
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
}
});
}else {
status.setTranslationShown(!status.isTranslationShown());
notifyStatusChanged(status);
}
}
2017-05-05 16:36:04 +02:00
}