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>. */
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
2017-06-03 15:54:19 +02:00
|
|
|
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;
|
2017-07-04 21:15:11 +02:00
|
|
|
import android.net.Uri;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2017-08-05 19:01:24 +02:00
|
|
|
import android.os.CountDownTimer;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-07-31 15:17:19 +02:00
|
|
|
import android.support.v7.widget.CardView;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.text.Html;
|
2017-08-08 15:33:02 +02:00
|
|
|
import android.text.Selection;
|
2017-07-31 15:17:19 +02:00
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
2017-08-08 15:33:02 +02:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.ContextMenu;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.view.LayoutInflater;
|
2017-08-08 12:36:39 +02:00
|
|
|
import android.view.MotionEvent;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2017-06-30 17:09:07 +02:00
|
|
|
import android.view.Window;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
2017-05-30 19:31:44 +02:00
|
|
|
import android.widget.Toast;
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2017-07-29 13:28:50 +02:00
|
|
|
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
2017-05-05 16:36:04 +02:00
|
|
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
2017-07-29 13:28:50 +02:00
|
|
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
2017-05-05 16:36:04 +02:00
|
|
|
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
|
|
|
|
2017-07-03 11:30:36 +02:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2017-07-29 13:28:50 +02:00
|
|
|
import java.io.File;
|
2017-07-03 11:30:36 +02:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLDecoder;
|
2017-05-05 16:36:04 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2017-06-26 18:49:39 +02:00
|
|
|
import fr.gouv.etalab.mastodon.activities.MediaActivity;
|
2017-08-05 19:01:24 +02:00
|
|
|
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.asynctasks.PostActionAsyncTask;
|
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
|
|
|
import fr.gouv.etalab.mastodon.client.API;
|
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
2017-08-05 19:01:24 +02:00
|
|
|
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-08-05 19:01:24 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
|
|
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
2017-08-05 19:01:24 +02:00
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
|
|
|
import fr.gouv.etalab.mastodon.translation.YandexQuery;
|
|
|
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
|
|
|
|
2017-07-03 11:30:36 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
|
2017-07-01 15:24:28 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 24/04/2017.
|
|
|
|
* Adapter for Status
|
|
|
|
*/
|
2017-07-03 11:30:36 +02:00
|
|
|
public class StatusListAdapter extends BaseAdapter implements OnPostActionInterface, OnTranslatedInterface {
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private List<Status> statuses;
|
|
|
|
private LayoutInflater layoutInflater;
|
|
|
|
private ImageLoader imageLoader;
|
|
|
|
private DisplayImageOptions options;
|
|
|
|
private boolean isOnWifi;
|
|
|
|
private int behaviorWithAttachments;
|
|
|
|
private StatusListAdapter statusListAdapter;
|
|
|
|
private final int REBLOG = 1;
|
|
|
|
private final int FAVOURITE = 2;
|
|
|
|
private RetrieveFeedsAsyncTask.Type type;
|
2017-07-20 15:00:43 +02:00
|
|
|
private String targetedId;
|
2017-08-12 18:41:35 +02:00
|
|
|
private int style;
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2017-07-20 15:00:43 +02:00
|
|
|
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, List<Status> statuses){
|
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;
|
2017-07-20 15:00:43 +02:00
|
|
|
this.targetedId = targetedId;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return statuses.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
|
|
|
return statuses.get(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
|
|
2017-07-29 13:28:50 +02:00
|
|
|
|
|
|
|
imageLoader = ImageLoader.getInstance();
|
|
|
|
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
|
|
|
|
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(context)
|
|
|
|
.imageDownloader(new PatchBaseImageDownloader(context))
|
|
|
|
.threadPoolSize(5)
|
|
|
|
.threadPriority(Thread.MIN_PRIORITY + 3)
|
|
|
|
.denyCacheImageMultipleSizesInMemory()
|
|
|
|
.diskCache(new UnlimitedDiskCache(cacheDir))
|
|
|
|
.build();
|
2017-07-31 19:29:14 +02:00
|
|
|
if( !imageLoader.isInited())
|
|
|
|
imageLoader.init(configImg);
|
2017-07-29 13:28:50 +02:00
|
|
|
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
|
|
|
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
final Status status = statuses.get(position);
|
2017-07-31 15:17:19 +02:00
|
|
|
final ViewHolder holder;
|
2017-05-05 16:36:04 +02:00
|
|
|
if (convertView == null) {
|
|
|
|
convertView = layoutInflater.inflate(R.layout.drawer_status, parent, false);
|
|
|
|
holder = new ViewHolder();
|
2017-07-31 15:17:19 +02:00
|
|
|
holder.card_status_container = (CardView) convertView.findViewById(R.id.card_status_container);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_document_container = (LinearLayout) convertView.findViewById(R.id.status_document_container);
|
|
|
|
holder.status_content = (TextView) convertView.findViewById(R.id.status_content);
|
2017-07-03 11:30:36 +02:00
|
|
|
holder.status_content_translated = (TextView) convertView.findViewById(R.id.status_content_translated);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_account_username = (TextView) convertView.findViewById(R.id.status_account_username);
|
|
|
|
holder.status_account_displayname = (TextView) convertView.findViewById(R.id.status_account_displayname);
|
|
|
|
holder.status_account_profile = (ImageView) convertView.findViewById(R.id.status_account_profile);
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_account_profile_boost = (ImageView) convertView.findViewById(R.id.status_account_profile_boost);
|
2017-07-07 19:26:26 +02:00
|
|
|
holder.status_account_profile_boost_by = (ImageView) convertView.findViewById(R.id.status_account_profile_boost_by);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_favorite_count = (TextView) convertView.findViewById(R.id.status_favorite_count);
|
|
|
|
holder.status_reblog_count = (TextView) convertView.findViewById(R.id.status_reblog_count);
|
|
|
|
holder.status_toot_date = (TextView) convertView.findViewById(R.id.status_toot_date);
|
|
|
|
holder.status_show_more = (Button) convertView.findViewById(R.id.status_show_more);
|
|
|
|
holder.status_more = (ImageView) convertView.findViewById(R.id.status_more);
|
|
|
|
holder.status_reblog_user = (TextView) convertView.findViewById(R.id.status_reblog_user);
|
|
|
|
holder.status_action_container = (LinearLayout) convertView.findViewById(R.id.status_action_container);
|
|
|
|
holder.status_prev1 = (ImageView) convertView.findViewById(R.id.status_prev1);
|
|
|
|
holder.status_prev2 = (ImageView) convertView.findViewById(R.id.status_prev2);
|
|
|
|
holder.status_prev3 = (ImageView) convertView.findViewById(R.id.status_prev3);
|
|
|
|
holder.status_prev4 = (ImageView) convertView.findViewById(R.id.status_prev4);
|
2017-06-16 19:23:41 +02:00
|
|
|
holder.status_prev1_play = (ImageView) convertView.findViewById(R.id.status_prev1_play);
|
|
|
|
holder.status_prev2_play = (ImageView) convertView.findViewById(R.id.status_prev2_play);
|
|
|
|
holder.status_prev3_play = (ImageView) convertView.findViewById(R.id.status_prev3_play);
|
|
|
|
holder.status_prev4_play = (ImageView) convertView.findViewById(R.id.status_prev4_play);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_container2 = (LinearLayout) convertView.findViewById(R.id.status_container2);
|
|
|
|
holder.status_container3 = (LinearLayout) convertView.findViewById(R.id.status_container3);
|
2017-06-17 07:49:47 +02:00
|
|
|
holder.status_prev4_container = (RelativeLayout) convertView.findViewById(R.id.status_prev4_container);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply);
|
|
|
|
holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy);
|
2017-07-07 19:26:26 +02:00
|
|
|
holder.status_translate = (Button) convertView.findViewById(R.id.status_translate);
|
2017-07-04 21:15:11 +02:00
|
|
|
holder.status_content_translated_container = (LinearLayout) convertView.findViewById(R.id.status_content_translated_container);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.main_container = (LinearLayout) convertView.findViewById(R.id.main_container);
|
2017-06-07 16:52:53 +02:00
|
|
|
holder.status_spoiler_container = (LinearLayout) convertView.findViewById(R.id.status_spoiler_container);
|
|
|
|
holder.status_content_container = (LinearLayout) convertView.findViewById(R.id.status_content_container);
|
|
|
|
holder.status_spoiler = (TextView) convertView.findViewById(R.id.status_spoiler);
|
|
|
|
holder.status_spoiler_button = (Button) convertView.findViewById(R.id.status_spoiler_button);
|
2017-07-04 21:15:11 +02:00
|
|
|
holder.yandex_translate = (TextView) convertView.findViewById(R.id.yandex_translate);
|
2017-05-05 16:36:04 +02:00
|
|
|
convertView.setTag(holder);
|
|
|
|
} else {
|
|
|
|
holder = (ViewHolder) convertView.getTag();
|
|
|
|
}
|
2017-06-07 16:52:53 +02:00
|
|
|
if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 && !status.isSpoilerShown()){
|
|
|
|
holder.status_content_container.setVisibility(View.GONE);
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_spoiler_container.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_spoiler_button.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_spoiler.setVisibility(View.VISIBLE);
|
2017-06-07 16:52:53 +02:00
|
|
|
}else {
|
|
|
|
holder.status_spoiler_button.setVisibility(View.GONE);
|
|
|
|
holder.status_content_container.setVisibility(View.VISIBLE);
|
2017-06-14 16:08:39 +02:00
|
|
|
if( status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 )
|
|
|
|
holder.status_spoiler_container.setVisibility(View.VISIBLE);
|
|
|
|
else
|
|
|
|
holder.status_spoiler_container.setVisibility(View.GONE);
|
2017-06-07 16:52:53 +02:00
|
|
|
}
|
|
|
|
if( status.getSpoiler_text() != null)
|
|
|
|
holder.status_spoiler.setText(status.getSpoiler_text());
|
|
|
|
//Spoiler opens
|
|
|
|
holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
status.setSpoilerShown(true);
|
|
|
|
holder.status_spoiler_button.setVisibility(View.GONE);
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
2017-07-17 19:18:21 +02:00
|
|
|
if( currentLocale != null && status.getLanguage() != null && !status.getLanguage().trim().equals(currentLocale) && !status.getLanguage().trim().equals("null")){
|
2017-07-03 11:30:36 +02:00
|
|
|
holder.status_translate.setVisibility(View.VISIBLE);
|
|
|
|
}else {
|
|
|
|
holder.status_translate.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
holder.status_translate.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
try {
|
|
|
|
if( !status.isTranslated() ){
|
2017-07-13 22:42:58 +02:00
|
|
|
new YandexQuery(StatusListAdapter.this).getYandexTextview(position, status.getContent(), currentLocale);
|
2017-07-04 21:15:11 +02:00
|
|
|
}else {
|
|
|
|
status.setTranslationShown(!status.isTranslationShown());
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
2017-07-03 11:30:36 +02:00
|
|
|
}
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-04 21:15:11 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2017-07-03 11:30:36 +02:00
|
|
|
//Toot was translated and user asked to see it
|
|
|
|
if( status.isTranslationShown()){
|
|
|
|
holder.status_content.setVisibility(View.GONE);
|
2017-07-04 21:15:11 +02:00
|
|
|
holder.status_content_translated_container.setVisibility(View.VISIBLE);
|
2017-07-03 11:30:36 +02:00
|
|
|
}else { //Toot is not translated
|
|
|
|
holder.status_content.setVisibility(View.VISIBLE);
|
2017-07-04 21:15:11 +02:00
|
|
|
holder.status_content_translated_container.setVisibility(View.GONE);
|
2017-07-03 11:30:36 +02:00
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
//Hides action bottom bar action when looking to status trough accounts
|
|
|
|
if( type == RetrieveFeedsAsyncTask.Type.USER){
|
|
|
|
holder.status_action_container.setVisibility(View.GONE);
|
|
|
|
}
|
2017-07-01 15:24:28 +02:00
|
|
|
//Manages theme for icon colors
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
2017-07-04 21:15:11 +02:00
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
2017-07-01 15:24:28 +02:00
|
|
|
if( theme == Helper.THEME_DARK){
|
|
|
|
changeDrawableColor(context, R.drawable.ic_reply,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_more,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.dark_text);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_photo,R.color.dark_text);
|
2017-07-02 15:20:58 +02:00
|
|
|
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.dark_text);
|
2017-07-03 11:30:36 +02:00
|
|
|
changeDrawableColor(context, R.drawable.ic_translate,R.color.dark_text);
|
2017-08-12 18:41:35 +02:00
|
|
|
style = R.style.AlertDialogDark;
|
2017-07-01 15:24:28 +02:00
|
|
|
}else {
|
|
|
|
changeDrawableColor(context, R.drawable.ic_reply,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_more,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_retweet_black,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_fav_black,R.color.black);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_photo,R.color.black);
|
2017-07-02 15:20:58 +02:00
|
|
|
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.black);
|
2017-07-03 11:30:36 +02:00
|
|
|
changeDrawableColor(context, R.drawable.ic_translate,R.color.black);
|
2017-08-12 18:41:35 +02:00
|
|
|
style = R.style.AlertDialog;
|
2017-07-01 15:24:28 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 09:45:08 +02:00
|
|
|
//Redraws top icons (boost/reply)
|
2017-05-05 16:36:04 +02:00
|
|
|
final float scale = context.getResources().getDisplayMetrics().density;
|
|
|
|
if( !status.getIn_reply_to_account_id().equals("null") || !status.getIn_reply_to_id().equals("null") ){
|
|
|
|
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply);
|
|
|
|
img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (15 * scale + 0.5f));
|
|
|
|
holder.status_account_displayname.setCompoundDrawables( img, null, null, null);
|
|
|
|
}else if( status.getReblog() != null){
|
2017-06-24 17:50:54 +02:00
|
|
|
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black);
|
2017-05-05 16:36:04 +02:00
|
|
|
img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (15 * scale + 0.5f));
|
|
|
|
holder.status_account_displayname.setCompoundDrawables( img, null, null, null);
|
|
|
|
}else{
|
|
|
|
holder.status_account_displayname.setCompoundDrawables( null, null, null, null);
|
|
|
|
}
|
2017-07-01 15:24:28 +02:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
//Click on a conversation
|
|
|
|
if( type != RetrieveFeedsAsyncTask.Type.CONTEXT ){
|
2017-05-17 16:28:26 +02:00
|
|
|
holder.status_content.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(context, ShowConversationActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
2017-08-01 15:44:26 +02:00
|
|
|
if( status.getReblog() == null)
|
|
|
|
b.putString("statusId", status.getId());
|
|
|
|
else
|
|
|
|
b.putString("statusId", status.getReblog().getId());
|
2017-07-22 10:00:15 +02:00
|
|
|
intent.putExtras(b);
|
2017-05-17 16:28:26 +02:00
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2017-07-31 15:17:19 +02:00
|
|
|
holder.card_status_container.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(context, ShowConversationActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
2017-08-01 15:44:26 +02:00
|
|
|
if( status.getReblog() == null)
|
|
|
|
b.putString("statusId", status.getId());
|
|
|
|
else
|
|
|
|
b.putString("statusId", status.getReblog().getId());
|
2017-07-31 15:17:19 +02:00
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2017-05-05 16:36:04 +02:00
|
|
|
}else {
|
2017-06-30 17:09:07 +02:00
|
|
|
if( theme == Helper.THEME_LIGHT){
|
|
|
|
if( position == ShowConversationActivity.position){
|
2017-08-13 15:19:01 +02:00
|
|
|
holder.main_container.setBackgroundResource(R.color.mastodonC3_);
|
2017-06-30 17:09:07 +02:00
|
|
|
}else {
|
2017-08-13 15:19:01 +02:00
|
|
|
holder.main_container.setBackgroundResource(R.color.mastodonC3);
|
2017-06-30 17:09:07 +02:00
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}else {
|
2017-06-30 17:09:07 +02:00
|
|
|
if( position == ShowConversationActivity.position){
|
2017-08-13 11:30:28 +02:00
|
|
|
holder.main_container.setBackgroundResource(R.color.mastodonC1_);
|
2017-06-30 17:09:07 +02:00
|
|
|
}else {
|
2017-08-13 11:30:28 +02:00
|
|
|
holder.main_container.setBackgroundResource(R.color.mastodonC1);
|
2017-06-30 17:09:07 +02:00
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final String content, displayName, username, ppurl;
|
|
|
|
if( status.getReblog() != null){
|
|
|
|
content = status.getReblog().getContent();
|
2017-06-20 19:22:08 +02:00
|
|
|
displayName = Helper.shortnameToUnicode(status.getReblog().getAccount().getDisplay_name(), true);
|
2017-05-05 16:36:04 +02:00
|
|
|
username = status.getReblog().getAccount().getUsername();
|
|
|
|
holder.status_reblog_user.setText(displayName + " " +String.format("@%s",username));
|
|
|
|
ppurl = status.getReblog().getAccount().getAvatar();
|
|
|
|
holder.status_reblog_user.setVisibility(View.VISIBLE);
|
2017-05-27 08:32:14 +02:00
|
|
|
holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername()));
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_account_username.setText( "");
|
|
|
|
}else {
|
|
|
|
ppurl = status.getAccount().getAvatar();
|
|
|
|
content = status.getContent();
|
2017-06-19 15:59:34 +02:00
|
|
|
displayName = Helper.shortnameToUnicode(status.getAccount().getDisplay_name(), true);
|
2017-05-05 16:36:04 +02:00
|
|
|
username = status.getAccount().getUsername();
|
|
|
|
holder.status_reblog_user.setVisibility(View.GONE);
|
|
|
|
holder.status_account_displayname.setText(displayName);
|
2017-06-23 20:03:17 +02:00
|
|
|
holder.status_account_username.setText(String.format("@%s",username));
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
holder.status_reply.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(context, TootActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
2017-08-10 14:51:13 +02:00
|
|
|
if( status.getReblog() != null )
|
|
|
|
b.putParcelable("tootReply", status.getReblog());
|
|
|
|
else
|
|
|
|
b.putParcelable("tootReply", status);
|
2017-05-05 16:36:04 +02:00
|
|
|
intent.putExtras(b); //Put your id to your next Intent
|
|
|
|
context.startActivity(intent);
|
2017-07-22 10:00:15 +02:00
|
|
|
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
|
|
|
|
try {
|
|
|
|
//Avoid to open multi activities when replying in a conversation
|
|
|
|
((ShowConversationActivity)context).finish();
|
|
|
|
}catch (Exception ignored){}
|
|
|
|
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-08 12:36:39 +02:00
|
|
|
|
2017-06-23 20:03:17 +02:00
|
|
|
|
2017-07-03 11:30:36 +02:00
|
|
|
if( status.getContent_translated() != null && status.getContent_translated().length() > 0){
|
2017-07-31 15:17:19 +02:00
|
|
|
SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(),
|
2017-07-24 10:50:40 +02:00
|
|
|
status.getReblog() != null?status.getReblog().getMentions():status.getMentions());
|
2017-07-31 15:17:19 +02:00
|
|
|
holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE);
|
2017-08-08 12:36:39 +02:00
|
|
|
holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
holder.status_content_translated.setFocusableInTouchMode(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
holder.status_content_translated.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
holder.status_content_translated.setFocusableInTouchMode(false);
|
|
|
|
holder.status_content_translated.clearFocus();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2017-07-31 15:17:19 +02:00
|
|
|
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
|
2017-07-03 11:30:36 +02:00
|
|
|
}
|
2017-08-08 15:33:02 +02:00
|
|
|
|
|
|
|
final SpannableString spannableString = Helper.clickableElements(context,content,
|
2017-08-08 12:36:39 +02:00
|
|
|
status.getReblog() != null?status.getReblog().getMentions():status.getMentions());
|
|
|
|
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
|
|
|
|
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
holder.status_content.setFocusableInTouchMode(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
holder.status_content.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
holder.status_content.setFocusableInTouchMode(false);
|
|
|
|
holder.status_content.clearFocus();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2017-07-31 15:17:19 +02:00
|
|
|
holder.status_content.setMovementMethod(LinkMovementMethod.getInstance());
|
2017-08-08 12:36:39 +02:00
|
|
|
|
2017-08-01 09:11:27 +02: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()));
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at()));
|
2017-07-02 15:20:58 +02:00
|
|
|
|
2017-07-07 19:26:26 +02:00
|
|
|
|
2017-06-14 16:08:39 +02:00
|
|
|
if( status.getReblog() != null) {
|
2017-07-07 19:26:26 +02:00
|
|
|
imageLoader.displayImage(ppurl, holder.status_account_profile_boost, options);
|
|
|
|
imageLoader.displayImage(status.getAccount().getAvatar(), holder.status_account_profile_boost_by, options);
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_account_profile_boost.setVisibility(View.VISIBLE);
|
2017-07-07 19:26:26 +02:00
|
|
|
holder.status_account_profile_boost_by.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_account_profile.setVisibility(View.GONE);
|
2017-05-05 16:36:04 +02:00
|
|
|
}else{
|
2017-07-07 19:26:26 +02:00
|
|
|
imageLoader.displayImage(ppurl, holder.status_account_profile, options);
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_account_profile_boost.setVisibility(View.GONE);
|
2017-07-07 19:26:26 +02:00
|
|
|
holder.status_account_profile_boost_by.setVisibility(View.GONE);
|
|
|
|
holder.status_account_profile.setVisibility(View.VISIBLE);
|
2017-06-14 16:08:39 +02:00
|
|
|
}
|
|
|
|
if( status.getReblog() == null) {
|
|
|
|
if (status.getMedia_attachments().size() < 1) {
|
|
|
|
holder.status_document_container.setVisibility(View.GONE);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_show_more.setVisibility(View.GONE);
|
2017-06-14 16:08:39 +02:00
|
|
|
} else {
|
|
|
|
//If medias are loaded without any conditions or if device is on wifi
|
|
|
|
if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
|
2017-07-31 15:17:19 +02:00
|
|
|
loadAttachments(status, holder);
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_show_more.setVisibility(View.GONE);
|
|
|
|
status.setAttachmentShown(true);
|
|
|
|
} else {
|
|
|
|
//Text depending if toots is sensitive or not
|
|
|
|
String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
|
|
|
|
holder.status_show_more.setText(textShowMore);
|
|
|
|
if (!status.isAttachmentShown()) {
|
|
|
|
holder.status_show_more.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_document_container.setVisibility(View.GONE);
|
|
|
|
} else {
|
2017-07-31 15:17:19 +02:00
|
|
|
loadAttachments(status, holder);
|
2017-06-14 16:08:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else { //Attachments for reblogs
|
|
|
|
if (status.getReblog().getMedia_attachments().size() < 1) {
|
|
|
|
holder.status_document_container.setVisibility(View.GONE);
|
|
|
|
holder.status_show_more.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
//If medias are loaded without any conditions or if device is on wifi
|
|
|
|
if (!status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
|
2017-07-31 15:17:19 +02:00
|
|
|
loadAttachments(status.getReblog(), holder);
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_show_more.setVisibility(View.GONE);
|
|
|
|
status.getReblog().setAttachmentShown(true);
|
|
|
|
} else {
|
|
|
|
//Text depending if toots is sensitive or not
|
|
|
|
String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
|
|
|
|
holder.status_show_more.setText(textShowMore);
|
2017-06-19 19:20:20 +02:00
|
|
|
if (!status.isAttachmentShown()) {
|
2017-06-14 16:08:39 +02:00
|
|
|
holder.status_show_more.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_document_container.setVisibility(View.GONE);
|
|
|
|
} else {
|
2017-07-31 15:17:19 +02:00
|
|
|
loadAttachments(status.getReblog(), holder);
|
2017-06-14 16:08:39 +02:00
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (status.getVisibility()){
|
|
|
|
case "public":
|
|
|
|
holder.status_privacy.setImageResource(R.drawable.ic_action_globe);
|
|
|
|
break;
|
|
|
|
case "unlisted":
|
|
|
|
holder.status_privacy.setImageResource(R.drawable.ic_action_lock_open);
|
|
|
|
break;
|
|
|
|
case "private":
|
|
|
|
holder.status_privacy.setImageResource(R.drawable.ic_action_lock_closed);
|
|
|
|
break;
|
|
|
|
case "direct":
|
|
|
|
holder.status_privacy.setImageResource(R.drawable.ic_local_post_office);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Drawable imgFav, imgReblog;
|
2017-08-01 09:11:27 +02:00
|
|
|
if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited()))
|
2017-05-05 16:36:04 +02:00
|
|
|
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_yellow);
|
|
|
|
else
|
|
|
|
imgFav = ContextCompat.getDrawable(context, R.drawable.ic_fav_black);
|
|
|
|
|
2017-08-01 09:11:27 +02:00
|
|
|
if( status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))
|
2017-05-05 16:36:04 +02:00
|
|
|
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_yellow);
|
|
|
|
else
|
|
|
|
imgReblog = ContextCompat.getDrawable(context, R.drawable.ic_retweet_black);
|
|
|
|
|
|
|
|
imgFav.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
|
2017-06-24 17:50:54 +02:00
|
|
|
imgReblog.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null);
|
|
|
|
holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null);
|
|
|
|
|
|
|
|
holder.status_show_more.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-31 15:17:19 +02:00
|
|
|
loadAttachments(status, holder);
|
2017-05-05 16:36:04 +02:00
|
|
|
holder.status_show_more.setVisibility(View.GONE);
|
|
|
|
status.setAttachmentShown(true);
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
2017-08-05 19:01:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Added a Countdown Timer, so that Sensitive (NSFW)
|
2017-08-07 01:53:33 +02:00
|
|
|
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.
|
2017-08-07 07:49:00 +02:00
|
|
|
-> Default value is set to 5 seconds
|
2017-08-05 19:01:24 +02:00
|
|
|
*/
|
2017-08-07 07:49:00 +02:00
|
|
|
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
2017-08-05 19:01:24 +02:00
|
|
|
|
2017-08-07 01:53:33 +02:00
|
|
|
if (timeout > 0) {
|
2017-08-05 19:01:24 +02:00
|
|
|
|
2017-08-07 01:53:33 +02:00
|
|
|
new CountDownTimer((timeout * 1000), 1000) {
|
2017-08-05 19:01:24 +02:00
|
|
|
|
2017-08-07 01:53:33 +02:00
|
|
|
public void onTick(long millisUntilFinished) {
|
|
|
|
}
|
2017-08-05 19:01:24 +02:00
|
|
|
|
2017-08-07 01:53:33 +02:00
|
|
|
public void onFinish() {
|
|
|
|
status.setAttachmentShown(false);
|
|
|
|
holder.status_show_more.setVisibility(View.VISIBLE);
|
2017-08-05 19:01:24 +02:00
|
|
|
|
2017-08-07 01:53:33 +02:00
|
|
|
statusListAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}.start();
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.status_favorite_count.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-06-30 17:09:07 +02:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
boolean confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
|
|
|
|
if( confirmation )
|
|
|
|
displayConfirmationDialog(FAVOURITE,status);
|
|
|
|
else
|
|
|
|
favouriteAction(status);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
boolean confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
|
|
|
|
if( confirmation )
|
|
|
|
displayConfirmationDialog(REBLOG,status);
|
|
|
|
else
|
2017-07-20 11:06:11 +02:00
|
|
|
reblogAction(status);
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
});
|
2017-07-20 11:06:11 +02:00
|
|
|
switch (status.getVisibility()){
|
|
|
|
case "direct":
|
|
|
|
case "private":
|
|
|
|
holder.status_reblog_count.setVisibility(View.GONE);
|
|
|
|
break;
|
|
|
|
case "public":
|
|
|
|
case "unlisted":
|
|
|
|
holder.status_reblog_count.setVisibility(View.VISIBLE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
holder.status_reblog_count.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
holder.status_more.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
moreOptionDialog(status);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
holder.status_account_profile.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-20 15:00: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);
|
|
|
|
}
|
2017-07-07 19:26:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-20 15:00:43 +02:00
|
|
|
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);
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
//Profile picture
|
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Favourites/Unfavourites a status
|
|
|
|
* @param status Status
|
|
|
|
*/
|
|
|
|
private void favouriteAction(Status status){
|
2017-08-01 09:11:27 +02:00
|
|
|
if( status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())){
|
2017-05-05 16:36:04 +02:00
|
|
|
new PostActionAsyncTask(context, API.StatusAction.UNFAVOURITE, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
status.setFavourited(false);
|
|
|
|
}else{
|
|
|
|
new PostActionAsyncTask(context, API.StatusAction.FAVOURITE, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
status.setFavourited(true);
|
|
|
|
}
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reblog/Unreblog a status
|
|
|
|
* @param status Status
|
|
|
|
*/
|
|
|
|
private void reblogAction(Status status){
|
2017-08-01 09:11:27 +02:00
|
|
|
if( status.isReblogged() || (status.getReblog()!= null && status.getReblog().isReblogged())){
|
2017-05-05 16:36:04 +02:00
|
|
|
new PostActionAsyncTask(context, API.StatusAction.UNREBLOG, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
status.setReblogged(false);
|
|
|
|
}else{
|
|
|
|
new PostActionAsyncTask(context, API.StatusAction.REBLOG, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
status.setReblogged(true);
|
|
|
|
}
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-31 15:17:19 +02:00
|
|
|
private void loadAttachments(final Status status, ViewHolder holder){
|
2017-05-05 16:36:04 +02:00
|
|
|
List<Attachment> attachments = status.getMedia_attachments();
|
|
|
|
if( attachments != null && attachments.size() > 0){
|
|
|
|
int i = 0;
|
|
|
|
if( attachments.size() == 1){
|
|
|
|
holder.status_container2.setVisibility(View.GONE);
|
2017-07-15 08:19:07 +02:00
|
|
|
if( attachments.get(0).getUrl().trim().contains("missing.png"))
|
|
|
|
holder.status_document_container.setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
holder.status_document_container.setVisibility(View.VISIBLE);
|
2017-05-05 16:36:04 +02:00
|
|
|
}else if(attachments.size() == 2){
|
|
|
|
holder.status_container2.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_container3.setVisibility(View.GONE);
|
2017-07-15 08:19:07 +02:00
|
|
|
if( attachments.get(1).getUrl().trim().contains("missing.png"))
|
|
|
|
holder.status_container2.setVisibility(View.GONE);
|
|
|
|
holder.status_document_container.setVisibility(View.VISIBLE);
|
2017-05-05 16:36:04 +02:00
|
|
|
}else if( attachments.size() == 3){
|
|
|
|
holder.status_container2.setVisibility(View.VISIBLE);
|
|
|
|
holder.status_container3.setVisibility(View.VISIBLE);
|
2017-06-17 07:49:47 +02:00
|
|
|
holder.status_prev4_container.setVisibility(View.GONE);
|
2017-07-15 08:19:07 +02:00
|
|
|
if( attachments.get(2).getUrl().trim().contains("missing.png"))
|
|
|
|
holder.status_container3.setVisibility(View.GONE);
|
|
|
|
holder.status_document_container.setVisibility(View.VISIBLE);
|
2017-05-05 16:36:04 +02:00
|
|
|
}else {
|
2017-06-17 07:49:47 +02:00
|
|
|
holder.status_prev4_container.setVisibility(View.VISIBLE);
|
2017-07-15 08:19:07 +02:00
|
|
|
if( attachments.get(2).getUrl().trim().contains("missing.png"))
|
|
|
|
holder.status_prev4_container.setVisibility(View.GONE);
|
|
|
|
holder.status_document_container.setVisibility(View.VISIBLE);
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
2017-06-26 18:49:39 +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 = holder.status_prev1;
|
|
|
|
if( attachment.getType().equals("image"))
|
|
|
|
holder.status_prev1_play.setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
holder.status_prev1_play.setVisibility(View.VISIBLE);
|
|
|
|
}else if( i == 1) {
|
|
|
|
imageView = holder.status_prev2;
|
|
|
|
if( attachment.getType().equals("image"))
|
|
|
|
holder.status_prev2_play.setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
holder.status_prev2_play.setVisibility(View.VISIBLE);
|
|
|
|
}else if(i == 2) {
|
|
|
|
imageView = holder.status_prev3;
|
|
|
|
if( attachment.getType().equals("image"))
|
|
|
|
holder.status_prev3_play.setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
holder.status_prev3_play.setVisibility(View.VISIBLE);
|
|
|
|
}else {
|
|
|
|
imageView = holder.status_prev4;
|
|
|
|
if( attachment.getType().equals("image"))
|
|
|
|
holder.status_prev4_play.setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
holder.status_prev4_play.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
String url = attachment.getPreview_url();
|
|
|
|
if( url == null || url.trim().equals(""))
|
|
|
|
url = attachment.getUrl();
|
2017-07-15 08:19:07 +02:00
|
|
|
if( !url.trim().contains("missing.png"))
|
|
|
|
imageLoader.displayImage(url, imageView, options);
|
2017-06-26 18:49:39 +02:00
|
|
|
final int finalPosition = position;
|
2017-05-05 16:36:04 +02:00
|
|
|
imageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-06-26 18:49:39 +02:00
|
|
|
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++;
|
2017-06-26 18:49:39 +02:00
|
|
|
position++;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
holder.status_document_container.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
holder.status_show_more.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-30 19:31:44 +02:00
|
|
|
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
|
|
|
|
|
|
|
|
if( error != null){
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
|
|
|
if( show_error_messages)
|
|
|
|
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 ){
|
|
|
|
for(Status status: statuses){
|
|
|
|
if( status.getId().equals(targetedId))
|
|
|
|
statusesToRemove.add(status);
|
|
|
|
}
|
|
|
|
statuses.removeAll(statusesToRemove);
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 11:30:36 +02:00
|
|
|
@Override
|
|
|
|
public void onTranslatedTextview(int position, String translatedResult, Boolean error) {
|
|
|
|
if( error){
|
|
|
|
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
|
2017-07-08 11:32:38 +02:00
|
|
|
}else if( statuses.size() > position) {
|
2017-07-03 11:30:36 +02:00
|
|
|
try {
|
2017-07-13 22:42:58 +02:00
|
|
|
String aJsonString = yandexTranslateToText(translatedResult);
|
2017-07-03 11:30:36 +02:00
|
|
|
statuses.get(position).setTranslated(true);
|
|
|
|
statuses.get(position).setTranslationShown(true);
|
|
|
|
statuses.get(position).setContent_translated(aJsonString);
|
|
|
|
statusListAdapter.notifyDataSetChanged();
|
2017-07-08 11:32:38 +02:00
|
|
|
} catch (JSONException | UnsupportedEncodingException | IllegalArgumentException e) {
|
2017-07-03 11:30:36 +02:00
|
|
|
Toast.makeText(context, R.string.toast_error_translate, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2017-07-13 18:30:25 +02:00
|
|
|
private String yandexTranslateToText(String text) throws JSONException, UnsupportedEncodingException{
|
|
|
|
JSONObject translationJson = new JSONObject(text);
|
|
|
|
JSONArray aJsonArray = translationJson.getJSONArray("text");
|
|
|
|
String aJsonString = aJsonArray.get(0).toString();
|
|
|
|
aJsonString = URLDecoder.decode(aJsonString, "UTF-8");
|
|
|
|
return aJsonString;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String googleTranslateToText(String text) throws JSONException, UnsupportedEncodingException{
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
String aJsonString = "";
|
|
|
|
while( i < new JSONArray(new JSONArray(text).get(0).toString()).length() ) {
|
|
|
|
aJsonString += new JSONArray(new JSONArray(new JSONArray(text).get(0).toString()).get(i).toString()).get(0).toString();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
//Some fixes due to translation with Google
|
|
|
|
aJsonString = aJsonString.trim();
|
|
|
|
aJsonString = aJsonString.replace("< / ","</");
|
|
|
|
aJsonString = aJsonString.replace("</ ","</");
|
|
|
|
aJsonString = aJsonString.replace("> ",">");
|
|
|
|
aJsonString = aJsonString.replace(" <","<");
|
|
|
|
aJsonString = aJsonString.replace(" // ","//");
|
|
|
|
aJsonString = aJsonString.replace("// ","//");
|
|
|
|
aJsonString = aJsonString.replace(" //","//");
|
|
|
|
aJsonString = aJsonString.replace(" www .","www.");
|
|
|
|
aJsonString = aJsonString.replace("www .","www.");
|
|
|
|
aJsonString = URLDecoder.decode(aJsonString, "UTF-8");
|
|
|
|
return aJsonString;
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
private class ViewHolder {
|
2017-06-07 16:52:53 +02:00
|
|
|
LinearLayout status_content_container;
|
|
|
|
LinearLayout status_spoiler_container;
|
|
|
|
TextView status_spoiler;
|
|
|
|
Button status_spoiler_button;
|
2017-07-31 15:17:19 +02:00
|
|
|
CardView card_status_container;
|
2017-05-05 16:36:04 +02:00
|
|
|
TextView status_content;
|
2017-07-03 11:30:36 +02:00
|
|
|
TextView status_content_translated;
|
2017-07-04 21:15:11 +02:00
|
|
|
LinearLayout status_content_translated_container;
|
2017-05-05 16:36:04 +02:00
|
|
|
TextView status_account_username;
|
|
|
|
TextView status_account_displayname;
|
|
|
|
ImageView status_account_profile;
|
2017-06-14 16:08:39 +02:00
|
|
|
ImageView status_account_profile_boost;
|
2017-07-07 19:26:26 +02:00
|
|
|
ImageView status_account_profile_boost_by;
|
2017-05-05 16:36:04 +02:00
|
|
|
TextView status_favorite_count;
|
|
|
|
TextView status_reblog_count;
|
|
|
|
TextView status_toot_date;
|
|
|
|
TextView status_reblog_user;
|
|
|
|
Button status_show_more;
|
|
|
|
ImageView status_more;
|
|
|
|
LinearLayout status_action_container;
|
|
|
|
LinearLayout status_document_container;
|
|
|
|
ImageView status_prev1;
|
|
|
|
ImageView status_prev2;
|
|
|
|
ImageView status_prev3;
|
|
|
|
ImageView status_prev4;
|
2017-06-16 19:23:41 +02:00
|
|
|
ImageView status_prev1_play;
|
|
|
|
ImageView status_prev2_play;
|
|
|
|
ImageView status_prev3_play;
|
|
|
|
ImageView status_prev4_play;
|
2017-06-17 07:49:47 +02:00
|
|
|
RelativeLayout status_prev4_container;
|
2017-05-05 16:36:04 +02:00
|
|
|
ImageView status_reply;
|
|
|
|
ImageView status_privacy;
|
2017-07-07 19:26:26 +02:00
|
|
|
Button status_translate;
|
2017-05-05 16:36:04 +02:00
|
|
|
LinearLayout status_container2;
|
|
|
|
LinearLayout status_container3;
|
|
|
|
LinearLayout main_container;
|
2017-07-04 21:15:11 +02:00
|
|
|
TextView yandex_translate;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a validation message
|
|
|
|
* @param action int
|
|
|
|
* @param status Status
|
|
|
|
*/
|
|
|
|
private void displayConfirmationDialog(final int action, final Status status){
|
|
|
|
|
|
|
|
String title = null;
|
|
|
|
if( action == FAVOURITE){
|
2017-08-01 09:11:27 +02:00
|
|
|
if( status.isFavourited() || ( status.getReblog() != null && status.getReblog().isFavourited()))
|
2017-05-05 16:36:04 +02:00
|
|
|
title = context.getString(R.string.favourite_remove);
|
|
|
|
else
|
|
|
|
title = context.getString(R.string.favourite_add);
|
|
|
|
}else if( action == REBLOG ){
|
2017-08-01 09:11:27 +02:00
|
|
|
if( status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged()))
|
2017-05-05 16:36:04 +02:00
|
|
|
title = context.getString(R.string.reblog_remove);
|
|
|
|
else
|
|
|
|
title = context.getString(R.string.reblog_add);
|
|
|
|
}
|
2017-08-12 18:41:35 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
2017-08-08 18:02:06 +02:00
|
|
|
builder.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
2017-05-05 16:36:04 +02:00
|
|
|
else
|
|
|
|
//noinspection deprecation
|
|
|
|
builder.setMessage(Html.fromHtml(status.getContent()));
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.setTitle(title)
|
|
|
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
if( action == REBLOG)
|
|
|
|
reblogAction(status);
|
|
|
|
else if( action == FAVOURITE)
|
|
|
|
favouriteAction(status);
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* More option for status (report / remove status / Mute / Block)
|
|
|
|
* @param status Status current status
|
|
|
|
*/
|
|
|
|
private void moreOptionDialog(final Status status){
|
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
final boolean isOwner = status.getAccount().getId().equals(userId);
|
2017-08-12 18:41:35 +02:00
|
|
|
AlertDialog.Builder builderSingle = new AlertDialog.Builder(context, style);
|
2017-06-30 17:09:07 +02:00
|
|
|
//builderSingle.setTitle(R.string.make_a_choice);
|
2017-05-05 16:36:04 +02:00
|
|
|
final String[] stringArray, stringArrayConf;
|
|
|
|
final API.StatusAction[] doAction;
|
|
|
|
if( isOwner) {
|
|
|
|
stringArray = context.getResources().getStringArray(R.array.more_action_owner);
|
|
|
|
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
|
|
|
|
doAction = new API.StatusAction[]{API.StatusAction.UNSTATUS};
|
|
|
|
|
|
|
|
}else {
|
|
|
|
stringArray = context.getResources().getStringArray(R.array.more_action);
|
|
|
|
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
|
|
|
|
doAction = new API.StatusAction[]{API.StatusAction.MUTE,API.StatusAction.BLOCK,API.StatusAction.REPORT};
|
|
|
|
}
|
|
|
|
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, stringArray);
|
|
|
|
builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2017-08-12 18:41:35 +02:00
|
|
|
AlertDialog.Builder builderInner = new AlertDialog.Builder(context, style);
|
2017-05-05 16:36:04 +02:00
|
|
|
builderInner.setTitle(stringArrayConf[which]);
|
|
|
|
if( isOwner) {
|
2017-06-03 15:54:19 +02:00
|
|
|
if( which == 0) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
2017-08-08 18:02:06 +02:00
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
2017-06-03 15:54:19 +02:00
|
|
|
else
|
|
|
|
//noinspection deprecation
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent()));
|
2017-08-04 16:13:28 +02:00
|
|
|
}else if( which == 1){
|
2017-06-03 15:54:19 +02:00
|
|
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
String content;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
2017-08-08 18:02:06 +02:00
|
|
|
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
2017-06-03 15:54:19 +02:00
|
|
|
else
|
|
|
|
//noinspection deprecation
|
|
|
|
content = Html.fromHtml(status.getContent()).toString();
|
|
|
|
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show();
|
|
|
|
dialog.dismiss();
|
|
|
|
return;
|
2017-08-04 16:13:28 +02:00
|
|
|
}else {
|
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl());
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
|
|
|
|
return;
|
2017-06-03 15:54:19 +02:00
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}else {
|
|
|
|
if( which < 2 ){
|
|
|
|
builderInner.setMessage(status.getAccount().getAcct());
|
2017-08-04 16:13:28 +02:00
|
|
|
}else if( which == 2) {
|
2017-05-05 16:36:04 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
2017-08-08 18:02:06 +02:00
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
2017-05-05 16:36:04 +02:00
|
|
|
else
|
|
|
|
//noinspection deprecation
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent()));
|
2017-08-04 16:13:28 +02:00
|
|
|
}else if( which == 3 ){
|
2017-06-03 15:54:19 +02:00
|
|
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
String content;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
2017-08-08 18:02:06 +02:00
|
|
|
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
2017-06-03 15:54:19 +02:00
|
|
|
else
|
|
|
|
//noinspection deprecation
|
|
|
|
content = Html.fromHtml(status.getContent()).toString();
|
|
|
|
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show();
|
|
|
|
dialog.dismiss();
|
|
|
|
return;
|
2017-08-04 16:13:28 +02:00
|
|
|
}else {
|
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl());
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
|
|
|
|
return;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//Text for report
|
|
|
|
EditText input = null;
|
|
|
|
final int position = which;
|
|
|
|
if( doAction[which] == 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) {
|
|
|
|
API.StatusAction statusAction = doAction[position];
|
|
|
|
if(statusAction == API.StatusAction.REPORT || statusAction == API.StatusAction.CREATESTATUS){
|
|
|
|
String comment = null;
|
|
|
|
if( finalInput != null && finalInput.getText() != null)
|
|
|
|
comment = finalInput.getText().toString();
|
|
|
|
new PostActionAsyncTask(context, statusAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}else{
|
|
|
|
String targetedId;
|
|
|
|
if( doAction[position] == API.StatusAction.FAVOURITE ||
|
|
|
|
doAction[position] == API.StatusAction.UNFAVOURITE ||
|
|
|
|
doAction[position] == API.StatusAction.REBLOG ||
|
|
|
|
doAction[position] == API.StatusAction.UNREBLOG ||
|
|
|
|
doAction[position] == API.StatusAction.UNSTATUS
|
|
|
|
)
|
|
|
|
targetedId = status.getId();
|
|
|
|
else
|
|
|
|
targetedId = status.getAccount().getId();
|
|
|
|
new PostActionAsyncTask(context, statusAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
}
|
|
|
|
});
|
2017-06-30 17:09:07 +02:00
|
|
|
builderSingle.create().requestWindowFeature(Window.FEATURE_NO_TITLE);
|
2017-05-05 16:36:04 +02:00
|
|
|
builderSingle.show();
|
|
|
|
}
|
|
|
|
}
|