2023-01-22 15:22:59 +01:00
|
|
|
package app.fedilab.android.mastodon.activities;
|
2022-04-27 15:20:42 +02:00
|
|
|
/* Copyright 2022 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Fedilab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
2022-06-21 17:09:34 +02:00
|
|
|
import static app.fedilab.android.BaseMainActivity.currentAccount;
|
|
|
|
|
2023-12-12 15:47:15 +01:00
|
|
|
import android.app.DownloadManager;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.ColorStateList;
|
2022-12-07 18:37:18 +01:00
|
|
|
import android.graphics.drawable.Animatable;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2023-12-12 15:47:15 +01:00
|
|
|
import android.os.Build;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
|
import android.text.style.UnderlineSpan;
|
2022-11-08 09:52:20 +01:00
|
|
|
import android.util.TypedValue;
|
2023-01-12 11:13:52 +01:00
|
|
|
import android.view.LayoutInflater;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2023-02-27 14:11:14 +01:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2022-11-30 18:15:32 +01:00
|
|
|
import androidx.core.app.ActivityCompat;
|
2022-04-27 15:20:42 +02:00
|
|
|
import androidx.core.app.ActivityOptionsCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
import com.bumptech.glide.request.target.CustomTarget;
|
|
|
|
import com.bumptech.glide.request.transition.Transition;
|
2023-01-17 14:36:51 +01:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2022-07-09 15:30:39 +02:00
|
|
|
import com.google.android.material.tabs.TabLayout;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-07-18 11:43:23 +02:00
|
|
|
import java.lang.ref.WeakReference;
|
2022-04-27 15:20:42 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import app.fedilab.android.BaseMainActivity;
|
|
|
|
import app.fedilab.android.R;
|
2023-01-22 15:22:59 +01:00
|
|
|
import app.fedilab.android.activities.MainActivity;
|
2022-04-27 15:20:42 +02:00
|
|
|
import app.fedilab.android.databinding.ActivityProfileBinding;
|
2023-01-12 11:13:52 +01:00
|
|
|
import app.fedilab.android.databinding.NotificationsRelatedAccountsBinding;
|
2023-08-26 17:53:55 +02:00
|
|
|
import app.fedilab.android.databinding.TabProfileCustomViewBinding;
|
2023-01-22 15:22:59 +01:00
|
|
|
import app.fedilab.android.mastodon.client.entities.api.Account;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.FamiliarFollowers;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.Field;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.IdentityProof;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.MastodonList;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.api.RelationShip;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.Languages;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.Pinned;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.RemoteInstance;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.Timeline;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.WellKnownNodeinfo;
|
|
|
|
import app.fedilab.android.mastodon.exception.DBException;
|
|
|
|
import app.fedilab.android.mastodon.helper.CrossActionHelper;
|
|
|
|
import app.fedilab.android.mastodon.helper.Helper;
|
|
|
|
import app.fedilab.android.mastodon.helper.MastodonHelper;
|
|
|
|
import app.fedilab.android.mastodon.helper.SpannableHelper;
|
|
|
|
import app.fedilab.android.mastodon.helper.ThemeHelper;
|
|
|
|
import app.fedilab.android.mastodon.ui.drawer.FieldAdapter;
|
|
|
|
import app.fedilab.android.mastodon.ui.drawer.IdentityProofsAdapter;
|
|
|
|
import app.fedilab.android.mastodon.ui.pageadapter.FedilabProfileTLPageAdapter;
|
|
|
|
import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM;
|
|
|
|
import app.fedilab.android.mastodon.viewmodel.mastodon.NodeInfoVM;
|
|
|
|
import app.fedilab.android.mastodon.viewmodel.mastodon.ReorderVM;
|
|
|
|
import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM;
|
2022-04-27 15:20:42 +02:00
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
|
|
|
|
|
|
|
public class ProfileActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
|
|
|
private RelationShip relationship;
|
2023-01-12 11:13:52 +01:00
|
|
|
private FamiliarFollowers familiarFollowers;
|
2022-04-27 15:20:42 +02:00
|
|
|
private Account account;
|
|
|
|
private ScheduledExecutorService scheduledExecutorService;
|
|
|
|
private action doAction;
|
|
|
|
private AccountsVM accountsVM;
|
|
|
|
private RecyclerView identityProofsRecycler;
|
|
|
|
private List<IdentityProof> identityProofList;
|
|
|
|
private ActivityProfileBinding binding;
|
|
|
|
private String account_id;
|
|
|
|
private String mention_str;
|
|
|
|
private WellKnownNodeinfo.NodeInfo nodeInfo;
|
2023-03-22 17:32:27 +01:00
|
|
|
|
|
|
|
|
2022-11-19 12:08:31 +01:00
|
|
|
private boolean checkRemotely;
|
2022-04-27 15:20:42 +02:00
|
|
|
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
Bundle b = intent.getExtras();
|
|
|
|
if (b != null) {
|
|
|
|
Account accountReceived = (Account) b.getSerializable(Helper.ARG_ACCOUNT);
|
|
|
|
if (b.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) {
|
2022-06-22 15:07:42 +02:00
|
|
|
if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) {
|
2022-04-27 15:20:42 +02:00
|
|
|
initializeView(accountReceived);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-01-01 11:55:32 +01:00
|
|
|
private boolean homeMuted;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2022-11-28 10:37:57 +01:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
binding = ActivityProfileBinding.inflate(getLayoutInflater());
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
setSupportActionBar(binding.toolbar);
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
Bundle b = getIntent().getExtras();
|
|
|
|
binding.accountFollow.setEnabled(false);
|
2022-11-19 17:17:23 +01:00
|
|
|
checkRemotely = false;
|
2023-01-01 18:20:18 +01:00
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2022-12-14 11:21:00 +01:00
|
|
|
homeMuted = false;
|
2022-04-27 15:20:42 +02:00
|
|
|
if (b != null) {
|
|
|
|
account = (Account) b.getSerializable(Helper.ARG_ACCOUNT);
|
|
|
|
account_id = b.getString(Helper.ARG_USER_ID, null);
|
|
|
|
mention_str = b.getString(Helper.ARG_MENTION, null);
|
2022-11-19 12:08:31 +01:00
|
|
|
checkRemotely = b.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2023-01-01 18:20:18 +01:00
|
|
|
if (!checkRemotely) {
|
|
|
|
checkRemotely = sharedpreferences.getBoolean(getString(R.string.SET_PROFILE_REMOTELY), false);
|
|
|
|
}
|
2022-11-30 18:15:32 +01:00
|
|
|
ActivityCompat.postponeEnterTransition(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
//Remove title
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setDisplayShowTitleEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getSupportActionBar() != null) {
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
|
|
|
}
|
2023-01-01 18:20:18 +01:00
|
|
|
|
2022-11-08 09:52:20 +01:00
|
|
|
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
|
|
|
|
binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
|
2022-04-27 15:20:42 +02:00
|
|
|
accountsVM = new ViewModelProvider(ProfileActivity.this).get(AccountsVM.class);
|
|
|
|
if (account != null) {
|
2022-07-18 11:43:23 +02:00
|
|
|
initializeView(account);
|
2022-04-27 15:20:42 +02:00
|
|
|
} else if (account_id != null) {
|
|
|
|
accountsVM.getAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account_id).observe(ProfileActivity.this, fetchedAccount -> {
|
|
|
|
account = fetchedAccount;
|
|
|
|
initializeView(account);
|
|
|
|
});
|
|
|
|
} else if (mention_str != null) {
|
|
|
|
accountsVM.searchAccounts(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, mention_str, 1, true, false).observe(ProfileActivity.this, accounts -> {
|
|
|
|
if (accounts != null && accounts.size() > 0) {
|
|
|
|
account = accounts.get(0);
|
|
|
|
initializeView(account);
|
|
|
|
} else {
|
2022-11-14 09:08:02 +01:00
|
|
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
2022-04-27 15:20:42 +02:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2022-11-14 09:08:02 +01:00
|
|
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
2022-04-27 15:20:42 +02:00
|
|
|
finish();
|
|
|
|
}
|
2022-12-14 11:21:00 +01:00
|
|
|
//Check if account is homeMuted
|
2022-12-14 14:29:20 +01:00
|
|
|
accountsVM.isMuted(currentAccount, account).observe(this, result -> homeMuted = result != null && result);
|
2023-12-12 16:07:48 +01:00
|
|
|
ContextCompat.registerReceiver(ProfileActivity.this, broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), ContextCompat.RECEIVER_NOT_EXPORTED);
|
2023-12-12 15:47:15 +01:00
|
|
|
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
|
2022-12-11 11:36:39 +01:00
|
|
|
|
|
|
|
private void updateViewWithNewData(Account account) {
|
|
|
|
if (account != null) {
|
|
|
|
if (account.role != null && account.role.highlighted) {
|
|
|
|
binding.accountRole.setText(account.role.name);
|
|
|
|
binding.accountRole.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2022-12-11 11:53:40 +01:00
|
|
|
if (binding.accountTabLayout.getTabCount() > 2) {
|
|
|
|
TabLayout.Tab statusTab = binding.accountTabLayout.getTabAt(0);
|
|
|
|
TabLayout.Tab followingTab = binding.accountTabLayout.getTabAt(1);
|
|
|
|
TabLayout.Tab followerTab = binding.accountTabLayout.getTabAt(2);
|
|
|
|
if (statusTab != null) {
|
|
|
|
statusTab.setText(getString(R.string.status_cnt, Helper.withSuffix(account.statuses_count)));
|
|
|
|
}
|
|
|
|
if (followingTab != null) {
|
|
|
|
followingTab.setText(getString(R.string.following_cnt, Helper.withSuffix(account.following_count)));
|
|
|
|
}
|
|
|
|
if (followerTab != null) {
|
|
|
|
followerTab.setText(getString(R.string.followers_cnt, Helper.withSuffix(account.followers_count)));
|
|
|
|
}
|
|
|
|
}
|
2023-03-22 17:32:27 +01:00
|
|
|
|
2022-12-11 11:36:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
private void initializeView(Account account) {
|
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
|
|
|
|
if (account == null) {
|
2022-11-14 09:08:02 +01:00
|
|
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
2022-04-27 15:20:42 +02:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
binding.title.setText(String.format(Locale.getDefault(), "@%s", account.acct));
|
|
|
|
binding.headerEditProfile.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(ProfileActivity.this, EditProfileActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
|
|
|
// MastodonHelper.loadPPMastodon(binding.profilePicture, account);
|
|
|
|
binding.appBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
|
|
|
|
|
|
|
|
if (Math.abs(verticalOffset) - binding.appBar.getTotalScrollRange() == 0) {
|
|
|
|
binding.profilePicture.setVisibility(View.VISIBLE);
|
|
|
|
binding.title.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
binding.profilePicture.setVisibility(View.GONE);
|
|
|
|
binding.title.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//Retrieve relationship with the connected account
|
|
|
|
List<String> accountListToCheck = new ArrayList<>();
|
|
|
|
accountListToCheck.add(account.id);
|
|
|
|
//Retrieve relation ship
|
|
|
|
accountsVM.getRelationships(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountListToCheck).observe(ProfileActivity.this, relationShips -> {
|
|
|
|
if (relationShips != null && relationShips.size() > 0) {
|
|
|
|
this.relationship = relationShips.get(0);
|
|
|
|
updateAccount();
|
|
|
|
}
|
|
|
|
});
|
2023-01-12 11:13:52 +01:00
|
|
|
accountsVM.getFamiliarFollowers(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountListToCheck).observe(ProfileActivity.this, familiarFollowersList -> {
|
|
|
|
if (familiarFollowersList != null && familiarFollowersList.size() > 0) {
|
|
|
|
this.familiarFollowers = familiarFollowersList.get(0);
|
|
|
|
updateAccount();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
//Retrieve identity proofs
|
|
|
|
accountsVM.getIdentityProofs(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id).observe(ProfileActivity.this, identityProofs -> {
|
|
|
|
this.identityProofList = identityProofs;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
//Animate emojis
|
|
|
|
if (account.emojis != null && account.emojis.size() > 0) {
|
|
|
|
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
|
|
|
|
if (!disableAnimatedEmoji) {
|
|
|
|
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
scheduledExecutorService.scheduleAtFixedRate(() -> binding.accountDn.invalidate(), 0, 130, TimeUnit.MILLISECONDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binding.accountTabLayout.clearOnTabSelectedListeners();
|
|
|
|
binding.accountTabLayout.removeAllTabs();
|
|
|
|
//Tablayout for timelines/following/followers
|
2022-11-19 16:44:23 +01:00
|
|
|
FedilabProfileTLPageAdapter fedilabProfileTLPageAdapter = new FedilabProfileTLPageAdapter(getSupportFragmentManager(), account, checkRemotely);
|
2023-08-26 17:53:55 +02:00
|
|
|
TabProfileCustomViewBinding tabMessagesView = TabProfileCustomViewBinding.inflate(getLayoutInflater());
|
|
|
|
TabProfileCustomViewBinding tabFollowingView = TabProfileCustomViewBinding.inflate(getLayoutInflater());
|
|
|
|
TabProfileCustomViewBinding tabFollowersView = TabProfileCustomViewBinding.inflate(getLayoutInflater());
|
|
|
|
|
|
|
|
tabMessagesView.title.setText(getString(R.string.toots));
|
|
|
|
tabMessagesView.count.setText(Helper.withSuffix(account.statuses_count));
|
|
|
|
tabFollowingView.title.setText(getString(R.string.following));
|
|
|
|
tabFollowingView.count.setText(Helper.withSuffix(account.following_count));
|
|
|
|
tabFollowersView.title.setText(getString(R.string.followers));
|
|
|
|
tabFollowersView.count.setText(Helper.withSuffix(account.followers_count));
|
|
|
|
|
|
|
|
TabLayout.Tab tabMessages = binding.accountTabLayout.newTab();
|
|
|
|
TabLayout.Tab tabFollowing = binding.accountTabLayout.newTab();
|
|
|
|
TabLayout.Tab tabFollowers = binding.accountTabLayout.newTab();
|
|
|
|
tabMessages.setCustomView(tabMessagesView.getRoot());
|
|
|
|
tabFollowing.setCustomView(tabFollowingView.getRoot());
|
|
|
|
tabFollowers.setCustomView(tabFollowersView.getRoot());
|
|
|
|
|
|
|
|
binding.accountTabLayout.addTab(tabMessages);
|
|
|
|
binding.accountTabLayout.addTab(tabFollowing);
|
|
|
|
binding.accountTabLayout.addTab(tabFollowers);
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountViewpager.setAdapter(fedilabProfileTLPageAdapter);
|
|
|
|
binding.accountViewpager.setOffscreenPageLimit(3);
|
2022-07-09 15:30:39 +02:00
|
|
|
binding.accountViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.accountTabLayout));
|
2023-02-27 14:11:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
|
|
|
|
|
|
|
|
binding.accountTabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
@Override
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
binding.accountTabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
|
|
|
ViewGroup.LayoutParams params = binding.accountTabLayout.getLayoutParams();
|
|
|
|
params.height = (int) (binding.accountTabLayout.getHeight() * scale);
|
|
|
|
binding.accountTabLayout.setLayoutParams(params);
|
|
|
|
}
|
|
|
|
});
|
2022-07-09 15:30:39 +02:00
|
|
|
binding.accountTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
|
binding.accountViewpager.setCurrentItem(tab.getPosition());
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-07-09 15:30:39 +02:00
|
|
|
@Override
|
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(TabLayout.Tab tab) {
|
|
|
|
}
|
|
|
|
});
|
2022-04-27 15:20:42 +02:00
|
|
|
boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false);
|
|
|
|
String targetedUrl = disableGif ? account.avatar_static : account.avatar;
|
2022-12-07 18:37:18 +01:00
|
|
|
// MastodonHelper.loadPPMastodon(binding.accountPp, account);
|
2022-04-27 15:20:42 +02:00
|
|
|
Glide.with(ProfileActivity.this)
|
|
|
|
.asDrawable()
|
|
|
|
.dontTransform()
|
|
|
|
.load(targetedUrl).into(
|
2022-09-26 17:08:00 +02:00
|
|
|
new CustomTarget<Drawable>() {
|
|
|
|
@Override
|
|
|
|
public void onResourceReady(@NonNull final Drawable resource, Transition<? super Drawable> transition) {
|
|
|
|
binding.profilePicture.setImageDrawable(resource);
|
2022-12-02 16:14:57 +01:00
|
|
|
binding.accountPp.setImageDrawable(resource);
|
2022-12-07 18:37:18 +01:00
|
|
|
if (resource instanceof Animatable) {
|
|
|
|
binding.profilePicture.animate();
|
|
|
|
binding.accountPp.animate();
|
|
|
|
((Animatable) resource).start();
|
|
|
|
}
|
2022-11-30 18:15:32 +01:00
|
|
|
ActivityCompat.startPostponedEnterTransition(ProfileActivity.this);
|
2022-09-26 17:08:00 +02:00
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-09-26 17:08:00 +02:00
|
|
|
@Override
|
|
|
|
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
|
|
|
binding.profilePicture.setImageResource(R.drawable.ic_person);
|
2022-12-02 16:14:57 +01:00
|
|
|
binding.accountPp.setImageResource(R.drawable.ic_person);
|
2022-11-30 18:15:32 +01:00
|
|
|
ActivityCompat.startPostponedEnterTransition(ProfileActivity.this);
|
2022-09-26 17:08:00 +02:00
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-09-26 17:08:00 +02:00
|
|
|
@Override
|
|
|
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
2022-11-30 18:15:32 +01:00
|
|
|
binding.profilePicture.setImageResource(R.drawable.ic_person);
|
2022-12-02 16:14:57 +01:00
|
|
|
binding.accountPp.setImageResource(R.drawable.ic_person);
|
2022-11-30 18:15:32 +01:00
|
|
|
ActivityCompat.startPostponedEnterTransition(ProfileActivity.this);
|
2022-09-26 17:08:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2022-04-27 15:20:42 +02:00
|
|
|
//Load header
|
2022-11-26 11:20:15 +01:00
|
|
|
MastodonHelper.loadProfileMediaMastodon(ProfileActivity.this, binding.bannerPp, account, MastodonHelper.MediaAccountType.HEADER);
|
2022-04-27 15:20:42 +02:00
|
|
|
//Redraws icon for locked accounts
|
|
|
|
if (account.locked) {
|
|
|
|
Drawable img = ContextCompat.getDrawable(ProfileActivity.this, R.drawable.ic_baseline_lock_24);
|
|
|
|
assert img != null;
|
2023-03-15 18:56:55 +01:00
|
|
|
img.setBounds(0, 0, (int) (Helper.convertDpToPixel(14, this) * scale + 0.5f), (int) (Helper.convertDpToPixel(14, this) * scale + 0.5f));
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountUn.setCompoundDrawables(null, null, img, null);
|
|
|
|
} else {
|
|
|
|
binding.accountUn.setCompoundDrawables(null, null, null, null);
|
|
|
|
}
|
|
|
|
//Peertube account watched by a Mastodon account
|
|
|
|
//Bot account
|
|
|
|
if (account.bot) {
|
|
|
|
binding.accountBot.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (account.acct != null) {
|
|
|
|
setTitle(account.acct);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final SpannableString content = new SpannableString(getString(R.string.disclaimer_full));
|
|
|
|
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
|
2022-11-30 15:06:34 +01:00
|
|
|
content.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, content.length(),
|
2022-04-27 15:20:42 +02:00
|
|
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
binding.warningMessage.setText(content);
|
|
|
|
binding.warningMessage.setOnClickListener(view -> {
|
|
|
|
if (!account.url.toLowerCase().startsWith("http://") && !account.url.toLowerCase().startsWith("https://"))
|
|
|
|
account.url = "http://" + account.url;
|
|
|
|
Helper.openBrowser(ProfileActivity.this, account.url);
|
|
|
|
});
|
|
|
|
//Timed muted account
|
|
|
|
if (account.mute_expires_at != null && account.mute_expires_at.after(new Date())) {
|
|
|
|
binding.tempMute.setVisibility(View.VISIBLE);
|
|
|
|
SpannableString content_temp_mute = new SpannableString(getString(R.string.timed_mute_profile, account.acct, account.mute_expires_at));
|
|
|
|
content_temp_mute.setSpan(new UnderlineSpan(), 0, content_temp_mute.length(), 0);
|
|
|
|
binding.tempMute.setText(content_temp_mute);
|
|
|
|
}
|
|
|
|
//This account was moved to another one
|
|
|
|
if (account.moved != null) {
|
|
|
|
binding.accountMoved.setVisibility(View.VISIBLE);
|
|
|
|
Drawable imgTravel = ContextCompat.getDrawable(ProfileActivity.this, R.drawable.ic_baseline_card_travel_24);
|
|
|
|
assert imgTravel != null;
|
2023-03-15 18:56:55 +01:00
|
|
|
imgTravel.setBounds(0, 0, (int) (Helper.convertDpToPixel(20, this) * scale + 0.5f), (int) (Helper.convertDpToPixel(20, this) * scale + 0.5f));
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountMoved.setCompoundDrawables(imgTravel, null, null, null);
|
|
|
|
//Retrieves content and make account names clickable
|
|
|
|
SpannableString spannableString = SpannableHelper.moveToText(ProfileActivity.this, account);
|
|
|
|
binding.accountMoved.setText(spannableString, TextView.BufferType.SPANNABLE);
|
|
|
|
binding.accountMoved.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
2022-06-29 18:54:08 +02:00
|
|
|
if (account.acct != null && account.acct.contains("@"))
|
2022-11-19 17:17:23 +01:00
|
|
|
binding.warningContainer.setVisibility(View.VISIBLE);
|
2022-04-27 15:20:42 +02:00
|
|
|
else
|
2022-11-19 17:17:23 +01:00
|
|
|
binding.warningContainer.setVisibility(View.GONE);
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-11-19 17:17:23 +01:00
|
|
|
if (checkRemotely) {
|
|
|
|
binding.openRemoteProfile.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
binding.openRemoteProfile.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(ProfileActivity.this, ProfileActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putSerializable(Helper.ARG_ACCOUNT, account);
|
|
|
|
b.putSerializable(Helper.ARG_CHECK_REMOTELY, true);
|
|
|
|
intent.putExtras(b);
|
|
|
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
|
|
|
.makeSceneTransitionAnimation(ProfileActivity.this, binding.profilePicture, getString(R.string.activity_porfile_pp));
|
|
|
|
startActivity(intent, options.toBundle());
|
|
|
|
finish();
|
|
|
|
});
|
2022-04-27 15:20:42 +02:00
|
|
|
//Fields for profile
|
|
|
|
List<Field> fields = account.fields;
|
|
|
|
if (fields != null && fields.size() > 0) {
|
2022-11-25 17:30:04 +01:00
|
|
|
FieldAdapter fieldAdapter = new FieldAdapter(fields, account);
|
2022-07-08 10:20:40 +02:00
|
|
|
binding.fieldsContainer.setAdapter(fieldAdapter);
|
|
|
|
binding.fieldsContainer.setLayoutManager(new LinearLayoutManager(ProfileActivity.this));
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2022-07-18 11:43:23 +02:00
|
|
|
|
|
|
|
binding.accountDn.setText(
|
2023-09-09 16:10:33 +02:00
|
|
|
account.getSpanDisplayNameEmoji(ProfileActivity.this,
|
2022-07-18 14:13:12 +02:00
|
|
|
new WeakReference<>(binding.accountDn)),
|
2022-07-18 11:43:23 +02:00
|
|
|
TextView.BufferType.SPANNABLE);
|
2022-06-15 16:47:39 +02:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountUn.setText(String.format("@%s", account.acct));
|
|
|
|
binding.accountUn.setOnLongClickListener(v -> {
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
|
|
|
String account_id = account.acct;
|
|
|
|
if (account_id.split("@").length == 1)
|
|
|
|
account_id += "@" + BaseMainActivity.currentInstance;
|
|
|
|
ClipData clip = ClipData.newPlainText("mastodon_account_id", "@" + account_id);
|
|
|
|
Toasty.info(ProfileActivity.this, getString(R.string.account_id_clipbloard), Toast.LENGTH_SHORT).show();
|
|
|
|
assert clipboard != null;
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
return false;
|
|
|
|
});
|
2022-07-18 11:43:23 +02:00
|
|
|
binding.accountNote.setText(
|
|
|
|
account.getSpanNote(ProfileActivity.this,
|
2022-07-18 14:13:12 +02:00
|
|
|
new WeakReference<>(binding.accountNote)),
|
2022-07-18 11:43:23 +02:00
|
|
|
TextView.BufferType.SPANNABLE);
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountNote.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
2022-12-07 18:37:18 +01:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountPp.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(ProfileActivity.this, MediaActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
Attachment attachment = new Attachment();
|
|
|
|
attachment.description = account.acct;
|
|
|
|
attachment.preview_url = account.avatar;
|
|
|
|
attachment.url = account.avatar;
|
|
|
|
attachment.remote_url = account.avatar;
|
|
|
|
attachment.type = "image";
|
|
|
|
ArrayList<Attachment> attachments = new ArrayList<>();
|
|
|
|
attachments.add(attachment);
|
|
|
|
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
|
|
|
|
b.putInt(Helper.ARG_MEDIA_POSITION, 1);
|
|
|
|
intent.putExtras(b);
|
|
|
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
|
|
|
.makeSceneTransitionAnimation(ProfileActivity.this, binding.accountPp, attachment.url);
|
|
|
|
// start the new activity
|
|
|
|
startActivity(intent, options.toBundle());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
binding.accountFollow.setOnClickListener(v -> {
|
|
|
|
if (doAction == action.NOTHING) {
|
|
|
|
Toasty.info(ProfileActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
|
|
|
|
} else if (doAction == action.FOLLOW) {
|
|
|
|
binding.accountFollow.setEnabled(false);
|
2023-01-17 16:41:39 +01:00
|
|
|
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
|
2022-04-27 15:20:42 +02:00
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
} else if (doAction == action.UNFOLLOW) {
|
|
|
|
boolean confirm_unfollow = sharedpreferences.getBoolean(getString(R.string.SET_UNFOLLOW_VALIDATION), true);
|
|
|
|
if (confirm_unfollow) {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder unfollowConfirm = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
unfollowConfirm.setTitle(getString(R.string.unfollow_confirm));
|
|
|
|
unfollowConfirm.setMessage(account.acct);
|
|
|
|
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
binding.accountFollow.setEnabled(false);
|
|
|
|
accountsVM.unfollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
unfollowConfirm.show();
|
|
|
|
} else {
|
|
|
|
binding.accountFollow.setEnabled(false);
|
|
|
|
binding.accountFollow.setEnabled(false);
|
|
|
|
accountsVM.unfollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (doAction == action.UNBLOCK) {
|
|
|
|
binding.accountFollow.setEnabled(false);
|
|
|
|
accountsVM.unblock(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-07-25 17:00:21 +02:00
|
|
|
binding.accountFollow.setOnLongClickListener(v -> {
|
2022-04-27 15:20:42 +02:00
|
|
|
CrossActionHelper.doCrossAction(ProfileActivity.this, CrossActionHelper.TypeOfCrossAction.FOLLOW_ACTION, account, null);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
binding.accountDate.setText(Helper.shortDateToString(account.created_at));
|
|
|
|
binding.accountDate.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
String[] accountInstanceArray = account.acct.split("@");
|
|
|
|
String accountInstance = BaseMainActivity.currentInstance;
|
|
|
|
if (accountInstanceArray.length > 1) {
|
|
|
|
accountInstance = accountInstanceArray[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeInfoVM nodeInfoVM = new ViewModelProvider(ProfileActivity.this).get(NodeInfoVM.class);
|
|
|
|
String finalAccountInstance = accountInstance;
|
|
|
|
nodeInfoVM.getNodeInfo(accountInstance).observe(ProfileActivity.this, nodeInfo -> {
|
|
|
|
this.nodeInfo = nodeInfo;
|
|
|
|
if (nodeInfo != null && nodeInfo.software != null) {
|
|
|
|
binding.instanceInfo.setText(nodeInfo.software.name);
|
|
|
|
binding.instanceInfo.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
binding.instanceInfo.setOnClickListener(v -> {
|
2023-01-18 15:37:03 +01:00
|
|
|
InstanceProfileActivity instanceProfileActivity = new InstanceProfileActivity();
|
2022-04-27 15:20:42 +02:00
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putString(Helper.ARG_INSTANCE, finalAccountInstance);
|
2023-01-18 15:37:03 +01:00
|
|
|
instanceProfileActivity.setArguments(b);
|
|
|
|
instanceProfileActivity.show(getSupportFragmentManager(), null);
|
2022-04-27 15:20:42 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-12-11 11:53:40 +01:00
|
|
|
if (accountInstance != null && !accountInstance.equalsIgnoreCase(MainActivity.currentInstance)) {
|
2022-12-11 11:36:39 +01:00
|
|
|
accountsVM.lookUpAccount(accountInstance, account.username).observe(ProfileActivity.this, this::updateViewWithNewData);
|
2022-12-11 11:53:40 +01:00
|
|
|
} else if (accountInstance != null && accountInstance.equalsIgnoreCase(MainActivity.currentInstance)) {
|
|
|
|
updateViewWithNewData(account);
|
2022-12-11 11:36:39 +01:00
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This methode is called to update the view once an action has been performed
|
|
|
|
*/
|
|
|
|
private void updateAccount() {
|
2022-07-30 18:47:30 +02:00
|
|
|
if (currentAccount == null || account == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-14 15:15:29 +01:00
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
//Manage indentity proofs if not yet displayed
|
|
|
|
|
|
|
|
if (identityProofList != null && identityProofList.size() > 0) {
|
|
|
|
ImageView identity_proofs_indicator = findViewById(R.id.identity_proofs_indicator);
|
|
|
|
identity_proofs_indicator.setVisibility(View.VISIBLE);
|
|
|
|
//Recyclerview for identity proof has not been inflated yet
|
|
|
|
if (identityProofsRecycler == null) {
|
|
|
|
identity_proofs_indicator.setOnClickListener(v -> {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
identityProofsRecycler = new RecyclerView(ProfileActivity.this);
|
|
|
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ProfileActivity.this);
|
|
|
|
identityProofsRecycler.setLayoutManager(mLayoutManager);
|
|
|
|
IdentityProofsAdapter identityProofsAdapter = new IdentityProofsAdapter(identityProofList);
|
|
|
|
identityProofsRecycler.setAdapter(identityProofsAdapter);
|
|
|
|
builder.setView(identityProofsRecycler);
|
|
|
|
builder
|
|
|
|
.setTitle(R.string.identity_proofs)
|
|
|
|
.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss())
|
|
|
|
.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 15:15:29 +01:00
|
|
|
|
2023-01-12 11:13:52 +01:00
|
|
|
if (familiarFollowers != null && familiarFollowers.accounts != null && familiarFollowers.accounts.size() > 0) {
|
|
|
|
binding.relatedAccounts.removeAllViews();
|
|
|
|
for (Account account : familiarFollowers.accounts) {
|
|
|
|
NotificationsRelatedAccountsBinding notificationsRelatedAccountsBinding = NotificationsRelatedAccountsBinding.inflate(LayoutInflater.from(ProfileActivity.this));
|
|
|
|
MastodonHelper.loadProfileMediaMastodonRound(ProfileActivity.this, notificationsRelatedAccountsBinding.profilePicture, account);
|
|
|
|
notificationsRelatedAccountsBinding.acc.setText(account.username);
|
|
|
|
notificationsRelatedAccountsBinding.relatedAccountContainer.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(ProfileActivity.this, ProfileActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putSerializable(Helper.ARG_ACCOUNT, account);
|
|
|
|
intent.putExtras(b);
|
|
|
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
|
|
|
.makeSceneTransitionAnimation(ProfileActivity.this, notificationsRelatedAccountsBinding.profilePicture, getString(R.string.activity_porfile_pp));
|
|
|
|
// start the new activity
|
|
|
|
startActivity(intent, options.toBundle());
|
|
|
|
});
|
|
|
|
binding.relatedAccounts.addView(notificationsRelatedAccountsBinding.getRoot());
|
|
|
|
}
|
|
|
|
binding.familiarFollowers.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountFollow.setEnabled(true);
|
|
|
|
//Visibility depending of the relationship
|
|
|
|
if (relationship != null) {
|
|
|
|
if (relationship.blocked_by) {
|
2022-11-28 11:46:48 +01:00
|
|
|
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_add_24);
|
2022-04-27 15:20:42 +02:00
|
|
|
binding.accountFollow.setVisibility(View.VISIBLE);
|
|
|
|
binding.accountFollow.setEnabled(false);
|
|
|
|
binding.accountFollow.setContentDescription(getString(R.string.action_disabled));
|
|
|
|
}
|
|
|
|
|
2023-03-09 15:35:12 +01:00
|
|
|
|
2022-05-20 15:46:38 +02:00
|
|
|
if (relationship.followed_by) {
|
|
|
|
binding.accountFollowedBy.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
binding.accountFollowedBy.setVisibility(View.GONE);
|
|
|
|
}
|
2023-03-09 15:35:12 +01:00
|
|
|
if (relationship.requested_by) {
|
|
|
|
binding.accountRequestedBy.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
binding.accountRequestedBy.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
binding.accountFollowRequest.setVisibility(View.GONE);
|
2022-04-27 15:20:42 +02:00
|
|
|
if (relationship.following) {
|
2022-11-28 11:46:48 +01:00
|
|
|
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_remove_24);
|
2022-11-29 10:23:19 +01:00
|
|
|
binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(this, R.attr.colorError)));
|
2022-04-27 15:20:42 +02:00
|
|
|
doAction = action.UNFOLLOW;
|
|
|
|
binding.accountFollow.setContentDescription(getString(R.string.action_unfollow));
|
|
|
|
binding.accountFollow.setVisibility(View.VISIBLE);
|
|
|
|
} else if (relationship.blocking) {
|
2022-11-29 10:23:19 +01:00
|
|
|
binding.accountFollow.setBackgroundTintList(ColorStateList.valueOf(ThemeHelper.getAttColor(this, R.attr.colorError)));
|
2022-11-28 11:46:48 +01:00
|
|
|
binding.accountFollow.setIconResource(R.drawable.ic_baseline_lock_open_24);
|
2022-04-27 15:20:42 +02:00
|
|
|
doAction = action.UNBLOCK;
|
|
|
|
binding.accountFollow.setVisibility(View.VISIBLE);
|
|
|
|
binding.accountFollow.setContentDescription(getString(R.string.action_unblock));
|
2023-03-09 15:35:12 +01:00
|
|
|
} else if (relationship.requested) {
|
|
|
|
binding.accountFollowRequest.setVisibility(View.VISIBLE);
|
|
|
|
binding.accountFollow.setIconResource(R.drawable.ic_baseline_hourglass_full_24);
|
|
|
|
binding.accountFollow.setVisibility(View.VISIBLE);
|
|
|
|
binding.accountFollow.setContentDescription(getString(R.string.follow_request));
|
|
|
|
doAction = action.UNFOLLOW;
|
2022-04-27 15:20:42 +02:00
|
|
|
} else {
|
2022-11-28 11:46:48 +01:00
|
|
|
binding.accountFollow.setIconResource(R.drawable.ic_baseline_person_add_24);
|
2022-04-27 15:20:42 +02:00
|
|
|
doAction = action.FOLLOW;
|
|
|
|
binding.accountFollow.setVisibility(View.VISIBLE);
|
|
|
|
binding.accountFollow.setContentDescription(getString(R.string.action_follow));
|
|
|
|
}
|
2023-03-09 15:35:12 +01:00
|
|
|
|
|
|
|
|
2022-11-14 15:15:29 +01:00
|
|
|
//The value for account is from same server so id can be used
|
|
|
|
|
|
|
|
if (account.id.equals(currentAccount.user_id)) {
|
|
|
|
binding.accountFollow.setVisibility(View.GONE);
|
|
|
|
binding.headerEditProfile.setVisibility(View.VISIBLE);
|
|
|
|
binding.headerEditProfile.bringToFront();
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
if (!relationship.following) {
|
|
|
|
binding.accountNotification.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
binding.accountNotification.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (relationship.notifying) {
|
2022-11-28 11:46:48 +01:00
|
|
|
binding.accountNotification.setIconResource(R.drawable.ic_baseline_notifications_active_24);
|
2022-04-27 15:20:42 +02:00
|
|
|
} else {
|
2022-11-28 11:46:48 +01:00
|
|
|
binding.accountNotification.setIconResource(R.drawable.ic_baseline_notifications_off_24);
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2022-07-25 16:54:54 +02:00
|
|
|
binding.accountNotification.setOnClickListener(v -> {
|
|
|
|
if (relationship != null && relationship.following) {
|
|
|
|
relationship.notifying = !relationship.notifying;
|
2023-01-17 16:41:39 +01:00
|
|
|
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, relationship.showing_reblogs, relationship.notifying, relationship.languages)
|
2022-07-25 16:54:54 +02:00
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-04-27 15:20:42 +02:00
|
|
|
//Account note
|
|
|
|
if (relationship.note == null || relationship.note.trim().isEmpty()) {
|
|
|
|
binding.personalNote.setText(R.string.note_for_account);
|
|
|
|
} else {
|
|
|
|
binding.personalNote.setText(relationship.note);
|
|
|
|
}
|
|
|
|
binding.personalNote.setOnClickListener(view -> {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
builderInner.setTitle(R.string.note_for_account);
|
|
|
|
EditText input = new EditText(ProfileActivity.this);
|
|
|
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
input.setLayoutParams(lp);
|
|
|
|
input.setSingleLine(false);
|
|
|
|
input.setText(relationship.note);
|
|
|
|
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) -> {
|
|
|
|
String notes = input.getText().toString().trim();
|
2022-06-17 11:07:31 +02:00
|
|
|
binding.personalNote.setText(notes);
|
|
|
|
if (relationship != null) {
|
|
|
|
relationship.note = notes;
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
accountsVM.updateNote(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, notes);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.activity_profile, menu);
|
|
|
|
if (account != null) {
|
2022-05-25 14:41:27 +02:00
|
|
|
final boolean isOwner = account.id != null && BaseMainActivity.currentUserID != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0;
|
2022-04-27 15:20:42 +02:00
|
|
|
String[] splitAcct = account.acct.split("@");
|
|
|
|
//check if user is from the same instance
|
|
|
|
if (splitAcct.length <= 1) { //If yes, these entries must be hidden
|
|
|
|
menu.findItem(R.id.action_follow_instance).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_block_instance).setVisible(false);
|
|
|
|
}
|
|
|
|
if (isOwner) {
|
|
|
|
menu.findItem(R.id.action_block).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_report).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_mute).setVisible(false);
|
2022-11-20 15:55:30 +01:00
|
|
|
menu.findItem(R.id.action_timed_mute).setVisible(false);
|
2022-04-27 15:20:42 +02:00
|
|
|
menu.findItem(R.id.action_mention).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_follow_instance).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_block_instance).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_hide_boost).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_endorse).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_direct_message).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_add_to_list).setVisible(false);
|
2022-12-14 11:21:00 +01:00
|
|
|
menu.findItem(R.id.action_mute_home).setVisible(false);
|
2023-01-17 16:41:39 +01:00
|
|
|
menu.findItem(R.id.action_subscribed_language).setVisible(false);
|
2022-04-27 15:20:42 +02:00
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.action_block).setVisible(true);
|
|
|
|
menu.findItem(R.id.action_mute).setVisible(true);
|
2022-12-14 11:21:00 +01:00
|
|
|
menu.findItem(R.id.action_mute_home).setVisible(true);
|
2022-11-20 15:55:30 +01:00
|
|
|
menu.findItem(R.id.action_timed_mute).setVisible(true);
|
2022-04-27 15:20:42 +02:00
|
|
|
menu.findItem(R.id.action_mention).setVisible(true);
|
|
|
|
}
|
|
|
|
//Update menu title depending of relationship
|
|
|
|
if (relationship != null) {
|
|
|
|
if (!relationship.following) {
|
|
|
|
menu.findItem(R.id.action_hide_boost).setVisible(false);
|
|
|
|
menu.findItem(R.id.action_endorse).setVisible(false);
|
2022-12-14 11:21:00 +01:00
|
|
|
menu.findItem(R.id.action_mute_home).setVisible(false);
|
2023-01-17 16:41:39 +01:00
|
|
|
menu.findItem(R.id.action_subscribed_language).setVisible(false);
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
if (relationship.blocking) {
|
|
|
|
menu.findItem(R.id.action_block).setTitle(R.string.action_unblock);
|
|
|
|
}
|
|
|
|
if (relationship.muting) {
|
|
|
|
menu.findItem(R.id.action_mute).setTitle(R.string.action_unmute);
|
|
|
|
}
|
|
|
|
if (relationship.endorsed) {
|
|
|
|
menu.findItem(R.id.action_endorse).setTitle(R.string.unendorse);
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.action_endorse).setTitle(R.string.endorse);
|
|
|
|
}
|
|
|
|
if (relationship.showing_reblogs) {
|
|
|
|
menu.findItem(R.id.action_hide_boost).setTitle(getString(R.string.hide_boost, account.username));
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.action_hide_boost).setTitle(getString(R.string.show_boost, account.username));
|
|
|
|
}
|
2022-12-14 11:21:00 +01:00
|
|
|
if (homeMuted) {
|
|
|
|
menu.findItem(R.id.action_mute_home).setTitle(getString(R.string.unmute_home));
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.action_mute_home).setTitle(getString(R.string.mute_home));
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
int itemId = item.getItemId();
|
2022-10-30 18:12:51 +01:00
|
|
|
String[] splitAcct = null;
|
2022-11-05 14:57:41 +01:00
|
|
|
if (account != null && account.acct != null) {
|
2022-10-30 18:12:51 +01:00
|
|
|
splitAcct = account.acct.split("@");
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
|
2022-11-05 14:57:41 +01:00
|
|
|
final boolean isOwner = account != null && account.id != null && BaseMainActivity.currentUserID != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0;
|
2022-04-27 15:20:42 +02:00
|
|
|
final String[] stringArrayConf;
|
|
|
|
if (isOwner) {
|
|
|
|
stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm);
|
|
|
|
} else {
|
|
|
|
stringArrayConf = getResources().getStringArray(R.array.more_action_confirm);
|
|
|
|
}
|
|
|
|
action doActionAccount;
|
|
|
|
if (itemId == android.R.id.home) {
|
|
|
|
finish();
|
|
|
|
return true;
|
2022-10-30 18:12:51 +01:00
|
|
|
} else if (itemId == R.id.action_follow_instance && splitAcct != null) {
|
2022-04-27 15:20:42 +02:00
|
|
|
String finalInstanceName = splitAcct[1];
|
|
|
|
ReorderVM reorderVM = new ViewModelProvider(ProfileActivity.this).get(ReorderVM.class);
|
|
|
|
//Get pinned instances
|
|
|
|
reorderVM.getPinned().observe(ProfileActivity.this, pinned -> {
|
|
|
|
boolean alreadyPinned = false;
|
2022-06-08 15:54:23 +02:00
|
|
|
boolean present = true;
|
|
|
|
if (pinned == null) {
|
|
|
|
pinned = new Pinned();
|
|
|
|
pinned.pinnedTimelines = new ArrayList<>();
|
|
|
|
present = false;
|
|
|
|
} else {
|
|
|
|
for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
|
|
|
|
if (pinnedTimeline.remoteInstance != null && pinnedTimeline.remoteInstance.host.compareToIgnoreCase(finalInstanceName) == 0) {
|
|
|
|
alreadyPinned = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (alreadyPinned) {
|
|
|
|
Toasty.info(ProfileActivity.this, getString(R.string.toast_instance_already_added), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
2022-06-08 15:54:23 +02:00
|
|
|
RemoteInstance.InstanceType instanceType;
|
2022-04-27 15:20:42 +02:00
|
|
|
if (nodeInfo != null) {
|
|
|
|
if (nodeInfo.software.name.compareToIgnoreCase("peertube") == 0) {
|
|
|
|
instanceType = RemoteInstance.InstanceType.PEERTUBE;
|
|
|
|
} else if (nodeInfo.software.name.compareToIgnoreCase("pixelfed") == 0) {
|
|
|
|
instanceType = RemoteInstance.InstanceType.PIXELFED;
|
|
|
|
} else if (nodeInfo.software.name.compareToIgnoreCase("misskey") == 0) {
|
|
|
|
instanceType = RemoteInstance.InstanceType.MISSKEY;
|
2023-07-07 16:01:09 +02:00
|
|
|
} else if (nodeInfo.software.name.compareToIgnoreCase("lemmy") == 0) {
|
|
|
|
instanceType = RemoteInstance.InstanceType.LEMMY;
|
2022-04-27 15:20:42 +02:00
|
|
|
} else if (nodeInfo.software.name.compareToIgnoreCase("gnu") == 0) {
|
|
|
|
instanceType = RemoteInstance.InstanceType.GNU;
|
|
|
|
} else {
|
|
|
|
instanceType = RemoteInstance.InstanceType.MASTODON;
|
|
|
|
}
|
2022-06-08 15:54:23 +02:00
|
|
|
} else {
|
|
|
|
instanceType = RemoteInstance.InstanceType.MASTODON;
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2022-06-08 15:54:23 +02:00
|
|
|
RemoteInstance remoteInstance = new RemoteInstance();
|
|
|
|
remoteInstance.type = instanceType;
|
|
|
|
remoteInstance.host = finalInstanceName;
|
|
|
|
PinnedTimeline pinnedTimeline = new PinnedTimeline();
|
|
|
|
pinnedTimeline.remoteInstance = remoteInstance;
|
|
|
|
pinnedTimeline.displayed = true;
|
|
|
|
pinnedTimeline.type = Timeline.TimeLineEnum.REMOTE;
|
|
|
|
pinnedTimeline.position = pinned.pinnedTimelines.size();
|
|
|
|
pinned.pinnedTimelines.add(pinnedTimeline);
|
2023-02-03 17:23:33 +01:00
|
|
|
if (pinned.instance == null || pinned.user_id == null) {
|
|
|
|
pinned.instance = MainActivity.currentInstance;
|
|
|
|
pinned.user_id = MainActivity.currentUserID;
|
|
|
|
}
|
2022-06-08 15:54:23 +02:00
|
|
|
Pinned finalPinned = pinned;
|
|
|
|
boolean finalPresent = present;
|
|
|
|
new Thread(() -> {
|
|
|
|
try {
|
|
|
|
if (finalPresent) {
|
|
|
|
new Pinned(ProfileActivity.this).updatePinned(finalPinned);
|
|
|
|
} else {
|
|
|
|
new Pinned(ProfileActivity.this).insertPinned(finalPinned);
|
|
|
|
}
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
|
|
|
|
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
|
|
|
|
intentBD.putExtras(b);
|
|
|
|
LocalBroadcastManager.getInstance(ProfileActivity.this).sendBroadcast(intentBD);
|
|
|
|
});
|
|
|
|
} catch (DBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}).start();
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_filter) {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder filterTagDialog = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
Set<String> featuredTagsSet = sharedpreferences.getStringSet(getString(R.string.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(getString(R.string.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);
|
|
|
|
}
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putString(getString(R.string.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.endorsed) {
|
|
|
|
accountsVM.endorse(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
|
|
|
|
} else {
|
|
|
|
accountsVM.unendorse(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
|
|
|
|
}
|
|
|
|
return true;
|
2023-01-17 16:41:39 +01:00
|
|
|
} else if (itemId == R.id.action_subscribed_language) {
|
|
|
|
if (relationship != null) {
|
|
|
|
List<String> subscribedLanguages = relationship.languages;
|
|
|
|
Set<String> storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null);
|
|
|
|
List<Languages.Language> languages = Languages.get(ProfileActivity.this);
|
|
|
|
if (languages == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
String[] codesArr;
|
|
|
|
String[] languagesArr;
|
|
|
|
boolean[] presentArr;
|
|
|
|
if (storedLanguages != null && storedLanguages.size() > 0) {
|
|
|
|
int i = 0;
|
|
|
|
codesArr = new String[storedLanguages.size()];
|
|
|
|
languagesArr = new String[storedLanguages.size()];
|
|
|
|
presentArr = new boolean[storedLanguages.size()];
|
|
|
|
for (String code : storedLanguages) {
|
|
|
|
for (Languages.Language language : languages) {
|
|
|
|
if (language.code.equalsIgnoreCase(code)) {
|
|
|
|
languagesArr[i] = language.language;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
codesArr[i] = code;
|
|
|
|
presentArr[i] = subscribedLanguages != null && subscribedLanguages.contains(code);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
codesArr = new String[languages.size()];
|
|
|
|
presentArr = new boolean[languages.size()];
|
|
|
|
languagesArr = new String[languages.size()];
|
|
|
|
int i = 0;
|
|
|
|
for (Languages.Language language : languages) {
|
|
|
|
codesArr[i] = language.code;
|
|
|
|
languagesArr[i] = language.language;
|
|
|
|
if (subscribedLanguages != null && subscribedLanguages.contains(language.code)) {
|
|
|
|
presentArr[i] = true;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2023-01-17 16:41:39 +01:00
|
|
|
builder.setTitle(getString(R.string.filter_languages));
|
|
|
|
builder.setMultiChoiceItems(languagesArr, presentArr, (dialog, which, isChecked) -> {
|
|
|
|
List<String> languagesFilter = new ArrayList<>();
|
|
|
|
for (int i = 0; i < codesArr.length; i++) {
|
|
|
|
if (presentArr[i]) {
|
|
|
|
languagesFilter.add(codesArr[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, relationship.showing_reblogs, relationship.notifying, languagesFilter)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.close, (dialog, which) -> dialog.dismiss());
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
return true;
|
2022-04-27 15:20:42 +02:00
|
|
|
} else if (itemId == R.id.action_hide_boost) {
|
|
|
|
if (relationship != null)
|
|
|
|
if (relationship.showing_reblogs) {
|
2023-01-17 16:41:39 +01:00
|
|
|
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, false, relationship.notifying, relationship.languages)
|
2022-04-27 15:20:42 +02:00
|
|
|
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
|
|
|
|
} else {
|
2023-01-17 16:41:39 +01:00
|
|
|
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, relationship.notifying, relationship.languages)
|
2022-04-27 15:20:42 +02:00
|
|
|
.observe(ProfileActivity.this, relationShip -> this.relationship = relationShip);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_direct_message) {
|
|
|
|
Intent intent = new Intent(ProfileActivity.this, ComposeActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
2022-05-01 16:32:37 +02:00
|
|
|
b.putSerializable(Helper.ARG_ACCOUNT_MENTION, account);
|
2022-04-27 15:20:42 +02:00
|
|
|
b.putString(Helper.ARG_VISIBILITY, "direct");
|
|
|
|
intent.putExtras(b);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_add_to_list) {
|
|
|
|
TimelinesVM timelinesVM = new ViewModelProvider(ProfileActivity.this).get(TimelinesVM.class);
|
|
|
|
timelinesVM.getLists(BaseMainActivity.currentInstance, BaseMainActivity.currentToken)
|
|
|
|
.observe(ProfileActivity.this, mastodonLists -> {
|
|
|
|
if (mastodonLists == null || mastodonLists.size() == 0) {
|
|
|
|
Toasty.info(ProfileActivity.this, getString(R.string.action_lists_empty), Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
accountsVM.getListContainingAccount(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
|
|
|
|
.observe(ProfileActivity.this, mastodonListUserIs -> {
|
2023-08-12 09:48:03 +02:00
|
|
|
if (mastodonListUserIs == null) {
|
|
|
|
mastodonListUserIs = new ArrayList<>();
|
|
|
|
}
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builderSingle = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
builderSingle.setTitle(getString(R.string.action_lists_add_to));
|
|
|
|
builderSingle.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss());
|
|
|
|
String[] listsId = new String[mastodonLists.size()];
|
|
|
|
String[] listsArray = new String[mastodonLists.size()];
|
|
|
|
boolean[] presentArray = new boolean[mastodonLists.size()];
|
|
|
|
int i = 0;
|
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
|
userIds.add(account.id);
|
|
|
|
for (MastodonList mastodonList : mastodonLists) {
|
|
|
|
listsArray[i] = mastodonList.title;
|
|
|
|
presentArray[i] = false;
|
|
|
|
listsId[i] = mastodonList.id;
|
|
|
|
for (MastodonList mastodonListPresent : mastodonListUserIs) {
|
|
|
|
if (mastodonList.id.equalsIgnoreCase(mastodonListPresent.id)) {
|
|
|
|
presentArray[i] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
builderSingle.setMultiChoiceItems(listsArray, presentArray, (dialog, which, isChecked) -> {
|
2022-11-23 12:13:24 +01:00
|
|
|
if (relationship == null || !relationship.following) {
|
2023-01-17 16:41:39 +01:00
|
|
|
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false, null)
|
2022-04-27 15:20:42 +02:00
|
|
|
.observe(ProfileActivity.this, newRelationShip -> {
|
2022-12-13 12:04:35 +01:00
|
|
|
if (newRelationShip != null) {
|
|
|
|
relationship = newRelationShip;
|
|
|
|
updateAccount();
|
|
|
|
if (isChecked) {
|
|
|
|
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> {
|
|
|
|
if (success == null || !success) {
|
|
|
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
timelinesVM.deleteAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
} else {
|
2022-12-13 12:04:35 +01:00
|
|
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show();
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (isChecked) {
|
2022-11-19 11:58:58 +01:00
|
|
|
timelinesVM.addAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds).observe(ProfileActivity.this, success -> {
|
2022-11-20 09:45:05 +01:00
|
|
|
if (success == null || !success) {
|
2022-11-19 11:58:58 +01:00
|
|
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error_add_to_list), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
2022-04-27 15:20:42 +02:00
|
|
|
} else {
|
|
|
|
timelinesVM.deleteAccountsList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, listsId[which], userIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
builderSingle.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_open_browser) {
|
|
|
|
if (account.url != null) {
|
|
|
|
if (!account.url.toLowerCase().startsWith("http://") && !account.url.toLowerCase().startsWith("https://"))
|
|
|
|
account.url = "http://" + account.url;
|
|
|
|
Helper.openBrowser(ProfileActivity.this, account.url);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_mention) {
|
|
|
|
Intent intent;
|
|
|
|
Bundle b;
|
|
|
|
intent = new Intent(ProfileActivity.this, ComposeActivity.class);
|
|
|
|
b = new Bundle();
|
2022-05-01 16:32:37 +02:00
|
|
|
b.putSerializable(Helper.ARG_ACCOUNT_MENTION, account);
|
2022-04-27 15:20:42 +02:00
|
|
|
intent.putExtras(b);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_mute) {
|
2022-11-24 16:44:24 +01:00
|
|
|
AlertDialog.Builder builderInner;
|
2022-09-08 08:49:42 +02:00
|
|
|
if (relationship != null) {
|
2022-11-24 16:44:24 +01:00
|
|
|
String target;
|
|
|
|
if (item.getItemId() == R.id.action_block_instance) {
|
|
|
|
target = account.acct.split("@")[1];
|
2022-09-08 08:49:42 +02:00
|
|
|
} else {
|
2022-11-24 16:44:24 +01:00
|
|
|
target = account.id;
|
2022-09-08 08:49:42 +02:00
|
|
|
}
|
2022-11-24 16:44:24 +01:00
|
|
|
if (relationship.muting) {
|
|
|
|
accountsVM.unmute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
2023-01-30 18:15:12 +01:00
|
|
|
builderInner = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-11-24 16:44:24 +01:00
|
|
|
builderInner.setTitle(stringArrayConf[0]);
|
2022-09-08 08:49:42 +02:00
|
|
|
|
2022-11-24 16:44:24 +01:00
|
|
|
builderInner.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
2022-12-09 10:59:03 +01:00
|
|
|
builderInner.setNegativeButton(R.string.keep_notifications, (dialog, which) -> accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target, false, 0)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
}));
|
2022-11-24 16:44:24 +01:00
|
|
|
builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> {
|
|
|
|
accountsVM.mute(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target, true, 0)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
}
|
2022-12-14 11:21:00 +01:00
|
|
|
} else if (itemId == R.id.action_mute_home) {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-12-14 11:21:00 +01:00
|
|
|
builderInner.setMessage(account.acct);
|
|
|
|
builderInner.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
if (homeMuted) {
|
|
|
|
builderInner.setTitle(R.string.unmute_home);
|
|
|
|
builderInner.setPositiveButton(R.string.action_unmute, (dialog, which) -> accountsVM.unmuteHome(currentAccount, account)
|
|
|
|
.observe(ProfileActivity.this, account -> {
|
|
|
|
homeMuted = false;
|
2022-12-14 14:29:20 +01:00
|
|
|
invalidateOptionsMenu();
|
2022-12-14 11:21:00 +01:00
|
|
|
Toasty.info(ProfileActivity.this, getString(R.string.toast_unmute), Toasty.LENGTH_LONG).show();
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
builderInner.setTitle(R.string.mute_home);
|
|
|
|
builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, account)
|
|
|
|
.observe(ProfileActivity.this, account -> {
|
|
|
|
homeMuted = true;
|
2022-12-14 14:29:20 +01:00
|
|
|
invalidateOptionsMenu();
|
2022-12-14 11:21:00 +01:00
|
|
|
Toasty.info(ProfileActivity.this, getString(R.string.toast_mute), Toasty.LENGTH_LONG).show();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
builderInner.show();
|
2022-11-20 15:55:30 +01:00
|
|
|
} else if (itemId == R.id.action_timed_mute) {
|
|
|
|
MastodonHelper.scheduleBoost(ProfileActivity.this, MastodonHelper.ScheduleType.TIMED_MUTED, null, account, rs -> {
|
|
|
|
this.relationship = rs;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
return true;
|
2022-04-27 15:20:42 +02:00
|
|
|
} else if (itemId == R.id.action_report) {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-04-27 15:20:42 +02:00
|
|
|
builderInner.setTitle(R.string.report_account);
|
|
|
|
//Text for report
|
|
|
|
EditText input = new EditText(ProfileActivity.this);
|
|
|
|
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, (dialog, which) -> dialog.dismiss());
|
|
|
|
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
String comment = null;
|
|
|
|
if (input.getText() != null)
|
|
|
|
comment = input.getText().toString();
|
|
|
|
accountsVM.report(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, null, null, null, comment, false);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
return true;
|
|
|
|
} else if (itemId == R.id.action_block) {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-09-08 08:49:42 +02:00
|
|
|
if (relationship != null) {
|
|
|
|
if (relationship.blocking) {
|
|
|
|
builderInner.setTitle(stringArrayConf[5]);
|
|
|
|
doActionAccount = action.UNBLOCK;
|
|
|
|
} else {
|
|
|
|
builderInner.setTitle(stringArrayConf[1]);
|
|
|
|
doActionAccount = action.BLOCK;
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
} else {
|
2022-09-08 08:49:42 +02:00
|
|
|
doActionAccount = action.NOTHING;
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2022-09-08 08:49:42 +02:00
|
|
|
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
String target;
|
|
|
|
if (item.getItemId() == R.id.action_block_instance) {
|
|
|
|
target = account.acct.split("@")[1];
|
|
|
|
} else {
|
|
|
|
target = account.id;
|
|
|
|
}
|
|
|
|
switch (doActionAccount) {
|
|
|
|
case BLOCK:
|
|
|
|
accountsVM.block(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case UNBLOCK:
|
|
|
|
accountsVM.unblock(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target)
|
|
|
|
.observe(ProfileActivity.this, relationShip -> {
|
|
|
|
this.relationship = relationShip;
|
|
|
|
updateAccount();
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
builderInner.show();
|
2022-11-24 16:44:24 +01:00
|
|
|
} else if (itemId == R.id.action_block_instance) {
|
2023-01-30 18:15:12 +01:00
|
|
|
AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
2022-11-24 16:44:24 +01:00
|
|
|
String domain = account.acct.split("@")[1];
|
|
|
|
builderInner.setMessage(getString(R.string.block_domain_confirm_message, domain));
|
|
|
|
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
String target;
|
|
|
|
if (item.getItemId() == R.id.action_block_instance) {
|
|
|
|
target = account.acct.split("@")[1];
|
|
|
|
} else {
|
|
|
|
target = account.id;
|
|
|
|
}
|
|
|
|
accountsVM.addDomainBlocks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, target);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
builderInner.show();
|
|
|
|
} else {
|
|
|
|
return true;
|
2022-09-08 08:49:42 +02:00
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
if (scheduledExecutorService != null) {
|
|
|
|
scheduledExecutorService.shutdownNow();
|
|
|
|
scheduledExecutorService = null;
|
|
|
|
}
|
2023-12-12 15:47:15 +01:00
|
|
|
unregisterReceiver(broadcast_data);
|
2022-04-27 15:20:42 +02:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum action {
|
|
|
|
FOLLOW,
|
|
|
|
UNFOLLOW,
|
|
|
|
BLOCK,
|
|
|
|
UNBLOCK,
|
|
|
|
NOTHING,
|
|
|
|
MUTE,
|
|
|
|
UNMUTE,
|
|
|
|
REPORT,
|
|
|
|
BLOCK_DOMAIN
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|