fedilab-Android-App/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java

1578 lines
79 KiB
Java
Raw Normal View History

2017-05-05 16:36:04 +02:00
/* Copyright 2017 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
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.
*
2019-05-18 11:10:30 +02:00
* Fedilab 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.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2017-05-05 16:36:04 +02:00
* see <http://www.gnu.org/licenses>. */
2019-05-18 11:10:30 +02:00
package app.fedilab.android.activities;
2017-05-05 16:36:04 +02:00
import android.content.ClipData;
import android.content.ClipboardManager;
2017-08-26 19:39:11 +02:00
import android.content.Intent;
2017-05-05 16:36:04 +02:00
import android.content.SharedPreferences;
2019-01-12 14:28:56 +01:00
import android.content.res.ColorStateList;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
2017-08-01 10:33:50 +02:00
import android.graphics.drawable.Drawable;
import android.os.Build;
2017-05-05 16:36:04 +02:00
import android.os.Bundle;
2018-09-27 19:33:22 +02:00
import android.text.Spannable;
2017-07-31 19:29:14 +02:00
import android.text.SpannableString;
2018-11-03 12:06:44 +01:00
import android.text.Spanned;
2017-07-31 19:29:14 +02:00
import android.text.method.LinkMovementMethod;
2018-09-27 19:33:22 +02:00
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
2019-12-18 09:26:21 +01:00
import android.view.LayoutInflater;
import android.view.Menu;
2017-05-05 16:36:04 +02:00
import android.view.MenuItem;
import android.view.View;
2019-09-12 19:15:14 +02:00
import android.view.inputmethod.EditorInfo;
2019-08-19 17:36:09 +02:00
import android.widget.ArrayAdapter;
2019-08-07 17:46:13 +02:00
import android.widget.EditText;
2017-10-15 09:22:56 +02:00
import android.widget.ImageButton;
2017-05-05 16:36:04 +02:00
import android.widget.ImageView;
import android.widget.LinearLayout;
2017-05-05 16:36:04 +02:00
import android.widget.TextView;
import android.widget.Toast;
2019-11-15 16:32:25 +01:00
import androidx.annotation.NonNull;
2020-04-09 14:59:36 +02:00
import androidx.annotation.Nullable;
2019-11-15 16:32:25 +01:00
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
2020-07-06 11:48:59 +02:00
import androidx.core.app.ActivityOptionsCompat;
2019-11-15 16:32:25 +01:00
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
2019-12-18 09:26:21 +01:00
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
2019-11-15 16:32:25 +01:00
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
2017-12-02 11:02:25 +01:00
import com.bumptech.glide.Glide;
2020-04-09 14:59:36 +02:00
import com.bumptech.glide.request.target.CustomTarget;
2017-12-02 11:02:25 +01:00
import com.bumptech.glide.request.transition.Transition;
2019-11-15 16:32:25 +01:00
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
2020-03-07 08:52:47 +01:00
import org.jetbrains.annotations.NotNull;
2017-05-05 16:36:04 +02:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
2018-10-24 15:44:57 +02:00
import java.util.LinkedHashMap;
2017-05-05 16:36:04 +02:00
import java.util.List;
import java.util.Map;
2019-03-01 18:50:52 +01:00
import java.util.Set;
2019-07-27 12:47:10 +02:00
import java.util.concurrent.Executors;
2019-08-16 16:56:59 +02:00
import java.util.concurrent.ScheduledExecutorService;
2019-07-27 12:47:10 +02:00
import java.util.concurrent.TimeUnit;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.R;
2019-08-19 17:36:09 +02:00
import app.fedilab.android.asynctasks.ManageListsAsyncTask;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.asynctasks.PostActionAsyncTask;
import app.fedilab.android.asynctasks.RetrieveAccountAsyncTask;
import app.fedilab.android.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
2019-12-17 19:26:03 +01:00
import app.fedilab.android.asynctasks.RetrieveIdentityProofAsyncTask;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.asynctasks.RetrieveRelationshipAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Attachment;
import app.fedilab.android.client.Entities.Error;
2019-12-17 19:26:03 +01:00
import app.fedilab.android.client.Entities.IdentityProof;
import app.fedilab.android.client.Entities.InstanceNodeInfo;
2019-08-19 17:36:09 +02:00
import app.fedilab.android.client.Entities.ManageTimelines;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.Entities.Relationship;
import app.fedilab.android.client.Entities.RemoteInstance;
import app.fedilab.android.client.Entities.Status;
2020-03-07 08:46:48 +01:00
import app.fedilab.android.client.Entities.StatusDrawerParams;
2019-09-12 19:15:14 +02:00
import app.fedilab.android.client.Entities.UserNote;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.HttpsConnection;
2019-12-18 09:26:21 +01:00
import app.fedilab.android.drawers.IdentityProofsAdapter;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.drawers.StatusListAdapter;
import app.fedilab.android.fragments.DisplayAccountsFragment;
import app.fedilab.android.fragments.DisplayStatusFragment;
import app.fedilab.android.fragments.TabLayoutTootsFragment;
import app.fedilab.android.helper.CrossActions;
import app.fedilab.android.helper.Helper;
2019-08-19 17:36:09 +02:00
import app.fedilab.android.interfaces.OnListActionInterface;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.interfaces.OnPostActionInterface;
import app.fedilab.android.interfaces.OnRetrieveAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveFeedsAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
2019-12-17 19:26:03 +01:00
import app.fedilab.android.interfaces.OnRetrieveIdentityProofInterface;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.interfaces.OnRetrieveRelationshipInterface;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.InstancesDAO;
import app.fedilab.android.sqlite.NotesDAO;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.TempMuteDAO;
import es.dmoral.toasty.Toasty;
2019-05-18 11:10:30 +02:00
2019-08-18 18:05:50 +02:00
import static app.fedilab.android.activities.BaseMainActivity.mutedAccount;
2019-08-19 17:36:09 +02:00
import static app.fedilab.android.activities.BaseMainActivity.timelines;
import static app.fedilab.android.helper.Helper.getLiveInstance;
2017-08-01 10:33:50 +02:00
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 01/05/2017.
* Show account activity class
*/
2019-12-17 19:26:03 +01:00
public class ShowAccountActivity extends BaseActivity implements OnPostActionInterface, OnRetrieveAccountInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface, OnRetrieveEmojiAccountInterface, OnListActionInterface, OnRetrieveIdentityProofInterface {
2017-05-05 16:36:04 +02:00
private List<Status> statuses;
private StatusListAdapter statusListAdapter;
2019-09-12 19:15:14 +02:00
private ImageButton account_follow, account_personal_note;
2019-08-19 17:36:09 +02:00
private String addToList;
2017-05-05 16:36:04 +02:00
private ViewPager mPager;
private TabLayout tabLayout;
2019-08-17 11:32:12 +02:00
private TextView account_note;
private TextView account_follow_request;
private TextView account_bot;
2017-05-20 19:40:46 +02:00
private String userId;
2017-07-31 20:18:14 +02:00
private Relationship relationship;
2019-08-04 10:00:21 +02:00
private ImageButton header_edit_profile;
private List<Status> pins;
private String accountUrl;
2017-10-14 10:14:55 +02:00
private int maxScrollSize;
private boolean avatarShown = true;
2017-12-02 12:23:38 +01:00
private ImageView account_pp;
2017-10-18 09:15:19 +02:00
private TextView account_dn;
private TextView account_un;
private Account account;
private boolean show_boosts, show_replies;
2018-10-22 16:18:11 +02:00
private boolean showMediaOnly, showPinned;
private boolean peertubeAccount;
2018-12-22 11:43:28 +01:00
private String accountId;
2019-01-03 18:59:44 +01:00
private boolean ischannel;
2019-08-16 16:56:59 +02:00
private ScheduledExecutorService scheduledExecutorService;
2017-05-05 16:36:04 +02:00
private action doAction;
private API.StatusAction doActionAccount;
ImageButton account_notification;
2017-10-13 19:06:39 +02:00
2017-05-05 16:36:04 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2019-05-18 11:10:30 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2019-09-06 17:55:14 +02:00
switch (theme) {
2018-05-11 11:28:05 +02:00
case Helper.THEME_LIGHT:
2019-07-20 15:15:47 +02:00
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
2018-05-11 11:28:05 +02:00
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack_NoActionBar);
break;
default:
setTheme(R.style.AppThemeDark_NoActionBar);
2017-06-30 17:09:07 +02:00
}
2017-05-05 16:36:04 +02:00
setContentView(R.layout.activity_show_account);
2017-08-13 11:30:28 +02:00
setTitle("");
pins = new ArrayList<>();
Bundle b = getIntent().getExtras();
2017-10-18 09:15:19 +02:00
account_follow = findViewById(R.id.account_follow);
2019-09-12 19:15:14 +02:00
account_personal_note = findViewById(R.id.account_personal_note);
2017-10-18 09:15:19 +02:00
account_follow_request = findViewById(R.id.account_follow_request);
header_edit_profile = findViewById(R.id.header_edit_profile);
2017-05-05 16:36:04 +02:00
account_follow.setEnabled(false);
2017-10-18 09:15:19 +02:00
account_pp = findViewById(R.id.account_pp);
account_dn = findViewById(R.id.account_dn);
account_un = findViewById(R.id.account_un);
2018-12-22 11:08:04 +01:00
account_bot = findViewById(R.id.account_bot);
account_notification = findViewById(R.id.account_notification);
2019-08-19 17:36:09 +02:00
addToList = null;
2019-11-08 18:58:12 +01:00
account_pp.setBackgroundResource(R.drawable.account_pp_border);
2019-09-06 17:55:14 +02:00
if (b != null) {
2018-12-22 11:43:28 +01:00
account = b.getParcelable("account");
2019-09-06 17:55:14 +02:00
if (account == null) {
2018-12-22 11:43:28 +01:00
accountId = b.getString("accountId");
2019-09-06 17:55:14 +02:00
} else {
2018-12-22 11:43:28 +01:00
accountId = account.getId();
}
2019-01-03 18:59:44 +01:00
ischannel = b.getBoolean("ischannel", false);
2019-01-03 17:11:53 +01:00
peertubeAccount = b.getBoolean("peertubeaccount", false);
2018-12-22 11:43:28 +01:00
if (account == null) {
2021-01-19 17:43:51 +01:00
new RetrieveAccountAsyncTask(ShowAccountActivity.this, accountId, ShowAccountActivity.this);
2018-12-22 11:43:28 +01:00
}
2017-05-20 19:40:46 +02:00
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
2019-09-06 17:55:14 +02:00
} else {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, getString(R.string.toast_error_loading_account), Toast.LENGTH_LONG).show();
2017-05-05 16:36:04 +02:00
}
accountUrl = null;
2020-03-14 08:41:21 +01:00
show_boosts = sharedpreferences.getBoolean(Helper.SHOW_ACCOUNT_BOOSTS, true);
show_replies = sharedpreferences.getBoolean(Helper.SHOW_ACCOUNT_REPLIES, true);
statuses = new ArrayList<>();
2020-04-08 12:42:15 +02:00
boolean isOnWifi = Helper.isOnWIFI(ShowAccountActivity.this);
2020-03-07 08:46:48 +01:00
StatusDrawerParams statusDrawerParams = new StatusDrawerParams();
statusDrawerParams.setType(RetrieveFeedsAsyncTask.Type.USER);
statusDrawerParams.setTargetedId(accountId);
statusDrawerParams.setOnWifi(isOnWifi);
statusDrawerParams.setStatuses(statuses);
statusListAdapter = new StatusListAdapter(statusDrawerParams);
2017-12-02 11:02:25 +01:00
2018-10-22 16:18:11 +02:00
showMediaOnly = false;
showPinned = false;
2017-05-05 16:36:04 +02:00
2017-10-18 09:15:19 +02:00
tabLayout = findViewById(R.id.account_tabLayout);
2019-11-13 12:54:01 +01:00
tabLayout.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.cyanea_primary));
2017-10-18 09:15:19 +02:00
account_note = findViewById(R.id.account_note);
2017-05-20 19:40:46 +02:00
2018-08-16 14:29:57 +02:00
2020-03-07 08:52:47 +01:00
header_edit_profile.setOnClickListener(v -> {
Intent intent = new Intent(ShowAccountActivity.this, EditProfileActivity.class);
startActivity(intent);
});
2017-10-15 09:22:56 +02:00
2019-11-09 18:07:33 +01:00
final ImageView account_menu = findViewById(R.id.account_menu);
ImageView action_more = findViewById(R.id.action_more);
ImageView reload_tabs = findViewById(R.id.reload_tabs);
ImageView action_back = findViewById(R.id.action_back);
2020-03-07 08:52:47 +01:00
account_menu.setOnClickListener(v -> showMenu(account_menu));
action_more.setOnClickListener(v -> showMenu(account_menu));
2019-08-14 18:55:45 +02:00
reload_tabs.setOnClickListener(view -> {
2019-09-06 17:55:14 +02:00
if (mPager != null && mPager
.getAdapter() != null) {
if (mPager
2019-08-15 11:59:21 +02:00
.getAdapter()
2019-09-06 17:55:14 +02:00
.instantiateItem(mPager, mPager.getCurrentItem()) instanceof TabLayoutTootsFragment) {
TabLayoutTootsFragment tabLayoutTootsFragment = (TabLayoutTootsFragment) mPager
2019-08-14 18:55:45 +02:00
.getAdapter()
2019-08-15 11:59:21 +02:00
.instantiateItem(mPager, mPager.getCurrentItem());
ViewPager viewPager = tabLayoutTootsFragment.getViewPager();
2019-09-06 17:55:14 +02:00
if (viewPager != null && viewPager.getAdapter() != null && viewPager
2019-08-14 18:55:45 +02:00
.getAdapter()
2019-09-06 17:55:14 +02:00
.instantiateItem(viewPager, viewPager.getCurrentItem()) instanceof DisplayStatusFragment) {
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) viewPager
2019-08-14 18:55:45 +02:00
.getAdapter()
2019-08-15 11:59:21 +02:00
.instantiateItem(viewPager, viewPager.getCurrentItem());
displayStatusFragment.pullToRefresh();
2019-08-14 18:55:45 +02:00
}
2019-08-15 11:59:21 +02:00
2019-09-06 17:55:14 +02:00
} else if (mPager
2019-08-15 11:59:21 +02:00
.getAdapter()
2019-09-06 17:55:14 +02:00
.instantiateItem(mPager, mPager.getCurrentItem()) instanceof DisplayAccountsFragment) {
2019-08-15 11:59:21 +02:00
DisplayAccountsFragment displayAccountsFragment = (DisplayAccountsFragment) mPager
.getAdapter()
.instantiateItem(mPager, mPager.getCurrentItem());
displayAccountsFragment.pullToRefresh();
2019-08-14 18:55:45 +02:00
}
}
});
2020-03-07 08:52:47 +01:00
action_back.setOnClickListener(v -> finish());
2019-09-06 17:55:14 +02:00
if (account != null) {
2018-12-22 11:43:28 +01:00
ManageAccount();
2018-10-22 16:18:11 +02:00
}
2017-05-05 16:36:04 +02:00
}
2019-09-06 17:55:14 +02:00
private void ManageAccount() {
2019-05-18 11:10:30 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
2017-08-01 10:33:50 +02:00
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2018-12-22 11:43:28 +01:00
accountUrl = account.getUrl();
2019-09-04 00:31:37 +02:00
int style;
if (theme == Helper.THEME_LIGHT)
style = R.style.Dialog;
else if (theme == Helper.THEME_BLACK)
style = R.style.DialogBlack;
else
style = R.style.DialogDark;
2019-01-03 18:12:24 +01:00
String accountIdRelation = accountId;
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
accountIdRelation = account.getAcct();
2019-01-04 10:11:55 +01:00
}
2021-01-19 17:43:51 +01:00
new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, accountIdRelation, ShowAccountActivity.this);
2018-12-22 11:43:28 +01:00
2019-09-25 11:43:31 +02:00
if (account.getId() != null && account.getId().equals(userId) && (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED)) {
account_follow.setVisibility(View.GONE);
header_edit_profile.setVisibility(View.VISIBLE);
header_edit_profile.bringToFront();
}
2019-12-17 19:26:03 +01:00
//TODO: add other software that supports identity proofs
2020-03-08 10:29:06 +01:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
2021-01-19 17:43:51 +01:00
new RetrieveIdentityProofAsyncTask(ShowAccountActivity.this, account.getId(), ShowAccountActivity.this);
2019-12-17 19:26:03 +01:00
}
2017-10-27 15:34:53 +02:00
String urlHeader = account.getHeader();
2018-08-19 10:57:24 +02:00
if (urlHeader != null && urlHeader.startsWith("/")) {
2018-01-24 15:56:33 +01:00
urlHeader = Helper.getLiveInstanceWithProtocol(ShowAccountActivity.this) + account.getHeader();
2017-10-27 15:34:53 +02:00
}
2018-08-19 10:57:24 +02:00
if (urlHeader != null && !urlHeader.contains("missing.png")) {
2019-08-02 16:49:02 +02:00
boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false);
2019-08-19 11:02:22 +02:00
ImageView banner_pp = findViewById(R.id.banner_pp);
2019-09-06 17:55:14 +02:00
if (!disableGif) {
2019-08-19 11:02:22 +02:00
Glide.with(banner_pp.getContext())
2019-08-02 16:49:02 +02:00
.load(urlHeader)
.into(banner_pp);
2019-09-06 17:55:14 +02:00
} else {
2019-08-19 11:02:22 +02:00
Glide.with(banner_pp.getContext())
2019-08-02 16:49:02 +02:00
.asBitmap()
.load(urlHeader)
2020-04-09 14:59:36 +02:00
.into(new CustomTarget<Bitmap>() {
2019-08-02 16:49:02 +02:00
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
2019-08-19 11:02:22 +02:00
2019-08-02 16:49:02 +02:00
banner_pp.setImageBitmap(resource);
}
2020-04-09 14:59:36 +02:00
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
2019-08-02 16:49:02 +02:00
});
}
}
2017-08-01 10:33:50 +02:00
//Redraws icon for locked accounts
final float scale = getResources().getDisplayMetrics().density;
2019-09-06 17:55:14 +02:00
if (account.isLocked()) {
2019-11-23 11:52:47 +01:00
Drawable img = ContextCompat.getDrawable(ShowAccountActivity.this, R.drawable.ic_locked_account);
assert img != null;
2019-09-06 17:55:14 +02:00
img.setBounds(0, 0, (int) (16 * scale + 0.5f), (int) (16 * scale + 0.5f));
account_un.setCompoundDrawables(null, null, img, null);
} else {
account_un.setCompoundDrawables(null, null, null, null);
2017-08-01 10:33:50 +02:00
}
2019-01-03 17:11:53 +01:00
//Peertube account watched by a Mastodon account
2018-12-22 11:08:04 +01:00
//Bot account
2019-09-06 17:55:14 +02:00
if (account.isBot()) {
2018-12-22 11:08:04 +01:00
account_bot.setVisibility(View.VISIBLE);
}
2017-10-27 15:34:53 +02:00
TextView actionbar_title = findViewById(R.id.show_account_title);
2019-09-06 17:55:14 +02:00
if (account.getAcct() != null)
2017-10-27 15:34:53 +02:00
actionbar_title.setText(account.getAcct());
2019-08-17 11:32:12 +02:00
ImageView pp_actionBar = findViewById(R.id.pp_actionBar);
2019-09-06 17:55:14 +02:00
if (account.getAvatar() != null) {
2020-04-08 12:42:15 +02:00
Helper.loadGiF(ShowAccountActivity.this, account, pp_actionBar);
2017-12-02 12:23:38 +01:00
2018-08-24 15:47:16 +02:00
}
2017-10-27 15:34:53 +02:00
final AppBarLayout appBar = findViewById(R.id.appBar);
maxScrollSize = appBar.getTotalScrollRange();
2017-10-13 19:06:39 +02:00
final TextView warning_message = findViewById(R.id.warning_message);
final SpannableString content = new SpannableString(getString(R.string.disclaimer_full));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
2019-11-09 17:11:55 +01:00
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(ShowAccountActivity.this, R.color.cyanea_accent_reference)), 0, content.length(),
2019-11-07 20:23:07 +01:00
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
warning_message.setText(content);
2020-03-07 08:52:47 +01:00
warning_message.setOnClickListener(view -> {
if (!accountUrl.toLowerCase().startsWith("http://") && !accountUrl.toLowerCase().startsWith("https://"))
accountUrl = "http://" + accountUrl;
Helper.openBrowser(ShowAccountActivity.this, accountUrl);
});
//Timed muted account
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
2019-06-05 14:35:42 +02:00
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
2020-04-09 18:57:12 +02:00
final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
2020-04-08 12:42:15 +02:00
final Account authenticatedAccount = new AccountDAO(ShowAccountActivity.this, db).getUniqAccount(userId, instance);
boolean isTimedMute = new TempMuteDAO(ShowAccountActivity.this, db).isTempMuted(authenticatedAccount, accountId);
2019-09-06 17:55:14 +02:00
if (isTimedMute) {
2020-04-08 12:42:15 +02:00
String date_mute = new TempMuteDAO(ShowAccountActivity.this, db).getMuteDateByID(authenticatedAccount, accountId);
2019-09-06 17:55:14 +02:00
if (date_mute != null) {
final TextView temp_mute = findViewById(R.id.temp_mute);
temp_mute.setVisibility(View.VISIBLE);
SpannableString content_temp_mute = new SpannableString(getString(R.string.timed_mute_profile, account.getAcct(), date_mute));
content_temp_mute.setSpan(new UnderlineSpan(), 0, content_temp_mute.length(), 0);
temp_mute.setText(content_temp_mute);
2020-03-07 08:52:47 +01:00
temp_mute.setOnClickListener(view -> {
2020-04-08 12:42:15 +02:00
new TempMuteDAO(ShowAccountActivity.this, db).remove(authenticatedAccount, accountId);
2020-03-07 08:52:47 +01:00
mutedAccount.remove(accountId);
2020-04-08 12:42:15 +02:00
Toasty.success(ShowAccountActivity.this, getString(R.string.toast_unmute), Toast.LENGTH_LONG).show();
2020-03-07 08:52:47 +01:00
temp_mute.setVisibility(View.GONE);
});
}
}
//This account was moved to another one
2019-09-06 17:55:14 +02:00
if (account.getMoved_to_account() != null) {
TextView account_moved = findViewById(R.id.account_moved);
account_moved.setVisibility(View.VISIBLE);
Drawable imgTravel = ContextCompat.getDrawable(ShowAccountActivity.this, R.drawable.ic_card_travel);
assert imgTravel != null;
2019-09-06 17:55:14 +02:00
imgTravel.setBounds(0, 0, (int) (20 * scale + 0.5f), (int) (20 * scale + 0.5f));
account_moved.setCompoundDrawables(imgTravel, null, null, null);
//Retrieves content and make account names clickable
SpannableString spannableString = account.moveToText(ShowAccountActivity.this);
account_moved.setText(spannableString, TextView.BufferType.SPANNABLE);
account_moved.setMovementMethod(LinkMovementMethod.getInstance());
}
2018-08-15 10:00:24 +02:00
2019-09-06 17:55:14 +02:00
if (account.getAcct().contains("@"))
warning_message.setVisibility(View.VISIBLE);
else
warning_message.setVisibility(View.GONE);
2020-03-07 08:52:47 +01:00
appBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
LinearLayout toolbarContent = findViewById(R.id.toolbar_content);
if (toolbarContent != null) {
if (Math.abs(verticalOffset) - appBar.getTotalScrollRange() == 0) {
if (toolbarContent.getVisibility() == View.GONE)
toolbarContent.setVisibility(View.VISIBLE);
} else {
if (toolbarContent.getVisibility() == View.VISIBLE)
toolbarContent.setVisibility(View.GONE);
2017-10-27 15:34:53 +02:00
}
2020-03-07 08:52:47 +01:00
}
if (maxScrollSize == 0)
maxScrollSize = appBarLayout.getTotalScrollRange();
2017-10-14 11:09:12 +02:00
2020-03-07 08:52:47 +01:00
int percentage = (Math.abs(verticalOffset)) * 100 / maxScrollSize;
2017-10-14 11:09:12 +02:00
2020-03-07 08:52:47 +01:00
if (percentage >= 40 && avatarShown) {
avatarShown = false;
2017-10-14 11:09:12 +02:00
2020-03-07 08:52:47 +01:00
account_pp.animate()
.scaleY(0).scaleX(0)
.setDuration(400)
.start();
warning_message.setVisibility(View.GONE);
}
if (percentage <= 40 && !avatarShown) {
avatarShown = true;
account_pp.animate()
.scaleY(1).scaleX(1)
.start();
if (account.getAcct().contains("@"))
warning_message.setVisibility(View.VISIBLE);
else
warning_message.setVisibility(View.GONE);
2017-10-27 15:34:53 +02:00
}
});
2018-10-22 17:09:25 +02:00
mPager = findViewById(R.id.account_viewpager);
2019-09-06 17:55:14 +02:00
if (!peertubeAccount) {
2018-10-22 16:18:11 +02:00
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.followers)));
2019-07-03 11:39:10 +02:00
mPager.setOffscreenPageLimit(3);
2019-09-06 17:55:14 +02:00
} else if (!ischannel) {
2018-10-22 16:18:11 +02:00
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.videos)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.channels)));
2019-07-03 11:39:10 +02:00
mPager.setOffscreenPageLimit(2);
2019-09-06 17:55:14 +02:00
} else {
2019-01-04 10:11:55 +01:00
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.videos)));
mPager.setOffscreenPageLimit(1);
2018-10-22 16:18:11 +02:00
}
2018-10-22 17:09:25 +02:00
2018-10-22 16:18:11 +02:00
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
2019-09-06 17:55:14 +02:00
if (tab != null)
2018-10-22 16:18:11 +02:00
tab.select();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null;
2019-09-06 17:55:14 +02:00
if (mPager.getAdapter() != null)
2018-10-22 16:18:11 +02:00
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
2019-09-06 17:55:14 +02:00
switch (tab.getPosition()) {
2018-10-22 16:18:11 +02:00
case 0:
2019-09-06 17:55:14 +02:00
if (mPager != null && mPager
2019-08-17 14:25:38 +02:00
.getAdapter() != null) {
if (mPager
.getAdapter()
.instantiateItem(mPager, mPager.getCurrentItem()) instanceof TabLayoutTootsFragment) {
TabLayoutTootsFragment tabLayoutTootsFragment = (TabLayoutTootsFragment) mPager
.getAdapter()
.instantiateItem(mPager, mPager.getCurrentItem());
ViewPager viewPager = tabLayoutTootsFragment.getViewPager();
if (viewPager != null && viewPager.getAdapter() != null && viewPager
.getAdapter()
.instantiateItem(viewPager, viewPager.getCurrentItem()) instanceof DisplayStatusFragment) {
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) viewPager
.getAdapter()
.instantiateItem(viewPager, viewPager.getCurrentItem());
displayStatusFragment.scrollToTop();
}
}
2019-08-17 11:32:12 +02:00
}
2019-08-17 14:25:38 +02:00
2018-10-22 16:18:11 +02:00
break;
case 1:
case 2:
2019-09-06 17:55:14 +02:00
if (fragment != null) {
2018-10-22 16:18:11 +02:00
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
displayAccountsFragment.scrollToTop();
}
break;
}
}
});
2018-08-15 14:31:15 +02:00
2019-09-06 17:55:14 +02:00
if ((MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) && account.getFields() != null && account.getFields().size() > 0) {
2018-10-24 15:44:57 +02:00
LinkedHashMap<String, String> fields = account.getFields();
LinkedHashMap<String, Boolean> fieldsVerified = account.getFieldsVerified();
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<String, String>> it = fields.entrySet().iterator();
int i = 1;
LinearLayout fields_container = findViewById(R.id.fields_container);
2019-09-06 17:55:14 +02:00
if (fields_container != null)
fields_container.setVisibility(View.VISIBLE);
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<String, String> pair = it.next();
String label = pair.getKey();
2019-09-06 17:55:14 +02:00
if (label != null && fieldsVerified != null && fieldsVerified.containsKey(label)) {
2019-01-02 13:31:11 +01:00
boolean verified = fieldsVerified.get(label);
LinearLayout field;
TextView labelView;
TextView valueView;
LinearLayout verifiedView;
switch (i) {
case 1:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
verifiedView = findViewById(R.id.value1BG);
break;
case 2:
field = findViewById(R.id.field2);
labelView = findViewById(R.id.label2);
valueView = findViewById(R.id.value2);
verifiedView = findViewById(R.id.value2BG);
break;
2019-01-02 13:31:11 +01:00
case 3:
field = findViewById(R.id.field3);
labelView = findViewById(R.id.label3);
valueView = findViewById(R.id.value3);
verifiedView = findViewById(R.id.value3BG);
break;
2020-03-07 08:52:47 +01:00
default:
2019-01-02 13:31:11 +01:00
field = findViewById(R.id.field4);
labelView = findViewById(R.id.label4);
valueView = findViewById(R.id.value4);
verifiedView = findViewById(R.id.value4BG);
break;
2018-09-27 19:33:22 +02:00
}
2019-01-02 13:31:11 +01:00
if (field != null && labelView != null && valueView != null) {
field.setVisibility(View.VISIBLE);
if (verified) {
verifiedView.setBackgroundResource(R.drawable.verified);
}
2018-12-31 16:11:44 +01:00
2019-01-02 13:31:11 +01:00
}
}
i++;
}
}
2020-04-08 15:29:02 +02:00
account_dn.setText(account.getDisplay_name());
2019-09-06 17:55:14 +02:00
if (!ischannel || account.getAcct().split("-").length < 4) {
2019-01-05 09:55:56 +01:00
account_un.setText(String.format("@%s", account.getAcct()));
2020-03-07 08:52:47 +01:00
account_un.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
String account_id = account.getAcct();
if (account_id.split("@").length == 1)
2020-04-08 12:42:15 +02:00
account_id += "@" + Helper.getLiveInstance(ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
ClipData clip = ClipData.newPlainText("mastodon_account_id", "@" + account_id);
2020-04-08 12:42:15 +02:00
Toasty.info(ShowAccountActivity.this, getString(R.string.account_id_clipbloard), Toast.LENGTH_SHORT).show();
2020-03-07 08:52:47 +01:00
assert clipboard != null;
clipboard.setPrimaryClip(clip);
return false;
2019-01-05 09:55:56 +01:00
});
2019-09-06 17:55:14 +02:00
} else {
2019-01-05 09:55:56 +01:00
account_un.setVisibility(View.GONE);
}
2018-11-14 18:12:59 +01:00
SpannableString spannableString = Helper.clickableElementsDescription(ShowAccountActivity.this, account.getNote());
2018-08-15 10:00:24 +02:00
account.setNoteSpan(spannableString);
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
2020-06-16 20:09:29 +02:00
account.fillProfileAccount(ShowAccountActivity.this, ShowAccountActivity.this, account);
2018-08-15 14:31:15 +02:00
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
2017-10-27 15:34:53 +02:00
account_note.setMovementMethod(LinkMovementMethod.getInstance());
2018-10-22 16:18:11 +02:00
if (!peertubeAccount && tabLayout.getTabAt(0) != null && tabLayout.getTabAt(1) != null && tabLayout.getTabAt(2) != null) {
2019-05-18 11:10:30 +02:00
tabLayout.getTabAt(0).setText(getString(R.string.status_cnt, Helper.withSuffix(account.getStatuses_count())));
tabLayout.getTabAt(1).setText(getString(R.string.following_cnt, Helper.withSuffix(account.getFollowing_count())));
tabLayout.getTabAt(2).setText(getString(R.string.followers_cnt, Helper.withSuffix(account.getFollowers_count())));
2017-10-27 15:34:53 +02:00
//Allows to filter by long click
2018-10-22 16:18:11 +02:00
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
2020-03-07 08:52:47 +01:00
tabStrip.getChildAt(0).setOnLongClickListener(v -> {
PopupMenu popup = new PopupMenu(ShowAccountActivity.this, tabStrip.getChildAt(0));
popup.getMenuInflater()
.inflate(R.menu.option_filter_toots_account, popup.getMenu());
Menu menu = popup.getMenu();
popup.getMenu().findItem(R.id.action_show_pinned).setVisible(false);
final MenuItem itemShowPined = menu.findItem(R.id.action_show_pinned);
final MenuItem itemShowMedia = menu.findItem(R.id.action_show_media);
final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts);
final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies);
itemShowMedia.setChecked(showMediaOnly);
itemShowPined.setChecked(showPinned);
itemShowBoosts.setChecked(show_boosts);
itemShowReplies.setChecked(show_replies);
popup.setOnDismissListener(menu1 -> {
if (mPager != null && mPager
.getAdapter() != null) {
if (mPager
.getAdapter()
.instantiateItem(mPager, mPager.getCurrentItem()) instanceof TabLayoutTootsFragment) {
TabLayoutTootsFragment tabLayoutTootsFragment = (TabLayoutTootsFragment) mPager
.getAdapter()
.instantiateItem(mPager, mPager.getCurrentItem());
ViewPager viewPager = tabLayoutTootsFragment.getViewPager();
if (viewPager != null && viewPager.getAdapter() != null && viewPager
.getAdapter()
.instantiateItem(viewPager, viewPager.getCurrentItem()) instanceof DisplayStatusFragment) {
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) viewPager
2019-08-17 11:32:12 +02:00
.getAdapter()
2020-03-07 08:52:47 +01:00
.instantiateItem(viewPager, viewPager.getCurrentItem());
displayStatusFragment.pullToRefresh();
displayStatusFragment.refreshFilter();
2019-08-17 11:32:12 +02:00
}
2017-10-15 09:22:56 +02:00
}
2020-03-07 08:52:47 +01:00
}
2017-10-15 09:22:56 +02:00
2020-03-07 08:52:47 +01:00
});
popup.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
2020-04-08 12:42:15 +02:00
item.setActionView(new View(ShowAccountActivity.this));
2020-03-07 08:52:47 +01:00
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
2020-03-07 08:52:47 +01:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
2017-10-27 15:34:53 +02:00
}
});
2021-01-19 17:43:51 +01:00
int itemId = item.getItemId();
if (itemId == R.id.action_show_pinned) {
showPinned = !showPinned;
} else if (itemId == R.id.action_show_media) {
showMediaOnly = !showMediaOnly;
} else if (itemId == R.id.action_show_boosts) {
show_boosts = !show_boosts;
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOW_ACCOUNT_BOOSTS, show_boosts);
editor.apply();
} else if (itemId == R.id.action_show_replies) {
SharedPreferences.Editor editor;
show_replies = !show_replies;
editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOW_ACCOUNT_REPLIES, show_replies);
editor.apply();
2020-03-07 08:52:47 +01:00
}
if (tabLayout.getTabAt(0) != null)
tabLayout.getTabAt(0).select();
PagerAdapter mPagerAdapter1 = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter1);
itemShowMedia.setChecked(showMediaOnly);
itemShowPined.setChecked(showPinned);
itemShowReplies.setChecked(show_replies);
itemShowBoosts.setChecked(show_boosts);
2017-10-27 15:34:53 +02:00
return true;
2020-03-07 08:52:47 +01:00
});
popup.show();
return true;
2018-10-22 16:18:11 +02:00
});
2017-10-15 09:22:56 +02:00
2017-10-27 15:34:53 +02:00
}
2020-04-08 12:42:15 +02:00
Helper.loadGiF(ShowAccountActivity.this, account, account_pp);
2020-03-07 08:52:47 +01:00
account_pp.setOnClickListener(v -> {
Intent intent = new Intent(ShowAccountActivity.this, SlideMediaActivity.class);
Bundle b = new Bundle();
Attachment attachment = new Attachment();
attachment.setDescription(account.getAcct());
attachment.setPreview_url(account.getAvatar());
attachment.setUrl(account.getAvatar());
attachment.setRemote_url(account.getAvatar());
attachment.setType("image");
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
intent.putParcelableArrayListExtra("mediaArray", attachments);
b.putInt("position", 1);
2020-05-16 17:06:13 +02:00
b.putInt("bgcolor", getResources().getColor(R.color.cyanea_primary_dark));
2020-03-07 08:52:47 +01:00
intent.putExtras(b);
2020-07-06 11:48:59 +02:00
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(ShowAccountActivity.this, account_pp, attachment.getUrl());
// start the new activity
startActivity(intent, options.toBundle());
2020-07-08 09:48:45 +02:00
} else {
2020-07-06 11:48:59 +02:00
// start the new activity
startActivity(intent);
}
2018-09-05 10:19:07 +02:00
});
2018-08-16 14:29:57 +02:00
//Follow button
String target = account.getId();
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
target = account.getAcct();
String finalTarget = target;
account_notification.setOnClickListener(v -> {
if (relationship != null) {
new PostActionAsyncTask(ShowAccountActivity.this, relationship.isNotifying() ? API.StatusAction.UNNOTIFY_FOR_ACCOUNT : API.StatusAction.NOTIFY_FOR_ACCOUNT, finalTarget, ShowAccountActivity.this);
}
});
2020-03-07 08:52:47 +01:00
account_follow.setOnClickListener(v -> {
if (doAction == action.NOTHING) {
2020-04-08 12:42:15 +02:00
Toasty.info(ShowAccountActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
2020-03-07 08:52:47 +01:00
} else if (doAction == action.FOLLOW) {
account_follow.setEnabled(false);
2021-01-19 17:43:51 +01:00
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.FOLLOW, finalTarget, ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
} else if (doAction == action.UNFOLLOW) {
boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true);
if (confirm_unfollow) {
AlertDialog.Builder unfollowConfirm = new AlertDialog.Builder(ShowAccountActivity.this, style);
unfollowConfirm.setTitle(getString(R.string.unfollow_confirm));
unfollowConfirm.setMessage(account.getAcct());
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> {
2019-09-04 00:31:37 +02:00
account_follow.setEnabled(false);
2021-01-19 17:43:51 +01:00
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
dialog.dismiss();
});
unfollowConfirm.show();
} else {
2018-08-16 14:29:57 +02:00
account_follow.setEnabled(false);
2021-01-19 17:43:51 +01:00
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this);
2018-08-16 14:29:57 +02:00
}
2020-03-07 08:52:47 +01:00
} else if (doAction == action.UNBLOCK) {
account_follow.setEnabled(false);
2021-01-19 17:43:51 +01:00
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.UNBLOCK, finalTarget, ShowAccountActivity.this);
2018-08-16 14:29:57 +02:00
}
});
2020-03-07 08:52:47 +01:00
account_follow.setOnLongClickListener(v -> {
CrossActions.doCrossAction(ShowAccountActivity.this, null, null, account, API.StatusAction.FOLLOW, null, ShowAccountActivity.this, false);
return false;
2018-08-16 14:29:57 +02:00
});
2019-09-12 19:15:14 +02:00
2020-04-08 12:42:15 +02:00
UserNote userNote = new NotesDAO(ShowAccountActivity.this, db).getUserNote(account.getAcct());
2019-11-15 16:32:25 +01:00
if (userNote != null) {
2019-09-12 19:15:14 +02:00
account_personal_note.setVisibility(View.VISIBLE);
2019-11-15 16:32:25 +01:00
account_personal_note.setOnClickListener(view -> {
2019-09-12 19:15:14 +02:00
AlertDialog.Builder builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
builderInner.setTitle(R.string.note_for_account);
EditText input = new EditText(ShowAccountActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
input.setSingleLine(false);
input.setText(userNote.getNote());
input.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
builderInner.setView(input);
2020-03-07 08:52:47 +01:00
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.validate, (dialog, which) -> {
2020-04-08 12:42:15 +02:00
UserNote userNote1 = new NotesDAO(ShowAccountActivity.this, db).getUserNote(account.getAcct());
2020-03-07 08:52:47 +01:00
if (userNote1 == null) {
userNote1 = new UserNote();
userNote1.setAcct(account.getAcct());
2019-09-12 19:15:14 +02:00
}
2020-03-07 08:52:47 +01:00
userNote1.setNote(input.getText().toString());
2020-04-08 12:42:15 +02:00
new NotesDAO(ShowAccountActivity.this, db).insertInstance(userNote1);
2020-03-07 08:52:47 +01:00
if (input.getText().toString().trim().length() > 0) {
account_personal_note.setVisibility(View.VISIBLE);
} else {
account_personal_note.setVisibility(View.GONE);
2019-09-12 19:15:14 +02:00
}
2020-03-07 08:52:47 +01:00
dialog.dismiss();
2019-09-12 19:15:14 +02:00
});
builderInner.show();
});
}
TextView account_date = findViewById(R.id.account_date);
account_date.setText(Helper.shortDateToString(account.getCreated_at()));
2019-11-16 17:12:47 +01:00
account_date.setVisibility(View.VISIBLE);
2020-03-07 08:52:47 +01:00
new Thread(() -> {
2020-04-08 12:42:15 +02:00
String instance1 = getLiveInstance(ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
if (account.getAcct().split("@").length > 1) {
instance1 = account.getAcct().split("@")[1];
}
InstanceNodeInfo instanceNodeInfo = new API(ShowAccountActivity.this).displayNodeInfo(instance1);
String finalInstance = instance1;
runOnUiThread(() -> {
if (instanceNodeInfo != null && instanceNodeInfo.getName() != null) {
TextView instance_info = findViewById(R.id.instance_info);
instance_info.setText(instanceNodeInfo.getName());
instance_info.setVisibility(View.VISIBLE);
instance_info.setOnClickListener(v -> {
2020-04-08 12:42:15 +02:00
Intent intent = new Intent(ShowAccountActivity.this, InstanceProfileActivity.class);
2020-03-07 08:52:47 +01:00
Bundle b = new Bundle();
b.putString("instance", finalInstance);
intent.putExtras(b);
startActivity(intent);
2019-11-16 11:36:00 +01:00
2020-03-07 08:52:47 +01:00
});
}
});
}).start();
2017-12-02 12:23:38 +01:00
}
2017-10-15 09:22:56 +02:00
2017-05-05 16:36:04 +02:00
@Override
public void onRetrieveFeedsAccount(List<Status> statuses) {
2019-09-06 17:55:14 +02:00
if (statuses != null) {
2017-10-27 15:34:53 +02:00
this.statuses.addAll(statuses);
2017-05-05 16:36:04 +02:00
statusListAdapter.notifyDataSetChanged();
}
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
2019-09-06 17:55:14 +02:00
if (apiResponse.getError() != null) {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
pins = apiResponse.getStatuses();
2017-09-15 19:15:23 +02:00
if (pins != null && pins.size() > 0) {
2019-01-03 17:11:53 +01:00
if (pins.get(0).isPinned()) {
2017-10-27 15:34:53 +02:00
this.statuses.addAll(pins);
2017-09-15 19:15:23 +02:00
tabLayout.getTabAt(3).setText(getString(R.string.pins_cnt, pins.size()));
statusListAdapter.notifyDataSetChanged();
}
}
}
2017-05-05 16:36:04 +02:00
@Override
public void onRetrieveRelationship(Relationship relationship, Error error) {
2019-09-06 17:55:14 +02:00
if (error != null) {
2019-11-15 16:32:25 +01:00
if (error.getError().length() < 100) {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
2019-11-15 16:32:25 +01:00
} else {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
2019-09-30 18:14:46 +02:00
}
return;
}
2017-07-31 20:18:14 +02:00
this.relationship = relationship;
manageButtonVisibility();
//The authenticated account is followed by the account
2019-09-06 17:55:14 +02:00
if (relationship != null && relationship.isFollowed_by() && !accountId.equals(userId)) {
2017-10-18 09:15:19 +02:00
TextView account_followed_by = findViewById(R.id.account_followed_by);
2017-07-31 20:18:14 +02:00
account_followed_by.setVisibility(View.VISIBLE);
}
2018-09-04 19:27:26 +02:00
invalidateOptionsMenu();
2017-07-31 20:18:14 +02:00
}
//Manages the visibility of the button
2019-09-06 17:55:14 +02:00
private void manageButtonVisibility() {
if (relationship == null)
2017-07-31 20:18:14 +02:00
return;
2019-08-04 10:00:21 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
2020-03-08 10:29:06 +01:00
int[][] states = new int[][]{
new int[]{android.R.attr.state_enabled}, // enabled
new int[]{-android.R.attr.state_enabled}, // disabled
new int[]{-android.R.attr.state_checked}, // unchecked
new int[]{android.R.attr.state_pressed} // pressed
};
2020-03-08 10:29:06 +01:00
int[] colors = new int[]{
ContextCompat.getColor(ShowAccountActivity.this, R.color.mastodonC4),
ContextCompat.getColor(ShowAccountActivity.this, R.color.mastodonC4___),
ContextCompat.getColor(ShowAccountActivity.this, R.color.mastodonC4),
ContextCompat.getColor(ShowAccountActivity.this, R.color.mastodonC4)
};
account_follow.setBackgroundTintList(new ColorStateList(states, colors));
2019-08-04 10:00:21 +02:00
}
account_follow.setEnabled(true);
2019-09-25 11:43:31 +02:00
if (relationship.isBlocking()) {
2017-10-28 17:59:50 +02:00
account_follow.setImageResource(R.drawable.ic_lock_open);
2017-05-05 16:36:04 +02:00
doAction = action.UNBLOCK;
2019-08-04 10:00:21 +02:00
account_follow.setVisibility(View.VISIBLE);
2020-02-01 12:22:22 +01:00
account_follow.setContentDescription(getString(R.string.action_unblock));
} else if (relationship.isBlocked_by()) {
account_follow.setImageResource(R.drawable.ic_user_plus);
account_follow.setVisibility(View.VISIBLE);
account_follow.setEnabled(false);
2020-02-01 12:22:22 +01:00
account_follow.setContentDescription(getString(R.string.action_disabled));
doAction = action.NOTHING;
2020-03-08 10:29:06 +01:00
} else if (relationship.isRequested()) {
2017-07-31 19:29:14 +02:00
account_follow_request.setVisibility(View.VISIBLE);
2019-01-02 14:47:33 +01:00
account_follow.setImageResource(R.drawable.ic_hourglass_full);
2019-08-04 10:00:21 +02:00
account_follow.setVisibility(View.VISIBLE);
2020-02-01 12:22:22 +01:00
account_follow.setContentDescription(getString(R.string.follow_request));
2019-01-02 14:47:33 +01:00
doAction = action.UNFOLLOW;
2019-09-06 17:55:14 +02:00
} else if (relationship.isFollowing()) {
2019-11-10 10:48:43 +01:00
account_follow.setImageResource(R.drawable.ic_user_minus);
2019-08-04 10:00:21 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowAccountActivity.this, R.color.red_1)));
}
2017-05-05 16:36:04 +02:00
doAction = action.UNFOLLOW;
2020-02-01 12:22:22 +01:00
account_follow.setContentDescription(getString(R.string.action_unfollow));
2019-08-04 10:00:21 +02:00
account_follow.setVisibility(View.VISIBLE);
2019-09-06 17:55:14 +02:00
} else if (!relationship.isFollowing()) {
2017-07-31 19:29:14 +02:00
account_follow.setImageResource(R.drawable.ic_user_plus);
2017-05-05 16:36:04 +02:00
doAction = action.FOLLOW;
2019-09-06 17:55:14 +02:00
account_follow.setVisibility(View.VISIBLE);
2020-02-01 12:22:22 +01:00
account_follow.setContentDescription(getString(R.string.action_follow));
2019-09-06 17:55:14 +02:00
} else {
2019-08-04 10:00:21 +02:00
account_follow.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
doAction = action.NOTHING;
}
if (!relationship.isFollowing()) {
account_notification.setVisibility(View.GONE);
} else {
account_notification.setVisibility(View.VISIBLE);
}
if (relationship.isNotifying()) {
account_notification.setImageResource(R.drawable.ic_baseline_notifications_account_yes);
} else {
account_notification.setImageResource(R.drawable.ic_baseline_notifications_account_none);
}
2017-05-05 16:36:04 +02:00
}
2018-08-15 14:31:15 +02:00
@Override
public void onRetrieveEmojiAccount(Account account) {
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
2020-04-09 11:04:38 +02:00
account_dn.setText(account.getDisplayNameSpan(), TextView.BufferType.SPANNABLE);
2018-12-31 16:11:44 +01:00
LinkedHashMap<String, Boolean> fieldsVerified = account.getFieldsVerified();
2019-09-06 17:55:14 +02:00
if (account.getFieldsSpan() != null && account.getFieldsSpan().size() > 0) {
HashMap<SpannableString, SpannableString> fieldsSpan = account.getFieldsSpan();
2020-06-17 18:20:35 +02:00
Iterator<Map.Entry<SpannableString, SpannableString>> it = fieldsSpan.entrySet().iterator();
2018-08-15 14:31:15 +02:00
int i = 1;
LinearLayout fields_container = findViewById(R.id.fields_container);
2019-09-06 17:55:14 +02:00
if (fields_container != null)
2018-08-15 14:31:15 +02:00
fields_container.setVisibility(View.VISIBLE);
while (it.hasNext()) {
2020-06-17 18:20:35 +02:00
Map.Entry<SpannableString, SpannableString> pair = it.next();
SpannableString label = pair.getKey();
SpannableString value = pair.getValue();
2018-08-15 14:31:15 +02:00
LinearLayout field;
TextView labelView;
TextView valueView;
2019-09-06 17:55:14 +02:00
switch (i) {
2018-08-15 14:31:15 +02:00
case 2:
field = findViewById(R.id.field2);
labelView = findViewById(R.id.label2);
valueView = findViewById(R.id.value2);
break;
case 3:
field = findViewById(R.id.field3);
labelView = findViewById(R.id.label3);
valueView = findViewById(R.id.value3);
break;
case 4:
field = findViewById(R.id.field4);
labelView = findViewById(R.id.label4);
valueView = findViewById(R.id.value4);
break;
default:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
break;
}
2019-09-06 17:55:14 +02:00
if (field != null && labelView != null && valueView != null) {
2018-08-15 14:31:15 +02:00
field.setVisibility(View.VISIBLE);
valueView.setText(value, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
2019-09-06 17:55:14 +02:00
if (field != null && labelView != null && valueView != null) {
2019-11-15 16:32:25 +01:00
boolean verified = fieldsVerified.get(pair.getKey().toString());
2019-09-06 17:55:14 +02:00
if (verified) {
2018-12-31 16:11:44 +01:00
valueView.setBackgroundResource(R.drawable.verified);
value.setSpan(new ForegroundColorSpan(ContextCompat.getColor(ShowAccountActivity.this, R.color.verified_text)), 0, value.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
field.setVisibility(View.VISIBLE);
valueView.setText(value, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
2018-08-15 14:31:15 +02:00
i++;
}
}
2019-09-06 17:55:14 +02:00
if (account.getEmojis() != null && account.getEmojis().size() > 0) {
2019-08-16 16:56:59 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
2019-09-06 17:55:14 +02:00
if (!disableAnimatedEmoji) {
2019-08-16 16:56:59 +02:00
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
2020-03-07 08:52:47 +01:00
scheduledExecutorService.scheduleAtFixedRate(() -> account_dn.invalidate(), 0, 130, TimeUnit.MILLISECONDS);
2019-08-16 16:56:59 +02:00
}
}
2018-08-15 14:31:15 +02:00
}
2019-09-06 17:55:14 +02:00
private void showMenu(View account_menu) {
if (account == null)
2018-12-22 11:43:28 +01:00
return;
final PopupMenu popup = new PopupMenu(ShowAccountActivity.this, account_menu);
popup.getMenuInflater()
.inflate(R.menu.main_showaccount, popup.getMenu());
final String[] stringArrayConf;
final boolean isOwner = account.getId().equals(userId);
String[] splitAcct = account.getAcct().split("@");
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
2019-03-01 18:50:52 +01:00
popup.getMenu().findItem(R.id.action_filter).setVisible(true);
2019-09-06 17:55:14 +02:00
if (splitAcct.length <= 1) {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_follow_instance).setVisible(false);
popup.getMenu().findItem(R.id.action_block_instance).setVisible(false);
2019-09-06 17:55:14 +02:00
}
if (isOwner) {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_block).setVisible(false);
2019-08-07 17:46:13 +02:00
popup.getMenu().findItem(R.id.action_report).setVisible(false);
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
popup.getMenu().findItem(R.id.action_follow_instance).setVisible(false);
popup.getMenu().findItem(R.id.action_block_instance).setVisible(false);
popup.getMenu().findItem(R.id.action_hide_boost).setVisible(false);
popup.getMenu().findItem(R.id.action_endorse).setVisible(false);
popup.getMenu().findItem(R.id.action_direct_message).setVisible(false);
2019-09-12 19:15:14 +02:00
popup.getMenu().findItem(R.id.action_add_notes).setVisible(false);
2019-08-19 17:36:09 +02:00
popup.getMenu().findItem(R.id.action_add_to_list).setVisible(false);
2019-09-06 17:55:14 +02:00
stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm);
} else {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_block).setVisible(true);
popup.getMenu().findItem(R.id.action_mute).setVisible(true);
popup.getMenu().findItem(R.id.action_mention).setVisible(true);
2019-09-06 17:55:14 +02:00
stringArrayConf = getResources().getStringArray(R.array.more_action_confirm);
2018-12-22 11:43:28 +01:00
}
2019-09-06 17:55:14 +02:00
if (peertubeAccount) {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_hide_boost).setVisible(false);
popup.getMenu().findItem(R.id.action_endorse).setVisible(false);
popup.getMenu().findItem(R.id.action_direct_message).setVisible(false);
2019-08-19 17:36:09 +02:00
popup.getMenu().findItem(R.id.action_add_to_list).setVisible(false);
2018-12-22 11:43:28 +01:00
}
2019-09-06 17:55:14 +02:00
if (relationship != null) {
if (!relationship.isFollowing()) {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_hide_boost).setVisible(false);
popup.getMenu().findItem(R.id.action_endorse).setVisible(false);
}
2019-09-06 17:55:14 +02:00
if (relationship.isBlocking()) {
2019-01-22 10:15:21 +01:00
popup.getMenu().findItem(R.id.action_block).setTitle(R.string.action_unblock);
}
2019-09-06 17:55:14 +02:00
if (relationship.isMuting()) {
2019-01-22 10:15:21 +01:00
popup.getMenu().findItem(R.id.action_mute).setTitle(R.string.action_unmute);
}
2019-09-06 17:55:14 +02:00
if (relationship.isEndorsed()) {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_endorse).setTitle(R.string.unendorse);
2019-09-06 17:55:14 +02:00
} else {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_endorse).setTitle(R.string.endorse);
}
2019-09-06 17:55:14 +02:00
if (relationship.isShowing_reblogs()) {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_hide_boost).setTitle(getString(R.string.hide_boost, account.getUsername()));
2019-09-06 17:55:14 +02:00
} else {
2018-12-22 11:43:28 +01:00
popup.getMenu().findItem(R.id.action_hide_boost).setTitle(getString(R.string.show_boost, account.getUsername()));
}
}
2020-03-07 08:52:47 +01:00
popup.setOnMenuItemClickListener(item -> {
AlertDialog.Builder builderInner;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
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;
}
2020-04-09 18:57:12 +02:00
final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
2021-01-19 17:43:51 +01:00
int itemId = item.getItemId();
if (itemId == R.id.action_follow_instance) {
String finalInstanceName = splitAcct[1];
List<RemoteInstance> remoteInstances = new InstancesDAO(ShowAccountActivity.this, db).getInstanceByName(finalInstanceName);
if (remoteInstances != null && remoteInstances.size() > 0) {
Toasty.info(ShowAccountActivity.this, getString(R.string.toast_instance_already_added), Toast.LENGTH_LONG).show();
Intent intent = new Intent(ShowAccountActivity.this, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(Helper.INTENT_ACTION, Helper.SEARCH_INSTANCE);
bundle.putString(Helper.INSTANCE_NAME, finalInstanceName);
intent.putExtras(bundle);
2020-03-07 08:52:47 +01:00
startActivity(intent);
return true;
2021-01-19 17:43:51 +01:00
}
new Thread(() -> {
try {
if (!peertubeAccount) {
//Here we can't know if the instance is a Mastodon one or not
try { //Testing Mastodon
new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/timelines/public?local=true", 10, null, null);
} catch (Exception ignored) {
new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/videos/", 10, null, null);
peertubeAccount = true;
2019-09-12 19:15:14 +02:00
}
2021-01-19 17:43:51 +01:00
} else
new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/videos/", 10, null, null);
runOnUiThread(() -> {
if (!peertubeAccount)
new InstancesDAO(ShowAccountActivity.this, db).insertInstance(finalInstanceName, "MASTODON");
else
new InstancesDAO(ShowAccountActivity.this, db).insertInstance(finalInstanceName, "PEERTUBE");
Toasty.success(ShowAccountActivity.this, getString(R.string.toast_instance_followed), Toast.LENGTH_LONG).show();
Intent intent = new Intent(ShowAccountActivity.this, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(Helper.INTENT_ACTION, Helper.SEARCH_INSTANCE);
bundle.putString(Helper.INSTANCE_NAME, finalInstanceName);
intent.putExtras(bundle);
startActivity(intent);
2019-09-12 19:15:14 +02:00
});
2021-01-19 17:43:51 +01:00
} catch (final Exception e) {
e.printStackTrace();
runOnUiThread(() -> Toasty.warning(ShowAccountActivity.this, getString(R.string.toast_instance_unavailable), Toast.LENGTH_LONG).show());
2020-03-07 08:52:47 +01:00
}
2021-01-19 17:43:51 +01:00
}).start();
return true;
} else if (itemId == R.id.action_filter) {
AlertDialog.Builder filterTagDialog = new AlertDialog.Builder(ShowAccountActivity.this, style);
Set<String> featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null);
List<String> tags = new ArrayList<>();
if (featuredTagsSet != null) {
tags = new ArrayList<>(featuredTagsSet);
}
tags.add(0, getString(R.string.no_tags));
String[] tagsString = tags.toArray(new String[0]);
List<String> finalTags = tags;
String tag = sharedpreferences.getString(Helper.SET_FEATURED_TAG_ACTION, null);
int checkedposition = 0;
int i = 0;
for (String _t : tags) {
if (_t.equals(tag))
checkedposition = i;
i++;
}
filterTagDialog.setSingleChoiceItems(tagsString, checkedposition, (dialog, item1) -> {
String tag1;
if (item1 == 0) {
tag1 = null;
} else {
tag1 = finalTags.get(item1);
2020-03-07 08:52:47 +01:00
}
2021-01-19 17:43:51 +01:00
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SET_FEATURED_TAG_ACTION, tag1);
editor.apply();
dialog.dismiss();
});
filterTagDialog.show();
return true;
} else if (itemId == R.id.action_endorse) {
if (relationship != null)
if (relationship.isEndorsed()) {
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.UNENDORSE, account.getId(), ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
} else {
2021-01-19 17:43:51 +01:00
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.ENDORSE, account.getId(), ShowAccountActivity.this);
2018-12-22 11:43:28 +01:00
}
2021-01-19 17:43:51 +01:00
return true;
} else if (itemId == R.id.action_hide_boost) {
if (relationship != null)
if (relationship.isShowing_reblogs()) {
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.HIDE_BOOST, account.getId(), ShowAccountActivity.this);
} else {
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.SHOW_BOOST, account.getId(), ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
}
2021-01-19 17:43:51 +01:00
return true;
} else if (itemId == R.id.action_direct_message) {
Intent intent = new Intent(ShowAccountActivity.this, TootActivity.class);
Bundle b = new Bundle();
b.putString("mentionAccount", account.getAcct());
b.putString("visibility", "direct");
intent.putExtras(b);
startActivity(intent);
return true;
} else if (itemId == R.id.action_add_to_list) {
if (timelines != null) {
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(ShowAccountActivity.this, android.R.layout.select_dialog_item);
boolean hasLists = false;
for (ManageTimelines timeline : timelines) {
if (timeline.getListTimeline() != null) {
arrayAdapter.add(timeline.getListTimeline().getTitle());
hasLists = true;
2020-03-07 08:52:47 +01:00
}
2021-01-19 17:43:51 +01:00
}
if (!hasLists) {
Toasty.info(ShowAccountActivity.this, getString(R.string.action_lists_empty), Toast.LENGTH_SHORT).show();
return true;
}
AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowAccountActivity.this, style);
builderSingle.setTitle(getString(R.string.action_lists_add_to));
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
String listTitle = arrayAdapter.getItem(which);
for (ManageTimelines timeline : timelines) {
if (timeline.getListTimeline() != null && timeline.getListTimeline().getTitle().equals(listTitle)) {
app.fedilab.android.client.Entities.List list = timeline.getListTimeline();
if (relationship == null || !relationship.isFollowing()) {
addToList = list.getId();
new PostActionAsyncTask(ShowAccountActivity.this, API.StatusAction.FOLLOW, account.getId(), ShowAccountActivity.this);
} else {
new ManageListsAsyncTask(ShowAccountActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{account.getId()}, list.getId(), null, ShowAccountActivity.this);
}
break;
}
2018-12-22 11:43:28 +01:00
}
2020-03-07 08:52:47 +01:00
});
2021-01-19 17:43:51 +01:00
builderSingle.show();
}
return true;
} else if (itemId == R.id.action_open_browser) {
if (accountUrl != null) {
if (!accountUrl.toLowerCase().startsWith("http://") && !accountUrl.toLowerCase().startsWith("https://"))
accountUrl = "http://" + accountUrl;
Helper.openBrowser(ShowAccountActivity.this, accountUrl);
}
return true;
} else if (itemId == R.id.action_mention) {
Intent intent;
Bundle b;
intent = new Intent(ShowAccountActivity.this, TootActivity.class);
b = new Bundle();
b.putString("mentionAccount", account.getAcct());
intent.putExtras(b);
startActivity(intent);
return true;
} else if (itemId == R.id.action_mute) {
if (relationship.isMuting()) {
2020-03-07 08:52:47 +01:00
builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
2021-01-19 17:43:51 +01:00
builderInner.setTitle(stringArrayConf[4]);
doActionAccount = API.StatusAction.UNMUTE;
} else {
builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
builderInner.setTitle(stringArrayConf[0]);
doActionAccount = API.StatusAction.MUTE;
}
} else if (itemId == R.id.action_report) {
builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
builderInner.setTitle(R.string.report_account);
//Text for report
EditText input = new EditText(ShowAccountActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
builderInner.setView(input);
doActionAccount = API.StatusAction.REPORT;
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
String comment = null;
if (input.getText() != null)
comment = input.getText().toString();
new PostActionAsyncTask(ShowAccountActivity.this, doActionAccount, account.getId(), null, comment, ShowAccountActivity.this);
dialog.dismiss();
});
builderInner.show();
return true;
} else if (itemId == R.id.action_add_notes) {
EditText input;
LinearLayout.LayoutParams lp;
UserNote userNote = new NotesDAO(ShowAccountActivity.this, db).getUserNote(account.getAcct());
builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
builderInner.setTitle(R.string.note_for_account);
input = new EditText(ShowAccountActivity.this);
lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
input.setSingleLine(false);
if (userNote != null) {
input.setText(userNote.getNote());
}
input.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
builderInner.setView(input);
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.validate, (dialog, which) -> {
UserNote userNote1 = new NotesDAO(ShowAccountActivity.this, db).getUserNote(account.getAcct());
if (userNote1 == null) {
userNote1 = new UserNote();
userNote1.setAcct(account.getAcct());
}
userNote1.setNote(input.getText().toString());
new NotesDAO(ShowAccountActivity.this, db).insertInstance(userNote1);
if (input.getText().toString().trim().length() > 0) {
account_personal_note.setVisibility(View.VISIBLE);
} else {
2021-01-19 17:43:51 +01:00
account_personal_note.setVisibility(View.GONE);
}
2021-01-19 17:43:51 +01:00
dialog.dismiss();
});
builderInner.show();
return true;
} else if (itemId == R.id.action_block) {
builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
if (relationship.isBlocking()) {
builderInner.setTitle(stringArrayConf[5]);
doActionAccount = API.StatusAction.UNBLOCK;
} else {
builderInner.setTitle(stringArrayConf[1]);
doActionAccount = API.StatusAction.BLOCK;
}
} else if (itemId == R.id.action_block_instance) {
builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style);
doActionAccount = API.StatusAction.BLOCK_DOMAIN;
String domain = account.getAcct().split("@")[1];
builderInner.setMessage(getString(R.string.block_domain_confirm_message, domain));
} else {
return true;
2018-12-22 11:43:28 +01:00
}
2020-03-07 08:52:47 +01:00
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
String targetedId;
if (item.getItemId() == R.id.action_block_instance) {
targetedId = account.getAcct().split("@")[1];
} else {
targetedId = account.getId();
}
2021-01-19 17:43:51 +01:00
new PostActionAsyncTask(ShowAccountActivity.this, doActionAccount, targetedId, ShowAccountActivity.this);
2020-03-07 08:52:47 +01:00
dialog.dismiss();
});
builderInner.show();
return true;
2018-12-22 11:43:28 +01:00
});
popup.show();
}
2019-08-16 16:56:59 +02:00
2019-08-18 12:56:24 +02:00
@Override
2019-09-06 17:55:14 +02:00
public void onDestroy() {
2019-08-18 12:56:24 +02:00
super.onDestroy();
}
2019-08-16 16:56:59 +02:00
@Override
2019-09-06 17:55:14 +02:00
public void onStop() {
2019-08-16 16:56:59 +02:00
super.onStop();
2019-09-06 17:55:14 +02:00
if (scheduledExecutorService != null) {
2019-08-16 16:56:59 +02:00
scheduledExecutorService.shutdownNow();
}
}
2018-12-22 11:43:28 +01:00
@Override
2019-09-06 17:55:14 +02:00
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
2019-09-06 17:55:14 +02:00
if (error != null) {
2019-11-15 16:32:25 +01:00
if (error.getError().length() < 100) {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
2019-11-15 16:32:25 +01:00
} else {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
2019-09-30 18:14:46 +02:00
}
2018-12-22 11:43:28 +01:00
return;
}
2019-09-06 17:55:14 +02:00
if (addToList != null) {
2021-01-19 17:43:51 +01:00
new ManageListsAsyncTask(ShowAccountActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{account.getId()}, addToList, null, ShowAccountActivity.this);
2019-09-06 17:55:14 +02:00
} else {
2020-04-08 12:42:15 +02:00
Helper.manageMessageStatusCode(ShowAccountActivity.this, statusCode, statusAction);
2019-08-19 17:36:09 +02:00
}
String target = account.getId();
2019-07-09 18:08:55 +02:00
//IF action is unfollow or mute, sends an intent to remove statuses
2019-09-06 17:55:14 +02:00
if (statusAction == API.StatusAction.UNFOLLOW || statusAction == API.StatusAction.MUTE) {
2019-07-09 18:08:55 +02:00
Bundle b = new Bundle();
b.putString("receive_action", targetedId);
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
intentBC.putExtras(b);
}
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
target = account.getAcct();
2021-01-19 17:43:51 +01:00
new RetrieveRelationshipAsyncTask(ShowAccountActivity.this, target, ShowAccountActivity.this);
2018-12-22 11:43:28 +01:00
}
@Override
public void onRetrieveAccount(final Account account, Error error) {
2019-09-06 17:55:14 +02:00
if (error != null || account == null || account.getAcct() == null) {
if (error == null)
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
2019-11-15 16:32:25 +01:00
else if (error.getError().length() < 100) {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show();
2019-11-15 16:32:25 +01:00
} else {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
2019-11-15 16:32:25 +01:00
}
2018-12-22 11:43:28 +01:00
return;
}
this.account = account;
ManageAccount();
}
2019-08-19 17:36:09 +02:00
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
if (apiResponse.getError() != null) {
2020-03-08 10:29:06 +01:00
if (!apiResponse.getError().getError().startsWith("404 -") && !apiResponse.getError().getError().startsWith("501 -"))
2020-04-08 12:42:15 +02:00
Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
2019-08-19 17:36:09 +02:00
return;
}
2019-09-06 17:55:14 +02:00
if (actionType == ManageListsAsyncTask.action.ADD_USERS) {
2020-04-08 12:42:15 +02:00
Toasty.success(ShowAccountActivity.this, getString(R.string.action_lists_add_user), Toast.LENGTH_LONG).show();
2019-08-19 17:36:09 +02:00
}
}
2020-04-08 12:42:15 +02:00
2019-12-17 19:26:03 +01:00
@Override
public void onIdentityProof(APIResponse apiResponse) {
2020-03-08 10:29:06 +01:00
if (apiResponse == null) {
2019-12-17 19:26:03 +01:00
return;
}
List<IdentityProof> identityProofs = apiResponse.getIdentityProofs();
2020-03-08 10:29:06 +01:00
if (identityProofs != null && identityProofs.size() > 0) {
2019-12-17 21:30:15 +01:00
ImageView identity_proofs_indicator = findViewById(R.id.identity_proofs_indicator);
identity_proofs_indicator.setVisibility(View.VISIBLE);
2019-12-18 08:31:46 +01:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
accountUrl = account.getUrl();
int style;
if (theme == Helper.THEME_LIGHT)
style = R.style.Dialog;
else if (theme == Helper.THEME_BLACK)
style = R.style.DialogBlack;
else
style = R.style.DialogDark;
identity_proofs_indicator.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(ShowAccountActivity.this, style);
2019-12-18 09:26:21 +01:00
LayoutInflater inflater = getLayoutInflater();
2020-03-08 10:29:06 +01:00
View identityProofsView = inflater.inflate(R.layout.popup_identity_proof, new LinearLayout(ShowAccountActivity.this), false);
RecyclerView identityProofsRecycler = identityProofsView.findViewById(R.id.identity_proofs_list);
2019-12-18 09:26:21 +01:00
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ShowAccountActivity.this);
identityProofsRecycler.setLayoutManager(mLayoutManager);
IdentityProofsAdapter identityProofsAdapter = new IdentityProofsAdapter(identityProofs);
identityProofsRecycler.setAdapter(identityProofsAdapter);
builder.setView(identityProofsView);
2019-12-18 08:31:46 +01:00
builder
.setTitle(R.string.identity_proofs)
2020-03-07 08:52:47 +01:00
.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss())
2019-12-18 08:31:46 +01:00
.show();
});
2019-12-17 19:26:03 +01:00
}
}
2019-11-15 16:32:25 +01:00
public enum action {
FOLLOW,
UNFOLLOW,
UNBLOCK,
NOTHING
}
/**
* Pager adapter for the 4 fragments
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) {
2020-03-08 10:29:06 +01:00
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
2019-11-15 16:32:25 +01:00
}
2020-03-07 08:52:47 +01:00
@NotNull
2019-11-15 16:32:25 +01:00
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position) {
case 0:
if (!peertubeAccount) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
TabLayoutTootsFragment tabLayoutTootsFragment = new TabLayoutTootsFragment();
bundle.putString("targetedid", account.getId());
tabLayoutTootsFragment.setArguments(bundle);
return tabLayoutTootsFragment;
} else {
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("instanceType", "PIXELFED");
bundle.putString("targetedid", account.getId());
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
}
} else {
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedid", account.getAcct());
bundle.putString("instanceType", "PEERTUBE");
bundle.putBoolean("showReply", false);
bundle.putBoolean("ischannel", ischannel);
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
}
case 1:
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
2019-11-15 16:32:25 +01:00
if (peertubeAccount) {
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.CHANNELS);
bundle.putString("targetedid", account.getId());
bundle.putString("instance", Helper.getLiveInstance(ShowAccountActivity.this));
bundle.putString("name", account.getAcct());
} else {
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWING);
bundle.putString("targetedid", account.getId());
}
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
2019-11-15 16:32:25 +01:00
2020-03-07 08:52:47 +01:00
default:
displayAccountsFragment = new DisplayAccountsFragment();
2019-11-15 16:32:25 +01:00
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWERS);
bundle.putString("targetedid", account.getId());
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
}
}
@Override
public int getCount() {
if (ischannel)
return 1;
else if (peertubeAccount)
return 2;
else
return 3;
}
}
2017-05-05 16:36:04 +02:00
}